2 This file is part of GNUnet
3 (C) 2010 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/plugin_transport_wlan.c
23 * @brief transport plugin for wlan
24 * @author David Brodski
27 //TODO split rx and tx structures for better handling
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_protocols.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_statistics_service.h"
34 #include "gnunet_transport_service.h"
35 #include "gnunet_transport_plugin.h"
36 #include "plugin_transport_wlan.h"
37 #include "gnunet_common.h"
38 #include "gnunet_crypto_lib.h"
39 #include "gnunet_fragmentation_lib.h"
40 #include "gnunet_constants.h"
41 //#include "wlan/ieee80211.h"
42 //#include <netinet/ip.h>
46 #define PROTOCOL_PREFIX "wlan"
48 #define PLUGIN_LOG_NAME "wlan-plugin"
56 * time out of a session
58 #define SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
61 * time out of a mac endpoint
63 #define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2)
66 * scaling factor for hello beacon
68 #define HELLO_BEACON_SCALING_FACTOR 30
71 * scaling factor for restarting the helper
73 #define HELPER_RESTART_SCALING_FACTOR 2
76 * max size of fragment queue
78 #define FRAGMENT_QUEUE_SIZE 10
80 * max messages in fragment queue per session/client
82 #define FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION 1
85 * max messages in fragment queue per MAC
87 #define FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT 1
90 * max messages in in queue
92 #define MESSAGES_IN_QUEUE_SIZE 10
94 * max messages in in queue per session/client
96 #define MESSAGES_IN_DEFRAG_QUEUE_PER_MAC 1
99 * LLC fields for better compatibility
101 #define WLAN_LLC_DSAP_FIELD 0x1f
102 #define WLAN_LLC_SSAP_FIELD 0x1f
108 #define DEBUG_wlan GNUNET_EXTRA_LOGGING
109 #define DEBUG_wlan_retransmission GNUNET_EXTRA_LOGGING
110 #define DEBUG_wlan_ip_udp_packets_on_air GNUNET_NO
111 #define DEBUG_wlan_msg_dump GNUNET_EXTRA_LOGGING
114 #define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
116 #define IEEE80211_FC0_VERSION_MASK 0x03
117 #define IEEE80211_FC0_VERSION_SHIFT 0
118 #define IEEE80211_FC0_VERSION_0 0x00
119 #define IEEE80211_FC0_TYPE_MASK 0x0c
120 #define IEEE80211_FC0_TYPE_SHIFT 2
121 #define IEEE80211_FC0_TYPE_MGT 0x00
122 #define IEEE80211_FC0_TYPE_CTL 0x04
123 #define IEEE80211_FC0_TYPE_DATA 0x08
126 * Structure of an internet header, naked of options.
130 #if __BYTE_ORDER == __LITTLE_ENDIAN
131 unsigned int ip_hl:4; /* header length */
132 unsigned int ip_v:4; /* version */
134 #if __BYTE_ORDER == __BIG_ENDIAN
135 unsigned int ip_v:4; /* version */
136 unsigned int ip_hl:4; /* header length */
138 u_int8_t ip_tos; /* type of service */
139 u_short ip_len; /* total length */
140 u_short ip_id; /* identification */
141 u_short ip_off; /* fragment offset field */
142 #define IP_RF 0x8000 /* reserved fragment flag */
143 #define IP_DF 0x4000 /* dont fragment flag */
144 #define IP_MF 0x2000 /* more fragments flag */
145 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
146 u_int8_t ip_ttl; /* time to live */
147 u_int8_t ip_p; /* protocol */
148 u_short ip_sum; /* checksum */
149 struct in_addr ip_src, ip_dst; /* source and dest address */
161 * generic definitions for IEEE 802.11 frames
163 struct ieee80211_frame
167 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
168 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
169 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
172 #if DEBUG_wlan_ip_udp_packets_on_air > 1
179 * Encapsulation of all of the state of the plugin.
186 struct GNUNET_TRANSPORT_PluginEnvironment *env;
189 * List of open connections. head
191 struct MacEndpoint *mac_head;
194 * List of open connections. tail
196 struct MacEndpoint *mac_tail;
199 * Number of connections
201 unsigned int mac_count;
204 * encapsulation of data from the local wlan helper program
206 struct GNUNET_SERVER_MessageStreamTokenizer *suid_tokenizer;
209 * encapsulation of packets received from the wlan helper
211 struct GNUNET_SERVER_MessageStreamTokenizer *data_tokenizer;
214 * stdout pipe handle for the gnunet-wlan-helper process
216 struct GNUNET_DISK_PipeHandle *server_stdout;
219 * stdout file handle for the gnunet-wlan-helper process
221 const struct GNUNET_DISK_FileHandle *server_stdout_handle;
224 * stdin pipe handle for the gnunet-wlan-helper process
226 struct GNUNET_DISK_PipeHandle *server_stdin;
229 * stdin file handle for the gnunet-wlan-helper process
231 const struct GNUNET_DISK_FileHandle *server_stdin_handle;
234 * ID of the gnunet-wlan-server std read task
236 GNUNET_SCHEDULER_TaskIdentifier server_read_task;
239 * ID of the gnunet-wlan-server std read task
241 GNUNET_SCHEDULER_TaskIdentifier server_write_task;
244 * ID of the delay task for writing
246 GNUNET_SCHEDULER_TaskIdentifier server_write_delay_task;
249 * The process id of the wlan process
251 struct GNUNET_OS_Process *server_proc;
254 * The interface of the wlan card given to us by the user.
259 * Mode of operation for the helper, 0 = normal, 1 = first loopback, 2 = second loopback
261 long long unsigned int testmode;
264 * The mac_address of the wlan card given to us by the helper.
266 struct MacAddress mac_address;
269 * Sessions currently pending for transmission
272 struct Sessionqueue *pending_Sessions_head;
275 * Sessions currently pending for transmission
276 * to a peer (tail), if any.
278 struct Sessionqueue *pending_Sessions_tail;
281 * number of pending sessions
283 unsigned int pendingsessions;
286 * Messages in the sending queues
288 int pending_Fragment_Messages;
291 * messages ready for send, head
293 struct FragmentMessage_queue *sending_messages_head;
295 * messages ready for send, tail
297 struct FragmentMessage_queue *sending_messages_tail;
299 * time of the next "hello-beacon"
301 struct GNUNET_TIME_Absolute beacon_time;
304 * queue to send acks for received fragments (head)
306 struct AckSendQueue *ack_send_queue_head;
309 * queue to send acks for received fragments (tail)
311 struct AckSendQueue *ack_send_queue_tail;
314 * Tracker for bandwidth limit
316 struct GNUNET_BANDWIDTH_Tracker tracker;
320 * Struct to store data if file write did not accept the whole packet
325 * pointer to the global plugin struct
327 struct Plugin *plugin;
330 * head of the next part to send to the helper
332 char *head_of_next_write;
335 * Start of the message to send, needed for free
337 struct GNUNET_MessageHeader *msgstart;
346 * Queue of sessions, for the general session queue and the pending session queue
351 struct Sessionqueue *next;
352 struct Sessionqueue *prev;
353 struct Session *content;
357 * Queue of fragmented messages, for the sending queue of the plugin
360 struct FragmentMessage_queue
362 struct FragmentMessage_queue *next;
363 struct FragmentMessage_queue *prev;
364 struct FragmentMessage *content;
368 * Queue for the fragments received
371 struct Receive_Fragment_Queue
373 struct Receive_Fragment_Queue *next;
374 struct Receive_Fragment_Queue *prev;
378 struct Radiotap_rx rxinfo;
382 struct MacEndpoint_id_fragment_triple
384 struct MacEndpoint *endpoint;
386 struct FragmentMessage *fm;
390 struct Plugin_Session_pair
392 struct Plugin *plugin;
393 struct Session *session;
397 * Information kept for each message that is yet to
400 struct PendingMessage
405 struct PendingMessage *next;
409 struct PendingMessage *prev;
412 * The pending message
414 struct WlanHeader *msg;
417 * Size of the message
422 * Continuation function to call once the message
423 * has been sent. Can be NULL if there is no
424 * continuation to call.
426 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
429 * Cls for transmit_cont
431 void *transmit_cont_cls;
434 * Timeout value for the pending message.
436 struct GNUNET_TIME_Absolute timeout;
441 * Queue for acks to send for fragments recived
447 * next ack in the ack send queue
449 struct AckSendQueue *next;
451 * previous ack in the ack send queue
453 struct AckSendQueue *prev;
455 * pointer to the session this ack belongs to
457 struct MacEndpoint *endpoint;
459 * ID of message, to distinguish between the messages, picked randomly.
466 struct GNUNET_MessageHeader *hdr;
468 * pointer to the ieee wlan header
470 struct ieee80211_frame *ieeewlanheader;
472 * pointer to the radiotap header
474 struct Radiotap_Send *radioHeader;
478 * Session infos gathered from a messages
484 * the session this message belongs to
486 struct Session *session;
490 struct MacAddress addr;
495 struct MacEndpoint *macendpoint;
499 * Session handle for connections.
507 struct SessionHeader header;
510 * Message currently pending for transmission
511 * to this peer, if any. head
513 struct PendingMessage *pending_message_head;
516 * Message currently pending for transmission
517 * to this peer, if any. tail
519 struct PendingMessage *pending_message_tail;
522 * To whom are we talking to (set to our identity
523 * if we are still waiting for the welcome message)
525 struct GNUNET_PeerIdentity target;
528 * Address of the other peer (either based on our 'connect'
529 * call or on our 'accept' call).
534 * Last activity on this connection. Used to select preferred
535 * connection and timeout
537 struct GNUNET_TIME_Absolute last_activity;
542 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
547 struct MacEndpoint *mac;
550 * count of messages in the fragment out queue for this session
553 int fragment_messages_out_count;
558 * Struct to represent one network card connection
563 * Pointer to the global plugin struct.
565 struct Plugin *plugin;
567 * Struct to hold the session reachable over this mac; head
569 struct Sessionqueue *sessions_head;
571 * Struct to hold the session reachable over this mac; tail
573 struct Sessionqueue *sessions_tail;
575 * Messages currently sending
578 struct FragmentMessage *sending_messages_head;
581 * Messages currently sending
582 * to a peer (tail), if any.
584 struct FragmentMessage *sending_messages_tail;
588 struct MacEndpoint *next;
592 struct MacEndpoint *prev;
597 struct MacAddress addr;
600 * Defrag context for this mac endpoint
602 struct GNUNET_DEFRAGMENT_Context *defrag;
605 * count of messages in the fragment out queue for this mac endpoint
608 int fragment_messages_out_count;
616 * Duplicates received
631 * Last activity on this endpoint. Used to select preferred
634 struct GNUNET_TIME_Absolute last_activity;
639 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
643 * Struct for Messages in the fragment queue
646 struct FragmentMessage
650 * Session this message belongs to
653 struct Session *session;
656 * This is a doubly-linked list.
658 struct FragmentMessage *next;
661 * This is a doubly-linked list.
663 struct FragmentMessage *prev;
666 * Fragmentation context
668 struct GNUNET_FRAGMENT_Context *fragcontext;
671 * Timeout value for the message.
673 struct GNUNET_TIME_Absolute timeout;
678 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
691 * pointer to the ieee wlan header
693 struct ieee80211_frame *ieeewlanheader;
695 * pointer to the radiotap header
697 struct Radiotap_Send *radioHeader;
701 do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
703 free_session (struct Plugin *plugin, struct Sessionqueue *queue,
704 int do_free_macendpoint);
705 static struct MacEndpoint *
706 create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr);
709 finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
712 * Generates a nice hexdump of a memory area.
714 * \param mem pointer to memory to dump
715 * \param length how many bytes to dump
718 hexdump (const void *mem, unsigned length)
721 char *src = (char *) mem;
723 printf ("dumping %u bytes from %p\r\n"
724 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n",
729 for (i = 0; i < length; i += 16, src += 16)
733 t += sprintf (t, "%04x: ", i);
734 for (j = 0; j < 16; j++)
737 t += sprintf (t, "%02X", src[j] & 0xff);
739 t += sprintf (t, " ");
741 t += sprintf (t, j % 2 ? " " : "-");
744 t += sprintf (t, " ");
745 for (j = 0; j < 16; j++)
749 if (isprint ((unsigned char) src[j]))
750 t += sprintf (t, "%c", src[j]);
752 t += sprintf (t, ".");
756 t += sprintf (t, " ");
760 t += sprintf (t, "\r\n");
766 * Function to find a MacEndpoint with a specific mac addr
767 * @param plugin pointer to the plugin struct
768 * @param addr pointer to the mac address
769 * @param create_new GNUNET_YES if a new end point should be created
772 static struct MacEndpoint *
773 get_macendpoint (struct Plugin *plugin, const struct MacAddress *addr,
776 struct MacEndpoint *queue = plugin->mac_head;
778 while (queue != NULL)
780 //GNUNET_assert (queue->sessions_head != NULL);
781 if (memcmp (addr, &queue->addr, sizeof (struct MacAddress)) == 0)
782 return queue; /* session found */
786 if (create_new == GNUNET_YES)
788 return create_macendpoint (plugin, addr);
798 * search for a session with the macendpoint and peer id
800 * @param plugin pointer to the plugin struct
801 * @param endpoint pointer to the mac endpoint of the peer
802 * @param peer pointer to the peerid
803 * @return returns the session
805 static struct Session *
806 search_session (struct Plugin *plugin, const struct MacEndpoint *endpoint,
807 const struct GNUNET_PeerIdentity *peer)
809 GNUNET_assert (endpoint != NULL);
810 struct Sessionqueue *queue = endpoint->sessions_head;
812 while (queue != NULL)
814 GNUNET_assert (queue->content != NULL);
816 (peer, &queue->content->target,
817 sizeof (struct GNUNET_PeerIdentity)) == 0)
818 return queue->content; /* session found */
825 * Function called for a quick conversion of the binary address to
826 * a numeric address. Note that the caller must not free the
827 * address and that the next call to this function is allowed
828 * to override the address again.
831 * @param addr binary address
832 * @param addrlen length of the address
833 * @return string representing the same address
836 wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
839 const struct MacAddress *mac;
841 if (addrlen != sizeof (struct MacAddress))
847 GNUNET_snprintf (ret, sizeof (ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
848 PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2],
849 mac->mac[3], mac->mac[4], mac->mac[5]);
855 * Function for the scheduler if a session times out
856 * @param cls pointer to the Sessionqueue
857 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
860 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
862 struct Sessionqueue *queue = cls;
864 GNUNET_assert (queue != NULL);
865 GNUNET_assert(queue->content != NULL);
866 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
867 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
871 if (GNUNET_TIME_absolute_get_remaining
872 (GNUNET_TIME_absolute_add
873 (queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0)
876 GNUNET_assert(queue->content->mac != NULL);
877 GNUNET_assert(queue->content->mac->plugin != NULL);
878 GNUNET_STATISTICS_update (queue->content->mac->plugin->env->stats, _("# wlan session timeouts"), 1, GNUNET_NO);
879 free_session (queue->content->mac->plugin, queue, GNUNET_YES);
883 queue->content->timeout_task =
884 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
889 * create a new session
891 * @param plugin pointer to the plugin struct
892 * @param endpoint pointer to the mac endpoint of the peer
893 * @param peer peer identity to use for this session
894 * @return returns the session
897 static struct Session *
898 create_session (struct Plugin *plugin, struct MacEndpoint *endpoint,
899 const struct GNUNET_PeerIdentity *peer)
901 GNUNET_assert (endpoint != NULL);
902 GNUNET_assert (plugin != NULL);
903 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1, GNUNET_NO);
904 struct Sessionqueue *queue =
905 GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session));
907 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
908 endpoint->sessions_tail, queue);
910 queue->content = (struct Session *) &queue[1];
911 queue->content->mac = endpoint;
912 memcpy (&(queue->content->target), peer, sizeof (struct GNUNET_PeerIdentity));
913 queue->content->last_activity = GNUNET_TIME_absolute_get ();
914 queue->content->timeout_task =
915 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
918 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
919 "New session %p with endpoint %p: %s\n", queue->content,
920 endpoint, wlan_plugin_address_to_string (NULL,
925 return queue->content;
929 * Get session from address, create if no session exists
931 * @param plugin pointer to the plugin struct
932 * @param addr pointer to the mac address of the peer
933 * @param peer pointer to the peerid
934 * @return returns the session
936 static struct Session *
937 get_session (struct Plugin *plugin, const struct MacAddress *addr,
938 const struct GNUNET_PeerIdentity *peer)
940 struct MacEndpoint *mac;
942 mac = get_macendpoint (plugin, addr, GNUNET_YES);
943 struct Session *session = search_session (plugin, mac, peer);
947 return create_session (plugin, mac, peer);
951 * Queue the session to send data
952 * checks if there is a message pending
953 * checks if this session is not allready in the queue
954 * @param plugin pointer to the plugin
955 * @param session pointer to the session to add
958 queue_session (struct Plugin *plugin, struct Session *session)
960 struct Sessionqueue *queue = plugin->pending_Sessions_head;
962 if (session->pending_message_head != NULL)
964 while (queue != NULL)
966 // content is never NULL
967 GNUNET_assert (queue->content != NULL);
968 // is session already in queue?
969 if (session == queue->content)
977 // Session is not in the queue
979 queue = GNUNET_malloc (sizeof (struct Sessionqueue));
980 queue->content = session;
983 GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head,
984 plugin->pending_Sessions_tail, queue);
985 plugin->pendingsessions++;
986 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
992 * Function to schedule the write task, executed after a delay
993 * @param cls pointer to the plugin struct
994 * @param tc GNUNET_SCHEDULER_TaskContext pointer
997 delay_fragment_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
999 struct Plugin *plugin = cls;
1001 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1003 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1006 // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg
1007 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1009 plugin->server_write_task =
1010 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1011 plugin->server_stdin_handle,
1012 &do_transmit, plugin);
1017 * Function to calculate the time of the next periodic "hello-beacon"
1018 * @param plugin pointer to the plugin struct
1022 set_next_beacon_time (struct Plugin *const plugin)
1024 //under 10 known peers: once a second
1025 if (plugin->mac_count < 10)
1027 plugin->beacon_time =
1028 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1029 GNUNET_TIME_relative_multiply
1030 (GNUNET_TIME_UNIT_SECONDS,
1031 HELLO_BEACON_SCALING_FACTOR));
1033 //under 30 known peers: every 10 seconds
1034 else if (plugin->mac_count < 30)
1036 plugin->beacon_time =
1037 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1038 GNUNET_TIME_relative_multiply
1039 (GNUNET_TIME_UNIT_SECONDS,
1040 10 * HELLO_BEACON_SCALING_FACTOR));
1042 //over 30 known peers: once a minute
1045 plugin->beacon_time =
1046 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1047 GNUNET_TIME_relative_multiply
1048 (GNUNET_TIME_UNIT_MINUTES,
1049 HELLO_BEACON_SCALING_FACTOR));
1054 * Function to set the timer for the next timeout of the fragment queue
1055 * @param plugin the handle to the plugin struct
1059 set_next_send (struct Plugin *const plugin)
1061 struct GNUNET_TIME_Relative next_send;
1064 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1066 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1067 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1070 //check if some acks are in the queue
1071 if (plugin->ack_send_queue_head != NULL)
1073 next_send = GNUNET_TIME_UNIT_ZERO;
1076 //check if there are some fragments in the queue
1077 else if (plugin->sending_messages_head != NULL)
1079 next_send = GNUNET_TIME_UNIT_ZERO;
1083 next_send = GNUNET_TIME_absolute_get_remaining (plugin->beacon_time);
1087 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1088 "Next packet is send in: %u\n", next_send.rel_value);
1091 if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value)
1093 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1095 plugin->server_write_task =
1096 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1097 plugin->server_stdin_handle,
1098 &do_transmit, plugin);
1103 if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK)
1105 plugin->server_write_delay_task =
1106 GNUNET_SCHEDULER_add_delayed (next_send, &delay_fragment_task,
1113 * Function to get the next queued Session, removes the session from the queue
1114 * @param plugin pointer to the plugin struct
1115 * @return pointer to the session found, returns NULL if there is now session in the queue
1117 static struct Session *
1118 get_next_queue_session (struct Plugin *plugin)
1120 struct Session *session;
1121 struct Sessionqueue *sessionqueue;
1122 struct Sessionqueue *sessionqueue_alt;
1123 struct PendingMessage *pm;
1125 sessionqueue = plugin->pending_Sessions_head;
1127 while (sessionqueue != NULL)
1129 session = sessionqueue->content;
1131 GNUNET_assert (session != NULL);
1132 pm = session->pending_message_head;
1137 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1138 "pending message is empty, should not happen. session %p\n",
1141 sessionqueue_alt = sessionqueue;
1142 sessionqueue = sessionqueue->next;
1143 plugin->pendingsessions--;
1144 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
1145 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1146 plugin->pending_Sessions_tail,
1149 GNUNET_free (sessionqueue_alt);
1154 //check for message timeout
1155 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
1157 //check if session has no message in the fragment queue
1158 if ((session->mac->fragment_messages_out_count <
1159 FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT) &&
1160 (session->fragment_messages_out_count <
1161 FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
1163 plugin->pendingsessions--;
1164 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
1165 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1166 plugin->pending_Sessions_tail,
1168 GNUNET_free (sessionqueue);
1174 sessionqueue = sessionqueue->next;
1179 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1180 session->pending_message_tail, pm);
1182 //call the cont func that it did not work
1183 if (pm->transmit_cont != NULL)
1184 pm->transmit_cont (pm->transmit_cont_cls, &(session->target),
1186 GNUNET_free (pm->msg);
1189 if (session->pending_message_head == NULL)
1191 sessionqueue_alt = sessionqueue;
1192 sessionqueue = sessionqueue->next;
1193 plugin->pendingsessions--;
1194 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
1195 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1196 plugin->pending_Sessions_tail,
1199 GNUNET_free (sessionqueue_alt);
1208 * frees the space of a message in the fragment queue (send queue)
1209 * @param plugin the plugin struct
1210 * @param fm message to free
1213 free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm)
1215 struct Session *session = fm->session;
1216 struct MacEndpoint *endpoint = session->mac;
1217 struct FragmentMessage_queue *fmq;
1218 struct FragmentMessage_queue *fmq_next;
1222 fmq = plugin->sending_messages_head;
1225 fmq_next = fmq->next;
1226 if (fmq->content == fm)
1228 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1229 plugin->sending_messages_tail, fmq);
1235 (session->mac->fragment_messages_out_count)--;
1236 session->fragment_messages_out_count--;
1237 plugin->pending_Fragment_Messages--;
1238 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending fragments"), plugin->pending_Fragment_Messages, GNUNET_NO);
1239 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
1240 endpoint->sending_messages_tail, fm);
1241 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
1242 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK){
1243 GNUNET_SCHEDULER_cancel (fm->timeout_task);
1244 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1249 queue_session (plugin, session);
1251 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1252 "Free pending fragment messages %p, session %p\n", fm,
1259 * function to fill the radiotap header
1260 * @param plugin pointer to the plugin struct
1261 * @param endpoint pointer to the endpoint
1262 * @param header pointer to the radiotap header
1263 * @return GNUNET_YES at success
1266 getRadiotapHeader (struct Plugin *plugin, struct MacEndpoint *endpoint,
1267 struct Radiotap_Send *header)
1270 if (endpoint != NULL)
1272 header->rate = endpoint->rate;
1273 header->tx_power = endpoint->tx_power;
1274 header->antenna = endpoint->antenna;
1279 header->tx_power = 0;
1280 header->antenna = 0;
1287 * function to generate the wlan hardware header for one packet
1288 * @param Header address to write the header to
1289 * @param to_mac_addr address of the recipient
1290 * @param plugin pointer to the plugin struct
1291 * @param size size of the whole packet, needed to calculate the time to send the packet
1292 * @return GNUNET_YES if there was no error
1295 getWlanHeader (struct ieee80211_frame *Header,
1296 const struct MacAddress *to_mac_addr, struct Plugin *plugin,
1300 const int rate = 11000000;
1302 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA;
1303 Header->i_fc[1] = 0x00;
1304 memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid));
1305 memcpy (&Header->i_addr2, plugin->mac_address.mac,
1306 sizeof (plugin->mac_address));
1307 memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress));
1309 tmp16 = (uint16_t *) Header->i_dur;
1310 *tmp16 = (uint16_t) htole16 ((size * 1000000) / rate + 290);
1311 Header->llc[0] = WLAN_LLC_DSAP_FIELD;
1312 Header->llc[1] = WLAN_LLC_SSAP_FIELD;
1314 #if DEBUG_wlan_ip_udp_packets_on_air > 1
1319 Header->ip.ip_dst.s_addr = *((uint32_t *) & to_mac_addr->mac[2]);
1320 Header->ip.ip_src.s_addr = *((uint32_t *) & plugin->mac_address.mac[2]);
1321 Header->ip.ip_v = 4;
1322 Header->ip.ip_hl = 5;
1323 Header->ip.ip_p = 17;
1324 Header->ip.ip_ttl = 1;
1325 Header->ip.ip_len = htons (size + 8);
1326 Header->ip.ip_sum = 0;
1327 x = (uint16_t *) & Header->ip;
1328 count = sizeof (struct iph);
1331 /* This is the inner loop */
1332 crc += (unsigned short) *x++;
1335 /* Add left-over byte, if any */
1337 crc += *(unsigned char *) x;
1338 crc = (crc & 0xffff) + (crc >> 16);
1339 Header->ip.ip_sum = htons (~(unsigned short) crc);
1340 Header->udp.len = htons (size - sizeof (struct ieee80211_frame));
1350 * @param msgbuf pointer tor the data
1351 * @param msgbuf_size size of the data
1353 * @return 32bit crc value
1357 getcrc32 (const char *msgbuf, size_t msgbuf_size)
1360 return GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size);;
1366 * @param msgbuf pointer tor the data
1367 * @param msgbuf_size size of the data
1369 * @return 16bit crc value
1373 getcrc16 (const char *msgbuf, size_t msgbuf_size)
1375 //TODO calc some crc
1380 * function to add a fragment of a message to send
1381 * @param cls FragmentMessage this message belongs to
1382 * @param hdr pointer to the start of the message
1386 add_message_for_send (void *cls, const struct GNUNET_MessageHeader *hdr)
1389 struct FragmentMessage *fm = cls;
1390 struct FragmentMessage_queue *fmqueue;
1392 GNUNET_assert (cls != NULL);
1393 GNUNET_assert (fm->frag == NULL);
1394 struct MacEndpoint *endpoint = fm->session->mac;
1395 struct Plugin *plugin = endpoint->plugin;
1396 struct GNUNET_MessageHeader *msgheader;
1397 struct GNUNET_MessageHeader *msgheader2;
1400 #if DEBUG_wlan_retransmission > 1
1401 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1402 "Adding fragment of message %p to send, session %p, endpoint %p, type %u\n",
1403 fm, fm->session, endpoint, hdr->type);
1407 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1408 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1409 fm->frag = GNUNET_malloc (size);
1412 msgheader = (struct GNUNET_MessageHeader *) fm->frag;
1413 msgheader->size = htons (size);
1414 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1416 fm->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1417 fm->ieeewlanheader = (struct ieee80211_frame *) &fm->radioHeader[1];
1418 msgheader2 = (struct GNUNET_MessageHeader *) &fm->ieeewlanheader[1];
1419 memcpy (msgheader2, hdr, ntohs (hdr->size));
1421 fmqueue = GNUNET_malloc (sizeof (struct FragmentMessage_queue));
1422 fmqueue->content = fm;
1424 GNUNET_CONTAINER_DLL_insert_tail (plugin->sending_messages_head,
1425 plugin->sending_messages_tail, fmqueue);
1426 set_next_send (plugin);
1431 * We have been notified that wlan-helper has written something to stdout.
1432 * Handle the output, then reschedule this function to be called again once
1433 * more is available.
1435 * @param cls the plugin handle
1436 * @param tc the scheduling context
1439 wlan_plugin_helper_read (void *cls,
1440 const struct GNUNET_SCHEDULER_TaskContext *tc)
1442 struct Plugin *plugin = cls;
1444 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1446 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1449 char mybuf[WLAN_MTU + sizeof (struct GNUNET_MessageHeader)];
1453 GNUNET_DISK_file_read (plugin->server_stdout_handle, mybuf,
1458 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1460 ("Finished reading from wlan-helper stdout with code: %d\n"),
1465 GNUNET_SERVER_mst_receive (plugin->suid_tokenizer, NULL, mybuf, bytes,
1466 GNUNET_NO, GNUNET_NO);
1468 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
1469 plugin->server_read_task =
1470 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1471 plugin->server_stdout_handle,
1472 &wlan_plugin_helper_read, plugin);
1476 * Start the gnunet-wlan-helper process.
1478 * @param plugin the transport plugin
1479 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
1482 wlan_transport_start_wlan_helper (struct Plugin *plugin)
1484 const char *filenamehw = "gnunet-transport-wlan-helper";
1485 char *filenameloopback = "gnunet-transport-wlan-helper-dummy";
1486 char *absolute_filename = NULL;
1488 plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
1489 if (plugin->server_stdout == NULL)
1490 return GNUNET_SYSERR;
1492 plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
1493 if (plugin->server_stdin == NULL)
1494 return GNUNET_SYSERR;
1496 if ((plugin->testmode == 1) || (plugin->testmode == 2))
1498 if (GNUNET_OS_check_helper_binary (filenameloopback) == GNUNET_YES)
1500 absolute_filename = strdup (filenameloopback);
1504 char cwd[FILENAME_MAX];
1505 GNUNET_assert (getcwd(cwd, sizeof(cwd)) != NULL);
1507 GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR, filenameloopback);
1509 if (GNUNET_DISK_file_test (filenameloopback) != GNUNET_YES)
1511 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1512 "Helper `%s' not found! %i\n", absolute_filename);
1518 /* Start the server process */
1520 if (plugin->testmode == 0)
1524 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1525 "Starting gnunet-wlan-helper process cmd: %s %s %i\n",
1526 filenamehw, plugin->interface, plugin->testmode);
1529 if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_YES)
1531 plugin->server_proc =
1532 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1533 filenamehw, filenamehw, plugin->interface,
1536 else if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_NO)
1538 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1539 "gnunet-transport-wlan-helper is not suid, please change it or look at the doku\n");
1544 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1545 "gnunet-transport-wlan-helper not found, please look if it exists and is the $PATH variable!\n");
1550 else if (plugin->testmode == 1)
1554 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
1555 "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n",
1556 absolute_filename, plugin->interface, plugin->testmode);
1558 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1559 absolute_filename, absolute_filename, "1",
1561 if (plugin->server_proc == NULL)
1563 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1564 "`%s' not found, please look if it exists and is in the $PATH variable!\n", absolute_filename);
1568 else if (plugin->testmode == 2)
1571 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
1572 "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n",
1573 absolute_filename, plugin->interface, plugin->testmode);
1576 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1577 absolute_filename, absolute_filename, "2",
1579 if (plugin->server_proc == NULL)
1581 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1582 "`%s' not found, please look if it exists and is in the $PATH variable!\n", absolute_filename);
1586 if (absolute_filename != NULL)
1587 GNUNET_free(absolute_filename);
1588 if (plugin->server_proc == NULL)
1591 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1592 "Failed to start gnunet-wlan-helper process\n");
1594 return GNUNET_SYSERR;
1599 /* Close the write end of the read pipe */
1600 GNUNET_DISK_pipe_close_end (plugin->server_stdout,
1601 GNUNET_DISK_PIPE_END_WRITE);
1603 /* Close the read end of the write pipe */
1604 GNUNET_DISK_pipe_close_end (plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
1606 plugin->server_stdout_handle =
1607 GNUNET_DISK_pipe_handle (plugin->server_stdout,
1608 GNUNET_DISK_PIPE_END_READ);
1609 plugin->server_stdin_handle =
1610 GNUNET_DISK_pipe_handle (plugin->server_stdin,
1611 GNUNET_DISK_PIPE_END_WRITE);
1613 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
1616 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1617 "Adding server_read_task for the wlan-helper\n");
1620 plugin->server_read_task =
1621 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1622 plugin->server_stdout_handle,
1623 &wlan_plugin_helper_read, plugin);
1629 * Stops the gnunet-wlan-helper process.
1631 * @param plugin the transport plugin
1632 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
1635 wlan_transport_stop_wlan_helper (struct Plugin *plugin)
1638 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1639 "Stoping WLAN helper process\n");
1642 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1644 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1645 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1648 if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK)
1650 GNUNET_SCHEDULER_cancel (plugin->server_write_task);
1651 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1654 if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK)
1656 GNUNET_SCHEDULER_cancel (plugin->server_read_task);
1657 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1660 GNUNET_DISK_pipe_close (plugin->server_stdout);
1661 GNUNET_DISK_pipe_close (plugin->server_stdin);
1662 GNUNET_OS_process_kill (plugin->server_proc, SIGKILL);
1663 GNUNET_OS_process_wait(plugin->server_proc);
1664 GNUNET_OS_process_close (plugin->server_proc);
1670 * function for delayed restart of the helper process
1671 * @param cls Finish_send struct if message should be finished
1672 * @param tc TaskContext
1675 delay_restart_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1677 struct Finish_send *finish = cls;
1678 struct Plugin *plugin;
1679 plugin = finish->plugin;
1681 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1682 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1684 GNUNET_free_non_null(finish->msgstart);
1685 GNUNET_free (finish);
1689 wlan_transport_start_wlan_helper(plugin);
1691 if (finish->size != 0)
1693 plugin->server_write_task =
1694 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1695 plugin->server_stdin_handle,
1696 &finish_sending, finish);
1700 set_next_send (plugin);
1701 GNUNET_free_non_null(finish->msgstart);
1702 GNUNET_free (finish);
1708 * Function to restart the helper
1709 * @param plugin pointer to the global plugin struct
1710 * @param finish pointer to the Finish_send struct to finish
1713 restart_helper(struct Plugin *plugin, struct Finish_send *finish)
1715 static struct GNUNET_TIME_Relative next_try = {1000};
1716 GNUNET_assert(finish != NULL);
1718 wlan_transport_stop_wlan_helper(plugin);
1719 plugin->server_write_task = GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish);
1720 GNUNET_TIME_relative_multiply(next_try, HELPER_RESTART_SCALING_FACTOR);
1725 * function to finish a sending if not all could have been writen befor
1726 * @param cls pointer to the Finish_send struct
1727 * @param tc TaskContext
1730 finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1732 struct Finish_send *finish = cls;
1733 struct Plugin *plugin;
1736 plugin = finish->plugin;
1737 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1739 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1741 GNUNET_free (finish->msgstart);
1742 GNUNET_free (finish);
1746 GNUNET_DISK_file_write (plugin->server_stdin_handle, finish->head_of_next_write,
1749 if (bytes != finish->size)
1751 if (bytes != GNUNET_SYSERR)
1753 finish->head_of_next_write += bytes;
1754 finish->size -= bytes;
1755 plugin->server_write_task =
1756 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1757 plugin->server_stdin_handle,
1758 &finish_sending, finish);
1762 restart_helper(plugin, finish);
1767 GNUNET_free (finish->msgstart);
1768 GNUNET_free (finish);
1769 set_next_send (plugin);
1774 * function to send a hello beacon
1775 * @param plugin pointer to the plugin struct
1778 send_hello_beacon (struct Plugin *plugin)
1782 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1783 "Sending hello beacon\n");
1788 uint16_t hello_size;
1789 struct GNUNET_MessageHeader *msgheader;
1790 struct ieee80211_frame *ieeewlanheader;
1791 struct Radiotap_Send *radioHeader;
1792 struct GNUNET_MessageHeader *msgheader2;
1793 const struct GNUNET_MessageHeader *hello;
1794 struct Finish_send * finish;
1796 GNUNET_assert (plugin != NULL);
1798 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"), 1, GNUNET_NO);
1800 hello = plugin->env->get_our_hello ();
1801 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1802 GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
1804 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1805 sizeof (struct ieee80211_frame) + hello_size;
1807 msgheader = GNUNET_malloc (size);
1808 msgheader->size = htons (size);
1809 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1811 radioHeader = (struct Radiotap_Send *) &msgheader[1];
1812 getRadiotapHeader (plugin, NULL, radioHeader);
1813 ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
1814 getWlanHeader (ieeewlanheader, &bc_all_mac, plugin, size);
1816 msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1];
1817 /*msgheader2->size =
1818 htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) +
1819 sizeof (struct GNUNET_MessageHeader));
1821 msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);*/
1822 memcpy (msgheader2, hello, hello_size);
1824 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size);
1826 if (bytes == GNUNET_SYSERR)
1828 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1830 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1831 errno, strerror (errno));
1832 finish = GNUNET_malloc (sizeof (struct Finish_send));
1833 finish->plugin = plugin;
1834 finish->head_of_next_write = NULL;
1836 finish->msgstart = NULL;
1837 restart_helper(plugin, finish);
1839 set_next_beacon_time (plugin);
1844 GNUNET_assert (bytes == size);
1845 set_next_beacon_time (plugin);
1846 set_next_send (plugin);
1848 GNUNET_free (msgheader);
1854 * function to add an ack to send it for a received fragment
1855 * @param cls MacEndpoint this ack belongs to
1856 * @param msg_id id of the message
1857 * @param hdr pointer to the hdr where the ack is stored
1862 add_ack_for_send (void *cls, uint32_t msg_id,
1863 const struct GNUNET_MessageHeader *hdr)
1866 struct AckSendQueue *ack;
1868 GNUNET_assert (cls != NULL);
1869 struct MacEndpoint *endpoint = cls;
1870 struct Plugin *plugin = endpoint->plugin;
1871 struct GNUNET_MessageHeader *msgheader;
1872 struct GNUNET_MessageHeader *msgheader2;
1876 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1877 sizeof (struct ieee80211_frame) + ntohs (hdr->size) +
1878 sizeof (struct AckSendQueue);
1880 ack = GNUNET_malloc (size);
1881 ack->message_id = msg_id;
1882 ack->endpoint = endpoint;
1885 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1886 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1888 msgheader = (struct GNUNET_MessageHeader *) &ack[1];
1889 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1];
1890 msgheader->size = htons (size);
1891 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1893 ack->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1894 ack->ieeewlanheader = (struct ieee80211_frame *) &(ack->radioHeader)[1];
1895 msgheader2 = (struct GNUNET_MessageHeader *) &(ack->ieeewlanheader)[1];
1896 memcpy (msgheader2, hdr, ntohs (hdr->size));
1898 GNUNET_CONTAINER_DLL_insert_tail (plugin->ack_send_queue_head,
1899 plugin->ack_send_queue_tail, ack);
1901 #if DEBUG_wlan_retransmission > 1
1902 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1903 "Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n",
1904 msg_id, ack, endpoint);
1907 set_next_send (plugin);
1911 * Function for the scheduler if a FragmentMessage times out
1912 * @param cls pointer to the FragmentMessage
1913 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
1916 fragmentmessage_timeout (void *cls,
1917 const struct GNUNET_SCHEDULER_TaskContext *tc)
1919 struct FragmentMessage *fm = cls;
1921 GNUNET_assert (fm != NULL);
1922 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1923 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1927 free_fragment_message (fm->session->mac->plugin, fm);
1931 * Function to check if there is some space in the fragment queue
1932 * inserts a message if space is available
1933 * @param plugin the plugin struct
1937 check_fragment_queue (struct Plugin *plugin)
1939 struct Session *session;
1940 struct FragmentMessage *fm;
1941 struct GNUNET_PeerIdentity pid;
1943 struct PendingMessage *pm;
1945 if (plugin->pending_Fragment_Messages < FRAGMENT_QUEUE_SIZE)
1947 session = get_next_queue_session (plugin);
1948 if (session != NULL)
1950 pm = session->pending_message_head;
1951 GNUNET_assert (pm != NULL);
1952 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1953 session->pending_message_tail, pm);
1954 session->mac->fragment_messages_out_count++;
1955 session->fragment_messages_out_count++;
1956 plugin->pending_Fragment_Messages++;
1957 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending fragments"), plugin->pending_Fragment_Messages, GNUNET_NO);
1959 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
1960 fm->session = session;
1961 fm->timeout.abs_value = pm->timeout.abs_value;
1964 GNUNET_FRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
1966 GNUNET_TIME_UNIT_SECONDS,
1968 &add_message_for_send, fm);
1970 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
1971 (fm->timeout), fragmentmessage_timeout,
1973 GNUNET_CONTAINER_DLL_insert_tail (session->mac->sending_messages_head,
1974 session->mac->sending_messages_tail,
1977 if (pm->transmit_cont != NULL)
1979 pid = session->target;
1980 pm->transmit_cont (pm->transmit_cont_cls, &pid, GNUNET_OK);
1982 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1983 "called pm->transmit_cont for %p\n", session);
1989 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1990 "no pm->transmit_cont for %p\n", session);
1995 if (session->pending_message_head != NULL)
1998 queue_session (plugin, session);
2004 //check if timeout changed
2005 set_next_send (plugin);
2009 * Function to send an ack, does not free the ack
2010 * @param plugin pointer to the plugin
2013 send_ack (struct Plugin *plugin)
2017 struct AckSendQueue *ack;
2018 struct Finish_send * finish;
2020 ack = plugin->ack_send_queue_head;
2024 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2025 "Sending ack for message_id %u for mac endpoint %p, size %u\n",
2026 ack->message_id, ack->endpoint,
2027 ntohs (ack->hdr->size) - sizeof (struct Radiotap_Send));
2030 GNUNET_assert (plugin != NULL);
2031 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1, GNUNET_NO);
2033 getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader);
2034 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
2035 ntohs (ack->hdr->size));
2038 GNUNET_DISK_file_write (plugin->server_stdin_handle, ack->hdr,
2039 ntohs (ack->hdr->size));
2040 if (bytes == GNUNET_SYSERR)
2042 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2044 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
2045 errno, strerror (errno));
2046 finish = GNUNET_malloc (sizeof (struct Finish_send));
2047 finish->plugin = plugin;
2048 finish->head_of_next_write = NULL;
2050 finish->msgstart = NULL;
2051 restart_helper(plugin, finish);
2055 GNUNET_assert (bytes == ntohs (ack->hdr->size));
2056 GNUNET_CONTAINER_DLL_remove (plugin->ack_send_queue_head,
2057 plugin->ack_send_queue_tail, ack);
2059 set_next_send (plugin);
2064 * Function called when wlan helper is ready to get some data
2066 * @param cls closure
2067 * @param tc GNUNET_SCHEDULER_TaskContext
2070 do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2072 struct Plugin *plugin = cls;
2073 GNUNET_assert (plugin != NULL);
2075 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2076 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2079 struct Session *session;
2080 struct FragmentMessage *fm;
2081 struct Finish_send *finish;
2082 struct FragmentMessage_queue *fmq;
2085 if (plugin->ack_send_queue_head != NULL)
2091 //test if a "hello-beacon" has to be send
2092 if (GNUNET_TIME_absolute_get_remaining (plugin->beacon_time).rel_value == 0)
2094 send_hello_beacon (plugin);
2098 if (plugin->sending_messages_head != NULL)
2100 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1, GNUNET_NO);
2102 fmq = plugin->sending_messages_head;
2104 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
2105 plugin->sending_messages_tail, fmq);
2108 session = fm->session;
2109 GNUNET_assert (session != NULL);
2112 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2113 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p, size: %u\n",
2117 getRadiotapHeader (plugin, session->mac, fm->radioHeader);
2118 getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
2122 GNUNET_DISK_file_write (plugin->server_stdin_handle, fm->frag,
2126 if (bytes != fm->size)
2128 finish = GNUNET_malloc (sizeof (struct Finish_send));
2129 finish->plugin = plugin;
2130 finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag;
2131 GNUNET_assert (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
2133 if (bytes == GNUNET_SYSERR)
2135 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2137 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
2138 errno, strerror (errno));
2140 finish->head_of_next_write = fm->frag;
2141 finish->size = fm->size;
2142 restart_helper(plugin, finish);
2146 finish->head_of_next_write = fm->frag + bytes;
2147 finish->size = fm->size - bytes;
2148 plugin->server_write_task =
2149 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
2150 plugin->server_stdin_handle,
2151 &finish_sending, finish);
2158 GNUNET_free (fm->frag);
2160 set_next_send (plugin);
2162 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
2166 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2167 "do_transmit did nothing, should not happen!\n");
2171 * Another peer has suggested an address for this
2172 * peer and transport plugin. Check that this could be a valid
2173 * address. If so, consider adding it to the list
2176 * @param cls closure
2177 * @param addr pointer to the address
2178 * @param addrlen length of addr
2179 * @return GNUNET_OK if this is a plausible address for this peer
2183 wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
2185 //struct Plugin *plugin = cls;
2187 /* check if the address is plausible; if so,
2188 * add it to our list! */
2190 GNUNET_assert (cls != NULL);
2191 //FIXME mitm is not checked
2192 //Mac Address has 6 bytes
2195 /* TODO check for bad addresses like multicast, broadcast, etc */
2197 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2198 "wlan_plugin_address_suggested got good address, size %u!\n", addrlen);
2203 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2204 "wlan_plugin_address_suggested got bad address, size %u!\n", addrlen);
2206 return GNUNET_SYSERR;
2210 * Function that can be used by the transport service to transmit
2211 * a message using the plugin.
2213 * @param cls closure
2214 * @param target who should receive this message
2215 * @param priority how important is the message
2216 * @param msgbuf the message to transmit
2217 * @param msgbuf_size number of bytes in 'msgbuf'
2218 * @param timeout when should we time out
2219 * @param session which session must be used (or NULL for "any")
2220 * @param addr the address to use (can be NULL if the plugin
2221 * is "on its own" (i.e. re-use existing TCP connection))
2222 * @param addrlen length of the address in bytes
2223 * @param force_address GNUNET_YES if the plugin MUST use the given address,
2224 * otherwise the plugin may use other addresses or
2225 * existing connections (if available)
2226 * @param cont continuation to call once the message has
2227 * been transmitted (or if the transport is ready
2228 * for the next transmission call; or if the
2229 * peer disconnected...)
2230 * @param cont_cls closure for cont
2231 * @return number of bytes used (on the physical network, with overheads);
2232 * -1 on hard errors (i.e. address invalid); 0 is a legal value
2233 * and does NOT mean that the message was not transmitted (DV)
2236 wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
2237 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
2238 struct GNUNET_TIME_Relative timeout, struct Session *session,
2239 const void *addr, size_t addrlen, int force_address,
2240 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
2242 struct Plugin *plugin = cls;
2243 struct PendingMessage *newmsg;
2244 struct WlanHeader *wlanheader;
2245 GNUNET_assert (plugin != NULL);
2246 //check if msglen > 0
2247 GNUNET_assert (msgbuf_size > 0);
2249 //get session if needed
2250 if (session == NULL)
2252 if (wlan_plugin_address_suggested (plugin, addr, addrlen) == GNUNET_OK)
2254 session = get_session (plugin, addr, target);
2258 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2259 _("Wlan Address len %d is wrong\n"), addrlen);
2264 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1, GNUNET_NO);
2268 //queue message in session
2269 //test if there is no other message in the "queue"
2270 //FIXME: to many send requests
2271 if (session->pending_message_head != NULL)
2273 newmsg = session->pending_message_head;
2274 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2275 "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",
2276 GNUNET_TIME_absolute_get_remaining (newmsg->
2278 session->mac->fragment_messages_out_count);
2281 newmsg = GNUNET_malloc (sizeof (struct PendingMessage));
2282 newmsg->msg = GNUNET_malloc (msgbuf_size + sizeof (struct WlanHeader));
2283 wlanheader = newmsg->msg;
2284 //copy msg to buffer, not fragmented / segmented yet, but with message header
2285 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
2286 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
2287 memcpy (&(wlanheader->target), target, sizeof (struct GNUNET_PeerIdentity));
2288 memcpy (&(wlanheader->source), plugin->env->my_identity,
2289 sizeof (struct GNUNET_PeerIdentity));
2290 wlanheader->crc = 0;
2291 memcpy (&wlanheader[1], msgbuf, msgbuf_size);
2294 ((char *) wlanheader, msgbuf_size + sizeof (struct WlanHeader)));
2295 //GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, "Wlan message Header crc: %u, %u\n",getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader)), wlanheader->crc);
2296 //hexdump(newmsg->msg, msgbuf_size + sizeof(struct WlanHeader));
2298 newmsg->transmit_cont = cont;
2299 newmsg->transmit_cont_cls = cont_cls;
2300 newmsg->timeout = GNUNET_TIME_relative_to_absolute (timeout);
2302 newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
2304 newmsg->message_size = msgbuf_size + sizeof (struct WlanHeader);
2306 GNUNET_CONTAINER_DLL_insert_tail (session->pending_message_head,
2307 session->pending_message_tail, newmsg);
2310 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2311 "New message for %p with size (incl wlan header) %u added\n",
2312 session, newmsg->message_size);
2314 #if DEBUG_wlan_msg_dump > 1
2315 hexdump (msgbuf, GNUNET_MIN (msgbuf_size, 256));
2318 queue_session (plugin, session);
2320 check_fragment_queue (plugin);
2321 //FIXME not the correct size
2327 * function to free a mac endpoint
2328 * @param plugin pointer to the plugin struct
2329 * @param endpoint pointer to the MacEndpoint to free
2332 free_macendpoint (struct Plugin *plugin, struct MacEndpoint *endpoint)
2334 struct Sessionqueue *sessions;
2335 struct Sessionqueue *sessions_next;
2337 GNUNET_assert (endpoint != NULL);
2339 sessions = endpoint->sessions_head;
2340 while (sessions != NULL)
2342 sessions_next = sessions->next;
2343 free_session (plugin, sessions, GNUNET_NO);
2344 sessions = sessions_next;
2347 GNUNET_CONTAINER_DLL_remove (plugin->mac_head, plugin->mac_tail, endpoint);
2348 if (endpoint->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2350 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
2351 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2353 plugin->mac_count--;
2354 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO);
2355 GNUNET_free (endpoint);
2360 * function to free a session
2361 * @param plugin pointer to the plugin
2362 * @param queue pointer to the sessionqueue element to free
2363 * @param free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint
2366 free_session (struct Plugin *plugin, struct Sessionqueue *queue,
2367 int do_free_macendpoint)
2369 struct Sessionqueue *pendingsession;
2370 struct Sessionqueue *pendingsession_tmp;
2371 struct PendingMessage *pm;
2372 struct MacEndpoint *endpoint;
2373 struct FragmentMessage *fm;
2374 struct FragmentMessage *fmnext;
2377 GNUNET_assert (plugin != NULL);
2378 GNUNET_assert (queue != NULL);
2379 GNUNET_assert (queue->content != NULL);
2382 //is this session pending for send
2383 pendingsession = plugin->pending_Sessions_head;
2384 while (pendingsession != NULL)
2386 pendingsession_tmp = pendingsession;
2387 pendingsession = pendingsession->next;
2388 GNUNET_assert (pendingsession_tmp->content != NULL);
2389 if (pendingsession_tmp->content == queue->content)
2391 plugin->pendingsessions--;
2392 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
2393 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
2394 plugin->pending_Sessions_tail,
2395 pendingsession_tmp);
2396 GNUNET_free (pendingsession_tmp);
2398 GNUNET_assert (check == 0);
2403 endpoint = queue->content->mac;
2404 fm = endpoint->sending_messages_head;
2408 if (fm->session == queue->content)
2410 free_fragment_message (plugin, fm);
2415 // remove PendingMessage
2416 pm = queue->content->pending_message_head;
2419 GNUNET_CONTAINER_DLL_remove (queue->content->pending_message_head,
2420 queue->content->pending_message_tail, pm);
2421 GNUNET_free (pm->msg);
2423 pm = queue->content->pending_message_head;
2426 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, endpoint->sessions_tail,
2428 //Check that no ohter session on this endpoint for this session exits
2429 GNUNET_assert(search_session(plugin, endpoint, &queue->content->target) == NULL);
2430 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
2432 free_macendpoint (plugin, endpoint);
2433 //check if no endpoint with the same address exists
2434 GNUNET_assert(get_macendpoint(plugin, &endpoint->addr, GNUNET_NO) == NULL);
2437 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2439 GNUNET_SCHEDULER_cancel (queue->content->timeout_task);
2440 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2442 GNUNET_free (queue);
2444 check_fragment_queue (plugin);
2448 * Function that can be used to force the plugin to disconnect
2449 * from the given peer and cancel all previous transmissions
2450 * (and their continuation).
2452 * @param cls closure
2453 * @param target peer from which to disconnect
2456 wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2458 struct Plugin *plugin = cls;
2459 struct Sessionqueue *queue;
2460 struct Sessionqueue *queue_next;
2461 struct MacEndpoint *endpoint = plugin->mac_head;
2462 struct MacEndpoint *endpoint_next;
2464 // just look at all the session for the needed one
2465 while (endpoint != NULL)
2467 queue = endpoint->sessions_head;
2468 endpoint_next = endpoint->next;
2469 while (queue != NULL)
2471 // content is never NULL
2472 GNUNET_assert (queue->content != NULL);
2473 queue_next = queue->next;
2475 (target, &(queue->content->target),
2476 sizeof (struct GNUNET_PeerIdentity)) == 0)
2478 free_session (plugin, queue, GNUNET_YES);
2483 endpoint = endpoint_next;
2488 * Convert the transports address to a nice, human-readable
2491 * @param cls closure
2492 * @param type name of the transport that generated the address
2493 * @param addr one of the addresses of the host, NULL for the last address
2494 * the specific address format depends on the transport
2495 * @param addrlen length of the address
2496 * @param numeric should (IP) addresses be displayed in numeric form?
2497 * @param timeout after how long should we give up?
2498 * @param asc function to call on each string
2499 * @param asc_cls closure for asc
2502 wlan_plugin_address_pretty_printer (void *cls, const char *type,
2503 const void *addr, size_t addrlen,
2505 struct GNUNET_TIME_Relative timeout,
2506 GNUNET_TRANSPORT_AddressStringCallback asc,
2510 const unsigned char *input;
2512 //GNUNET_assert(cls !=NULL);
2513 if (addrlen != sizeof(struct MacAddress))
2515 /* invalid address (MAC addresses have 6 bytes) */
2518 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2519 "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n",
2525 input = (const unsigned char *) addr;
2526 GNUNET_asprintf (&ret,
2527 "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",type,
2528 PROTOCOL_PREFIX, input[0], input[1], input[2], input[3],
2529 input[4], input[5]);
2531 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2532 "Func wlan_plugin_address_pretty_printer got size: %u, nummeric %u, type %s; made string: %s\n",
2533 addrlen, numeric, type, ret);
2535 asc ( asc_cls, ret);
2536 //only one mac address per plugin
2537 asc ( asc_cls, NULL);
2543 * handels the data after all fragments are put together
2544 * @param cls macendpoint this messages belongs to
2545 * @param hdr pointer to the data
2548 wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2550 struct MacEndpoint *endpoint = (struct MacEndpoint *) cls;
2551 struct Plugin *plugin = endpoint->plugin;
2552 struct WlanHeader *wlanheader;
2553 struct Session *session;
2555 const struct GNUNET_MessageHeader *temp_hdr;
2556 struct GNUNET_PeerIdentity tmpsource;
2559 GNUNET_assert (plugin != NULL);
2561 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
2565 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2566 "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
2570 if (ntohs (hdr->size) <
2571 sizeof (struct WlanHeader) + sizeof (struct GNUNET_MessageHeader))
2573 //packet not big enought
2577 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan whole messages received"), 1, GNUNET_NO);
2578 wlanheader = (struct WlanHeader *) hdr;
2580 session = search_session (plugin, endpoint, &wlanheader->source);
2582 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
2583 crc = ntohl (wlanheader->crc);
2584 wlanheader->crc = 0;
2585 if (getcrc32 ((char *) wlanheader, ntohs (wlanheader->header.size)) != crc)
2587 //wrong crc, dispose message
2588 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2589 "Wlan message header crc was wrong: %u != %u\n",
2590 getcrc32 ((char *) wlanheader,
2591 ntohs (wlanheader->header.size)), crc);
2592 hexdump ((void *) hdr, ntohs (hdr->size));
2596 //if not in session list
2597 if (session == NULL)
2600 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2601 "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n",
2602 ntohs (wlanheader->header.size), ntohs (temp_hdr->size),
2603 sizeof (struct WlanHeader));
2605 //try if it is a hello message
2606 if (ntohs (wlanheader->header.size) >=
2607 ntohs (temp_hdr->size) + sizeof (struct WlanHeader))
2609 if (ntohs (temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2611 if (GNUNET_HELLO_get_id
2612 ((const struct GNUNET_HELLO_Message *) temp_hdr,
2613 &tmpsource) == GNUNET_OK)
2615 session = create_session (plugin, endpoint, &tmpsource);
2619 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2620 "WLAN client not in session list and hello message is not okay\n");
2627 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2628 "WLAN client not in session list and not a hello message\n");
2634 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2635 "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n",
2636 ntohs (wlanheader->header.size),
2637 ntohs (temp_hdr->size), sizeof (struct WlanHeader));
2642 //"receive" the message
2645 (&wlanheader->source, &session->target,
2646 sizeof (struct GNUNET_PeerIdentity)) != 0)
2650 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2651 "WLAN peer source id doesn't match packet peer source id: session %p\n",
2658 (&wlanheader->target, plugin->env->my_identity,
2659 sizeof (struct GNUNET_PeerIdentity)) != 0)
2663 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2664 "WLAN peer target id doesn't match our peer id: session %p\n",
2670 GNUNET_SERVER_mst_receive (plugin->data_tokenizer, session,
2671 (const char *) temp_hdr,
2672 ntohs (hdr->size) - sizeof (struct WlanHeader),
2673 GNUNET_YES, GNUNET_NO);
2679 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2680 "wlan_data_message_handler got wrong message type: %u\n",
2687 * function to process the a message, give it to the higher layer
2688 * @param cls pointer to the plugin
2689 * @param client pointer to the session this message belongs to
2690 * @param hdr start of the message
2692 //TODO ATS informations
2694 process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2697 GNUNET_assert (client != NULL);
2698 GNUNET_assert (cls != NULL);
2699 struct Session *session = (struct Session *) client;
2700 struct Plugin *plugin = (struct Plugin *) cls;
2702 struct GNUNET_ATS_Information distance;
2704 distance.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
2705 distance.value = htonl (1);
2708 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2709 "Calling plugin->env->receive for session %p; %s; size: %u\n",
2710 session, wlan_plugin_address_to_string (NULL,
2716 plugin->env->receive (plugin->env->cls, &(session->target), hdr,
2717 (const struct GNUNET_ATS_Information *)
2718 &distance, 1, session,
2719 (const char *) &session->mac->addr,
2720 sizeof (session->mac->addr));
2724 * Function used for to process the data received from the wlan interface
2726 * @param cls the plugin handle
2727 * @param session_light pointer to the struct holding known informations
2728 * @param hdr hdr of the GNUNET_MessageHeader
2729 * @param rxinfo pointer to the radiotap informations got with this packet FIXME: give ATS for info
2732 wlan_data_helper (void *cls, struct Session_light *session_light,
2733 const struct GNUNET_MessageHeader *hdr,
2734 const struct Radiotap_rx *rxinfo)
2736 struct Plugin *plugin = cls;
2737 struct FragmentMessage *fm;
2738 struct FragmentMessage *fm2;
2739 struct GNUNET_PeerIdentity tmpsource;
2741 GNUNET_assert(plugin != NULL);
2744 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2747 //TODO better DOS protection, error handling
2748 //TODO test first than create session
2749 GNUNET_assert (session_light != NULL);
2752 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2753 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_HELLO size: %u; %s\n",
2754 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2755 session_light->addr.
2759 if (session_light->macendpoint == NULL)
2761 session_light->macendpoint =
2762 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2766 if (GNUNET_HELLO_get_id
2767 ((const struct GNUNET_HELLO_Message *) hdr,
2768 &tmpsource) == GNUNET_OK)
2770 session_light->session = search_session (plugin, session_light->macendpoint, &tmpsource);
2771 if (session_light->session == NULL)
2773 session_light->session = create_session (plugin, session_light->macendpoint, &tmpsource);
2775 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello messages received"), 1, GNUNET_NO);
2776 plugin->env->receive(plugin->env->cls,&session_light->session->target,hdr, NULL, 0, session_light->session,
2777 (const char *) &session_light->session->mac->addr,
2778 sizeof (session_light->session->mac->addr));
2782 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2783 "WLAN client not in session list and hello message is not okay\n");
2790 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT)
2793 GNUNET_assert (session_light != NULL);
2794 if (session_light->macendpoint == NULL)
2796 session_light->macendpoint =
2797 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2801 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2802 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size: %u; mac endpoint %p: %s\n",
2803 ntohs (hdr->size), session_light->macendpoint,
2804 wlan_plugin_address_to_string (NULL,
2805 session_light->addr.mac,
2809 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments received"), 1, GNUNET_NO);
2811 GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag,
2814 if (ret == GNUNET_NO)
2816 session_light->macendpoint->dups++;
2818 else if (ret == GNUNET_OK)
2820 session_light->macendpoint->fragc++;
2822 set_next_send (plugin);
2828 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK)
2830 GNUNET_assert (session_light != NULL);
2831 if (session_light->macendpoint == NULL)
2833 session_light->macendpoint =
2834 get_macendpoint (plugin, &session_light->addr, GNUNET_NO);
2837 if (session_light->macendpoint == NULL)
2840 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2841 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n",
2842 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2843 session_light->addr.mac,
2850 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2851 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n",
2852 ntohs (hdr->size), session_light->macendpoint,
2853 wlan_plugin_address_to_string (NULL,
2854 session_light->addr.mac,
2857 fm = session_light->macendpoint->sending_messages_head;
2861 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"), 1, GNUNET_NO);
2862 int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
2864 if (ret == GNUNET_OK)
2866 #if DEBUG_wlan_retransmission > 1
2867 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2868 "Got last ack, finished fragment message %p\n", fm);
2870 session_light->macendpoint->acks++;
2871 fm->session->last_activity = GNUNET_TIME_absolute_get ();
2872 session_light->macendpoint->last_activity = fm->session->last_activity;
2873 free_fragment_message (plugin, fm);
2874 check_fragment_queue (plugin);
2877 if (ret == GNUNET_NO)
2879 #if DEBUG_wlan_retransmission > 1
2880 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2881 "Got ack for: %p\n", fm);
2883 session_light->macendpoint->acks++;
2886 if (ret == GNUNET_SYSERR)
2894 #if DEBUG_wlan_retransmission > 1
2895 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2896 "WLAN fragment not in fragment list\n");
2904 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2905 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n",
2906 ntohs (hdr->type), ntohs (hdr->size));
2912 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2913 "Helper finished\n");
2919 * Function to print mac addresses nice *
2920 * @param pointer to 6 byte with the mac address
2921 * @return pointer to the chars which hold the print out
2924 macprinter (const u_int8_t * mac)
2926 static char macstr[20];
2928 GNUNET_snprintf (macstr, sizeof (macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1],
2929 mac[2], mac[3], mac[4], mac[5]);
2934 * Function for the scheduler if a mac endpoint times out
2935 * @param cls pointer to the MacEndpoint
2936 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
2939 macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2941 struct MacEndpoint *endpoint = cls;
2943 GNUNET_assert (endpoint != NULL);
2944 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2945 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
2949 if (GNUNET_TIME_absolute_get_remaining
2950 (GNUNET_TIME_absolute_add
2951 (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0)
2953 GNUNET_assert(endpoint->plugin != NULL);
2954 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# wlan mac endpoints timeouts"), 1, GNUNET_NO);
2955 free_macendpoint (endpoint->plugin, endpoint);
2959 endpoint->timeout_task =
2960 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
2966 * function to create an macendpoint
2967 * @param plugin pointer to the plugin struct
2968 * @param addr pointer to the macaddress
2969 * @return returns a macendpoint
2971 static struct MacEndpoint *
2972 create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
2974 struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
2976 GNUNET_assert(plugin != NULL);
2977 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan mac endpoints created"), 1, GNUNET_NO);
2978 newend->addr = *addr;
2979 newend->plugin = plugin;
2980 newend->addr = *addr;
2981 newend->fragment_messages_out_count = 0;
2983 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
2984 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
2985 newend, &wlan_data_message_handler,
2987 newend->last_activity = GNUNET_TIME_absolute_get ();
2988 newend->timeout_task =
2989 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
2992 plugin->mac_count++;
2993 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO);
2994 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
2996 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2997 "New Mac Endpoint %p: %s\n", newend,
2998 wlan_plugin_address_to_string (NULL, newend->addr.mac, 6));
3004 * Function used for to process the data from the suid process
3006 * @param cls the plugin handle
3007 * @param client client that send the data (not used)
3008 * @param hdr header of the GNUNET_MessageHeader
3011 wlan_process_helper (void *cls, void *client,
3012 const struct GNUNET_MessageHeader *hdr)
3014 struct Plugin *plugin = cls;
3015 struct ieee80211_frame *wlanIeeeHeader = NULL;
3016 struct Session_light *session_light = NULL;
3017 struct Radiotap_rx *rxinfo;
3018 const struct GNUNET_MessageHeader *temp_hdr = NULL;
3023 GNUNET_assert(plugin != NULL);
3024 switch (ntohs (hdr->type))
3026 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
3028 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3029 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
3033 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan WLAN_HELPER_DATA received"), 1, GNUNET_NO);
3034 //call wlan_process_helper with the message inside, later with wlan: analyze signal
3035 if (ntohs (hdr->size) <
3036 sizeof (struct ieee80211_frame) + 2*sizeof (struct GNUNET_MessageHeader) +
3037 sizeof (struct Radiotap_rx))
3040 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3041 "Size of packet is too small; size: %u min size: %u\n",
3043 sizeof (struct ieee80211_frame) +
3044 sizeof (struct GNUNET_MessageHeader));
3047 /* FIXME: restart SUID process */
3051 rxinfo = (struct Radiotap_rx *) &hdr[1];
3052 wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1];
3054 //process only if it is an broadcast or for this computer both with the gnunet bssid
3058 (&(wlanIeeeHeader->i_addr3), &mac_bssid,
3059 sizeof (struct MacAddress)) == 0)
3061 //check for broadcast or mac
3063 (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
3064 sizeof (struct MacAddress)) == 0) ||
3065 (memcmp (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
3066 sizeof (struct MacAddress)) == 0))
3068 //if packet is from us return
3069 if ((memcmp (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address),
3070 sizeof (struct MacAddress)) == 0)){
3073 // process the inner data
3077 ntohs (hdr->size) - sizeof (struct ieee80211_frame) -
3078 sizeof (struct GNUNET_MessageHeader) - sizeof (struct Radiotap_rx);
3080 session_light = GNUNET_malloc (sizeof (struct Session_light));
3081 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
3082 sizeof (struct MacAddress));
3083 //session_light->session = search_session(plugin,session_light->addr);
3084 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages for this client received"), 1, GNUNET_NO);
3087 while (pos < datasize)
3089 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
3090 if (ntohs(temp_hdr->size) <= datasize + pos)
3092 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages inside WLAN_HELPER_DATA received"), 1, GNUNET_NO);
3093 wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
3098 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3099 "Size of packet is too small; size: %u > size of packet: %u\n",
3100 ntohs(temp_hdr->size),datasize + pos);
3103 pos += ntohs (temp_hdr->size);
3108 GNUNET_free (session_light);
3113 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3114 "Func wlan_process_helper got wrong MAC: %s\n",
3115 macprinter (wlanIeeeHeader->i_addr1));
3122 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3123 "Func wlan_process_helper got wrong BSSID: %s\n",
3124 macprinter (wlanIeeeHeader->i_addr2));
3128 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
3129 //TODO more control messages
3130 if (ntohs (hdr->size) != sizeof (struct Wlan_Helper_Control_Message))
3133 /* FIXME: restart SUID process */
3136 memcpy (&plugin->mac_address, &hdr[1], sizeof (struct MacAddress));
3138 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3139 "Received WLAN_HELPER_CONTROL message with transport of address %s\n",
3140 wlan_plugin_address_to_string (cls, &plugin->mac_address,
3144 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
3145 &plugin->mac_address,
3146 sizeof (struct MacAddress));
3150 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3151 "Func wlan_process_helper got unknown message with number %u, size %u\n",
3152 ntohs (hdr->type), ntohs (hdr->size));
3155 #if DEBUG_wlan_msg_dump > 1
3156 hexdump (hdr, GNUNET_MIN (ntohs (hdr->size), 256));
3164 * Exit point from the plugin.
3165 * @param cls pointer to the api struct
3170 libgnunet_plugin_transport_wlan_done (void *cls)
3172 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3173 struct Plugin *plugin = api->cls;
3174 struct MacEndpoint *endpoint = plugin->mac_head;
3175 struct MacEndpoint *endpoint_next;
3178 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3179 "libgnunet_plugin_transport_wlan_done started\n");
3182 wlan_transport_stop_wlan_helper(plugin);
3184 GNUNET_assert (cls != NULL);
3186 while (endpoint != NULL)
3188 endpoint_next = endpoint->next;
3189 free_macendpoint (plugin, endpoint);
3190 endpoint = endpoint_next;
3195 if (plugin->suid_tokenizer != NULL)
3196 GNUNET_SERVER_mst_destroy (plugin->suid_tokenizer);
3198 if (plugin->data_tokenizer != NULL)
3199 GNUNET_SERVER_mst_destroy (plugin->data_tokenizer);
3201 GNUNET_free_non_null (plugin->interface);
3202 GNUNET_free (plugin);
3208 * Entry point for the plugin.
3210 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
3211 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
3214 libgnunet_plugin_transport_wlan_init (void *cls)
3216 //struct GNUNET_SERVICE_Context *service;
3217 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3218 struct GNUNET_TRANSPORT_PluginFunctions *api;
3219 struct Plugin *plugin;
3221 GNUNET_assert (cls != NULL);
3223 plugin = GNUNET_malloc (sizeof (struct Plugin));
3225 plugin->pendingsessions = 0;
3226 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan pending sessions"), plugin->pendingsessions, GNUNET_NO);
3227 plugin->mac_count = 0;
3228 GNUNET_STATISTICS_set(plugin->env->stats, _("# wlan mac endpoints"), plugin->mac_count, GNUNET_NO);
3229 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
3230 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
3231 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
3232 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
3233 GNUNET_BANDWIDTH_value_init (100 * 1024 *
3236 plugin->suid_tokenizer =
3237 GNUNET_SERVER_mst_create (&wlan_process_helper, plugin);
3239 plugin->data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
3241 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
3242 //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue));
3244 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
3246 api->send = &wlan_plugin_send;
3247 api->disconnect = &wlan_plugin_disconnect;
3248 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
3249 api->check_address = &wlan_plugin_address_suggested;
3250 api->address_to_string = &wlan_plugin_address_to_string;
3254 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE"))
3256 if (GNUNET_SYSERR ==
3257 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
3258 "TESTMODE", &(plugin->testmode)))
3259 plugin->testmode = 0; //default value
3262 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE"))
3264 if (GNUNET_CONFIGURATION_get_value_string
3265 (env->cfg, "transport-wlan", "INTERFACE",
3266 &(plugin->interface)) != GNUNET_YES)
3268 libgnunet_plugin_transport_wlan_done (api);
3274 wlan_transport_start_wlan_helper (plugin);
3275 set_next_beacon_time (plugin);
3276 set_next_send(plugin);
3278 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3279 "wlan init finished\n");
3285 /* end of plugin_transport_wlan.c */