2 This file is part of GNUnet
3 (C) 2010 2011 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
27 //TODO split rx and tx structures for better handling
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_protocols.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_statistics_service.h"
34 #include "gnunet_transport_service.h"
35 #include "gnunet_transport_plugin.h"
36 #include "plugin_transport_wlan.h"
37 #include "gnunet_common.h"
38 #include "gnunet_crypto_lib.h"
39 #include "gnunet_fragmentation_lib.h"
40 #include "gnunet_constants.h"
41 //#include "wlan/ieee80211.h"
42 //#include <netinet/ip.h>
46 #define PROTOCOL_PREFIX "wlan"
48 #define PLUGIN_LOG_NAME "wlan-plugin"
56 * time out of a session
58 #define SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
61 * time out of a mac endpoint
63 #define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2)
66 * scaling factor for hello beacon
68 #define HELLO_BEACON_SCALING_FACTOR 30
71 * scaling factor for restarting the helper
73 #define HELPER_RESTART_SCALING_FACTOR 2
76 * max size of fragment queue
78 #define FRAGMENT_QUEUE_SIZE 10
80 * max messages in fragment queue per session/client
82 #define FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION 1
85 * max messages in fragment queue per MAC
87 #define FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT 1
90 * max messages in in queue
92 #define MESSAGES_IN_QUEUE_SIZE 10
94 * max messages in in queue per session/client
96 #define MESSAGES_IN_DEFRAG_QUEUE_PER_MAC 1
99 * LLC fields for better compatibility
101 #define WLAN_LLC_DSAP_FIELD 0x1f
102 #define WLAN_LLC_SSAP_FIELD 0x1f
108 #define DEBUG_wlan GNUNET_EXTRA_LOGGING
109 #define DEBUG_wlan_retransmission GNUNET_EXTRA_LOGGING
110 #define DEBUG_wlan_ip_udp_packets_on_air GNUNET_NO
111 #define DEBUG_wlan_msg_dump GNUNET_EXTRA_LOGGING
114 #define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
116 #define IEEE80211_FC0_VERSION_MASK 0x03
117 #define IEEE80211_FC0_VERSION_SHIFT 0
118 #define IEEE80211_FC0_VERSION_0 0x00
119 #define IEEE80211_FC0_TYPE_MASK 0x0c
120 #define IEEE80211_FC0_TYPE_SHIFT 2
121 #define IEEE80211_FC0_TYPE_MGT 0x00
122 #define IEEE80211_FC0_TYPE_CTL 0x04
123 #define IEEE80211_FC0_TYPE_DATA 0x08
126 * Structure of an internet header, naked of options.
130 #if __BYTE_ORDER == __LITTLE_ENDIAN
131 unsigned int ip_hl:4; /* header length */
132 unsigned int ip_v:4; /* version */
134 #if __BYTE_ORDER == __BIG_ENDIAN
135 unsigned int ip_v:4; /* version */
136 unsigned int ip_hl:4; /* header length */
138 u_int8_t ip_tos; /* type of service */
139 u_short ip_len; /* total length */
140 u_short ip_id; /* identification */
141 u_short ip_off; /* fragment offset field */
142 #define IP_RF 0x8000 /* reserved fragment flag */
143 #define IP_DF 0x4000 /* dont fragment flag */
144 #define IP_MF 0x2000 /* more fragments flag */
145 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
146 u_int8_t ip_ttl; /* time to live */
147 u_int8_t ip_p; /* protocol */
148 u_short ip_sum; /* checksum */
149 struct in_addr ip_src, ip_dst; /* source and dest address */
161 * generic definitions for IEEE 802.11 frames
163 struct ieee80211_frame
167 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
168 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
169 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
172 #if DEBUG_wlan_ip_udp_packets_on_air > 1
179 * Encapsulation of all of the state of the plugin.
186 struct GNUNET_TRANSPORT_PluginEnvironment *env;
189 * List of open connections. head
191 struct MacEndpoint *mac_head;
194 * List of open connections. tail
196 struct MacEndpoint *mac_tail;
199 * Number of connections
201 unsigned int mac_count;
204 * encapsulation of data from the local wlan helper program
206 struct GNUNET_SERVER_MessageStreamTokenizer *suid_tokenizer;
209 * encapsulation of packets received from the wlan helper
211 struct GNUNET_SERVER_MessageStreamTokenizer *data_tokenizer;
214 * stdout pipe handle for the gnunet-wlan-helper process
216 struct GNUNET_DISK_PipeHandle *server_stdout;
219 * stdout file handle for the gnunet-wlan-helper process
221 const struct GNUNET_DISK_FileHandle *server_stdout_handle;
224 * stdin pipe handle for the gnunet-wlan-helper process
226 struct GNUNET_DISK_PipeHandle *server_stdin;
229 * stdin file handle for the gnunet-wlan-helper process
231 const struct GNUNET_DISK_FileHandle *server_stdin_handle;
234 * ID of the gnunet-wlan-server std read task
236 GNUNET_SCHEDULER_TaskIdentifier server_read_task;
239 * ID of the gnunet-wlan-server std read task
241 GNUNET_SCHEDULER_TaskIdentifier server_write_task;
244 * ID of the delay task for writing
246 GNUNET_SCHEDULER_TaskIdentifier server_write_delay_task;
249 * The process id of the wlan process
251 struct GNUNET_OS_Process *server_proc;
254 * The interface of the wlan card given to us by the user.
259 * Mode of operation for the helper, 0 = normal, 1 = first loopback, 2 = second loopback
261 long long unsigned int testmode;
264 * The mac_address of the wlan card given to us by the helper.
266 struct MacAddress mac_address;
269 * Sessions currently pending for transmission
272 struct Sessionqueue *pending_Sessions_head;
275 * Sessions currently pending for transmission
276 * to a peer (tail), if any.
278 struct Sessionqueue *pending_Sessions_tail;
281 * number of pending sessions
283 unsigned int pendingsessions;
286 * Messages in the sending queues
288 int pending_Fragment_Messages;
291 * messages ready for send, head
293 struct FragmentMessage_queue *sending_messages_head;
295 * messages ready for send, tail
297 struct FragmentMessage_queue *sending_messages_tail;
299 * time of the next "hello-beacon"
301 struct GNUNET_TIME_Absolute beacon_time;
304 * queue to send acks for received fragments (head)
306 struct AckSendQueue *ack_send_queue_head;
309 * queue to send acks for received fragments (tail)
311 struct AckSendQueue *ack_send_queue_tail;
314 * Tracker for bandwidth limit
316 struct GNUNET_BANDWIDTH_Tracker tracker;
319 * saves the current state of the helper process
321 int helper_is_running;
325 * Struct to store data if file write did not accept the whole packet
330 * pointer to the global plugin struct
332 struct Plugin *plugin;
335 * head of the next part to send to the helper
337 char *head_of_next_write;
340 * Start of the message to send, needed for free
342 struct GNUNET_MessageHeader *msgstart;
351 * Queue of sessions, for the general session queue and the pending session queue
356 struct Sessionqueue *next;
357 struct Sessionqueue *prev;
358 struct Session *content;
362 * Queue of fragmented messages, for the sending queue of the plugin
365 struct FragmentMessage_queue
367 struct FragmentMessage_queue *next;
368 struct FragmentMessage_queue *prev;
369 struct FragmentMessage *content;
373 * Queue for the fragments received
376 struct Receive_Fragment_Queue
378 struct Receive_Fragment_Queue *next;
379 struct Receive_Fragment_Queue *prev;
383 struct Radiotap_rx rxinfo;
387 struct MacEndpoint_id_fragment_triple
389 struct MacEndpoint *endpoint;
391 struct FragmentMessage *fm;
395 struct Plugin_Session_pair
397 struct Plugin *plugin;
398 struct Session *session;
402 * Information kept for each message that is yet to
405 struct PendingMessage
410 struct PendingMessage *next;
414 struct PendingMessage *prev;
417 * The pending message
419 struct WlanHeader *msg;
422 * Size of the message
427 * Continuation function to call once the message
428 * has been sent. Can be NULL if there is no
429 * continuation to call.
431 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
434 * Cls for transmit_cont
436 void *transmit_cont_cls;
439 * Timeout value for the pending message.
441 struct GNUNET_TIME_Absolute timeout;
446 * Queue for acks to send for fragments recived
452 * next ack in the ack send queue
454 struct AckSendQueue *next;
456 * previous ack in the ack send queue
458 struct AckSendQueue *prev;
460 * pointer to the session this ack belongs to
462 struct MacEndpoint *endpoint;
464 * ID of message, to distinguish between the messages, picked randomly.
471 struct GNUNET_MessageHeader *hdr;
473 * pointer to the ieee wlan header
475 struct ieee80211_frame *ieeewlanheader;
477 * pointer to the radiotap header
479 struct Radiotap_Send *radioHeader;
483 * Session infos gathered from a messages
489 * the session this message belongs to
491 struct Session *session;
495 struct MacAddress addr;
500 struct MacEndpoint *macendpoint;
504 * Session handle for connections.
512 struct SessionHeader header;
515 * Message currently pending for transmission
516 * to this peer, if any. head
518 struct PendingMessage *pending_message_head;
521 * Message currently pending for transmission
522 * to this peer, if any. tail
524 struct PendingMessage *pending_message_tail;
527 * To whom are we talking to (set to our identity
528 * if we are still waiting for the welcome message)
530 struct GNUNET_PeerIdentity target;
533 * Address of the other peer (either based on our 'connect'
534 * call or on our 'accept' call).
539 * Last activity on this connection. Used to select preferred
540 * connection and timeout
542 struct GNUNET_TIME_Absolute last_activity;
547 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
552 struct MacEndpoint *mac;
555 * count of messages in the fragment out queue for this session
558 int fragment_messages_out_count;
563 * Struct to represent one network card connection
568 * Pointer to the global plugin struct.
570 struct Plugin *plugin;
572 * Struct to hold the session reachable over this mac; head
574 struct Sessionqueue *sessions_head;
576 * Struct to hold the session reachable over this mac; tail
578 struct Sessionqueue *sessions_tail;
580 * Messages currently sending
583 struct FragmentMessage *sending_messages_head;
586 * Messages currently sending
587 * to a peer (tail), if any.
589 struct FragmentMessage *sending_messages_tail;
593 struct MacEndpoint *next;
597 struct MacEndpoint *prev;
602 struct MacAddress addr;
605 * Defrag context for this mac endpoint
607 struct GNUNET_DEFRAGMENT_Context *defrag;
610 * count of messages in the fragment out queue for this mac endpoint
613 int fragment_messages_out_count;
621 * Duplicates received
636 * Last activity on this endpoint. Used to select preferred
639 struct GNUNET_TIME_Absolute last_activity;
644 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
648 * Struct for Messages in the fragment queue
651 struct FragmentMessage
655 * Session this message belongs to
658 struct Session *session;
661 * This is a doubly-linked list.
663 struct FragmentMessage *next;
666 * This is a doubly-linked list.
668 struct FragmentMessage *prev;
671 * Fragmentation context
673 struct GNUNET_FRAGMENT_Context *fragcontext;
676 * Timeout value for the message.
678 struct GNUNET_TIME_Absolute timeout;
683 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
696 * pointer to the ieee wlan header
698 struct ieee80211_frame *ieeewlanheader;
700 * pointer to the radiotap header
702 struct Radiotap_Send *radioHeader;
706 do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
708 free_session (struct Plugin *plugin, struct Sessionqueue *queue,
709 int do_free_macendpoint);
710 static struct MacEndpoint *
711 create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr);
714 finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
717 * Generates a nice hexdump of a memory area.
719 * \param mem pointer to memory to dump
720 * \param length how many bytes to dump
723 hexdump (const void *mem, unsigned length)
726 char *src = (char *) mem;
728 printf ("dumping %u bytes from %p\r\n"
729 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n",
734 for (i = 0; i < length; i += 16, src += 16)
738 t += sprintf (t, "%04x: ", i);
739 for (j = 0; j < 16; j++)
742 t += sprintf (t, "%02X", src[j] & 0xff);
744 t += sprintf (t, " ");
746 t += sprintf (t, j % 2 ? " " : "-");
749 t += sprintf (t, " ");
750 for (j = 0; j < 16; j++)
754 if (isprint ((unsigned char) src[j]))
755 t += sprintf (t, "%c", src[j]);
757 t += sprintf (t, ".");
761 t += sprintf (t, " ");
765 t += sprintf (t, "\r\n");
771 * Function to find a MacEndpoint with a specific mac addr
772 * @param plugin pointer to the plugin struct
773 * @param addr pointer to the mac address
774 * @param create_new GNUNET_YES if a new end point should be created
777 static struct MacEndpoint *
778 get_macendpoint (struct Plugin *plugin, const struct MacAddress *addr,
781 struct MacEndpoint *queue = plugin->mac_head;
783 while (queue != NULL)
785 //GNUNET_assert (queue->sessions_head != NULL);
786 if (memcmp (addr, &queue->addr, sizeof (struct MacAddress)) == 0)
787 return queue; /* session found */
791 if (create_new == GNUNET_YES)
793 return create_macendpoint (plugin, addr);
803 * search for a session with the macendpoint and peer id
805 * @param plugin pointer to the plugin struct
806 * @param endpoint pointer to the mac endpoint of the peer
807 * @param peer pointer to the peerid
808 * @return returns the session
810 static struct Session *
811 search_session (struct Plugin *plugin, const struct MacEndpoint *endpoint,
812 const struct GNUNET_PeerIdentity *peer)
814 GNUNET_assert (endpoint != NULL);
815 struct Sessionqueue *queue = endpoint->sessions_head;
817 while (queue != NULL)
819 GNUNET_assert (queue->content != NULL);
821 (peer, &queue->content->target,
822 sizeof (struct GNUNET_PeerIdentity)) == 0)
823 return queue->content; /* session found */
830 * Function called for a quick conversion of the binary address to
831 * a numeric address. Note that the caller must not free the
832 * address and that the next call to this function is allowed
833 * to override the address again.
836 * @param addr binary address
837 * @param addrlen length of the address
838 * @return string representing the same address
841 wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
844 const struct MacAddress *mac;
846 if (addrlen != sizeof (struct MacAddress))
852 GNUNET_snprintf (ret, sizeof (ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
853 PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2],
854 mac->mac[3], mac->mac[4], mac->mac[5]);
860 * Function for the scheduler if a session times out
861 * @param cls pointer to the Sessionqueue
862 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
865 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
867 struct Sessionqueue *queue = cls;
869 GNUNET_assert (queue != NULL);
870 GNUNET_assert (queue->content != NULL);
871 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
872 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
876 if (GNUNET_TIME_absolute_get_remaining
877 (GNUNET_TIME_absolute_add
878 (queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0)
881 GNUNET_assert (queue->content->mac != NULL);
882 GNUNET_assert (queue->content->mac->plugin != NULL);
883 GNUNET_STATISTICS_update (queue->content->mac->plugin->env->stats,
884 _("# wlan session timeouts"), 1, GNUNET_NO);
885 free_session (queue->content->mac->plugin, queue, GNUNET_YES);
889 queue->content->timeout_task =
890 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
895 * create a new session
897 * @param plugin pointer to the plugin struct
898 * @param endpoint pointer to the mac endpoint of the peer
899 * @param peer peer identity to use for this session
900 * @return returns the session
903 static struct Session *
904 create_session (struct Plugin *plugin, struct MacEndpoint *endpoint,
905 const struct GNUNET_PeerIdentity *peer)
907 GNUNET_assert (endpoint != NULL);
908 GNUNET_assert (plugin != NULL);
909 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1,
911 struct Sessionqueue *queue =
912 GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session));
914 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
915 endpoint->sessions_tail, queue);
917 queue->content = (struct Session *) &queue[1];
918 queue->content->mac = endpoint;
919 queue->content->target = *peer;
920 queue->content->last_activity = GNUNET_TIME_absolute_get ();
921 queue->content->timeout_task =
922 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
925 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
926 "New session %p with endpoint %p: %s\n", queue->content,
927 endpoint, wlan_plugin_address_to_string (NULL,
932 return queue->content;
936 * Get session from address, create if no session exists
938 * @param plugin pointer to the plugin struct
939 * @param addr pointer to the mac address of the peer
940 * @param peer pointer to the peerid
941 * @return returns the session
943 static struct Session *
944 get_session (struct Plugin *plugin, const struct MacAddress *addr,
945 const struct GNUNET_PeerIdentity *peer)
947 struct MacEndpoint *mac;
949 mac = get_macendpoint (plugin, addr, GNUNET_YES);
950 struct Session *session = search_session (plugin, mac, peer);
954 return create_session (plugin, mac, peer);
958 * Queue the session to send data
959 * checks if there is a message pending
960 * checks if this session is not allready in the queue
961 * @param plugin pointer to the plugin
962 * @param session pointer to the session to add
965 queue_session (struct Plugin *plugin, struct Session *session)
967 struct Sessionqueue *queue = plugin->pending_Sessions_head;
969 if (session->pending_message_head != NULL)
971 while (queue != NULL)
973 // content is never NULL
974 GNUNET_assert (queue->content != NULL);
975 // is session already in queue?
976 if (session == queue->content)
984 // Session is not in the queue
986 queue = GNUNET_malloc (sizeof (struct Sessionqueue));
987 queue->content = session;
990 GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head,
991 plugin->pending_Sessions_tail, queue);
992 plugin->pendingsessions++;
993 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
994 plugin->pendingsessions, GNUNET_NO);
1000 * Function to schedule the write task, executed after a delay
1001 * @param cls pointer to the plugin struct
1002 * @param tc GNUNET_SCHEDULER_TaskContext pointer
1005 delay_fragment_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1007 struct Plugin *plugin = cls;
1009 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1011 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1014 // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg
1015 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1017 plugin->server_write_task =
1018 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1019 plugin->server_stdin_handle,
1020 &do_transmit, plugin);
1025 * Function to calculate the time of the next periodic "hello-beacon"
1026 * @param plugin pointer to the plugin struct
1030 set_next_beacon_time (struct Plugin *const plugin)
1032 //under 10 known peers: once a second
1033 if (plugin->mac_count < 10)
1035 plugin->beacon_time =
1036 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1037 GNUNET_TIME_relative_multiply
1038 (GNUNET_TIME_UNIT_SECONDS,
1039 HELLO_BEACON_SCALING_FACTOR));
1041 //under 30 known peers: every 10 seconds
1042 else if (plugin->mac_count < 30)
1044 plugin->beacon_time =
1045 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1046 GNUNET_TIME_relative_multiply
1047 (GNUNET_TIME_UNIT_SECONDS,
1048 10 * HELLO_BEACON_SCALING_FACTOR));
1050 //over 30 known peers: once a minute
1053 plugin->beacon_time =
1054 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1055 GNUNET_TIME_relative_multiply
1056 (GNUNET_TIME_UNIT_MINUTES,
1057 HELLO_BEACON_SCALING_FACTOR));
1062 * Function to set the timer for the next timeout of the fragment queue
1063 * @param plugin the handle to the plugin struct
1067 set_next_send (struct Plugin *const plugin)
1069 struct GNUNET_TIME_Relative next_send;
1071 //abort if helper is not running
1072 if (plugin->helper_is_running == GNUNET_NO){
1077 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1079 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1080 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1083 //check if some acks are in the queue
1084 if (plugin->ack_send_queue_head != NULL)
1086 next_send = GNUNET_TIME_UNIT_ZERO;
1089 //check if there are some fragments in the queue
1090 else if (plugin->sending_messages_head != NULL)
1092 next_send = GNUNET_TIME_UNIT_ZERO;
1096 next_send = GNUNET_TIME_absolute_get_remaining (plugin->beacon_time);
1100 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1101 "Next packet is send in: %u\n", next_send.rel_value);
1104 if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value)
1106 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1108 plugin->server_write_task =
1109 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1110 plugin->server_stdin_handle,
1111 &do_transmit, plugin);
1116 if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK)
1118 plugin->server_write_delay_task =
1119 GNUNET_SCHEDULER_add_delayed (next_send, &delay_fragment_task,
1126 * Function to get the next queued Session, removes the session from the queue
1127 * @param plugin pointer to the plugin struct
1128 * @return pointer to the session found, returns NULL if there is now session in the queue
1130 static struct Session *
1131 get_next_queue_session (struct Plugin *plugin)
1133 struct Session *session;
1134 struct Sessionqueue *sessionqueue;
1135 struct Sessionqueue *sessionqueue_alt;
1136 struct PendingMessage *pm;
1138 sessionqueue = plugin->pending_Sessions_head;
1140 while (sessionqueue != NULL)
1142 session = sessionqueue->content;
1144 GNUNET_assert (session != NULL);
1145 pm = session->pending_message_head;
1150 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1151 "pending message is empty, should not happen. session %p\n",
1154 sessionqueue_alt = sessionqueue;
1155 sessionqueue = sessionqueue->next;
1156 plugin->pendingsessions--;
1157 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1158 plugin->pendingsessions, GNUNET_NO);
1159 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1160 plugin->pending_Sessions_tail,
1163 GNUNET_free (sessionqueue_alt);
1168 //check for message timeout
1169 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
1171 //check if session has no message in the fragment queue
1172 if ((session->mac->fragment_messages_out_count <
1173 FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT) &&
1174 (session->fragment_messages_out_count <
1175 FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
1177 plugin->pendingsessions--;
1178 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1179 plugin->pendingsessions, GNUNET_NO);
1180 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1181 plugin->pending_Sessions_tail,
1183 GNUNET_free (sessionqueue);
1189 sessionqueue = sessionqueue->next;
1194 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1195 session->pending_message_tail, pm);
1197 //call the cont func that it did not work
1198 if (pm->transmit_cont != NULL)
1199 pm->transmit_cont (pm->transmit_cont_cls, &(session->target),
1201 GNUNET_free (pm->msg);
1204 if (session->pending_message_head == NULL)
1206 sessionqueue_alt = sessionqueue;
1207 sessionqueue = sessionqueue->next;
1208 plugin->pendingsessions--;
1209 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1210 plugin->pendingsessions, GNUNET_NO);
1211 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1212 plugin->pending_Sessions_tail,
1215 GNUNET_free (sessionqueue_alt);
1224 * frees the space of a message in the fragment queue (send queue)
1225 * @param plugin the plugin struct
1226 * @param fm message to free
1229 free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm)
1231 struct Session *session = fm->session;
1232 struct MacEndpoint *endpoint = session->mac;
1233 struct FragmentMessage_queue *fmq;
1234 struct FragmentMessage_queue *fmq_next;
1236 fmq = plugin->sending_messages_head;
1239 fmq_next = fmq->next;
1240 if (fmq->content == fm)
1242 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1243 plugin->sending_messages_tail, fmq);
1249 (session->mac->fragment_messages_out_count)--;
1250 session->fragment_messages_out_count--;
1251 plugin->pending_Fragment_Messages--;
1252 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
1253 plugin->pending_Fragment_Messages, GNUNET_NO);
1254 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
1255 endpoint->sending_messages_tail, fm);
1256 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
1257 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1259 GNUNET_SCHEDULER_cancel (fm->timeout_task);
1260 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1265 queue_session (plugin, session);
1267 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1268 "Free pending fragment messages %p, session %p\n", fm,
1274 * function to fill the radiotap header
1275 * @param plugin pointer to the plugin struct
1276 * @param endpoint pointer to the endpoint
1277 * @param header pointer to the radiotap header
1278 * @return GNUNET_YES at success
1281 getRadiotapHeader (struct Plugin *plugin, struct MacEndpoint *endpoint,
1282 struct Radiotap_Send *header)
1285 if (endpoint != NULL)
1287 header->rate = endpoint->rate;
1288 header->tx_power = endpoint->tx_power;
1289 header->antenna = endpoint->antenna;
1294 header->tx_power = 0;
1295 header->antenna = 0;
1302 * function to generate the wlan hardware header for one packet
1303 * @param Header address to write the header to
1304 * @param to_mac_addr address of the recipient
1305 * @param plugin pointer to the plugin struct
1306 * @param size size of the whole packet, needed to calculate the time to send the packet
1307 * @return GNUNET_YES if there was no error
1310 getWlanHeader (struct ieee80211_frame *Header,
1311 const struct MacAddress *to_mac_addr, struct Plugin *plugin,
1315 const int rate = 11000000;
1317 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA;
1318 Header->i_fc[1] = 0x00;
1319 memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid));
1320 memcpy (&Header->i_addr2, plugin->mac_address.mac,
1321 sizeof (plugin->mac_address));
1322 memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress));
1324 tmp16 = (uint16_t *) Header->i_dur;
1325 *tmp16 = (uint16_t) htole16 ((size * 1000000) / rate + 290);
1326 Header->llc[0] = WLAN_LLC_DSAP_FIELD;
1327 Header->llc[1] = WLAN_LLC_SSAP_FIELD;
1329 #if DEBUG_wlan_ip_udp_packets_on_air > 1
1334 Header->ip.ip_dst.s_addr = *((uint32_t *) & to_mac_addr->mac[2]);
1335 Header->ip.ip_src.s_addr = *((uint32_t *) & plugin->mac_address.mac[2]);
1336 Header->ip.ip_v = 4;
1337 Header->ip.ip_hl = 5;
1338 Header->ip.ip_p = 17;
1339 Header->ip.ip_ttl = 1;
1340 Header->ip.ip_len = htons (size + 8);
1341 Header->ip.ip_sum = 0;
1342 x = (uint16_t *) & Header->ip;
1343 count = sizeof (struct iph);
1346 /* This is the inner loop */
1347 crc += (unsigned short) *x++;
1350 /* Add left-over byte, if any */
1352 crc += *(unsigned char *) x;
1353 crc = (crc & 0xffff) + (crc >> 16);
1354 Header->ip.ip_sum = htons (~(unsigned short) crc);
1355 Header->udp.len = htons (size - sizeof (struct ieee80211_frame));
1365 * @param msgbuf pointer tor the data
1366 * @param msgbuf_size size of the data
1368 * @return 32bit crc value
1372 getcrc32 (const char *msgbuf, size_t msgbuf_size)
1375 return GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size);;
1381 * @param msgbuf pointer tor the data
1382 * @param msgbuf_size size of the data
1384 * @return 16bit crc value
1388 getcrc16 (const char *msgbuf, size_t msgbuf_size)
1390 //TODO calc some crc
1395 * function to add a fragment of a message to send
1396 * @param cls FragmentMessage this message belongs to
1397 * @param hdr pointer to the start of the message
1401 add_message_for_send (void *cls, const struct GNUNET_MessageHeader *hdr)
1404 struct FragmentMessage *fm = cls;
1405 struct FragmentMessage_queue *fmqueue;
1407 GNUNET_assert (cls != NULL);
1408 GNUNET_assert (fm->frag == NULL);
1409 struct MacEndpoint *endpoint = fm->session->mac;
1410 struct Plugin *plugin = endpoint->plugin;
1411 struct GNUNET_MessageHeader *msgheader;
1412 struct GNUNET_MessageHeader *msgheader2;
1415 #if DEBUG_wlan_retransmission > 1
1416 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1417 "Adding fragment of message %p to send, session %p, endpoint %p, type %u\n",
1418 fm, fm->session, endpoint, hdr->type);
1422 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1423 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1424 fm->frag = GNUNET_malloc (size);
1427 msgheader = (struct GNUNET_MessageHeader *) fm->frag;
1428 msgheader->size = htons (size);
1429 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1431 fm->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1432 fm->ieeewlanheader = (struct ieee80211_frame *) &fm->radioHeader[1];
1433 msgheader2 = (struct GNUNET_MessageHeader *) &fm->ieeewlanheader[1];
1434 memcpy (msgheader2, hdr, ntohs (hdr->size));
1436 fmqueue = GNUNET_malloc (sizeof (struct FragmentMessage_queue));
1437 fmqueue->content = fm;
1439 GNUNET_CONTAINER_DLL_insert_tail (plugin->sending_messages_head,
1440 plugin->sending_messages_tail, fmqueue);
1441 set_next_send (plugin);
1446 * We have been notified that wlan-helper has written something to stdout.
1447 * Handle the output, then reschedule this function to be called again once
1448 * more is available.
1450 * @param cls the plugin handle
1451 * @param tc the scheduling context
1454 wlan_plugin_helper_read (void *cls,
1455 const struct GNUNET_SCHEDULER_TaskContext *tc)
1457 struct Plugin *plugin = cls;
1459 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1461 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1464 char mybuf[WLAN_MTU + sizeof (struct GNUNET_MessageHeader)];
1468 GNUNET_DISK_file_read (plugin->server_stdout_handle, mybuf,
1473 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1475 ("Finished reading from wlan-helper stdout with code: %d\n"),
1480 GNUNET_SERVER_mst_receive (plugin->suid_tokenizer, NULL, mybuf, bytes,
1481 GNUNET_NO, GNUNET_NO);
1483 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
1484 plugin->server_read_task =
1485 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1486 plugin->server_stdout_handle,
1487 &wlan_plugin_helper_read, plugin);
1491 * Start the gnunet-wlan-helper process.
1493 * @param plugin the transport plugin
1494 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
1497 wlan_transport_start_wlan_helper (struct Plugin *plugin)
1499 const char *filenamehw = "gnunet-transport-wlan-helper";
1500 char *filenameloopback = "gnunet-transport-wlan-helper-dummy";
1501 char *absolute_filename = NULL;
1503 if (plugin->helper_is_running == GNUNET_YES){
1505 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1506 "wlan_transport_start_wlan_helper not needed, helper already running!");
1511 plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
1512 if (plugin->server_stdout == NULL)
1513 return GNUNET_SYSERR;
1515 plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
1516 if (plugin->server_stdin == NULL)
1517 return GNUNET_SYSERR;
1519 if ((plugin->testmode == 1) || (plugin->testmode == 2))
1521 if (GNUNET_OS_check_helper_binary (filenameloopback) == GNUNET_YES)
1523 absolute_filename = strdup (filenameloopback);
1527 char cwd[FILENAME_MAX];
1529 GNUNET_assert (getcwd (cwd, sizeof (cwd)) != NULL);
1531 GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR,
1534 if (GNUNET_DISK_file_test (filenameloopback) != GNUNET_YES)
1536 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1537 "Helper `%s' not found! %i\n", absolute_filename);
1543 /* Start the server process */
1545 if (plugin->testmode == 0)
1549 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1550 "Starting gnunet-wlan-helper process cmd: %s %s %i\n",
1551 filenamehw, plugin->interface, plugin->testmode);
1554 if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_YES)
1556 plugin->server_proc =
1557 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1558 filenamehw, filenamehw, plugin->interface,
1561 else if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_NO)
1563 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1564 "gnunet-transport-wlan-helper is not suid, please change it or look at the doku\n");
1569 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1570 "gnunet-transport-wlan-helper not found, please look if it exists and is the $PATH variable!\n");
1575 else if (plugin->testmode == 1)
1579 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
1580 "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n",
1581 absolute_filename, plugin->interface, plugin->testmode);
1583 plugin->server_proc =
1584 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1585 absolute_filename, absolute_filename, "1",
1587 if (plugin->server_proc == NULL)
1589 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1590 "`%s' not found, please look if it exists and is in the $PATH variable!\n",
1595 else if (plugin->testmode == 2)
1598 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
1599 "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n",
1600 absolute_filename, plugin->interface, plugin->testmode);
1603 plugin->server_proc =
1604 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1605 absolute_filename, absolute_filename, "2",
1607 if (plugin->server_proc == NULL)
1609 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1610 "`%s' not found, please look if it exists and is in the $PATH variable!\n",
1615 if (absolute_filename != NULL)
1616 GNUNET_free (absolute_filename);
1617 if (plugin->server_proc == NULL)
1620 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1621 "Failed to start gnunet-wlan-helper process\n");
1623 return GNUNET_SYSERR;
1628 /* Close the write end of the read pipe */
1629 GNUNET_DISK_pipe_close_end (plugin->server_stdout,
1630 GNUNET_DISK_PIPE_END_WRITE);
1632 /* Close the read end of the write pipe */
1633 GNUNET_DISK_pipe_close_end (plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
1635 plugin->server_stdout_handle =
1636 GNUNET_DISK_pipe_handle (plugin->server_stdout,
1637 GNUNET_DISK_PIPE_END_READ);
1638 plugin->server_stdin_handle =
1639 GNUNET_DISK_pipe_handle (plugin->server_stdin,
1640 GNUNET_DISK_PIPE_END_WRITE);
1642 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
1645 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1646 "Adding server_read_task for the wlan-helper\n");
1649 plugin->server_read_task =
1650 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1651 plugin->server_stdout_handle,
1652 &wlan_plugin_helper_read, plugin);
1654 plugin->helper_is_running = GNUNET_YES;
1659 * Stops the gnunet-wlan-helper process.
1661 * @param plugin the transport plugin
1662 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
1665 wlan_transport_stop_wlan_helper (struct Plugin *plugin)
1668 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1669 "Stoping WLAN helper process\n");
1672 if (plugin->helper_is_running == GNUNET_NO){
1674 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1675 "wlan_transport_stop_wlan_helper not needed, helper already stopped!");
1680 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1682 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1683 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1686 if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK)
1688 GNUNET_SCHEDULER_cancel (plugin->server_write_task);
1689 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1692 if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK)
1694 GNUNET_SCHEDULER_cancel (plugin->server_read_task);
1695 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1698 GNUNET_DISK_pipe_close (plugin->server_stdout);
1699 GNUNET_DISK_pipe_close (plugin->server_stdin);
1700 GNUNET_OS_process_kill (plugin->server_proc, SIGKILL);
1701 GNUNET_OS_process_wait (plugin->server_proc);
1702 GNUNET_OS_process_close (plugin->server_proc);
1704 plugin->helper_is_running = GNUNET_NO;
1710 * function for delayed restart of the helper process
1711 * @param cls Finish_send struct if message should be finished
1712 * @param tc TaskContext
1715 delay_restart_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1717 struct Finish_send *finish = cls;
1718 struct Plugin *plugin;
1720 plugin = finish->plugin;
1722 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1723 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1725 GNUNET_free_non_null (finish->msgstart);
1726 GNUNET_free (finish);
1730 wlan_transport_start_wlan_helper (plugin);
1732 if (finish->size != 0)
1734 plugin->server_write_task =
1735 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1736 plugin->server_stdin_handle,
1737 &finish_sending, finish);
1741 set_next_send (plugin);
1742 GNUNET_free_non_null (finish->msgstart);
1743 GNUNET_free (finish);
1749 * Function to restart the helper
1750 * @param plugin pointer to the global plugin struct
1751 * @param finish pointer to the Finish_send struct to finish
1754 restart_helper (struct Plugin *plugin, struct Finish_send *finish)
1756 static struct GNUNET_TIME_Relative next_try = { 1000 };
1757 GNUNET_assert (finish != NULL);
1759 wlan_transport_stop_wlan_helper (plugin);
1760 plugin->server_write_task =
1761 GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish);
1762 GNUNET_TIME_relative_multiply (next_try, HELPER_RESTART_SCALING_FACTOR);
1767 * function to finish a sending if not all could have been writen befor
1768 * @param cls pointer to the Finish_send struct
1769 * @param tc TaskContext
1772 finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1774 struct Finish_send *finish = cls;
1775 struct Plugin *plugin;
1778 plugin = finish->plugin;
1779 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1781 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1783 GNUNET_free (finish->msgstart);
1784 GNUNET_free (finish);
1788 GNUNET_DISK_file_write (plugin->server_stdin_handle,
1789 finish->head_of_next_write, finish->size);
1791 if (bytes != finish->size)
1793 if (bytes != GNUNET_SYSERR)
1795 finish->head_of_next_write += bytes;
1796 finish->size -= bytes;
1797 plugin->server_write_task =
1798 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1799 plugin->server_stdin_handle,
1800 &finish_sending, finish);
1804 restart_helper (plugin, finish);
1809 GNUNET_free (finish->msgstart);
1810 GNUNET_free (finish);
1811 set_next_send (plugin);
1816 * function to send a hello beacon
1817 * @param plugin pointer to the plugin struct
1820 send_hello_beacon (struct Plugin *plugin)
1824 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1825 "Sending hello beacon\n");
1830 uint16_t hello_size;
1831 struct GNUNET_MessageHeader *msgheader;
1832 struct ieee80211_frame *ieeewlanheader;
1833 struct Radiotap_Send *radioHeader;
1834 struct GNUNET_MessageHeader *msgheader2;
1835 const struct GNUNET_MessageHeader *hello;
1836 struct Finish_send *finish;
1838 GNUNET_assert (plugin != NULL);
1840 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"),
1843 hello = plugin->env->get_our_hello ();
1844 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1845 GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
1847 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1848 sizeof (struct ieee80211_frame) + hello_size;
1850 msgheader = GNUNET_malloc (size);
1851 msgheader->size = htons (size);
1852 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1854 radioHeader = (struct Radiotap_Send *) &msgheader[1];
1855 getRadiotapHeader (plugin, NULL, radioHeader);
1856 ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
1857 getWlanHeader (ieeewlanheader, &bc_all_mac, plugin, size);
1859 msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1];
1860 /*msgheader2->size =
1861 * htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) +
1862 * sizeof (struct GNUNET_MessageHeader));
1864 * msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); */
1865 memcpy (msgheader2, hello, hello_size);
1867 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size);
1869 if (bytes == GNUNET_SYSERR)
1871 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1873 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1874 errno, strerror (errno));
1875 finish = GNUNET_malloc (sizeof (struct Finish_send));
1876 finish->plugin = plugin;
1877 finish->head_of_next_write = NULL;
1879 finish->msgstart = NULL;
1880 restart_helper (plugin, finish);
1882 set_next_beacon_time (plugin);
1887 GNUNET_assert (bytes == size);
1888 set_next_beacon_time (plugin);
1889 set_next_send (plugin);
1891 GNUNET_free (msgheader);
1897 * function to add an ack to send it for a received fragment
1898 * @param cls MacEndpoint this ack belongs to
1899 * @param msg_id id of the message
1900 * @param hdr pointer to the hdr where the ack is stored
1905 add_ack_for_send (void *cls, uint32_t msg_id,
1906 const struct GNUNET_MessageHeader *hdr)
1909 struct AckSendQueue *ack;
1911 GNUNET_assert (cls != NULL);
1912 struct MacEndpoint *endpoint = cls;
1913 struct Plugin *plugin = endpoint->plugin;
1914 struct GNUNET_MessageHeader *msgheader;
1915 struct GNUNET_MessageHeader *msgheader2;
1919 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1920 sizeof (struct ieee80211_frame) + ntohs (hdr->size) +
1921 sizeof (struct AckSendQueue);
1923 ack = GNUNET_malloc (size);
1924 ack->message_id = msg_id;
1925 ack->endpoint = endpoint;
1928 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1929 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1931 msgheader = (struct GNUNET_MessageHeader *) &ack[1];
1932 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1];
1933 msgheader->size = htons (size);
1934 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1936 ack->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1937 ack->ieeewlanheader = (struct ieee80211_frame *) &(ack->radioHeader)[1];
1938 msgheader2 = (struct GNUNET_MessageHeader *) &(ack->ieeewlanheader)[1];
1939 memcpy (msgheader2, hdr, ntohs (hdr->size));
1941 GNUNET_CONTAINER_DLL_insert_tail (plugin->ack_send_queue_head,
1942 plugin->ack_send_queue_tail, ack);
1944 #if DEBUG_wlan_retransmission > 1
1945 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1946 "Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n",
1947 msg_id, ack, endpoint);
1950 set_next_send (plugin);
1954 * Function for the scheduler if a FragmentMessage times out
1955 * @param cls pointer to the FragmentMessage
1956 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
1959 fragmentmessage_timeout (void *cls,
1960 const struct GNUNET_SCHEDULER_TaskContext *tc)
1962 struct FragmentMessage *fm = cls;
1964 GNUNET_assert (fm != NULL);
1965 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1966 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1970 free_fragment_message (fm->session->mac->plugin, fm);
1974 * Function to check if there is some space in the fragment queue
1975 * inserts a message if space is available
1976 * @param plugin the plugin struct
1980 check_fragment_queue (struct Plugin *plugin)
1982 struct Session *session;
1983 struct FragmentMessage *fm;
1984 struct GNUNET_PeerIdentity pid;
1986 struct PendingMessage *pm;
1988 if (plugin->pending_Fragment_Messages < FRAGMENT_QUEUE_SIZE)
1990 session = get_next_queue_session (plugin);
1991 if (session != NULL)
1993 pm = session->pending_message_head;
1994 GNUNET_assert (pm != NULL);
1995 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1996 session->pending_message_tail, pm);
1997 session->mac->fragment_messages_out_count++;
1998 session->fragment_messages_out_count++;
1999 plugin->pending_Fragment_Messages++;
2000 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
2001 plugin->pending_Fragment_Messages, GNUNET_NO);
2003 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
2004 fm->session = session;
2005 fm->timeout.abs_value = pm->timeout.abs_value;
2008 GNUNET_FRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
2010 GNUNET_TIME_UNIT_SECONDS,
2012 &add_message_for_send, fm);
2014 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
2015 (fm->timeout), fragmentmessage_timeout,
2017 GNUNET_CONTAINER_DLL_insert_tail (session->mac->sending_messages_head,
2018 session->mac->sending_messages_tail,
2021 if (pm->transmit_cont != NULL)
2023 pid = session->target;
2024 pm->transmit_cont (pm->transmit_cont_cls, &pid, GNUNET_OK);
2026 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2027 "called pm->transmit_cont for %p\n", session);
2033 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2034 "no pm->transmit_cont for %p\n", session);
2039 if (session->pending_message_head != NULL)
2042 queue_session (plugin, session);
2048 //check if timeout changed
2049 set_next_send (plugin);
2053 * Function to send an ack, does not free the ack
2054 * @param plugin pointer to the plugin
2057 send_ack (struct Plugin *plugin)
2061 struct AckSendQueue *ack;
2062 struct Finish_send *finish;
2064 ack = plugin->ack_send_queue_head;
2068 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2069 "Sending ack for message_id %u for mac endpoint %p, size %u\n",
2070 ack->message_id, ack->endpoint,
2071 ntohs (ack->hdr->size) - sizeof (struct Radiotap_Send));
2074 GNUNET_assert (plugin != NULL);
2075 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1,
2078 getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader);
2079 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
2080 ntohs (ack->hdr->size));
2083 GNUNET_DISK_file_write (plugin->server_stdin_handle, ack->hdr,
2084 ntohs (ack->hdr->size));
2085 if (bytes == GNUNET_SYSERR)
2087 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2089 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
2090 errno, strerror (errno));
2091 finish = GNUNET_malloc (sizeof (struct Finish_send));
2092 finish->plugin = plugin;
2093 finish->head_of_next_write = NULL;
2095 finish->msgstart = NULL;
2096 restart_helper (plugin, finish);
2100 GNUNET_assert (bytes == ntohs (ack->hdr->size));
2101 GNUNET_CONTAINER_DLL_remove (plugin->ack_send_queue_head,
2102 plugin->ack_send_queue_tail, ack);
2104 set_next_send (plugin);
2109 * Function called when wlan helper is ready to get some data
2111 * @param cls closure
2112 * @param tc GNUNET_SCHEDULER_TaskContext
2115 do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2117 struct Plugin *plugin = cls;
2119 GNUNET_assert (plugin != NULL);
2121 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2122 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2125 struct Session *session;
2126 struct FragmentMessage *fm;
2127 struct Finish_send *finish;
2128 struct FragmentMessage_queue *fmq;
2131 if (plugin->ack_send_queue_head != NULL)
2137 //test if a "hello-beacon" has to be send
2138 if (GNUNET_TIME_absolute_get_remaining (plugin->beacon_time).rel_value == 0)
2140 send_hello_beacon (plugin);
2144 if (plugin->sending_messages_head != NULL)
2146 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1,
2149 fmq = plugin->sending_messages_head;
2151 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
2152 plugin->sending_messages_tail, fmq);
2155 session = fm->session;
2156 GNUNET_assert (session != NULL);
2159 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2160 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p, size: %u\n",
2164 getRadiotapHeader (plugin, session->mac, fm->radioHeader);
2165 getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
2169 GNUNET_DISK_file_write (plugin->server_stdin_handle, fm->frag,
2173 if (bytes != fm->size)
2175 finish = GNUNET_malloc (sizeof (struct Finish_send));
2176 finish->plugin = plugin;
2177 finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag;
2178 GNUNET_assert (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
2180 if (bytes == GNUNET_SYSERR)
2182 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2184 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
2185 errno, strerror (errno));
2187 finish->head_of_next_write = fm->frag;
2188 finish->size = fm->size;
2189 restart_helper (plugin, finish);
2193 finish->head_of_next_write = fm->frag + bytes;
2194 finish->size = fm->size - bytes;
2195 plugin->server_write_task =
2196 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
2197 plugin->server_stdin_handle,
2198 &finish_sending, finish);
2205 GNUNET_free (fm->frag);
2207 set_next_send (plugin);
2209 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
2214 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2215 "do_transmit did nothing, should not happen!\n");
2217 set_next_send (plugin);
2221 * Another peer has suggested an address for this
2222 * peer and transport plugin. Check that this could be a valid
2223 * address. If so, consider adding it to the list
2226 * @param cls closure
2227 * @param addr pointer to the address
2228 * @param addrlen length of addr
2229 * @return GNUNET_OK if this is a plausible address for this peer
2233 wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
2235 //struct Plugin *plugin = cls;
2237 /* check if the address is plausible; if so,
2238 * add it to our list! */
2240 GNUNET_assert (cls != NULL);
2241 //FIXME mitm is not checked
2242 //Mac Address has 6 bytes
2245 /* TODO check for bad addresses like multicast, broadcast, etc */
2247 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2248 "wlan_plugin_address_suggested got good address, size %u!\n",
2254 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2255 "wlan_plugin_address_suggested got bad address, size %u!\n",
2258 return GNUNET_SYSERR;
2262 * Function that can be used by the transport service to transmit
2263 * a message using the plugin.
2265 * @param cls closure
2266 * @param target who should receive this message
2267 * @param priority how important is the message
2268 * @param msgbuf the message to transmit
2269 * @param msgbuf_size number of bytes in 'msgbuf'
2270 * @param timeout when should we time out
2271 * @param session which session must be used (or NULL for "any")
2272 * @param addr the address to use (can be NULL if the plugin
2273 * is "on its own" (i.e. re-use existing TCP connection))
2274 * @param addrlen length of the address in bytes
2275 * @param force_address GNUNET_YES if the plugin MUST use the given address,
2276 * otherwise the plugin may use other addresses or
2277 * existing connections (if available)
2278 * @param cont continuation to call once the message has
2279 * been transmitted (or if the transport is ready
2280 * for the next transmission call; or if the
2281 * peer disconnected...)
2282 * @param cont_cls closure for cont
2283 * @return number of bytes used (on the physical network, with overheads);
2284 * -1 on hard errors (i.e. address invalid); 0 is a legal value
2285 * and does NOT mean that the message was not transmitted (DV)
2288 wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
2289 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
2290 struct GNUNET_TIME_Relative timeout, struct Session *session,
2291 const void *addr, size_t addrlen, int force_address,
2292 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
2294 struct Plugin *plugin = cls;
2295 struct PendingMessage *newmsg;
2296 struct WlanHeader *wlanheader;
2298 GNUNET_assert (plugin != NULL);
2299 //check if msglen > 0
2300 GNUNET_assert (msgbuf_size > 0);
2302 //get session if needed
2303 if (session == NULL)
2305 if (wlan_plugin_address_suggested (plugin, addr, addrlen) == GNUNET_OK)
2307 session = get_session (plugin, addr, target);
2311 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2312 _("Wlan Address len %d is wrong\n"), addrlen);
2317 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1,
2322 //queue message in session
2323 //test if there is no other message in the "queue"
2324 //FIXME: to many send requests
2325 if (session->pending_message_head != NULL)
2327 newmsg = session->pending_message_head;
2328 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2329 "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",
2330 GNUNET_TIME_absolute_get_remaining (newmsg->
2332 session->mac->fragment_messages_out_count);
2335 newmsg = GNUNET_malloc (sizeof (struct PendingMessage));
2336 newmsg->msg = GNUNET_malloc (msgbuf_size + sizeof (struct WlanHeader));
2337 wlanheader = newmsg->msg;
2338 //copy msg to buffer, not fragmented / segmented yet, but with message header
2339 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
2340 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
2341 memcpy (&(wlanheader->target), target, sizeof (struct GNUNET_PeerIdentity));
2342 memcpy (&(wlanheader->source), plugin->env->my_identity,
2343 sizeof (struct GNUNET_PeerIdentity));
2344 wlanheader->crc = 0;
2345 memcpy (&wlanheader[1], msgbuf, msgbuf_size);
2348 ((char *) wlanheader, msgbuf_size + sizeof (struct WlanHeader)));
2349 //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);
2350 //hexdump(newmsg->msg, msgbuf_size + sizeof(struct WlanHeader));
2352 newmsg->transmit_cont = cont;
2353 newmsg->transmit_cont_cls = cont_cls;
2354 newmsg->timeout = GNUNET_TIME_relative_to_absolute (timeout);
2356 newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
2358 newmsg->message_size = msgbuf_size + sizeof (struct WlanHeader);
2360 GNUNET_CONTAINER_DLL_insert_tail (session->pending_message_head,
2361 session->pending_message_tail, newmsg);
2364 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2365 "New message for %p with size (incl wlan header) %u added\n",
2366 session, newmsg->message_size);
2368 #if DEBUG_wlan_msg_dump > 1
2369 hexdump (msgbuf, GNUNET_MIN (msgbuf_size, 256));
2372 queue_session (plugin, session);
2374 check_fragment_queue (plugin);
2375 //FIXME not the correct size
2381 * function to free a mac endpoint
2382 * @param plugin pointer to the plugin struct
2383 * @param endpoint pointer to the MacEndpoint to free
2386 free_macendpoint (struct Plugin *plugin, struct MacEndpoint *endpoint)
2388 struct Sessionqueue *sessions;
2389 struct Sessionqueue *sessions_next;
2391 GNUNET_assert (endpoint != NULL);
2393 sessions = endpoint->sessions_head;
2394 while (sessions != NULL)
2396 sessions_next = sessions->next;
2397 free_session (plugin, sessions, GNUNET_NO);
2398 sessions = sessions_next;
2401 GNUNET_CONTAINER_DLL_remove (plugin->mac_head, plugin->mac_tail, endpoint);
2402 if (endpoint->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2404 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
2405 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2407 plugin->mac_count--;
2408 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
2409 plugin->mac_count, GNUNET_NO);
2410 GNUNET_free (endpoint);
2415 * function to free a session
2416 * @param plugin pointer to the plugin
2417 * @param queue pointer to the sessionqueue element to free
2418 * @param free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint
2421 free_session (struct Plugin *plugin, struct Sessionqueue *queue,
2422 int do_free_macendpoint)
2424 struct Sessionqueue *pendingsession;
2425 struct Sessionqueue *pendingsession_tmp;
2426 struct PendingMessage *pm;
2427 struct MacEndpoint *endpoint;
2428 struct FragmentMessage *fm;
2429 struct FragmentMessage *fmnext;
2432 GNUNET_assert (plugin != NULL);
2433 GNUNET_assert (queue != NULL);
2434 GNUNET_assert (queue->content != NULL);
2437 //is this session pending for send
2438 pendingsession = plugin->pending_Sessions_head;
2439 while (pendingsession != NULL)
2441 pendingsession_tmp = pendingsession;
2442 pendingsession = pendingsession->next;
2443 GNUNET_assert (pendingsession_tmp->content != NULL);
2444 if (pendingsession_tmp->content == queue->content)
2446 plugin->pendingsessions--;
2447 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
2448 plugin->pendingsessions, GNUNET_NO);
2449 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
2450 plugin->pending_Sessions_tail,
2451 pendingsession_tmp);
2452 GNUNET_free (pendingsession_tmp);
2454 GNUNET_assert (check == 0);
2459 endpoint = queue->content->mac;
2460 fm = endpoint->sending_messages_head;
2464 if (fm->session == queue->content)
2466 free_fragment_message (plugin, fm);
2471 // remove PendingMessage
2472 pm = queue->content->pending_message_head;
2475 GNUNET_CONTAINER_DLL_remove (queue->content->pending_message_head,
2476 queue->content->pending_message_tail, pm);
2477 GNUNET_free (pm->msg);
2479 pm = queue->content->pending_message_head;
2482 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, endpoint->sessions_tail,
2484 //Check that no ohter session on this endpoint for this session exits
2485 GNUNET_assert (search_session (plugin, endpoint, &queue->content->target) ==
2487 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
2489 free_macendpoint (plugin, endpoint);
2490 //check if no endpoint with the same address exists
2491 GNUNET_assert (get_macendpoint (plugin, &endpoint->addr, GNUNET_NO) ==
2495 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2497 GNUNET_SCHEDULER_cancel (queue->content->timeout_task);
2498 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2500 GNUNET_free (queue);
2502 check_fragment_queue (plugin);
2506 * Function that can be used to force the plugin to disconnect
2507 * from the given peer and cancel all previous transmissions
2508 * (and their continuation).
2510 * @param cls closure
2511 * @param target peer from which to disconnect
2514 wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2516 struct Plugin *plugin = cls;
2517 struct Sessionqueue *queue;
2518 struct Sessionqueue *queue_next;
2519 struct MacEndpoint *endpoint = plugin->mac_head;
2520 struct MacEndpoint *endpoint_next;
2522 // just look at all the session for the needed one
2523 while (endpoint != NULL)
2525 queue = endpoint->sessions_head;
2526 endpoint_next = endpoint->next;
2527 while (queue != NULL)
2529 // content is never NULL
2530 GNUNET_assert (queue->content != NULL);
2531 queue_next = queue->next;
2533 (target, &(queue->content->target),
2534 sizeof (struct GNUNET_PeerIdentity)) == 0)
2536 free_session (plugin, queue, GNUNET_YES);
2541 endpoint = endpoint_next;
2546 * Convert the transports address to a nice, human-readable
2549 * @param cls closure
2550 * @param type name of the transport that generated the address
2551 * @param addr one of the addresses of the host, NULL for the last address
2552 * the specific address format depends on the transport
2553 * @param addrlen length of the address
2554 * @param numeric should (IP) addresses be displayed in numeric form?
2555 * @param timeout after how long should we give up?
2556 * @param asc function to call on each string
2557 * @param asc_cls closure for asc
2560 wlan_plugin_address_pretty_printer (void *cls, const char *type,
2561 const void *addr, size_t addrlen,
2563 struct GNUNET_TIME_Relative timeout,
2564 GNUNET_TRANSPORT_AddressStringCallback asc,
2568 const unsigned char *input;
2570 //GNUNET_assert(cls !=NULL);
2571 if (addrlen != sizeof (struct MacAddress))
2573 /* invalid address (MAC addresses have 6 bytes) */
2576 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2577 "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n",
2580 asc (asc_cls, NULL);
2583 input = (const unsigned char *) addr;
2584 GNUNET_asprintf (&ret,
2585 "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
2586 type, PROTOCOL_PREFIX, input[0], input[1], input[2],
2587 input[3], input[4], input[5]);
2589 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2590 "Func wlan_plugin_address_pretty_printer got size: %u, nummeric %u, type %s; made string: %s\n",
2591 addrlen, numeric, type, ret);
2594 //only one mac address per plugin
2595 asc (asc_cls, NULL);
2601 * handels the data after all fragments are put together
2602 * @param cls macendpoint this messages belongs to
2603 * @param hdr pointer to the data
2606 wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2608 struct MacEndpoint *endpoint = (struct MacEndpoint *) cls;
2609 struct Plugin *plugin = endpoint->plugin;
2610 struct WlanHeader *wlanheader;
2611 struct Session *session;
2613 const struct GNUNET_MessageHeader *temp_hdr;
2614 struct GNUNET_PeerIdentity tmpsource;
2617 GNUNET_assert (plugin != NULL);
2619 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
2623 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2624 "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
2628 if (ntohs (hdr->size) <
2629 sizeof (struct WlanHeader) + sizeof (struct GNUNET_MessageHeader))
2631 //packet not big enought
2635 GNUNET_STATISTICS_update (plugin->env->stats,
2636 _("# wlan whole messages received"), 1,
2638 wlanheader = (struct WlanHeader *) hdr;
2640 session = search_session (plugin, endpoint, &wlanheader->source);
2642 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
2643 crc = ntohl (wlanheader->crc);
2644 wlanheader->crc = 0;
2645 if (getcrc32 ((char *) wlanheader, ntohs (wlanheader->header.size)) != crc)
2647 //wrong crc, dispose message
2648 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2649 "Wlan message header crc was wrong: %u != %u\n",
2650 getcrc32 ((char *) wlanheader,
2651 ntohs (wlanheader->header.size)), crc);
2652 hexdump ((void *) hdr, ntohs (hdr->size));
2656 //if not in session list
2657 if (session == NULL)
2660 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2661 "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n",
2662 ntohs (wlanheader->header.size), ntohs (temp_hdr->size),
2663 sizeof (struct WlanHeader));
2665 //try if it is a hello message
2666 if (ntohs (wlanheader->header.size) >=
2667 ntohs (temp_hdr->size) + sizeof (struct WlanHeader))
2669 if (ntohs (temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2671 if (GNUNET_HELLO_get_id
2672 ((const struct GNUNET_HELLO_Message *) temp_hdr,
2673 &tmpsource) == GNUNET_OK)
2675 session = create_session (plugin, endpoint, &tmpsource);
2679 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2680 "WLAN client not in session list and hello message is not okay\n");
2687 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2688 "WLAN client not in session list and not a hello message\n");
2694 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2695 "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n",
2696 ntohs (wlanheader->header.size),
2697 ntohs (temp_hdr->size), sizeof (struct WlanHeader));
2702 //"receive" the message
2705 (&wlanheader->source, &session->target,
2706 sizeof (struct GNUNET_PeerIdentity)) != 0)
2710 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2711 "WLAN peer source id doesn't match packet peer source id: session %p\n",
2718 (&wlanheader->target, plugin->env->my_identity,
2719 sizeof (struct GNUNET_PeerIdentity)) != 0)
2723 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2724 "WLAN peer target id doesn't match our peer id: session %p\n",
2730 GNUNET_SERVER_mst_receive (plugin->data_tokenizer, session,
2731 (const char *) temp_hdr,
2732 ntohs (hdr->size) - sizeof (struct WlanHeader),
2733 GNUNET_YES, GNUNET_NO);
2739 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2740 "wlan_data_message_handler got wrong message type: %u\n",
2747 * function to process the a message, give it to the higher layer
2748 * @param cls pointer to the plugin
2749 * @param client pointer to the session this message belongs to
2750 * @param hdr start of the message
2752 //TODO ATS informations
2754 process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2757 GNUNET_assert (client != NULL);
2758 GNUNET_assert (cls != NULL);
2759 struct Session *session = (struct Session *) client;
2760 struct Plugin *plugin = (struct Plugin *) cls;
2762 struct GNUNET_ATS_Information distance;
2764 distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
2765 distance.value = htonl (1);
2768 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2769 "Calling plugin->env->receive for session %p; %s; size: %u\n",
2770 session, wlan_plugin_address_to_string (NULL,
2776 plugin->env->receive (plugin->env->cls, &(session->target), hdr,
2777 (const struct GNUNET_ATS_Information *) &distance, 1,
2778 session, (const char *) &session->mac->addr,
2779 sizeof (session->mac->addr));
2783 * Function used for to process the data received from the wlan interface
2785 * @param cls the plugin handle
2786 * @param session_light pointer to the struct holding known informations
2787 * @param hdr hdr of the GNUNET_MessageHeader
2788 * @param rxinfo pointer to the radiotap informations got with this packet FIXME: give ATS for info
2791 wlan_data_helper (void *cls, struct Session_light *session_light,
2792 const struct GNUNET_MessageHeader *hdr,
2793 const struct Radiotap_rx *rxinfo)
2795 struct Plugin *plugin = cls;
2796 struct FragmentMessage *fm;
2797 struct FragmentMessage *fm2;
2798 struct GNUNET_PeerIdentity tmpsource;
2800 GNUNET_assert (plugin != NULL);
2803 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2806 //TODO better DOS protection, error handling
2807 //TODO test first than create session
2808 GNUNET_assert (session_light != NULL);
2811 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2812 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_HELLO size: %u; %s\n",
2813 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2814 session_light->addr.
2818 if (session_light->macendpoint == NULL)
2820 session_light->macendpoint =
2821 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2825 if (GNUNET_HELLO_get_id
2826 ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource) == GNUNET_OK)
2828 session_light->session =
2829 search_session (plugin, session_light->macendpoint, &tmpsource);
2830 if (session_light->session == NULL)
2832 session_light->session =
2833 create_session (plugin, session_light->macendpoint, &tmpsource);
2835 GNUNET_STATISTICS_update (plugin->env->stats,
2836 _("# wlan hello messages received"), 1,
2838 plugin->env->receive (plugin->env->cls, &session_light->session->target,
2839 hdr, NULL, 0, session_light->session,
2840 (const char *) &session_light->session->mac->addr,
2841 sizeof (session_light->session->mac->addr));
2845 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2846 "WLAN client not in session list and hello message is not okay\n");
2853 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT)
2856 GNUNET_assert (session_light != NULL);
2857 if (session_light->macendpoint == NULL)
2859 session_light->macendpoint =
2860 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2864 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2865 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size: %u; mac endpoint %p: %s\n",
2866 ntohs (hdr->size), session_light->macendpoint,
2867 wlan_plugin_address_to_string (NULL,
2868 session_light->addr.mac,
2872 GNUNET_STATISTICS_update (plugin->env->stats,
2873 _("# wlan fragments received"), 1, GNUNET_NO);
2875 GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag,
2878 if (ret == GNUNET_NO)
2880 session_light->macendpoint->dups++;
2882 else if (ret == GNUNET_OK)
2884 session_light->macendpoint->fragc++;
2886 set_next_send (plugin);
2892 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK)
2894 GNUNET_assert (session_light != NULL);
2895 if (session_light->macendpoint == NULL)
2897 session_light->macendpoint =
2898 get_macendpoint (plugin, &session_light->addr, GNUNET_NO);
2901 if (session_light->macendpoint == NULL)
2904 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2905 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n",
2906 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2907 session_light->addr.mac,
2914 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2915 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n",
2916 ntohs (hdr->size), session_light->macendpoint,
2917 wlan_plugin_address_to_string (NULL,
2918 session_light->addr.mac,
2921 fm = session_light->macendpoint->sending_messages_head;
2925 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"),
2927 int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
2929 if (ret == GNUNET_OK)
2931 #if DEBUG_wlan_retransmission > 1
2932 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2933 "Got last ack, finished fragment message %p\n", fm);
2935 session_light->macendpoint->acks++;
2936 fm->session->last_activity = GNUNET_TIME_absolute_get ();
2937 session_light->macendpoint->last_activity = fm->session->last_activity;
2938 free_fragment_message (plugin, fm);
2939 check_fragment_queue (plugin);
2942 if (ret == GNUNET_NO)
2944 #if DEBUG_wlan_retransmission > 1
2945 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2946 "Got ack for: %p\n", fm);
2948 session_light->macendpoint->acks++;
2951 if (ret == GNUNET_SYSERR)
2959 #if DEBUG_wlan_retransmission > 1
2960 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2961 "WLAN fragment not in fragment list\n");
2969 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2970 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n",
2971 ntohs (hdr->type), ntohs (hdr->size));
2977 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2978 "Helper finished\n");
2984 * Function to print mac addresses nice *
2985 * @param pointer to 6 byte with the mac address
2986 * @return pointer to the chars which hold the print out
2989 macprinter (const u_int8_t * mac)
2991 static char macstr[20];
2993 GNUNET_snprintf (macstr, sizeof (macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1],
2994 mac[2], mac[3], mac[4], mac[5]);
2999 * Function for the scheduler if a mac endpoint times out
3000 * @param cls pointer to the MacEndpoint
3001 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
3004 macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3006 struct MacEndpoint *endpoint = cls;
3008 GNUNET_assert (endpoint != NULL);
3009 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
3010 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
3014 if (GNUNET_TIME_absolute_get_remaining
3015 (GNUNET_TIME_absolute_add
3016 (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0)
3018 GNUNET_assert (endpoint->plugin != NULL);
3019 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
3020 _("# wlan mac endpoints timeouts"), 1, GNUNET_NO);
3021 free_macendpoint (endpoint->plugin, endpoint);
3025 endpoint->timeout_task =
3026 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
3032 * function to create an macendpoint
3033 * @param plugin pointer to the plugin struct
3034 * @param addr pointer to the macaddress
3035 * @return returns a macendpoint
3037 static struct MacEndpoint *
3038 create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
3040 struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
3042 GNUNET_assert (plugin != NULL);
3043 GNUNET_STATISTICS_update (plugin->env->stats,
3044 _("# wlan mac endpoints created"), 1, GNUNET_NO);
3045 newend->addr = *addr;
3046 newend->plugin = plugin;
3047 newend->addr = *addr;
3048 newend->fragment_messages_out_count = 0;
3050 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
3051 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
3052 newend, &wlan_data_message_handler,
3054 newend->last_activity = GNUNET_TIME_absolute_get ();
3055 newend->timeout_task =
3056 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
3059 plugin->mac_count++;
3060 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
3061 plugin->mac_count, GNUNET_NO);
3062 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
3064 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3065 "New Mac Endpoint %p: %s\n", newend,
3066 wlan_plugin_address_to_string (NULL, newend->addr.mac, 6));
3072 * Function used for to process the data from the suid process
3074 * @param cls the plugin handle
3075 * @param client client that send the data (not used)
3076 * @param hdr header of the GNUNET_MessageHeader
3079 wlan_process_helper (void *cls, void *client,
3080 const struct GNUNET_MessageHeader *hdr)
3082 struct Plugin *plugin = cls;
3083 struct ieee80211_frame *wlanIeeeHeader = NULL;
3084 struct Session_light *session_light = NULL;
3085 struct Radiotap_rx *rxinfo;
3086 const struct GNUNET_MessageHeader *temp_hdr = NULL;
3091 GNUNET_assert (plugin != NULL);
3092 switch (ntohs (hdr->type))
3094 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
3096 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3097 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
3101 GNUNET_STATISTICS_update (plugin->env->stats,
3102 _("# wlan WLAN_HELPER_DATA received"), 1,
3104 //call wlan_process_helper with the message inside, later with wlan: analyze signal
3105 if (ntohs (hdr->size) <
3106 sizeof (struct ieee80211_frame) +
3107 2 * sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx))
3110 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3111 "Size of packet is too small; size: %u min size: %u\n",
3113 sizeof (struct ieee80211_frame) +
3114 sizeof (struct GNUNET_MessageHeader));
3117 /* FIXME: restart SUID process */
3121 rxinfo = (struct Radiotap_rx *) &hdr[1];
3122 wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1];
3124 //process only if it is an broadcast or for this computer both with the gnunet bssid
3128 (&(wlanIeeeHeader->i_addr3), &mac_bssid,
3129 sizeof (struct MacAddress)) == 0)
3131 //check for broadcast or mac
3133 (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
3134 sizeof (struct MacAddress)) == 0) ||
3136 (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
3137 sizeof (struct MacAddress)) == 0))
3139 //if packet is from us return
3141 (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address),
3142 sizeof (struct MacAddress)) == 0))
3146 // process the inner data
3150 ntohs (hdr->size) - sizeof (struct ieee80211_frame) -
3151 sizeof (struct GNUNET_MessageHeader) - sizeof (struct Radiotap_rx);
3153 session_light = GNUNET_malloc (sizeof (struct Session_light));
3154 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
3155 sizeof (struct MacAddress));
3156 //session_light->session = search_session(plugin,session_light->addr);
3157 GNUNET_STATISTICS_update (plugin->env->stats,
3158 _("# wlan messages for this client received"),
3162 while (pos < datasize)
3164 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
3165 if (ntohs (temp_hdr->size) <= datasize + pos)
3167 GNUNET_STATISTICS_update (plugin->env->stats,
3169 ("# wlan messages inside WLAN_HELPER_DATA received"),
3171 wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
3176 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3177 "Size of packet is too small; size: %u > size of packet: %u\n",
3178 ntohs (temp_hdr->size), datasize + pos);
3181 pos += ntohs (temp_hdr->size);
3186 GNUNET_free (session_light);
3191 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3192 "Func wlan_process_helper got wrong MAC: %s\n",
3193 macprinter (wlanIeeeHeader->i_addr1));
3200 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3201 "Func wlan_process_helper got wrong BSSID: %s\n",
3202 macprinter (wlanIeeeHeader->i_addr2));
3206 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
3207 //TODO more control messages
3208 if (ntohs (hdr->size) != sizeof (struct Wlan_Helper_Control_Message))
3211 /* FIXME: restart SUID process */
3214 memcpy (&plugin->mac_address, &hdr[1], sizeof (struct MacAddress));
3216 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3217 "Received WLAN_HELPER_CONTROL message with transport of address %s\n",
3218 wlan_plugin_address_to_string (cls, &plugin->mac_address,
3222 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
3223 &plugin->mac_address,
3224 sizeof (struct MacAddress));
3228 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3229 "Func wlan_process_helper got unknown message with number %u, size %u\n",
3230 ntohs (hdr->type), ntohs (hdr->size));
3233 #if DEBUG_wlan_msg_dump > 1
3234 hexdump (hdr, GNUNET_MIN (ntohs (hdr->size), 256));
3242 * Exit point from the plugin.
3243 * @param cls pointer to the api struct
3248 libgnunet_plugin_transport_wlan_done (void *cls)
3250 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3251 struct Plugin *plugin = api->cls;
3252 struct MacEndpoint *endpoint = plugin->mac_head;
3253 struct MacEndpoint *endpoint_next;
3256 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3257 "libgnunet_plugin_transport_wlan_done started\n");
3260 wlan_transport_stop_wlan_helper (plugin);
3262 GNUNET_assert (cls != NULL);
3264 while (endpoint != NULL)
3266 endpoint_next = endpoint->next;
3267 free_macendpoint (plugin, endpoint);
3268 endpoint = endpoint_next;
3273 if (plugin->suid_tokenizer != NULL)
3274 GNUNET_SERVER_mst_destroy (plugin->suid_tokenizer);
3276 if (plugin->data_tokenizer != NULL)
3277 GNUNET_SERVER_mst_destroy (plugin->data_tokenizer);
3279 GNUNET_free_non_null (plugin->interface);
3280 GNUNET_free (plugin);
3286 * Entry point for the plugin.
3288 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
3289 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
3292 libgnunet_plugin_transport_wlan_init (void *cls)
3294 //struct GNUNET_SERVICE_Context *service;
3295 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3296 struct GNUNET_TRANSPORT_PluginFunctions *api;
3297 struct Plugin *plugin;
3299 GNUNET_assert (cls != NULL);
3301 plugin = GNUNET_malloc (sizeof (struct Plugin));
3303 plugin->pendingsessions = 0;
3304 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
3305 plugin->pendingsessions, GNUNET_NO);
3306 plugin->mac_count = 0;
3307 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
3308 plugin->mac_count, GNUNET_NO);
3309 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
3310 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
3311 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
3312 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
3313 GNUNET_BANDWIDTH_value_init (100 * 1024 *
3316 plugin->suid_tokenizer =
3317 GNUNET_SERVER_mst_create (&wlan_process_helper, plugin);
3319 plugin->data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
3321 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
3322 //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue));
3324 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
3326 api->send = &wlan_plugin_send;
3327 api->disconnect = &wlan_plugin_disconnect;
3328 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
3329 api->check_address = &wlan_plugin_address_suggested;
3330 api->address_to_string = &wlan_plugin_address_to_string;
3334 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE"))
3336 if (GNUNET_SYSERR ==
3337 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
3338 "TESTMODE", &(plugin->testmode)))
3339 plugin->testmode = 0; //default value
3342 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE"))
3344 if (GNUNET_CONFIGURATION_get_value_string
3345 (env->cfg, "transport-wlan", "INTERFACE",
3346 &(plugin->interface)) != GNUNET_YES)
3348 libgnunet_plugin_transport_wlan_done (api);
3354 wlan_transport_start_wlan_helper (plugin);
3355 set_next_beacon_time (plugin);
3356 set_next_send (plugin);
3358 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3359 "wlan init finished\n");
3365 /* end of plugin_transport_wlan.c */