GNUnet  0.10.x
plugin_transport_wlan.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2010-2014 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
30 #include "platform.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_hello_lib.h"
33 #include "gnunet_protocols.h"
37 #include "plugin_transport_wlan.h"
39 #include "gnunet_constants.h"
40 
41 
42 #if BUILD_WLAN
43 /* begin case wlan */
44 #define PLUGIN_NAME "wlan"
45 #define CONFIG_NAME "transport-wlan"
46 #define HELPER_NAME "gnunet-helper-transport-wlan"
47 #define DUMMY_HELPER_NAME "gnunet-helper-transport-wlan-dummy"
48 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_wlan_init
49 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_wlan_done
50 #define LOG(kind, ...) GNUNET_log_from(kind, "transport-wlan", __VA_ARGS__)
51 
52 
56 #define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2)
57 
63 #define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2)
64 
65 
66 /* end case wlan */
67 #elif BUILD_BLUETOOTH
68 /* begin case bluetooth */
69 
70 #define PLUGIN_NAME "bluetooth"
71 #define CONFIG_NAME "transport-bluetooth"
72 #define HELPER_NAME "gnunet-helper-transport-bluetooth"
73 /* yes, this is correct, we use the same dummy driver as 'wlan' */
74 #define DUMMY_HELPER_NAME "gnunet-helper-transport-wlan-dummy"
75 #define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_bluetooth_init
76 #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_bluetooth_done
77 #define LOG(kind, ...) GNUNET_log_from(kind, "transport-bluetooth", __VA_ARGS__)
78 
82 #define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 60)
83 
84 
90 #define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60)
91 
92 /* end case bluetooth */
93 #else
94 #error need to build wlan or bluetooth
95 #endif
96 
97 
98 
111 typedef int
113  void *client,
114  const struct GNUNET_MessageHeader *message);
115 
116 
117 /* Include legacy message stream tokenizer that was removed from util (for now) */
118 #include "tcp_server_mst_legacy.c"
119 
120 
124 #define WLAN_MTU 1430
125 
126 
130 #if BUILD_WLAN
131 static const enum GNUNET_NetworkType scope = GNUNET_NT_WLAN;
132 #else
133 static const enum GNUNET_NetworkType scope = GNUNET_NT_BT;
134 #endif
135 
136 
140 #define MESSAGES_IN_DEFRAG_QUEUE_PER_MAC 2
141 
146 #define WLAN_LLC_DSAP_FIELD 0x1f
147 #define WLAN_LLC_SSAP_FIELD 0x1f
148 
149 
157 struct WlanHeader {
162 
166  uint32_t crc GNUNET_PACKED;
167 
172 
177 
178  /* followed by payload, possibly including
179  multiple messages! */
180 };
181 
182 
186 struct WlanAddress {
191 
196 };
197 
198 
200 
201 
206 struct PendingMessage {
210  struct PendingMessage *next;
211 
215  struct PendingMessage *prev;
216 
220  struct WlanHeader *msg;
221 
228 
232  void *transmit_cont_cls;
233 
238 };
239 
240 
244 struct GNUNET_ATS_Session {
249  struct GNUNET_PeerIdentity target;
250 
255  struct GNUNET_ATS_Session *next;
256 
261  struct GNUNET_ATS_Session *prev;
262 
266  struct MacEndpoint *mac;
267 
272 
277 
282 };
283 
284 
293 
298 
303 
308 
314 
318  struct GNUNET_PeerIdentity target;
319 
324 
329 
334 
340 
344  void *cont_cls;
345 
349  size_t size_payload;
350 
354  size_t size_on_wire;
355 };
356 
357 
361 struct MacEndpoint {
365  struct MacEndpoint *next;
366 
370  struct MacEndpoint *prev;
371 
375  struct Plugin *plugin;
376 
381 
386 
391 
396 
401 
406 
411 
416 
420  struct WlanAddress wlan_addr;
421 
425  struct GNUNET_TIME_Relative msg_delay;
426 
430  struct GNUNET_TIME_Relative ack_delay;
431 
435  uint16_t tx_power;
436 
440  uint8_t rate;
441 
445  uint8_t antenna;
446 };
447 
448 
452 struct Plugin {
457 
462 
467 
471  void *sic_cls;
472 
477  char *helper_argv[3];
478 
483 
489 
494 
499 
504 
509 
514 
518  struct GNUNET_BANDWIDTH_Tracker tracker;
519 
524 
528  int have_mac;
529 
533  unsigned int mac_count;
534 
538  uint32_t options;
539 };
540 
541 
552 
557 };
558 
559 
568 static const char *
570 {
571  static char macstr[20];
572 
573  GNUNET_snprintf(macstr,
574  sizeof(macstr),
575  "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
576  mac->mac[0], mac->mac[1],
577  mac->mac[2], mac->mac[3],
578  mac->mac[4], mac->mac[5]);
579  return macstr;
580 }
581 
582 
594 static const char *
596  const void *addr,
597  size_t addrlen)
598 {
600  static char macstr[36];
601 
602  if (sizeof(struct WlanAddress) != addrlen)
603  {
604  GNUNET_break(0);
605  return NULL;
606  }
607  mac = &((struct WlanAddress *)addr)->mac;
608  GNUNET_snprintf(macstr,
609  sizeof(macstr),
610  "%s.%u.%s",
611  PLUGIN_NAME,
612  ntohl(((struct WlanAddress *)addr)->options),
613  mac_to_string(mac));
614  return macstr;
615 }
616 
617 
626 static void
628  struct GNUNET_ATS_Session *session,
630 {
631  struct GNUNET_TRANSPORT_SessionInfo info;
632 
633  if (NULL == plugin->sic)
634  return;
635  memset(&info, 0, sizeof(info));
636  info.state = state;
637  info.is_inbound = GNUNET_SYSERR; /* hard to say */
638  info.num_msg_pending = 0; /* we queue per MAC, not per peer */
639  info.num_bytes_pending = 0; /* we queue per MAC, not per peer */
640  info.receive_delay = GNUNET_TIME_UNIT_ZERO_ABS; /* not supported by WLAN */
641  info.session_timeout = session->timeout;
642  info.address = session->address;
643  plugin->sic(plugin->sic_cls,
644  session,
645  &info);
646 }
647 
648 
656 static void
659  uint16_t size)
660 {
662  header->header.size = ntohs(size);
663  if (NULL != endpoint)
664  {
665  header->rate = endpoint->rate;
666  header->tx_power = endpoint->tx_power;
667  header->antenna = endpoint->antenna;
668  }
669  else
670  {
671  header->rate = 255;
672  header->tx_power = 0;
673  header->antenna = 0;
674  }
675 }
676 
677 
686 static void
689  const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
690  unsigned int size)
691 {
692  const int rate = 11000000;
693 
694  header->frame_control = htons(IEEE80211_FC0_TYPE_DATA);
695  header->addr1 = *to_mac_addr;
696  header->addr2 = plugin->mac_address;
697  header->addr3 = mac_bssid_gnunet;
698  header->duration = GNUNET_htole16((size * 1000000) / rate + 290);
699  header->sequence_control = 0; // FIXME?
700  header->llc[0] = WLAN_LLC_DSAP_FIELD;
701  header->llc[1] = WLAN_LLC_SSAP_FIELD;
702  header->llc[2] = 0; // FIXME?
703  header->llc[3] = 0; // FIXME?
704 }
705 
706 
714 static void
715 send_ack(void *cls,
716  uint32_t msg_id,
717  const struct GNUNET_MessageHeader *hdr)
718 {
719  struct MacEndpoint *endpoint = cls;
720  struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage* radio_header;
721  uint16_t msize = ntohs(hdr->size);
722  size_t size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
723  char buf[size];
724 
725  if (NULL == endpoint)
726  {
727  GNUNET_break(0);
728  return;
729  }
730  if (size >= GNUNET_MAX_MESSAGE_SIZE)
731  {
732  GNUNET_break(0);
733  return;
734  }
736  "Sending ACK to %s\n",
737  mac_to_string(&endpoint->wlan_addr.mac));
738  radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)buf;
739  get_radiotap_header(endpoint, radio_header, size);
740  get_wlan_header(endpoint->plugin,
741  &radio_header->frame,
742  &endpoint->wlan_addr.mac,
743  sizeof(endpoint->wlan_addr.mac));
744  GNUNET_memcpy(&radio_header[1], hdr, msize);
745  if (NULL !=
747  &radio_header->header,
748  GNUNET_NO /* dropping ACKs is bad */,
749  NULL, NULL))
750  GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
751  _("# ACKs sent"),
752  1, GNUNET_NO);
753 }
754 
755 
762 static void
764  const struct GNUNET_MessageHeader *hdr)
765 {
766  struct MacEndpoint *endpoint = cls;
767  struct Plugin *plugin = endpoint->plugin;
768  struct MacAndSession mas;
769 
770  GNUNET_STATISTICS_update(plugin->env->stats,
771  _("# Messages defragmented"),
772  1,
773  GNUNET_NO);
774  mas.session = NULL;
775  mas.endpoint = endpoint;
777  &mas,
778  (const char *)hdr,
779  ntohs(hdr->size),
781 }
782 
783 
790 static int
792  struct GNUNET_ATS_Session *session)
793 {
794  struct MacEndpoint *endpoint = session->mac;
795  struct Plugin *plugin = endpoint->plugin;
796 
797  plugin->env->session_end(plugin->env->cls,
798  session->address,
799  session);
800  notify_session_monitor(plugin,
801  session,
804  endpoint->sessions_tail,
805  session);
806  if (session->timeout_task != NULL)
807  {
809  session->timeout_task = NULL;
810  }
811  GNUNET_STATISTICS_update(plugin->env->stats,
812  _("# Sessions allocated"),
813  -1,
814  GNUNET_NO);
816  GNUNET_free(session);
817  return GNUNET_OK;
818 }
819 
820 
829 static unsigned int
831 {
832  return 3;
833 }
834 
835 
841 static void
842 session_timeout(void *cls)
843 {
844  struct GNUNET_ATS_Session *session = cls;
845  struct GNUNET_TIME_Relative left;
846 
847  session->timeout_task = NULL;
849  if (0 != left.rel_value_us)
850  {
851  session->timeout_task =
854  session);
855  return;
856  }
858  session);
859 }
860 
861 
862 
870 static struct GNUNET_ATS_Session *
871 lookup_session(struct MacEndpoint *endpoint,
872  const struct GNUNET_PeerIdentity *peer)
873 {
874  struct GNUNET_ATS_Session *session;
875 
876  for (session = endpoint->sessions_head; NULL != session; session = session->next)
877  if (0 == memcmp(peer, &session->target, sizeof(struct GNUNET_PeerIdentity)))
878  return session;
879  return NULL;
880 }
881 
882 
890 static struct GNUNET_ATS_Session *
891 create_session(struct MacEndpoint *endpoint,
892  const struct GNUNET_PeerIdentity *peer)
893 {
894  struct GNUNET_ATS_Session *session;
895 
896  GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
897  _("# Sessions allocated"),
898  1,
899  GNUNET_NO);
900  session = GNUNET_new(struct GNUNET_ATS_Session);
902  endpoint->sessions_tail,
903  session);
904  session->address = GNUNET_HELLO_address_allocate(peer,
905  PLUGIN_NAME,
906  &endpoint->wlan_addr,
907  sizeof(endpoint->wlan_addr),
909  session->mac = endpoint;
910  session->target = *peer;
912  session->timeout_task =
914  session);
915  notify_session_monitor(endpoint->plugin,
916  session,
918  notify_session_monitor(endpoint->plugin,
919  session,
922  "Created new session %p for peer `%s' with endpoint %s\n",
923  session,
924  GNUNET_i2s(peer),
925  mac_to_string(&endpoint->wlan_addr.mac));
926 
927  return session;
928 }
929 
930 
938 static struct GNUNET_ATS_Session *
939 get_session(struct MacEndpoint *endpoint,
940  const struct GNUNET_PeerIdentity *peer)
941 {
942  struct GNUNET_ATS_Session *session;
943 
944  if (NULL != (session = lookup_session(endpoint, peer)))
945  return session;
946  return create_session(endpoint, peer);
947 }
948 
949 
960 static void
962  int result)
963 {
964  struct FragmentMessage *fm = cls;
965 
966  fm->sh = NULL;
968 }
969 
970 
977 static void
979  const struct GNUNET_MessageHeader *hdr)
980 {
981  struct FragmentMessage *fm = cls;
982  struct MacEndpoint *endpoint = fm->macendpoint;
983  size_t size;
984  uint16_t msize;
985 
986  if (NULL == endpoint)
987  {
988  GNUNET_break(0);
989  return;
990  }
991  msize = ntohs(hdr->size);
992  size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
993  {
994  char buf[size];
995  struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radio_header;
996 
997  radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)buf;
998  get_radiotap_header(endpoint, radio_header, size);
1000  "Sending %u bytes of data to MAC `%s'\n",
1001  (unsigned int)msize,
1002  mac_to_string(&endpoint->wlan_addr.mac));
1003 
1004  get_wlan_header(endpoint->plugin,
1005  &radio_header->frame,
1006  &endpoint->wlan_addr.mac,
1007  sizeof(endpoint->wlan_addr.mac));
1008  GNUNET_memcpy(&radio_header[1], hdr, msize);
1009  GNUNET_assert(NULL == fm->sh);
1010  fm->sh = GNUNET_HELPER_send(endpoint->plugin->suid_helper,
1011  &radio_header->header,
1012  GNUNET_NO,
1014  fm->size_on_wire += size;
1015  if (NULL != fm->sh)
1016  {
1017  GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
1018  _("# message fragments sent"),
1019  1,
1020  GNUNET_NO);
1021  }
1022  else
1023  {
1025  }
1026  GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
1027  "# bytes currently in buffers",
1028  -msize, GNUNET_NO);
1029  GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
1030  "# bytes transmitted",
1031  msize, GNUNET_NO);
1032  }
1033 }
1034 
1035 
1041 static void
1043 {
1044  struct MacEndpoint *endpoint = fm->macendpoint;
1045 
1046  GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
1047  _("# messages pending (with fragmentation)"),
1048  -1, GNUNET_NO);
1050  endpoint->sending_messages_tail,
1051  fm);
1052  if (NULL != fm->sh)
1053  {
1055  fm->sh = NULL;
1056  }
1057  if (NULL != fm->msg)
1058  {
1059  GNUNET_free(fm->msg);
1060  fm->msg = NULL;
1061  }
1062  if (NULL != fm->fragcontext)
1063  {
1065  &endpoint->msg_delay,
1066  &endpoint->ack_delay);
1067  fm->fragcontext = NULL;
1068  }
1069  if (NULL != fm->timeout_task)
1070  {
1072  fm->timeout_task = NULL;
1073  }
1074  GNUNET_free(fm);
1075 }
1076 
1077 
1083 static void
1085 {
1086  struct FragmentMessage *fm = cls;
1087 
1088  fm->timeout_task = NULL;
1089  if (NULL != fm->cont)
1090  {
1091  fm->cont(fm->cont_cls,
1092  &fm->target,
1093  GNUNET_SYSERR,
1094  fm->size_payload,
1095  fm->size_on_wire);
1096  fm->cont = NULL;
1097  }
1099 }
1100 
1101 
1116 static void
1119  const struct GNUNET_PeerIdentity *target,
1120  const struct GNUNET_MessageHeader *msg,
1121  size_t payload_size,
1123  void *cont_cls)
1124 
1125 {
1126  struct FragmentMessage *fm;
1127  struct Plugin *plugin;
1128 
1129  plugin = endpoint->plugin;
1130  fm = GNUNET_new(struct FragmentMessage);
1131  fm->macendpoint = endpoint;
1132  fm->target = *target;
1133  fm->size_payload = payload_size;
1135  fm->cont = cont;
1136  fm->cont_cls = cont_cls;
1137  /* 1 MBit/s typical data rate, 1430 byte fragments => ~100 ms per message */
1138  fm->timeout_task =
1141  fm);
1142  if (GNUNET_YES == plugin->have_mac)
1143  {
1144  fm->fragcontext =
1145  GNUNET_FRAGMENT_context_create(plugin->env->stats,
1146  WLAN_MTU,
1147  &plugin->tracker,
1148  fm->macendpoint->msg_delay,
1149  fm->macendpoint->ack_delay,
1150  msg,
1151  &transmit_fragment, fm);
1152  }
1153  else
1154  {
1155  fm->msg = GNUNET_copy_message(msg);
1156  }
1158  endpoint->sending_messages_tail,
1159  fm);
1160 }
1161 
1162 
1168 static void
1170 {
1171  struct Plugin *plugin = endpoint->plugin;
1172  struct FragmentMessage *fm;
1173  struct GNUNET_ATS_Session *session;
1174 
1175  GNUNET_STATISTICS_update(plugin->env->stats,
1176  _("# MAC endpoints allocated"),
1177  -1,
1178  GNUNET_NO);
1179  while (NULL != (session = endpoint->sessions_head))
1181  session);
1182  while (NULL != (fm = endpoint->sending_messages_head))
1185  plugin->mac_tail,
1186  endpoint);
1187 
1188  if (NULL != endpoint->defrag)
1189  {
1191  endpoint->defrag = NULL;
1192  }
1193 
1194  plugin->mac_count--;
1195  if (NULL != endpoint->timeout_task)
1196  {
1198  endpoint->timeout_task = NULL;
1199  }
1200  GNUNET_free(endpoint);
1201 }
1202 
1203 
1209 static void
1211 {
1212  struct MacEndpoint *endpoint = cls;
1213  struct GNUNET_TIME_Relative timeout;
1214 
1215  endpoint->timeout_task = NULL;
1216  timeout = GNUNET_TIME_absolute_get_remaining(endpoint->timeout);
1217  if (0 == timeout.rel_value_us)
1218  {
1219  free_macendpoint(endpoint);
1220  return;
1221  }
1222  endpoint->timeout_task =
1225  endpoint);
1226 }
1227 
1228 
1236 static struct MacEndpoint *
1238  struct WlanAddress *mac)
1239 {
1240  struct MacEndpoint *pos;
1241 
1242  for (pos = plugin->mac_head; NULL != pos; pos = pos->next)
1243  if (0 == memcmp(mac, &pos->wlan_addr, sizeof(pos->wlan_addr)))
1244  return pos;
1245  pos = GNUNET_new(struct MacEndpoint);
1246  pos->wlan_addr = (*mac);
1247  pos->plugin = plugin;
1248  pos->defrag =
1249  GNUNET_DEFRAGMENT_context_create(plugin->env->stats,
1250  WLAN_MTU,
1252  pos,
1254  &send_ack);
1255 
1258  pos->timeout = GNUNET_TIME_relative_to_absolute(MACENDPOINT_TIMEOUT);
1259  pos->timeout_task =
1260  GNUNET_SCHEDULER_add_delayed(MACENDPOINT_TIMEOUT, &macendpoint_timeout,
1261  pos);
1263  plugin->mac_tail,
1264  pos);
1265  plugin->mac_count++;
1266  GNUNET_STATISTICS_update(plugin->env->stats,
1267  _("# MAC endpoints allocated"),
1268  1, GNUNET_NO);
1270  "New MAC endpoint `%s'\n",
1272  &pos->wlan_addr,
1273  sizeof(struct WlanAddress)));
1274  return pos;
1275 }
1276 
1277 
1285 static enum GNUNET_NetworkType
1287  struct GNUNET_ATS_Session *session)
1288 {
1289 #if BUILD_WLAN
1290  return GNUNET_NT_WLAN;
1291 #else
1292  return GNUNET_NT_BT;
1293 #endif
1294 }
1295 
1296 
1304 static enum GNUNET_NetworkType
1306  const struct GNUNET_HELLO_Address *address)
1307 {
1308 #if BUILD_WLAN
1309  return GNUNET_NT_WLAN;
1310 #else
1311  return GNUNET_NT_BT;
1312 #endif
1313 }
1314 
1315 
1324 static struct GNUNET_ATS_Session *
1326  const struct GNUNET_HELLO_Address *address)
1327 {
1328  struct Plugin *plugin = cls;
1329  struct MacEndpoint *endpoint;
1330 
1331  if (NULL == address)
1332  return NULL;
1333  if (sizeof(struct WlanAddress) != address->address_length)
1334  {
1335  GNUNET_break(0);
1336  return NULL;
1337  }
1339  "Service asked to create session for peer `%s' with MAC `%s'\n",
1340  GNUNET_i2s(&address->peer),
1342  address->address,
1343  address->address_length));
1344  endpoint = create_macendpoint(plugin,
1345  (struct WlanAddress *)address->address);
1346  return get_session(endpoint, &address->peer);
1347 }
1348 
1349 
1358 static void
1360  const struct GNUNET_PeerIdentity *target)
1361 {
1362  struct Plugin *plugin = cls;
1363  struct GNUNET_ATS_Session *session;
1364  struct MacEndpoint *endpoint;
1365 
1366  for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
1367  for (session = endpoint->sessions_head; NULL != session; session = session->next)
1368  if (0 == memcmp(target, &session->target,
1369  sizeof(struct GNUNET_PeerIdentity)))
1370  {
1371  wlan_plugin_disconnect_session(plugin, session);
1372  break; /* inner-loop only (in case peer has another MAC as well!) */
1373  }
1374 }
1375 
1376 
1404 static ssize_t
1406  struct GNUNET_ATS_Session *session,
1407  const char *msgbuf, size_t msgbuf_size,
1408  unsigned int priority,
1409  struct GNUNET_TIME_Relative to,
1410  GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1411 {
1412  struct Plugin *plugin = cls;
1413  struct WlanHeader *wlanheader;
1414  size_t size = msgbuf_size + sizeof(struct WlanHeader);
1415  char buf[size] GNUNET_ALIGN;
1416 
1418  "Transmitting %u bytes of payload to peer `%s' (starting with %u byte message of type %u)\n",
1419  msgbuf_size,
1420  GNUNET_i2s(&session->target),
1421  (unsigned int)ntohs(((struct GNUNET_MessageHeader*)msgbuf)->size),
1422  (unsigned int)ntohs(((struct GNUNET_MessageHeader*)msgbuf)->type));
1423  wlanheader = (struct WlanHeader *)buf;
1424  wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader));
1425  wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA);
1426  wlanheader->sender = *plugin->env->my_identity;
1427  wlanheader->target = session->target;
1428  wlanheader->crc = htonl(GNUNET_CRYPTO_crc32_n(msgbuf, msgbuf_size));
1429  GNUNET_memcpy(&wlanheader[1],
1430  msgbuf,
1431  msgbuf_size);
1432  GNUNET_STATISTICS_update(plugin->env->stats,
1433  "# bytes currently in buffers",
1434  msgbuf_size,
1435  GNUNET_NO);
1436  send_with_fragmentation(session->mac,
1437  to,
1438  &session->target,
1439  &wlanheader->header,
1440  msgbuf_size,
1441  cont, cont_cls);
1442  return size;
1443 }
1444 
1445 
1454 static int
1455 process_data(void *cls,
1456  void *client,
1457  const struct GNUNET_MessageHeader *hdr)
1458 {
1459  struct Plugin *plugin = cls;
1460  struct GNUNET_HELLO_Address *address;
1461  struct MacAndSession *mas = client;
1462  struct FragmentMessage *fm;
1463  struct GNUNET_PeerIdentity tmpsource;
1464  const struct WlanHeader *wlanheader;
1465  int ret;
1466  uint16_t msize;
1467 
1468  msize = ntohs(hdr->size);
1469 
1470  GNUNET_STATISTICS_update(plugin->env->stats,
1471  "# bytes received",
1472  msize, GNUNET_NO);
1473 
1474  switch (ntohs(hdr->type))
1475  {
1477 
1478  if (GNUNET_OK !=
1479  GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)hdr,
1480  &tmpsource))
1481  {
1482  GNUNET_break_op(0);
1483  break;
1484  }
1485  if (NULL == mas->endpoint)
1486  {
1487  GNUNET_break(0);
1488  break;
1489  }
1490 
1492  "Processing %u bytes of HELLO from peer `%s' at MAC %s\n",
1493  (unsigned int)msize,
1494  GNUNET_i2s(&tmpsource),
1496  &mas->endpoint->wlan_addr,
1497  sizeof(mas->endpoint->wlan_addr)));
1498 
1499  GNUNET_STATISTICS_update(plugin->env->stats,
1500  _("# HELLO messages received"), 1,
1501  GNUNET_NO);
1502  address = GNUNET_HELLO_address_allocate(&tmpsource,
1503  PLUGIN_NAME,
1504  &mas->endpoint->wlan_addr,
1505  sizeof(mas->endpoint->wlan_addr),
1507  mas->session = lookup_session(mas->endpoint,
1508  &tmpsource);
1509  if (NULL == mas->session)
1510  {
1511  mas->session = create_session(mas->endpoint,
1512  &tmpsource);
1513  plugin->env->session_start(plugin->env->cls,
1514  address,
1515  mas->session,
1516  scope);
1517  }
1518  plugin->env->receive(plugin->env->cls,
1519  address,
1520  mas->session,
1521  hdr);
1522  GNUNET_HELLO_address_free(address);
1523  break;
1524 
1526  if (NULL == mas->endpoint)
1527  {
1528  GNUNET_break(0);
1529  break;
1530  }
1532  "Processing %u bytes of FRAGMENT from MAC %s\n",
1533  (unsigned int)msize,
1535  &mas->endpoint->wlan_addr,
1536  sizeof(mas->endpoint->wlan_addr)));
1537  GNUNET_STATISTICS_update(plugin->env->stats,
1538  _("# fragments received"),
1539  1,
1540  GNUNET_NO);
1542  hdr);
1543  break;
1544 
1546  if (NULL == mas->endpoint)
1547  {
1548  GNUNET_break(0);
1549  break;
1550  }
1551  GNUNET_STATISTICS_update(plugin->env->stats,
1552  _("# ACKs received"),
1553  1, GNUNET_NO);
1554  for (fm = mas->endpoint->sending_messages_head; NULL != fm; fm = fm->next)
1555  {
1556  ret = GNUNET_FRAGMENT_process_ack(fm->fragcontext, hdr);
1557  if (GNUNET_OK == ret)
1558  {
1560  "Got last ACK, finished message transmission to `%s' (%p)\n",
1562  &mas->endpoint->wlan_addr,
1563  sizeof(mas->endpoint->wlan_addr)),
1564  fm);
1565  mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute(MACENDPOINT_TIMEOUT);
1566  if (NULL != fm->cont)
1567  {
1568  fm->cont(fm->cont_cls,
1569  &fm->target,
1570  GNUNET_OK,
1571  fm->size_payload,
1572  fm->size_on_wire);
1573  fm->cont = NULL;
1574  }
1576  break;
1577  }
1578  if (GNUNET_NO == ret)
1579  {
1581  "Got an ACK, message transmission to `%s' not yet finished\n",
1583  &mas->endpoint->wlan_addr,
1584  sizeof(mas->endpoint->wlan_addr)));
1585  break;
1586  }
1587  }
1588  if (NULL == fm)
1590  "ACK not matched against any active fragmentation with MAC `%s'\n",
1592  &mas->endpoint->wlan_addr,
1593  sizeof(mas->endpoint->wlan_addr)));
1594  break;
1595 
1597  if (NULL == mas->endpoint)
1598  {
1599  GNUNET_break(0);
1600  break;
1601  }
1602  if (msize < sizeof(struct WlanHeader))
1603  {
1604  GNUNET_break(0);
1605  break;
1606  }
1607  wlanheader = (const struct WlanHeader *)hdr;
1608  if (0 != memcmp(&wlanheader->target,
1609  plugin->env->my_identity,
1610  sizeof(struct GNUNET_PeerIdentity)))
1611  {
1613  "Data for `%s', not for me, ignoring\n",
1614  GNUNET_i2s(&wlanheader->target));
1615  break;
1616  }
1617  if (ntohl(wlanheader->crc) !=
1618  GNUNET_CRYPTO_crc32_n(&wlanheader[1],
1619  msize - sizeof(struct WlanHeader)))
1620  {
1621  GNUNET_STATISTICS_update(plugin->env->stats,
1622  _("# DATA messages discarded due to CRC32 error"),
1623  1,
1624  GNUNET_NO);
1625  break;
1626  }
1627  mas->session = lookup_session(mas->endpoint,
1628  &wlanheader->sender);
1629  if (NULL == mas->session)
1630  {
1631  mas->session = create_session(mas->endpoint,
1632  &wlanheader->sender);
1633  address = GNUNET_HELLO_address_allocate(&wlanheader->sender,
1634  PLUGIN_NAME,
1635  &mas->endpoint->wlan_addr,
1636  sizeof(struct WlanAddress),
1638  plugin->env->session_start(plugin->env->cls,
1639  address,
1640  mas->session,
1641  scope);
1643  "Notifying transport about peer `%s''s new session %p \n",
1644  GNUNET_i2s(&wlanheader->sender),
1645  mas->session);
1646  GNUNET_HELLO_address_free(address);
1647  }
1649  "Processing %u bytes of DATA from peer `%s'\n",
1650  (unsigned int)msize,
1651  GNUNET_i2s(&wlanheader->sender));
1654  mas,
1655  (const char *)&wlanheader[1],
1656  msize - sizeof(struct WlanHeader),
1657  GNUNET_YES,
1658  GNUNET_NO);
1659  break;
1660 
1661  default:
1662  if (NULL == mas->endpoint)
1663  {
1664  GNUNET_break(0);
1665  break;
1666  }
1667  if (NULL == mas->session)
1668  {
1669  GNUNET_break(0);
1670  break;
1671  }
1673  "Received packet with %u bytes of type %u from peer %s\n",
1674  (unsigned int)msize,
1675  (unsigned int)ntohs(hdr->type),
1676  GNUNET_i2s(&mas->session->target));
1677  plugin->env->receive(plugin->env->cls,
1678  mas->session->address,
1679  mas->session,
1680  hdr);
1681  break;
1682  }
1683  return GNUNET_OK;
1684 }
1685 
1686 
1692 static void
1694 {
1695  struct Plugin *plugin = cls;
1696  uint16_t size;
1697  uint16_t hello_size;
1698  struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader;
1699  const struct GNUNET_MessageHeader *hello;
1700 
1701  hello = plugin->env->get_our_hello();
1702  if (NULL != hello)
1703  {
1704  hello_size = GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)hello);
1705  GNUNET_assert(sizeof(struct WlanHeader) + hello_size <= WLAN_MTU);
1706  size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size;
1707  {
1708  char buf[size] GNUNET_ALIGN;
1709 
1711  "Sending %u byte HELLO beacon\n",
1712  (unsigned int)size);
1713  radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*)buf;
1714  get_radiotap_header(NULL, radioHeader, size);
1716  "Broadcasting %u bytes of data to MAC `%s'\n",
1717  (unsigned int)size,
1719  get_wlan_header(plugin, &radioHeader->frame, &bc_all_mac, size);
1720  GNUNET_memcpy(&radioHeader[1], hello, hello_size);
1721  if (NULL !=
1723  &radioHeader->header,
1724  GNUNET_YES /* can drop */,
1725  NULL, NULL))
1726  GNUNET_STATISTICS_update(plugin->env->stats,
1727  _("# HELLO beacons sent"),
1728  1, GNUNET_NO);
1729  }
1730  }
1731  plugin->beacon_task =
1733  (HELLO_BEACON_SCALING_FACTOR,
1734  plugin->mac_count + 1),
1736  plugin);
1737 }
1738 
1739 
1746 static int
1748  const struct GNUNET_MessageHeader *hdr)
1749 {
1750  struct Plugin *plugin = cls;
1751  struct GNUNET_HELLO_Address *my_address;
1752  const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo;
1754  struct WlanAddress wa;
1755  struct MacAndSession mas;
1756  uint16_t msize;
1757  struct FragmentMessage *fm;
1758  struct MacEndpoint *endpoint;
1759 
1760  msize = ntohs(hdr->size);
1761  switch (ntohs(hdr->type))
1762  {
1764  if (msize != sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
1765  {
1766  GNUNET_break(0);
1767  break;
1768  }
1769  cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *)hdr;
1770  if (GNUNET_YES == plugin->have_mac)
1771  {
1772  if (0 == memcmp(&plugin->mac_address,
1773  &cm->mac,
1774  sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1775  break; /* no change */
1776  /* remove old address */
1777  memset(&wa, 0, sizeof(struct WlanAddress));
1778  wa.mac = plugin->mac_address;
1779  wa.options = htonl(plugin->options);
1780  my_address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
1781  PLUGIN_NAME,
1782  &wa, sizeof(wa),
1784  plugin->env->notify_address(plugin->env->cls,
1785  GNUNET_NO,
1786  my_address);
1787  GNUNET_HELLO_address_free(my_address);
1788  plugin->mac_address = cm->mac;
1789  }
1790  else
1791  {
1792  plugin->mac_address = cm->mac;
1793  plugin->have_mac = GNUNET_YES;
1794  for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
1795  {
1796  for (fm = endpoint->sending_messages_head; NULL != fm; fm = fm->next)
1797  {
1798  if (NULL != fm->fragcontext)
1799  {
1800  GNUNET_break(0); /* should not happen */
1801  continue;
1802  }
1803  fm->fragcontext =
1804  GNUNET_FRAGMENT_context_create(plugin->env->stats,
1805  WLAN_MTU,
1806  &plugin->tracker,
1807  fm->macendpoint->msg_delay,
1808  fm->macendpoint->ack_delay,
1809  fm->msg,
1810  &transmit_fragment, fm);
1811  GNUNET_free(fm->msg);
1812  fm->msg = NULL;
1813  }
1814  }
1815  GNUNET_break(NULL == plugin->beacon_task);
1817  plugin);
1818  }
1819 
1820  memset(&wa, 0, sizeof(struct WlanAddress));
1821  wa.mac = plugin->mac_address;
1822  wa.options = htonl(plugin->options);
1823  my_address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
1824  PLUGIN_NAME,
1825  &wa, sizeof(wa),
1827 
1829  "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n",
1830  mac_to_string(&cm->mac),
1831  GNUNET_i2s(plugin->env->my_identity));
1832  plugin->env->notify_address(plugin->env->cls,
1833  GNUNET_YES,
1834  my_address);
1835  GNUNET_HELLO_address_free(my_address);
1836  break;
1837 
1840  "Got data message from helper with %u bytes\n",
1841  msize);
1842  GNUNET_STATISTICS_update(plugin->env->stats,
1843  _("# DATA messages received"), 1,
1844  GNUNET_NO);
1845  if (msize < sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage))
1846  {
1848  "Size of packet is too small (%u bytes < %u)\n",
1849  msize, sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage));
1850  break;
1851  }
1852  rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)hdr;
1853 
1854  /* check if message is actually for us */
1855  if (0 != memcmp(&rxinfo->frame.addr3, &mac_bssid_gnunet,
1856  sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1857  {
1858  /* Not the GNUnet BSSID */
1859  break;
1860  }
1861  if ((0 != memcmp(&rxinfo->frame.addr1, &bc_all_mac,
1862  sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) &&
1863  (0 != memcmp(&rxinfo->frame.addr1, &plugin->mac_address,
1864  sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))))
1865  {
1866  /* Neither broadcast nor specifically for us */
1867  break;
1868  }
1869  if (0 == memcmp(&rxinfo->frame.addr2, &plugin->mac_address,
1870  sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1871  {
1872  /* packet is FROM us, thus not FOR us */
1873  break;
1874  }
1875 
1876  GNUNET_STATISTICS_update(plugin->env->stats,
1877  _("# DATA messages processed"),
1878  1, GNUNET_NO);
1880  "Receiving %u bytes of data from MAC `%s'\n",
1881  (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1882  mac_to_string(&rxinfo->frame.addr2));
1884  "Receiving %u bytes of data to MAC `%s'\n",
1885  (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1886  mac_to_string(&rxinfo->frame.addr1));
1888  "Receiving %u bytes of data with BSSID MAC `%s'\n",
1889  (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1890  mac_to_string(&rxinfo->frame.addr3));
1891  wa.mac = rxinfo->frame.addr2;
1892  wa.options = htonl(0);
1893  mas.endpoint = create_macendpoint(plugin, &wa);
1894  mas.session = NULL;
1896  &mas,
1897  (const char*)&rxinfo[1],
1898  msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage),
1899  GNUNET_YES, GNUNET_NO);
1900  break;
1901 
1902  default:
1903  GNUNET_break(0);
1905  "Unexpected message of type %u (%u bytes)",
1906  ntohs(hdr->type),
1907  ntohs(hdr->size));
1908  break;
1909  }
1910  return GNUNET_OK;
1911 }
1912 
1913 
1926 static int
1928  const void *addr,
1929  size_t addrlen)
1930 {
1931  struct Plugin *plugin = cls;
1932  struct WlanAddress *wa = (struct WlanAddress *)addr;
1933 
1934  if (addrlen != sizeof(struct WlanAddress))
1935  {
1936  GNUNET_break_op(0);
1937  return GNUNET_SYSERR;
1938  }
1939  if (GNUNET_YES != plugin->have_mac)
1940  {
1942  "Rejecting MAC `%s': I don't know my MAC!\n",
1943  mac_to_string(addr));
1944  return GNUNET_NO; /* don't know my MAC */
1945  }
1946  if (0 != memcmp(&wa->mac,
1947  &plugin->mac_address,
1948  sizeof(wa->mac)))
1949  {
1951  "Rejecting MAC `%s': not my MAC!\n",
1952  mac_to_string(addr));
1953  return GNUNET_NO; /* not my MAC */
1954  }
1955  return GNUNET_OK;
1956 }
1957 
1958 
1972 static void
1974  const char *type,
1975  const void *addr,
1976  size_t addrlen,
1977  int numeric,
1980  void *asc_cls)
1981 {
1982  const char *ret;
1983 
1984  if (sizeof(struct WlanAddress) == addrlen)
1985  ret = wlan_plugin_address_to_string(NULL,
1986  addr,
1987  addrlen);
1988  else
1989  ret = NULL;
1990  asc(asc_cls,
1991  ret,
1992  (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1993  asc(asc_cls, NULL, GNUNET_OK);
1994 }
1995 
1996 
2002 void *
2004 {
2005  struct WlanAddress wa;
2006  struct GNUNET_HELLO_Address *address;
2007  struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2008  struct Plugin *plugin = api->cls;
2009  struct MacEndpoint *endpoint;
2010  struct MacEndpoint *endpoint_next;
2011 
2012  if (NULL == plugin)
2013  {
2014  GNUNET_free(api);
2015  return NULL;
2016  }
2017  if (GNUNET_YES == plugin->have_mac)
2018  {
2019  memset(&wa, 0, sizeof(wa));
2020  wa.options = htonl(plugin->options);
2021  wa.mac = plugin->mac_address;
2022  address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
2023  PLUGIN_NAME,
2024  &wa, sizeof(struct WlanAddress),
2026 
2027  plugin->env->notify_address(plugin->env->cls,
2028  GNUNET_NO,
2029  address);
2030  plugin->have_mac = GNUNET_NO;
2031  GNUNET_HELLO_address_free(address);
2032  }
2033 
2034  if (NULL != plugin->beacon_task)
2035  {
2037  plugin->beacon_task = NULL;
2038  }
2039  if (NULL != plugin->suid_helper)
2040  {
2042  GNUNET_NO);
2043  plugin->suid_helper = NULL;
2044  }
2045  endpoint_next = plugin->mac_head;
2046  while (NULL != (endpoint = endpoint_next))
2047  {
2048  endpoint_next = endpoint->next;
2049  free_macendpoint(endpoint);
2050  }
2051  if (NULL != plugin->fragment_data_tokenizer)
2052  {
2054  plugin->fragment_data_tokenizer = NULL;
2055  }
2056  if (NULL != plugin->wlan_header_payload_tokenizer)
2057  {
2059  plugin->wlan_header_payload_tokenizer = NULL;
2060  }
2061  if (NULL != plugin->helper_payload_tokenizer)
2062  {
2064  plugin->helper_payload_tokenizer = NULL;
2065  }
2067  GNUNET_free(plugin);
2068  GNUNET_free(api);
2069  return NULL;
2070 }
2071 
2072 
2085 static int
2087  const char *addr,
2088  uint16_t addrlen,
2089  void **buf,
2090  size_t *added)
2091 {
2092  struct WlanAddress *wa;
2093  unsigned int a[6];
2094  unsigned int i;
2095  char plugin[5];
2096  uint32_t options;
2097 
2098  if ((NULL == addr) || (0 == addrlen))
2099  {
2100  GNUNET_break(0);
2101  return GNUNET_SYSERR;
2102  }
2103  if ('\0' != addr[addrlen - 1])
2104  {
2105  GNUNET_break(0);
2106  return GNUNET_SYSERR;
2107  }
2108  if (strlen(addr) != addrlen - 1)
2109  {
2110  GNUNET_break(0);
2111  return GNUNET_SYSERR;
2112  }
2113 
2114  if (8 != sscanf(addr,
2115  "%4s.%u.%X:%X:%X:%X:%X:%X",
2116  plugin, &options,
2117  &a[0], &a[1], &a[2],
2118  &a[3], &a[4], &a[5]))
2119  {
2120  GNUNET_break(0);
2121  return GNUNET_SYSERR;
2122  }
2123  wa = GNUNET_new(struct WlanAddress);
2124  for (i = 0; i < 6; i++)
2125  wa->mac.mac[i] = a[i];
2126  wa->options = htonl(0);
2127  *buf = wa;
2128  *added = sizeof(struct WlanAddress);
2129  return GNUNET_OK;
2130 }
2131 
2132 
2145 static void
2148  void *sic_cls)
2149 {
2150  struct Plugin *plugin = cls;
2151  struct MacEndpoint *mac;
2152  struct GNUNET_ATS_Session *session;
2153 
2154  plugin->sic = sic;
2155  plugin->sic_cls = sic_cls;
2156  if (NULL != sic)
2157  {
2158  for (mac = plugin->mac_head; NULL != mac; mac = mac->next)
2159  for (session = mac->sessions_head; NULL != session; session = session->next)
2160  {
2161  notify_session_monitor(plugin,
2162  session,
2164  notify_session_monitor(plugin,
2165  session,
2167  }
2168  sic(sic_cls, NULL, NULL);
2169  }
2170 }
2171 
2172 
2173 
2183 static void
2185  const struct GNUNET_PeerIdentity *peer,
2186  struct GNUNET_ATS_Session *session)
2187 {
2188  GNUNET_assert(NULL != session->timeout_task);
2190 }
2191 
2192 
2203 static void
2205  const struct GNUNET_PeerIdentity *peer,
2206  struct GNUNET_ATS_Session *session,
2207  struct GNUNET_TIME_Relative delay)
2208 {
2209  /* does nothing, as inbound delay is not supported by WLAN */
2210 }
2211 
2212 
2219 void *
2221 {
2224  struct Plugin *plugin;
2225  char *wlan_interface;
2226  unsigned long long testmode;
2227  char *binary;
2228 
2229  /* check for 'special' mode */
2230  if (NULL == env->receive)
2231  {
2232  /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2233  initialze the plugin or the API */
2235  api->cls = NULL;
2239  return api;
2240  }
2241 
2242  testmode = 0;
2243  /* check configuration */
2244  if ((GNUNET_YES ==
2246  CONFIG_NAME,
2247  "TESTMODE")) &&
2248  ((GNUNET_SYSERR ==
2250  CONFIG_NAME,
2251  "TESTMODE",
2252  &testmode)) ||
2253  (testmode > 2)))
2254  {
2256  CONFIG_NAME,
2257  "TESTMODE");
2258  return NULL;
2259  }
2260  binary = GNUNET_OS_get_libexec_binary_path(HELPER_NAME);
2261  if ((0 == testmode) &&
2262  (GNUNET_YES !=
2264  GNUNET_YES,
2265  NULL)))
2266  {
2268  _("Helper binary `%s' not SUID, cannot run WLAN transport\n"),
2269  HELPER_NAME);
2270  GNUNET_free(binary);
2271  return NULL;
2272  }
2273  GNUNET_free(binary);
2274  if (GNUNET_YES !=
2276  CONFIG_NAME,
2277  "INTERFACE",
2278  &wlan_interface))
2279  {
2281  CONFIG_NAME,
2282  "INTERFACE");
2283  return NULL;
2284  }
2285 
2286  plugin = GNUNET_new(struct Plugin);
2287  plugin->wlan_interface = wlan_interface;
2288  plugin->env = env;
2289  GNUNET_STATISTICS_set(plugin->env->stats,
2290  _("# sessions allocated"),
2291  0, GNUNET_NO);
2292  GNUNET_STATISTICS_set(plugin->env->stats,
2293  _("# MAC endpoints allocated"),
2294  0, 0);
2295  GNUNET_BANDWIDTH_tracker_init(&plugin->tracker, NULL, NULL,
2296  GNUNET_BANDWIDTH_value_init(100 * 1024 *
2297  1024 / 8),
2298  100);
2300  plugin);
2302  plugin);
2304  plugin);
2305 
2306  plugin->options = 0;
2307 
2308  /* some compilers do not like switch on 'long long'... */
2309  switch ((unsigned int)testmode)
2310  {
2311  case 0: /* normal */
2312  plugin->helper_argv[0] = (char *)HELPER_NAME;
2313  plugin->helper_argv[1] = wlan_interface;
2314  plugin->helper_argv[2] = NULL;
2316  HELPER_NAME,
2317  plugin->helper_argv,
2319  NULL,
2320  plugin);
2321  break;
2322 
2323  case 1: /* testmode, peer 1 */
2324  plugin->helper_argv[0] = (char *)DUMMY_HELPER_NAME;
2325  plugin->helper_argv[1] = (char *)"1";
2326  plugin->helper_argv[2] = NULL;
2328  DUMMY_HELPER_NAME,
2329  plugin->helper_argv,
2331  NULL,
2332  plugin);
2333  break;
2334 
2335  case 2: /* testmode, peer 2 */
2336  plugin->helper_argv[0] = (char *)DUMMY_HELPER_NAME;
2337  plugin->helper_argv[1] = (char *)"2";
2338  plugin->helper_argv[2] = NULL;
2340  DUMMY_HELPER_NAME,
2341  plugin->helper_argv,
2343  NULL,
2344  plugin);
2345  break;
2346 
2347  default:
2348  GNUNET_assert(0);
2349  }
2350 
2352  api->cls = plugin;
2353  api->send = &wlan_plugin_send;
2367  return api;
2368 }
2369 
2370 
2371 /* end of plugin_transport_wlan.c */
static struct GNUNET_ATS_Session * create_session(struct MacEndpoint *endpoint, const struct GNUNET_PeerIdentity *peer)
Create a new session.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static int handle_helper_message(void *cls, const struct GNUNET_MessageHeader *hdr)
Function used for to process the data from the suid process.
size_t address_length
Number of bytes in address.
Session is being torn down and about to disappear.
static void session_timeout(void *cls)
A session is timing out.
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
GNUNET_TRANSPORT_TransmitContinuation cont
Continuation to call when we&#39;re done with this message.
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:662
struct GNUNET_HELPER_Handle * suid_helper
Handle to helper process for priviledged operations.
#define GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL
Control message between the gnunet-wlan-helper and the daemon (with the MAC).
uint32_t num_bytes_pending
Number of bytes pending transmission for this session.
char * helper_argv[3]
ARGV-vector for the helper (all helpers take only the binary name, one actual argument, plus the NULL terminator for &#39;argv&#39;).
static void notify_session_monitor(struct Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
A HELLO message is used to exchange information about transports with other peers.
#define WLAN_LLC_SSAP_FIELD
uint32_t crc
CRC32 checksum (only over the payload), in NBO.
struct MacEndpoint * endpoint
MAC address of the other peer, NULL if not known.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
GNUNET_TRANSPORT_CreateSession get_session
Function that will be called tell the plugin to create a session object.
static void wlan_plugin_update_session_timeout(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *session)
Function that will be called whenever the transport service wants to notify the plugin that a session...
GNUNET_TRANSPORT_AddressToString address_to_string
Function that will be called to convert a binary address to a string (numeric conversion only)...
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
static int wlan_plugin_string_to_address(void *cls, const char *addr, uint16_t addrlen, void **buf, size_t *added)
Function called to convert a string address to a binary address.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
void GNUNET_BANDWIDTH_tracker_init(struct GNUNET_BANDWIDTH_Tracker *av, GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb, void *update_cb_cls, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, uint32_t max_carry_s)
Initialize bandwidth tracker.
Definition: bandwidth.c:302
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
uint64_t rel_value_us
The actual value.
const void * address
Binary representation of the address (plugin-specific).
static void wlan_plugin_setup_monitor(void *cls, GNUNET_TRANSPORT_SessionInfoCallback sic, void *sic_cls)
Begin monitoring sessions of a plugin.
int have_mac
Have we received a control message with our MAC address yet?
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
uint8_t antenna
Antenna we should use for this MAC.
static struct GNUNET_ATS_Session * lookup_session(struct MacEndpoint *endpoint, const struct GNUNET_PeerIdentity *peer)
Lookup a new session.
static void wlan_plugin_update_inbound_delay(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *session, struct GNUNET_TIME_Relative delay)
Function that will be called whenever the transport service wants to notify the plugin that the inbou...
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int32_t GNUNET_CRYPTO_crc32_n(const void *buf, size_t len)
Compute the CRC32 checksum for the first len bytes of the buffer.
Definition: crypto_crc.c:105
Address format for WLAN.
static void get_radiotap_header(struct MacEndpoint *endpoint, struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, uint16_t size)
Fill the radiotap header.
struct MacEndpoint * prev
We keep all MACs in a DLL in the plugin.
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static void free_fragment_message(struct FragmentMessage *fm)
Frees the space of a message in the fragment queue (send queue)
void * cont_cls
Closure for cont.
struct MacEndpoint * macendpoint
MAC endpoint this message belongs to.
uint8_t antenna
Antenna; the first antenna is 0.
The handle to a helper process.
Definition: helper.c:77
struct GNUNET_HELPER_Handle * GNUNET_HELPER_start(int with_control_pipe, const char *binary_name, char *const binary_argv[], GNUNET_MessageTokenizerCallback cb, GNUNET_HELPER_ExceptionCallback exp_cb, void *cb_cls)
Starts a helper and begins reading from it.
Definition: helper.c:487
struct GNUNET_ATS_Session * next
Stored in a linked list.
GNUNET_TRANSPORT_TransmitFunction send
Function that the transport service will use to transmit data to another peer.
GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
#define LOG(kind,...)
Definition: arm_api.c:33
int is_inbound
GNUNET_YES if this is an inbound connection, GNUNET_NO if this is an outbound connection, GNUNET_SYSERR if connections of this plugin are so fundamentally bidirectional that they have no &#39;initiator&#39;
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
struct GNUNET_DEFRAGMENT_Context * GNUNET_DEFRAGMENT_context_create(struct GNUNET_STATISTICS_Handle *stats, uint16_t mtu, unsigned int num_msgs, void *cls, GNUNET_FRAGMENT_MessageProcessor proc, GNUNET_DEFRAGMENT_AckProcessor ackp)
Create a defragmentation context.
static unsigned int wlan_plugin_query_keepalive_factor(void *cls)
Function that is called to get the keepalive factor.
enum GNUNET_TRANSPORT_SessionState state
New state of the session.
struct GNUNET_SERVER_MessageStreamTokenizer * helper_payload_tokenizer
Tokenizer for demultiplexing of data packets received from the suid helper.
struct GNUNET_ATS_Session * prev
Stored in a linked list.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t options
Options for addresses.
unsigned int mac_count
Number of connections.
GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
static void transmit_fragment(void *cls, const struct GNUNET_MessageHeader *hdr)
Transmit a fragment of a message.
struct GNUNET_HELPER_SendHandle * sh
Transmission handle to helper (to cancel if the frag context is destroyed early for some reason)...
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
Header for messages which need fragmentation.
GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor
Function to monitor the sessions managed by the plugin.
struct MacEndpoint * next
We keep all MACs in a DLL in the plugin.
void GNUNET_HELPER_stop(struct GNUNET_HELPER_Handle *h, int soft_kill)
Kills the helper, closes the pipe, frees the handle and calls wait() on the helper process...
Definition: helper.c:563
static int wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
Another peer has suggested an address for this peer and transport plugin.
struct GNUNET_PeerIdentity sender
Sender of the message.
struct GNUNET_SERVER_MessageStreamTokenizer * fragment_data_tokenizer
Tokenizer for demultiplexing of data packets resulting from defragmentation.
void * LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls)
Entry point for the plugin.
struct GNUNET_FRAGMENT_Context * GNUNET_FRAGMENT_context_create(struct GNUNET_STATISTICS_Handle *stats, uint16_t mtu, struct GNUNET_BANDWIDTH_Tracker *tracker, struct GNUNET_TIME_Relative msg_delay, struct GNUNET_TIME_Relative ack_delay, const struct GNUNET_MessageHeader *msg, GNUNET_FRAGMENT_MessageProcessor proc, void *proc_cls)
Create a fragmentation context for the given message.
Entry in the queue of messages we need to transmit to the helper.
Definition: helper.c:36
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct PendingMessage * next
DLL next, prev.
Struct to track available bandwidth.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
static ssize_t wlan_plugin_send(void *cls, struct GNUNET_ATS_Session *session, const char *msgbuf, size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
Function that can be used by the transport service to transmit a message using the plugin...
#define GNUNET_NO
Definition: gnunet_common.h:78
static int numeric
Option -n.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Wireless LAN (i.e.
Definition: gnunet_nt_lib.h:59
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
int GNUNET_OS_check_helper_binary(const char *binary, int check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
void GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst)
Destroys a tokenizer.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HELLO_Address * address
Address.
static char * helper_argv[8]
Command-line arguments we are giving to the hijacker process.
#define WLAN_LLC_DSAP_FIELD
Link layer control fields for better compatibility (i.e.
int GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst, void *client_identity, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
static void wlan_data_message_handler(void *cls, const struct GNUNET_MessageHeader *hdr)
Handles the data after all fragments are put together.
u_int8_t llc[4]
Link layer control (LLC).
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define IEEE80211_FC0_TYPE_DATA
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
const struct GNUNET_HELLO_Address * address
Address used by the session.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_MESSAGE_TYPE_FRAGMENT_ACK
Acknowledgement of a FRAGMENT of a larger message.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
uint32_t num_msg_pending
Number of messages pending transmission for this session.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static enum GNUNET_NetworkType wlan_plugin_get_network_for_address(void *cls, const struct GNUNET_HELLO_Address *address)
Function obtain the network type for an address.
uint8_t rate
Desired transmission rate for this MAC.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:46
struct GNUNET_TIME_Absolute receive_delay
Until when does this plugin refuse to receive to manage staying within the inbound quota...
struct MacEndpoint * mac_head
Head of list of open connections.
void GNUNET_FRAGMENT_context_transmission_done(struct GNUNET_FRAGMENT_Context *fc)
Continuation to call from the &#39;proc&#39; function after the fragment has been transmitted (and hence the ...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
Format of a WLAN Control Message.
struct Plugin * plugin
Pointer to the global plugin struct.
Handle to a message stream tokenizer.
GNUNET_TRANSPORT_PluginReceiveCallback receive
Function that should be called by the transport plugin whenever a message is received.
int(* GNUNET_SERVER_MessageTokenizerCallback)(void *cls, void *client, const struct GNUNET_MessageHeader *message)
Functions with this signature are called whenever a complete message is received by the tokenizer...
Message from the WLAN helper to the plugin: we have received the given message with the given perform...
struct GNUNET_TRANSPORT_WLAN_MacAddress mac
MAC Address of the local WLAN interface.
GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout
Function that will be called whenever the transport service wants to notify the plugin that a session...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Information about a plugin&#39;s session.
Bluetooth LAN.
Definition: gnunet_nt_lib.h:64
Fragmentation context.
Definition: fragmentation.c:40
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1237
struct GNUNET_ATS_Session * sessions_head
Head of sessions that use this MAC.
struct FragmentMessage * next
This is a doubly-linked list.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct GNUNET_SCHEDULER_Task * timeout_task
Timeout task (for this message).
void * cls
Closure for the various callbacks.
enum State state
current state of profiling
void GNUNET_HELPER_send_cancel(struct GNUNET_HELPER_SendHandle *sh)
Cancel a GNUNET_HELPER_send operation.
Definition: helper.c:692
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
void * cls
Closure for all of the callbacks.
void GNUNET_DEFRAGMENT_context_destroy(struct GNUNET_DEFRAGMENT_Context *dc)
Destroy the given defragmentation context.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
void(* GNUNET_TRANSPORT_AddressStringCallback)(void *cls, const char *address, int res)
Function called by the pretty printer for the resolved address for each human-readable address obtain...
GNUNET_TRANSPORT_StringToAddress string_to_address
Function that will be called to convert a string address to binary (numeric conversion only)...
char * wlan_interface
The interface of the wlan card given to us by the user.
Information about ongoing sessions of the transport client.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
The transport service will pass a pointer to a struct of this type as the first and only argument to ...
static enum GNUNET_NetworkType scope
Which network scope do we belong to?
int GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
GNUNET_TRANSPORT_GetNetworkType get_network
Function to obtain the network type for a session.
static void wlan_plugin_disconnect_peer(void *cls, const struct GNUNET_PeerIdentity *target)
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
static struct GNUNET_ATS_Session * get_session(struct MacEndpoint *endpoint, const struct GNUNET_PeerIdentity *peer)
Look up a session for a peer and create a new session if none is found.
static char buf[2048]
struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame
IEEE Frame.
void(* GNUNET_TRANSPORT_SessionInfoCallback)(void *cls, struct GNUNET_ATS_Session *session, const struct GNUNET_TRANSPORT_SessionInfo *info)
Function called by the plugin with information about the current sessions managed by the plugin (for ...
struct GNUNET_SERVER_MessageStreamTokenizer * wlan_header_payload_tokenizer
Tokenizer for demultiplexing of data packets that follow the WLAN Header.
static int result
Global testing status.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:440
static GNUNET_NETWORK_STRUCT_END const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet
GNUnet bssid.
struct MacEndpoint * mac_tail
Tail of list of open connections.
struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame
IEEE Frame to transmit (the sender MAC address will be overwritten by the helper as it does not trust...
struct GNUNET_TIME_Absolute session_timeout
At what time will this session timeout (unless activity happens)?
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
GNUNET_TRANSPORT_UpdateInboundDelay update_inbound_delay
Function that will be called whenever the transport service wants to notify the plugin that the inbou...
#define GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER
Type of data messages from the plugin to the gnunet-wlan-helper.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
#define GNUNET_htole16(x)
int GNUNET_FRAGMENT_process_ack(struct GNUNET_FRAGMENT_Context *fc, const struct GNUNET_MessageHeader *msg)
Process an acknowledgement message we got from the other side (to control re-transmits).
struct GNUNET_PeerIdentity target
Target of the message.
struct FragmentMessage * sending_messages_head
Head of messages we are currently sending to this MAC.
struct GNUNET_SCHEDULER_Task * beacon_task
Task that periodically sends a HELLO beacon via the helper.
static void send_ack(void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr)
Send an ACK for a fragment we received.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
Defragmentation context (one per connection).
static void free_macendpoint(struct MacEndpoint *endpoint)
Free a MAC endpoint.
uint16_t tx_power
Desired transmission power for this MAC.
struct FragmentMessage * prev
This is a doubly-linked list.
struct PendingMessage * prev
This is a doubly-linked list.
Struct for messages that are being fragmented in a MAC&#39;s transmission queue.
uint16_t frame_control
802.11 Frame Control field.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_MESSAGE_TYPE_WLAN_DATA
Type of messages for data over the wlan.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct GNUNET_MessageHeader header
Message type is GNUNET_MESSAGE_TYPE_WLAN_DATA.
struct MacEndpoint * mac
MAC endpoint with the address of this peer.
struct GNUNET_FRAGMENT_Context * fragcontext
Fragmentation context.
static struct MacEndpoint * create_macendpoint(struct Plugin *plugin, struct WlanAddress *mac)
Find (or create) a MacEndpoint with a specific MAC address.
static void fragmentmessage_timeout(void *cls)
A FragmentMessage has timed out.
struct GNUNET_TIME_Absolute timeout
Timeout value for the message.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_ATS_Session * sessions_tail
Tail of sessions that use this MAC.
void(* GNUNET_TRANSPORT_TransmitContinuation)(void *cls, const struct GNUNET_PeerIdentity *target, int result, size_t size_payload, size_t size_on_wire)
Function called by the GNUNET_TRANSPORT_TransmitFunction upon "completion".
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
void * LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls)
Exit point from the plugin.
static struct GNUNET_SCHEDULER_Task * timeout_task
Task to be run on timeout.
Definition: gnunet-arm.c:119
struct GNUNET_MessageHeader header
Type is &#39;GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER&#39;.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_PeerIdentity peer
For which peer is this an address?
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_init(uint32_t bytes_per_second)
Create a new bandwidth value.
Definition: bandwidth.c:39
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct WlanAddress wlan_addr
peer MAC address
struct GNUNET_TRANSPORT_WLAN_MacAddress mac_address
The mac_address of the wlan card given to us by the helper.
struct GNUNET_TRANSPORT_WLAN_MacAddress mac
WLAN addresses using MACs.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
struct GNUNET_DEFRAGMENT_Context * defrag
Defrag context for this MAC.
struct WlanHeader * msg
The pending message.
struct FragmentMessage * sending_messages_tail
Tail of messages we are currently sending to this MAC.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
uint16_t sequence_control
802.11 sequence control field; contains fragment number an sequence number (we set this to all zeros)...
GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor
Function that is used to query keepalive factor.
The identity of the host (wraps the signing key of the peer).
No additional information.
uint16_t duration
Microseconds to reserve link (duration), 0 by default.
static const char * wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
size_t size_on_wire
Number of bytes used to transmit message.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
struct GNUNET_SCHEDULER_Task * timeout_task
Timeout task.
struct GNUNET_TIME_Relative ack_delay
ACK delay for fragmentation context.
#define GNUNET_PACKED
gcc-ism to get packed structs.
size_t size_payload
Size of original message.
#define MESSAGES_IN_DEFRAG_QUEUE_PER_MAC
Maximum number of messages in defragmentation queue per MAC.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define PLUGIN_NAME
generic definitions for IEEE 802.11 frames
unsigned int fragment_messages_out_count
count of messages in the fragment out queue for this mac endpoint
static void macendpoint_timeout(void *cls)
A MAC endpoint is timing out.
An address for communicating with a peer.
struct GNUNET_HELPER_SendHandle * GNUNET_HELPER_send(struct GNUNET_HELPER_Handle *h, const struct GNUNET_MessageHeader *msg, int can_drop, GNUNET_HELPER_Continuation cont, void *cont_cls)
Send an message to the helper.
Definition: helper.c:653
struct GNUNET_TIME_Relative msg_delay
Message delay for fragmentation context.
static const char * mac_to_string(const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
Print MAC addresses nicely.
The session was created (first call for each session object).
Entry in list of pending tasks.
Definition: scheduler.c:131
header for transport plugin and the helper for wlan
List containing all messages that are yet to be send.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:643
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
static void send_hello_beacon(void *cls)
Task to (periodically) send a HELLO beacon.
struct GNUNET_TIME_Absolute timeout
When should this endpoint time out?
static int wlan_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session)
Free a session.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
void * cls
Closure to use for callbacks.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer
Function to pretty-print addresses.
Header for all communications.
int GNUNET_DEFRAGMENT_process_fragment(struct GNUNET_DEFRAGMENT_Context *dc, const struct GNUNET_MessageHeader *msg)
We have received a fragment.
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TRANSPORT_WLAN_MacAddress addr3
Address 3: BSSID in ad-hoc mode, Destination if station, source if AP.
struct GNUNET_PeerIdentity target
Intended recipient.
Struct to represent one network card connection.
#define GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER
Type of data messages from the gnunet-wlan-helper to the plugin.
struct GNUNET_SCHEDULER_Task * timeout_task
Timeout task.
struct GNUNET_BANDWIDTH_Tracker tracker
Bandwidth tracker to limit global UDP traffic.
#define GNUNET_MESSAGE_TYPE_FRAGMENT
FRAGMENT of a larger message.
static const struct GNUNET_TRANSPORT_WLAN_MacAddress bc_all_mac
Broadcast MAC.
uint32_t options
Options set for the WLAN, in NBO.
static void send_with_fragmentation(struct MacEndpoint *endpoint, struct GNUNET_TIME_Relative timeout, const struct GNUNET_PeerIdentity *target, const struct GNUNET_MessageHeader *msg, size_t payload_size, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
Transmit a message to the given destination with fragmentation.
struct GNUNET_MessageHeader * msg
Message we need to fragment and transmit, NULL after the fragmentcontext has been created...
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
GNUNET_TRANSPORT_CheckAddress check_address
Function that will be called to check if a binary address for this plugin is well-formed and correspo...
Information associated with a message.
GNUNET_TRANSPORT_SessionState
Possible states of a session in a plugin.
void GNUNET_FRAGMENT_context_destroy(struct GNUNET_FRAGMENT_Context *fc, struct GNUNET_TIME_Relative *msg_delay, struct GNUNET_TIME_Relative *ack_delay)
Destroy the given fragmentation context (stop calling &#39;proc&#39;, free resources).
Message from the plugin to the WLAN helper: send the given message with the given connection paramete...
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct GNUNET_TRANSPORT_WLAN_MacAddress addr2
Address 2: source address if in ad-hoc-mode or station, BSSID if AP.
#define GNUNET_HELLO_address_free(addr)
Free an address.
struct GNUNET_TRANSPORT_WLAN_MacAddress addr1
Address 1: destination address in ad-hoc mode or AP, BSSID if station,.
void * sic_cls
Closure for sic.
struct GNUNET_SERVER_MessageStreamTokenizer * GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
uint16_t tx_power
Transmit power expressed as unitless distance from max power set at factory calibration.
static void fragment_transmission_done(void *cls, int result)
Function called once we have successfully given the fragment message to the SUID helper process and w...
static enum GNUNET_NetworkType wlan_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
Function obtain the network type for a session.
static struct GNUNET_ATS_Session * wlan_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
Creates a new outbound session the transport service will use to send data to the peer...
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_ATS_Session * session
NULL if the identity of the other peer is not known.
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address
Function to obtain the network type for an address.
static int process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
We have received data from the WLAN via some session.
#define WLAN_MTU
Max size of packet (that we give to the WLAN driver for transmission)
static void wlan_plugin_address_pretty_printer(void *cls, const char *type, const void *addr, size_t addrlen, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
Convert the transports address to a nice, human-readable format.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
static void get_wlan_header(struct Plugin *plugin, struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *header, const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, unsigned int size)
Generate the WLAN hardware header for one packet.