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"
45 #define DEBUG_WLAN GNUNET_EXTRA_LOGGING
48 #define PROTOCOL_PREFIX "wlan"
50 #define PLUGIN_LOG_NAME "wlan-plugin"
58 * time out of a session
60 #define SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
63 * time out of a mac endpoint
65 #define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2)
68 * scaling factor for hello beacon
70 #define HELLO_BEACON_SCALING_FACTOR 30
73 * scaling factor for restarting the helper
75 #define HELPER_RESTART_SCALING_FACTOR 2
78 * max size of fragment queue
80 #define FRAGMENT_QUEUE_SIZE 10
82 * max messages in fragment queue per session/client
84 #define FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION 1
87 * max messages in fragment queue per MAC
89 #define FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT 1
92 * max messages in in queue
94 #define MESSAGES_IN_QUEUE_SIZE 10
96 * max messages in in queue per session/client
98 #define MESSAGES_IN_DEFRAG_QUEUE_PER_MAC 1
101 * LLC fields for better compatibility
103 #define WLAN_LLC_DSAP_FIELD 0x1f
104 #define WLAN_LLC_SSAP_FIELD 0x1f
107 #define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
109 #define IEEE80211_FC0_VERSION_MASK 0x03
110 #define IEEE80211_FC0_VERSION_SHIFT 0
111 #define IEEE80211_FC0_VERSION_0 0x00
112 #define IEEE80211_FC0_TYPE_MASK 0x0c
113 #define IEEE80211_FC0_TYPE_SHIFT 2
114 #define IEEE80211_FC0_TYPE_MGT 0x00
115 #define IEEE80211_FC0_TYPE_CTL 0x04
116 #define IEEE80211_FC0_TYPE_DATA 0x08
118 GNUNET_NETWORK_STRUCT_BEGIN
121 * generic definitions for IEEE 802.11 frames
123 struct ieee80211_frame
127 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
128 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
129 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
133 GNUNET_NETWORK_STRUCT_END
136 * Encapsulation of all of the state of the plugin.
143 struct GNUNET_TRANSPORT_PluginEnvironment *env;
146 * List of open connections. head
148 struct MacEndpoint *mac_head;
151 * List of open connections. tail
153 struct MacEndpoint *mac_tail;
156 * Number of connections
158 unsigned int mac_count;
161 * encapsulation of data from the local wlan helper program
163 struct GNUNET_SERVER_MessageStreamTokenizer *suid_tokenizer;
166 * encapsulation of packets received from the wlan helper
168 struct GNUNET_SERVER_MessageStreamTokenizer *data_tokenizer;
171 * stdout pipe handle for the gnunet-helper-transport-wlan process
173 struct GNUNET_DISK_PipeHandle *server_stdout;
176 * stdout file handle for the gnunet-helper-transport-wlan process
178 const struct GNUNET_DISK_FileHandle *server_stdout_handle;
181 * stdin pipe handle for the gnunet-helper-transport-wlan process
183 struct GNUNET_DISK_PipeHandle *server_stdin;
186 * stdin file handle for the gnunet-helper-transport-wlan process
188 const struct GNUNET_DISK_FileHandle *server_stdin_handle;
191 * ID of the gnunet-wlan-server std read task
193 GNUNET_SCHEDULER_TaskIdentifier server_read_task;
196 * ID of the gnunet-wlan-server std read task
198 GNUNET_SCHEDULER_TaskIdentifier server_write_task;
201 * ID of the delay task for writing
203 GNUNET_SCHEDULER_TaskIdentifier server_write_delay_task;
206 * The process id of the wlan process
208 struct GNUNET_OS_Process *server_proc;
211 * The interface of the wlan card given to us by the user.
216 * Mode of operation for the helper, 0 = normal, 1 = first loopback, 2 = second loopback
218 long long unsigned int testmode;
221 * The mac_address of the wlan card given to us by the helper.
223 struct GNUNET_TRANSPORT_WLAN_MacAddress mac_address;
226 * Sessions currently pending for transmission
229 struct Sessionqueue *pending_Sessions_head;
232 * Sessions currently pending for transmission
233 * to a peer (tail), if any.
235 struct Sessionqueue *pending_Sessions_tail;
238 * number of pending sessions
240 unsigned int pendingsessions;
243 * Messages in the sending queues
245 int pending_Fragment_Messages;
248 * messages ready for send, head
250 struct FragmentMessage_queue *sending_messages_head;
252 * messages ready for send, tail
254 struct FragmentMessage_queue *sending_messages_tail;
256 * time of the next "hello-beacon"
258 struct GNUNET_TIME_Absolute beacon_time;
261 * queue to send acks for received fragments (head)
263 struct AckSendQueue *ack_send_queue_head;
266 * queue to send acks for received fragments (tail)
268 struct AckSendQueue *ack_send_queue_tail;
271 * Tracker for bandwidth limit
273 struct GNUNET_BANDWIDTH_Tracker tracker;
276 * saves the current state of the helper process
278 int helper_is_running;
282 * Struct to store data if file write did not accept the whole packet
287 * pointer to the global plugin struct
289 struct Plugin *plugin;
292 * head of the next part to send to the helper
294 char *head_of_next_write;
297 * Start of the message to send, needed for free
299 struct GNUNET_MessageHeader *msgstart;
308 * Queue of sessions, for the general session queue and the pending session queue
313 struct Sessionqueue *next;
314 struct Sessionqueue *prev;
315 struct Session *content;
316 #if !HAVE_UNALIGNED_64_ACCESS
317 void *dummy; /* for alignment, see #1909 */
322 * Queue of fragmented messages, for the sending queue of the plugin
325 struct FragmentMessage_queue
327 struct FragmentMessage_queue *next;
328 struct FragmentMessage_queue *prev;
329 struct FragmentMessage *content;
333 * Queue for the fragments received
336 struct Receive_Fragment_Queue
338 struct Receive_Fragment_Queue *next;
339 struct Receive_Fragment_Queue *prev;
343 struct Radiotap_rx rxinfo;
347 struct MacEndpoint_id_fragment_triple
349 struct MacEndpoint *endpoint;
351 struct FragmentMessage *fm;
355 struct Plugin_Session_pair
357 struct Plugin *plugin;
358 struct Session *session;
362 GNUNET_NETWORK_STRUCT_BEGIN
365 * Header for messages which need fragmentation
370 struct GNUNET_MessageHeader header;
373 * checksum/error correction
375 uint32_t crc GNUNET_PACKED;
378 * To whom are we talking to (set to our identity
379 * if we are still waiting for the welcome message)
381 struct GNUNET_PeerIdentity target;
384 * Where the packet came from
386 struct GNUNET_PeerIdentity source;
388 // followed by payload
391 GNUNET_NETWORK_STRUCT_END
394 * Information kept for each message that is yet to
397 struct PendingMessage
402 struct PendingMessage *next;
406 struct PendingMessage *prev;
409 * The pending message
411 struct WlanHeader *msg;
414 * Size of the message
419 * Continuation function to call once the message
420 * has been sent. Can be NULL if there is no
421 * continuation to call.
423 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
426 * Cls for transmit_cont
428 void *transmit_cont_cls;
431 * Timeout value for the pending message.
433 struct GNUNET_TIME_Absolute timeout;
438 * Queue for acks to send for fragments recived
444 * next ack in the ack send queue
446 struct AckSendQueue *next;
448 * previous ack in the ack send queue
450 struct AckSendQueue *prev;
452 * pointer to the session this ack belongs to
454 struct MacEndpoint *endpoint;
456 * ID of message, to distinguish between the messages, picked randomly.
463 struct GNUNET_MessageHeader *hdr;
465 * pointer to the ieee wlan header
467 struct ieee80211_frame *ieeewlanheader;
469 * pointer to the radiotap header
471 struct Radiotap_Send *radioHeader;
475 * Session infos gathered from a messages
480 * the session this message belongs to
482 struct Session *session;
486 struct GNUNET_TRANSPORT_WLAN_MacAddress addr;
491 struct MacEndpoint *macendpoint;
495 * Session handle for connections.
503 struct SessionHeader header;
506 * Message currently pending for transmission
507 * to this peer, if any. head
509 struct PendingMessage *pending_message_head;
512 * Message currently pending for transmission
513 * to this peer, if any. tail
515 struct PendingMessage *pending_message_tail;
518 * To whom are we talking to (set to our identity
519 * if we are still waiting for the welcome message)
521 struct GNUNET_PeerIdentity target;
524 * Address of the other peer (either based on our 'connect'
525 * call or on our 'accept' call).
530 * Last activity on this connection. Used to select preferred
531 * connection and timeout
533 struct GNUNET_TIME_Absolute last_activity;
538 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
543 struct MacEndpoint *mac;
546 * count of messages in the fragment out queue for this session
549 int fragment_messages_out_count;
554 * Struct to represent one network card connection
559 * Pointer to the global plugin struct.
561 struct Plugin *plugin;
563 * Struct to hold the session reachable over this mac; head
565 struct Sessionqueue *sessions_head;
567 * Struct to hold the session reachable over this mac; tail
569 struct Sessionqueue *sessions_tail;
571 * Messages currently sending
574 struct FragmentMessage *sending_messages_head;
577 * Messages currently sending
578 * to a peer (tail), if any.
580 struct FragmentMessage *sending_messages_tail;
584 struct MacEndpoint *next;
588 struct MacEndpoint *prev;
593 struct GNUNET_TRANSPORT_WLAN_MacAddress addr;
596 * Defrag context for this mac endpoint
598 struct GNUNET_DEFRAGMENT_Context *defrag;
601 * count of messages in the fragment out queue for this mac endpoint
604 int fragment_messages_out_count;
612 * Duplicates received
627 * Last activity on this endpoint. Used to select preferred
630 struct GNUNET_TIME_Absolute last_activity;
635 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
639 * Struct for Messages in the fragment queue
641 struct FragmentMessage
645 * Session this message belongs to
647 struct Session *session;
650 * This is a doubly-linked list.
652 struct FragmentMessage *next;
655 * This is a doubly-linked list.
657 struct FragmentMessage *prev;
660 * Fragmentation context
662 struct GNUNET_FRAGMENT_Context *fragcontext;
665 * Timeout value for the message.
667 struct GNUNET_TIME_Absolute timeout;
672 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
685 * pointer to the ieee wlan header
687 struct ieee80211_frame *ieeewlanheader;
689 * pointer to the radiotap header
691 struct Radiotap_Send *radioHeader;
695 do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
698 free_session (struct Plugin *plugin, struct Sessionqueue *queue,
699 int do_free_macendpoint);
701 static struct MacEndpoint *
702 create_macendpoint (struct Plugin *plugin, const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr);
705 finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
708 * Generates a nice hexdump of a memory area.
710 * \param mem pointer to memory to dump
711 * \param length how many bytes to dump
714 hexdump (const void *mem, unsigned length)
717 char *src = (char *) mem;
719 printf ("dumping %u bytes from %p\r\n"
720 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n",
725 for (i = 0; i < length; i += 16, src += 16)
729 t += sprintf (t, "%04x: ", i);
730 for (j = 0; j < 16; j++)
733 t += sprintf (t, "%02X", src[j] & 0xff);
735 t += sprintf (t, " ");
737 t += sprintf (t, (j % 2) ? " " : "-");
740 t += sprintf (t, " ");
741 for (j = 0; j < 16; j++)
745 if (isprint ((unsigned char) src[j]))
746 t += sprintf (t, "%c", src[j]);
748 t += sprintf (t, ".");
752 t += sprintf (t, " ");
756 t += sprintf (t, "\r\n");
762 * Function to find a MacEndpoint with a specific mac addr
763 * @param plugin pointer to the plugin struct
764 * @param addr pointer to the mac address
765 * @param create_new GNUNET_YES if a new end point should be created
768 static struct MacEndpoint *
769 get_macendpoint (struct Plugin *plugin, const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr,
772 struct MacEndpoint *queue = plugin->mac_head;
774 while (queue != NULL)
776 //GNUNET_assert (queue->sessions_head != NULL);
777 if (memcmp (addr, &queue->addr, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
778 return queue; /* session found */
782 if (create_new == GNUNET_YES)
784 return create_macendpoint (plugin, addr);
794 * search for a session with the macendpoint and peer id
796 * @param plugin pointer to the plugin struct
797 * @param endpoint pointer to the mac endpoint of the peer
798 * @param peer pointer to the peerid
799 * @return returns the session
801 static struct Session *
802 search_session (struct Plugin *plugin, const struct MacEndpoint *endpoint,
803 const struct GNUNET_PeerIdentity *peer)
805 GNUNET_assert (endpoint != NULL);
806 struct Sessionqueue *queue = endpoint->sessions_head;
808 while (queue != NULL)
810 GNUNET_assert (queue->content != NULL);
812 (peer, &queue->content->target,
813 sizeof (struct GNUNET_PeerIdentity)) == 0)
814 return queue->content; /* session found */
821 * Function called for a quick conversion of the binary address to
822 * a numeric address. Note that the caller must not free the
823 * address and that the next call to this function is allowed
824 * to override the address again.
827 * @param addr binary address
828 * @param addrlen length of the address
829 * @return string representing the same address
832 wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
835 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
837 if (addrlen != sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))
843 GNUNET_snprintf (ret, sizeof (ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
844 PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2],
845 mac->mac[3], mac->mac[4], mac->mac[5]);
851 * Function for the scheduler if a session times out
852 * @param cls pointer to the Sessionqueue
853 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
856 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
858 struct Sessionqueue *queue = cls;
860 GNUNET_assert (queue != NULL);
861 GNUNET_assert (queue->content != NULL);
862 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
863 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
867 if (GNUNET_TIME_absolute_get_remaining
868 (GNUNET_TIME_absolute_add
869 (queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0)
872 GNUNET_assert (queue->content->mac != NULL);
873 GNUNET_assert (queue->content->mac->plugin != NULL);
874 GNUNET_STATISTICS_update (queue->content->mac->plugin->env->stats,
875 _("# wlan session timeouts"), 1, GNUNET_NO);
876 free_session (queue->content->mac->plugin, queue, GNUNET_YES);
880 queue->content->timeout_task =
881 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
886 * create a new session
888 * @param plugin pointer to the plugin struct
889 * @param endpoint pointer to the mac endpoint of the peer
890 * @param peer peer identity to use for this session
891 * @return returns the session
893 static struct Session *
894 create_session (struct Plugin *plugin, struct MacEndpoint *endpoint,
895 const struct GNUNET_PeerIdentity *peer)
897 GNUNET_assert (endpoint != NULL);
898 GNUNET_assert (plugin != NULL);
899 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1,
901 struct Sessionqueue *queue =
902 GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session));
904 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
905 endpoint->sessions_tail, queue);
907 queue->content = (struct Session *) &queue[1];
908 queue->content->mac = endpoint;
909 queue->content->target = *peer;
910 queue->content->last_activity = GNUNET_TIME_absolute_get ();
911 queue->content->timeout_task =
912 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
914 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
915 "New session %p with endpoint %p: %s\n", queue->content,
916 endpoint, wlan_plugin_address_to_string (NULL,
919 return queue->content;
923 * Get session from address, create if no session exists
925 * @param plugin pointer to the plugin struct
926 * @param addr pointer to the mac address of the peer
927 * @param peer pointer to the peerid
928 * @return returns the session
930 static struct Session *
931 get_session (struct Plugin *plugin, const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr,
932 const struct GNUNET_PeerIdentity *peer)
934 struct MacEndpoint *mac;
936 mac = get_macendpoint (plugin, addr, GNUNET_YES);
937 struct Session *session = search_session (plugin, mac, peer);
941 return create_session (plugin, mac, peer);
945 * Queue the session to send data
946 * checks if there is a message pending
947 * checks if this session is not allready in the queue
948 * @param plugin pointer to the plugin
949 * @param session pointer to the session to add
952 queue_session (struct Plugin *plugin, struct Session *session)
954 struct Sessionqueue *queue = plugin->pending_Sessions_head;
956 if (session->pending_message_head != NULL)
958 while (queue != NULL)
960 // content is never NULL
961 GNUNET_assert (queue->content != NULL);
962 // is session already in queue?
963 if (session == queue->content)
971 // Session is not in the queue
973 queue = GNUNET_malloc (sizeof (struct Sessionqueue));
974 queue->content = session;
977 GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head,
978 plugin->pending_Sessions_tail, queue);
979 plugin->pendingsessions++;
980 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
981 plugin->pendingsessions, GNUNET_NO);
987 * Function to schedule the write task, executed after a delay
988 * @param cls pointer to the plugin struct
989 * @param tc GNUNET_SCHEDULER_TaskContext pointer
992 delay_fragment_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
994 struct Plugin *plugin = cls;
996 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
998 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1001 // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg
1002 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1004 plugin->server_write_task =
1005 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1006 plugin->server_stdin_handle,
1007 &do_transmit, plugin);
1012 * Function to calculate the time of the next periodic "hello-beacon"
1013 * @param plugin pointer to the plugin struct
1016 set_next_beacon_time (struct Plugin *const plugin)
1018 //under 10 known peers: once a second
1019 if (plugin->mac_count < 10)
1021 plugin->beacon_time =
1022 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1023 GNUNET_TIME_relative_multiply
1024 (GNUNET_TIME_UNIT_SECONDS,
1025 HELLO_BEACON_SCALING_FACTOR));
1027 //under 30 known peers: every 10 seconds
1028 else if (plugin->mac_count < 30)
1030 plugin->beacon_time =
1031 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1032 GNUNET_TIME_relative_multiply
1033 (GNUNET_TIME_UNIT_SECONDS,
1034 10 * HELLO_BEACON_SCALING_FACTOR));
1036 //over 30 known peers: once a minute
1039 plugin->beacon_time =
1040 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1041 GNUNET_TIME_relative_multiply
1042 (GNUNET_TIME_UNIT_MINUTES,
1043 HELLO_BEACON_SCALING_FACTOR));
1048 * Function to set the timer for the next timeout of the fragment queue
1049 * @param plugin the handle to the plugin struct
1052 set_next_send (struct Plugin *const plugin)
1054 struct GNUNET_TIME_Relative next_send;
1056 //abort if helper is not running
1057 if (plugin->helper_is_running == GNUNET_NO)
1063 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1065 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1066 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1069 //check if some acks are in the queue
1070 if (plugin->ack_send_queue_head != NULL)
1072 next_send = GNUNET_TIME_UNIT_ZERO;
1075 //check if there are some fragments in the queue
1076 else if (plugin->sending_messages_head != NULL)
1078 next_send = GNUNET_TIME_UNIT_ZERO;
1082 next_send = GNUNET_TIME_absolute_get_remaining (plugin->beacon_time);
1085 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1086 "Next packet is send in: %u\n", next_send.rel_value);
1087 if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value)
1089 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1091 plugin->server_write_task =
1092 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1093 plugin->server_stdin_handle,
1094 &do_transmit, plugin);
1099 if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK)
1101 plugin->server_write_delay_task =
1102 GNUNET_SCHEDULER_add_delayed (next_send, &delay_fragment_task,
1109 * Function to get the next queued Session, removes the session from the queue
1110 * @param plugin pointer to the plugin struct
1111 * @return pointer to the session found, returns NULL if there is now session in the queue
1113 static struct Session *
1114 get_next_queue_session (struct Plugin *plugin)
1116 struct Session *session;
1117 struct Sessionqueue *sessionqueue;
1118 struct Sessionqueue *sessionqueue_alt;
1119 struct PendingMessage *pm;
1121 sessionqueue = plugin->pending_Sessions_head;
1123 while (sessionqueue != NULL)
1125 session = sessionqueue->content;
1127 GNUNET_assert (session != NULL);
1128 pm = session->pending_message_head;
1132 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1133 "pending message is empty, should not happen. session %p\n",
1135 sessionqueue_alt = sessionqueue;
1136 sessionqueue = sessionqueue->next;
1137 plugin->pendingsessions--;
1138 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1139 plugin->pendingsessions, GNUNET_NO);
1140 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1141 plugin->pending_Sessions_tail,
1144 GNUNET_free (sessionqueue_alt);
1149 //check for message timeout
1150 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
1152 //check if session has no message in the fragment queue
1153 if ((session->mac->fragment_messages_out_count <
1154 FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT) &&
1155 (session->fragment_messages_out_count <
1156 FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
1158 plugin->pendingsessions--;
1159 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1160 plugin->pendingsessions, GNUNET_NO);
1161 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1162 plugin->pending_Sessions_tail,
1164 GNUNET_free (sessionqueue);
1170 sessionqueue = sessionqueue->next;
1175 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1176 session->pending_message_tail, pm);
1178 //call the cont func that it did not work
1179 if (pm->transmit_cont != NULL)
1180 pm->transmit_cont (pm->transmit_cont_cls, &(session->target),
1182 GNUNET_free (pm->msg);
1185 if (session->pending_message_head == NULL)
1187 sessionqueue_alt = sessionqueue;
1188 sessionqueue = sessionqueue->next;
1189 plugin->pendingsessions--;
1190 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1191 plugin->pendingsessions, GNUNET_NO);
1192 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1193 plugin->pending_Sessions_tail,
1196 GNUNET_free (sessionqueue_alt);
1205 * frees the space of a message in the fragment queue (send queue)
1206 * @param plugin the plugin struct
1207 * @param fm message to free
1210 free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm)
1212 struct Session *session = fm->session;
1213 struct MacEndpoint *endpoint = session->mac;
1214 struct FragmentMessage_queue *fmq;
1215 struct FragmentMessage_queue *fmq_next;
1217 fmq = plugin->sending_messages_head;
1220 fmq_next = fmq->next;
1221 if (fmq->content == fm)
1223 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1224 plugin->sending_messages_tail, fmq);
1230 (session->mac->fragment_messages_out_count)--;
1231 session->fragment_messages_out_count--;
1232 plugin->pending_Fragment_Messages--;
1233 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
1234 plugin->pending_Fragment_Messages, GNUNET_NO);
1235 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
1236 endpoint->sending_messages_tail, fm);
1237 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
1238 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1240 GNUNET_SCHEDULER_cancel (fm->timeout_task);
1241 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1246 queue_session (plugin, session);
1247 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1248 "Free pending fragment messages %p, session %p\n", fm,
1253 * function to fill the radiotap header
1254 * @param plugin pointer to the plugin struct
1255 * @param endpoint pointer to the endpoint
1256 * @param header pointer to the radiotap header
1257 * @return GNUNET_YES at success
1260 getRadiotapHeader (struct Plugin *plugin, struct MacEndpoint *endpoint,
1261 struct Radiotap_Send *header)
1264 if (endpoint != NULL)
1266 header->rate = endpoint->rate;
1267 header->tx_power = endpoint->tx_power;
1268 header->antenna = endpoint->antenna;
1273 header->tx_power = 0;
1274 header->antenna = 0;
1281 * function to generate the wlan hardware header for one packet
1282 * @param Header address to write the header to
1283 * @param to_mac_addr address of the recipient
1284 * @param plugin pointer to the plugin struct
1285 * @param size size of the whole packet, needed to calculate the time to send the packet
1286 * @return GNUNET_YES if there was no error
1289 getWlanHeader (struct ieee80211_frame *Header,
1290 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, struct Plugin *plugin,
1294 const int rate = 11000000;
1296 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA;
1297 Header->i_fc[1] = 0x00;
1298 memcpy (&Header->i_addr3, &mac_bssid_gnunet, sizeof (mac_bssid_gnunet));
1299 memcpy (&Header->i_addr2, plugin->mac_address.mac,
1300 sizeof (plugin->mac_address));
1301 memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1303 tmp16 = (uint16_t *) Header->i_dur;
1304 *tmp16 = (uint16_t) GNUNET_htole16 ((size * 1000000) / rate + 290);
1305 Header->llc[0] = WLAN_LLC_DSAP_FIELD;
1306 Header->llc[1] = WLAN_LLC_SSAP_FIELD;
1313 * function to add a fragment of a message to send
1314 * @param cls FragmentMessage this message belongs to
1315 * @param hdr pointer to the start of the message
1318 add_message_for_send (void *cls, const struct GNUNET_MessageHeader *hdr)
1321 struct FragmentMessage *fm = cls;
1322 struct FragmentMessage_queue *fmqueue;
1324 GNUNET_assert (cls != NULL);
1325 GNUNET_assert (fm->frag == NULL);
1326 struct MacEndpoint *endpoint = fm->session->mac;
1327 struct Plugin *plugin = endpoint->plugin;
1328 struct GNUNET_MessageHeader *msgheader;
1329 struct GNUNET_MessageHeader *msgheader2;
1332 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1333 "Adding fragment of message %p to send, session %p, endpoint %p, type %u\n",
1334 fm, fm->session, endpoint, hdr->type);
1336 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1337 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1338 fm->frag = GNUNET_malloc (size);
1341 msgheader = (struct GNUNET_MessageHeader *) fm->frag;
1342 msgheader->size = htons (size);
1343 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1345 fm->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1346 fm->ieeewlanheader = (struct ieee80211_frame *) &fm->radioHeader[1];
1347 msgheader2 = (struct GNUNET_MessageHeader *) &fm->ieeewlanheader[1];
1348 memcpy (msgheader2, hdr, ntohs (hdr->size));
1350 fmqueue = GNUNET_malloc (sizeof (struct FragmentMessage_queue));
1351 fmqueue->content = fm;
1353 GNUNET_CONTAINER_DLL_insert_tail (plugin->sending_messages_head,
1354 plugin->sending_messages_tail, fmqueue);
1355 set_next_send (plugin);
1360 * We have been notified that gnunet-helper-transport-wlan has written something to stdout.
1361 * Handle the output, then reschedule this function to be called again once
1362 * more is available.
1364 * @param cls the plugin handle
1365 * @param tc the scheduling context
1368 wlan_plugin_helper_read (void *cls,
1369 const struct GNUNET_SCHEDULER_TaskContext *tc)
1371 struct Plugin *plugin = cls;
1373 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1375 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1378 char mybuf[WLAN_MTU + sizeof (struct GNUNET_MessageHeader)];
1382 GNUNET_DISK_file_read (plugin->server_stdout_handle, mybuf,
1386 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1388 ("Finished reading from gnunet-helper-transport-wlan stdout with code: %d\n"),
1392 GNUNET_SERVER_mst_receive (plugin->suid_tokenizer, NULL, mybuf, bytes,
1393 GNUNET_NO, GNUNET_NO);
1395 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
1396 plugin->server_read_task =
1397 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1398 plugin->server_stdout_handle,
1399 &wlan_plugin_helper_read, plugin);
1403 * Start the gnunet-helper-transport-wlan process.
1405 * @param plugin the transport plugin
1406 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
1409 wlan_transport_start_wlan_helper (struct Plugin *plugin)
1411 const char *filenamehw = "gnunet-helper-transport-wlan";
1412 const char *filenameloopback = "gnunet-helper-transport-wlan-dummy";
1413 char *absolute_filename = NULL;
1415 if (plugin->helper_is_running == GNUNET_YES)
1417 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1418 "wlan_transport_start_wlan_helper not needed, helper already running!");
1422 plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
1423 if (plugin->server_stdout == NULL)
1424 return GNUNET_SYSERR;
1426 plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
1427 if (plugin->server_stdin == NULL)
1428 return GNUNET_SYSERR;
1430 if ((plugin->testmode == 1) || (plugin->testmode == 2))
1432 if (GNUNET_OS_check_helper_binary (filenameloopback) == GNUNET_YES)
1434 absolute_filename = GNUNET_strdup (filenameloopback);
1438 char cwd[FILENAME_MAX];
1440 GNUNET_assert (getcwd (cwd, sizeof (cwd)) != NULL);
1442 GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR,
1445 if (GNUNET_DISK_file_test (filenameloopback) != GNUNET_YES)
1447 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1448 "Helper `%s' not found! %i\n", absolute_filename);
1454 /* Start the server process */
1456 if (plugin->testmode == 0)
1459 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1460 "Starting gnunet-helper-transport-wlan process cmd: %s %s %i\n",
1461 filenamehw, plugin->interface, plugin->testmode);
1462 if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_YES)
1464 plugin->server_proc =
1465 GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout,
1466 filenamehw, filenamehw, plugin->interface,
1469 else if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_NO)
1471 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1472 "gnunet-helper-transport-wlan is not suid, please change it or look at the doku\n");
1477 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1478 "gnunet-helper-transport-wlan not found, please look if it exists and is the $PATH variable!\n");
1483 else if (plugin->testmode == 1)
1486 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
1487 "Starting gnunet-helper-transport-wlan-dummy loopback 1 process cmd: %s %s %i\n",
1488 absolute_filename, plugin->interface, plugin->testmode);
1489 plugin->server_proc =
1490 GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout,
1491 absolute_filename, absolute_filename, "1",
1493 if (plugin->server_proc == NULL)
1495 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1496 "`%s' not found, please look if it exists and is in the $PATH variable!\n",
1501 else if (plugin->testmode == 2)
1503 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
1504 "Starting gnunet-helper-transport-wlan-dummy loopback 2 process cmd: %s %s %i\n",
1505 absolute_filename, plugin->interface, plugin->testmode);
1506 plugin->server_proc =
1507 GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout,
1508 absolute_filename, absolute_filename, "2",
1510 if (plugin->server_proc == NULL)
1512 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1513 "`%s' not found, please look if it exists and is in the $PATH variable!\n",
1518 if (absolute_filename != NULL)
1519 GNUNET_free (absolute_filename);
1520 if (plugin->server_proc == NULL)
1522 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1523 "Failed to start gnunet-helper-transport-wlan process\n");
1524 return GNUNET_SYSERR;
1529 /* Close the write end of the read pipe */
1530 GNUNET_DISK_pipe_close_end (plugin->server_stdout,
1531 GNUNET_DISK_PIPE_END_WRITE);
1533 /* Close the read end of the write pipe */
1534 GNUNET_DISK_pipe_close_end (plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
1536 plugin->server_stdout_handle =
1537 GNUNET_DISK_pipe_handle (plugin->server_stdout,
1538 GNUNET_DISK_PIPE_END_READ);
1539 plugin->server_stdin_handle =
1540 GNUNET_DISK_pipe_handle (plugin->server_stdin,
1541 GNUNET_DISK_PIPE_END_WRITE);
1543 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
1545 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1546 "Adding server_read_task for the gnunet-helper-transport-wlan\n");
1547 plugin->server_read_task =
1548 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1549 plugin->server_stdout_handle,
1550 &wlan_plugin_helper_read, plugin);
1552 plugin->helper_is_running = GNUNET_YES;
1557 * Stops the gnunet-helper-transport-wlan process.
1559 * @param plugin the transport plugin
1560 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
1563 wlan_transport_stop_wlan_helper (struct Plugin *plugin)
1565 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1566 "Stoping WLAN helper process\n");
1568 if (plugin->helper_is_running == GNUNET_NO)
1570 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1571 "wlan_transport_stop_wlan_helper not needed, helper already stopped!");
1575 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1577 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1578 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1581 if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK)
1583 GNUNET_SCHEDULER_cancel (plugin->server_write_task);
1584 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1587 if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK)
1589 GNUNET_SCHEDULER_cancel (plugin->server_read_task);
1590 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1593 GNUNET_DISK_pipe_close (plugin->server_stdout);
1594 GNUNET_DISK_pipe_close (plugin->server_stdin);
1595 GNUNET_OS_process_kill (plugin->server_proc, SIGKILL);
1596 GNUNET_OS_process_wait (plugin->server_proc);
1597 GNUNET_OS_process_close (plugin->server_proc);
1599 plugin->helper_is_running = GNUNET_NO;
1605 * function for delayed restart of the helper process
1606 * @param cls Finish_send struct if message should be finished
1607 * @param tc TaskContext
1610 delay_restart_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1612 struct Finish_send *finish = cls;
1613 struct Plugin *plugin;
1615 plugin = finish->plugin;
1617 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1618 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1620 GNUNET_free_non_null (finish->msgstart);
1621 GNUNET_free (finish);
1625 wlan_transport_start_wlan_helper (plugin);
1627 if (finish->size != 0)
1629 plugin->server_write_task =
1630 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1631 plugin->server_stdin_handle,
1632 &finish_sending, finish);
1636 set_next_send (plugin);
1637 GNUNET_free_non_null (finish->msgstart);
1638 GNUNET_free (finish);
1644 * Function to restart the helper
1645 * @param plugin pointer to the global plugin struct
1646 * @param finish pointer to the Finish_send struct to finish
1649 restart_helper (struct Plugin *plugin, struct Finish_send *finish)
1651 static struct GNUNET_TIME_Relative next_try = { 1000 };
1652 GNUNET_assert (finish != NULL);
1654 wlan_transport_stop_wlan_helper (plugin);
1655 plugin->server_write_task =
1656 GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish);
1657 GNUNET_TIME_relative_multiply (next_try, HELPER_RESTART_SCALING_FACTOR);
1662 * function to finish a sending if not all could have been writen befor
1663 * @param cls pointer to the Finish_send struct
1664 * @param tc TaskContext
1667 finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1669 struct Finish_send *finish = cls;
1670 struct Plugin *plugin;
1673 plugin = finish->plugin;
1674 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1676 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1678 GNUNET_free (finish->msgstart);
1679 GNUNET_free (finish);
1683 GNUNET_DISK_file_write (plugin->server_stdin_handle,
1684 finish->head_of_next_write, finish->size);
1686 if (bytes != finish->size)
1688 if (bytes != GNUNET_SYSERR)
1690 finish->head_of_next_write += bytes;
1691 finish->size -= bytes;
1692 plugin->server_write_task =
1693 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1694 plugin->server_stdin_handle,
1695 &finish_sending, finish);
1699 restart_helper (plugin, finish);
1704 GNUNET_free (finish->msgstart);
1705 GNUNET_free (finish);
1706 set_next_send (plugin);
1711 * function to send a hello beacon
1712 * @param plugin pointer to the plugin struct
1715 send_hello_beacon (struct Plugin *plugin)
1719 uint16_t hello_size;
1720 struct GNUNET_MessageHeader *msgheader;
1721 struct ieee80211_frame *ieeewlanheader;
1722 struct Radiotap_Send *radioHeader;
1723 struct GNUNET_MessageHeader *msgheader2;
1724 const struct GNUNET_MessageHeader *hello;
1725 struct Finish_send *finish;
1727 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1728 "Sending hello beacon\n");
1730 GNUNET_assert (plugin != NULL);
1732 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"),
1735 hello = plugin->env->get_our_hello ();
1736 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1737 GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
1739 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1740 sizeof (struct ieee80211_frame) + hello_size;
1742 msgheader = GNUNET_malloc (size);
1743 msgheader->size = htons (size);
1744 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1746 radioHeader = (struct Radiotap_Send *) &msgheader[1];
1747 getRadiotapHeader (plugin, NULL, radioHeader);
1748 ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
1749 getWlanHeader (ieeewlanheader, &bc_all_mac, plugin, size);
1751 msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1];
1752 /*msgheader2->size =
1753 * htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) +
1754 * sizeof (struct GNUNET_MessageHeader));
1756 * msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); */
1757 memcpy (msgheader2, hello, hello_size);
1759 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size);
1761 if (bytes == GNUNET_SYSERR)
1763 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1765 ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
1766 errno, strerror (errno));
1767 finish = GNUNET_malloc (sizeof (struct Finish_send));
1768 finish->plugin = plugin;
1769 finish->head_of_next_write = NULL;
1771 finish->msgstart = NULL;
1772 restart_helper (plugin, finish);
1774 set_next_beacon_time (plugin);
1779 GNUNET_assert (bytes == size);
1780 set_next_beacon_time (plugin);
1781 set_next_send (plugin);
1783 GNUNET_free (msgheader);
1789 * function to add an ack to send it for a received fragment
1790 * @param cls MacEndpoint this ack belongs to
1791 * @param msg_id id of the message
1792 * @param hdr pointer to the hdr where the ack is stored
1796 add_ack_for_send (void *cls, uint32_t msg_id,
1797 const struct GNUNET_MessageHeader *hdr)
1800 struct AckSendQueue *ack;
1802 GNUNET_assert (cls != NULL);
1803 struct MacEndpoint *endpoint = cls;
1804 struct Plugin *plugin = endpoint->plugin;
1805 struct GNUNET_MessageHeader *msgheader;
1806 struct GNUNET_MessageHeader *msgheader2;
1810 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1811 sizeof (struct ieee80211_frame) + ntohs (hdr->size) +
1812 sizeof (struct AckSendQueue);
1814 ack = GNUNET_malloc (size);
1815 ack->message_id = msg_id;
1816 ack->endpoint = endpoint;
1819 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1820 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1822 msgheader = (struct GNUNET_MessageHeader *) &ack[1];
1823 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1];
1824 msgheader->size = htons (size);
1825 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1827 ack->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1828 ack->ieeewlanheader = (struct ieee80211_frame *) &(ack->radioHeader)[1];
1829 msgheader2 = (struct GNUNET_MessageHeader *) &(ack->ieeewlanheader)[1];
1830 memcpy (msgheader2, hdr, ntohs (hdr->size));
1832 GNUNET_CONTAINER_DLL_insert_tail (plugin->ack_send_queue_head,
1833 plugin->ack_send_queue_tail, ack);
1835 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1836 "Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n",
1837 msg_id, ack, endpoint);
1838 set_next_send (plugin);
1842 * Function for the scheduler if a FragmentMessage times out
1843 * @param cls pointer to the FragmentMessage
1844 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
1847 fragmentmessage_timeout (void *cls,
1848 const struct GNUNET_SCHEDULER_TaskContext *tc)
1850 struct FragmentMessage *fm = cls;
1852 GNUNET_assert (fm != NULL);
1853 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1854 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1858 free_fragment_message (fm->session->mac->plugin, fm);
1862 * Function to check if there is some space in the fragment queue
1863 * inserts a message if space is available
1864 * @param plugin the plugin struct
1868 check_fragment_queue (struct Plugin *plugin)
1870 struct Session *session;
1871 struct FragmentMessage *fm;
1872 struct GNUNET_PeerIdentity pid;
1874 struct PendingMessage *pm;
1876 if (plugin->pending_Fragment_Messages < FRAGMENT_QUEUE_SIZE)
1878 session = get_next_queue_session (plugin);
1879 if (session != NULL)
1881 pm = session->pending_message_head;
1882 GNUNET_assert (pm != NULL);
1883 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1884 session->pending_message_tail, pm);
1885 session->mac->fragment_messages_out_count++;
1886 session->fragment_messages_out_count++;
1887 plugin->pending_Fragment_Messages++;
1888 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
1889 plugin->pending_Fragment_Messages, GNUNET_NO);
1891 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
1892 fm->session = session;
1893 fm->timeout.abs_value = pm->timeout.abs_value;
1896 GNUNET_FRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
1898 GNUNET_TIME_UNIT_SECONDS,
1900 &add_message_for_send, fm);
1902 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
1903 (fm->timeout), fragmentmessage_timeout,
1905 GNUNET_CONTAINER_DLL_insert_tail (session->mac->sending_messages_head,
1906 session->mac->sending_messages_tail,
1909 if (pm->transmit_cont != NULL)
1911 pid = session->target;
1912 pm->transmit_cont (pm->transmit_cont_cls, &pid, GNUNET_OK);
1913 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1914 "called pm->transmit_cont for %p\n", session);
1918 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1919 "no pm->transmit_cont for %p\n", session);
1923 if (session->pending_message_head != NULL)
1926 queue_session (plugin, session);
1932 //check if timeout changed
1933 set_next_send (plugin);
1937 * Function to send an ack, does not free the ack
1938 * @param plugin pointer to the plugin
1941 send_ack (struct Plugin *plugin)
1945 struct AckSendQueue *ack;
1946 struct Finish_send *finish;
1948 ack = plugin->ack_send_queue_head;
1949 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1950 "Sending ack for message_id %u for mac endpoint %p, size %u\n",
1951 ack->message_id, ack->endpoint,
1952 ntohs (ack->hdr->size) - sizeof (struct Radiotap_Send));
1953 GNUNET_assert (plugin != NULL);
1954 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1,
1957 getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader);
1958 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
1959 ntohs (ack->hdr->size));
1962 GNUNET_DISK_file_write (plugin->server_stdin_handle, ack->hdr,
1963 ntohs (ack->hdr->size));
1964 if (bytes == GNUNET_SYSERR)
1966 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1968 ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
1969 errno, strerror (errno));
1970 finish = GNUNET_malloc (sizeof (struct Finish_send));
1971 finish->plugin = plugin;
1972 finish->head_of_next_write = NULL;
1974 finish->msgstart = NULL;
1975 restart_helper (plugin, finish);
1979 GNUNET_assert (bytes == ntohs (ack->hdr->size));
1980 GNUNET_CONTAINER_DLL_remove (plugin->ack_send_queue_head,
1981 plugin->ack_send_queue_tail, ack);
1983 set_next_send (plugin);
1988 * Function called when wlan helper is ready to get some data
1990 * @param cls closure
1991 * @param tc GNUNET_SCHEDULER_TaskContext
1994 do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1996 struct Plugin *plugin = cls;
1998 GNUNET_assert (plugin != NULL);
2000 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2001 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2004 struct Session *session;
2005 struct FragmentMessage *fm;
2006 struct Finish_send *finish;
2007 struct FragmentMessage_queue *fmq;
2010 if (plugin->ack_send_queue_head != NULL)
2016 //test if a "hello-beacon" has to be send
2017 if (GNUNET_TIME_absolute_get_remaining (plugin->beacon_time).rel_value == 0)
2019 send_hello_beacon (plugin);
2023 if (plugin->sending_messages_head != NULL)
2025 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1,
2028 fmq = plugin->sending_messages_head;
2030 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
2031 plugin->sending_messages_tail, fmq);
2034 session = fm->session;
2035 GNUNET_assert (session != NULL);
2036 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2037 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p, size: %u\n",
2039 getRadiotapHeader (plugin, session->mac, fm->radioHeader);
2040 getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
2044 GNUNET_DISK_file_write (plugin->server_stdin_handle, fm->frag,
2048 if (bytes != fm->size)
2050 finish = GNUNET_malloc (sizeof (struct Finish_send));
2051 finish->plugin = plugin;
2052 finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag;
2053 GNUNET_assert (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
2055 if (bytes == GNUNET_SYSERR)
2057 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2059 ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
2060 errno, strerror (errno));
2062 finish->head_of_next_write = fm->frag;
2063 finish->size = fm->size;
2064 restart_helper (plugin, finish);
2068 finish->head_of_next_write = fm->frag + bytes;
2069 finish->size = fm->size - bytes;
2070 plugin->server_write_task =
2071 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
2072 plugin->server_stdin_handle,
2073 &finish_sending, finish);
2080 GNUNET_free (fm->frag);
2082 set_next_send (plugin);
2084 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
2089 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2090 "do_transmit did nothing, should not happen!\n");
2092 set_next_send (plugin);
2096 * Another peer has suggested an address for this
2097 * peer and transport plugin. Check that this could be a valid
2098 * address. If so, consider adding it to the list
2101 * @param cls closure
2102 * @param addr pointer to the address
2103 * @param addrlen length of addr
2104 * @return GNUNET_OK if this is a plausible address for this peer
2108 wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
2110 //struct Plugin *plugin = cls;
2112 /* check if the address is plausible; if so,
2113 * add it to our list! */
2115 GNUNET_assert (cls != NULL);
2116 //FIXME mitm is not checked
2117 //Mac Address has 6 bytes
2120 /* TODO check for bad addresses like multicast, broadcast, etc */
2121 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2122 "wlan_plugin_address_suggested got good address, size %u!\n",
2126 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2127 "wlan_plugin_address_suggested got bad address, size %u!\n",
2129 return GNUNET_SYSERR;
2134 * Creates a new outbound session the transport service will use to send data to the
2137 * @param cls the plugin
2138 * @param address the address
2139 * @return the session or NULL of max connections exceeded
2142 static struct Session *
2143 wlan_plugin_get_session (void *cls,
2144 const struct GNUNET_HELLO_Address *address)
2146 struct Plugin *plugin = cls;
2147 struct Session * s = NULL;
2149 GNUNET_assert (plugin != NULL);
2150 GNUNET_assert (address != NULL);
2152 if (GNUNET_OK == wlan_plugin_address_suggested (plugin,
2154 address->address_length))
2156 s = get_session (plugin, address->address, &address->peer);
2160 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2161 _("Wlan Address len %d is wrong\n"), address->address_length);
2169 * Function that can be used by the transport service to transmit
2170 * a message using the plugin. Note that in the case of a
2171 * peer disconnecting, the continuation MUST be called
2172 * prior to the disconnect notification itself. This function
2173 * will be called with this peer's HELLO message to initiate
2174 * a fresh connection to another peer.
2176 * @param cls closure
2177 * @param session which session must be used
2178 * @param msgbuf the message to transmit
2179 * @param msgbuf_size number of bytes in 'msgbuf'
2180 * @param priority how important is the message (most plugins will
2181 * ignore message priority and just FIFO)
2182 * @param to how long to wait at most for the transmission (does not
2183 * require plugins to discard the message after the timeout,
2184 * just advisory for the desired delay; most plugins will ignore
2186 * @param cont continuation to call once the message has
2187 * been transmitted (or if the transport is ready
2188 * for the next transmission call; or if the
2189 * peer disconnected...); can be NULL
2190 * @param cont_cls closure for cont
2191 * @return number of bytes used (on the physical network, with overheads);
2192 * -1 on hard errors (i.e. address invalid); 0 is a legal value
2193 * and does NOT mean that the message was not transmitted (DV)
2196 wlan_plugin_send (void *cls,
2197 struct Session *session,
2198 const char *msgbuf, size_t msgbuf_size,
2199 unsigned int priority,
2200 struct GNUNET_TIME_Relative to,
2201 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
2203 struct Plugin *plugin = cls;
2204 struct PendingMessage *newmsg;
2205 struct WlanHeader *wlanheader;
2207 GNUNET_assert (plugin != NULL);
2208 GNUNET_assert (session != NULL);
2209 GNUNET_assert (msgbuf_size > 0);
2213 //queue message in session
2214 //test if there is no other message in the "queue"
2215 //FIXME: to many send requests
2216 if (session->pending_message_head != NULL)
2218 newmsg = session->pending_message_head;
2219 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2220 "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",
2221 GNUNET_TIME_absolute_get_remaining (newmsg->
2223 session->mac->fragment_messages_out_count);
2226 newmsg = GNUNET_malloc (sizeof (struct PendingMessage));
2227 newmsg->msg = GNUNET_malloc (msgbuf_size + sizeof (struct WlanHeader));
2228 wlanheader = newmsg->msg;
2229 //copy msg to buffer, not fragmented / segmented yet, but with message header
2230 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
2231 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
2232 memcpy (&(wlanheader->target), &session->target, sizeof (struct GNUNET_PeerIdentity));
2233 memcpy (&(wlanheader->source), plugin->env->my_identity,
2234 sizeof (struct GNUNET_PeerIdentity));
2235 wlanheader->crc = 0;
2236 memcpy (&wlanheader[1], msgbuf, msgbuf_size);
2238 htonl (GNUNET_CRYPTO_crc32_n
2239 ((char *) wlanheader, msgbuf_size + sizeof (struct WlanHeader)));
2241 newmsg->transmit_cont = cont;
2242 newmsg->transmit_cont_cls = cont_cls;
2243 newmsg->timeout = GNUNET_TIME_relative_to_absolute (to);
2245 newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
2247 newmsg->message_size = msgbuf_size + sizeof (struct WlanHeader);
2249 GNUNET_CONTAINER_DLL_insert_tail (session->pending_message_head,
2250 session->pending_message_tail, newmsg);
2252 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2253 "New message for %p with size (incl wlan header) %u added\n",
2254 session, newmsg->message_size);
2256 hexdump (msgbuf, GNUNET_MIN (msgbuf_size, 256));
2259 queue_session (plugin, session);
2261 check_fragment_queue (plugin);
2262 //FIXME not the correct size
2268 * function to free a mac endpoint
2269 * @param plugin pointer to the plugin struct
2270 * @param endpoint pointer to the MacEndpoint to free
2273 free_macendpoint (struct Plugin *plugin, struct MacEndpoint *endpoint)
2275 struct Sessionqueue *sessions;
2276 struct Sessionqueue *sessions_next;
2278 GNUNET_assert (endpoint != NULL);
2280 sessions = endpoint->sessions_head;
2281 while (sessions != NULL)
2283 sessions_next = sessions->next;
2284 free_session (plugin, sessions, GNUNET_NO);
2285 sessions = sessions_next;
2288 GNUNET_CONTAINER_DLL_remove (plugin->mac_head, plugin->mac_tail, endpoint);
2289 if (endpoint->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2291 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
2292 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2294 plugin->mac_count--;
2295 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
2296 plugin->mac_count, GNUNET_NO);
2297 GNUNET_free (endpoint);
2302 * function to free a session
2303 * @param plugin pointer to the plugin
2304 * @param queue pointer to the sessionqueue element to free
2305 * @param do_free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint
2308 free_session (struct Plugin *plugin, struct Sessionqueue *queue,
2309 int do_free_macendpoint)
2311 struct Sessionqueue *pendingsession;
2312 struct Sessionqueue *pendingsession_tmp;
2313 struct PendingMessage *pm;
2314 struct MacEndpoint *endpoint;
2315 struct FragmentMessage *fm;
2316 struct FragmentMessage *fmnext;
2319 GNUNET_assert (plugin != NULL);
2320 GNUNET_assert (queue != NULL);
2321 GNUNET_assert (queue->content != NULL);
2324 //is this session pending for send
2325 pendingsession = plugin->pending_Sessions_head;
2326 while (pendingsession != NULL)
2328 pendingsession_tmp = pendingsession;
2329 pendingsession = pendingsession->next;
2330 GNUNET_assert (pendingsession_tmp->content != NULL);
2331 if (pendingsession_tmp->content == queue->content)
2333 plugin->pendingsessions--;
2334 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
2335 plugin->pendingsessions, GNUNET_NO);
2336 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
2337 plugin->pending_Sessions_tail,
2338 pendingsession_tmp);
2339 GNUNET_free (pendingsession_tmp);
2341 GNUNET_assert (check == 0);
2346 endpoint = queue->content->mac;
2347 fm = endpoint->sending_messages_head;
2351 if (fm->session == queue->content)
2353 free_fragment_message (plugin, fm);
2358 // remove PendingMessage
2359 pm = queue->content->pending_message_head;
2362 GNUNET_CONTAINER_DLL_remove (queue->content->pending_message_head,
2363 queue->content->pending_message_tail, pm);
2364 GNUNET_free (pm->msg);
2366 pm = queue->content->pending_message_head;
2369 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, endpoint->sessions_tail,
2371 //Check that no ohter session on this endpoint for this session exits
2372 GNUNET_assert (search_session (plugin, endpoint, &queue->content->target) ==
2374 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
2376 free_macendpoint (plugin, endpoint);
2377 //check if no endpoint with the same address exists
2378 GNUNET_assert (get_macendpoint (plugin, &endpoint->addr, GNUNET_NO) ==
2382 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2384 GNUNET_SCHEDULER_cancel (queue->content->timeout_task);
2385 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2387 GNUNET_free (queue);
2389 check_fragment_queue (plugin);
2393 * Function that can be used to force the plugin to disconnect
2394 * from the given peer and cancel all previous transmissions
2395 * (and their continuation).
2397 * @param cls closure
2398 * @param target peer from which to disconnect
2401 wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2403 struct Plugin *plugin = cls;
2404 struct Sessionqueue *queue;
2405 struct Sessionqueue *queue_next;
2406 struct MacEndpoint *endpoint = plugin->mac_head;
2407 struct MacEndpoint *endpoint_next;
2409 // just look at all the session for the needed one
2410 while (endpoint != NULL)
2412 queue = endpoint->sessions_head;
2413 endpoint_next = endpoint->next;
2414 while (queue != NULL)
2416 // content is never NULL
2417 GNUNET_assert (queue->content != NULL);
2418 queue_next = queue->next;
2420 (target, &(queue->content->target),
2421 sizeof (struct GNUNET_PeerIdentity)) == 0)
2423 free_session (plugin, queue, GNUNET_YES);
2428 endpoint = endpoint_next;
2433 * Convert the transports address to a nice, human-readable
2436 * @param cls closure
2437 * @param type name of the transport that generated the address
2438 * @param addr one of the addresses of the host, NULL for the last address
2439 * the specific address format depends on the transport
2440 * @param addrlen length of the address
2441 * @param numeric should (IP) addresses be displayed in numeric form?
2442 * @param timeout after how long should we give up?
2443 * @param asc function to call on each string
2444 * @param asc_cls closure for asc
2447 wlan_plugin_address_pretty_printer (void *cls, const char *type,
2448 const void *addr, size_t addrlen,
2450 struct GNUNET_TIME_Relative timeout,
2451 GNUNET_TRANSPORT_AddressStringCallback asc,
2455 const unsigned char *input;
2457 //GNUNET_assert(cls !=NULL);
2458 if (addrlen != sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))
2460 /* invalid address (MAC addresses have 6 bytes) */
2462 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2463 "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n",
2465 asc (asc_cls, NULL);
2468 input = (const unsigned char *) addr;
2469 GNUNET_asprintf (&ret,
2470 "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
2471 type, PROTOCOL_PREFIX, input[0], input[1], input[2],
2472 input[3], input[4], input[5]);
2473 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2474 "Func wlan_plugin_address_pretty_printer got size: %u, nummeric %u, type %s; made string: %s\n",
2475 addrlen, numeric, type, ret);
2477 //only one mac address per plugin
2478 asc (asc_cls, NULL);
2484 * handels the data after all fragments are put together
2485 * @param cls macendpoint this messages belongs to
2486 * @param hdr pointer to the data
2489 wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2491 struct MacEndpoint *endpoint = (struct MacEndpoint *) cls;
2492 struct Plugin *plugin = endpoint->plugin;
2493 struct WlanHeader *wlanheader;
2494 struct Session *session;
2496 const struct GNUNET_MessageHeader *temp_hdr;
2497 struct GNUNET_PeerIdentity tmpsource;
2500 GNUNET_assert (plugin != NULL);
2502 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
2505 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2506 "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
2509 if (ntohs (hdr->size) <
2510 sizeof (struct WlanHeader) + sizeof (struct GNUNET_MessageHeader))
2512 //packet not big enought
2516 GNUNET_STATISTICS_update (plugin->env->stats,
2517 _("# wlan whole messages received"), 1,
2519 wlanheader = (struct WlanHeader *) hdr;
2521 session = search_session (plugin, endpoint, &wlanheader->source);
2523 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
2524 crc = ntohl (wlanheader->crc);
2525 wlanheader->crc = 0;
2526 if (GNUNET_CRYPTO_crc32_n
2527 ((char *) wlanheader, ntohs (wlanheader->header.size)) != crc)
2529 //wrong crc, dispose message
2530 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2531 "Wlan message header crc was wrong: %u != %u\n",
2532 GNUNET_CRYPTO_crc32_n ((char *) wlanheader,
2533 ntohs (wlanheader->header.size)),
2535 hexdump ((void *) hdr, ntohs (hdr->size));
2539 //if not in session list
2540 if (session == NULL)
2542 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2543 "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n",
2544 ntohs (wlanheader->header.size), ntohs (temp_hdr->size),
2545 sizeof (struct WlanHeader));
2546 //try if it is a hello message
2547 if (ntohs (wlanheader->header.size) >=
2548 ntohs (temp_hdr->size) + sizeof (struct WlanHeader))
2550 if (ntohs (temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2552 if (GNUNET_HELLO_get_id
2553 ((const struct GNUNET_HELLO_Message *) temp_hdr,
2554 &tmpsource) == GNUNET_OK)
2556 session = create_session (plugin, endpoint, &tmpsource);
2560 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2561 "WLAN client not in session list and hello message is not okay\n");
2568 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2569 "WLAN client not in session list and not a hello message\n");
2575 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2576 "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n",
2577 ntohs (wlanheader->header.size),
2578 ntohs (temp_hdr->size), sizeof (struct WlanHeader));
2583 //"receive" the message
2586 (&wlanheader->source, &session->target,
2587 sizeof (struct GNUNET_PeerIdentity)) != 0)
2590 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2591 "WLAN peer source id doesn't match packet peer source id: session %p\n",
2597 (&wlanheader->target, plugin->env->my_identity,
2598 sizeof (struct GNUNET_PeerIdentity)) != 0)
2601 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2602 "WLAN peer target id doesn't match our peer id: session %p\n",
2607 GNUNET_SERVER_mst_receive (plugin->data_tokenizer, session,
2608 (const char *) temp_hdr,
2609 ntohs (hdr->size) - sizeof (struct WlanHeader),
2610 GNUNET_YES, GNUNET_NO);
2616 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2617 "wlan_data_message_handler got wrong message type: %u\n",
2624 * function to process the a message, give it to the higher layer
2625 * @param cls pointer to the plugin
2626 * @param client pointer to the session this message belongs to
2627 * @param hdr start of the message
2629 //TODO ATS informations
2631 process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2634 GNUNET_assert (client != NULL);
2635 GNUNET_assert (cls != NULL);
2636 struct Session *session = (struct Session *) client;
2637 struct Plugin *plugin = (struct Plugin *) cls;
2638 struct GNUNET_ATS_Information ats[2];
2640 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
2641 ats[0].value = htonl (1);
2642 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2643 ats[1].value = htonl (GNUNET_ATS_NET_WLAN);
2645 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2646 "Calling plugin->env->receive for session %p; %s; size: %u\n",
2647 session, wlan_plugin_address_to_string (NULL,
2651 plugin->env->receive (plugin->env->cls, &(session->target), hdr,
2652 (const struct GNUNET_ATS_Information *) &ats, 2,
2653 session, (const char *) &session->mac->addr,
2654 sizeof (session->mac->addr));
2658 * Function used for to process the data received from the wlan interface
2660 * @param cls the plugin handle
2661 * @param session_light pointer to the struct holding known informations
2662 * @param hdr hdr of the GNUNET_MessageHeader
2663 * @param rxinfo pointer to the radiotap informations got with this packet FIXME: give ATS for info
2666 wlan_data_helper (void *cls, struct Session_light *session_light,
2667 const struct GNUNET_MessageHeader *hdr,
2668 const struct Radiotap_rx *rxinfo)
2670 struct Plugin *plugin = cls;
2671 struct FragmentMessage *fm;
2672 struct FragmentMessage *fm2;
2673 struct GNUNET_PeerIdentity tmpsource;
2675 GNUNET_assert (plugin != NULL);
2678 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2681 //TODO better DOS protection, error handling
2682 //TODO test first than create session
2683 GNUNET_assert (session_light != NULL);
2685 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2686 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_HELLO size: %u; %s\n",
2687 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2688 session_light->addr.
2690 if (session_light->macendpoint == NULL)
2692 session_light->macendpoint =
2693 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2697 if (GNUNET_HELLO_get_id
2698 ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource) == GNUNET_OK)
2700 session_light->session =
2701 search_session (plugin, session_light->macendpoint, &tmpsource);
2702 if (session_light->session == NULL)
2704 session_light->session =
2705 create_session (plugin, session_light->macendpoint, &tmpsource);
2707 GNUNET_STATISTICS_update (plugin->env->stats,
2708 _("# wlan hello messages received"), 1,
2710 plugin->env->receive (plugin->env->cls, &session_light->session->target,
2711 hdr, NULL, 0, session_light->session,
2712 (const char *) &session_light->session->mac->addr,
2713 sizeof (session_light->session->mac->addr));
2717 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2718 "WLAN client not in session list and hello message is not okay\n");
2725 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT)
2728 GNUNET_assert (session_light != NULL);
2729 if (session_light->macendpoint == NULL)
2731 session_light->macendpoint =
2732 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2735 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2736 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size: %u; mac endpoint %p: %s\n",
2737 ntohs (hdr->size), session_light->macendpoint,
2738 wlan_plugin_address_to_string (NULL,
2739 session_light->addr.mac,
2741 GNUNET_STATISTICS_update (plugin->env->stats,
2742 _("# wlan fragments received"), 1, GNUNET_NO);
2744 GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag,
2747 if (ret == GNUNET_NO)
2749 session_light->macendpoint->dups++;
2751 else if (ret == GNUNET_OK)
2753 session_light->macendpoint->fragc++;
2755 set_next_send (plugin);
2761 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK)
2763 GNUNET_assert (session_light != NULL);
2764 if (session_light->macendpoint == NULL)
2766 session_light->macendpoint =
2767 get_macendpoint (plugin, &session_light->addr, GNUNET_NO);
2770 if (session_light->macendpoint == NULL)
2772 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2773 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n",
2774 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2775 session_light->addr.mac,
2780 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2781 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n",
2782 ntohs (hdr->size), session_light->macendpoint,
2783 wlan_plugin_address_to_string (NULL,
2784 session_light->addr.mac,
2786 fm = session_light->macendpoint->sending_messages_head;
2790 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"),
2792 int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
2794 if (ret == GNUNET_OK)
2796 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2797 "Got last ack, finished fragment message %p\n", fm);
2798 session_light->macendpoint->acks++;
2799 fm->session->last_activity = GNUNET_TIME_absolute_get ();
2800 session_light->macendpoint->last_activity = fm->session->last_activity;
2801 free_fragment_message (plugin, fm);
2802 check_fragment_queue (plugin);
2805 if (ret == GNUNET_NO)
2807 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2808 "Got ack for: %p\n", fm);
2809 session_light->macendpoint->acks++;
2812 if (ret == GNUNET_SYSERR)
2820 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2821 "WLAN fragment not in fragment list\n");
2828 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2829 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n",
2830 ntohs (hdr->type), ntohs (hdr->size));
2836 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2837 "Helper finished\n");
2843 * Function to print mac addresses nicely.
2845 * @param mac the mac address
2846 * @return string to a static buffer with the human-readable mac, will be overwritten during the next call to this function
2849 macprinter (const u_int8_t * mac)
2851 static char macstr[20];
2853 GNUNET_snprintf (macstr, sizeof (macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1],
2854 mac[2], mac[3], mac[4], mac[5]);
2859 * Function for the scheduler if a mac endpoint times out
2860 * @param cls pointer to the MacEndpoint
2861 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
2864 macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2866 struct MacEndpoint *endpoint = cls;
2868 GNUNET_assert (endpoint != NULL);
2869 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2870 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
2874 if (GNUNET_TIME_absolute_get_remaining
2875 (GNUNET_TIME_absolute_add
2876 (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0)
2878 GNUNET_assert (endpoint->plugin != NULL);
2879 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
2880 _("# wlan mac endpoints timeouts"), 1, GNUNET_NO);
2881 free_macendpoint (endpoint->plugin, endpoint);
2885 endpoint->timeout_task =
2886 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
2892 * function to create an macendpoint
2893 * @param plugin pointer to the plugin struct
2894 * @param addr pointer to the macaddress
2895 * @return returns a macendpoint
2897 static struct MacEndpoint *
2898 create_macendpoint (struct Plugin *plugin, const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr)
2900 struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
2902 GNUNET_assert (plugin != NULL);
2903 GNUNET_STATISTICS_update (plugin->env->stats,
2904 _("# wlan mac endpoints created"), 1, GNUNET_NO);
2905 newend->addr = *addr;
2906 newend->plugin = plugin;
2907 newend->addr = *addr;
2908 newend->fragment_messages_out_count = 0;
2910 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
2911 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
2912 newend, &wlan_data_message_handler,
2914 newend->last_activity = GNUNET_TIME_absolute_get ();
2915 newend->timeout_task =
2916 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
2919 plugin->mac_count++;
2920 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
2921 plugin->mac_count, GNUNET_NO);
2922 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
2923 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2924 "New Mac Endpoint %p: %s\n", newend,
2925 wlan_plugin_address_to_string (NULL, newend->addr.mac, 6));
2930 * Function used for to process the data from the suid process
2932 * @param cls the plugin handle
2933 * @param client client that send the data (not used)
2934 * @param hdr header of the GNUNET_MessageHeader
2937 wlan_process_helper (void *cls, void *client,
2938 const struct GNUNET_MessageHeader *hdr)
2940 struct Plugin *plugin = cls;
2941 struct ieee80211_frame *wlanIeeeHeader = NULL;
2942 struct Session_light *session_light = NULL;
2943 struct Radiotap_rx *rxinfo;
2944 const struct GNUNET_MessageHeader *temp_hdr = NULL;
2949 GNUNET_assert (plugin != NULL);
2950 switch (ntohs (hdr->type))
2952 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
2953 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2954 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
2956 GNUNET_STATISTICS_update (plugin->env->stats,
2957 _("# wlan WLAN_HELPER_DATA received"), 1,
2959 //call wlan_process_helper with the message inside, later with wlan: analyze signal
2960 if (ntohs (hdr->size) <
2961 sizeof (struct ieee80211_frame) +
2962 2 * sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx))
2964 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2965 "Size of packet is too small; size: %u min size: %u\n",
2967 sizeof (struct ieee80211_frame) +
2968 sizeof (struct GNUNET_MessageHeader));
2970 /* FIXME: restart SUID process */
2974 rxinfo = (struct Radiotap_rx *) &hdr[1];
2975 wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1];
2977 //process only if it is an broadcast or for this computer both with the gnunet bssid
2981 (&(wlanIeeeHeader->i_addr3), &mac_bssid_gnunet,
2982 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
2984 //check for broadcast or mac
2986 (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
2987 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0) ||
2989 (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
2990 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0))
2992 //if packet is from us return
2994 (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address),
2995 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0))
2999 // process the inner data
3003 ntohs (hdr->size) - sizeof (struct ieee80211_frame) -
3004 sizeof (struct GNUNET_MessageHeader) - sizeof (struct Radiotap_rx);
3006 session_light = GNUNET_malloc (sizeof (struct Session_light));
3007 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
3008 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
3009 //session_light->session = search_session(plugin,session_light->addr);
3010 GNUNET_STATISTICS_update (plugin->env->stats,
3011 _("# wlan messages for this client received"),
3015 while (pos < datasize)
3017 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
3018 if (ntohs (temp_hdr->size) <= datasize + pos)
3020 GNUNET_STATISTICS_update (plugin->env->stats,
3022 ("# wlan messages inside WLAN_HELPER_DATA received"),
3024 wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
3028 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3029 "Size of packet is too small; size: %u > size of packet: %u\n",
3030 ntohs (temp_hdr->size), datasize + pos);
3032 pos += ntohs (temp_hdr->size);
3037 GNUNET_free (session_light);
3041 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3042 "Func wlan_process_helper got wrong MAC: %s\n",
3043 macprinter (wlanIeeeHeader->i_addr1));
3048 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3049 "Func wlan_process_helper got wrong BSSID: %s\n",
3050 macprinter (wlanIeeeHeader->i_addr2));
3053 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
3054 //TODO more control messages
3055 if (ntohs (hdr->size) != sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
3058 /* FIXME: restart SUID process */
3061 memcpy (&plugin->mac_address, &hdr[1], sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
3062 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3063 "Received WLAN_HELPER_CONTROL message with transport of address %s\n",
3064 wlan_plugin_address_to_string (cls, &plugin->mac_address,
3065 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)));
3066 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
3067 &plugin->mac_address,
3068 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
3071 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3072 "Func wlan_process_helper got unknown message with number %u, size %u\n",
3073 ntohs (hdr->type), ntohs (hdr->size));
3076 hexdump (hdr, GNUNET_MIN (ntohs (hdr->size), 256));
3084 * Exit point from the plugin.
3085 * @param cls pointer to the api struct
3090 libgnunet_plugin_transport_wlan_done (void *cls)
3092 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3093 struct Plugin *plugin = api->cls;
3094 struct MacEndpoint *endpoint = plugin->mac_head;
3095 struct MacEndpoint *endpoint_next;
3097 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3098 "libgnunet_plugin_transport_wlan_done started\n");
3099 wlan_transport_stop_wlan_helper (plugin);
3101 GNUNET_assert (cls != NULL);
3103 while (endpoint != NULL)
3105 endpoint_next = endpoint->next;
3106 free_macendpoint (plugin, endpoint);
3107 endpoint = endpoint_next;
3112 if (plugin->suid_tokenizer != NULL)
3113 GNUNET_SERVER_mst_destroy (plugin->suid_tokenizer);
3115 if (plugin->data_tokenizer != NULL)
3116 GNUNET_SERVER_mst_destroy (plugin->data_tokenizer);
3118 GNUNET_free_non_null (plugin->interface);
3119 GNUNET_free (plugin);
3125 * Entry point for the plugin.
3127 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
3128 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
3131 libgnunet_plugin_transport_wlan_init (void *cls)
3133 //struct GNUNET_SERVICE_Context *service;
3134 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3135 struct GNUNET_TRANSPORT_PluginFunctions *api;
3136 struct Plugin *plugin;
3138 GNUNET_assert (cls != NULL);
3140 plugin = GNUNET_malloc (sizeof (struct Plugin));
3142 plugin->pendingsessions = 0;
3143 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
3144 plugin->pendingsessions, GNUNET_NO);
3145 plugin->mac_count = 0;
3146 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
3147 plugin->mac_count, GNUNET_NO);
3148 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
3149 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
3150 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
3151 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
3152 GNUNET_BANDWIDTH_value_init (100 * 1024 *
3155 plugin->suid_tokenizer =
3156 GNUNET_SERVER_mst_create (&wlan_process_helper, plugin);
3158 plugin->data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
3160 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
3161 //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue));
3163 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
3165 api->send = &wlan_plugin_send;
3166 api->get_session = &wlan_plugin_get_session;
3167 api->disconnect = &wlan_plugin_disconnect;
3168 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
3169 api->check_address = &wlan_plugin_address_suggested;
3170 api->address_to_string = &wlan_plugin_address_to_string;
3174 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE"))
3176 if (GNUNET_SYSERR ==
3177 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
3178 "TESTMODE", &(plugin->testmode)))
3179 plugin->testmode = 0; //default value
3182 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE"))
3184 if (GNUNET_CONFIGURATION_get_value_string
3185 (env->cfg, "transport-wlan", "INTERFACE",
3186 &(plugin->interface)) != GNUNET_YES)
3188 libgnunet_plugin_transport_wlan_done (api);
3194 wlan_transport_start_wlan_helper (plugin);
3195 set_next_beacon_time (plugin);
3196 set_next_send (plugin);
3197 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3198 "wlan init finished\n");
3202 /* end of plugin_transport_wlan.c */