aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-helper-transport-wlan.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-14 15:02:53 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-14 15:02:53 +0000
commit09923f6cb3e8ff97586824c57f34d7d38e0c0986 (patch)
tree66ade3702ca8500100acfa05b139cd463d456fee /src/transport/gnunet-helper-transport-wlan.c
parentf326fb85c52d9b7c13023c98795674c379269349 (diff)
downloadgnunet-09923f6cb3e8ff97586824c57f34d7d38e0c0986.tar.gz
gnunet-09923f6cb3e8ff97586824c57f34d7d38e0c0986.zip
-fixing some of the issues from #1939 -- untested
Diffstat (limited to 'src/transport/gnunet-helper-transport-wlan.c')
-rw-r--r--src/transport/gnunet-helper-transport-wlan.c86
1 files changed, 32 insertions, 54 deletions
diff --git a/src/transport/gnunet-helper-transport-wlan.c b/src/transport/gnunet-helper-transport-wlan.c
index 582df7cf5..03862cc1c 100644
--- a/src/transport/gnunet-helper-transport-wlan.c
+++ b/src/transport/gnunet-helper-transport-wlan.c
@@ -297,6 +297,10 @@ struct ieee80211_radiotap_header
297 * compatible new fields does not count. 297 * compatible new fields does not count.
298 */ 298 */
299 uint8_t it_version; 299 uint8_t it_version;
300
301 /**
302 *
303 */
300 uint8_t it_pad; 304 uint8_t it_pad;
301 305
302 /** 306 /**
@@ -375,23 +379,6 @@ static struct SendBuffer write_pout;
375static struct SendBuffer write_std; 379static struct SendBuffer write_std;
376 380
377 381
378GNUNET_NETWORK_STRUCT_BEGIN
379
380/**
381 * generic definitions for IEEE 802.11 frames
382 */
383struct ieee80211_frame
384{
385 uint8_t i_fc[2];
386 uint8_t i_dur[2];
387 uint8_t i_addr1[IEEE80211_ADDR_LEN];
388 uint8_t i_addr2[IEEE80211_ADDR_LEN];
389 uint8_t i_addr3[IEEE80211_ADDR_LEN];
390 uint8_t i_seq[2];
391 /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
392 /* see below */
393} GNUNET_PACKED;
394GNUNET_NETWORK_STRUCT_END
395 382
396 383
397/** 384/**
@@ -1439,19 +1426,19 @@ test_wlan_interface (const char *iface)
1439/** 1426/**
1440 * Function to test incoming packets mac for being our own. 1427 * Function to test incoming packets mac for being our own.
1441 * 1428 *
1442 * @param uint8_taIeeeHeader buffer of the packet 1429 * @param taIeeeHeader buffer of the packet
1443 * @param dev the Hardware_Infos struct 1430 * @param dev the Hardware_Infos struct
1444 * @return 0 if mac belongs to us, 1 if mac is for another target 1431 * @return 0 if mac belongs to us, 1 if mac is for another target
1445 */ 1432 */
1446static int 1433static int
1447mac_test (const struct ieee80211_frame *uint8_taIeeeHeader, 1434mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1448 const struct HardwareInfos *dev) 1435 const struct HardwareInfos *dev)
1449{ 1436{
1450 if (0 != memcmp (uint8_taIeeeHeader->i_addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE)) 1437 if (0 != memcmp (&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE))
1451 return 1; 1438 return 1;
1452 if (0 == memcmp (uint8_taIeeeHeader->i_addr1, &dev->pl_mac, MAC_ADDR_SIZE)) 1439 if (0 == memcmp (&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE))
1453 return 0; 1440 return 0;
1454 if (0 == memcmp (uint8_taIeeeHeader->i_addr1, &bc_all_mac, MAC_ADDR_SIZE)) 1441 if (0 == memcmp (&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE))
1455 return 0; 1442 return 0;
1456 return 1; 1443 return 1;
1457} 1444}
@@ -1459,17 +1446,16 @@ mac_test (const struct ieee80211_frame *uint8_taIeeeHeader,
1459 1446
1460/** 1447/**
1461 * function to set the wlan header to make attacks more difficult 1448 * function to set the wlan header to make attacks more difficult
1462 * @param uint8_taIeeeHeader pointer to the header of the packet 1449 * @param taIeeeHeader pointer to the header of the packet
1463 * @param dev pointer to the Hardware_Infos struct 1450 * @param dev pointer to the Hardware_Infos struct
1464 */ 1451 */
1465static void 1452static void
1466mac_set (struct ieee80211_frame *uint8_taIeeeHeader, 1453mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1467 const struct HardwareInfos *dev) 1454 const struct HardwareInfos *dev)
1468{ 1455{
1469 uint8_taIeeeHeader->i_fc[0] = 0x08; 1456 taIeeeHeader->frame_control = ntohs (0x08); // FIXME: need to shift by 8?
1470 uint8_taIeeeHeader->i_fc[1] = 0x00; 1457 taIeeeHeader->addr2 = dev->pl_mac;
1471 memcpy (uint8_taIeeeHeader->i_addr2, &dev->pl_mac, MAC_ADDR_SIZE); 1458 taIeeeHeader->addr3 = mac_bssid_gnunet;
1472 memcpy (uint8_taIeeeHeader->i_addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE);
1473} 1459}
1474 1460
1475 1461
@@ -1482,47 +1468,39 @@ static void
1482stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) 1468stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1483{ 1469{
1484 struct HardwareInfos *dev = cls; 1470 struct HardwareInfos *dev = cls;
1485 struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1]; 1471 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header;
1486 struct ieee80211_frame *wlanheader; 1472 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *wlanheader;
1487 size_t sendsize; 1473 size_t sendsize;
1488 struct RadioTapheader rtheader; 1474 struct RadioTapheader rtheader;
1489 1475
1490 rtheader.header.it_version = 0; /* radiotap version */
1491 rtheader.header.it_len = GNUNET_htole16 (0x0c); /* radiotap header length */
1492 rtheader.header.it_present = GNUNET_le16toh (0x00008004); /* our bitmap */
1493 rtheader.rate = 0x00;
1494 rtheader.pad1 = 0x00;
1495 rtheader.txflags =
1496 GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
1497
1498 sendsize = ntohs (hdr->size); 1476 sendsize = ntohs (hdr->size);
1499 if (sendsize < 1477 if ( (sendsize <
1500 sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader)) 1478 sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) ||
1479 (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type)) )
1501 { 1480 {
1502 fprintf (stderr, "Function stdin_send_hw: malformed packet (too small)\n"); 1481 fprintf (stderr, "Received malformed message\n");
1503 exit (1); 1482 exit (1);
1504 } 1483 }
1505 sendsize -= 1484 sendsize -= (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
1506 sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader);
1507
1508 if (MAXLINE < sendsize) 1485 if (MAXLINE < sendsize)
1509 { 1486 {
1510 fprintf (stderr, "Function stdin_send_hw: Packet too big for buffer\n"); 1487 fprintf (stderr, "Function stdin_send_hw: Packet too big for buffer\n");
1511 exit (1); 1488 exit (1);
1512 } 1489 }
1513 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type)) 1490 header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
1514 { 1491 rtheader.header.it_version = 0; /* radiotap version */
1515 fprintf (stderr, "Function stdin_send_hw: wrong packet type\n"); 1492 rtheader.header.it_len = GNUNET_htole16 (0x0c); /* radiotap header length */
1516 exit (1); 1493 rtheader.header.it_present = GNUNET_htole16 (0x00008004); /* our bitmap */
1517 } 1494 rtheader.rate = 0x00;
1518 1495 rtheader.pad1 = 0x00;
1496 rtheader.txflags = GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
1519 rtheader.header.it_len = GNUNET_htole16 (sizeof (rtheader)); 1497 rtheader.header.it_len = GNUNET_htole16 (sizeof (rtheader));
1520 rtheader.rate = header->rate; 1498 rtheader.rate = header->rate;
1521 memcpy (write_pout.buf, &rtheader, sizeof (rtheader)); 1499 memcpy (write_pout.buf, &rtheader, sizeof (rtheader));
1522 memcpy (write_pout.buf + sizeof (rtheader), &header[1], sendsize); 1500 wlanheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &write_pout.buf[sizeof (rtheader)];
1501 memcpy (wlanheader, &header->frame, sendsize);
1523 /* payload contains MAC address, but we don't trust it, so we'll 1502 /* payload contains MAC address, but we don't trust it, so we'll
1524 * overwrite it with OUR MAC address again to prevent mischief */ 1503 * overwrite it with OUR MAC address again to prevent mischief */
1525 wlanheader = (struct ieee80211_frame *) (write_pout.buf + sizeof (rtheader));
1526 mac_set (wlanheader, dev); 1504 mac_set (wlanheader, dev);
1527 write_pout.size = sendsize + sizeof (rtheader); 1505 write_pout.size = sendsize + sizeof (rtheader);
1528} 1506}
@@ -1723,12 +1701,12 @@ main (int argc, char *argv[])
1723 { 1701 {
1724 struct GNUNET_MessageHeader *header; 1702 struct GNUNET_MessageHeader *header;
1725 struct Radiotap_rx *rxinfo; 1703 struct Radiotap_rx *rxinfo;
1726 struct ieee80211_frame *datastart; 1704 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *datastart;
1727 ssize_t ret; 1705 ssize_t ret;
1728 1706
1729 header = (struct GNUNET_MessageHeader *) write_std.buf; 1707 header = (struct GNUNET_MessageHeader *) write_std.buf;
1730 rxinfo = (struct Radiotap_rx *) &header[1]; 1708 rxinfo = (struct Radiotap_rx *) &header[1];
1731 datastart = (struct ieee80211_frame *) &rxinfo[1]; 1709 datastart = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &rxinfo[1];
1732 ret = 1710 ret =
1733 linux_read (&dev, (unsigned char *) datastart, 1711 linux_read (&dev, (unsigned char *) datastart,
1734 sizeof (write_std.buf) - sizeof (struct Radiotap_rx) - 1712 sizeof (write_std.buf) - sizeof (struct Radiotap_rx) -