aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/plugin_transport_wlan.c111
1 files changed, 62 insertions, 49 deletions
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 103d21ae1..ea65838eb 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -193,6 +193,11 @@ struct Session
193 struct MacEndpoint *mac; 193 struct MacEndpoint *mac;
194 194
195 /** 195 /**
196 * Address associated with this session and MAC endpoint
197 */
198 struct GNUNET_HELLO_Address *address;
199
200 /**
196 * Head of messages currently pending for transmission to this peer. 201 * Head of messages currently pending for transmission to this peer.
197 */ 202 */
198 struct PendingMessage *pending_message_head; 203 struct PendingMessage *pending_message_head;
@@ -349,11 +354,9 @@ struct MacEndpoint
349 unsigned int fragment_messages_out_count; 354 unsigned int fragment_messages_out_count;
350 355
351 /** 356 /**
352 * peer mac address 357 * peer MAC address
353 */ 358 */
354 //struct WlanAddress addr; 359 struct WlanAddress wlan_addr;
355
356 struct GNUNET_HELLO_Address *address;
357 360
358 /** 361 /**
359 * Inbound or outbound session 362 * Inbound or outbound session
@@ -614,8 +617,8 @@ send_ack (void *cls, uint32_t msg_id,
614 get_radiotap_header (endpoint, radio_header, size); 617 get_radiotap_header (endpoint, radio_header, size);
615 get_wlan_header (endpoint->plugin, 618 get_wlan_header (endpoint->plugin,
616 &radio_header->frame, 619 &radio_header->frame,
617 endpoint->address->address, 620 &endpoint->wlan_addr.mac,
618 endpoint->address->address_length); 621 sizeof (endpoint->wlan_addr.mac));
619 memcpy (&radio_header[1], hdr, msize); 622 memcpy (&radio_header[1], hdr, msize);
620 if (NULL != 623 if (NULL !=
621 GNUNET_HELPER_send (endpoint->plugin->suid_helper, 624 GNUNET_HELPER_send (endpoint->plugin->suid_helper,
@@ -692,6 +695,7 @@ wlan_plugin_disconnect_session (void *cls,
692 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, 695 GNUNET_STATISTICS_update (endpoint->plugin->env->stats,
693 _("# WLAN sessions allocated"), -1, 696 _("# WLAN sessions allocated"), -1,
694 GNUNET_NO); 697 GNUNET_NO);
698 GNUNET_HELLO_address_free (session->address);
695 GNUNET_free (session); 699 GNUNET_free (session);
696 return GNUNET_OK; 700 return GNUNET_OK;
697} 701}
@@ -783,6 +787,9 @@ create_session (struct MacEndpoint *endpoint,
783 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head, 787 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
784 endpoint->sessions_tail, 788 endpoint->sessions_tail,
785 session); 789 session);
790 session->address = GNUNET_HELLO_address_allocate (peer, PLUGIN_NAME,
791 &endpoint->wlan_addr, sizeof (endpoint->wlan_addr),
792 (GNUNET_YES == inbound) ? GNUNET_HELLO_ADDRESS_INFO_INBOUND : GNUNET_HELLO_ADDRESS_INFO_NONE);
786 session->inbound = inbound; 793 session->inbound = inbound;
787 session->mac = endpoint; 794 session->mac = endpoint;
788 session->target = *peer; 795 session->target = *peer;
@@ -791,11 +798,10 @@ create_session (struct MacEndpoint *endpoint,
791 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session); 798 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session);
792 LOG (GNUNET_ERROR_TYPE_DEBUG, 799 LOG (GNUNET_ERROR_TYPE_DEBUG,
793 "Created new %s session %p for peer `%s' with endpoint %s\n", 800 "Created new %s session %p for peer `%s' with endpoint %s\n",
794
795 (GNUNET_YES == inbound) ? "inbound" : "outbound", 801 (GNUNET_YES == inbound) ? "inbound" : "outbound",
796 session, 802 session,
797 GNUNET_i2s (peer), 803 GNUNET_i2s (peer),
798 mac_to_string (endpoint->address->address)); 804 mac_to_string (&endpoint->wlan_addr.mac));
799 805
800 return session; 806 return session;
801} 807}
@@ -873,8 +879,8 @@ transmit_fragment (void *cls,
873 get_radiotap_header (endpoint, radio_header, size); 879 get_radiotap_header (endpoint, radio_header, size);
874 get_wlan_header (endpoint->plugin, 880 get_wlan_header (endpoint->plugin,
875 &radio_header->frame, 881 &radio_header->frame,
876 endpoint->address->address, 882 &endpoint->wlan_addr.mac,
877 endpoint->address->address_length); 883 sizeof (endpoint->wlan_addr.mac));
878 memcpy (&radio_header[1], hdr, msize); 884 memcpy (&radio_header[1], hdr, msize);
879 GNUNET_assert (NULL == fm->sh); 885 GNUNET_assert (NULL == fm->sh);
880 fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, 886 fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper,
@@ -1037,7 +1043,6 @@ free_macendpoint (struct MacEndpoint *endpoint)
1037 GNUNET_SCHEDULER_cancel (endpoint->timeout_task); 1043 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
1038 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1044 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1039 } 1045 }
1040 GNUNET_HELLO_address_free (endpoint->address);
1041 GNUNET_free (endpoint); 1046 GNUNET_free (endpoint);
1042} 1047}
1043 1048
@@ -1075,17 +1080,21 @@ macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1075 * @return handle to our data structure for this MAC 1080 * @return handle to our data structure for this MAC
1076 */ 1081 */
1077static struct MacEndpoint * 1082static struct MacEndpoint *
1078create_macendpoint (struct Plugin *plugin, 1083create_macendpoint (struct Plugin *plugin, struct WlanAddress *mac)
1079 const struct GNUNET_HELLO_Address *address)
1080{ 1084{
1081 struct MacEndpoint *pos; 1085 struct MacEndpoint *pos;
1082 1086
1083 for (pos = plugin->mac_head; NULL != pos; pos = pos->next) 1087 for (pos = plugin->mac_head; NULL != pos; pos = pos->next)
1084 if (0 == memcmp (address->address, pos->address->address, 1088 {
1085 pos->address->address_length)) 1089 if (0 == memcmp (mac, &pos->wlan_addr, sizeof (pos->wlan_addr)))
1090 {
1091 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing MAC endpoint `%s'\n",
1092 wlan_plugin_address_to_string(NULL, &pos->wlan_addr.mac, sizeof (pos->wlan_addr)));
1086 return pos; 1093 return pos;
1094 }
1095 }
1087 pos = GNUNET_new (struct MacEndpoint); 1096 pos = GNUNET_new (struct MacEndpoint);
1088 pos->address = GNUNET_HELLO_address_copy (address); 1097 pos->wlan_addr = (*mac);
1089 pos->plugin = plugin; 1098 pos->plugin = plugin;
1090 pos->defrag = 1099 pos->defrag =
1091 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU, 1100 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU,
@@ -1105,7 +1114,7 @@ create_macendpoint (struct Plugin *plugin,
1105 GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"), 1114 GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"),
1106 1, GNUNET_NO); 1115 1, GNUNET_NO);
1107 LOG (GNUNET_ERROR_TYPE_DEBUG, "New MAC endpoint `%s'\n", 1116 LOG (GNUNET_ERROR_TYPE_DEBUG, "New MAC endpoint `%s'\n",
1108 wlan_plugin_address_to_string(NULL, address->address, address->address_length)); 1117 wlan_plugin_address_to_string(NULL, &pos->wlan_addr, sizeof (struct WlanAddress)));
1109 return pos; 1118 return pos;
1110} 1119}
1111 1120
@@ -1152,7 +1161,7 @@ wlan_plugin_get_session (void *cls,
1152 "Service asked to create session for peer `%s' with MAC `%s'\n", 1161 "Service asked to create session for peer `%s' with MAC `%s'\n",
1153 GNUNET_i2s (&address->peer), 1162 GNUNET_i2s (&address->peer),
1154 wlan_plugin_address_to_string(NULL, address->address, address->address_length)); 1163 wlan_plugin_address_to_string(NULL, address->address, address->address_length));
1155 endpoint = create_macendpoint (plugin, address); 1164 endpoint = create_macendpoint (plugin, (struct WlanAddress *) address->address);
1156 return get_session (endpoint, &address->peer, GNUNET_NO); 1165 return get_session (endpoint, &address->peer, GNUNET_NO);
1157} 1166}
1158 1167
@@ -1285,30 +1294,39 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1285 switch (ntohs (hdr->type)) 1294 switch (ntohs (hdr->type))
1286 { 1295 {
1287 case GNUNET_MESSAGE_TYPE_HELLO: 1296 case GNUNET_MESSAGE_TYPE_HELLO:
1297
1288 if (GNUNET_OK != 1298 if (GNUNET_OK !=
1289 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource)) 1299 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hdr, &tmpsource))
1290 { 1300 {
1291 GNUNET_break_op (0); 1301 GNUNET_break_op (0);
1292 break; 1302 break;
1293 } 1303 }
1304 if (NULL == mas->endpoint)
1305 {
1306 GNUNET_break (0);
1307 break;
1308 }
1309
1294 LOG (GNUNET_ERROR_TYPE_DEBUG, 1310 LOG (GNUNET_ERROR_TYPE_DEBUG,
1295 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", 1311 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n",
1296 (unsigned int) msize, 1312 (unsigned int) msize,
1297 GNUNET_i2s (&tmpsource), 1313 GNUNET_i2s (&tmpsource),
1298 wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, mas->endpoint->address->address_length)); 1314 wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr, sizeof (mas->endpoint->wlan_addr)));
1299 1315
1300 GNUNET_STATISTICS_update (plugin->env->stats, 1316 GNUNET_STATISTICS_update (plugin->env->stats,
1301 _("# HELLO messages received via WLAN"), 1, 1317 _("# HELLO messages received via WLAN"), 1,
1302 GNUNET_NO); 1318 GNUNET_NO);
1303 1319
1320 address = GNUNET_HELLO_address_allocate (&tmpsource, PLUGIN_NAME,
1321 &mas->endpoint->wlan_addr, sizeof (mas->endpoint->wlan_addr),
1322 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
1304 plugin->env->receive (plugin->env->cls, 1323 plugin->env->receive (plugin->env->cls,
1305 mas->endpoint->address, 1324 address, mas->session, hdr);
1306 mas->session,
1307 hdr);
1308 plugin->env->update_address_metrics (plugin->env->cls, 1325 plugin->env->update_address_metrics (plugin->env->cls,
1309 mas->endpoint->address, 1326 address, mas->session, &ats, 1);
1310 mas->session, 1327 GNUNET_HELLO_address_free (address);
1311 &ats, 1); 1328
1329
1312 break; 1330 break;
1313 case GNUNET_MESSAGE_TYPE_FRAGMENT: 1331 case GNUNET_MESSAGE_TYPE_FRAGMENT:
1314 if (NULL == mas->endpoint) 1332 if (NULL == mas->endpoint)
@@ -1319,8 +1337,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1319 LOG (GNUNET_ERROR_TYPE_DEBUG, 1337 LOG (GNUNET_ERROR_TYPE_DEBUG,
1320 "Processing %u bytes of FRAGMENT from MAC %s\n", 1338 "Processing %u bytes of FRAGMENT from MAC %s\n",
1321 (unsigned int) msize, 1339 (unsigned int) msize,
1322 wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, 1340 wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr,
1323 mas->endpoint->address->address_length)); 1341 sizeof (mas->endpoint->wlan_addr)));
1324 GNUNET_STATISTICS_update (plugin->env->stats, 1342 GNUNET_STATISTICS_update (plugin->env->stats,
1325 _("# fragments received via WLAN"), 1, GNUNET_NO); 1343 _("# fragments received via WLAN"), 1, GNUNET_NO);
1326 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, 1344 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag,
@@ -1341,8 +1359,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1341 { 1359 {
1342 LOG (GNUNET_ERROR_TYPE_DEBUG, 1360 LOG (GNUNET_ERROR_TYPE_DEBUG,
1343 "Got last ACK, finished message transmission to `%s' (%p)\n", 1361 "Got last ACK, finished message transmission to `%s' (%p)\n",
1344 wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, 1362 wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr,
1345 mas->endpoint->address->address_length), 1363 sizeof (mas->endpoint->wlan_addr)),
1346 fm); 1364 fm);
1347 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); 1365 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT);
1348 if (NULL != fm->cont) 1366 if (NULL != fm->cont)
@@ -1357,15 +1375,15 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1357 { 1375 {
1358 LOG (GNUNET_ERROR_TYPE_DEBUG, 1376 LOG (GNUNET_ERROR_TYPE_DEBUG,
1359 "Got an ACK, message transmission to `%s' not yet finished\n", 1377 "Got an ACK, message transmission to `%s' not yet finished\n",
1360 wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, 1378 wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr,
1361 mas->endpoint->address->address_length)); 1379 sizeof (mas->endpoint->wlan_addr)));
1362 break; 1380 break;
1363 } 1381 }
1364 } 1382 }
1365 LOG (GNUNET_ERROR_TYPE_DEBUG, 1383 LOG (GNUNET_ERROR_TYPE_DEBUG,
1366 "ACK not matched against any active fragmentation with MAC `%s'\n", 1384 "ACK not matched against any active fragmentation with MAC `%s'\n",
1367 wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, 1385 wlan_plugin_address_to_string (NULL, &mas->endpoint->wlan_addr,
1368 mas->endpoint->address->address_length)); 1386 sizeof (mas->endpoint->wlan_addr)));
1369 break; 1387 break;
1370 case GNUNET_MESSAGE_TYPE_WLAN_DATA: 1388 case GNUNET_MESSAGE_TYPE_WLAN_DATA:
1371 if (NULL == mas->endpoint) 1389 if (NULL == mas->endpoint)
@@ -1401,7 +1419,7 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1401 { 1419 {
1402 xmas.session = create_session (mas->endpoint, &wlanheader->sender, GNUNET_YES); 1420 xmas.session = create_session (mas->endpoint, &wlanheader->sender, GNUNET_YES);
1403 address = GNUNET_HELLO_address_allocate (&wlanheader->sender, PLUGIN_NAME, 1421 address = GNUNET_HELLO_address_allocate (&wlanheader->sender, PLUGIN_NAME,
1404 &mas->endpoint->address, sizeof (struct WlanAddress), 1422 &mas->endpoint->wlan_addr, sizeof (struct WlanAddress),
1405 GNUNET_HELLO_ADDRESS_INFO_NONE); 1423 GNUNET_HELLO_ADDRESS_INFO_NONE);
1406 plugin->env->session_start (NULL, address, xmas.session, NULL, 0); 1424 plugin->env->session_start (NULL, address, xmas.session, NULL, 0);
1407 LOG (GNUNET_ERROR_TYPE_DEBUG, 1425 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1436,11 +1454,11 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
1436 (unsigned int) ntohs (hdr->type), 1454 (unsigned int) ntohs (hdr->type),
1437 GNUNET_i2s (&mas->session->target)); 1455 GNUNET_i2s (&mas->session->target));
1438 plugin->env->receive (plugin->env->cls, 1456 plugin->env->receive (plugin->env->cls,
1439 mas->session->mac->address, 1457 mas->session->address,
1440 mas->session, 1458 mas->session,
1441 hdr); 1459 hdr);
1442 plugin->env->update_address_metrics (plugin->env->cls, 1460 plugin->env->update_address_metrics (plugin->env->cls,
1443 mas->session->mac->address, 1461 mas->session->address,
1444 mas->session, 1462 mas->session,
1445 &ats, 1); 1463 &ats, 1);
1446 break; 1464 break;
@@ -1461,7 +1479,7 @@ handle_helper_message (void *cls, void *client,
1461 const struct GNUNET_MessageHeader *hdr) 1479 const struct GNUNET_MessageHeader *hdr)
1462{ 1480{
1463 struct Plugin *plugin = cls; 1481 struct Plugin *plugin = cls;
1464 struct GNUNET_HELLO_Address *address; 1482 struct GNUNET_HELLO_Address *my_address;
1465 const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo; 1483 const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo;
1466 const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm; 1484 const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm;
1467 struct WlanAddress wa; 1485 struct WlanAddress wa;
@@ -1488,10 +1506,10 @@ handle_helper_message (void *cls, void *client,
1488 memset (&wa, 0, sizeof (struct WlanAddress)); 1506 memset (&wa, 0, sizeof (struct WlanAddress));
1489 wa.mac = plugin->mac_address; 1507 wa.mac = plugin->mac_address;
1490 wa.options = htonl(plugin->options); 1508 wa.options = htonl(plugin->options);
1491 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1509 my_address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1492 PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE); 1510 PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE);
1493 plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); 1511 plugin->env->notify_address (plugin->env->cls, GNUNET_NO, my_address);
1494 GNUNET_HELLO_address_free (address); 1512 GNUNET_HELLO_address_free (my_address);
1495 } 1513 }
1496 plugin->mac_address = cm->mac; 1514 plugin->mac_address = cm->mac;
1497 plugin->have_mac = GNUNET_YES; 1515 plugin->have_mac = GNUNET_YES;
@@ -1499,15 +1517,15 @@ handle_helper_message (void *cls, void *client,
1499 memset (&wa, 0, sizeof (struct WlanAddress)); 1517 memset (&wa, 0, sizeof (struct WlanAddress));
1500 wa.mac = plugin->mac_address; 1518 wa.mac = plugin->mac_address;
1501 wa.options = htonl(plugin->options); 1519 wa.options = htonl(plugin->options);
1502 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1520 my_address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1503 PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE); 1521 PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE);
1504 1522
1505 LOG (GNUNET_ERROR_TYPE_DEBUG, 1523 LOG (GNUNET_ERROR_TYPE_DEBUG,
1506 "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n", 1524 "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n",
1507 mac_to_string (&cm->mac), 1525 mac_to_string (&cm->mac),
1508 GNUNET_i2s (plugin->env->my_identity)); 1526 GNUNET_i2s (plugin->env->my_identity));
1509 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); 1527 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, my_address);
1510 GNUNET_HELLO_address_free (address); 1528 GNUNET_HELLO_address_free (my_address);
1511 break; 1529 break;
1512 case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: 1530 case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER:
1513 LOG (GNUNET_ERROR_TYPE_DEBUG, 1531 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1557,12 +1575,7 @@ handle_helper_message (void *cls, void *client,
1557 mac_to_string (&rxinfo->frame.addr2)); 1575 mac_to_string (&rxinfo->frame.addr2));
1558 wa.mac = rxinfo->frame.addr2; 1576 wa.mac = rxinfo->frame.addr2;
1559 wa.options = htonl (0); 1577 wa.options = htonl (0);
1560 struct GNUNET_PeerIdentity dummy; 1578 mas.endpoint = create_macendpoint (plugin, &wa);
1561 memset (&dummy, '\0', sizeof (dummy));
1562 address = GNUNET_HELLO_address_allocate (&dummy, PLUGIN_NAME, &wa,
1563 sizeof (struct WlanAddress), GNUNET_HELLO_ADDRESS_INFO_NONE);
1564 mas.endpoint = create_macendpoint (plugin, address);
1565 GNUNET_HELLO_address_free (address);
1566 mas.session = NULL; 1579 mas.session = NULL;
1567 (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer, 1580 (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer,
1568 &mas, 1581 &mas,