2 This file is part of GNUnet
3 (C) 2010, 2011, 2012 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
25 * @author Christian Grothoff
28 #include "gnunet_hello_lib.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_statistics_service.h"
32 #include "gnunet_transport_service.h"
33 #include "gnunet_transport_plugin.h"
34 #include "plugin_transport_wlan.h"
35 #include "gnunet_common.h"
36 #include "gnunet_crypto_lib.h"
37 #include "gnunet_fragmentation_lib.h"
38 #include "gnunet_constants.h"
40 #define LOG(kind,...) GNUNET_log_from (kind, "transport-wlan",__VA_ARGS__)
43 * Max size of packet (that we give to the WLAN driver for transmission)
48 * time out of a mac endpoint
50 #define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2)
53 * We reduce the frequence of HELLO beacons in relation to
54 * the number of MAC addresses currently visible to us.
55 * This is the multiplication factor.
57 #define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
60 * Maximum number of messages in defragmentation queue per MAC
62 #define MESSAGES_IN_DEFRAG_QUEUE_PER_MAC 2
65 * Link layer control fields for better compatibility
66 * (i.e. GNUnet over WLAN is not IP-over-WLAN).
68 #define WLAN_LLC_DSAP_FIELD 0x1f
69 #define WLAN_LLC_SSAP_FIELD 0x1f
72 GNUNET_NETWORK_STRUCT_BEGIN
74 * Header for messages which need fragmentation. This is the format of
75 * a message we obtain AFTER defragmentation. We then need to check
76 * the CRC and then tokenize the payload and pass it to the
83 * Message type is GNUNET_MESSAGE_TYPE_WLAN_DATA.
85 struct GNUNET_MessageHeader header;
88 * CRC32 checksum (only over the payload), in NBO.
90 uint32_t crc GNUNET_PACKED;
93 * Sender of the message.
95 struct GNUNET_PeerIdentity sender;
98 * Target of the message.
100 struct GNUNET_PeerIdentity target;
102 /* followed by payload, possibly including
103 multiple messages! */
106 GNUNET_NETWORK_STRUCT_END
110 * Information kept for each message that is yet to be fragmented and
113 struct PendingMessage
116 * next entry in the DLL
118 struct PendingMessage *next;
121 * previous entry in the DLL
123 struct PendingMessage *prev;
126 * The pending message
128 struct WlanHeader *msg;
131 * Continuation function to call once the message
132 * has been sent. Can be NULL if there is no
133 * continuation to call.
135 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
138 * Cls for transmit_cont
140 void *transmit_cont_cls;
143 * Timeout task (for this message).
145 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
151 * Session handle for connections with other peers.
156 * To whom are we talking to (set to our identity
157 * if we are still waiting for the welcome message)
159 struct GNUNET_PeerIdentity target;
162 * API requirement (must be first).
164 struct SessionHeader header;
167 * We keep all sessions in a DLL at their respective
168 * 'struct MACEndpoint'.
170 struct Session *next;
173 * We keep all sessions in a DLL at their respective
174 * 'struct MACEndpoint'.
176 struct Session *prev;
179 * MAC endpoint with the address of this peer.
181 struct MacEndpoint *mac;
184 * Head of messages currently pending for transmission to this peer.
186 struct PendingMessage *pending_message_head;
189 * Tail of messages currently pending for transmission to this peer.
191 struct PendingMessage *pending_message_tail;
194 * When should this session time out?
196 struct GNUNET_TIME_Absolute timeout;
199 * Timeout task (for the session).
201 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
207 * Struct for messages that are being fragmented in a MAC's transmission queue.
209 struct FragmentMessage
213 * This is a doubly-linked list.
215 struct FragmentMessage *next;
218 * This is a doubly-linked list.
220 struct FragmentMessage *prev;
223 * MAC endpoint this message belongs to
225 struct MacEndpoint *macendpoint;
228 * Fragmentation context
230 struct GNUNET_FRAGMENT_Context *fragcontext;
233 * Transmission handle to helper (to cancel if the frag context
234 * is destroyed early for some reason).
236 struct GNUNET_HELPER_SendHandle *sh;
239 * Intended recipient.
241 struct GNUNET_PeerIdentity target;
244 * Timeout value for the message.
246 struct GNUNET_TIME_Absolute timeout;
251 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
254 * Continuation to call when we're done with this message.
256 GNUNET_TRANSPORT_TransmitContinuation cont;
267 * Struct to represent one network card connection
273 * We keep all MACs in a DLL in the plugin.
275 struct MacEndpoint *next;
278 * We keep all MACs in a DLL in the plugin.
280 struct MacEndpoint *prev;
283 * Pointer to the global plugin struct.
285 struct Plugin *plugin;
288 * Head of sessions that use this MAC.
290 struct Session *sessions_head;
293 * Tail of sessions that use this MAC.
295 struct Session *sessions_tail;
298 * Head of messages we are currently sending to this MAC.
300 struct FragmentMessage *sending_messages_head;
303 * Tail of messages we are currently sending to this MAC.
305 struct FragmentMessage *sending_messages_tail;
308 * Defrag context for this MAC
310 struct GNUNET_DEFRAGMENT_Context *defrag;
313 * When should this endpoint time out?
315 struct GNUNET_TIME_Absolute timeout;
320 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
323 * count of messages in the fragment out queue for this mac endpoint
325 unsigned int fragment_messages_out_count;
330 struct GNUNET_TRANSPORT_WLAN_MacAddress addr;
333 * Desired transmission power for this MAC
338 * Desired transmission rate for this MAC
343 * Antenna we should use for this MAC
351 * Encapsulation of all of the state of the plugin.
358 struct GNUNET_TRANSPORT_PluginEnvironment *env;
361 * Handle to helper process for priviledged operations.
363 struct GNUNET_HELPER_Handle *suid_helper;
366 * ARGV-vector for the helper (all helpers take only the binary
367 * name, one actual argument, plus the NULL terminator for 'argv').
369 char * helper_argv[3];
372 * The interface of the wlan card given to us by the user.
377 * Tokenizer for demultiplexing of data packets resulting from defragmentation.
379 struct GNUNET_SERVER_MessageStreamTokenizer *fragment_data_tokenizer;
382 * Tokenizer for demultiplexing of data packets received from the suid helper
384 struct GNUNET_SERVER_MessageStreamTokenizer *helper_payload_tokenizer;
387 * Tokenizer for demultiplexing of data packets that follow the WLAN Header
389 struct GNUNET_SERVER_MessageStreamTokenizer *wlan_header_payload_tokenizer;
392 * Head of list of open connections.
394 struct MacEndpoint *mac_head;
397 * Tail of list of open connections.
399 struct MacEndpoint *mac_tail;
402 * Number of connections
404 unsigned int mac_count;
407 * Task that periodically sends a HELLO beacon via the helper.
409 GNUNET_SCHEDULER_TaskIdentifier beacon_task;
412 * Tracker for bandwidth limit
414 struct GNUNET_BANDWIDTH_Tracker tracker;
417 * The mac_address of the wlan card given to us by the helper.
419 struct GNUNET_TRANSPORT_WLAN_MacAddress mac_address;
422 * Have we received a control message with our MAC address yet?
431 * Information associated with a message. Can contain
432 * the session or the MAC endpoint associated with the
438 * NULL if the identity of the other peer is not known.
440 struct Session *session;
443 * MAC address of the other peer, NULL if not known.
445 struct MacEndpoint *endpoint;
450 * Print MAC addresses nicely.
452 * @param mac the mac address
453 * @return string to a static buffer with the human-readable mac, will be overwritten during the next call to this function
456 mac_to_string (const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac)
458 static char macstr[20];
460 GNUNET_snprintf (macstr, sizeof (macstr), "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac->mac[0], mac->mac[1],
461 mac->mac[2], mac->mac[3], mac->mac[4], mac->mac[5]);
467 * Fill the radiotap header
469 * @param endpoint pointer to the endpoint, can be NULL
470 * @param header pointer to the radiotap header
471 * @param size total message size
474 get_radiotap_header (struct MacEndpoint *endpoint,
475 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
478 header->header.type = ntohs (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER);
479 header->header.size = ntohs (size);
480 if (NULL != endpoint)
482 header->rate = endpoint->rate;
483 header->tx_power = endpoint->tx_power;
484 header->antenna = endpoint->antenna;
489 header->tx_power = 0;
496 * Generate the WLAN hardware header for one packet
498 * @param plugin the plugin handle
499 * @param header address to write the header to
500 * @param to_mac_addr address of the recipient
501 * @param size size of the whole packet, needed to calculate the time to send the packet
504 get_wlan_header (struct Plugin *plugin,
505 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *header,
506 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
509 const int rate = 11000000;
511 header->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
512 header->addr1 = *to_mac_addr;
513 header->addr2 = plugin->mac_address;
514 header->addr3 = mac_bssid_gnunet;
515 header->duration = GNUNET_htole16 ((size * 1000000) / rate + 290);
516 header->sequence_control = 0; // FIXME?
517 header->llc[0] = WLAN_LLC_DSAP_FIELD;
518 header->llc[1] = WLAN_LLC_SSAP_FIELD;
519 header->llc[2] = 0; // FIXME?
520 header->llc[3] = 0; // FIXME?
525 * Send an ACK for a fragment we received.
527 * @param cls the 'struct MacEndpoint' the ACK must be sent to
528 * @param msg_id id of the message
529 * @param hdr pointer to the hdr where the ack is stored
532 send_ack (void *cls, uint32_t msg_id,
533 const struct GNUNET_MessageHeader *hdr)
535 struct MacEndpoint *endpoint = cls;
536 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage* radio_header;
537 uint16_t msize = ntohs (hdr->size);
538 size_t size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
541 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
546 LOG (GNUNET_ERROR_TYPE_DEBUG,
547 "Sending ACK to helper\n");
548 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
549 get_radiotap_header (endpoint, radio_header, size);
550 get_wlan_header (endpoint->plugin,
551 &radio_header->frame,
554 memcpy (&radio_header[1], hdr, msize);
556 GNUNET_HELPER_send (endpoint->plugin->suid_helper,
557 &radio_header->header,
558 GNUNET_NO /* dropping ACKs is bad */,
560 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN ACKs sent"),
566 * Handles the data after all fragments are put together
568 * @param cls macendpoint this messages belongs to
569 * @param hdr pointer to the data
572 wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
574 struct MacEndpoint *endpoint = cls;
575 struct Plugin *plugin = endpoint->plugin;
576 struct MacAndSession mas;
578 GNUNET_STATISTICS_update (plugin->env->stats,
579 _("# WLAN messages defragmented"), 1,
582 mas.endpoint = endpoint;
583 (void) GNUNET_SERVER_mst_receive (plugin->fragment_data_tokenizer,
587 GNUNET_YES, GNUNET_NO);
594 * @param session the session free
597 free_session (struct Session *session)
599 struct MacEndpoint *endpoint = session->mac;
600 struct PendingMessage *pm;
602 endpoint->plugin->env->session_end (endpoint->plugin->env->cls,
605 while (NULL != (pm = session->pending_message_head))
607 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
608 session->pending_message_tail, pm);
609 if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task)
611 GNUNET_SCHEDULER_cancel (pm->timeout_task);
612 pm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
614 GNUNET_free (pm->msg);
617 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head,
618 endpoint->sessions_tail,
620 if (session->timeout_task != GNUNET_SCHEDULER_NO_TASK)
622 GNUNET_SCHEDULER_cancel (session->timeout_task);
623 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
625 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), -1,
627 GNUNET_free (session);
632 * A session is timing out. Clean up.
634 * @param cls pointer to the Session
635 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
638 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
640 struct Session * session = cls;
641 struct GNUNET_TIME_Relative timeout;
643 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
644 timeout = GNUNET_TIME_absolute_get_remaining (session->timeout);
645 if (0 == timeout.rel_value)
647 free_session (session);
650 session->timeout_task =
651 GNUNET_SCHEDULER_add_delayed (timeout, &session_timeout, session);
656 * Create a new session
658 * @param endpoint pointer to the mac endpoint of the peer
659 * @param peer peer identity to use for this session
660 * @return returns the session
662 static struct Session *
663 create_session (struct MacEndpoint *endpoint,
664 const struct GNUNET_PeerIdentity *peer)
666 struct Session *session;
668 for (session = endpoint->sessions_head; NULL != session; session = session->next)
669 if (0 == memcmp (peer, &session->target,
670 sizeof (struct GNUNET_PeerIdentity)))
672 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
675 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), 1,
677 session = GNUNET_malloc (sizeof (struct Session));
678 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
679 endpoint->sessions_tail,
681 session->mac = endpoint;
682 session->target = *peer;
683 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
684 session->timeout_task =
685 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session);
686 LOG (GNUNET_ERROR_TYPE_DEBUG,
687 "Created new session for peer `%s' with endpoint %s\n",
689 mac_to_string (&endpoint->addr));
695 * Function called once we have successfully given the fragment
696 * message to the SUID helper process and we are thus ready for
699 * @param cls the 'struct FragmentMessage'
700 * @param result result of the operation (GNUNET_OK on success, GNUNET_NO if the helper died, GNUNET_SYSERR
701 * if the helper was stopped)
704 fragment_transmission_done (void *cls,
707 struct FragmentMessage *fm = cls;
710 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
715 * Transmit a fragment of a message.
717 * @param cls 'struct FragmentMessage' this fragment message belongs to
718 * @param hdr pointer to the start of the fragment message
721 transmit_fragment (void *cls,
722 const struct GNUNET_MessageHeader *hdr)
724 struct FragmentMessage *fm = cls;
725 struct MacEndpoint *endpoint = fm->macendpoint;
729 msize = ntohs (hdr->size);
730 size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
733 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radio_header;
735 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
736 get_radiotap_header (endpoint, radio_header, size);
737 get_wlan_header (endpoint->plugin,
738 &radio_header->frame,
741 memcpy (&radio_header[1], hdr, msize);
742 GNUNET_assert (NULL == fm->sh);
743 fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper,
744 &radio_header->header,
746 &fragment_transmission_done, fm);
748 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN message fragments sent"),
751 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
757 * Frees the space of a message in the fragment queue (send queue)
759 * @param fm message to free
762 free_fragment_message (struct FragmentMessage *fm)
764 struct MacEndpoint *endpoint = fm->macendpoint;
766 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN messages pending (with fragmentation)"),
768 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
769 endpoint->sending_messages_tail, fm);
772 GNUNET_HELPER_send_cancel (fm->sh);
775 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
776 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
778 GNUNET_SCHEDULER_cancel (fm->timeout_task);
779 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
786 * A FragmentMessage has timed out. Remove it.
788 * @param cls pointer to the 'struct FragmentMessage'
789 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
792 fragmentmessage_timeout (void *cls,
793 const struct GNUNET_SCHEDULER_TaskContext *tc)
795 struct FragmentMessage *fm = cls;
797 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
798 if (NULL != fm->cont)
800 fm->cont (fm->cont_cls, &fm->target, GNUNET_SYSERR);
803 free_fragment_message (fm);
808 * Transmit a message to the given destination with fragmentation.
810 * @param endpoint desired destination
811 * @param timeout how long can the message wait?
812 * @param target peer that should receive the message
813 * @param msg message to transmit
814 * @param cont continuation to call once the message has
815 * been transmitted (or if the transport is ready
816 * for the next transmission call; or if the
817 * peer disconnected...); can be NULL
818 * @param cont_cls closure for cont
821 send_with_fragmentation (struct MacEndpoint *endpoint,
822 struct GNUNET_TIME_Relative timeout,
823 const struct GNUNET_PeerIdentity *target,
824 const struct GNUNET_MessageHeader *msg,
825 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
828 struct FragmentMessage *fm;
829 struct Plugin *plugin;
831 plugin = endpoint->plugin;
832 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
833 fm->macendpoint = endpoint;
834 fm->target = *target;
835 fm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
837 fm->cont_cls = cont_cls;
839 GNUNET_FRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
841 GNUNET_TIME_UNIT_SECONDS,
843 &transmit_fragment, fm);
845 GNUNET_SCHEDULER_add_delayed (timeout,
846 &fragmentmessage_timeout, fm);
847 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sending_messages_head,
848 endpoint->sending_messages_tail,
854 * Free a MAC endpoint.
856 * @param endpoint pointer to the MacEndpoint to free
859 free_macendpoint (struct MacEndpoint *endpoint)
861 struct Plugin *plugin = endpoint->plugin;
862 struct FragmentMessage *fm;
863 struct Session *session;
865 GNUNET_STATISTICS_update (plugin->env->stats,
866 _("# WLAN MAC endpoints allocated"), -1, GNUNET_NO);
867 while (NULL != (session = endpoint->sessions_head))
868 free_session (session);
869 while (NULL != (fm = endpoint->sending_messages_head))
870 free_fragment_message (fm);
871 GNUNET_CONTAINER_DLL_remove (plugin->mac_head,
875 if (NULL != endpoint->defrag)
877 GNUNET_DEFRAGMENT_context_destroy(endpoint->defrag);
878 endpoint->defrag = NULL;
882 if (GNUNET_SCHEDULER_NO_TASK != endpoint->timeout_task)
884 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
885 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
887 GNUNET_free (endpoint);
892 * A MAC endpoint is timing out. Clean up.
894 * @param cls pointer to the MacEndpoint
895 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
898 macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
900 struct MacEndpoint *endpoint = cls;
901 struct GNUNET_TIME_Relative timeout;
903 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
904 timeout = GNUNET_TIME_absolute_get_remaining (endpoint->timeout);
905 if (0 == timeout.rel_value)
907 free_macendpoint (endpoint);
910 endpoint->timeout_task =
911 GNUNET_SCHEDULER_add_delayed (timeout, &macendpoint_timeout,
917 * Find (or create) a MacEndpoint with a specific MAC address
919 * @param plugin pointer to the plugin struct
920 * @param addr the MAC address of the endpoint
921 * @return handle to our data structure for this MAC
923 static struct MacEndpoint *
924 create_macendpoint (struct Plugin *plugin,
925 const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr)
927 struct MacEndpoint *pos;
929 for (pos = plugin->mac_head; NULL != pos; pos = pos->next)
930 if (0 == memcmp (addr, &pos->addr, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
932 pos = GNUNET_malloc (sizeof (struct MacEndpoint));
934 pos->plugin = plugin;
936 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
937 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
939 &wlan_data_message_handler,
941 pos->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
943 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
945 GNUNET_CONTAINER_DLL_insert (plugin->mac_head, plugin->mac_tail, pos);
947 GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"),
949 LOG (GNUNET_ERROR_TYPE_DEBUG,
950 "New MAC endpoint `%s'\n",
951 mac_to_string (addr));
957 * Creates a new outbound session the transport service will use to send data to the
960 * @param cls the plugin
961 * @param address the address
962 * @return the session or NULL of max connections exceeded
964 static struct Session *
965 wlan_plugin_get_session (void *cls,
966 const struct GNUNET_HELLO_Address *address)
968 struct Plugin *plugin = cls;
969 struct MacEndpoint *endpoint;
973 if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != address->address_length)
978 LOG (GNUNET_ERROR_TYPE_DEBUG,
979 "Service asked to create session for peer `%s' with MAC `%s'\n",
980 GNUNET_i2s (&address->peer),
981 mac_to_string (address->address));
982 endpoint = create_macendpoint (plugin, address->address);
983 return create_session (endpoint, &address->peer);
988 * Function that can be used to force the plugin to disconnect
989 * from the given peer and cancel all previous transmissions
990 * (and their continuation).
993 * @param target peer from which to disconnect
996 wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
998 struct Plugin *plugin = cls;
999 struct Session *session;
1000 struct MacEndpoint *endpoint;
1002 for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
1003 for (session = endpoint->sessions_head; NULL != session; session = session->next)
1004 if (0 == memcmp (target, &session->target,
1005 sizeof (struct GNUNET_PeerIdentity)))
1007 free_session (session);
1008 break; /* inner-loop only (in case peer has another MAC as well!) */
1014 * Function that can be used by the transport service to transmit
1015 * a message using the plugin. Note that in the case of a
1016 * peer disconnecting, the continuation MUST be called
1017 * prior to the disconnect notification itself. This function
1018 * will be called with this peer's HELLO message to initiate
1019 * a fresh connection to another peer.
1021 * @param cls closure
1022 * @param session which session must be used
1023 * @param msgbuf the message to transmit
1024 * @param msgbuf_size number of bytes in 'msgbuf'
1025 * @param priority how important is the message (most plugins will
1026 * ignore message priority and just FIFO)
1027 * @param to how long to wait at most for the transmission (does not
1028 * require plugins to discard the message after the timeout,
1029 * just advisory for the desired delay; most plugins will ignore
1031 * @param cont continuation to call once the message has
1032 * been transmitted (or if the transport is ready
1033 * for the next transmission call; or if the
1034 * peer disconnected...); can be NULL
1035 * @param cont_cls closure for cont
1036 * @return number of bytes used (on the physical network, with overheads);
1037 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1038 * and does NOT mean that the message was not transmitted (DV)
1041 wlan_plugin_send (void *cls,
1042 struct Session *session,
1043 const char *msgbuf, size_t msgbuf_size,
1044 unsigned int priority,
1045 struct GNUNET_TIME_Relative to,
1046 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1048 struct Plugin *plugin = cls;
1049 struct WlanHeader *wlanheader;
1050 size_t size = msgbuf_size + sizeof (struct WlanHeader);
1051 char buf[size] GNUNET_ALIGN;
1053 LOG (GNUNET_ERROR_TYPE_DEBUG,
1054 "Transmitting %u bytes of payload to peer `%s' (starting with %u byte message of type %u)\n",
1056 GNUNET_i2s (&session->target),
1057 (unsigned int) ntohs (((struct GNUNET_MessageHeader*)msgbuf)->size),
1058 (unsigned int) ntohs (((struct GNUNET_MessageHeader*)msgbuf)->type));
1059 wlanheader = (struct WlanHeader *) buf;
1060 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
1061 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
1062 wlanheader->sender = *plugin->env->my_identity;
1063 wlanheader->target = session->target;
1064 wlanheader->crc = htonl (GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size));
1065 memcpy (&wlanheader[1], msgbuf, msgbuf_size);
1066 send_with_fragmentation (session->mac,
1069 &wlanheader->header,
1076 * We have received data from the WLAN via some session. Process depending
1077 * on the message type (HELLO, DATA, FRAGMENTATION or FRAGMENTATION-ACK).
1079 * @param cls pointer to the plugin
1080 * @param client pointer to the session this message belongs to
1081 * @param hdr start of the message
1084 process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1086 struct Plugin *plugin = cls;
1087 struct MacAndSession *mas = client;
1088 struct MacAndSession xmas;
1090 struct GNUNET_ATS_Information ats[NUM_ATS]; /* FIXME: do better here */
1091 struct FragmentMessage *fm;
1092 struct GNUNET_PeerIdentity tmpsource;
1093 const struct WlanHeader *wlanheader;
1097 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
1098 ats[0].value = htonl (1);
1099 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1100 ats[1].value = htonl (GNUNET_ATS_NET_WLAN);
1101 msize = ntohs (hdr->size);
1102 switch (ntohs (hdr->type))
1104 case GNUNET_MESSAGE_TYPE_HELLO:
1106 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource))
1108 GNUNET_break_op (0);
1111 LOG (GNUNET_ERROR_TYPE_DEBUG,
1112 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n",
1113 (unsigned int) msize,
1114 GNUNET_i2s (&tmpsource),
1115 mac_to_string (&mas->endpoint->addr));
1117 GNUNET_STATISTICS_update (plugin->env->stats,
1118 _("# HELLO messages received via WLAN"), 1,
1120 plugin->env->receive (plugin->env->cls,
1125 (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr,
1126 (mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1128 case GNUNET_MESSAGE_TYPE_FRAGMENT:
1129 if (NULL == mas->endpoint)
1134 LOG (GNUNET_ERROR_TYPE_DEBUG,
1135 "Processing %u bytes of FRAGMENT from MAC %s\n",
1136 (unsigned int) msize,
1137 mac_to_string (&mas->endpoint->addr));
1138 GNUNET_STATISTICS_update (plugin->env->stats,
1139 _("# fragments received via WLAN"), 1, GNUNET_NO);
1140 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag,
1143 case GNUNET_MESSAGE_TYPE_FRAGMENT_ACK:
1144 if (NULL == mas->endpoint)
1149 GNUNET_STATISTICS_update (plugin->env->stats, _("# ACKs received via WLAN"),
1151 for (fm = mas->endpoint->sending_messages_head; NULL != fm; fm = fm->next)
1153 ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
1154 if (GNUNET_OK == ret)
1156 LOG (GNUNET_ERROR_TYPE_DEBUG,
1157 "Got last ACK, finished message transmission to `%s' (%p)\n",
1158 mac_to_string (&mas->endpoint->addr),
1160 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
1161 if (NULL != fm->cont)
1163 fm->cont (fm->cont_cls, &fm->target, GNUNET_OK);
1166 free_fragment_message (fm);
1169 if (GNUNET_NO == ret)
1171 LOG (GNUNET_ERROR_TYPE_DEBUG,
1172 "Got an ACK, message transmission to `%s' not yet finished\n",
1173 mac_to_string (&mas->endpoint->addr));
1177 LOG (GNUNET_ERROR_TYPE_DEBUG,
1178 "ACK not matched against any active fragmentation with MAC `%s'\n",
1179 mac_to_string (&mas->endpoint->addr));
1181 case GNUNET_MESSAGE_TYPE_WLAN_DATA:
1182 if (NULL == mas->endpoint)
1187 if (msize < sizeof (struct WlanHeader))
1192 wlanheader = (const struct WlanHeader *) hdr;
1193 if (0 != memcmp (&wlanheader->target,
1194 plugin->env->my_identity,
1195 sizeof (struct GNUNET_PeerIdentity)))
1197 LOG (GNUNET_ERROR_TYPE_DEBUG,
1198 "WLAN data for `%s', not for me, ignoring\n",
1199 GNUNET_i2s (&wlanheader->target));
1202 if (ntohl (wlanheader->crc) !=
1203 GNUNET_CRYPTO_crc32_n (&wlanheader[1], msize - sizeof (struct WlanHeader)))
1205 GNUNET_STATISTICS_update (plugin->env->stats,
1206 _("# WLAN DATA messages discarded due to CRC32 error"), 1,
1210 xmas.endpoint = mas->endpoint;
1211 xmas.session = create_session (mas->endpoint, &wlanheader->sender);
1212 LOG (GNUNET_ERROR_TYPE_DEBUG,
1213 "Processing %u bytes of WLAN DATA from peer `%s'\n",
1214 (unsigned int) msize,
1215 GNUNET_i2s (&wlanheader->sender));
1216 (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer,
1218 (const char *) &wlanheader[1],
1219 msize - sizeof (struct WlanHeader),
1220 GNUNET_YES, GNUNET_NO);
1223 if (NULL == mas->endpoint)
1228 if (NULL == mas->session)
1233 LOG (GNUNET_ERROR_TYPE_DEBUG,
1234 "Received packet with %u bytes of type %u from peer %s\n",
1235 (unsigned int) msize,
1236 (unsigned int) ntohs (hdr->type),
1237 GNUNET_i2s (&mas->session->target));
1238 plugin->env->receive (plugin->env->cls,
1239 &mas->session->target,
1243 (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr,
1244 (mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1253 * Function used for to process the data from the suid process
1255 * @param cls the plugin handle
1256 * @param client client that send the data (not used)
1257 * @param hdr header of the GNUNET_MessageHeader
1260 handle_helper_message (void *cls, void *client,
1261 const struct GNUNET_MessageHeader *hdr)
1263 struct Plugin *plugin = cls;
1264 const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo;
1265 const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm;
1266 struct MacAndSession mas;
1269 msize = ntohs (hdr->size);
1270 switch (ntohs (hdr->type))
1272 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
1273 if (msize != sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
1278 cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *) hdr;
1279 if (GNUNET_YES == plugin->have_mac)
1281 if (0 == memcmp (&plugin->mac_address,
1283 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1284 break; /* no change */
1285 /* remove old address */
1286 plugin->env->notify_address (plugin->env->cls, GNUNET_NO,
1287 &plugin->mac_address,
1288 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress),
1291 plugin->mac_address = cm->mac;
1292 plugin->have_mac = GNUNET_YES;
1293 LOG (GNUNET_ERROR_TYPE_DEBUG,
1294 "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n",
1295 mac_to_string (&cm->mac),
1296 GNUNET_i2s (plugin->env->my_identity));
1297 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
1298 &plugin->mac_address,
1299 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress),
1302 case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER:
1303 LOG (GNUNET_ERROR_TYPE_DEBUG,
1304 "Got data message from helper with %u bytes\n",
1306 GNUNET_STATISTICS_update (plugin->env->stats,
1307 _("# DATA messages received via WLAN"), 1,
1309 if (msize < sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage))
1312 LOG (GNUNET_ERROR_TYPE_DEBUG,
1313 "Size of packet is too small (%u bytes)\n",
1317 rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) hdr;
1319 /* check if message is actually for us */
1320 if (0 != memcmp (&rxinfo->frame.addr3, &mac_bssid_gnunet,
1321 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1323 /* Not the GNUnet BSSID */
1326 if ( (0 != memcmp (&rxinfo->frame.addr1, &bc_all_mac,
1327 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))) &&
1328 (0 != memcmp (&rxinfo->frame.addr1, &plugin->mac_address,
1329 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))) )
1331 /* Neither broadcast nor specifically for us */
1334 if (0 == memcmp (&rxinfo->frame.addr2, &plugin->mac_address,
1335 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1337 /* packet is FROM us, thus not FOR us */
1341 GNUNET_STATISTICS_update (plugin->env->stats,
1342 _("# WLAN DATA messages processed"),
1344 LOG (GNUNET_ERROR_TYPE_DEBUG,
1345 "Receiving %u bytes of data from MAC `%s'\n",
1346 (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1347 mac_to_string (&rxinfo->frame.addr2));
1348 mas.endpoint = create_macendpoint (plugin, &rxinfo->frame.addr2);
1350 (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer,
1352 (const char*) &rxinfo[1],
1353 msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage),
1354 GNUNET_YES, GNUNET_NO);
1358 LOG (GNUNET_ERROR_TYPE_DEBUG,
1359 "Unexpected message of type %u (%u bytes)",
1360 ntohs (hdr->type), ntohs (hdr->size));
1369 * Task to (periodically) send a HELLO beacon
1371 * @param cls pointer to the plugin struct
1372 * @param tc scheduler context
1375 send_hello_beacon (void *cls,
1376 const struct GNUNET_SCHEDULER_TaskContext *tc)
1378 struct Plugin *plugin = cls;
1380 uint16_t hello_size;
1381 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader;
1382 const struct GNUNET_MessageHeader *hello;
1384 hello = plugin->env->get_our_hello ();
1385 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1386 GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
1387 size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size;
1389 char buf[size] GNUNET_ALIGN;
1391 LOG (GNUNET_ERROR_TYPE_DEBUG,
1392 "Sending %u byte HELLO beacon\n",
1393 (unsigned int) size);
1394 radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*) buf;
1395 get_radiotap_header (NULL, radioHeader, size);
1396 get_wlan_header (plugin, &radioHeader->frame, &bc_all_mac, size);
1397 memcpy (&radioHeader[1], hello, hello_size);
1399 GNUNET_HELPER_send (plugin->suid_helper,
1400 &radioHeader->header,
1401 GNUNET_YES /* can drop */,
1403 GNUNET_STATISTICS_update (plugin->env->stats, _("# HELLO beacons sent via WLAN"),
1406 plugin->beacon_task =
1407 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1408 (HELLO_BEACON_SCALING_FACTOR,
1409 plugin->mac_count + 1),
1417 * Another peer has suggested an address for this
1418 * peer and transport plugin. Check that this could be a valid
1419 * address. If so, consider adding it to the list
1422 * @param cls closure
1423 * @param addr pointer to the address
1424 * @param addrlen length of addr
1425 * @return GNUNET_OK if this is a plausible address for this peer
1429 wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
1431 struct Plugin *plugin = cls;
1433 if (addrlen != sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))
1435 GNUNET_break_op (0);
1436 return GNUNET_SYSERR;
1438 if (GNUNET_YES != plugin->have_mac)
1440 LOG (GNUNET_ERROR_TYPE_DEBUG,
1441 "Rejecting MAC `%s': I don't know my MAC!\n",
1442 mac_to_string (addr));
1443 return GNUNET_NO; /* don't know my MAC */
1445 if (0 != memcmp (addr,
1446 &plugin->mac_address,
1449 LOG (GNUNET_ERROR_TYPE_DEBUG,
1450 "Rejecting MAC `%s': not my MAC!\n",
1451 mac_to_string (addr));
1452 return GNUNET_NO; /* not my MAC */
1459 * Function called for a quick conversion of the binary address to
1460 * a numeric address. Note that the caller must not free the
1461 * address and that the next call to this function is allowed
1462 * to override the address again.
1464 * @param cls closure
1465 * @param addr binary address
1466 * @param addrlen length of the address
1467 * @return string representing the same address
1470 wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1472 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1474 if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != addrlen)
1480 return GNUNET_strdup (mac_to_string (mac));
1485 * Convert the transports address to a nice, human-readable format.
1487 * @param cls closure
1488 * @param type name of the transport that generated the address
1489 * @param addr one of the addresses of the host, NULL for the last address
1490 * the specific address format depends on the transport
1491 * @param addrlen length of the address
1492 * @param numeric should (IP) addresses be displayed in numeric form?
1493 * @param timeout after how long should we give up?
1494 * @param asc function to call on each string
1495 * @param asc_cls closure for asc
1498 wlan_plugin_address_pretty_printer (void *cls, const char *type,
1499 const void *addr, size_t addrlen,
1501 struct GNUNET_TIME_Relative timeout,
1502 GNUNET_TRANSPORT_AddressStringCallback asc,
1505 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1508 if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != addrlen)
1510 /* invalid address */
1511 LOG (GNUNET_ERROR_TYPE_WARNING,
1512 _("WLAN address with invalid size encountered\n"));
1513 asc (asc_cls, NULL);
1517 ret = GNUNET_strdup (mac_to_string (mac));
1520 asc (asc_cls, NULL);
1525 * Exit point from the plugin.
1527 * @param cls pointer to the api struct
1530 libgnunet_plugin_transport_wlan_done (void *cls)
1532 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1533 struct Plugin *plugin = api->cls;
1534 struct MacEndpoint *endpoint;
1535 struct MacEndpoint *endpoint_next;
1543 if (GNUNET_YES == plugin->have_mac)
1545 plugin->env->notify_address (plugin->env->cls, GNUNET_NO,
1546 &plugin->mac_address,
1547 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress),
1549 plugin->have_mac = GNUNET_NO;
1552 if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task)
1554 GNUNET_SCHEDULER_cancel (plugin->beacon_task);
1555 plugin->beacon_task = GNUNET_SCHEDULER_NO_TASK;
1557 if (NULL != plugin->suid_helper)
1559 GNUNET_HELPER_stop (plugin->suid_helper);
1560 plugin->suid_helper = NULL;
1562 endpoint_next = plugin->mac_head;
1563 while (NULL != (endpoint = endpoint_next))
1565 endpoint_next = endpoint->next;
1566 free_macendpoint (endpoint);
1568 if (NULL != plugin->fragment_data_tokenizer)
1570 GNUNET_SERVER_mst_destroy (plugin->fragment_data_tokenizer);
1571 plugin->fragment_data_tokenizer = NULL;
1573 if (NULL != plugin->wlan_header_payload_tokenizer)
1575 GNUNET_SERVER_mst_destroy (plugin->wlan_header_payload_tokenizer);
1576 plugin->wlan_header_payload_tokenizer = NULL;
1578 if (NULL != plugin->helper_payload_tokenizer)
1580 GNUNET_SERVER_mst_destroy (plugin->helper_payload_tokenizer);
1581 plugin->helper_payload_tokenizer = NULL;
1583 GNUNET_free_non_null (plugin->interface);
1584 GNUNET_free (plugin);
1591 * Function called to convert a string address to
1594 * @param cls closure ('struct Plugin*')
1595 * @param addr string address
1596 * @param addrlen length of the address
1597 * @param buf location to store the buffer
1598 * @param added location to store the number of bytes in the buffer.
1599 * If the function returns GNUNET_SYSERR, its contents are undefined.
1600 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1603 wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen,
1604 void **buf, size_t *added)
1606 struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1610 if ((NULL == addr) || (addrlen == 0))
1613 return GNUNET_SYSERR;
1615 if ('\0' != addr[addrlen - 1])
1618 return GNUNET_SYSERR;
1620 if (strlen (addr) != addrlen - 1)
1623 return GNUNET_SYSERR;
1625 if (6 != SSCANF (addr,
1626 "%X:%X:%X:%X:%X:%X",
1627 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
1630 return GNUNET_SYSERR;
1632 mac = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1636 *added = sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress);
1642 * Entry point for the plugin.
1644 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
1645 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
1648 libgnunet_plugin_transport_wlan_init (void *cls)
1650 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1651 struct GNUNET_TRANSPORT_PluginFunctions *api;
1652 struct Plugin *plugin;
1654 unsigned long long testmode;
1656 /* check for 'special' mode */
1657 if (NULL == env->receive)
1659 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1660 initialze the plugin or the API */
1661 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1663 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
1664 api->address_to_string = &wlan_plugin_address_to_string;
1665 api->string_to_address = &wlan_string_to_address;
1670 /* check configuration */
1672 GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE")) &&
1674 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
1675 "TESTMODE", &testmode)) ||
1678 LOG (GNUNET_ERROR_TYPE_ERROR,
1679 _("Invalid configuration option `%s' in section `%s'\n"),
1684 if ( (0 == testmode) &&
1685 (GNUNET_YES != GNUNET_OS_check_helper_binary ("gnunet-helper-transport-wlan")) )
1687 LOG (GNUNET_ERROR_TYPE_ERROR,
1688 _("Helper binary `%s' not SUID, cannot run WLAN transport\n"),
1689 "gnunet-helper-transport-wlan");
1693 GNUNET_CONFIGURATION_get_value_string
1694 (env->cfg, "transport-wlan", "INTERFACE",
1697 LOG (GNUNET_ERROR_TYPE_ERROR,
1698 _("Missing configuration option `%s' in section `%s'\n"),
1704 plugin = GNUNET_malloc (sizeof (struct Plugin));
1705 plugin->interface = interface;
1707 GNUNET_STATISTICS_set (plugin->env->stats, _("# WLAN sessions allocated"),
1709 GNUNET_STATISTICS_set (plugin->env->stats, _("# WLAN MAC endpoints allocated"),
1711 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
1712 GNUNET_BANDWIDTH_value_init (100 * 1024 *
1714 plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1715 plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1716 plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1717 plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon,
1721 case 0: /* normal */
1722 plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan";
1723 plugin->helper_argv[1] = interface;
1724 plugin->helper_argv[2] = NULL;
1725 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
1726 "gnunet-helper-transport-wlan",
1727 plugin->helper_argv,
1728 &handle_helper_message,
1732 case 1: /* testmode, peer 1 */
1733 plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
1734 plugin->helper_argv[1] = (char *) "1";
1735 plugin->helper_argv[2] = NULL;
1736 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
1737 "gnunet-helper-transport-wlan-dummy",
1738 plugin->helper_argv,
1739 &handle_helper_message,
1743 case 2: /* testmode, peer 2 */
1744 plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
1745 plugin->helper_argv[1] = (char *) "2";
1746 plugin->helper_argv[2] = NULL;
1747 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
1748 "gnunet-helper-transport-wlan-dummy",
1749 plugin->helper_argv,
1750 &handle_helper_message,
1758 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1760 api->send = &wlan_plugin_send;
1761 api->get_session = &wlan_plugin_get_session;
1762 api->disconnect = &wlan_plugin_disconnect;
1763 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
1764 api->check_address = &wlan_plugin_address_suggested;
1765 api->address_to_string = &wlan_plugin_address_to_string;
1766 api->string_to_address = &wlan_string_to_address;
1771 /* end of plugin_transport_wlan.c */