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"
44 #define PROTOCOL_PREFIX "wlan"
46 #define PLUGIN_LOG_NAME "wlan-plugin"
54 * time out of a session
56 #define SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
59 * time out of a mac endpoint
61 #define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2)
64 * scaling factor for hello beacon
66 #define HELLO_BEACON_SCALING_FACTOR 30
69 * scaling factor for restarting the helper
71 #define HELPER_RESTART_SCALING_FACTOR 2
74 * max size of fragment queue
76 #define FRAGMENT_QUEUE_SIZE 10
78 * max messages in fragment queue per session/client
80 #define FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION 1
83 * max messages in fragment queue per MAC
85 #define FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT 1
88 * max messages in in queue
90 #define MESSAGES_IN_QUEUE_SIZE 10
92 * max messages in in queue per session/client
94 #define MESSAGES_IN_DEFRAG_QUEUE_PER_MAC 1
97 * LLC fields for better compatibility
99 #define WLAN_LLC_DSAP_FIELD 0x1f
100 #define WLAN_LLC_SSAP_FIELD 0x1f
106 #define DEBUG_wlan GNUNET_EXTRA_LOGGING
107 #define DEBUG_wlan_retransmission GNUNET_EXTRA_LOGGING
108 #define DEBUG_wlan_ip_udp_packets_on_air GNUNET_NO
109 #define DEBUG_wlan_msg_dump GNUNET_EXTRA_LOGGING
112 #define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
114 #define IEEE80211_FC0_VERSION_MASK 0x03
115 #define IEEE80211_FC0_VERSION_SHIFT 0
116 #define IEEE80211_FC0_VERSION_0 0x00
117 #define IEEE80211_FC0_TYPE_MASK 0x0c
118 #define IEEE80211_FC0_TYPE_SHIFT 2
119 #define IEEE80211_FC0_TYPE_MGT 0x00
120 #define IEEE80211_FC0_TYPE_CTL 0x04
121 #define IEEE80211_FC0_TYPE_DATA 0x08
124 * Structure of an internet header, naked of options.
128 #if __BYTE_ORDER == __LITTLE_ENDIAN
129 unsigned int ip_hl:4; /* header length */
130 unsigned int ip_v:4; /* version */
132 #if __BYTE_ORDER == __BIG_ENDIAN
133 unsigned int ip_v:4; /* version */
134 unsigned int ip_hl:4; /* header length */
136 u_int8_t ip_tos; /* type of service */
137 u_short ip_len; /* total length */
138 u_short ip_id; /* identification */
139 u_short ip_off; /* fragment offset field */
140 #define IP_RF 0x8000 /* reserved fragment flag */
141 #define IP_DF 0x4000 /* dont fragment flag */
142 #define IP_MF 0x2000 /* more fragments flag */
143 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
144 u_int8_t ip_ttl; /* time to live */
145 u_int8_t ip_p; /* protocol */
146 u_short ip_sum; /* checksum */
147 struct in_addr ip_src, ip_dst; /* source and dest address */
159 * generic definitions for IEEE 802.11 frames
161 struct ieee80211_frame
165 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
166 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
167 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
170 #if DEBUG_wlan_ip_udp_packets_on_air > 1
177 * Encapsulation of all of the state of the plugin.
184 struct GNUNET_TRANSPORT_PluginEnvironment *env;
187 * List of open connections. head
189 struct MacEndpoint *mac_head;
192 * List of open connections. tail
194 struct MacEndpoint *mac_tail;
197 * Number of connections
199 unsigned int mac_count;
202 * encapsulation of data from the local wlan helper program
204 struct GNUNET_SERVER_MessageStreamTokenizer *suid_tokenizer;
207 * encapsulation of packets received from the wlan helper
209 struct GNUNET_SERVER_MessageStreamTokenizer *data_tokenizer;
212 * stdout pipe handle for the gnunet-wlan-helper process
214 struct GNUNET_DISK_PipeHandle *server_stdout;
217 * stdout file handle for the gnunet-wlan-helper process
219 const struct GNUNET_DISK_FileHandle *server_stdout_handle;
222 * stdin pipe handle for the gnunet-wlan-helper process
224 struct GNUNET_DISK_PipeHandle *server_stdin;
227 * stdin file handle for the gnunet-wlan-helper process
229 const struct GNUNET_DISK_FileHandle *server_stdin_handle;
232 * ID of the gnunet-wlan-server std read task
234 GNUNET_SCHEDULER_TaskIdentifier server_read_task;
237 * ID of the gnunet-wlan-server std read task
239 GNUNET_SCHEDULER_TaskIdentifier server_write_task;
242 * ID of the delay task for writing
244 GNUNET_SCHEDULER_TaskIdentifier server_write_delay_task;
247 * The process id of the wlan process
249 struct GNUNET_OS_Process *server_proc;
252 * The interface of the wlan card given to us by the user.
257 * Mode of operation for the helper, 0 = normal, 1 = first loopback, 2 = second loopback
259 long long unsigned int testmode;
262 * The mac_address of the wlan card given to us by the helper.
264 struct MacAddress mac_address;
267 * Sessions currently pending for transmission
270 struct Sessionqueue *pending_Sessions_head;
273 * Sessions currently pending for transmission
274 * to a peer (tail), if any.
276 struct Sessionqueue *pending_Sessions_tail;
279 * number of pending sessions
281 unsigned int pendingsessions;
284 * Messages in the sending queues
286 int pending_Fragment_Messages;
289 * messages ready for send, head
291 struct FragmentMessage_queue *sending_messages_head;
293 * messages ready for send, tail
295 struct FragmentMessage_queue *sending_messages_tail;
297 * time of the next "hello-beacon"
299 struct GNUNET_TIME_Absolute beacon_time;
302 * queue to send acks for received fragments (head)
304 struct AckSendQueue *ack_send_queue_head;
307 * queue to send acks for received fragments (tail)
309 struct AckSendQueue *ack_send_queue_tail;
312 * Tracker for bandwidth limit
314 struct GNUNET_BANDWIDTH_Tracker tracker;
317 * saves the current state of the helper process
319 int helper_is_running;
323 * Struct to store data if file write did not accept the whole packet
328 * pointer to the global plugin struct
330 struct Plugin *plugin;
333 * head of the next part to send to the helper
335 char *head_of_next_write;
338 * Start of the message to send, needed for free
340 struct GNUNET_MessageHeader *msgstart;
349 * Queue of sessions, for the general session queue and the pending session queue
354 struct Sessionqueue *next;
355 struct Sessionqueue *prev;
356 struct Session *content;
357 #if !HAVE_UNALIGNED_64_ACCESS
358 void *dummy; /* for alignment, see #1909 */
363 * Queue of fragmented messages, for the sending queue of the plugin
366 struct FragmentMessage_queue
368 struct FragmentMessage_queue *next;
369 struct FragmentMessage_queue *prev;
370 struct FragmentMessage *content;
374 * Queue for the fragments received
377 struct Receive_Fragment_Queue
379 struct Receive_Fragment_Queue *next;
380 struct Receive_Fragment_Queue *prev;
384 struct Radiotap_rx rxinfo;
388 struct MacEndpoint_id_fragment_triple
390 struct MacEndpoint *endpoint;
392 struct FragmentMessage *fm;
396 struct Plugin_Session_pair
398 struct Plugin *plugin;
399 struct Session *session;
403 * Information kept for each message that is yet to
406 struct PendingMessage
411 struct PendingMessage *next;
415 struct PendingMessage *prev;
418 * The pending message
420 struct WlanHeader *msg;
423 * Size of the message
428 * Continuation function to call once the message
429 * has been sent. Can be NULL if there is no
430 * continuation to call.
432 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
435 * Cls for transmit_cont
437 void *transmit_cont_cls;
440 * Timeout value for the pending message.
442 struct GNUNET_TIME_Absolute timeout;
447 * Queue for acks to send for fragments recived
453 * next ack in the ack send queue
455 struct AckSendQueue *next;
457 * previous ack in the ack send queue
459 struct AckSendQueue *prev;
461 * pointer to the session this ack belongs to
463 struct MacEndpoint *endpoint;
465 * ID of message, to distinguish between the messages, picked randomly.
472 struct GNUNET_MessageHeader *hdr;
474 * pointer to the ieee wlan header
476 struct ieee80211_frame *ieeewlanheader;
478 * pointer to the radiotap header
480 struct Radiotap_Send *radioHeader;
484 * 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
650 struct FragmentMessage
654 * Session this message belongs to
656 struct Session *session;
659 * This is a doubly-linked list.
661 struct FragmentMessage *next;
664 * This is a doubly-linked list.
666 struct FragmentMessage *prev;
669 * Fragmentation context
671 struct GNUNET_FRAGMENT_Context *fragcontext;
674 * Timeout value for the message.
676 struct GNUNET_TIME_Absolute timeout;
681 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
694 * pointer to the ieee wlan header
696 struct ieee80211_frame *ieeewlanheader;
698 * pointer to the radiotap header
700 struct Radiotap_Send *radioHeader;
704 do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
707 free_session (struct Plugin *plugin, struct Sessionqueue *queue,
708 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
902 static struct Session *
903 create_session (struct Plugin *plugin, struct MacEndpoint *endpoint,
904 const struct GNUNET_PeerIdentity *peer)
906 GNUNET_assert (endpoint != NULL);
907 GNUNET_assert (plugin != NULL);
908 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1,
910 struct Sessionqueue *queue =
911 GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session));
913 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
914 endpoint->sessions_tail, queue);
916 queue->content = (struct Session *) &queue[1];
917 queue->content->mac = endpoint;
918 queue->content->target = *peer;
919 queue->content->last_activity = GNUNET_TIME_absolute_get ();
920 queue->content->timeout_task =
921 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
924 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
925 "New session %p with endpoint %p: %s\n", queue->content,
926 endpoint, wlan_plugin_address_to_string (NULL,
931 return queue->content;
935 * Get session from address, create if no session exists
937 * @param plugin pointer to the plugin struct
938 * @param addr pointer to the mac address of the peer
939 * @param peer pointer to the peerid
940 * @return returns the session
942 static struct Session *
943 get_session (struct Plugin *plugin, const struct MacAddress *addr,
944 const struct GNUNET_PeerIdentity *peer)
946 struct MacEndpoint *mac;
948 mac = get_macendpoint (plugin, addr, GNUNET_YES);
949 struct Session *session = search_session (plugin, mac, peer);
953 return create_session (plugin, mac, peer);
957 * Queue the session to send data
958 * checks if there is a message pending
959 * checks if this session is not allready in the queue
960 * @param plugin pointer to the plugin
961 * @param session pointer to the session to add
964 queue_session (struct Plugin *plugin, struct Session *session)
966 struct Sessionqueue *queue = plugin->pending_Sessions_head;
968 if (session->pending_message_head != NULL)
970 while (queue != NULL)
972 // content is never NULL
973 GNUNET_assert (queue->content != NULL);
974 // is session already in queue?
975 if (session == queue->content)
983 // Session is not in the queue
985 queue = GNUNET_malloc (sizeof (struct Sessionqueue));
986 queue->content = session;
989 GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head,
990 plugin->pending_Sessions_tail, queue);
991 plugin->pendingsessions++;
992 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
993 plugin->pendingsessions, GNUNET_NO);
999 * Function to schedule the write task, executed after a delay
1000 * @param cls pointer to the plugin struct
1001 * @param tc GNUNET_SCHEDULER_TaskContext pointer
1004 delay_fragment_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1006 struct Plugin *plugin = cls;
1008 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1010 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1013 // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg
1014 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1016 plugin->server_write_task =
1017 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1018 plugin->server_stdin_handle,
1019 &do_transmit, plugin);
1024 * Function to calculate the time of the next periodic "hello-beacon"
1025 * @param plugin pointer to the plugin struct
1028 set_next_beacon_time (struct Plugin *const plugin)
1030 //under 10 known peers: once a second
1031 if (plugin->mac_count < 10)
1033 plugin->beacon_time =
1034 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1035 GNUNET_TIME_relative_multiply
1036 (GNUNET_TIME_UNIT_SECONDS,
1037 HELLO_BEACON_SCALING_FACTOR));
1039 //under 30 known peers: every 10 seconds
1040 else if (plugin->mac_count < 30)
1042 plugin->beacon_time =
1043 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1044 GNUNET_TIME_relative_multiply
1045 (GNUNET_TIME_UNIT_SECONDS,
1046 10 * HELLO_BEACON_SCALING_FACTOR));
1048 //over 30 known peers: once a minute
1051 plugin->beacon_time =
1052 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1053 GNUNET_TIME_relative_multiply
1054 (GNUNET_TIME_UNIT_MINUTES,
1055 HELLO_BEACON_SCALING_FACTOR));
1060 * Function to set the timer for the next timeout of the fragment queue
1061 * @param plugin the handle to the plugin struct
1064 set_next_send (struct Plugin *const plugin)
1066 struct GNUNET_TIME_Relative next_send;
1068 //abort if helper is not running
1069 if (plugin->helper_is_running == GNUNET_NO)
1075 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1077 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1078 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1081 //check if some acks are in the queue
1082 if (plugin->ack_send_queue_head != NULL)
1084 next_send = GNUNET_TIME_UNIT_ZERO;
1087 //check if there are some fragments in the queue
1088 else if (plugin->sending_messages_head != NULL)
1090 next_send = GNUNET_TIME_UNIT_ZERO;
1094 next_send = GNUNET_TIME_absolute_get_remaining (plugin->beacon_time);
1098 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1099 "Next packet is send in: %u\n", next_send.rel_value);
1102 if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value)
1104 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1106 plugin->server_write_task =
1107 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1108 plugin->server_stdin_handle,
1109 &do_transmit, plugin);
1114 if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK)
1116 plugin->server_write_delay_task =
1117 GNUNET_SCHEDULER_add_delayed (next_send, &delay_fragment_task,
1124 * Function to get the next queued Session, removes the session from the queue
1125 * @param plugin pointer to the plugin struct
1126 * @return pointer to the session found, returns NULL if there is now session in the queue
1128 static struct Session *
1129 get_next_queue_session (struct Plugin *plugin)
1131 struct Session *session;
1132 struct Sessionqueue *sessionqueue;
1133 struct Sessionqueue *sessionqueue_alt;
1134 struct PendingMessage *pm;
1136 sessionqueue = plugin->pending_Sessions_head;
1138 while (sessionqueue != NULL)
1140 session = sessionqueue->content;
1142 GNUNET_assert (session != NULL);
1143 pm = session->pending_message_head;
1148 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1149 "pending message is empty, should not happen. session %p\n",
1152 sessionqueue_alt = sessionqueue;
1153 sessionqueue = sessionqueue->next;
1154 plugin->pendingsessions--;
1155 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1156 plugin->pendingsessions, GNUNET_NO);
1157 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1158 plugin->pending_Sessions_tail,
1161 GNUNET_free (sessionqueue_alt);
1166 //check for message timeout
1167 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
1169 //check if session has no message in the fragment queue
1170 if ((session->mac->fragment_messages_out_count <
1171 FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT) &&
1172 (session->fragment_messages_out_count <
1173 FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
1175 plugin->pendingsessions--;
1176 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1177 plugin->pendingsessions, GNUNET_NO);
1178 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1179 plugin->pending_Sessions_tail,
1181 GNUNET_free (sessionqueue);
1187 sessionqueue = sessionqueue->next;
1192 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1193 session->pending_message_tail, pm);
1195 //call the cont func that it did not work
1196 if (pm->transmit_cont != NULL)
1197 pm->transmit_cont (pm->transmit_cont_cls, &(session->target),
1199 GNUNET_free (pm->msg);
1202 if (session->pending_message_head == NULL)
1204 sessionqueue_alt = sessionqueue;
1205 sessionqueue = sessionqueue->next;
1206 plugin->pendingsessions--;
1207 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1208 plugin->pendingsessions, GNUNET_NO);
1209 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1210 plugin->pending_Sessions_tail,
1213 GNUNET_free (sessionqueue_alt);
1222 * frees the space of a message in the fragment queue (send queue)
1223 * @param plugin the plugin struct
1224 * @param fm message to free
1227 free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm)
1229 struct Session *session = fm->session;
1230 struct MacEndpoint *endpoint = session->mac;
1231 struct FragmentMessage_queue *fmq;
1232 struct FragmentMessage_queue *fmq_next;
1234 fmq = plugin->sending_messages_head;
1237 fmq_next = fmq->next;
1238 if (fmq->content == fm)
1240 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1241 plugin->sending_messages_tail, fmq);
1247 (session->mac->fragment_messages_out_count)--;
1248 session->fragment_messages_out_count--;
1249 plugin->pending_Fragment_Messages--;
1250 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
1251 plugin->pending_Fragment_Messages, GNUNET_NO);
1252 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
1253 endpoint->sending_messages_tail, fm);
1254 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
1255 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1257 GNUNET_SCHEDULER_cancel (fm->timeout_task);
1258 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1263 queue_session (plugin, session);
1265 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1266 "Free pending fragment messages %p, session %p\n", fm,
1272 * function to fill the radiotap header
1273 * @param plugin pointer to the plugin struct
1274 * @param endpoint pointer to the endpoint
1275 * @param header pointer to the radiotap header
1276 * @return GNUNET_YES at success
1279 getRadiotapHeader (struct Plugin *plugin, struct MacEndpoint *endpoint,
1280 struct Radiotap_Send *header)
1283 if (endpoint != NULL)
1285 header->rate = endpoint->rate;
1286 header->tx_power = endpoint->tx_power;
1287 header->antenna = endpoint->antenna;
1292 header->tx_power = 0;
1293 header->antenna = 0;
1300 * function to generate the wlan hardware header for one packet
1301 * @param Header address to write the header to
1302 * @param to_mac_addr address of the recipient
1303 * @param plugin pointer to the plugin struct
1304 * @param size size of the whole packet, needed to calculate the time to send the packet
1305 * @return GNUNET_YES if there was no error
1308 getWlanHeader (struct ieee80211_frame *Header,
1309 const struct MacAddress *to_mac_addr, struct Plugin *plugin,
1313 const int rate = 11000000;
1315 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA;
1316 Header->i_fc[1] = 0x00;
1317 memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid));
1318 memcpy (&Header->i_addr2, plugin->mac_address.mac,
1319 sizeof (plugin->mac_address));
1320 memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress));
1322 tmp16 = (uint16_t *) Header->i_dur;
1323 *tmp16 = (uint16_t) GNUNET_htole16 ((size * 1000000) / rate + 290);
1324 Header->llc[0] = WLAN_LLC_DSAP_FIELD;
1325 Header->llc[1] = WLAN_LLC_SSAP_FIELD;
1327 #if DEBUG_wlan_ip_udp_packets_on_air > 1
1332 Header->ip.ip_dst.s_addr = *((uint32_t *) & to_mac_addr->mac[2]);
1333 Header->ip.ip_src.s_addr = *((uint32_t *) & plugin->mac_address.mac[2]);
1334 Header->ip.ip_v = 4;
1335 Header->ip.ip_hl = 5;
1336 Header->ip.ip_p = 17;
1337 Header->ip.ip_ttl = 1;
1338 Header->ip.ip_len = htons (size + 8);
1339 Header->ip.ip_sum = 0;
1340 x = (uint16_t *) & Header->ip;
1341 count = sizeof (struct iph);
1344 /* This is the inner loop */
1345 crc += (unsigned short) *x++;
1348 /* Add left-over byte, if any */
1350 crc += *(unsigned char *) x;
1351 crc = (crc & 0xffff) + (crc >> 16);
1352 Header->ip.ip_sum = htons (~(unsigned short) crc);
1353 Header->udp.len = htons (size - sizeof (struct ieee80211_frame));
1362 * function to add a fragment of a message to send
1363 * @param cls FragmentMessage this message belongs to
1364 * @param hdr pointer to the start of the message
1367 add_message_for_send (void *cls, const struct GNUNET_MessageHeader *hdr)
1370 struct FragmentMessage *fm = cls;
1371 struct FragmentMessage_queue *fmqueue;
1373 GNUNET_assert (cls != NULL);
1374 GNUNET_assert (fm->frag == NULL);
1375 struct MacEndpoint *endpoint = fm->session->mac;
1376 struct Plugin *plugin = endpoint->plugin;
1377 struct GNUNET_MessageHeader *msgheader;
1378 struct GNUNET_MessageHeader *msgheader2;
1381 #if DEBUG_wlan_retransmission > 1
1382 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1383 "Adding fragment of message %p to send, session %p, endpoint %p, type %u\n",
1384 fm, fm->session, endpoint, hdr->type);
1388 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1389 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1390 fm->frag = GNUNET_malloc (size);
1393 msgheader = (struct GNUNET_MessageHeader *) fm->frag;
1394 msgheader->size = htons (size);
1395 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1397 fm->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1398 fm->ieeewlanheader = (struct ieee80211_frame *) &fm->radioHeader[1];
1399 msgheader2 = (struct GNUNET_MessageHeader *) &fm->ieeewlanheader[1];
1400 memcpy (msgheader2, hdr, ntohs (hdr->size));
1402 fmqueue = GNUNET_malloc (sizeof (struct FragmentMessage_queue));
1403 fmqueue->content = fm;
1405 GNUNET_CONTAINER_DLL_insert_tail (plugin->sending_messages_head,
1406 plugin->sending_messages_tail, fmqueue);
1407 set_next_send (plugin);
1412 * We have been notified that wlan-helper has written something to stdout.
1413 * Handle the output, then reschedule this function to be called again once
1414 * more is available.
1416 * @param cls the plugin handle
1417 * @param tc the scheduling context
1420 wlan_plugin_helper_read (void *cls,
1421 const struct GNUNET_SCHEDULER_TaskContext *tc)
1423 struct Plugin *plugin = cls;
1425 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1427 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1430 char mybuf[WLAN_MTU + sizeof (struct GNUNET_MessageHeader)];
1434 GNUNET_DISK_file_read (plugin->server_stdout_handle, mybuf,
1439 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1441 ("Finished reading from wlan-helper stdout with code: %d\n"),
1446 GNUNET_SERVER_mst_receive (plugin->suid_tokenizer, NULL, mybuf, bytes,
1447 GNUNET_NO, GNUNET_NO);
1449 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
1450 plugin->server_read_task =
1451 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1452 plugin->server_stdout_handle,
1453 &wlan_plugin_helper_read, plugin);
1457 * Start the gnunet-wlan-helper process.
1459 * @param plugin the transport plugin
1460 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
1463 wlan_transport_start_wlan_helper (struct Plugin *plugin)
1465 const char *filenamehw = "gnunet-transport-wlan-helper";
1466 const char *filenameloopback = "gnunet-transport-wlan-helper-dummy";
1467 char *absolute_filename = NULL;
1469 if (plugin->helper_is_running == GNUNET_YES)
1472 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1473 "wlan_transport_start_wlan_helper not needed, helper already running!");
1478 plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
1479 if (plugin->server_stdout == NULL)
1480 return GNUNET_SYSERR;
1482 plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
1483 if (plugin->server_stdin == NULL)
1484 return GNUNET_SYSERR;
1486 if ((plugin->testmode == 1) || (plugin->testmode == 2))
1488 if (GNUNET_OS_check_helper_binary (filenameloopback) == GNUNET_YES)
1490 absolute_filename = GNUNET_strdup (filenameloopback);
1494 char cwd[FILENAME_MAX];
1496 GNUNET_assert (getcwd (cwd, sizeof (cwd)) != NULL);
1498 GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR,
1501 if (GNUNET_DISK_file_test (filenameloopback) != GNUNET_YES)
1503 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1504 "Helper `%s' not found! %i\n", absolute_filename);
1510 /* Start the server process */
1512 if (plugin->testmode == 0)
1516 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1517 "Starting gnunet-wlan-helper process cmd: %s %s %i\n",
1518 filenamehw, plugin->interface, plugin->testmode);
1521 if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_YES)
1523 plugin->server_proc =
1524 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1525 filenamehw, filenamehw, plugin->interface,
1528 else if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_NO)
1530 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1531 "gnunet-transport-wlan-helper is not suid, please change it or look at the doku\n");
1536 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1537 "gnunet-transport-wlan-helper not found, please look if it exists and is the $PATH variable!\n");
1542 else if (plugin->testmode == 1)
1546 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
1547 "Starting gnunet-transport-wlan-helper-dummy loopback 1 process cmd: %s %s %i\n",
1548 absolute_filename, plugin->interface, plugin->testmode);
1550 plugin->server_proc =
1551 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1552 absolute_filename, absolute_filename, "1",
1554 if (plugin->server_proc == NULL)
1556 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1557 "`%s' not found, please look if it exists and is in the $PATH variable!\n",
1562 else if (plugin->testmode == 2)
1565 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
1566 "Starting gnunet-transport-wlan-helper-dummy loopback 2 process cmd: %s %s %i\n",
1567 absolute_filename, plugin->interface, plugin->testmode);
1570 plugin->server_proc =
1571 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1572 absolute_filename, absolute_filename, "2",
1574 if (plugin->server_proc == NULL)
1576 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1577 "`%s' not found, please look if it exists and is in the $PATH variable!\n",
1582 if (absolute_filename != NULL)
1583 GNUNET_free (absolute_filename);
1584 if (plugin->server_proc == NULL)
1587 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1588 "Failed to start gnunet-transport-wlan-helper process\n");
1590 return GNUNET_SYSERR;
1595 /* Close the write end of the read pipe */
1596 GNUNET_DISK_pipe_close_end (plugin->server_stdout,
1597 GNUNET_DISK_PIPE_END_WRITE);
1599 /* Close the read end of the write pipe */
1600 GNUNET_DISK_pipe_close_end (plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
1602 plugin->server_stdout_handle =
1603 GNUNET_DISK_pipe_handle (plugin->server_stdout,
1604 GNUNET_DISK_PIPE_END_READ);
1605 plugin->server_stdin_handle =
1606 GNUNET_DISK_pipe_handle (plugin->server_stdin,
1607 GNUNET_DISK_PIPE_END_WRITE);
1609 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
1612 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1613 "Adding server_read_task for the wlan-helper\n");
1616 plugin->server_read_task =
1617 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1618 plugin->server_stdout_handle,
1619 &wlan_plugin_helper_read, plugin);
1621 plugin->helper_is_running = GNUNET_YES;
1626 * Stops the gnunet-wlan-helper process.
1628 * @param plugin the transport plugin
1629 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
1632 wlan_transport_stop_wlan_helper (struct Plugin *plugin)
1635 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1636 "Stoping WLAN helper process\n");
1639 if (plugin->helper_is_running == GNUNET_NO)
1642 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1643 "wlan_transport_stop_wlan_helper not needed, helper already stopped!");
1648 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1650 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1651 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1654 if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK)
1656 GNUNET_SCHEDULER_cancel (plugin->server_write_task);
1657 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1660 if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK)
1662 GNUNET_SCHEDULER_cancel (plugin->server_read_task);
1663 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1666 GNUNET_DISK_pipe_close (plugin->server_stdout);
1667 GNUNET_DISK_pipe_close (plugin->server_stdin);
1668 GNUNET_OS_process_kill (plugin->server_proc, SIGKILL);
1669 GNUNET_OS_process_wait (plugin->server_proc);
1670 GNUNET_OS_process_close (plugin->server_proc);
1672 plugin->helper_is_running = GNUNET_NO;
1678 * function for delayed restart of the helper process
1679 * @param cls Finish_send struct if message should be finished
1680 * @param tc TaskContext
1683 delay_restart_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1685 struct Finish_send *finish = cls;
1686 struct Plugin *plugin;
1688 plugin = finish->plugin;
1690 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1691 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1693 GNUNET_free_non_null (finish->msgstart);
1694 GNUNET_free (finish);
1698 wlan_transport_start_wlan_helper (plugin);
1700 if (finish->size != 0)
1702 plugin->server_write_task =
1703 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1704 plugin->server_stdin_handle,
1705 &finish_sending, finish);
1709 set_next_send (plugin);
1710 GNUNET_free_non_null (finish->msgstart);
1711 GNUNET_free (finish);
1717 * Function to restart the helper
1718 * @param plugin pointer to the global plugin struct
1719 * @param finish pointer to the Finish_send struct to finish
1722 restart_helper (struct Plugin *plugin, struct Finish_send *finish)
1724 static struct GNUNET_TIME_Relative next_try = { 1000 };
1725 GNUNET_assert (finish != NULL);
1727 wlan_transport_stop_wlan_helper (plugin);
1728 plugin->server_write_task =
1729 GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish);
1730 GNUNET_TIME_relative_multiply (next_try, HELPER_RESTART_SCALING_FACTOR);
1735 * function to finish a sending if not all could have been writen befor
1736 * @param cls pointer to the Finish_send struct
1737 * @param tc TaskContext
1740 finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1742 struct Finish_send *finish = cls;
1743 struct Plugin *plugin;
1746 plugin = finish->plugin;
1747 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1749 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1751 GNUNET_free (finish->msgstart);
1752 GNUNET_free (finish);
1756 GNUNET_DISK_file_write (plugin->server_stdin_handle,
1757 finish->head_of_next_write, finish->size);
1759 if (bytes != finish->size)
1761 if (bytes != GNUNET_SYSERR)
1763 finish->head_of_next_write += bytes;
1764 finish->size -= bytes;
1765 plugin->server_write_task =
1766 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1767 plugin->server_stdin_handle,
1768 &finish_sending, finish);
1772 restart_helper (plugin, finish);
1777 GNUNET_free (finish->msgstart);
1778 GNUNET_free (finish);
1779 set_next_send (plugin);
1784 * function to send a hello beacon
1785 * @param plugin pointer to the plugin struct
1788 send_hello_beacon (struct Plugin *plugin)
1792 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1793 "Sending hello beacon\n");
1798 uint16_t hello_size;
1799 struct GNUNET_MessageHeader *msgheader;
1800 struct ieee80211_frame *ieeewlanheader;
1801 struct Radiotap_Send *radioHeader;
1802 struct GNUNET_MessageHeader *msgheader2;
1803 const struct GNUNET_MessageHeader *hello;
1804 struct Finish_send *finish;
1806 GNUNET_assert (plugin != NULL);
1808 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"),
1811 hello = plugin->env->get_our_hello ();
1812 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1813 GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
1815 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1816 sizeof (struct ieee80211_frame) + hello_size;
1818 msgheader = GNUNET_malloc (size);
1819 msgheader->size = htons (size);
1820 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1822 radioHeader = (struct Radiotap_Send *) &msgheader[1];
1823 getRadiotapHeader (plugin, NULL, radioHeader);
1824 ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
1825 getWlanHeader (ieeewlanheader, &bc_all_mac, plugin, size);
1827 msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1];
1828 /*msgheader2->size =
1829 * htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) +
1830 * sizeof (struct GNUNET_MessageHeader));
1832 * msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); */
1833 memcpy (msgheader2, hello, hello_size);
1835 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size);
1837 if (bytes == GNUNET_SYSERR)
1839 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1841 ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
1842 errno, strerror (errno));
1843 finish = GNUNET_malloc (sizeof (struct Finish_send));
1844 finish->plugin = plugin;
1845 finish->head_of_next_write = NULL;
1847 finish->msgstart = NULL;
1848 restart_helper (plugin, finish);
1850 set_next_beacon_time (plugin);
1855 GNUNET_assert (bytes == size);
1856 set_next_beacon_time (plugin);
1857 set_next_send (plugin);
1859 GNUNET_free (msgheader);
1865 * function to add an ack to send it for a received fragment
1866 * @param cls MacEndpoint this ack belongs to
1867 * @param msg_id id of the message
1868 * @param hdr pointer to the hdr where the ack is stored
1872 add_ack_for_send (void *cls, uint32_t msg_id,
1873 const struct GNUNET_MessageHeader *hdr)
1876 struct AckSendQueue *ack;
1878 GNUNET_assert (cls != NULL);
1879 struct MacEndpoint *endpoint = cls;
1880 struct Plugin *plugin = endpoint->plugin;
1881 struct GNUNET_MessageHeader *msgheader;
1882 struct GNUNET_MessageHeader *msgheader2;
1886 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1887 sizeof (struct ieee80211_frame) + ntohs (hdr->size) +
1888 sizeof (struct AckSendQueue);
1890 ack = GNUNET_malloc (size);
1891 ack->message_id = msg_id;
1892 ack->endpoint = endpoint;
1895 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1896 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1898 msgheader = (struct GNUNET_MessageHeader *) &ack[1];
1899 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1];
1900 msgheader->size = htons (size);
1901 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1903 ack->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1904 ack->ieeewlanheader = (struct ieee80211_frame *) &(ack->radioHeader)[1];
1905 msgheader2 = (struct GNUNET_MessageHeader *) &(ack->ieeewlanheader)[1];
1906 memcpy (msgheader2, hdr, ntohs (hdr->size));
1908 GNUNET_CONTAINER_DLL_insert_tail (plugin->ack_send_queue_head,
1909 plugin->ack_send_queue_tail, ack);
1911 #if DEBUG_wlan_retransmission > 1
1912 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1913 "Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n",
1914 msg_id, ack, endpoint);
1917 set_next_send (plugin);
1921 * Function for the scheduler if a FragmentMessage times out
1922 * @param cls pointer to the FragmentMessage
1923 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
1926 fragmentmessage_timeout (void *cls,
1927 const struct GNUNET_SCHEDULER_TaskContext *tc)
1929 struct FragmentMessage *fm = cls;
1931 GNUNET_assert (fm != NULL);
1932 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1933 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1937 free_fragment_message (fm->session->mac->plugin, fm);
1941 * Function to check if there is some space in the fragment queue
1942 * inserts a message if space is available
1943 * @param plugin the plugin struct
1947 check_fragment_queue (struct Plugin *plugin)
1949 struct Session *session;
1950 struct FragmentMessage *fm;
1951 struct GNUNET_PeerIdentity pid;
1953 struct PendingMessage *pm;
1955 if (plugin->pending_Fragment_Messages < FRAGMENT_QUEUE_SIZE)
1957 session = get_next_queue_session (plugin);
1958 if (session != NULL)
1960 pm = session->pending_message_head;
1961 GNUNET_assert (pm != NULL);
1962 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1963 session->pending_message_tail, pm);
1964 session->mac->fragment_messages_out_count++;
1965 session->fragment_messages_out_count++;
1966 plugin->pending_Fragment_Messages++;
1967 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
1968 plugin->pending_Fragment_Messages, GNUNET_NO);
1970 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
1971 fm->session = session;
1972 fm->timeout.abs_value = pm->timeout.abs_value;
1975 GNUNET_FRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
1977 GNUNET_TIME_UNIT_SECONDS,
1979 &add_message_for_send, fm);
1981 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
1982 (fm->timeout), fragmentmessage_timeout,
1984 GNUNET_CONTAINER_DLL_insert_tail (session->mac->sending_messages_head,
1985 session->mac->sending_messages_tail,
1988 if (pm->transmit_cont != NULL)
1990 pid = session->target;
1991 pm->transmit_cont (pm->transmit_cont_cls, &pid, GNUNET_OK);
1993 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1994 "called pm->transmit_cont for %p\n", session);
2000 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2001 "no pm->transmit_cont for %p\n", session);
2006 if (session->pending_message_head != NULL)
2009 queue_session (plugin, session);
2015 //check if timeout changed
2016 set_next_send (plugin);
2020 * Function to send an ack, does not free the ack
2021 * @param plugin pointer to the plugin
2024 send_ack (struct Plugin *plugin)
2028 struct AckSendQueue *ack;
2029 struct Finish_send *finish;
2031 ack = plugin->ack_send_queue_head;
2035 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2036 "Sending ack for message_id %u for mac endpoint %p, size %u\n",
2037 ack->message_id, ack->endpoint,
2038 ntohs (ack->hdr->size) - sizeof (struct Radiotap_Send));
2041 GNUNET_assert (plugin != NULL);
2042 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1,
2045 getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader);
2046 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
2047 ntohs (ack->hdr->size));
2050 GNUNET_DISK_file_write (plugin->server_stdin_handle, ack->hdr,
2051 ntohs (ack->hdr->size));
2052 if (bytes == GNUNET_SYSERR)
2054 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2056 ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
2057 errno, strerror (errno));
2058 finish = GNUNET_malloc (sizeof (struct Finish_send));
2059 finish->plugin = plugin;
2060 finish->head_of_next_write = NULL;
2062 finish->msgstart = NULL;
2063 restart_helper (plugin, finish);
2067 GNUNET_assert (bytes == ntohs (ack->hdr->size));
2068 GNUNET_CONTAINER_DLL_remove (plugin->ack_send_queue_head,
2069 plugin->ack_send_queue_tail, ack);
2071 set_next_send (plugin);
2076 * Function called when wlan helper is ready to get some data
2078 * @param cls closure
2079 * @param tc GNUNET_SCHEDULER_TaskContext
2082 do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2084 struct Plugin *plugin = cls;
2086 GNUNET_assert (plugin != NULL);
2088 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2089 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2092 struct Session *session;
2093 struct FragmentMessage *fm;
2094 struct Finish_send *finish;
2095 struct FragmentMessage_queue *fmq;
2098 if (plugin->ack_send_queue_head != NULL)
2104 //test if a "hello-beacon" has to be send
2105 if (GNUNET_TIME_absolute_get_remaining (plugin->beacon_time).rel_value == 0)
2107 send_hello_beacon (plugin);
2111 if (plugin->sending_messages_head != NULL)
2113 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1,
2116 fmq = plugin->sending_messages_head;
2118 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
2119 plugin->sending_messages_tail, fmq);
2122 session = fm->session;
2123 GNUNET_assert (session != NULL);
2126 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2127 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p, size: %u\n",
2131 getRadiotapHeader (plugin, session->mac, fm->radioHeader);
2132 getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
2136 GNUNET_DISK_file_write (plugin->server_stdin_handle, fm->frag,
2140 if (bytes != fm->size)
2142 finish = GNUNET_malloc (sizeof (struct Finish_send));
2143 finish->plugin = plugin;
2144 finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag;
2145 GNUNET_assert (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
2147 if (bytes == GNUNET_SYSERR)
2149 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2151 ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
2152 errno, strerror (errno));
2154 finish->head_of_next_write = fm->frag;
2155 finish->size = fm->size;
2156 restart_helper (plugin, finish);
2160 finish->head_of_next_write = fm->frag + bytes;
2161 finish->size = fm->size - bytes;
2162 plugin->server_write_task =
2163 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
2164 plugin->server_stdin_handle,
2165 &finish_sending, finish);
2172 GNUNET_free (fm->frag);
2174 set_next_send (plugin);
2176 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
2181 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2182 "do_transmit did nothing, should not happen!\n");
2184 set_next_send (plugin);
2188 * Another peer has suggested an address for this
2189 * peer and transport plugin. Check that this could be a valid
2190 * address. If so, consider adding it to the list
2193 * @param cls closure
2194 * @param addr pointer to the address
2195 * @param addrlen length of addr
2196 * @return GNUNET_OK if this is a plausible address for this peer
2200 wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
2202 //struct Plugin *plugin = cls;
2204 /* check if the address is plausible; if so,
2205 * add it to our list! */
2207 GNUNET_assert (cls != NULL);
2208 //FIXME mitm is not checked
2209 //Mac Address has 6 bytes
2212 /* TODO check for bad addresses like multicast, broadcast, etc */
2214 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2215 "wlan_plugin_address_suggested got good address, size %u!\n",
2221 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2222 "wlan_plugin_address_suggested got bad address, size %u!\n",
2225 return GNUNET_SYSERR;
2229 * Function that can be used by the transport service to transmit
2230 * a message using the plugin.
2232 * @param cls closure
2233 * @param target who should receive this message
2234 * @param priority how important is the message
2235 * @param msgbuf the message to transmit
2236 * @param msgbuf_size number of bytes in 'msgbuf'
2237 * @param timeout when should we time out
2238 * @param session which session must be used (or NULL for "any")
2239 * @param addr the address to use (can be NULL if the plugin
2240 * is "on its own" (i.e. re-use existing TCP connection))
2241 * @param addrlen length of the address in bytes
2242 * @param force_address GNUNET_YES if the plugin MUST use the given address,
2243 * otherwise the plugin may use other addresses or
2244 * existing connections (if available)
2245 * @param cont continuation to call once the message has
2246 * been transmitted (or if the transport is ready
2247 * for the next transmission call; or if the
2248 * peer disconnected...)
2249 * @param cont_cls closure for cont
2250 * @return number of bytes used (on the physical network, with overheads);
2251 * -1 on hard errors (i.e. address invalid); 0 is a legal value
2252 * and does NOT mean that the message was not transmitted (DV)
2255 wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
2256 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
2257 struct GNUNET_TIME_Relative timeout, struct Session *session,
2258 const void *addr, size_t addrlen, int force_address,
2259 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
2261 struct Plugin *plugin = cls;
2262 struct PendingMessage *newmsg;
2263 struct WlanHeader *wlanheader;
2265 GNUNET_assert (plugin != NULL);
2266 //check if msglen > 0
2267 GNUNET_assert (msgbuf_size > 0);
2269 //get session if needed
2270 if (session == NULL)
2272 if (wlan_plugin_address_suggested (plugin, addr, addrlen) == GNUNET_OK)
2274 session = get_session (plugin, addr, target);
2278 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2279 _("Wlan Address len %d is wrong\n"), addrlen);
2284 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1,
2289 //queue message in session
2290 //test if there is no other message in the "queue"
2291 //FIXME: to many send requests
2292 if (session->pending_message_head != NULL)
2294 newmsg = session->pending_message_head;
2295 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2296 "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",
2297 GNUNET_TIME_absolute_get_remaining (newmsg->
2299 session->mac->fragment_messages_out_count);
2302 newmsg = GNUNET_malloc (sizeof (struct PendingMessage));
2303 newmsg->msg = GNUNET_malloc (msgbuf_size + sizeof (struct WlanHeader));
2304 wlanheader = newmsg->msg;
2305 //copy msg to buffer, not fragmented / segmented yet, but with message header
2306 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
2307 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
2308 memcpy (&(wlanheader->target), target, sizeof (struct GNUNET_PeerIdentity));
2309 memcpy (&(wlanheader->source), plugin->env->my_identity,
2310 sizeof (struct GNUNET_PeerIdentity));
2311 wlanheader->crc = 0;
2312 memcpy (&wlanheader[1], msgbuf, msgbuf_size);
2314 htonl (GNUNET_CRYPTO_crc32_n
2315 ((char *) wlanheader, msgbuf_size + sizeof (struct WlanHeader)));
2317 newmsg->transmit_cont = cont;
2318 newmsg->transmit_cont_cls = cont_cls;
2319 newmsg->timeout = GNUNET_TIME_relative_to_absolute (timeout);
2321 newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
2323 newmsg->message_size = msgbuf_size + sizeof (struct WlanHeader);
2325 GNUNET_CONTAINER_DLL_insert_tail (session->pending_message_head,
2326 session->pending_message_tail, newmsg);
2329 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2330 "New message for %p with size (incl wlan header) %u added\n",
2331 session, newmsg->message_size);
2333 #if DEBUG_wlan_msg_dump > 1
2334 hexdump (msgbuf, GNUNET_MIN (msgbuf_size, 256));
2337 queue_session (plugin, session);
2339 check_fragment_queue (plugin);
2340 //FIXME not the correct size
2346 * function to free a mac endpoint
2347 * @param plugin pointer to the plugin struct
2348 * @param endpoint pointer to the MacEndpoint to free
2351 free_macendpoint (struct Plugin *plugin, struct MacEndpoint *endpoint)
2353 struct Sessionqueue *sessions;
2354 struct Sessionqueue *sessions_next;
2356 GNUNET_assert (endpoint != NULL);
2358 sessions = endpoint->sessions_head;
2359 while (sessions != NULL)
2361 sessions_next = sessions->next;
2362 free_session (plugin, sessions, GNUNET_NO);
2363 sessions = sessions_next;
2366 GNUNET_CONTAINER_DLL_remove (plugin->mac_head, plugin->mac_tail, endpoint);
2367 if (endpoint->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2369 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
2370 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2372 plugin->mac_count--;
2373 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
2374 plugin->mac_count, GNUNET_NO);
2375 GNUNET_free (endpoint);
2380 * function to free a session
2381 * @param plugin pointer to the plugin
2382 * @param queue pointer to the sessionqueue element to free
2383 * @param do_free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint
2386 free_session (struct Plugin *plugin, struct Sessionqueue *queue,
2387 int do_free_macendpoint)
2389 struct Sessionqueue *pendingsession;
2390 struct Sessionqueue *pendingsession_tmp;
2391 struct PendingMessage *pm;
2392 struct MacEndpoint *endpoint;
2393 struct FragmentMessage *fm;
2394 struct FragmentMessage *fmnext;
2397 GNUNET_assert (plugin != NULL);
2398 GNUNET_assert (queue != NULL);
2399 GNUNET_assert (queue->content != NULL);
2402 //is this session pending for send
2403 pendingsession = plugin->pending_Sessions_head;
2404 while (pendingsession != NULL)
2406 pendingsession_tmp = pendingsession;
2407 pendingsession = pendingsession->next;
2408 GNUNET_assert (pendingsession_tmp->content != NULL);
2409 if (pendingsession_tmp->content == queue->content)
2411 plugin->pendingsessions--;
2412 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
2413 plugin->pendingsessions, GNUNET_NO);
2414 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
2415 plugin->pending_Sessions_tail,
2416 pendingsession_tmp);
2417 GNUNET_free (pendingsession_tmp);
2419 GNUNET_assert (check == 0);
2424 endpoint = queue->content->mac;
2425 fm = endpoint->sending_messages_head;
2429 if (fm->session == queue->content)
2431 free_fragment_message (plugin, fm);
2436 // remove PendingMessage
2437 pm = queue->content->pending_message_head;
2440 GNUNET_CONTAINER_DLL_remove (queue->content->pending_message_head,
2441 queue->content->pending_message_tail, pm);
2442 GNUNET_free (pm->msg);
2444 pm = queue->content->pending_message_head;
2447 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, endpoint->sessions_tail,
2449 //Check that no ohter session on this endpoint for this session exits
2450 GNUNET_assert (search_session (plugin, endpoint, &queue->content->target) ==
2452 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
2454 free_macendpoint (plugin, endpoint);
2455 //check if no endpoint with the same address exists
2456 GNUNET_assert (get_macendpoint (plugin, &endpoint->addr, GNUNET_NO) ==
2460 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2462 GNUNET_SCHEDULER_cancel (queue->content->timeout_task);
2463 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2465 GNUNET_free (queue);
2467 check_fragment_queue (plugin);
2471 * Function that can be used to force the plugin to disconnect
2472 * from the given peer and cancel all previous transmissions
2473 * (and their continuation).
2475 * @param cls closure
2476 * @param target peer from which to disconnect
2479 wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2481 struct Plugin *plugin = cls;
2482 struct Sessionqueue *queue;
2483 struct Sessionqueue *queue_next;
2484 struct MacEndpoint *endpoint = plugin->mac_head;
2485 struct MacEndpoint *endpoint_next;
2487 // just look at all the session for the needed one
2488 while (endpoint != NULL)
2490 queue = endpoint->sessions_head;
2491 endpoint_next = endpoint->next;
2492 while (queue != NULL)
2494 // content is never NULL
2495 GNUNET_assert (queue->content != NULL);
2496 queue_next = queue->next;
2498 (target, &(queue->content->target),
2499 sizeof (struct GNUNET_PeerIdentity)) == 0)
2501 free_session (plugin, queue, GNUNET_YES);
2506 endpoint = endpoint_next;
2511 * Convert the transports address to a nice, human-readable
2514 * @param cls closure
2515 * @param type name of the transport that generated the address
2516 * @param addr one of the addresses of the host, NULL for the last address
2517 * the specific address format depends on the transport
2518 * @param addrlen length of the address
2519 * @param numeric should (IP) addresses be displayed in numeric form?
2520 * @param timeout after how long should we give up?
2521 * @param asc function to call on each string
2522 * @param asc_cls closure for asc
2525 wlan_plugin_address_pretty_printer (void *cls, const char *type,
2526 const void *addr, size_t addrlen,
2528 struct GNUNET_TIME_Relative timeout,
2529 GNUNET_TRANSPORT_AddressStringCallback asc,
2533 const unsigned char *input;
2535 //GNUNET_assert(cls !=NULL);
2536 if (addrlen != sizeof (struct MacAddress))
2538 /* invalid address (MAC addresses have 6 bytes) */
2541 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2542 "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n",
2545 asc (asc_cls, NULL);
2548 input = (const unsigned char *) addr;
2549 GNUNET_asprintf (&ret,
2550 "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
2551 type, PROTOCOL_PREFIX, input[0], input[1], input[2],
2552 input[3], input[4], input[5]);
2554 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2555 "Func wlan_plugin_address_pretty_printer got size: %u, nummeric %u, type %s; made string: %s\n",
2556 addrlen, numeric, type, ret);
2559 //only one mac address per plugin
2560 asc (asc_cls, NULL);
2566 * handels the data after all fragments are put together
2567 * @param cls macendpoint this messages belongs to
2568 * @param hdr pointer to the data
2571 wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2573 struct MacEndpoint *endpoint = (struct MacEndpoint *) cls;
2574 struct Plugin *plugin = endpoint->plugin;
2575 struct WlanHeader *wlanheader;
2576 struct Session *session;
2578 const struct GNUNET_MessageHeader *temp_hdr;
2579 struct GNUNET_PeerIdentity tmpsource;
2582 GNUNET_assert (plugin != NULL);
2584 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
2588 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2589 "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
2593 if (ntohs (hdr->size) <
2594 sizeof (struct WlanHeader) + sizeof (struct GNUNET_MessageHeader))
2596 //packet not big enought
2600 GNUNET_STATISTICS_update (plugin->env->stats,
2601 _("# wlan whole messages received"), 1,
2603 wlanheader = (struct WlanHeader *) hdr;
2605 session = search_session (plugin, endpoint, &wlanheader->source);
2607 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
2608 crc = ntohl (wlanheader->crc);
2609 wlanheader->crc = 0;
2610 if (GNUNET_CRYPTO_crc32_n
2611 ((char *) wlanheader, ntohs (wlanheader->header.size)) != crc)
2613 //wrong crc, dispose message
2614 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2615 "Wlan message header crc was wrong: %u != %u\n",
2616 GNUNET_CRYPTO_crc32_n ((char *) wlanheader,
2617 ntohs (wlanheader->header.size)),
2619 hexdump ((void *) hdr, ntohs (hdr->size));
2623 //if not in session list
2624 if (session == NULL)
2627 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2628 "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n",
2629 ntohs (wlanheader->header.size), ntohs (temp_hdr->size),
2630 sizeof (struct WlanHeader));
2632 //try if it is a hello message
2633 if (ntohs (wlanheader->header.size) >=
2634 ntohs (temp_hdr->size) + sizeof (struct WlanHeader))
2636 if (ntohs (temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2638 if (GNUNET_HELLO_get_id
2639 ((const struct GNUNET_HELLO_Message *) temp_hdr,
2640 &tmpsource) == GNUNET_OK)
2642 session = create_session (plugin, endpoint, &tmpsource);
2646 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2647 "WLAN client not in session list and hello message is not okay\n");
2654 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2655 "WLAN client not in session list and not a hello message\n");
2661 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2662 "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n",
2663 ntohs (wlanheader->header.size),
2664 ntohs (temp_hdr->size), sizeof (struct WlanHeader));
2669 //"receive" the message
2672 (&wlanheader->source, &session->target,
2673 sizeof (struct GNUNET_PeerIdentity)) != 0)
2677 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2678 "WLAN peer source id doesn't match packet peer source id: session %p\n",
2685 (&wlanheader->target, plugin->env->my_identity,
2686 sizeof (struct GNUNET_PeerIdentity)) != 0)
2690 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2691 "WLAN peer target id doesn't match our peer id: session %p\n",
2697 GNUNET_SERVER_mst_receive (plugin->data_tokenizer, session,
2698 (const char *) temp_hdr,
2699 ntohs (hdr->size) - sizeof (struct WlanHeader),
2700 GNUNET_YES, GNUNET_NO);
2706 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2707 "wlan_data_message_handler got wrong message type: %u\n",
2714 * function to process the a message, give it to the higher layer
2715 * @param cls pointer to the plugin
2716 * @param client pointer to the session this message belongs to
2717 * @param hdr start of the message
2719 //TODO ATS informations
2721 process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2724 GNUNET_assert (client != NULL);
2725 GNUNET_assert (cls != NULL);
2726 struct Session *session = (struct Session *) client;
2727 struct Plugin *plugin = (struct Plugin *) cls;
2729 struct GNUNET_ATS_Information distance;
2731 distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
2732 distance.value = htonl (1);
2735 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2736 "Calling plugin->env->receive for session %p; %s; size: %u\n",
2737 session, wlan_plugin_address_to_string (NULL,
2743 plugin->env->receive (plugin->env->cls, &(session->target), hdr,
2744 (const struct GNUNET_ATS_Information *) &distance, 1,
2745 session, (const char *) &session->mac->addr,
2746 sizeof (session->mac->addr));
2750 * Function used for to process the data received from the wlan interface
2752 * @param cls the plugin handle
2753 * @param session_light pointer to the struct holding known informations
2754 * @param hdr hdr of the GNUNET_MessageHeader
2755 * @param rxinfo pointer to the radiotap informations got with this packet FIXME: give ATS for info
2758 wlan_data_helper (void *cls, struct Session_light *session_light,
2759 const struct GNUNET_MessageHeader *hdr,
2760 const struct Radiotap_rx *rxinfo)
2762 struct Plugin *plugin = cls;
2763 struct FragmentMessage *fm;
2764 struct FragmentMessage *fm2;
2765 struct GNUNET_PeerIdentity tmpsource;
2767 GNUNET_assert (plugin != NULL);
2770 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2773 //TODO better DOS protection, error handling
2774 //TODO test first than create session
2775 GNUNET_assert (session_light != NULL);
2778 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2779 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_HELLO size: %u; %s\n",
2780 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2781 session_light->addr.
2785 if (session_light->macendpoint == NULL)
2787 session_light->macendpoint =
2788 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2792 if (GNUNET_HELLO_get_id
2793 ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource) == GNUNET_OK)
2795 session_light->session =
2796 search_session (plugin, session_light->macendpoint, &tmpsource);
2797 if (session_light->session == NULL)
2799 session_light->session =
2800 create_session (plugin, session_light->macendpoint, &tmpsource);
2802 GNUNET_STATISTICS_update (plugin->env->stats,
2803 _("# wlan hello messages received"), 1,
2805 plugin->env->receive (plugin->env->cls, &session_light->session->target,
2806 hdr, NULL, 0, session_light->session,
2807 (const char *) &session_light->session->mac->addr,
2808 sizeof (session_light->session->mac->addr));
2812 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2813 "WLAN client not in session list and hello message is not okay\n");
2820 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT)
2823 GNUNET_assert (session_light != NULL);
2824 if (session_light->macendpoint == NULL)
2826 session_light->macendpoint =
2827 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2831 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2832 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size: %u; mac endpoint %p: %s\n",
2833 ntohs (hdr->size), session_light->macendpoint,
2834 wlan_plugin_address_to_string (NULL,
2835 session_light->addr.mac,
2839 GNUNET_STATISTICS_update (plugin->env->stats,
2840 _("# wlan fragments received"), 1, GNUNET_NO);
2842 GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag,
2845 if (ret == GNUNET_NO)
2847 session_light->macendpoint->dups++;
2849 else if (ret == GNUNET_OK)
2851 session_light->macendpoint->fragc++;
2853 set_next_send (plugin);
2859 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK)
2861 GNUNET_assert (session_light != NULL);
2862 if (session_light->macendpoint == NULL)
2864 session_light->macendpoint =
2865 get_macendpoint (plugin, &session_light->addr, GNUNET_NO);
2868 if (session_light->macendpoint == NULL)
2871 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2872 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n",
2873 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2874 session_light->addr.mac,
2881 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2882 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n",
2883 ntohs (hdr->size), session_light->macendpoint,
2884 wlan_plugin_address_to_string (NULL,
2885 session_light->addr.mac,
2888 fm = session_light->macendpoint->sending_messages_head;
2892 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"),
2894 int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
2896 if (ret == GNUNET_OK)
2898 #if DEBUG_wlan_retransmission > 1
2899 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2900 "Got last ack, finished fragment message %p\n", fm);
2902 session_light->macendpoint->acks++;
2903 fm->session->last_activity = GNUNET_TIME_absolute_get ();
2904 session_light->macendpoint->last_activity = fm->session->last_activity;
2905 free_fragment_message (plugin, fm);
2906 check_fragment_queue (plugin);
2909 if (ret == GNUNET_NO)
2911 #if DEBUG_wlan_retransmission > 1
2912 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2913 "Got ack for: %p\n", fm);
2915 session_light->macendpoint->acks++;
2918 if (ret == GNUNET_SYSERR)
2926 #if DEBUG_wlan_retransmission > 1
2927 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2928 "WLAN fragment not in fragment list\n");
2936 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2937 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n",
2938 ntohs (hdr->type), ntohs (hdr->size));
2944 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2945 "Helper finished\n");
2952 * Function to print mac addresses nice *
2953 * @param pointer to 6 byte with the mac address
2954 * @return pointer to the chars which hold the print out
2957 macprinter (const u_int8_t * mac)
2959 static char macstr[20];
2961 GNUNET_snprintf (macstr, sizeof (macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1],
2962 mac[2], mac[3], mac[4], mac[5]);
2968 * Function for the scheduler if a mac endpoint times out
2969 * @param cls pointer to the MacEndpoint
2970 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
2973 macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2975 struct MacEndpoint *endpoint = cls;
2977 GNUNET_assert (endpoint != NULL);
2978 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2979 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
2983 if (GNUNET_TIME_absolute_get_remaining
2984 (GNUNET_TIME_absolute_add
2985 (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0)
2987 GNUNET_assert (endpoint->plugin != NULL);
2988 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
2989 _("# wlan mac endpoints timeouts"), 1, GNUNET_NO);
2990 free_macendpoint (endpoint->plugin, endpoint);
2994 endpoint->timeout_task =
2995 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
3001 * function to create an macendpoint
3002 * @param plugin pointer to the plugin struct
3003 * @param addr pointer to the macaddress
3004 * @return returns a macendpoint
3006 static struct MacEndpoint *
3007 create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
3009 struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
3011 GNUNET_assert (plugin != NULL);
3012 GNUNET_STATISTICS_update (plugin->env->stats,
3013 _("# wlan mac endpoints created"), 1, GNUNET_NO);
3014 newend->addr = *addr;
3015 newend->plugin = plugin;
3016 newend->addr = *addr;
3017 newend->fragment_messages_out_count = 0;
3019 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
3020 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
3021 newend, &wlan_data_message_handler,
3023 newend->last_activity = GNUNET_TIME_absolute_get ();
3024 newend->timeout_task =
3025 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
3028 plugin->mac_count++;
3029 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
3030 plugin->mac_count, GNUNET_NO);
3031 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
3033 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3034 "New Mac Endpoint %p: %s\n", newend,
3035 wlan_plugin_address_to_string (NULL, newend->addr.mac, 6));
3041 * Function used for to process the data from the suid process
3043 * @param cls the plugin handle
3044 * @param client client that send the data (not used)
3045 * @param hdr header of the GNUNET_MessageHeader
3048 wlan_process_helper (void *cls, void *client,
3049 const struct GNUNET_MessageHeader *hdr)
3051 struct Plugin *plugin = cls;
3052 struct ieee80211_frame *wlanIeeeHeader = NULL;
3053 struct Session_light *session_light = NULL;
3054 struct Radiotap_rx *rxinfo;
3055 const struct GNUNET_MessageHeader *temp_hdr = NULL;
3060 GNUNET_assert (plugin != NULL);
3061 switch (ntohs (hdr->type))
3063 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
3065 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3066 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
3070 GNUNET_STATISTICS_update (plugin->env->stats,
3071 _("# wlan WLAN_HELPER_DATA received"), 1,
3073 //call wlan_process_helper with the message inside, later with wlan: analyze signal
3074 if (ntohs (hdr->size) <
3075 sizeof (struct ieee80211_frame) +
3076 2 * sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx))
3079 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3080 "Size of packet is too small; size: %u min size: %u\n",
3082 sizeof (struct ieee80211_frame) +
3083 sizeof (struct GNUNET_MessageHeader));
3086 /* FIXME: restart SUID process */
3090 rxinfo = (struct Radiotap_rx *) &hdr[1];
3091 wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1];
3093 //process only if it is an broadcast or for this computer both with the gnunet bssid
3097 (&(wlanIeeeHeader->i_addr3), &mac_bssid,
3098 sizeof (struct MacAddress)) == 0)
3100 //check for broadcast or mac
3102 (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
3103 sizeof (struct MacAddress)) == 0) ||
3105 (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
3106 sizeof (struct MacAddress)) == 0))
3108 //if packet is from us return
3110 (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address),
3111 sizeof (struct MacAddress)) == 0))
3115 // process the inner data
3119 ntohs (hdr->size) - sizeof (struct ieee80211_frame) -
3120 sizeof (struct GNUNET_MessageHeader) - sizeof (struct Radiotap_rx);
3122 session_light = GNUNET_malloc (sizeof (struct Session_light));
3123 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
3124 sizeof (struct MacAddress));
3125 //session_light->session = search_session(plugin,session_light->addr);
3126 GNUNET_STATISTICS_update (plugin->env->stats,
3127 _("# wlan messages for this client received"),
3131 while (pos < datasize)
3133 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
3134 if (ntohs (temp_hdr->size) <= datasize + pos)
3136 GNUNET_STATISTICS_update (plugin->env->stats,
3138 ("# wlan messages inside WLAN_HELPER_DATA received"),
3140 wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
3145 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3146 "Size of packet is too small; size: %u > size of packet: %u\n",
3147 ntohs (temp_hdr->size), datasize + pos);
3150 pos += ntohs (temp_hdr->size);
3155 GNUNET_free (session_light);
3160 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3161 "Func wlan_process_helper got wrong MAC: %s\n",
3162 macprinter (wlanIeeeHeader->i_addr1));
3169 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3170 "Func wlan_process_helper got wrong BSSID: %s\n",
3171 macprinter (wlanIeeeHeader->i_addr2));
3175 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
3176 //TODO more control messages
3177 if (ntohs (hdr->size) != sizeof (struct Wlan_Helper_Control_Message))
3180 /* FIXME: restart SUID process */
3183 memcpy (&plugin->mac_address, &hdr[1], sizeof (struct MacAddress));
3185 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3186 "Received WLAN_HELPER_CONTROL message with transport of address %s\n",
3187 wlan_plugin_address_to_string (cls, &plugin->mac_address,
3191 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
3192 &plugin->mac_address,
3193 sizeof (struct MacAddress));
3197 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3198 "Func wlan_process_helper got unknown message with number %u, size %u\n",
3199 ntohs (hdr->type), ntohs (hdr->size));
3202 #if DEBUG_wlan_msg_dump > 1
3203 hexdump (hdr, GNUNET_MIN (ntohs (hdr->size), 256));
3211 * Exit point from the plugin.
3212 * @param cls pointer to the api struct
3217 libgnunet_plugin_transport_wlan_done (void *cls)
3219 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3220 struct Plugin *plugin = api->cls;
3221 struct MacEndpoint *endpoint = plugin->mac_head;
3222 struct MacEndpoint *endpoint_next;
3225 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3226 "libgnunet_plugin_transport_wlan_done started\n");
3229 wlan_transport_stop_wlan_helper (plugin);
3231 GNUNET_assert (cls != NULL);
3233 while (endpoint != NULL)
3235 endpoint_next = endpoint->next;
3236 free_macendpoint (plugin, endpoint);
3237 endpoint = endpoint_next;
3242 if (plugin->suid_tokenizer != NULL)
3243 GNUNET_SERVER_mst_destroy (plugin->suid_tokenizer);
3245 if (plugin->data_tokenizer != NULL)
3246 GNUNET_SERVER_mst_destroy (plugin->data_tokenizer);
3248 GNUNET_free_non_null (plugin->interface);
3249 GNUNET_free (plugin);
3255 * Entry point for the plugin.
3257 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
3258 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
3261 libgnunet_plugin_transport_wlan_init (void *cls)
3263 //struct GNUNET_SERVICE_Context *service;
3264 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3265 struct GNUNET_TRANSPORT_PluginFunctions *api;
3266 struct Plugin *plugin;
3268 GNUNET_assert (cls != NULL);
3270 plugin = GNUNET_malloc (sizeof (struct Plugin));
3272 plugin->pendingsessions = 0;
3273 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
3274 plugin->pendingsessions, GNUNET_NO);
3275 plugin->mac_count = 0;
3276 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
3277 plugin->mac_count, GNUNET_NO);
3278 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
3279 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
3280 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
3281 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
3282 GNUNET_BANDWIDTH_value_init (100 * 1024 *
3285 plugin->suid_tokenizer =
3286 GNUNET_SERVER_mst_create (&wlan_process_helper, plugin);
3288 plugin->data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
3290 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
3291 //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue));
3293 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
3295 api->send = &wlan_plugin_send;
3296 api->disconnect = &wlan_plugin_disconnect;
3297 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
3298 api->check_address = &wlan_plugin_address_suggested;
3299 api->address_to_string = &wlan_plugin_address_to_string;
3303 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE"))
3305 if (GNUNET_SYSERR ==
3306 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
3307 "TESTMODE", &(plugin->testmode)))
3308 plugin->testmode = 0; //default value
3311 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE"))
3313 if (GNUNET_CONFIGURATION_get_value_string
3314 (env->cfg, "transport-wlan", "INTERFACE",
3315 &(plugin->interface)) != GNUNET_YES)
3317 libgnunet_plugin_transport_wlan_done (api);
3323 wlan_transport_start_wlan_helper (plugin);
3324 set_next_beacon_time (plugin);
3325 set_next_send (plugin);
3327 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3328 "wlan init finished\n");
3334 /* end of plugin_transport_wlan.c */