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;
264 * Size of original message
269 * Number of bytes used to transmit message
277 * Struct to represent one network card connection
283 * We keep all MACs in a DLL in the plugin.
285 struct MacEndpoint *next;
288 * We keep all MACs in a DLL in the plugin.
290 struct MacEndpoint *prev;
293 * Pointer to the global plugin struct.
295 struct Plugin *plugin;
298 * Head of sessions that use this MAC.
300 struct Session *sessions_head;
303 * Tail of sessions that use this MAC.
305 struct Session *sessions_tail;
308 * Head of messages we are currently sending to this MAC.
310 struct FragmentMessage *sending_messages_head;
313 * Tail of messages we are currently sending to this MAC.
315 struct FragmentMessage *sending_messages_tail;
318 * Defrag context for this MAC
320 struct GNUNET_DEFRAGMENT_Context *defrag;
323 * When should this endpoint time out?
325 struct GNUNET_TIME_Absolute timeout;
330 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
333 * count of messages in the fragment out queue for this mac endpoint
335 unsigned int fragment_messages_out_count;
340 struct GNUNET_TRANSPORT_WLAN_MacAddress addr;
343 * Desired transmission power for this MAC
348 * Desired transmission rate for this MAC
353 * Antenna we should use for this MAC
361 * Encapsulation of all of the state of the plugin.
368 struct GNUNET_TRANSPORT_PluginEnvironment *env;
371 * Handle to helper process for priviledged operations.
373 struct GNUNET_HELPER_Handle *suid_helper;
376 * ARGV-vector for the helper (all helpers take only the binary
377 * name, one actual argument, plus the NULL terminator for 'argv').
379 char * helper_argv[3];
382 * The interface of the wlan card given to us by the user.
387 * Tokenizer for demultiplexing of data packets resulting from defragmentation.
389 struct GNUNET_SERVER_MessageStreamTokenizer *fragment_data_tokenizer;
392 * Tokenizer for demultiplexing of data packets received from the suid helper
394 struct GNUNET_SERVER_MessageStreamTokenizer *helper_payload_tokenizer;
397 * Tokenizer for demultiplexing of data packets that follow the WLAN Header
399 struct GNUNET_SERVER_MessageStreamTokenizer *wlan_header_payload_tokenizer;
402 * Head of list of open connections.
404 struct MacEndpoint *mac_head;
407 * Tail of list of open connections.
409 struct MacEndpoint *mac_tail;
412 * Number of connections
414 unsigned int mac_count;
417 * Task that periodically sends a HELLO beacon via the helper.
419 GNUNET_SCHEDULER_TaskIdentifier beacon_task;
422 * Tracker for bandwidth limit
424 struct GNUNET_BANDWIDTH_Tracker tracker;
427 * The mac_address of the wlan card given to us by the helper.
429 struct GNUNET_TRANSPORT_WLAN_MacAddress mac_address;
432 * Have we received a control message with our MAC address yet?
441 * Information associated with a message. Can contain
442 * the session or the MAC endpoint associated with the
448 * NULL if the identity of the other peer is not known.
450 struct Session *session;
453 * MAC address of the other peer, NULL if not known.
455 struct MacEndpoint *endpoint;
460 * Print MAC addresses nicely.
462 * @param mac the mac address
463 * @return string to a static buffer with the human-readable mac, will be overwritten during the next call to this function
466 mac_to_string (const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac)
468 static char macstr[20];
470 GNUNET_snprintf (macstr, sizeof (macstr), "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac->mac[0], mac->mac[1],
471 mac->mac[2], mac->mac[3], mac->mac[4], mac->mac[5]);
477 * Fill the radiotap header
479 * @param endpoint pointer to the endpoint, can be NULL
480 * @param header pointer to the radiotap header
481 * @param size total message size
484 get_radiotap_header (struct MacEndpoint *endpoint,
485 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
488 header->header.type = ntohs (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER);
489 header->header.size = ntohs (size);
490 if (NULL != endpoint)
492 header->rate = endpoint->rate;
493 header->tx_power = endpoint->tx_power;
494 header->antenna = endpoint->antenna;
499 header->tx_power = 0;
506 * Generate the WLAN hardware header for one packet
508 * @param plugin the plugin handle
509 * @param header address to write the header to
510 * @param to_mac_addr address of the recipient
511 * @param size size of the whole packet, needed to calculate the time to send the packet
514 get_wlan_header (struct Plugin *plugin,
515 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *header,
516 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
519 const int rate = 11000000;
521 header->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
522 header->addr1 = *to_mac_addr;
523 header->addr2 = plugin->mac_address;
524 header->addr3 = mac_bssid_gnunet;
525 header->duration = GNUNET_htole16 ((size * 1000000) / rate + 290);
526 header->sequence_control = 0; // FIXME?
527 header->llc[0] = WLAN_LLC_DSAP_FIELD;
528 header->llc[1] = WLAN_LLC_SSAP_FIELD;
529 header->llc[2] = 0; // FIXME?
530 header->llc[3] = 0; // FIXME?
535 * Send an ACK for a fragment we received.
537 * @param cls the 'struct MacEndpoint' the ACK must be sent to
538 * @param msg_id id of the message
539 * @param hdr pointer to the hdr where the ack is stored
542 send_ack (void *cls, uint32_t msg_id,
543 const struct GNUNET_MessageHeader *hdr)
545 struct MacEndpoint *endpoint = cls;
546 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage* radio_header;
547 uint16_t msize = ntohs (hdr->size);
548 size_t size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
551 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
556 LOG (GNUNET_ERROR_TYPE_DEBUG,
557 "Sending ACK to helper\n");
558 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
559 get_radiotap_header (endpoint, radio_header, size);
560 get_wlan_header (endpoint->plugin,
561 &radio_header->frame,
564 memcpy (&radio_header[1], hdr, msize);
566 GNUNET_HELPER_send (endpoint->plugin->suid_helper,
567 &radio_header->header,
568 GNUNET_NO /* dropping ACKs is bad */,
570 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN ACKs sent"),
576 * Handles the data after all fragments are put together
578 * @param cls macendpoint this messages belongs to
579 * @param hdr pointer to the data
582 wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
584 struct MacEndpoint *endpoint = cls;
585 struct Plugin *plugin = endpoint->plugin;
586 struct MacAndSession mas;
588 GNUNET_STATISTICS_update (plugin->env->stats,
589 _("# WLAN messages defragmented"), 1,
592 mas.endpoint = endpoint;
593 (void) GNUNET_SERVER_mst_receive (plugin->fragment_data_tokenizer,
597 GNUNET_YES, GNUNET_NO);
604 * @param session the session free
607 free_session (struct Session *session)
609 struct MacEndpoint *endpoint = session->mac;
610 struct PendingMessage *pm;
612 endpoint->plugin->env->session_end (endpoint->plugin->env->cls,
615 while (NULL != (pm = session->pending_message_head))
617 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
618 session->pending_message_tail, pm);
619 if (GNUNET_SCHEDULER_NO_TASK != pm->timeout_task)
621 GNUNET_SCHEDULER_cancel (pm->timeout_task);
622 pm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
624 GNUNET_free (pm->msg);
627 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head,
628 endpoint->sessions_tail,
630 if (session->timeout_task != GNUNET_SCHEDULER_NO_TASK)
632 GNUNET_SCHEDULER_cancel (session->timeout_task);
633 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
635 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), -1,
637 GNUNET_free (session);
642 * A session is timing out. Clean up.
644 * @param cls pointer to the Session
645 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
648 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
650 struct Session * session = cls;
651 struct GNUNET_TIME_Relative timeout;
653 session->timeout_task = GNUNET_SCHEDULER_NO_TASK;
654 timeout = GNUNET_TIME_absolute_get_remaining (session->timeout);
655 if (0 == timeout.rel_value)
657 free_session (session);
660 session->timeout_task =
661 GNUNET_SCHEDULER_add_delayed (timeout, &session_timeout, session);
666 * Create a new session
668 * @param endpoint pointer to the mac endpoint of the peer
669 * @param peer peer identity to use for this session
670 * @return returns the session
672 static struct Session *
673 create_session (struct MacEndpoint *endpoint,
674 const struct GNUNET_PeerIdentity *peer)
676 struct Session *session;
678 for (session = endpoint->sessions_head; NULL != session; session = session->next)
679 if (0 == memcmp (peer, &session->target,
680 sizeof (struct GNUNET_PeerIdentity)))
682 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
685 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), 1,
687 session = GNUNET_malloc (sizeof (struct Session));
688 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
689 endpoint->sessions_tail,
691 session->mac = endpoint;
692 session->target = *peer;
693 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
694 session->timeout_task =
695 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session);
696 LOG (GNUNET_ERROR_TYPE_DEBUG,
697 "Created new session for peer `%s' with endpoint %s\n",
699 mac_to_string (&endpoint->addr));
705 * Function called once we have successfully given the fragment
706 * message to the SUID helper process and we are thus ready for
709 * @param cls the 'struct FragmentMessage'
710 * @param result result of the operation (GNUNET_OK on success, GNUNET_NO if the helper died, GNUNET_SYSERR
711 * if the helper was stopped)
714 fragment_transmission_done (void *cls,
717 struct FragmentMessage *fm = cls;
721 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
726 * Transmit a fragment of a message.
728 * @param cls 'struct FragmentMessage' this fragment message belongs to
729 * @param hdr pointer to the start of the fragment message
732 transmit_fragment (void *cls,
733 const struct GNUNET_MessageHeader *hdr)
735 struct FragmentMessage *fm = cls;
736 struct MacEndpoint *endpoint = fm->macendpoint;
740 msize = ntohs (hdr->size);
741 size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
744 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radio_header;
746 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf;
747 get_radiotap_header (endpoint, radio_header, size);
748 get_wlan_header (endpoint->plugin,
749 &radio_header->frame,
752 memcpy (&radio_header[1], hdr, msize);
753 GNUNET_assert (NULL == fm->sh);
754 fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper,
755 &radio_header->header,
757 &fragment_transmission_done, fm);
758 fm->size_on_wire += size;
760 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN message fragments sent"),
763 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
764 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
765 "# bytes currently in WLAN buffers",
767 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
768 "# bytes transmitted via WLAN",
775 * Frees the space of a message in the fragment queue (send queue)
777 * @param fm message to free
780 free_fragment_message (struct FragmentMessage *fm)
782 struct MacEndpoint *endpoint = fm->macendpoint;
784 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN messages pending (with fragmentation)"),
786 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
787 endpoint->sending_messages_tail, fm);
790 GNUNET_HELPER_send_cancel (fm->sh);
793 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
794 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
796 GNUNET_SCHEDULER_cancel (fm->timeout_task);
797 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
804 * A FragmentMessage has timed out. Remove it.
806 * @param cls pointer to the 'struct FragmentMessage'
807 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
810 fragmentmessage_timeout (void *cls,
811 const struct GNUNET_SCHEDULER_TaskContext *tc)
813 struct FragmentMessage *fm = cls;
815 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
816 if (NULL != fm->cont)
818 fm->cont (fm->cont_cls, &fm->target, GNUNET_SYSERR, fm->size_payload, fm->size_on_wire);
821 free_fragment_message (fm);
826 * Transmit a message to the given destination with fragmentation.
828 * @param endpoint desired destination
829 * @param timeout how long can the message wait?
830 * @param target peer that should receive the message
831 * @param msg message to transmit
832 * @param payload_size bytes of payload
833 * @param cont continuation to call once the message has
834 * been transmitted (or if the transport is ready
835 * for the next transmission call; or if the
836 * peer disconnected...); can be NULL
837 * @param cont_cls closure for cont
840 send_with_fragmentation (struct MacEndpoint *endpoint,
841 struct GNUNET_TIME_Relative timeout,
842 const struct GNUNET_PeerIdentity *target,
843 const struct GNUNET_MessageHeader *msg,
845 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
848 struct FragmentMessage *fm;
849 struct Plugin *plugin;
851 plugin = endpoint->plugin;
852 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
853 fm->macendpoint = endpoint;
854 fm->target = *target;
855 fm->size_payload = payload_size;
856 fm->size_on_wire = 0;
857 fm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
859 fm->cont_cls = cont_cls;
861 GNUNET_FRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
863 GNUNET_TIME_UNIT_SECONDS,
865 &transmit_fragment, fm);
867 GNUNET_SCHEDULER_add_delayed (timeout,
868 &fragmentmessage_timeout, fm);
869 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sending_messages_head,
870 endpoint->sending_messages_tail,
876 * Free a MAC endpoint.
878 * @param endpoint pointer to the MacEndpoint to free
881 free_macendpoint (struct MacEndpoint *endpoint)
883 struct Plugin *plugin = endpoint->plugin;
884 struct FragmentMessage *fm;
885 struct Session *session;
887 GNUNET_STATISTICS_update (plugin->env->stats,
888 _("# WLAN MAC endpoints allocated"), -1, GNUNET_NO);
889 while (NULL != (session = endpoint->sessions_head))
890 free_session (session);
891 while (NULL != (fm = endpoint->sending_messages_head))
892 free_fragment_message (fm);
893 GNUNET_CONTAINER_DLL_remove (plugin->mac_head,
897 if (NULL != endpoint->defrag)
899 GNUNET_DEFRAGMENT_context_destroy(endpoint->defrag);
900 endpoint->defrag = NULL;
904 if (GNUNET_SCHEDULER_NO_TASK != endpoint->timeout_task)
906 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
907 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
909 GNUNET_free (endpoint);
914 * A MAC endpoint is timing out. Clean up.
916 * @param cls pointer to the MacEndpoint
917 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
920 macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
922 struct MacEndpoint *endpoint = cls;
923 struct GNUNET_TIME_Relative timeout;
925 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
926 timeout = GNUNET_TIME_absolute_get_remaining (endpoint->timeout);
927 if (0 == timeout.rel_value)
929 free_macendpoint (endpoint);
932 endpoint->timeout_task =
933 GNUNET_SCHEDULER_add_delayed (timeout, &macendpoint_timeout,
939 * Find (or create) a MacEndpoint with a specific MAC address
941 * @param plugin pointer to the plugin struct
942 * @param addr the MAC address of the endpoint
943 * @return handle to our data structure for this MAC
945 static struct MacEndpoint *
946 create_macendpoint (struct Plugin *plugin,
947 const struct GNUNET_TRANSPORT_WLAN_MacAddress *addr)
949 struct MacEndpoint *pos;
951 for (pos = plugin->mac_head; NULL != pos; pos = pos->next)
952 if (0 == memcmp (addr, &pos->addr, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
954 pos = GNUNET_malloc (sizeof (struct MacEndpoint));
956 pos->plugin = plugin;
958 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
959 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
961 &wlan_data_message_handler,
963 pos->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
965 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout,
967 GNUNET_CONTAINER_DLL_insert (plugin->mac_head, plugin->mac_tail, pos);
969 GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"),
971 LOG (GNUNET_ERROR_TYPE_DEBUG,
972 "New MAC endpoint `%s'\n",
973 mac_to_string (addr));
979 * Creates a new outbound session the transport service will use to send data to the
982 * @param cls the plugin
983 * @param address the address
984 * @return the session or NULL of max connections exceeded
986 static struct Session *
987 wlan_plugin_get_session (void *cls,
988 const struct GNUNET_HELLO_Address *address)
990 struct Plugin *plugin = cls;
991 struct MacEndpoint *endpoint;
995 if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != address->address_length)
1000 LOG (GNUNET_ERROR_TYPE_DEBUG,
1001 "Service asked to create session for peer `%s' with MAC `%s'\n",
1002 GNUNET_i2s (&address->peer),
1003 mac_to_string (address->address));
1004 endpoint = create_macendpoint (plugin, address->address);
1005 return create_session (endpoint, &address->peer);
1010 * Function that can be used to force the plugin to disconnect
1011 * from the given peer and cancel all previous transmissions
1012 * (and their continuation).
1014 * @param cls closure
1015 * @param target peer from which to disconnect
1018 wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
1020 struct Plugin *plugin = cls;
1021 struct Session *session;
1022 struct MacEndpoint *endpoint;
1024 for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
1025 for (session = endpoint->sessions_head; NULL != session; session = session->next)
1026 if (0 == memcmp (target, &session->target,
1027 sizeof (struct GNUNET_PeerIdentity)))
1029 free_session (session);
1030 break; /* inner-loop only (in case peer has another MAC as well!) */
1036 * Function that can be used by the transport service to transmit
1037 * a message using the plugin. Note that in the case of a
1038 * peer disconnecting, the continuation MUST be called
1039 * prior to the disconnect notification itself. This function
1040 * will be called with this peer's HELLO message to initiate
1041 * a fresh connection to another peer.
1043 * @param cls closure
1044 * @param session which session must be used
1045 * @param msgbuf the message to transmit
1046 * @param msgbuf_size number of bytes in 'msgbuf'
1047 * @param priority how important is the message (most plugins will
1048 * ignore message priority and just FIFO)
1049 * @param to how long to wait at most for the transmission (does not
1050 * require plugins to discard the message after the timeout,
1051 * just advisory for the desired delay; most plugins will ignore
1053 * @param cont continuation to call once the message has
1054 * been transmitted (or if the transport is ready
1055 * for the next transmission call; or if the
1056 * peer disconnected...); can be NULL
1057 * @param cont_cls closure for cont
1058 * @return number of bytes used (on the physical network, with overheads);
1059 * -1 on hard errors (i.e. address invalid); 0 is a legal value
1060 * and does NOT mean that the message was not transmitted (DV)
1063 wlan_plugin_send (void *cls,
1064 struct Session *session,
1065 const char *msgbuf, size_t msgbuf_size,
1066 unsigned int priority,
1067 struct GNUNET_TIME_Relative to,
1068 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1070 struct Plugin *plugin = cls;
1071 struct WlanHeader *wlanheader;
1072 size_t size = msgbuf_size + sizeof (struct WlanHeader);
1073 char buf[size] GNUNET_ALIGN;
1075 LOG (GNUNET_ERROR_TYPE_DEBUG,
1076 "Transmitting %u bytes of payload to peer `%s' (starting with %u byte message of type %u)\n",
1078 GNUNET_i2s (&session->target),
1079 (unsigned int) ntohs (((struct GNUNET_MessageHeader*)msgbuf)->size),
1080 (unsigned int) ntohs (((struct GNUNET_MessageHeader*)msgbuf)->type));
1081 wlanheader = (struct WlanHeader *) buf;
1082 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
1083 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
1084 wlanheader->sender = *plugin->env->my_identity;
1085 wlanheader->target = session->target;
1086 wlanheader->crc = htonl (GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size));
1087 memcpy (&wlanheader[1], msgbuf, msgbuf_size);
1089 GNUNET_STATISTICS_update (plugin->env->stats,
1090 "# bytes currently in WLAN buffers",
1091 msgbuf_size, GNUNET_NO);
1093 send_with_fragmentation (session->mac,
1096 &wlanheader->header,
1104 * We have received data from the WLAN via some session. Process depending
1105 * on the message type (HELLO, DATA, FRAGMENTATION or FRAGMENTATION-ACK).
1107 * @param cls pointer to the plugin
1108 * @param client pointer to the session this message belongs to
1109 * @param hdr start of the message
1112 process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1114 struct Plugin *plugin = cls;
1115 struct MacAndSession *mas = client;
1116 struct MacAndSession xmas;
1118 struct GNUNET_ATS_Information ats[NUM_ATS]; /* FIXME: do better here */
1119 struct FragmentMessage *fm;
1120 struct GNUNET_PeerIdentity tmpsource;
1121 const struct WlanHeader *wlanheader;
1125 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
1126 ats[0].value = htonl (1);
1127 ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1128 ats[1].value = htonl (GNUNET_ATS_NET_WLAN);
1129 msize = ntohs (hdr->size);
1131 GNUNET_STATISTICS_update (plugin->env->stats,
1132 "# bytes received via WLAN",
1135 switch (ntohs (hdr->type))
1137 case GNUNET_MESSAGE_TYPE_HELLO:
1139 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource))
1141 GNUNET_break_op (0);
1144 LOG (GNUNET_ERROR_TYPE_DEBUG,
1145 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n",
1146 (unsigned int) msize,
1147 GNUNET_i2s (&tmpsource),
1148 mac_to_string (&mas->endpoint->addr));
1150 GNUNET_STATISTICS_update (plugin->env->stats,
1151 _("# HELLO messages received via WLAN"), 1,
1153 plugin->env->receive (plugin->env->cls,
1158 (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr,
1159 (mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1161 case GNUNET_MESSAGE_TYPE_FRAGMENT:
1162 if (NULL == mas->endpoint)
1167 LOG (GNUNET_ERROR_TYPE_DEBUG,
1168 "Processing %u bytes of FRAGMENT from MAC %s\n",
1169 (unsigned int) msize,
1170 mac_to_string (&mas->endpoint->addr));
1171 GNUNET_STATISTICS_update (plugin->env->stats,
1172 _("# fragments received via WLAN"), 1, GNUNET_NO);
1173 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag,
1176 case GNUNET_MESSAGE_TYPE_FRAGMENT_ACK:
1177 if (NULL == mas->endpoint)
1182 GNUNET_STATISTICS_update (plugin->env->stats, _("# ACKs received via WLAN"),
1184 for (fm = mas->endpoint->sending_messages_head; NULL != fm; fm = fm->next)
1186 ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
1187 if (GNUNET_OK == ret)
1189 LOG (GNUNET_ERROR_TYPE_DEBUG,
1190 "Got last ACK, finished message transmission to `%s' (%p)\n",
1191 mac_to_string (&mas->endpoint->addr),
1193 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
1194 if (NULL != fm->cont)
1196 fm->cont (fm->cont_cls, &fm->target, GNUNET_OK, fm->size_payload, fm->size_on_wire);
1199 free_fragment_message (fm);
1202 if (GNUNET_NO == ret)
1204 LOG (GNUNET_ERROR_TYPE_DEBUG,
1205 "Got an ACK, message transmission to `%s' not yet finished\n",
1206 mac_to_string (&mas->endpoint->addr));
1210 LOG (GNUNET_ERROR_TYPE_DEBUG,
1211 "ACK not matched against any active fragmentation with MAC `%s'\n",
1212 mac_to_string (&mas->endpoint->addr));
1214 case GNUNET_MESSAGE_TYPE_WLAN_DATA:
1215 if (NULL == mas->endpoint)
1220 if (msize < sizeof (struct WlanHeader))
1225 wlanheader = (const struct WlanHeader *) hdr;
1226 if (0 != memcmp (&wlanheader->target,
1227 plugin->env->my_identity,
1228 sizeof (struct GNUNET_PeerIdentity)))
1230 LOG (GNUNET_ERROR_TYPE_DEBUG,
1231 "WLAN data for `%s', not for me, ignoring\n",
1232 GNUNET_i2s (&wlanheader->target));
1235 if (ntohl (wlanheader->crc) !=
1236 GNUNET_CRYPTO_crc32_n (&wlanheader[1], msize - sizeof (struct WlanHeader)))
1238 GNUNET_STATISTICS_update (plugin->env->stats,
1239 _("# WLAN DATA messages discarded due to CRC32 error"), 1,
1243 xmas.endpoint = mas->endpoint;
1244 xmas.session = create_session (mas->endpoint, &wlanheader->sender);
1245 LOG (GNUNET_ERROR_TYPE_DEBUG,
1246 "Processing %u bytes of WLAN DATA from peer `%s'\n",
1247 (unsigned int) msize,
1248 GNUNET_i2s (&wlanheader->sender));
1249 (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer,
1251 (const char *) &wlanheader[1],
1252 msize - sizeof (struct WlanHeader),
1253 GNUNET_YES, GNUNET_NO);
1256 if (NULL == mas->endpoint)
1261 if (NULL == mas->session)
1266 LOG (GNUNET_ERROR_TYPE_DEBUG,
1267 "Received packet with %u bytes of type %u from peer %s\n",
1268 (unsigned int) msize,
1269 (unsigned int) ntohs (hdr->type),
1270 GNUNET_i2s (&mas->session->target));
1271 plugin->env->receive (plugin->env->cls,
1272 &mas->session->target,
1276 (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr,
1277 (mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1286 * Function used for to process the data from the suid process
1288 * @param cls the plugin handle
1289 * @param client client that send the data (not used)
1290 * @param hdr header of the GNUNET_MessageHeader
1293 handle_helper_message (void *cls, void *client,
1294 const struct GNUNET_MessageHeader *hdr)
1296 struct Plugin *plugin = cls;
1297 const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo;
1298 const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm;
1299 struct MacAndSession mas;
1302 msize = ntohs (hdr->size);
1303 switch (ntohs (hdr->type))
1305 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
1306 if (msize != sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
1311 cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *) hdr;
1312 if (GNUNET_YES == plugin->have_mac)
1314 if (0 == memcmp (&plugin->mac_address,
1316 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1317 break; /* no change */
1318 /* remove old address */
1319 plugin->env->notify_address (plugin->env->cls, GNUNET_NO,
1320 &plugin->mac_address,
1321 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress),
1324 plugin->mac_address = cm->mac;
1325 plugin->have_mac = GNUNET_YES;
1326 LOG (GNUNET_ERROR_TYPE_DEBUG,
1327 "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n",
1328 mac_to_string (&cm->mac),
1329 GNUNET_i2s (plugin->env->my_identity));
1330 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
1331 &plugin->mac_address,
1332 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress),
1335 case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER:
1336 LOG (GNUNET_ERROR_TYPE_DEBUG,
1337 "Got data message from helper with %u bytes\n",
1339 GNUNET_STATISTICS_update (plugin->env->stats,
1340 _("# DATA messages received via WLAN"), 1,
1342 if (msize < sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage))
1345 LOG (GNUNET_ERROR_TYPE_DEBUG,
1346 "Size of packet is too small (%u bytes)\n",
1350 rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) hdr;
1352 /* check if message is actually for us */
1353 if (0 != memcmp (&rxinfo->frame.addr3, &mac_bssid_gnunet,
1354 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1356 /* Not the GNUnet BSSID */
1359 if ( (0 != memcmp (&rxinfo->frame.addr1, &bc_all_mac,
1360 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))) &&
1361 (0 != memcmp (&rxinfo->frame.addr1, &plugin->mac_address,
1362 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))) )
1364 /* Neither broadcast nor specifically for us */
1367 if (0 == memcmp (&rxinfo->frame.addr2, &plugin->mac_address,
1368 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1370 /* packet is FROM us, thus not FOR us */
1374 GNUNET_STATISTICS_update (plugin->env->stats,
1375 _("# WLAN DATA messages processed"),
1377 LOG (GNUNET_ERROR_TYPE_DEBUG,
1378 "Receiving %u bytes of data from MAC `%s'\n",
1379 (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1380 mac_to_string (&rxinfo->frame.addr2));
1381 mas.endpoint = create_macendpoint (plugin, &rxinfo->frame.addr2);
1383 (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer,
1385 (const char*) &rxinfo[1],
1386 msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage),
1387 GNUNET_YES, GNUNET_NO);
1391 LOG (GNUNET_ERROR_TYPE_DEBUG,
1392 "Unexpected message of type %u (%u bytes)",
1393 ntohs (hdr->type), ntohs (hdr->size));
1402 * Task to (periodically) send a HELLO beacon
1404 * @param cls pointer to the plugin struct
1405 * @param tc scheduler context
1408 send_hello_beacon (void *cls,
1409 const struct GNUNET_SCHEDULER_TaskContext *tc)
1411 struct Plugin *plugin = cls;
1413 uint16_t hello_size;
1414 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader;
1415 const struct GNUNET_MessageHeader *hello;
1417 hello = plugin->env->get_our_hello ();
1418 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1419 GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU);
1420 size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size;
1422 char buf[size] GNUNET_ALIGN;
1424 LOG (GNUNET_ERROR_TYPE_DEBUG,
1425 "Sending %u byte HELLO beacon\n",
1426 (unsigned int) size);
1427 radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*) buf;
1428 get_radiotap_header (NULL, radioHeader, size);
1429 get_wlan_header (plugin, &radioHeader->frame, &bc_all_mac, size);
1430 memcpy (&radioHeader[1], hello, hello_size);
1432 GNUNET_HELPER_send (plugin->suid_helper,
1433 &radioHeader->header,
1434 GNUNET_YES /* can drop */,
1436 GNUNET_STATISTICS_update (plugin->env->stats, _("# HELLO beacons sent via WLAN"),
1439 plugin->beacon_task =
1440 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1441 (HELLO_BEACON_SCALING_FACTOR,
1442 plugin->mac_count + 1),
1450 * Another peer has suggested an address for this
1451 * peer and transport plugin. Check that this could be a valid
1452 * address. If so, consider adding it to the list
1455 * @param cls closure
1456 * @param addr pointer to the address
1457 * @param addrlen length of addr
1458 * @return GNUNET_OK if this is a plausible address for this peer
1462 wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
1464 struct Plugin *plugin = cls;
1466 if (addrlen != sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))
1468 GNUNET_break_op (0);
1469 return GNUNET_SYSERR;
1471 if (GNUNET_YES != plugin->have_mac)
1473 LOG (GNUNET_ERROR_TYPE_DEBUG,
1474 "Rejecting MAC `%s': I don't know my MAC!\n",
1475 mac_to_string (addr));
1476 return GNUNET_NO; /* don't know my MAC */
1478 if (0 != memcmp (addr,
1479 &plugin->mac_address,
1482 LOG (GNUNET_ERROR_TYPE_DEBUG,
1483 "Rejecting MAC `%s': not my MAC!\n",
1484 mac_to_string (addr));
1485 return GNUNET_NO; /* not my MAC */
1492 * Function called for a quick conversion of the binary address to
1493 * a numeric address. Note that the caller must not free the
1494 * address and that the next call to this function is allowed
1495 * to override the address again.
1497 * @param cls closure
1498 * @param addr binary address
1499 * @param addrlen length of the address
1500 * @return string representing the same address
1503 wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1505 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1507 if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != addrlen)
1513 return mac_to_string (mac);
1518 * Convert the transports address to a nice, human-readable format.
1520 * @param cls closure
1521 * @param type name of the transport that generated the address
1522 * @param addr one of the addresses of the host, NULL for the last address
1523 * the specific address format depends on the transport
1524 * @param addrlen length of the address
1525 * @param numeric should (IP) addresses be displayed in numeric form?
1526 * @param timeout after how long should we give up?
1527 * @param asc function to call on each string
1528 * @param asc_cls closure for asc
1531 wlan_plugin_address_pretty_printer (void *cls, const char *type,
1532 const void *addr, size_t addrlen,
1534 struct GNUNET_TIME_Relative timeout,
1535 GNUNET_TRANSPORT_AddressStringCallback asc,
1538 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1541 if (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress) != addrlen)
1543 /* invalid address */
1544 LOG (GNUNET_ERROR_TYPE_WARNING,
1545 _("WLAN address with invalid size encountered\n"));
1546 asc (asc_cls, NULL);
1550 ret = GNUNET_strdup (mac_to_string (mac));
1553 asc (asc_cls, NULL);
1558 * Exit point from the plugin.
1560 * @param cls pointer to the api struct
1563 libgnunet_plugin_transport_wlan_done (void *cls)
1565 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1566 struct Plugin *plugin = api->cls;
1567 struct MacEndpoint *endpoint;
1568 struct MacEndpoint *endpoint_next;
1576 if (GNUNET_YES == plugin->have_mac)
1578 plugin->env->notify_address (plugin->env->cls, GNUNET_NO,
1579 &plugin->mac_address,
1580 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress),
1582 plugin->have_mac = GNUNET_NO;
1585 if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task)
1587 GNUNET_SCHEDULER_cancel (plugin->beacon_task);
1588 plugin->beacon_task = GNUNET_SCHEDULER_NO_TASK;
1590 if (NULL != plugin->suid_helper)
1592 GNUNET_HELPER_stop (plugin->suid_helper);
1593 plugin->suid_helper = NULL;
1595 endpoint_next = plugin->mac_head;
1596 while (NULL != (endpoint = endpoint_next))
1598 endpoint_next = endpoint->next;
1599 free_macendpoint (endpoint);
1601 if (NULL != plugin->fragment_data_tokenizer)
1603 GNUNET_SERVER_mst_destroy (plugin->fragment_data_tokenizer);
1604 plugin->fragment_data_tokenizer = NULL;
1606 if (NULL != plugin->wlan_header_payload_tokenizer)
1608 GNUNET_SERVER_mst_destroy (plugin->wlan_header_payload_tokenizer);
1609 plugin->wlan_header_payload_tokenizer = NULL;
1611 if (NULL != plugin->helper_payload_tokenizer)
1613 GNUNET_SERVER_mst_destroy (plugin->helper_payload_tokenizer);
1614 plugin->helper_payload_tokenizer = NULL;
1616 GNUNET_free_non_null (plugin->interface);
1617 GNUNET_free (plugin);
1624 * Function called to convert a string address to
1627 * @param cls closure ('struct Plugin*')
1628 * @param addr string address
1629 * @param addrlen length of the address
1630 * @param buf location to store the buffer
1631 * @param added location to store the number of bytes in the buffer.
1632 * If the function returns GNUNET_SYSERR, its contents are undefined.
1633 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1636 wlan_string_to_address (void *cls, const char *addr, uint16_t addrlen,
1637 void **buf, size_t *added)
1639 struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
1643 if ((NULL == addr) || (addrlen == 0))
1646 return GNUNET_SYSERR;
1648 if ('\0' != addr[addrlen - 1])
1651 return GNUNET_SYSERR;
1653 if (strlen (addr) != addrlen - 1)
1656 return GNUNET_SYSERR;
1658 if (6 != SSCANF (addr,
1659 "%X:%X:%X:%X:%X:%X",
1660 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
1663 return GNUNET_SYSERR;
1665 mac = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
1669 *added = sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress);
1675 * Entry point for the plugin.
1677 * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*'
1678 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
1681 libgnunet_plugin_transport_wlan_init (void *cls)
1683 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1684 struct GNUNET_TRANSPORT_PluginFunctions *api;
1685 struct Plugin *plugin;
1687 unsigned long long testmode;
1689 /* check for 'special' mode */
1690 if (NULL == env->receive)
1692 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1693 initialze the plugin or the API */
1694 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1696 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
1697 api->address_to_string = &wlan_plugin_address_to_string;
1698 api->string_to_address = &wlan_string_to_address;
1703 /* check configuration */
1705 GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE")) &&
1707 GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-wlan",
1708 "TESTMODE", &testmode)) ||
1711 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1712 "transport-wlan", "TESTMODE");
1715 if ( (0 == testmode) &&
1716 (GNUNET_YES != GNUNET_OS_check_helper_binary ("gnunet-helper-transport-wlan")) )
1718 LOG (GNUNET_ERROR_TYPE_ERROR,
1719 _("Helper binary `%s' not SUID, cannot run WLAN transport\n"),
1720 "gnunet-helper-transport-wlan");
1724 GNUNET_CONFIGURATION_get_value_string
1725 (env->cfg, "transport-wlan", "INTERFACE",
1728 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1729 "transport-wlan", "INTERFACE");
1733 plugin = GNUNET_malloc (sizeof (struct Plugin));
1734 plugin->interface = interface;
1736 GNUNET_STATISTICS_set (plugin->env->stats, _("# WLAN sessions allocated"),
1738 GNUNET_STATISTICS_set (plugin->env->stats, _("# WLAN MAC endpoints allocated"),
1740 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
1741 GNUNET_BANDWIDTH_value_init (100 * 1024 *
1743 plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1744 plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1745 plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
1746 plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon,
1750 case 0: /* normal */
1751 plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan";
1752 plugin->helper_argv[1] = interface;
1753 plugin->helper_argv[2] = NULL;
1754 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
1755 "gnunet-helper-transport-wlan",
1756 plugin->helper_argv,
1757 &handle_helper_message,
1761 case 1: /* testmode, peer 1 */
1762 plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
1763 plugin->helper_argv[1] = (char *) "1";
1764 plugin->helper_argv[2] = NULL;
1765 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
1766 "gnunet-helper-transport-wlan-dummy",
1767 plugin->helper_argv,
1768 &handle_helper_message,
1772 case 2: /* testmode, peer 2 */
1773 plugin->helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy";
1774 plugin->helper_argv[1] = (char *) "2";
1775 plugin->helper_argv[2] = NULL;
1776 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO,
1777 "gnunet-helper-transport-wlan-dummy",
1778 plugin->helper_argv,
1779 &handle_helper_message,
1787 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1789 api->send = &wlan_plugin_send;
1790 api->get_session = &wlan_plugin_get_session;
1791 api->disconnect = &wlan_plugin_disconnect;
1792 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
1793 api->check_address = &wlan_plugin_address_suggested;
1794 api->address_to_string = &wlan_plugin_address_to_string;
1795 api->string_to_address = &wlan_string_to_address;
1800 /* end of plugin_transport_wlan.c */