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
123 GNUNET_NETWORK_STRUCT_BEGIN
126 * generic definitions for IEEE 802.11 frames
128 struct ieee80211_frame
132 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
133 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
134 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
138 GNUNET_NETWORK_STRUCT_END
141 * Encapsulation of all of the state of the plugin.
148 struct GNUNET_TRANSPORT_PluginEnvironment *env;
151 * List of open connections. head
153 struct MacEndpoint *mac_head;
156 * List of open connections. tail
158 struct MacEndpoint *mac_tail;
161 * Number of connections
163 unsigned int mac_count;
166 * encapsulation of data from the local wlan helper program
168 struct GNUNET_SERVER_MessageStreamTokenizer *suid_tokenizer;
171 * encapsulation of packets received from the wlan helper
173 struct GNUNET_SERVER_MessageStreamTokenizer *data_tokenizer;
176 * stdout pipe handle for the gnunet-helper-transport-wlan process
178 struct GNUNET_DISK_PipeHandle *server_stdout;
181 * stdout file handle for the gnunet-helper-transport-wlan process
183 const struct GNUNET_DISK_FileHandle *server_stdout_handle;
186 * stdin pipe handle for the gnunet-helper-transport-wlan process
188 struct GNUNET_DISK_PipeHandle *server_stdin;
191 * stdin file handle for the gnunet-helper-transport-wlan process
193 const struct GNUNET_DISK_FileHandle *server_stdin_handle;
196 * ID of the gnunet-wlan-server std read task
198 GNUNET_SCHEDULER_TaskIdentifier server_read_task;
201 * ID of the gnunet-wlan-server std read task
203 GNUNET_SCHEDULER_TaskIdentifier server_write_task;
206 * ID of the delay task for writing
208 GNUNET_SCHEDULER_TaskIdentifier server_write_delay_task;
211 * The process id of the wlan process
213 struct GNUNET_OS_Process *server_proc;
216 * The interface of the wlan card given to us by the user.
221 * Mode of operation for the helper, 0 = normal, 1 = first loopback, 2 = second loopback
223 long long unsigned int testmode;
226 * The mac_address of the wlan card given to us by the helper.
228 struct MacAddress mac_address;
231 * Sessions currently pending for transmission
234 struct Sessionqueue *pending_Sessions_head;
237 * Sessions currently pending for transmission
238 * to a peer (tail), if any.
240 struct Sessionqueue *pending_Sessions_tail;
243 * number of pending sessions
245 unsigned int pendingsessions;
248 * Messages in the sending queues
250 int pending_Fragment_Messages;
253 * messages ready for send, head
255 struct FragmentMessage_queue *sending_messages_head;
257 * messages ready for send, tail
259 struct FragmentMessage_queue *sending_messages_tail;
261 * time of the next "hello-beacon"
263 struct GNUNET_TIME_Absolute beacon_time;
266 * queue to send acks for received fragments (head)
268 struct AckSendQueue *ack_send_queue_head;
271 * queue to send acks for received fragments (tail)
273 struct AckSendQueue *ack_send_queue_tail;
276 * Tracker for bandwidth limit
278 struct GNUNET_BANDWIDTH_Tracker tracker;
281 * saves the current state of the helper process
283 int helper_is_running;
287 * Struct to store data if file write did not accept the whole packet
292 * pointer to the global plugin struct
294 struct Plugin *plugin;
297 * head of the next part to send to the helper
299 char *head_of_next_write;
302 * Start of the message to send, needed for free
304 struct GNUNET_MessageHeader *msgstart;
313 * Queue of sessions, for the general session queue and the pending session queue
318 struct Sessionqueue *next;
319 struct Sessionqueue *prev;
320 struct Session *content;
321 #if !HAVE_UNALIGNED_64_ACCESS
322 void *dummy; /* for alignment, see #1909 */
327 * Queue of fragmented messages, for the sending queue of the plugin
330 struct FragmentMessage_queue
332 struct FragmentMessage_queue *next;
333 struct FragmentMessage_queue *prev;
334 struct FragmentMessage *content;
338 * Queue for the fragments received
341 struct Receive_Fragment_Queue
343 struct Receive_Fragment_Queue *next;
344 struct Receive_Fragment_Queue *prev;
348 struct Radiotap_rx rxinfo;
352 struct MacEndpoint_id_fragment_triple
354 struct MacEndpoint *endpoint;
356 struct FragmentMessage *fm;
360 struct Plugin_Session_pair
362 struct Plugin *plugin;
363 struct Session *session;
367 GNUNET_NETWORK_STRUCT_BEGIN
370 * Header for messages which need fragmentation
375 struct GNUNET_MessageHeader header;
378 * checksum/error correction
380 uint32_t crc GNUNET_PACKED;
383 * To whom are we talking to (set to our identity
384 * if we are still waiting for the welcome message)
386 struct GNUNET_PeerIdentity target;
389 * Where the packet came from
391 struct GNUNET_PeerIdentity source;
393 // followed by payload
396 GNUNET_NETWORK_STRUCT_END
399 * Information kept for each message that is yet to
402 struct PendingMessage
407 struct PendingMessage *next;
411 struct PendingMessage *prev;
414 * The pending message
416 struct WlanHeader *msg;
419 * Size of the message
424 * Continuation function to call once the message
425 * has been sent. Can be NULL if there is no
426 * continuation to call.
428 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
431 * Cls for transmit_cont
433 void *transmit_cont_cls;
436 * Timeout value for the pending message.
438 struct GNUNET_TIME_Absolute timeout;
443 * Queue for acks to send for fragments recived
449 * next ack in the ack send queue
451 struct AckSendQueue *next;
453 * previous ack in the ack send queue
455 struct AckSendQueue *prev;
457 * pointer to the session this ack belongs to
459 struct MacEndpoint *endpoint;
461 * ID of message, to distinguish between the messages, picked randomly.
468 struct GNUNET_MessageHeader *hdr;
470 * pointer to the ieee wlan header
472 struct ieee80211_frame *ieeewlanheader;
474 * pointer to the radiotap header
476 struct Radiotap_Send *radioHeader;
480 * Session infos gathered from a messages
485 * the session this message belongs to
487 struct Session *session;
491 struct MacAddress addr;
496 struct MacEndpoint *macendpoint;
500 * Session handle for connections.
508 struct SessionHeader header;
511 * Message currently pending for transmission
512 * to this peer, if any. head
514 struct PendingMessage *pending_message_head;
517 * Message currently pending for transmission
518 * to this peer, if any. tail
520 struct PendingMessage *pending_message_tail;
523 * To whom are we talking to (set to our identity
524 * if we are still waiting for the welcome message)
526 struct GNUNET_PeerIdentity target;
529 * Address of the other peer (either based on our 'connect'
530 * call or on our 'accept' call).
535 * Last activity on this connection. Used to select preferred
536 * connection and timeout
538 struct GNUNET_TIME_Absolute last_activity;
543 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
548 struct MacEndpoint *mac;
551 * count of messages in the fragment out queue for this session
554 int fragment_messages_out_count;
559 * Struct to represent one network card connection
564 * Pointer to the global plugin struct.
566 struct Plugin *plugin;
568 * Struct to hold the session reachable over this mac; head
570 struct Sessionqueue *sessions_head;
572 * Struct to hold the session reachable over this mac; tail
574 struct Sessionqueue *sessions_tail;
576 * Messages currently sending
579 struct FragmentMessage *sending_messages_head;
582 * Messages currently sending
583 * to a peer (tail), if any.
585 struct FragmentMessage *sending_messages_tail;
589 struct MacEndpoint *next;
593 struct MacEndpoint *prev;
598 struct MacAddress addr;
601 * Defrag context for this mac endpoint
603 struct GNUNET_DEFRAGMENT_Context *defrag;
606 * count of messages in the fragment out queue for this mac endpoint
609 int fragment_messages_out_count;
617 * Duplicates received
632 * Last activity on this endpoint. Used to select preferred
635 struct GNUNET_TIME_Absolute last_activity;
640 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
644 * Struct for Messages in the fragment queue
646 struct FragmentMessage
650 * Session this message belongs to
652 struct Session *session;
655 * This is a doubly-linked list.
657 struct FragmentMessage *next;
660 * This is a doubly-linked list.
662 struct FragmentMessage *prev;
665 * Fragmentation context
667 struct GNUNET_FRAGMENT_Context *fragcontext;
670 * Timeout value for the message.
672 struct GNUNET_TIME_Absolute timeout;
677 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
690 * pointer to the ieee wlan header
692 struct ieee80211_frame *ieeewlanheader;
694 * pointer to the radiotap header
696 struct Radiotap_Send *radioHeader;
700 do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
703 free_session (struct Plugin *plugin, struct Sessionqueue *queue,
704 int do_free_macendpoint);
706 static struct MacEndpoint *
707 create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr);
710 finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
713 * Generates a nice hexdump of a memory area.
715 * \param mem pointer to memory to dump
716 * \param length how many bytes to dump
719 hexdump (const void *mem, unsigned length)
722 char *src = (char *) mem;
724 printf ("dumping %u bytes from %p\r\n"
725 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n",
730 for (i = 0; i < length; i += 16, src += 16)
734 t += sprintf (t, "%04x: ", i);
735 for (j = 0; j < 16; j++)
738 t += sprintf (t, "%02X", src[j] & 0xff);
740 t += sprintf (t, " ");
742 t += sprintf (t, (j % 2) ? " " : "-");
745 t += sprintf (t, " ");
746 for (j = 0; j < 16; j++)
750 if (isprint ((unsigned char) src[j]))
751 t += sprintf (t, "%c", src[j]);
753 t += sprintf (t, ".");
757 t += sprintf (t, " ");
761 t += sprintf (t, "\r\n");
767 * Function to find a MacEndpoint with a specific mac addr
768 * @param plugin pointer to the plugin struct
769 * @param addr pointer to the mac address
770 * @param create_new GNUNET_YES if a new end point should be created
773 static struct MacEndpoint *
774 get_macendpoint (struct Plugin *plugin, const struct MacAddress *addr,
777 struct MacEndpoint *queue = plugin->mac_head;
779 while (queue != NULL)
781 //GNUNET_assert (queue->sessions_head != NULL);
782 if (memcmp (addr, &queue->addr, sizeof (struct MacAddress)) == 0)
783 return queue; /* session found */
787 if (create_new == GNUNET_YES)
789 return create_macendpoint (plugin, addr);
799 * search for a session with the macendpoint and peer id
801 * @param plugin pointer to the plugin struct
802 * @param endpoint pointer to the mac endpoint of the peer
803 * @param peer pointer to the peerid
804 * @return returns the session
806 static struct Session *
807 search_session (struct Plugin *plugin, const struct MacEndpoint *endpoint,
808 const struct GNUNET_PeerIdentity *peer)
810 GNUNET_assert (endpoint != NULL);
811 struct Sessionqueue *queue = endpoint->sessions_head;
813 while (queue != NULL)
815 GNUNET_assert (queue->content != NULL);
817 (peer, &queue->content->target,
818 sizeof (struct GNUNET_PeerIdentity)) == 0)
819 return queue->content; /* session found */
826 * Function called for a quick conversion of the binary address to
827 * a numeric address. Note that the caller must not free the
828 * address and that the next call to this function is allowed
829 * to override the address again.
832 * @param addr binary address
833 * @param addrlen length of the address
834 * @return string representing the same address
837 wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
840 const struct MacAddress *mac;
842 if (addrlen != sizeof (struct MacAddress))
848 GNUNET_snprintf (ret, sizeof (ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
849 PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2],
850 mac->mac[3], mac->mac[4], mac->mac[5]);
856 * Function for the scheduler if a session times out
857 * @param cls pointer to the Sessionqueue
858 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
861 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
863 struct Sessionqueue *queue = cls;
865 GNUNET_assert (queue != NULL);
866 GNUNET_assert (queue->content != NULL);
867 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
868 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
872 if (GNUNET_TIME_absolute_get_remaining
873 (GNUNET_TIME_absolute_add
874 (queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0)
877 GNUNET_assert (queue->content->mac != NULL);
878 GNUNET_assert (queue->content->mac->plugin != NULL);
879 GNUNET_STATISTICS_update (queue->content->mac->plugin->env->stats,
880 _("# wlan session timeouts"), 1, GNUNET_NO);
881 free_session (queue->content->mac->plugin, queue, GNUNET_YES);
885 queue->content->timeout_task =
886 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
891 * create a new session
893 * @param plugin pointer to the plugin struct
894 * @param endpoint pointer to the mac endpoint of the peer
895 * @param peer peer identity to use for this session
896 * @return returns the session
898 static struct Session *
899 create_session (struct Plugin *plugin, struct MacEndpoint *endpoint,
900 const struct GNUNET_PeerIdentity *peer)
902 GNUNET_assert (endpoint != NULL);
903 GNUNET_assert (plugin != NULL);
904 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan session created"), 1,
906 struct Sessionqueue *queue =
907 GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session));
909 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
910 endpoint->sessions_tail, queue);
912 queue->content = (struct Session *) &queue[1];
913 queue->content->mac = endpoint;
914 queue->content->target = *peer;
915 queue->content->last_activity = GNUNET_TIME_absolute_get ();
916 queue->content->timeout_task =
917 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
920 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
921 "New session %p with endpoint %p: %s\n", queue->content,
922 endpoint, wlan_plugin_address_to_string (NULL,
927 return queue->content;
931 * Get session from address, create if no session exists
933 * @param plugin pointer to the plugin struct
934 * @param addr pointer to the mac address of the peer
935 * @param peer pointer to the peerid
936 * @return returns the session
938 static struct Session *
939 get_session (struct Plugin *plugin, const struct MacAddress *addr,
940 const struct GNUNET_PeerIdentity *peer)
942 struct MacEndpoint *mac;
944 mac = get_macendpoint (plugin, addr, GNUNET_YES);
945 struct Session *session = search_session (plugin, mac, peer);
949 return create_session (plugin, mac, peer);
953 * Queue the session to send data
954 * checks if there is a message pending
955 * checks if this session is not allready in the queue
956 * @param plugin pointer to the plugin
957 * @param session pointer to the session to add
960 queue_session (struct Plugin *plugin, struct Session *session)
962 struct Sessionqueue *queue = plugin->pending_Sessions_head;
964 if (session->pending_message_head != NULL)
966 while (queue != NULL)
968 // content is never NULL
969 GNUNET_assert (queue->content != NULL);
970 // is session already in queue?
971 if (session == queue->content)
979 // Session is not in the queue
981 queue = GNUNET_malloc (sizeof (struct Sessionqueue));
982 queue->content = session;
985 GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head,
986 plugin->pending_Sessions_tail, queue);
987 plugin->pendingsessions++;
988 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
989 plugin->pendingsessions, GNUNET_NO);
995 * Function to schedule the write task, executed after a delay
996 * @param cls pointer to the plugin struct
997 * @param tc GNUNET_SCHEDULER_TaskContext pointer
1000 delay_fragment_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1002 struct Plugin *plugin = cls;
1004 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1006 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1009 // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg
1010 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1012 plugin->server_write_task =
1013 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1014 plugin->server_stdin_handle,
1015 &do_transmit, plugin);
1020 * Function to calculate the time of the next periodic "hello-beacon"
1021 * @param plugin pointer to the plugin struct
1024 set_next_beacon_time (struct Plugin *const plugin)
1026 //under 10 known peers: once a second
1027 if (plugin->mac_count < 10)
1029 plugin->beacon_time =
1030 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1031 GNUNET_TIME_relative_multiply
1032 (GNUNET_TIME_UNIT_SECONDS,
1033 HELLO_BEACON_SCALING_FACTOR));
1035 //under 30 known peers: every 10 seconds
1036 else if (plugin->mac_count < 30)
1038 plugin->beacon_time =
1039 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1040 GNUNET_TIME_relative_multiply
1041 (GNUNET_TIME_UNIT_SECONDS,
1042 10 * HELLO_BEACON_SCALING_FACTOR));
1044 //over 30 known peers: once a minute
1047 plugin->beacon_time =
1048 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
1049 GNUNET_TIME_relative_multiply
1050 (GNUNET_TIME_UNIT_MINUTES,
1051 HELLO_BEACON_SCALING_FACTOR));
1056 * Function to set the timer for the next timeout of the fragment queue
1057 * @param plugin the handle to the plugin struct
1060 set_next_send (struct Plugin *const plugin)
1062 struct GNUNET_TIME_Relative next_send;
1064 //abort if helper is not running
1065 if (plugin->helper_is_running == GNUNET_NO)
1071 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1073 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1074 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1077 //check if some acks are in the queue
1078 if (plugin->ack_send_queue_head != NULL)
1080 next_send = GNUNET_TIME_UNIT_ZERO;
1083 //check if there are some fragments in the queue
1084 else if (plugin->sending_messages_head != NULL)
1086 next_send = GNUNET_TIME_UNIT_ZERO;
1090 next_send = GNUNET_TIME_absolute_get_remaining (plugin->beacon_time);
1094 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1095 "Next packet is send in: %u\n", next_send.rel_value);
1098 if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value)
1100 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1102 plugin->server_write_task =
1103 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1104 plugin->server_stdin_handle,
1105 &do_transmit, plugin);
1110 if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK)
1112 plugin->server_write_delay_task =
1113 GNUNET_SCHEDULER_add_delayed (next_send, &delay_fragment_task,
1120 * Function to get the next queued Session, removes the session from the queue
1121 * @param plugin pointer to the plugin struct
1122 * @return pointer to the session found, returns NULL if there is now session in the queue
1124 static struct Session *
1125 get_next_queue_session (struct Plugin *plugin)
1127 struct Session *session;
1128 struct Sessionqueue *sessionqueue;
1129 struct Sessionqueue *sessionqueue_alt;
1130 struct PendingMessage *pm;
1132 sessionqueue = plugin->pending_Sessions_head;
1134 while (sessionqueue != NULL)
1136 session = sessionqueue->content;
1138 GNUNET_assert (session != NULL);
1139 pm = session->pending_message_head;
1144 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1145 "pending message is empty, should not happen. session %p\n",
1148 sessionqueue_alt = sessionqueue;
1149 sessionqueue = sessionqueue->next;
1150 plugin->pendingsessions--;
1151 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1152 plugin->pendingsessions, GNUNET_NO);
1153 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1154 plugin->pending_Sessions_tail,
1157 GNUNET_free (sessionqueue_alt);
1162 //check for message timeout
1163 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
1165 //check if session has no message in the fragment queue
1166 if ((session->mac->fragment_messages_out_count <
1167 FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT) &&
1168 (session->fragment_messages_out_count <
1169 FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
1171 plugin->pendingsessions--;
1172 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1173 plugin->pendingsessions, GNUNET_NO);
1174 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1175 plugin->pending_Sessions_tail,
1177 GNUNET_free (sessionqueue);
1183 sessionqueue = sessionqueue->next;
1188 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1189 session->pending_message_tail, pm);
1191 //call the cont func that it did not work
1192 if (pm->transmit_cont != NULL)
1193 pm->transmit_cont (pm->transmit_cont_cls, &(session->target),
1195 GNUNET_free (pm->msg);
1198 if (session->pending_message_head == NULL)
1200 sessionqueue_alt = sessionqueue;
1201 sessionqueue = sessionqueue->next;
1202 plugin->pendingsessions--;
1203 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
1204 plugin->pendingsessions, GNUNET_NO);
1205 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1206 plugin->pending_Sessions_tail,
1209 GNUNET_free (sessionqueue_alt);
1218 * frees the space of a message in the fragment queue (send queue)
1219 * @param plugin the plugin struct
1220 * @param fm message to free
1223 free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm)
1225 struct Session *session = fm->session;
1226 struct MacEndpoint *endpoint = session->mac;
1227 struct FragmentMessage_queue *fmq;
1228 struct FragmentMessage_queue *fmq_next;
1230 fmq = plugin->sending_messages_head;
1233 fmq_next = fmq->next;
1234 if (fmq->content == fm)
1236 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1237 plugin->sending_messages_tail, fmq);
1243 (session->mac->fragment_messages_out_count)--;
1244 session->fragment_messages_out_count--;
1245 plugin->pending_Fragment_Messages--;
1246 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
1247 plugin->pending_Fragment_Messages, GNUNET_NO);
1248 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
1249 endpoint->sending_messages_tail, fm);
1250 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
1251 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1253 GNUNET_SCHEDULER_cancel (fm->timeout_task);
1254 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1259 queue_session (plugin, session);
1261 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1262 "Free pending fragment messages %p, session %p\n", fm,
1268 * function to fill the radiotap header
1269 * @param plugin pointer to the plugin struct
1270 * @param endpoint pointer to the endpoint
1271 * @param header pointer to the radiotap header
1272 * @return GNUNET_YES at success
1275 getRadiotapHeader (struct Plugin *plugin, struct MacEndpoint *endpoint,
1276 struct Radiotap_Send *header)
1279 if (endpoint != NULL)
1281 header->rate = endpoint->rate;
1282 header->tx_power = endpoint->tx_power;
1283 header->antenna = endpoint->antenna;
1288 header->tx_power = 0;
1289 header->antenna = 0;
1296 * function to generate the wlan hardware header for one packet
1297 * @param Header address to write the header to
1298 * @param to_mac_addr address of the recipient
1299 * @param plugin pointer to the plugin struct
1300 * @param size size of the whole packet, needed to calculate the time to send the packet
1301 * @return GNUNET_YES if there was no error
1304 getWlanHeader (struct ieee80211_frame *Header,
1305 const struct MacAddress *to_mac_addr, struct Plugin *plugin,
1309 const int rate = 11000000;
1311 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA;
1312 Header->i_fc[1] = 0x00;
1313 memcpy (&Header->i_addr3, &mac_bssid_gnunet, sizeof (mac_bssid_gnunet));
1314 memcpy (&Header->i_addr2, plugin->mac_address.mac,
1315 sizeof (plugin->mac_address));
1316 memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress));
1318 tmp16 = (uint16_t *) Header->i_dur;
1319 *tmp16 = (uint16_t) GNUNET_htole16 ((size * 1000000) / rate + 290);
1320 Header->llc[0] = WLAN_LLC_DSAP_FIELD;
1321 Header->llc[1] = WLAN_LLC_SSAP_FIELD;
1328 * function to add a fragment of a message to send
1329 * @param cls FragmentMessage this message belongs to
1330 * @param hdr pointer to the start of the message
1333 add_message_for_send (void *cls, const struct GNUNET_MessageHeader *hdr)
1336 struct FragmentMessage *fm = cls;
1337 struct FragmentMessage_queue *fmqueue;
1339 GNUNET_assert (cls != NULL);
1340 GNUNET_assert (fm->frag == NULL);
1341 struct MacEndpoint *endpoint = fm->session->mac;
1342 struct Plugin *plugin = endpoint->plugin;
1343 struct GNUNET_MessageHeader *msgheader;
1344 struct GNUNET_MessageHeader *msgheader2;
1347 #if DEBUG_wlan_retransmission > 1
1348 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1349 "Adding fragment of message %p to send, session %p, endpoint %p, type %u\n",
1350 fm, fm->session, endpoint, hdr->type);
1354 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1355 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1356 fm->frag = GNUNET_malloc (size);
1359 msgheader = (struct GNUNET_MessageHeader *) fm->frag;
1360 msgheader->size = htons (size);
1361 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1363 fm->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1364 fm->ieeewlanheader = (struct ieee80211_frame *) &fm->radioHeader[1];
1365 msgheader2 = (struct GNUNET_MessageHeader *) &fm->ieeewlanheader[1];
1366 memcpy (msgheader2, hdr, ntohs (hdr->size));
1368 fmqueue = GNUNET_malloc (sizeof (struct FragmentMessage_queue));
1369 fmqueue->content = fm;
1371 GNUNET_CONTAINER_DLL_insert_tail (plugin->sending_messages_head,
1372 plugin->sending_messages_tail, fmqueue);
1373 set_next_send (plugin);
1378 * We have been notified that gnunet-helper-transport-wlan has written something to stdout.
1379 * Handle the output, then reschedule this function to be called again once
1380 * more is available.
1382 * @param cls the plugin handle
1383 * @param tc the scheduling context
1386 wlan_plugin_helper_read (void *cls,
1387 const struct GNUNET_SCHEDULER_TaskContext *tc)
1389 struct Plugin *plugin = cls;
1391 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1393 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1396 char mybuf[WLAN_MTU + sizeof (struct GNUNET_MessageHeader)];
1400 GNUNET_DISK_file_read (plugin->server_stdout_handle, mybuf,
1405 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1407 ("Finished reading from gnunet-helper-transport-wlan stdout with code: %d\n"),
1412 GNUNET_SERVER_mst_receive (plugin->suid_tokenizer, NULL, mybuf, bytes,
1413 GNUNET_NO, GNUNET_NO);
1415 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
1416 plugin->server_read_task =
1417 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1418 plugin->server_stdout_handle,
1419 &wlan_plugin_helper_read, plugin);
1423 * Start the gnunet-helper-transport-wlan process.
1425 * @param plugin the transport plugin
1426 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
1429 wlan_transport_start_wlan_helper (struct Plugin *plugin)
1431 const char *filenamehw = "gnunet-helper-transport-wlan";
1432 const char *filenameloopback = "gnunet-helper-transport-wlan-dummy";
1433 char *absolute_filename = NULL;
1435 if (plugin->helper_is_running == GNUNET_YES)
1438 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1439 "wlan_transport_start_wlan_helper not needed, helper already running!");
1444 plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
1445 if (plugin->server_stdout == NULL)
1446 return GNUNET_SYSERR;
1448 plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
1449 if (plugin->server_stdin == NULL)
1450 return GNUNET_SYSERR;
1452 if ((plugin->testmode == 1) || (plugin->testmode == 2))
1454 if (GNUNET_OS_check_helper_binary (filenameloopback) == GNUNET_YES)
1456 absolute_filename = GNUNET_strdup (filenameloopback);
1460 char cwd[FILENAME_MAX];
1462 GNUNET_assert (getcwd (cwd, sizeof (cwd)) != NULL);
1464 GNUNET_asprintf (&absolute_filename, "%s%s%s", cwd, DIR_SEPARATOR_STR,
1467 if (GNUNET_DISK_file_test (filenameloopback) != GNUNET_YES)
1469 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1470 "Helper `%s' not found! %i\n", absolute_filename);
1476 /* Start the server process */
1478 if (plugin->testmode == 0)
1482 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1483 "Starting gnunet-helper-transport-wlan process cmd: %s %s %i\n",
1484 filenamehw, plugin->interface, plugin->testmode);
1487 if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_YES)
1489 plugin->server_proc =
1490 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1491 filenamehw, filenamehw, plugin->interface,
1494 else if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_NO)
1496 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1497 "gnunet-helper-transport-wlan is not suid, please change it or look at the doku\n");
1502 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1503 "gnunet-helper-transport-wlan not found, please look if it exists and is the $PATH variable!\n");
1508 else if (plugin->testmode == 1)
1512 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
1513 "Starting gnunet-helper-transport-wlan-dummy loopback 1 process cmd: %s %s %i\n",
1514 absolute_filename, plugin->interface, plugin->testmode);
1516 plugin->server_proc =
1517 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1518 absolute_filename, absolute_filename, "1",
1520 if (plugin->server_proc == NULL)
1522 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1523 "`%s' not found, please look if it exists and is in the $PATH variable!\n",
1528 else if (plugin->testmode == 2)
1531 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
1532 "Starting gnunet-helper-transport-wlan-dummy loopback 2 process cmd: %s %s %i\n",
1533 absolute_filename, plugin->interface, plugin->testmode);
1536 plugin->server_proc =
1537 GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout,
1538 absolute_filename, absolute_filename, "2",
1540 if (plugin->server_proc == NULL)
1542 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1543 "`%s' not found, please look if it exists and is in the $PATH variable!\n",
1548 if (absolute_filename != NULL)
1549 GNUNET_free (absolute_filename);
1550 if (plugin->server_proc == NULL)
1553 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1554 "Failed to start gnunet-helper-transport-wlan process\n");
1556 return GNUNET_SYSERR;
1561 /* Close the write end of the read pipe */
1562 GNUNET_DISK_pipe_close_end (plugin->server_stdout,
1563 GNUNET_DISK_PIPE_END_WRITE);
1565 /* Close the read end of the write pipe */
1566 GNUNET_DISK_pipe_close_end (plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
1568 plugin->server_stdout_handle =
1569 GNUNET_DISK_pipe_handle (plugin->server_stdout,
1570 GNUNET_DISK_PIPE_END_READ);
1571 plugin->server_stdin_handle =
1572 GNUNET_DISK_pipe_handle (plugin->server_stdin,
1573 GNUNET_DISK_PIPE_END_WRITE);
1575 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
1578 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1579 "Adding server_read_task for the gnunet-helper-transport-wlan\n");
1582 plugin->server_read_task =
1583 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1584 plugin->server_stdout_handle,
1585 &wlan_plugin_helper_read, plugin);
1587 plugin->helper_is_running = GNUNET_YES;
1592 * Stops the gnunet-helper-transport-wlan process.
1594 * @param plugin the transport plugin
1595 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
1598 wlan_transport_stop_wlan_helper (struct Plugin *plugin)
1601 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1602 "Stoping WLAN helper process\n");
1605 if (plugin->helper_is_running == GNUNET_NO)
1608 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1609 "wlan_transport_stop_wlan_helper not needed, helper already stopped!");
1614 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1616 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1617 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1620 if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK)
1622 GNUNET_SCHEDULER_cancel (plugin->server_write_task);
1623 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1626 if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK)
1628 GNUNET_SCHEDULER_cancel (plugin->server_read_task);
1629 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1632 GNUNET_DISK_pipe_close (plugin->server_stdout);
1633 GNUNET_DISK_pipe_close (plugin->server_stdin);
1634 GNUNET_OS_process_kill (plugin->server_proc, SIGKILL);
1635 GNUNET_OS_process_wait (plugin->server_proc);
1636 GNUNET_OS_process_close (plugin->server_proc);
1638 plugin->helper_is_running = GNUNET_NO;
1644 * function for delayed restart of the helper process
1645 * @param cls Finish_send struct if message should be finished
1646 * @param tc TaskContext
1649 delay_restart_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1651 struct Finish_send *finish = cls;
1652 struct Plugin *plugin;
1654 plugin = finish->plugin;
1656 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1657 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1659 GNUNET_free_non_null (finish->msgstart);
1660 GNUNET_free (finish);
1664 wlan_transport_start_wlan_helper (plugin);
1666 if (finish->size != 0)
1668 plugin->server_write_task =
1669 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1670 plugin->server_stdin_handle,
1671 &finish_sending, finish);
1675 set_next_send (plugin);
1676 GNUNET_free_non_null (finish->msgstart);
1677 GNUNET_free (finish);
1683 * Function to restart the helper
1684 * @param plugin pointer to the global plugin struct
1685 * @param finish pointer to the Finish_send struct to finish
1688 restart_helper (struct Plugin *plugin, struct Finish_send *finish)
1690 static struct GNUNET_TIME_Relative next_try = { 1000 };
1691 GNUNET_assert (finish != NULL);
1693 wlan_transport_stop_wlan_helper (plugin);
1694 plugin->server_write_task =
1695 GNUNET_SCHEDULER_add_delayed (next_try, &delay_restart_helper, finish);
1696 GNUNET_TIME_relative_multiply (next_try, HELPER_RESTART_SCALING_FACTOR);
1701 * function to finish a sending if not all could have been writen befor
1702 * @param cls pointer to the Finish_send struct
1703 * @param tc TaskContext
1706 finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1708 struct Finish_send *finish = cls;
1709 struct Plugin *plugin;
1712 plugin = finish->plugin;
1713 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1715 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1717 GNUNET_free (finish->msgstart);
1718 GNUNET_free (finish);
1722 GNUNET_DISK_file_write (plugin->server_stdin_handle,
1723 finish->head_of_next_write, finish->size);
1725 if (bytes != finish->size)
1727 if (bytes != GNUNET_SYSERR)
1729 finish->head_of_next_write += bytes;
1730 finish->size -= bytes;
1731 plugin->server_write_task =
1732 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1733 plugin->server_stdin_handle,
1734 &finish_sending, finish);
1738 restart_helper (plugin, finish);
1743 GNUNET_free (finish->msgstart);
1744 GNUNET_free (finish);
1745 set_next_send (plugin);
1750 * function to send a hello beacon
1751 * @param plugin pointer to the plugin struct
1754 send_hello_beacon (struct Plugin *plugin)
1758 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1759 "Sending hello beacon\n");
1764 uint16_t hello_size;
1765 struct GNUNET_MessageHeader *msgheader;
1766 struct ieee80211_frame *ieeewlanheader;
1767 struct Radiotap_Send *radioHeader;
1768 struct GNUNET_MessageHeader *msgheader2;
1769 const struct GNUNET_MessageHeader *hello;
1770 struct Finish_send *finish;
1772 GNUNET_assert (plugin != NULL);
1774 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan hello beacons send"),
1777 hello = plugin->env->get_our_hello ();
1778 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1779 GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
1781 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1782 sizeof (struct ieee80211_frame) + hello_size;
1784 msgheader = GNUNET_malloc (size);
1785 msgheader->size = htons (size);
1786 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1788 radioHeader = (struct Radiotap_Send *) &msgheader[1];
1789 getRadiotapHeader (plugin, NULL, radioHeader);
1790 ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
1791 getWlanHeader (ieeewlanheader, &bc_all_mac, plugin, size);
1793 msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1];
1794 /*msgheader2->size =
1795 * htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) +
1796 * sizeof (struct GNUNET_MessageHeader));
1798 * msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); */
1799 memcpy (msgheader2, hello, hello_size);
1801 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size);
1803 if (bytes == GNUNET_SYSERR)
1805 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1807 ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
1808 errno, strerror (errno));
1809 finish = GNUNET_malloc (sizeof (struct Finish_send));
1810 finish->plugin = plugin;
1811 finish->head_of_next_write = NULL;
1813 finish->msgstart = NULL;
1814 restart_helper (plugin, finish);
1816 set_next_beacon_time (plugin);
1821 GNUNET_assert (bytes == size);
1822 set_next_beacon_time (plugin);
1823 set_next_send (plugin);
1825 GNUNET_free (msgheader);
1831 * function to add an ack to send it for a received fragment
1832 * @param cls MacEndpoint this ack belongs to
1833 * @param msg_id id of the message
1834 * @param hdr pointer to the hdr where the ack is stored
1838 add_ack_for_send (void *cls, uint32_t msg_id,
1839 const struct GNUNET_MessageHeader *hdr)
1842 struct AckSendQueue *ack;
1844 GNUNET_assert (cls != NULL);
1845 struct MacEndpoint *endpoint = cls;
1846 struct Plugin *plugin = endpoint->plugin;
1847 struct GNUNET_MessageHeader *msgheader;
1848 struct GNUNET_MessageHeader *msgheader2;
1852 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1853 sizeof (struct ieee80211_frame) + ntohs (hdr->size) +
1854 sizeof (struct AckSendQueue);
1856 ack = GNUNET_malloc (size);
1857 ack->message_id = msg_id;
1858 ack->endpoint = endpoint;
1861 sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send) +
1862 sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1864 msgheader = (struct GNUNET_MessageHeader *) &ack[1];
1865 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1];
1866 msgheader->size = htons (size);
1867 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1869 ack->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1870 ack->ieeewlanheader = (struct ieee80211_frame *) &(ack->radioHeader)[1];
1871 msgheader2 = (struct GNUNET_MessageHeader *) &(ack->ieeewlanheader)[1];
1872 memcpy (msgheader2, hdr, ntohs (hdr->size));
1874 GNUNET_CONTAINER_DLL_insert_tail (plugin->ack_send_queue_head,
1875 plugin->ack_send_queue_tail, ack);
1877 #if DEBUG_wlan_retransmission > 1
1878 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1879 "Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n",
1880 msg_id, ack, endpoint);
1883 set_next_send (plugin);
1887 * Function for the scheduler if a FragmentMessage times out
1888 * @param cls pointer to the FragmentMessage
1889 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
1892 fragmentmessage_timeout (void *cls,
1893 const struct GNUNET_SCHEDULER_TaskContext *tc)
1895 struct FragmentMessage *fm = cls;
1897 GNUNET_assert (fm != NULL);
1898 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1899 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1903 free_fragment_message (fm->session->mac->plugin, fm);
1907 * Function to check if there is some space in the fragment queue
1908 * inserts a message if space is available
1909 * @param plugin the plugin struct
1913 check_fragment_queue (struct Plugin *plugin)
1915 struct Session *session;
1916 struct FragmentMessage *fm;
1917 struct GNUNET_PeerIdentity pid;
1919 struct PendingMessage *pm;
1921 if (plugin->pending_Fragment_Messages < FRAGMENT_QUEUE_SIZE)
1923 session = get_next_queue_session (plugin);
1924 if (session != NULL)
1926 pm = session->pending_message_head;
1927 GNUNET_assert (pm != NULL);
1928 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1929 session->pending_message_tail, pm);
1930 session->mac->fragment_messages_out_count++;
1931 session->fragment_messages_out_count++;
1932 plugin->pending_Fragment_Messages++;
1933 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending fragments"),
1934 plugin->pending_Fragment_Messages, GNUNET_NO);
1936 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
1937 fm->session = session;
1938 fm->timeout.abs_value = pm->timeout.abs_value;
1941 GNUNET_FRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
1943 GNUNET_TIME_UNIT_SECONDS,
1945 &add_message_for_send, fm);
1947 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
1948 (fm->timeout), fragmentmessage_timeout,
1950 GNUNET_CONTAINER_DLL_insert_tail (session->mac->sending_messages_head,
1951 session->mac->sending_messages_tail,
1954 if (pm->transmit_cont != NULL)
1956 pid = session->target;
1957 pm->transmit_cont (pm->transmit_cont_cls, &pid, GNUNET_OK);
1959 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1960 "called pm->transmit_cont for %p\n", session);
1966 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1967 "no pm->transmit_cont for %p\n", session);
1972 if (session->pending_message_head != NULL)
1975 queue_session (plugin, session);
1981 //check if timeout changed
1982 set_next_send (plugin);
1986 * Function to send an ack, does not free the ack
1987 * @param plugin pointer to the plugin
1990 send_ack (struct Plugin *plugin)
1994 struct AckSendQueue *ack;
1995 struct Finish_send *finish;
1997 ack = plugin->ack_send_queue_head;
2001 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2002 "Sending ack for message_id %u for mac endpoint %p, size %u\n",
2003 ack->message_id, ack->endpoint,
2004 ntohs (ack->hdr->size) - sizeof (struct Radiotap_Send));
2007 GNUNET_assert (plugin != NULL);
2008 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks send"), 1,
2011 getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader);
2012 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
2013 ntohs (ack->hdr->size));
2016 GNUNET_DISK_file_write (plugin->server_stdin_handle, ack->hdr,
2017 ntohs (ack->hdr->size));
2018 if (bytes == GNUNET_SYSERR)
2020 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2022 ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
2023 errno, strerror (errno));
2024 finish = GNUNET_malloc (sizeof (struct Finish_send));
2025 finish->plugin = plugin;
2026 finish->head_of_next_write = NULL;
2028 finish->msgstart = NULL;
2029 restart_helper (plugin, finish);
2033 GNUNET_assert (bytes == ntohs (ack->hdr->size));
2034 GNUNET_CONTAINER_DLL_remove (plugin->ack_send_queue_head,
2035 plugin->ack_send_queue_tail, ack);
2037 set_next_send (plugin);
2042 * Function called when wlan helper is ready to get some data
2044 * @param cls closure
2045 * @param tc GNUNET_SCHEDULER_TaskContext
2048 do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2050 struct Plugin *plugin = cls;
2052 GNUNET_assert (plugin != NULL);
2054 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2055 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2058 struct Session *session;
2059 struct FragmentMessage *fm;
2060 struct Finish_send *finish;
2061 struct FragmentMessage_queue *fmq;
2064 if (plugin->ack_send_queue_head != NULL)
2070 //test if a "hello-beacon" has to be send
2071 if (GNUNET_TIME_absolute_get_remaining (plugin->beacon_time).rel_value == 0)
2073 send_hello_beacon (plugin);
2077 if (plugin->sending_messages_head != NULL)
2079 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan fragments send"), 1,
2082 fmq = plugin->sending_messages_head;
2084 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
2085 plugin->sending_messages_tail, fmq);
2088 session = fm->session;
2089 GNUNET_assert (session != NULL);
2092 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2093 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p, size: %u\n",
2097 getRadiotapHeader (plugin, session->mac, fm->radioHeader);
2098 getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
2102 GNUNET_DISK_file_write (plugin->server_stdin_handle, fm->frag,
2106 if (bytes != fm->size)
2108 finish = GNUNET_malloc (sizeof (struct Finish_send));
2109 finish->plugin = plugin;
2110 finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag;
2111 GNUNET_assert (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
2113 if (bytes == GNUNET_SYSERR)
2115 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2117 ("Error writing to wlan helper. errno == %d, ERROR: %s\n"),
2118 errno, strerror (errno));
2120 finish->head_of_next_write = fm->frag;
2121 finish->size = fm->size;
2122 restart_helper (plugin, finish);
2126 finish->head_of_next_write = fm->frag + bytes;
2127 finish->size = fm->size - bytes;
2128 plugin->server_write_task =
2129 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
2130 plugin->server_stdin_handle,
2131 &finish_sending, finish);
2138 GNUNET_free (fm->frag);
2140 set_next_send (plugin);
2142 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
2147 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2148 "do_transmit did nothing, should not happen!\n");
2150 set_next_send (plugin);
2154 * Another peer has suggested an address for this
2155 * peer and transport plugin. Check that this could be a valid
2156 * address. If so, consider adding it to the list
2159 * @param cls closure
2160 * @param addr pointer to the address
2161 * @param addrlen length of addr
2162 * @return GNUNET_OK if this is a plausible address for this peer
2166 wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
2168 //struct Plugin *plugin = cls;
2170 /* check if the address is plausible; if so,
2171 * add it to our list! */
2173 GNUNET_assert (cls != NULL);
2174 //FIXME mitm is not checked
2175 //Mac Address has 6 bytes
2178 /* TODO check for bad addresses like multicast, broadcast, etc */
2180 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2181 "wlan_plugin_address_suggested got good address, size %u!\n",
2187 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2188 "wlan_plugin_address_suggested got bad address, size %u!\n",
2191 return GNUNET_SYSERR;
2196 * Creates a new outbound session the transport service will use to send data to the
2199 * @param cls the plugin
2200 * @param address the address
2201 * @return the session or NULL of max connections exceeded
2204 static struct Session *
2205 wlan_plugin_get_session (void *cls,
2206 const struct GNUNET_HELLO_Address *address)
2208 struct Session * s = NULL;
2209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "To be implemented\n");
2215 * Function that can be used by the transport service to transmit
2216 * a message using the plugin. Note that in the case of a
2217 * peer disconnecting, the continuation MUST be called
2218 * prior to the disconnect notification itself. This function
2219 * will be called with this peer's HELLO message to initiate
2220 * a fresh connection to another peer.
2222 * @param cls closure
2223 * @param session which session must be used
2224 * @param msgbuf the message to transmit
2225 * @param msgbuf_size number of bytes in 'msgbuf'
2226 * @param priority how important is the message (most plugins will
2227 * ignore message priority and just FIFO)
2228 * @param to how long to wait at most for the transmission (does not
2229 * require plugins to discard the message after the timeout,
2230 * just advisory for the desired delay; most plugins will ignore
2232 * @param cont continuation to call once the message has
2233 * been transmitted (or if the transport is ready
2234 * for the next transmission call; or if the
2235 * peer disconnected...); can be NULL
2236 * @param cont_cls closure for cont
2237 * @return number of bytes used (on the physical network, with overheads);
2238 * -1 on hard errors (i.e. address invalid); 0 is a legal value
2239 * and does NOT mean that the message was not transmitted (DV)
2242 wlan_plugin_send (void *cls,
2243 struct Session *session,
2244 const char *msgbuf, size_t msgbuf_size,
2245 unsigned int priority,
2246 struct GNUNET_TIME_Relative to,
2247 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
2250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "To be implemented\n");
2257 * Function that can be used by the transport service to transmit
2258 * a message using the plugin.
2260 * @param cls closure
2261 * @param target who should receive this message
2262 * @param priority how important is the message
2263 * @param msgbuf the message to transmit
2264 * @param msgbuf_size number of bytes in 'msgbuf'
2265 * @param timeout when should we time out
2266 * @param session which session must be used (or NULL for "any")
2267 * @param addr the address to use (can be NULL if the plugin
2268 * is "on its own" (i.e. re-use existing TCP connection))
2269 * @param addrlen length of the address in bytes
2270 * @param force_address GNUNET_YES if the plugin MUST use the given address,
2271 * otherwise the plugin may use other addresses or
2272 * existing connections (if available)
2273 * @param cont continuation to call once the message has
2274 * been transmitted (or if the transport is ready
2275 * for the next transmission call; or if the
2276 * peer disconnected...)
2277 * @param cont_cls closure for cont
2278 * @return number of bytes used (on the physical network, with overheads);
2279 * -1 on hard errors (i.e. address invalid); 0 is a legal value
2280 * and does NOT mean that the message was not transmitted (DV)
2283 wlan_plugin_send_old (void *cls, const struct GNUNET_PeerIdentity *target,
2284 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
2285 struct GNUNET_TIME_Relative timeout, struct Session *session,
2286 const void *addr, size_t addrlen, int force_address,
2287 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
2289 struct Plugin *plugin = cls;
2290 struct PendingMessage *newmsg;
2291 struct WlanHeader *wlanheader;
2293 GNUNET_assert (plugin != NULL);
2294 //check if msglen > 0
2295 GNUNET_assert (msgbuf_size > 0);
2297 //get session if needed
2298 if (session == NULL)
2300 if (wlan_plugin_address_suggested (plugin, addr, addrlen) == GNUNET_OK)
2302 session = get_session (plugin, addr, target);
2306 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
2307 _("Wlan Address len %d is wrong\n"), addrlen);
2312 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan messages queued"), 1,
2317 //queue message in session
2318 //test if there is no other message in the "queue"
2319 //FIXME: to many send requests
2320 if (session->pending_message_head != NULL)
2322 newmsg = session->pending_message_head;
2323 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2324 "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",
2325 GNUNET_TIME_absolute_get_remaining (newmsg->
2327 session->mac->fragment_messages_out_count);
2330 newmsg = GNUNET_malloc (sizeof (struct PendingMessage));
2331 newmsg->msg = GNUNET_malloc (msgbuf_size + sizeof (struct WlanHeader));
2332 wlanheader = newmsg->msg;
2333 //copy msg to buffer, not fragmented / segmented yet, but with message header
2334 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
2335 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
2336 memcpy (&(wlanheader->target), target, sizeof (struct GNUNET_PeerIdentity));
2337 memcpy (&(wlanheader->source), plugin->env->my_identity,
2338 sizeof (struct GNUNET_PeerIdentity));
2339 wlanheader->crc = 0;
2340 memcpy (&wlanheader[1], msgbuf, msgbuf_size);
2342 htonl (GNUNET_CRYPTO_crc32_n
2343 ((char *) wlanheader, msgbuf_size + sizeof (struct WlanHeader)));
2345 newmsg->transmit_cont = cont;
2346 newmsg->transmit_cont_cls = cont_cls;
2347 newmsg->timeout = GNUNET_TIME_relative_to_absolute (timeout);
2349 newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
2351 newmsg->message_size = msgbuf_size + sizeof (struct WlanHeader);
2353 GNUNET_CONTAINER_DLL_insert_tail (session->pending_message_head,
2354 session->pending_message_tail, newmsg);
2357 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2358 "New message for %p with size (incl wlan header) %u added\n",
2359 session, newmsg->message_size);
2361 #if DEBUG_wlan_msg_dump > 1
2362 hexdump (msgbuf, GNUNET_MIN (msgbuf_size, 256));
2365 queue_session (plugin, session);
2367 check_fragment_queue (plugin);
2368 //FIXME not the correct size
2374 * function to free a mac endpoint
2375 * @param plugin pointer to the plugin struct
2376 * @param endpoint pointer to the MacEndpoint to free
2379 free_macendpoint (struct Plugin *plugin, struct MacEndpoint *endpoint)
2381 struct Sessionqueue *sessions;
2382 struct Sessionqueue *sessions_next;
2384 GNUNET_assert (endpoint != NULL);
2386 sessions = endpoint->sessions_head;
2387 while (sessions != NULL)
2389 sessions_next = sessions->next;
2390 free_session (plugin, sessions, GNUNET_NO);
2391 sessions = sessions_next;
2394 GNUNET_CONTAINER_DLL_remove (plugin->mac_head, plugin->mac_tail, endpoint);
2395 if (endpoint->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2397 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
2398 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2400 plugin->mac_count--;
2401 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
2402 plugin->mac_count, GNUNET_NO);
2403 GNUNET_free (endpoint);
2408 * function to free a session
2409 * @param plugin pointer to the plugin
2410 * @param queue pointer to the sessionqueue element to free
2411 * @param do_free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint
2414 free_session (struct Plugin *plugin, struct Sessionqueue *queue,
2415 int do_free_macendpoint)
2417 struct Sessionqueue *pendingsession;
2418 struct Sessionqueue *pendingsession_tmp;
2419 struct PendingMessage *pm;
2420 struct MacEndpoint *endpoint;
2421 struct FragmentMessage *fm;
2422 struct FragmentMessage *fmnext;
2425 GNUNET_assert (plugin != NULL);
2426 GNUNET_assert (queue != NULL);
2427 GNUNET_assert (queue->content != NULL);
2430 //is this session pending for send
2431 pendingsession = plugin->pending_Sessions_head;
2432 while (pendingsession != NULL)
2434 pendingsession_tmp = pendingsession;
2435 pendingsession = pendingsession->next;
2436 GNUNET_assert (pendingsession_tmp->content != NULL);
2437 if (pendingsession_tmp->content == queue->content)
2439 plugin->pendingsessions--;
2440 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
2441 plugin->pendingsessions, GNUNET_NO);
2442 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
2443 plugin->pending_Sessions_tail,
2444 pendingsession_tmp);
2445 GNUNET_free (pendingsession_tmp);
2447 GNUNET_assert (check == 0);
2452 endpoint = queue->content->mac;
2453 fm = endpoint->sending_messages_head;
2457 if (fm->session == queue->content)
2459 free_fragment_message (plugin, fm);
2464 // remove PendingMessage
2465 pm = queue->content->pending_message_head;
2468 GNUNET_CONTAINER_DLL_remove (queue->content->pending_message_head,
2469 queue->content->pending_message_tail, pm);
2470 GNUNET_free (pm->msg);
2472 pm = queue->content->pending_message_head;
2475 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, endpoint->sessions_tail,
2477 //Check that no ohter session on this endpoint for this session exits
2478 GNUNET_assert (search_session (plugin, endpoint, &queue->content->target) ==
2480 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
2482 free_macendpoint (plugin, endpoint);
2483 //check if no endpoint with the same address exists
2484 GNUNET_assert (get_macendpoint (plugin, &endpoint->addr, GNUNET_NO) ==
2488 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK)
2490 GNUNET_SCHEDULER_cancel (queue->content->timeout_task);
2491 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2493 GNUNET_free (queue);
2495 check_fragment_queue (plugin);
2499 * Function that can be used to force the plugin to disconnect
2500 * from the given peer and cancel all previous transmissions
2501 * (and their continuation).
2503 * @param cls closure
2504 * @param target peer from which to disconnect
2507 wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2509 struct Plugin *plugin = cls;
2510 struct Sessionqueue *queue;
2511 struct Sessionqueue *queue_next;
2512 struct MacEndpoint *endpoint = plugin->mac_head;
2513 struct MacEndpoint *endpoint_next;
2515 // just look at all the session for the needed one
2516 while (endpoint != NULL)
2518 queue = endpoint->sessions_head;
2519 endpoint_next = endpoint->next;
2520 while (queue != NULL)
2522 // content is never NULL
2523 GNUNET_assert (queue->content != NULL);
2524 queue_next = queue->next;
2526 (target, &(queue->content->target),
2527 sizeof (struct GNUNET_PeerIdentity)) == 0)
2529 free_session (plugin, queue, GNUNET_YES);
2534 endpoint = endpoint_next;
2539 * Convert the transports address to a nice, human-readable
2542 * @param cls closure
2543 * @param type name of the transport that generated the address
2544 * @param addr one of the addresses of the host, NULL for the last address
2545 * the specific address format depends on the transport
2546 * @param addrlen length of the address
2547 * @param numeric should (IP) addresses be displayed in numeric form?
2548 * @param timeout after how long should we give up?
2549 * @param asc function to call on each string
2550 * @param asc_cls closure for asc
2553 wlan_plugin_address_pretty_printer (void *cls, const char *type,
2554 const void *addr, size_t addrlen,
2556 struct GNUNET_TIME_Relative timeout,
2557 GNUNET_TRANSPORT_AddressStringCallback asc,
2561 const unsigned char *input;
2563 //GNUNET_assert(cls !=NULL);
2564 if (addrlen != sizeof (struct MacAddress))
2566 /* invalid address (MAC addresses have 6 bytes) */
2569 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2570 "Func wlan_plugin_address_pretty_printer got size: %u, worng size!\n",
2573 asc (asc_cls, NULL);
2576 input = (const unsigned char *) addr;
2577 GNUNET_asprintf (&ret,
2578 "Transport %s: %s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
2579 type, PROTOCOL_PREFIX, input[0], input[1], input[2],
2580 input[3], input[4], input[5]);
2582 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2583 "Func wlan_plugin_address_pretty_printer got size: %u, nummeric %u, type %s; made string: %s\n",
2584 addrlen, numeric, type, ret);
2587 //only one mac address per plugin
2588 asc (asc_cls, NULL);
2594 * handels the data after all fragments are put together
2595 * @param cls macendpoint this messages belongs to
2596 * @param hdr pointer to the data
2599 wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2601 struct MacEndpoint *endpoint = (struct MacEndpoint *) cls;
2602 struct Plugin *plugin = endpoint->plugin;
2603 struct WlanHeader *wlanheader;
2604 struct Session *session;
2606 const struct GNUNET_MessageHeader *temp_hdr;
2607 struct GNUNET_PeerIdentity tmpsource;
2610 GNUNET_assert (plugin != NULL);
2612 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
2616 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2617 "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
2621 if (ntohs (hdr->size) <
2622 sizeof (struct WlanHeader) + sizeof (struct GNUNET_MessageHeader))
2624 //packet not big enought
2628 GNUNET_STATISTICS_update (plugin->env->stats,
2629 _("# wlan whole messages received"), 1,
2631 wlanheader = (struct WlanHeader *) hdr;
2633 session = search_session (plugin, endpoint, &wlanheader->source);
2635 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
2636 crc = ntohl (wlanheader->crc);
2637 wlanheader->crc = 0;
2638 if (GNUNET_CRYPTO_crc32_n
2639 ((char *) wlanheader, ntohs (wlanheader->header.size)) != crc)
2641 //wrong crc, dispose message
2642 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2643 "Wlan message header crc was wrong: %u != %u\n",
2644 GNUNET_CRYPTO_crc32_n ((char *) wlanheader,
2645 ntohs (wlanheader->header.size)),
2647 hexdump ((void *) hdr, ntohs (hdr->size));
2651 //if not in session list
2652 if (session == NULL)
2655 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2656 "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n",
2657 ntohs (wlanheader->header.size), ntohs (temp_hdr->size),
2658 sizeof (struct WlanHeader));
2660 //try if it is a hello message
2661 if (ntohs (wlanheader->header.size) >=
2662 ntohs (temp_hdr->size) + sizeof (struct WlanHeader))
2664 if (ntohs (temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2666 if (GNUNET_HELLO_get_id
2667 ((const struct GNUNET_HELLO_Message *) temp_hdr,
2668 &tmpsource) == GNUNET_OK)
2670 session = create_session (plugin, endpoint, &tmpsource);
2674 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2675 "WLAN client not in session list and hello message is not okay\n");
2682 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2683 "WLAN client not in session list and not a hello message\n");
2689 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2690 "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n",
2691 ntohs (wlanheader->header.size),
2692 ntohs (temp_hdr->size), sizeof (struct WlanHeader));
2697 //"receive" the message
2700 (&wlanheader->source, &session->target,
2701 sizeof (struct GNUNET_PeerIdentity)) != 0)
2705 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2706 "WLAN peer source id doesn't match packet peer source id: session %p\n",
2713 (&wlanheader->target, plugin->env->my_identity,
2714 sizeof (struct GNUNET_PeerIdentity)) != 0)
2718 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2719 "WLAN peer target id doesn't match our peer id: session %p\n",
2725 GNUNET_SERVER_mst_receive (plugin->data_tokenizer, session,
2726 (const char *) temp_hdr,
2727 ntohs (hdr->size) - sizeof (struct WlanHeader),
2728 GNUNET_YES, GNUNET_NO);
2734 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2735 "wlan_data_message_handler got wrong message type: %u\n",
2742 * function to process the a message, give it to the higher layer
2743 * @param cls pointer to the plugin
2744 * @param client pointer to the session this message belongs to
2745 * @param hdr start of the message
2747 //TODO ATS informations
2749 process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2752 GNUNET_assert (client != NULL);
2753 GNUNET_assert (cls != NULL);
2754 struct Session *session = (struct Session *) client;
2755 struct Plugin *plugin = (struct Plugin *) cls;
2756 struct GNUNET_ATS_Information ats[2];
2758 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
2759 ats[0].value = htonl (1);
2760 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2761 ats[1].value = htonl (GNUNET_ATS_NET_WLAN);
2764 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2765 "Calling plugin->env->receive for session %p; %s; size: %u\n",
2766 session, wlan_plugin_address_to_string (NULL,
2772 plugin->env->receive (plugin->env->cls, &(session->target), hdr,
2773 (const struct GNUNET_ATS_Information *) &ats, 2,
2774 session, (const char *) &session->mac->addr,
2775 sizeof (session->mac->addr));
2779 * Function used for to process the data received from the wlan interface
2781 * @param cls the plugin handle
2782 * @param session_light pointer to the struct holding known informations
2783 * @param hdr hdr of the GNUNET_MessageHeader
2784 * @param rxinfo pointer to the radiotap informations got with this packet FIXME: give ATS for info
2787 wlan_data_helper (void *cls, struct Session_light *session_light,
2788 const struct GNUNET_MessageHeader *hdr,
2789 const struct Radiotap_rx *rxinfo)
2791 struct Plugin *plugin = cls;
2792 struct FragmentMessage *fm;
2793 struct FragmentMessage *fm2;
2794 struct GNUNET_PeerIdentity tmpsource;
2796 GNUNET_assert (plugin != NULL);
2799 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2802 //TODO better DOS protection, error handling
2803 //TODO test first than create session
2804 GNUNET_assert (session_light != NULL);
2807 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2808 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_HELLO size: %u; %s\n",
2809 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2810 session_light->addr.
2814 if (session_light->macendpoint == NULL)
2816 session_light->macendpoint =
2817 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2821 if (GNUNET_HELLO_get_id
2822 ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource) == GNUNET_OK)
2824 session_light->session =
2825 search_session (plugin, session_light->macendpoint, &tmpsource);
2826 if (session_light->session == NULL)
2828 session_light->session =
2829 create_session (plugin, session_light->macendpoint, &tmpsource);
2831 GNUNET_STATISTICS_update (plugin->env->stats,
2832 _("# wlan hello messages received"), 1,
2834 plugin->env->receive (plugin->env->cls, &session_light->session->target,
2835 hdr, NULL, 0, session_light->session,
2836 (const char *) &session_light->session->mac->addr,
2837 sizeof (session_light->session->mac->addr));
2841 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2842 "WLAN client not in session list and hello message is not okay\n");
2849 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT)
2852 GNUNET_assert (session_light != NULL);
2853 if (session_light->macendpoint == NULL)
2855 session_light->macendpoint =
2856 get_macendpoint (plugin, &session_light->addr, GNUNET_YES);
2860 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2861 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size: %u; mac endpoint %p: %s\n",
2862 ntohs (hdr->size), session_light->macendpoint,
2863 wlan_plugin_address_to_string (NULL,
2864 session_light->addr.mac,
2868 GNUNET_STATISTICS_update (plugin->env->stats,
2869 _("# wlan fragments received"), 1, GNUNET_NO);
2871 GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag,
2874 if (ret == GNUNET_NO)
2876 session_light->macendpoint->dups++;
2878 else if (ret == GNUNET_OK)
2880 session_light->macendpoint->fragc++;
2882 set_next_send (plugin);
2888 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK)
2890 GNUNET_assert (session_light != NULL);
2891 if (session_light->macendpoint == NULL)
2893 session_light->macendpoint =
2894 get_macendpoint (plugin, &session_light->addr, GNUNET_NO);
2897 if (session_light->macendpoint == NULL)
2900 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2901 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n",
2902 ntohs (hdr->size), wlan_plugin_address_to_string (NULL,
2903 session_light->addr.mac,
2910 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2911 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n",
2912 ntohs (hdr->size), session_light->macendpoint,
2913 wlan_plugin_address_to_string (NULL,
2914 session_light->addr.mac,
2917 fm = session_light->macendpoint->sending_messages_head;
2921 GNUNET_STATISTICS_update (plugin->env->stats, _("# wlan acks received"),
2923 int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
2925 if (ret == GNUNET_OK)
2927 #if DEBUG_wlan_retransmission > 1
2928 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2929 "Got last ack, finished fragment message %p\n", fm);
2931 session_light->macendpoint->acks++;
2932 fm->session->last_activity = GNUNET_TIME_absolute_get ();
2933 session_light->macendpoint->last_activity = fm->session->last_activity;
2934 free_fragment_message (plugin, fm);
2935 check_fragment_queue (plugin);
2938 if (ret == GNUNET_NO)
2940 #if DEBUG_wlan_retransmission > 1
2941 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2942 "Got ack for: %p\n", fm);
2944 session_light->macendpoint->acks++;
2947 if (ret == GNUNET_SYSERR)
2955 #if DEBUG_wlan_retransmission > 1
2956 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2957 "WLAN fragment not in fragment list\n");
2965 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2966 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n",
2967 ntohs (hdr->type), ntohs (hdr->size));
2973 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2974 "Helper finished\n");
2981 * Function to print mac addresses nice *
2982 * @param pointer to 6 byte with the mac address
2983 * @return pointer to the chars which hold the print out
2986 macprinter (const u_int8_t * mac)
2988 static char macstr[20];
2990 GNUNET_snprintf (macstr, sizeof (macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1],
2991 mac[2], mac[3], mac[4], mac[5]);
2997 * Function for the scheduler if a mac endpoint times out
2998 * @param cls pointer to the MacEndpoint
2999 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
3002 macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3004 struct MacEndpoint *endpoint = cls;
3006 GNUNET_assert (endpoint != NULL);
3007 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
3008 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
3012 if (GNUNET_TIME_absolute_get_remaining
3013 (GNUNET_TIME_absolute_add
3014 (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0)
3016 GNUNET_assert (endpoint->plugin != NULL);
3017 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
3018 _("# wlan mac endpoints timeouts"), 1, GNUNET_NO);
3019 free_macendpoint (endpoint->plugin, endpoint);
3023 endpoint->timeout_task =
3024 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
3030 * function to create an macendpoint
3031 * @param plugin pointer to the plugin struct
3032 * @param addr pointer to the macaddress
3033 * @return returns a macendpoint
3035 static struct MacEndpoint *
3036 create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
3038 struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
3040 GNUNET_assert (plugin != NULL);
3041 GNUNET_STATISTICS_update (plugin->env->stats,
3042 _("# wlan mac endpoints created"), 1, GNUNET_NO);
3043 newend->addr = *addr;
3044 newend->plugin = plugin;
3045 newend->addr = *addr;
3046 newend->fragment_messages_out_count = 0;
3048 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
3049 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
3050 newend, &wlan_data_message_handler,
3052 newend->last_activity = GNUNET_TIME_absolute_get ();
3053 newend->timeout_task =
3054 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
3057 plugin->mac_count++;
3058 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
3059 plugin->mac_count, GNUNET_NO);
3060 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
3062 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3063 "New Mac Endpoint %p: %s\n", newend,
3064 wlan_plugin_address_to_string (NULL, newend->addr.mac, 6));
3070 * Function used for to process the data from the suid process
3072 * @param cls the plugin handle
3073 * @param client client that send the data (not used)
3074 * @param hdr header of the GNUNET_MessageHeader
3077 wlan_process_helper (void *cls, void *client,
3078 const struct GNUNET_MessageHeader *hdr)
3080 struct Plugin *plugin = cls;
3081 struct ieee80211_frame *wlanIeeeHeader = NULL;
3082 struct Session_light *session_light = NULL;
3083 struct Radiotap_rx *rxinfo;
3084 const struct GNUNET_MessageHeader *temp_hdr = NULL;
3089 GNUNET_assert (plugin != NULL);
3090 switch (ntohs (hdr->type))
3092 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
3094 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3095 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
3099 GNUNET_STATISTICS_update (plugin->env->stats,
3100 _("# wlan WLAN_HELPER_DATA received"), 1,
3102 //call wlan_process_helper with the message inside, later with wlan: analyze signal
3103 if (ntohs (hdr->size) <
3104 sizeof (struct ieee80211_frame) +
3105 2 * sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx))
3108 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3109 "Size of packet is too small; size: %u min size: %u\n",
3111 sizeof (struct ieee80211_frame) +
3112 sizeof (struct GNUNET_MessageHeader));
3115 /* FIXME: restart SUID process */
3119 rxinfo = (struct Radiotap_rx *) &hdr[1];
3120 wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1];
3122 //process only if it is an broadcast or for this computer both with the gnunet bssid
3126 (&(wlanIeeeHeader->i_addr3), &mac_bssid_gnunet,
3127 sizeof (struct MacAddress)) == 0)
3129 //check for broadcast or mac
3131 (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
3132 sizeof (struct MacAddress)) == 0) ||
3134 (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
3135 sizeof (struct MacAddress)) == 0))
3137 //if packet is from us return
3139 (&(wlanIeeeHeader->i_addr2), &(plugin->mac_address),
3140 sizeof (struct MacAddress)) == 0))
3144 // process the inner data
3148 ntohs (hdr->size) - sizeof (struct ieee80211_frame) -
3149 sizeof (struct GNUNET_MessageHeader) - sizeof (struct Radiotap_rx);
3151 session_light = GNUNET_malloc (sizeof (struct Session_light));
3152 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
3153 sizeof (struct MacAddress));
3154 //session_light->session = search_session(plugin,session_light->addr);
3155 GNUNET_STATISTICS_update (plugin->env->stats,
3156 _("# wlan messages for this client received"),
3160 while (pos < datasize)
3162 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
3163 if (ntohs (temp_hdr->size) <= datasize + pos)
3165 GNUNET_STATISTICS_update (plugin->env->stats,
3167 ("# wlan messages inside WLAN_HELPER_DATA received"),
3169 wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
3174 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3175 "Size of packet is too small; size: %u > size of packet: %u\n",
3176 ntohs (temp_hdr->size), datasize + pos);
3179 pos += ntohs (temp_hdr->size);
3184 GNUNET_free (session_light);
3189 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3190 "Func wlan_process_helper got wrong MAC: %s\n",
3191 macprinter (wlanIeeeHeader->i_addr1));
3198 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3199 "Func wlan_process_helper got wrong BSSID: %s\n",
3200 macprinter (wlanIeeeHeader->i_addr2));
3204 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
3205 //TODO more control messages
3206 if (ntohs (hdr->size) != sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
3209 /* FIXME: restart SUID process */
3212 memcpy (&plugin->mac_address, &hdr[1], sizeof (struct MacAddress));
3214 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3215 "Received WLAN_HELPER_CONTROL message with transport of address %s\n",
3216 wlan_plugin_address_to_string (cls, &plugin->mac_address,
3220 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
3221 &plugin->mac_address,
3222 sizeof (struct MacAddress));
3226 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3227 "Func wlan_process_helper got unknown message with number %u, size %u\n",
3228 ntohs (hdr->type), ntohs (hdr->size));
3231 #if DEBUG_wlan_msg_dump > 1
3232 hexdump (hdr, GNUNET_MIN (ntohs (hdr->size), 256));
3240 * Exit point from the plugin.
3241 * @param cls pointer to the api struct
3246 libgnunet_plugin_transport_wlan_done (void *cls)
3248 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3249 struct Plugin *plugin = api->cls;
3250 struct MacEndpoint *endpoint = plugin->mac_head;
3251 struct MacEndpoint *endpoint_next;
3254 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3255 "libgnunet_plugin_transport_wlan_done started\n");
3258 wlan_transport_stop_wlan_helper (plugin);
3260 GNUNET_assert (cls != NULL);
3262 while (endpoint != NULL)
3264 endpoint_next = endpoint->next;
3265 free_macendpoint (plugin, endpoint);
3266 endpoint = endpoint_next;
3271 if (plugin->suid_tokenizer != NULL)
3272 GNUNET_SERVER_mst_destroy (plugin->suid_tokenizer);
3274 if (plugin->data_tokenizer != NULL)
3275 GNUNET_SERVER_mst_destroy (plugin->data_tokenizer);
3277 GNUNET_free_non_null (plugin->interface);
3278 GNUNET_free (plugin);
3284 * Entry point for the plugin.
3286 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
3287 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
3290 libgnunet_plugin_transport_wlan_init (void *cls)
3292 //struct GNUNET_SERVICE_Context *service;
3293 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3294 struct GNUNET_TRANSPORT_PluginFunctions *api;
3295 struct Plugin *plugin;
3297 GNUNET_assert (cls != NULL);
3299 plugin = GNUNET_malloc (sizeof (struct Plugin));
3301 plugin->pendingsessions = 0;
3302 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan pending sessions"),
3303 plugin->pendingsessions, GNUNET_NO);
3304 plugin->mac_count = 0;
3305 GNUNET_STATISTICS_set (plugin->env->stats, _("# wlan mac endpoints"),
3306 plugin->mac_count, GNUNET_NO);
3307 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
3308 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
3309 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
3310 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
3311 GNUNET_BANDWIDTH_value_init (100 * 1024 *
3314 plugin->suid_tokenizer =
3315 GNUNET_SERVER_mst_create (&wlan_process_helper, plugin);
3317 plugin->data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
3319 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
3320 //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue));
3322 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
3324 api->send = &wlan_plugin_send_old;
3325 api->send_with_session = &wlan_plugin_send;
3326 api->get_session = &wlan_plugin_get_session;
3327 api->disconnect = &wlan_plugin_disconnect;
3328 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
3329 api->check_address = &wlan_plugin_address_suggested;
3330 api->address_to_string = &wlan_plugin_address_to_string;
3334 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE"))
3336 if (GNUNET_SYSERR ==
3337 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
3338 "TESTMODE", &(plugin->testmode)))
3339 plugin->testmode = 0; //default value
3342 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE"))
3344 if (GNUNET_CONFIGURATION_get_value_string
3345 (env->cfg, "transport-wlan", "INTERFACE",
3346 &(plugin->interface)) != GNUNET_YES)
3348 libgnunet_plugin_transport_wlan_done (api);
3354 wlan_transport_start_wlan_helper (plugin);
3355 set_next_beacon_time (plugin);
3356 set_next_send (plugin);
3358 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
3359 "wlan init finished\n");
3365 /* end of plugin_transport_wlan.c */