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.
157 * API requirement (must be first).
159 struct SessionHeader header;
162 * We keep all sessions in a DLL at their respective
163 * 'struct MACEndpoint'.
165 struct Session *next;
168 * We keep all sessions in a DLL at their respective
169 * 'struct MACEndpoint'.
171 struct Session *prev;
174 * MAC endpoint with the address of this peer.
176 struct MacEndpoint *mac;
179 * Head of messages currently pending for transmission to this peer.
181 struct PendingMessage *pending_message_head;
184 * Tail of messages currently pending for transmission to this peer.
186 struct PendingMessage *pending_message_tail;
189 * To whom are we talking to (set to our identity
190 * if we are still waiting for the welcome message)
192 struct GNUNET_PeerIdentity target;
195 * When should this session time out?
197 struct GNUNET_TIME_Absolute timeout;
200 * Timeout task (for the session).
202 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
208 * Struct for messages that are being fragmented in a MAC's transmission queue.
210 struct FragmentMessage
214 * This is a doubly-linked list.
216 struct FragmentMessage *next;
219 * This is a doubly-linked list.
221 struct FragmentMessage *prev;
224 * MAC endpoint this message belongs to
226 struct MacEndpoint *macendpoint;
229 * Fragmentation context
231 struct GNUNET_FRAGMENT_Context *fragcontext;
234 * Transmission handle to helper (to cancel if the frag context
235 * is destroyed early for some reason).
237 struct GNUNET_HELPER_SendHandle *sh;
240 * Intended recipient.
242 struct GNUNET_PeerIdentity target;
245 * Timeout value for the message.
247 struct GNUNET_TIME_Absolute timeout;
252 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
255 * Continuation to call when we're done with this message.
257 GNUNET_TRANSPORT_TransmitContinuation cont;
268 * Struct to represent one network card connection
274 * We keep all MACs in a DLL in the plugin.
276 struct MacEndpoint *next;
279 * We keep all MACs in a DLL in the plugin.
281 struct MacEndpoint *prev;
284 * Pointer to the global plugin struct.
286 struct Plugin *plugin;
289 * Head of sessions that use this MAC.
291 struct Session *sessions_head;
294 * Tail of sessions that use this MAC.
296 struct Session *sessions_tail;
299 * Head of messages we are currently sending to this MAC.
301 struct FragmentMessage *sending_messages_head;
304 * Tail of messages we are currently sending to this MAC.
306 struct FragmentMessage *sending_messages_tail;
309 * Defrag context for this MAC
311 struct GNUNET_DEFRAGMENT_Context *defrag;
314 * When should this endpoint time out?
316 struct GNUNET_TIME_Absolute timeout;
321 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
324 * count of messages in the fragment out queue for this mac endpoint
326 unsigned int fragment_messages_out_count;
331 struct GNUNET_TRANSPORT_WLAN_MacAddress addr;
334 * Desired transmission power for this MAC
339 * Desired transmission rate for this MAC
344 * Antenna we should use for this MAC
352 * Encapsulation of all of the state of the plugin.
359 struct GNUNET_TRANSPORT_PluginEnvironment *env;
362 * Handle to helper process for priviledged operations.
364 struct GNUNET_HELPER_Handle *suid_helper;
367 * ARGV-vector for the helper (all helpers take only the binary
368 * name, one actual argument, plus the NULL terminator for 'argv').
370 char * helper_argv[3];
373 * The interface of the wlan card given to us by the user.
378 * Tokenizer for demultiplexing of data packets resulting from defragmentation.
380 struct GNUNET_SERVER_MessageStreamTokenizer *fragment_data_tokenizer;
383 * Tokenizer for demultiplexing of data packets received from the suid helper
385 struct GNUNET_SERVER_MessageStreamTokenizer *helper_payload_tokenizer;
388 * Tokenizer for demultiplexing of data packets that follow the WLAN Header
390 struct GNUNET_SERVER_MessageStreamTokenizer *wlan_header_payload_tokenizer;
393 * Head of list of open connections.
395 struct MacEndpoint *mac_head;
398 * Tail of list of open connections.
400 struct MacEndpoint *mac_tail;
403 * Number of connections
405 unsigned int mac_count;
408 * Task that periodically sends a HELLO beacon via the helper.
410 GNUNET_SCHEDULER_TaskIdentifier beacon_task;
413 * Tracker for bandwidth limit
415 struct GNUNET_BANDWIDTH_Tracker tracker;
418 * The mac_address of the wlan card given to us by the helper.
420 struct GNUNET_TRANSPORT_WLAN_MacAddress mac_address;
423 * Have we received a control message with our MAC address yet?
432 * Information associated with a message. Can contain
433 * the session or the MAC endpoint associated with the
439 * NULL if the identity of the other peer is not known.
441 struct Session *session;
444 * MAC address of the other peer, NULL if not known.
446 struct MacEndpoint *endpoint;
451 * Print MAC addresses nicely.
453 * @param mac the mac address
454 * @return string to a static buffer with the human-readable mac, will be overwritten during the next call to this function
457 mac_to_string (const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac)
459 static char macstr[20];
461 GNUNET_snprintf (macstr, sizeof (macstr), "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac->mac[0], mac->mac[1],
462 mac->mac[2], mac->mac[3], mac->mac[4], mac->mac[5]);
468 * Fill the radiotap header
470 * @param endpoint pointer to the endpoint, can be NULL
471 * @param header pointer to the radiotap header
472 * @param size total message size
475 get_radiotap_header (struct MacEndpoint *endpoint,
476 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
479 header->header.type = ntohs (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER);
480 header->header.size = ntohs (size);
481 if (NULL != endpoint)
483 header->rate = endpoint->rate;
484 header->tx_power = endpoint->tx_power;
485 header->antenna = endpoint->antenna;
490 header->tx_power = 0;
497 * Generate the WLAN hardware header for one packet
499 * @param plugin the plugin handle
500 * @param header address to write the header to
501 * @param to_mac_addr address of the recipient
502 * @param size size of the whole packet, needed to calculate the time to send the packet
505 get_wlan_header (struct Plugin *plugin,
506 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *header,
507 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
510 const int rate = 11000000;
512 header->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
513 header->addr1 = *to_mac_addr;
514 header->addr2 = plugin->mac_address;
515 header->addr3 = mac_bssid_gnunet;
516 header->duration = GNUNET_htole16 ((size * 1000000) / rate + 290);
517 header->sequence_control = 0; // FIXME?
518 header->llc[0] = WLAN_LLC_DSAP_FIELD;
519 header->llc[1] = WLAN_LLC_SSAP_FIELD;
520 header->llc[2] = 0; // FIXME?
521 header->llc[3] = 0; // FIXME?
526 * Send an ACK for a fragment we received.
528 * @param cls the 'struct MacEndpoint' the ACK must be sent to
529 * @param msg_id id of the message
530 * @param hdr pointer to the hdr where the ack is stored
533 send_ack (void *cls, uint32_t msg_id,
534 const struct GNUNET_MessageHeader *hdr)
536 struct MacEndpoint *endpoint = cls;
537 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage* radio_header;
538 uint16_t msize = ntohs (hdr->size);
539 size_t size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
542 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
547 LOG (GNUNET_ERROR_TYPE_DEBUG,
548 "Sending ACK to helper\n");
549 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
550 get_radiotap_header (endpoint, radio_header, size);
551 get_wlan_header (endpoint->plugin,
552 &radio_header->frame,
555 memcpy (&radio_header[1], hdr, msize);
557 GNUNET_HELPER_send (endpoint->plugin->suid_helper,
558 &radio_header->header,
559 GNUNET_NO /* dropping ACKs is bad */,
561 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN ACKs sent"),
567 * Handles the data after all fragments are put together
569 * @param cls macendpoint this messages belongs to
570 * @param hdr pointer to the data
573 wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
575 struct MacEndpoint *endpoint = cls;
576 struct Plugin *plugin = endpoint->plugin;
577 struct MacAndSession mas;
579 GNUNET_STATISTICS_update (plugin->env->stats,
580 _("# WLAN messages defragmented"), 1,
583 mas.endpoint = endpoint;
584 (void) GNUNET_SERVER_mst_receive (plugin->fragment_data_tokenizer,
588 GNUNET_YES, GNUNET_NO);
595 * @param session the session free
598 free_session (struct Session *session)
600 struct MacEndpoint *endpoint = session->mac;
601 struct PendingMessage *pm;
603 endpoint->plugin->env->session_end (endpoint->plugin->env->cls,
606 while (NULL != (pm = session->pending_message_head))
608 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
609 session->pending_message_tail, pm);
610 if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task)
612 GNUNET_SCHEDULER_cancel (pm->timeout_task);
613 pm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
615 GNUNET_free (pm->msg);
618 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head,
619 endpoint->sessions_tail,
621 if (session->timeout_task != GNUNET_SCHEDULER_NO_TASK)
623 GNUNET_SCHEDULER_cancel (session->timeout_task);
624 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
626 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), -1,
628 GNUNET_free (session);
633 * A session is timing out. Clean up.
635 * @param cls pointer to the Session
636 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
639 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
641 struct Session * session = cls;
642 struct GNUNET_TIME_Relative timeout;
644 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
645 timeout = GNUNET_TIME_absolute_get_remaining (session->timeout);
646 if (0 == timeout.rel_value)
648 free_session (session);
651 session->timeout_task =
652 GNUNET_SCHEDULER_add_delayed (timeout, &session_timeout, session);
657 * Create a new session
659 * @param endpoint pointer to the mac endpoint of the peer
660 * @param peer peer identity to use for this session
661 * @return returns the session
663 static struct Session *
664 create_session (struct MacEndpoint *endpoint,
665 const struct GNUNET_PeerIdentity *peer)
667 struct Session *session;
669 for (session = endpoint->sessions_head; NULL != session; session = session->next)
670 if (0 == memcmp (peer, &session->target,
671 sizeof (struct GNUNET_PeerIdentity)))
673 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
676 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), 1,
678 session = GNUNET_malloc (sizeof (struct Session));
679 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
680 endpoint->sessions_tail,
682 session->mac = endpoint;
683 session->target = *peer;
684 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
685 session->timeout_task =
686 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session);
687 LOG (GNUNET_ERROR_TYPE_DEBUG,
688 "Created new session for peer `%s' with endpoint %s\n",
690 mac_to_string (&endpoint->addr));
696 * Function called once we have successfully given the fragment
697 * message to the SUID helper process and we are thus ready for
700 * @param cls the 'struct FragmentMessage'
701 * @param result result of the operation (GNUNET_OK on success, GNUNET_NO if the helper died, GNUNET_SYSERR
702 * if the helper was stopped)
705 fragment_transmission_done (void *cls,
708 struct FragmentMessage *fm = cls;
711 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
716 * Transmit a fragment of a message.
718 * @param cls 'struct FragmentMessage' this fragment message belongs to
719 * @param hdr pointer to the start of the fragment message
722 transmit_fragment (void *cls,
723 const struct GNUNET_MessageHeader *hdr)
725 struct FragmentMessage *fm = cls;
726 struct MacEndpoint *endpoint = fm->macendpoint;
730 msize = ntohs (hdr->size);
731 size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
734 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radio_header;
736 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
737 get_radiotap_header (endpoint, radio_header, size);
738 get_wlan_header (endpoint->plugin,
739 &radio_header->frame,
742 memcpy (&radio_header[1], hdr, msize);
743 GNUNET_assert (NULL == fm->sh);
744 fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper,
745 &radio_header->header,
747 &fragment_transmission_done, fm);
749 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN message fragments sent"),
752 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
758 * Frees the space of a message in the fragment queue (send queue)
760 * @param fm message to free
763 free_fragment_message (struct FragmentMessage *fm)
765 struct MacEndpoint *endpoint = fm->macendpoint;
767 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN messages pending (with fragmentation)"),
769 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
770 endpoint->sending_messages_tail, fm);
773 GNUNET_HELPER_send_cancel (fm->sh);
776 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
777 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
779 GNUNET_SCHEDULER_cancel (fm->timeout_task);
780 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
787 * A FragmentMessage has timed out. Remove it.
789 * @param cls pointer to the 'struct FragmentMessage'
790 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
793 fragmentmessage_timeout (void *cls,
794 const struct GNUNET_SCHEDULER_TaskContext *tc)
796 struct FragmentMessage *fm = cls;
798 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
799 if (NULL != fm->cont)
801 fm->cont (fm->cont_cls, &fm->target, GNUNET_SYSERR);
804 free_fragment_message (fm);
809 * Transmit a message to the given destination with fragmentation.
811 * @param endpoint desired destination
812 * @param timeout how long can the message wait?
813 * @param target peer that should receive the message
814 * @param msg message to transmit
815 * @param cont continuation to call once the message has
816 * been transmitted (or if the transport is ready
817 * for the next transmission call; or if the
818 * peer disconnected...); can be NULL
819 * @param cont_cls closure for cont
822 send_with_fragmentation (struct MacEndpoint *endpoint,
823 struct GNUNET_TIME_Relative timeout,
824 const struct GNUNET_PeerIdentity *target,
825 const struct GNUNET_MessageHeader *msg,
826 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
829 struct FragmentMessage *fm;
830 struct Plugin *plugin;
832 plugin = endpoint->plugin;
833 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
834 fm->macendpoint = endpoint;
835 fm->target = *target;
836 fm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
838 fm->cont_cls = cont_cls;
840 GNUNET_FRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
842 GNUNET_TIME_UNIT_SECONDS,
844 &transmit_fragment, fm);
846 GNUNET_SCHEDULER_add_delayed (timeout,
847 &fragmentmessage_timeout, fm);
848 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sending_messages_head,
849 endpoint->sending_messages_tail,
855 * Free a MAC endpoint.
857 * @param endpoint pointer to the MacEndpoint to free
860 free_macendpoint (struct MacEndpoint *endpoint)
862 struct Plugin *plugin = endpoint->plugin;
863 struct FragmentMessage *fm;
864 struct Session *session;
866 GNUNET_STATISTICS_update (plugin->env->stats,
867 _("# WLAN MAC endpoints allocated"), -1, GNUNET_NO);
868 while (NULL != (session = endpoint->sessions_head))
869 free_session (session);
870 while (NULL != (fm = endpoint->sending_messages_head))
871 free_fragment_message (fm);
872 GNUNET_CONTAINER_DLL_remove (plugin->mac_head,
876 if (GNUNET_SCHEDULER_NO_TASK != endpoint->timeout_task)
878 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
879 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
881 GNUNET_free (endpoint);
886 * A MAC endpoint is timing out. Clean up.
888 * @param cls pointer to the MacEndpoint
889 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
892 macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
894 struct MacEndpoint *endpoint = cls;
895 struct GNUNET_TIME_Relative timeout;
897 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
898 timeout = GNUNET_TIME_absolute_get_remaining (endpoint->timeout);
899 if (0 == timeout.rel_value)
901 free_macendpoint (endpoint);
904 endpoint->timeout_task =
905 GNUNET_SCHEDULER_add_delayed (timeout, &macendpoint_timeout,
911 * Find (or create) a MacEndpoint with a specific MAC address
913 * @param plugin pointer to the plugin struct
914 * @param addr the MAC address of the endpoint
915 * @return handle to our data structure for this MAC
917 static struct MacEndpoint *
918 create_macendpoint (struct Plugin *plugin,
919 const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr)
921 struct MacEndpoint *pos;
923 for (pos = plugin->mac_head; NULL != pos; pos = pos->next)
924 if (0 == memcmp (addr, &pos->addr, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
926 pos = GNUNET_malloc (sizeof (struct MacEndpoint));
928 pos->plugin = plugin;
930 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
931 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
933 &wlan_data_message_handler,
935 pos->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
937 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
939 GNUNET_CONTAINER_DLL_insert (plugin->mac_head, plugin->mac_tail, pos);
941 GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"),
943 LOG (GNUNET_ERROR_TYPE_DEBUG,
944 "New MAC endpoint `%s'\n",
945 mac_to_string (addr));
951 * Creates a new outbound session the transport service will use to send data to the
954 * @param cls the plugin
955 * @param address the address
956 * @return the session or NULL of max connections exceeded
958 static struct Session *
959 wlan_plugin_get_session (void *cls,
960 const struct GNUNET_HELLO_Address *address)
962 struct Plugin *plugin = cls;
963 struct MacEndpoint *endpoint;
967 if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != address->address_length)
972 LOG (GNUNET_ERROR_TYPE_DEBUG,
973 "Service asked to create session for peer `%s' with MAC `%s'\n",
974 GNUNET_i2s (&address->peer),
975 mac_to_string (address->address));
976 endpoint = create_macendpoint (plugin, address->address);
977 return create_session (endpoint, &address->peer);
982 * Function that can be used to force the plugin to disconnect
983 * from the given peer and cancel all previous transmissions
984 * (and their continuation).
987 * @param target peer from which to disconnect
990 wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
992 struct Plugin *plugin = cls;
993 struct Session *session;
994 struct MacEndpoint *endpoint;
996 for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
997 for (session = endpoint->sessions_head; NULL != session; session = session->next)
998 if (0 == memcmp (target, &session->target,
999 sizeof (struct GNUNET_PeerIdentity)))
1001 free_session (session);
1002 break; /* inner-loop only (in case peer has another MAC as well!) */
1008 * Function that can be used by the transport service to transmit
1009 * a message using the plugin. Note that in the case of a
1010 * peer disconnecting, the continuation MUST be called
1011 * prior to the disconnect notification itself. This function
1012 * will be called with this peer's HELLO message to initiate
1013 * a fresh connection to another peer.
1015 * @param cls closure
1016 * @param session which session must be used
1017 * @param msgbuf the message to transmit
1018 * @param msgbuf_size number of bytes in 'msgbuf'
1019 * @param priority how important is the message (most plugins will
1020 * ignore message priority and just FIFO)
1021 * @param to how long to wait at most for the transmission (does not
1022 * require plugins to discard the message after the timeout,
1023 * just advisory for the desired delay; most plugins will ignore
1025 * @param cont continuation to call once the message has
1026 * been transmitted (or if the transport is ready
1027 * for the next transmission call; or if the
1028 * peer disconnected...); can be NULL
1029 * @param cont_cls closure for cont
1030 * @return number of bytes used (on the physical network, with overheads);
1031 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1032 * and does NOT mean that the message was not transmitted (DV)
1035 wlan_plugin_send (void *cls,
1036 struct Session *session,
1037 const char *msgbuf, size_t msgbuf_size,
1038 unsigned int priority,
1039 struct GNUNET_TIME_Relative to,
1040 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1042 struct Plugin *plugin = cls;
1043 struct WlanHeader *wlanheader;
1044 size_t size = msgbuf_size + sizeof (struct WlanHeader);
1045 char buf[size] GNUNET_ALIGN;
1047 LOG (GNUNET_ERROR_TYPE_DEBUG,
1048 "Transmitting %u bytes of payload to peer `%s' (starting with %u byte message of type %u)\n",
1050 GNUNET_i2s (&session->target),
1051 (unsigned int) ntohs (((struct GNUNET_MessageHeader*)msgbuf)->size),
1052 (unsigned int) ntohs (((struct GNUNET_MessageHeader*)msgbuf)->type));
1053 wlanheader = (struct WlanHeader *) buf;
1054 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
1055 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
1056 wlanheader->sender = *plugin->env->my_identity;
1057 wlanheader->target = session->target;
1058 wlanheader->crc = htonl (GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size));
1059 memcpy (&wlanheader[1], msgbuf, msgbuf_size);
1060 send_with_fragmentation (session->mac,
1063 &wlanheader->header,
1070 * We have received data from the WLAN via some session. Process depending
1071 * on the message type (HELLO, DATA, FRAGMENTATION or FRAGMENTATION-ACK).
1073 * @param cls pointer to the plugin
1074 * @param client pointer to the session this message belongs to
1075 * @param hdr start of the message
1078 process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1080 struct Plugin *plugin = cls;
1081 struct MacAndSession *mas = client;
1082 struct MacAndSession xmas;
1084 struct GNUNET_ATS_Information ats[NUM_ATS]; /* FIXME: do better here */
1085 struct FragmentMessage *fm;
1086 struct GNUNET_PeerIdentity tmpsource;
1087 const struct WlanHeader *wlanheader;
1091 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
1092 ats[0].value = htonl (1);
1093 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1094 ats[1].value = htonl (GNUNET_ATS_NET_WLAN);
1095 msize = ntohs (hdr->size);
1096 switch (ntohs (hdr->type))
1098 case GNUNET_MESSAGE_TYPE_HELLO:
1100 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource))
1102 GNUNET_break_op (0);
1105 LOG (GNUNET_ERROR_TYPE_DEBUG,
1106 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n",
1107 (unsigned int) msize,
1108 GNUNET_i2s (&tmpsource),
1109 mac_to_string (&mas->endpoint->addr));
1111 GNUNET_STATISTICS_update (plugin->env->stats,
1112 _("# HELLO messages received via WLAN"), 1,
1114 plugin->env->receive (plugin->env->cls,
1119 (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr,
1120 (mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1122 case GNUNET_MESSAGE_TYPE_FRAGMENT:
1123 if (NULL == mas->endpoint)
1128 LOG (GNUNET_ERROR_TYPE_DEBUG,
1129 "Processing %u bytes of FRAGMENT from MAC %s\n",
1130 (unsigned int) msize,
1131 mac_to_string (&mas->endpoint->addr));
1132 GNUNET_STATISTICS_update (plugin->env->stats,
1133 _("# fragments received via WLAN"), 1, GNUNET_NO);
1134 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag,
1137 case GNUNET_MESSAGE_TYPE_FRAGMENT_ACK:
1138 if (NULL == mas->endpoint)
1143 GNUNET_STATISTICS_update (plugin->env->stats, _("# ACKs received via WLAN"),
1145 for (fm = mas->endpoint->sending_messages_head; NULL != fm; fm = fm->next)
1147 ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
1148 if (GNUNET_OK == ret)
1150 LOG (GNUNET_ERROR_TYPE_DEBUG,
1151 "Got last ACK, finished message transmission to `%s' (%p)\n",
1152 mac_to_string (&mas->endpoint->addr),
1154 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
1155 if (NULL != fm->cont)
1157 fm->cont (fm->cont_cls, &fm->target, GNUNET_OK);
1160 free_fragment_message (fm);
1163 if (GNUNET_NO == ret)
1165 LOG (GNUNET_ERROR_TYPE_DEBUG,
1166 "Got an ACK, message transmission to `%s' not yet finished\n",
1167 mac_to_string (&mas->endpoint->addr));
1171 LOG (GNUNET_ERROR_TYPE_DEBUG,
1172 "ACK not matched against any active fragmentation with MAC `%s'\n",
1173 mac_to_string (&mas->endpoint->addr));
1175 case GNUNET_MESSAGE_TYPE_WLAN_DATA:
1176 if (NULL == mas->endpoint)
1181 if (msize < sizeof (struct WlanHeader))
1186 wlanheader = (const struct WlanHeader *) hdr;
1187 if (0 != memcmp (&wlanheader->target,
1188 plugin->env->my_identity,
1189 sizeof (struct GNUNET_PeerIdentity)))
1191 LOG (GNUNET_ERROR_TYPE_DEBUG,
1192 "WLAN data for `%s', not for me, ignoring\n",
1193 GNUNET_i2s (&wlanheader->target));
1196 if (ntohl (wlanheader->crc) !=
1197 GNUNET_CRYPTO_crc32_n (&wlanheader[1], msize - sizeof (struct WlanHeader)))
1199 GNUNET_STATISTICS_update (plugin->env->stats,
1200 _("# WLAN DATA messages discarded due to CRC32 error"), 1,
1204 xmas.endpoint = mas->endpoint;
1205 xmas.session = create_session (mas->endpoint, &wlanheader->sender);
1206 LOG (GNUNET_ERROR_TYPE_DEBUG,
1207 "Processing %u bytes of WLAN DATA from peer `%s'\n",
1208 (unsigned int) msize,
1209 GNUNET_i2s (&wlanheader->sender));
1210 (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer,
1212 (const char *) &wlanheader[1],
1213 msize - sizeof (struct WlanHeader),
1214 GNUNET_YES, GNUNET_NO);
1217 if (NULL == mas->endpoint)
1222 if (NULL == mas->session)
1227 LOG (GNUNET_ERROR_TYPE_DEBUG,
1228 "Received packet with %u bytes of type %u from peer %s\n",
1229 (unsigned int) msize,
1230 (unsigned int) ntohs (hdr->type),
1231 GNUNET_i2s (&mas->session->target));
1232 plugin->env->receive (plugin->env->cls,
1233 &mas->session->target,
1237 (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr,
1238 (mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1246 * Function used for to process the data from the suid process
1248 * @param cls the plugin handle
1249 * @param client client that send the data (not used)
1250 * @param hdr header of the GNUNET_MessageHeader
1253 handle_helper_message (void *cls, void *client,
1254 const struct GNUNET_MessageHeader *hdr)
1256 struct Plugin *plugin = cls;
1257 const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo;
1258 const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm;
1259 struct MacAndSession mas;
1262 msize = ntohs (hdr->size);
1263 switch (ntohs (hdr->type))
1265 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
1266 if (msize != sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
1271 cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *) hdr;
1272 if (GNUNET_YES == plugin->have_mac)
1274 if (0 == memcmp (&plugin->mac_address,
1276 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1277 break; /* no change */
1278 /* remove old address */
1279 plugin->env->notify_address (plugin->env->cls, GNUNET_NO,
1280 &plugin->mac_address,
1281 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1283 plugin->mac_address = cm->mac;
1284 plugin->have_mac = GNUNET_YES;
1285 LOG (GNUNET_ERROR_TYPE_DEBUG,
1286 "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n",
1287 mac_to_string (&cm->mac),
1288 GNUNET_i2s (plugin->env->my_identity));
1289 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
1290 &plugin->mac_address,
1291 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1293 case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER:
1294 LOG (GNUNET_ERROR_TYPE_DEBUG,
1295 "Got data message from helper with %u bytes\n",
1297 GNUNET_STATISTICS_update (plugin->env->stats,
1298 _("# DATA messages received via WLAN"), 1,
1300 if (msize < sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage))
1303 LOG (GNUNET_ERROR_TYPE_DEBUG,
1304 "Size of packet is too small (%u bytes)\n",
1308 rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) hdr;
1310 /* check if message is actually for us */
1311 if (0 != memcmp (&rxinfo->frame.addr3, &mac_bssid_gnunet,
1312 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1314 /* Not the GNUnet BSSID */
1317 if ( (0 != memcmp (&rxinfo->frame.addr1, &bc_all_mac,
1318 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))) &&
1319 (0 != memcmp (&rxinfo->frame.addr1, &plugin->mac_address,
1320 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))) )
1322 /* Neither broadcast nor specifically for us */
1325 if (0 == memcmp (&rxinfo->frame.addr2, &plugin->mac_address,
1326 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1328 /* packet is FROM us, thus not FOR us */
1332 GNUNET_STATISTICS_update (plugin->env->stats,
1333 _("# WLAN DATA messages processed"),
1335 LOG (GNUNET_ERROR_TYPE_DEBUG,
1336 "Receiving %u bytes of data from MAC `%s'\n",
1337 (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1338 mac_to_string (&rxinfo->frame.addr2));
1339 mas.endpoint = create_macendpoint (plugin, &rxinfo->frame.addr2);
1341 (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer,
1343 (const char*) &rxinfo[1],
1344 msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage),
1345 GNUNET_YES, GNUNET_NO);
1349 LOG (GNUNET_ERROR_TYPE_DEBUG,
1350 "Unexpected message of type %u (%u bytes)",
1351 ntohs (hdr->type), ntohs (hdr->size));
1359 * Task to (periodically) send a HELLO beacon
1361 * @param cls pointer to the plugin struct
1362 * @param tc scheduler context
1365 send_hello_beacon (void *cls,
1366 const struct GNUNET_SCHEDULER_TaskContext *tc)
1368 struct Plugin *plugin = cls;
1370 uint16_t hello_size;
1371 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader;
1372 const struct GNUNET_MessageHeader *hello;
1374 hello = plugin->env->get_our_hello ();
1375 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1376 GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
1377 size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size;
1379 char buf[size] GNUNET_ALIGN;
1381 LOG (GNUNET_ERROR_TYPE_DEBUG,
1382 "Sending %u byte HELLO beacon\n",
1383 (unsigned int) size);
1384 radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*) buf;
1385 get_radiotap_header (NULL, radioHeader, size);
1386 get_wlan_header (plugin, &radioHeader->frame, &bc_all_mac, size);
1387 memcpy (&radioHeader[1], hello, hello_size);
1389 GNUNET_HELPER_send (plugin->suid_helper,
1390 &radioHeader->header,
1391 GNUNET_YES /* can drop */,
1393 GNUNET_STATISTICS_update (plugin->env->stats, _("# HELLO beacons sent via WLAN"),
1396 plugin->beacon_task =
1397 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1398 (HELLO_BEACON_SCALING_FACTOR,
1399 plugin->mac_count + 1),
1407 * Another peer has suggested an address for this
1408 * peer and transport plugin. Check that this could be a valid
1409 * address. If so, consider adding it to the list
1412 * @param cls closure
1413 * @param addr pointer to the address
1414 * @param addrlen length of addr
1415 * @return GNUNET_OK if this is a plausible address for this peer
1419 wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
1421 struct Plugin *plugin = cls;
1423 if (addrlen != sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))
1425 GNUNET_break_op (0);
1426 return GNUNET_SYSERR;
1428 if (GNUNET_YES != plugin->have_mac)
1430 LOG (GNUNET_ERROR_TYPE_DEBUG,
1431 "Rejecting MAC `%s': I don't know my MAC!\n",
1432 mac_to_string (addr));
1433 return GNUNET_NO; /* don't know my MAC */
1435 if (0 != memcmp (addr,
1436 &plugin->mac_address,
1439 LOG (GNUNET_ERROR_TYPE_DEBUG,
1440 "Rejecting MAC `%s': not my MAC!\n",
1441 mac_to_string (addr));
1442 return GNUNET_NO; /* not my MAC */
1449 * Function called for a quick conversion of the binary address to
1450 * a numeric address. Note that the caller must not free the
1451 * address and that the next call to this function is allowed
1452 * to override the address again.
1454 * @param cls closure
1455 * @param addr binary address
1456 * @param addrlen length of the address
1457 * @return string representing the same address
1460 wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1462 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1464 if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != addrlen)
1470 return GNUNET_strdup (mac_to_string (mac));
1475 * Convert the transports address to a nice, human-readable format.
1477 * @param cls closure
1478 * @param type name of the transport that generated the address
1479 * @param addr one of the addresses of the host, NULL for the last address
1480 * the specific address format depends on the transport
1481 * @param addrlen length of the address
1482 * @param numeric should (IP) addresses be displayed in numeric form?
1483 * @param timeout after how long should we give up?
1484 * @param asc function to call on each string
1485 * @param asc_cls closure for asc
1488 wlan_plugin_address_pretty_printer (void *cls, const char *type,
1489 const void *addr, size_t addrlen,
1491 struct GNUNET_TIME_Relative timeout,
1492 GNUNET_TRANSPORT_AddressStringCallback asc,
1495 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1498 if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != addrlen)
1500 /* invalid address */
1501 LOG (GNUNET_ERROR_TYPE_WARNING,
1502 _("WLAN address with invalid size encountered\n"));
1503 asc (asc_cls, NULL);
1507 ret = GNUNET_strdup (mac_to_string (mac));
1510 asc (asc_cls, NULL);
1515 * Exit point from the plugin.
1517 * @param cls pointer to the api struct
1520 libgnunet_plugin_transport_wlan_done (void *cls)
1522 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1523 struct Plugin *plugin = api->cls;
1524 struct MacEndpoint *endpoint;
1525 struct MacEndpoint *endpoint_next;
1532 if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task)
1534 GNUNET_SCHEDULER_cancel (plugin->beacon_task);
1535 plugin->beacon_task = GNUNET_SCHEDULER_NO_TASK;
1537 if (NULL != plugin->suid_helper)
1539 GNUNET_HELPER_stop (plugin->suid_helper);
1540 plugin->suid_helper = NULL;
1542 endpoint_next = plugin->mac_head;
1543 while (NULL != (endpoint = endpoint_next))
1545 endpoint_next = endpoint->next;
1546 free_macendpoint (endpoint);
1548 if (NULL != plugin->fragment_data_tokenizer)
1550 GNUNET_SERVER_mst_destroy (plugin->fragment_data_tokenizer);
1551 plugin->fragment_data_tokenizer = NULL;
1553 if (NULL != plugin->wlan_header_payload_tokenizer)
1555 GNUNET_SERVER_mst_destroy (plugin->wlan_header_payload_tokenizer);
1556 plugin->wlan_header_payload_tokenizer = NULL;
1558 if (NULL != plugin->helper_payload_tokenizer)
1560 GNUNET_SERVER_mst_destroy (plugin->helper_payload_tokenizer);
1561 plugin->helper_payload_tokenizer = NULL;
1563 GNUNET_free_non_null (plugin->interface);
1564 GNUNET_free (plugin);
1571 * Function called to convert a string address to
1574 * @param cls closure ('struct Plugin*')
1575 * @param addr string address
1576 * @param addrlen length of the address
1577 * @param buf location to store the buffer
1578 * @param added location to store the number of bytes in the buffer.
1579 * If the function returns GNUNET_SYSERR, its contents are undefined.
1580 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1583 wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen,
1584 void **buf, size_t *added)
1586 struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1590 if ((NULL == addr) || (addrlen == 0))
1593 return GNUNET_SYSERR;
1595 if ('\0' != addr[addrlen - 1])
1598 return GNUNET_SYSERR;
1600 if (strlen (addr) != addrlen - 1)
1603 return GNUNET_SYSERR;
1605 if (6 != SSCANF (addr,
1606 "%X:%X:%X:%X:%X:%X",
1607 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
1610 return GNUNET_SYSERR;
1612 mac = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1616 *added = sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress);
1622 * Entry point for the plugin.
1624 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
1625 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
1628 libgnunet_plugin_transport_wlan_init (void *cls)
1630 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1631 struct GNUNET_TRANSPORT_PluginFunctions *api;
1632 struct Plugin *plugin;
1634 unsigned long long testmode;
1636 /* check for 'special' mode */
1637 if (NULL == env->receive)
1639 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1640 initialze the plugin or the API */
1641 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1643 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
1644 api->address_to_string = &wlan_plugin_address_to_string;
1645 api->string_to_address = &wlan_string_to_address;
1650 /* check configuration */
1652 GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE")) &&
1654 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
1655 "TESTMODE", &testmode)) ||
1658 LOG (GNUNET_ERROR_TYPE_ERROR,
1659 _("Invalid configuration option `%s' in section `%s'\n"),
1664 if ( (0 == testmode) &&
1665 (GNUNET_YES != GNUNET_OS_check_helper_binary ("gnunet-helper-transport-wlan")) )
1667 LOG (GNUNET_ERROR_TYPE_ERROR,
1668 _("Helper binary `%s' not SUID, cannot run WLAN transport\n"),
1669 "gnunet-helper-transport-wlan");
1673 GNUNET_CONFIGURATION_get_value_string
1674 (env->cfg, "transport-wlan", "INTERFACE",
1677 LOG (GNUNET_ERROR_TYPE_ERROR,
1678 _("Missing configuration option `%s' in section `%s'\n"),
1684 plugin = GNUNET_malloc (sizeof (struct Plugin));
1685 plugin->interface = interface;
1687 GNUNET_STATISTICS_set (plugin->env->stats, _("# WLAN sessions allocated"),
1689 GNUNET_STATISTICS_set (plugin->env->stats, _("# WLAN MAC endpoints allocated"),
1691 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
1692 GNUNET_BANDWIDTH_value_init (100 * 1024 *
1694 plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1695 plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1696 plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1697 plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon,
1701 case 0: /* normal */
1702 plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan";
1703 plugin->helper_argv[1] = interface;
1704 plugin->helper_argv[2] = NULL;
1705 plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan",
1706 plugin->helper_argv,
1707 &handle_helper_message,
1710 case 1: /* testmode, peer 1 */
1711 plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
1712 plugin->helper_argv[1] = (char *) "1";
1713 plugin->helper_argv[2] = NULL;
1714 plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan-dummy",
1715 plugin->helper_argv,
1716 &handle_helper_message,
1719 case 2: /* testmode, peer 2 */
1720 plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
1721 plugin->helper_argv[1] = (char *) "2";
1722 plugin->helper_argv[2] = NULL;
1723 plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan-dummy",
1724 plugin->helper_argv,
1725 &handle_helper_message,
1732 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1734 api->send = &wlan_plugin_send;
1735 api->get_session = &wlan_plugin_get_session;
1736 api->disconnect = &wlan_plugin_disconnect;
1737 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
1738 api->check_address = &wlan_plugin_address_suggested;
1739 api->address_to_string = &wlan_plugin_address_to_string;
1740 api->string_to_address = &wlan_string_to_address;
1745 /* end of plugin_transport_wlan.c */