aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport-wlan-helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-transport-wlan-helper.c')
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c133
1 files changed, 56 insertions, 77 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index 4a5362b32..1f56830bc 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -213,7 +213,7 @@
213 * Number of unicast retries a transmitted frame used. 213 * Number of unicast retries a transmitted frame used.
214 * 214 *
215 */ 215 */
216enum ieee80211_radiotap_type 216enum RadiotapType
217{ 217{
218 IEEE80211_RADIOTAP_TSFT = 0, 218 IEEE80211_RADIOTAP_TSFT = 0,
219 IEEE80211_RADIOTAP_FLAGS = 1, 219 IEEE80211_RADIOTAP_FLAGS = 1,
@@ -321,7 +321,7 @@ struct RadioTapheader
321/** 321/**
322 * FIXME. 322 * FIXME.
323 */ 323 */
324struct sendbuf 324struct SendBuffer
325{ 325{
326 unsigned int pos; 326 unsigned int pos;
327 unsigned int size; 327 unsigned int size;
@@ -348,13 +348,13 @@ struct ieee80211_frame
348/** 348/**
349 * struct for storing the information of the hardware 349 * struct for storing the information of the hardware
350 */ 350 */
351struct Hardware_Infos 351struct HardwareInfos
352{ 352{
353 353
354 /** 354 /**
355 * send buffer 355 * send buffer
356 */ 356 */
357 struct sendbuf write_pout; 357 struct SendBuffer write_pout;
358 /** 358 /**
359 * file descriptor for the raw socket 359 * file descriptor for the raw socket
360 */ 360 */
@@ -406,17 +406,17 @@ struct ieee80211_radiotap_iterator
406 /** 406 /**
407 * pointer to the radiotap header we are walking through 407 * pointer to the radiotap header we are walking through
408 */ 408 */
409 struct ieee80211_radiotap_header *rtheader; 409 const struct ieee80211_radiotap_header *rtheader;
410 410
411 /** 411 /**
412 * length of radiotap header in cpu byte ordering 412 * length of radiotap header in cpu byte ordering
413 */ 413 */
414 int max_length; 414 size_t max_length;
415 415
416 /** 416 /**
417 * IEEE80211_RADIOTAP_... index of current arg 417 * IEEE80211_RADIOTAP_... index of current arg
418 */ 418 */
419 int this_arg_index; 419 unsigned int this_arg_index;
420 420
421 /** 421 /**
422 * pointer to current radiotap arg 422 * pointer to current radiotap arg
@@ -426,7 +426,7 @@ struct ieee80211_radiotap_iterator
426 /** 426 /**
427 * internal next argument index 427 * internal next argument index
428 */ 428 */
429 int arg_index; 429 unsigned int arg_index;
430 430
431 /** 431 /**
432 * internal next argument pointer 432 * internal next argument pointer
@@ -464,9 +464,9 @@ struct ieee80211_radiotap_iterator
464 * @param message the actual message 464 * @param message the actual message
465 */ 465 */
466typedef void (*MessageTokenizerCallback) (void *cls, 466typedef void (*MessageTokenizerCallback) (void *cls,
467 const struct 467 const struct
468 GNUNET_MessageHeader * 468 GNUNET_MessageHeader *
469 message); 469 message);
470 470
471/** 471/**
472 * Handle to a message stream tokenizer. 472 * Handle to a message stream tokenizer.
@@ -517,7 +517,7 @@ struct MessageStreamTokenizer
517 */ 517 */
518static struct MessageStreamTokenizer * 518static struct MessageStreamTokenizer *
519mst_create (MessageTokenizerCallback cb, 519mst_create (MessageTokenizerCallback cb,
520 void *cb_cls) 520 void *cb_cls)
521{ 521{
522 struct MessageStreamTokenizer *ret; 522 struct MessageStreamTokenizer *ret;
523 523
@@ -546,7 +546,7 @@ mst_create (MessageTokenizerCallback cb,
546 */ 546 */
547static int 547static int
548mst_receive (struct MessageStreamTokenizer *mst, 548mst_receive (struct MessageStreamTokenizer *mst,
549 const char *buf, size_t size) 549 const char *buf, size_t size)
550{ 550{
551 const struct GNUNET_MessageHeader *hdr; 551 const struct GNUNET_MessageHeader *hdr;
552 size_t delta; 552 size_t delta;
@@ -703,26 +703,30 @@ mst_destroy (struct MessageStreamTokenizer *mst)
703 * argument associated with the current argument index that is present, 703 * argument associated with the current argument index that is present,
704 * which can be found in the iterator's this_arg_index member. This arg 704 * which can be found in the iterator's this_arg_index member. This arg
705 * index corresponds to the IEEE80211_RADIOTAP_... defines. 705 * index corresponds to the IEEE80211_RADIOTAP_... defines.
706 *
707 * @param iterator iterator to initialize
708 * @param radiotap_header message to parse
709 * @param max_length number of valid bytes in radiotap_header
710 * @return 0 on success
706 */ 711 */
707static int 712static int
708ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator, 713ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator,
709 struct ieee80211_radiotap_header 714 const struct ieee80211_radiotap_header
710 *radiotap_header, int max_length) 715 *radiotap_header,
716 size_t max_length)
711{ 717{
712 if (iterator == NULL) 718 if ( (iterator == NULL) ||
713 return (-EINVAL); 719 (radiotap_header == NULL) )
720 return -EINVAL;
714 721
715 if (radiotap_header == NULL)
716 return (-EINVAL);
717 /* Linux only supports version 0 radiotap format */ 722 /* Linux only supports version 0 radiotap format */
718 723 if (0 != radiotap_header->it_version)
719 if (radiotap_header->it_version) 724 return -EINVAL;
720 return (-EINVAL);
721 725
722 /* sanity check for allowed length and radiotap length field */ 726 /* sanity check for allowed length and radiotap length field */
723 727 if ( (max_length < sizeof (struct ieee80211_radiotap_header)) ||
724 if (max_length < (GNUNET_le16toh (radiotap_header->it_len))) 728 (max_length < (GNUNET_le16toh (radiotap_header->it_len))) )
725 return (-EINVAL); 729 return -EINVAL;
726 730
727 iterator->rtheader = radiotap_header; 731 iterator->rtheader = radiotap_header;
728 iterator->max_length = GNUNET_le16toh (radiotap_header->it_len); 732 iterator->max_length = GNUNET_le16toh (radiotap_header->it_len);
@@ -733,7 +737,6 @@ ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator,
733 iterator->this_arg = 0; 737 iterator->this_arg = 0;
734 738
735 /* find payload start allowing for extended bitmap(s) */ 739 /* find payload start allowing for extended bitmap(s) */
736
737 if ((iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) 740 if ((iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK))
738 { 741 {
739 while (GNUNET_le32toh (*((uint32_t *) iterator->arg)) & 742 while (GNUNET_le32toh (*((uint32_t *) iterator->arg)) &
@@ -746,23 +749,16 @@ ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator,
746 * keep claiming to extend up to or even beyond the 749 * keep claiming to extend up to or even beyond the
747 * stated radiotap header length 750 * stated radiotap header length
748 */ 751 */
749 752 if (iterator->arg - ((uint8_t*) iterator->rtheader) > iterator->max_length)
750 if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) > 753 return -EINVAL;
751 iterator->max_length)
752 return (-EINVAL);
753
754 } 754 }
755
756 iterator->arg += sizeof (uint32_t); 755 iterator->arg += sizeof (uint32_t);
757
758 /* 756 /*
759 * no need to check again for blowing past stated radiotap 757 * no need to check again for blowing past stated radiotap
760 * header length, becuase ieee80211_radiotap_iterator_next 758 * header length, becuase ieee80211_radiotap_iterator_next
761 * checks it before it is dereferenced 759 * checks it before it is dereferenced
762 */ 760 */
763
764 } 761 }
765
766 /* we are all initialized happily */ 762 /* we are all initialized happily */
767 return 0; 763 return 0;
768} 764}
@@ -830,7 +826,7 @@ ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator *iterator)
830 * least skip (by knowing the length)... 826 * least skip (by knowing the length)...
831 */ 827 */
832 828
833 while (iterator->arg_index < (int) sizeof (rt_sizes)) 829 while (iterator->arg_index < sizeof (rt_sizes))
834 { 830 {
835 int hit = 0; 831 int hit = 0;
836 832
@@ -885,7 +881,7 @@ ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator *iterator)
885 881
886 if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) > 882 if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) >
887 iterator->max_length) 883 iterator->max_length)
888 return (-EINVAL); 884 return -EINVAL;
889 885
890next_entry: 886next_entry:
891 887
@@ -914,13 +910,12 @@ next_entry:
914 /* if we found a valid arg earlier, return it now */ 910 /* if we found a valid arg earlier, return it now */
915 911
916 if (hit) 912 if (hit)
917 return (iterator->this_arg_index); 913 return iterator->this_arg_index;
918 914
919 } 915 }
920 916
921 /* we don't know how to handle any more args, we're done */ 917 /* we don't know how to handle any more args, we're done */
922 918 return -1;
923 return (-1);
924} 919}
925 920
926 921
@@ -933,13 +928,11 @@ next_entry:
933static int 928static int
934send_mac_to_plugin (char *buffer, struct MacAddress *mac) 929send_mac_to_plugin (char *buffer, struct MacAddress *mac)
935{ 930{
936
937 struct Wlan_Helper_Control_Message macmsg; 931 struct Wlan_Helper_Control_Message macmsg;
938 932
939 memcpy (&macmsg.mac, (char *) mac, sizeof (struct MacAddress)); 933 memcpy (&macmsg.mac, (char *) mac, sizeof (struct MacAddress));
940 macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message)); 934 macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message));
941 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 935 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
942
943 memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message)); 936 memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message));
944 return sizeof (struct Wlan_Helper_Control_Message); 937 return sizeof (struct Wlan_Helper_Control_Message);
945} 938}
@@ -951,16 +944,15 @@ send_mac_to_plugin (char *buffer, struct MacAddress *mac)
951 * @return number of the channel 944 * @return number of the channel
952 */ 945 */
953static int 946static int
954getChannelFromFrequency (int frequency) 947get_channel_from_frequency (int frequency)
955{ 948{
956 if (frequency >= 2412 && frequency <= 2472) 949 if (frequency >= 2412 && frequency <= 2472)
957 return (frequency - 2407) / 5; 950 return (frequency - 2407) / 5;
958 else if (frequency == 2484) 951 if (frequency == 2484)
959 return 14; 952 return 14;
960 else if (frequency >= 5000 && frequency <= 6100) 953 if (frequency >= 5000 && frequency <= 6100)
961 return (frequency - 5000) / 5; 954 return (frequency - 5000) / 5;
962 else 955 return -1;
963 return -1;
964} 956}
965 957
966 958
@@ -1044,7 +1036,6 @@ calc_crc_osdep (const unsigned char *buf, size_t len)
1044 1036
1045 for (; len > 0; len--, buf++) 1037 for (; len > 0; len--, buf++)
1046 crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8); 1038 crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8);
1047
1048 return (~crc); 1039 return (~crc);
1049} 1040}
1050 1041
@@ -1076,7 +1067,7 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
1076 * @return channel number 1067 * @return channel number
1077 */ 1068 */
1078static int 1069static int
1079linux_get_channel (const struct Hardware_Infos *dev) 1070linux_get_channel (const struct HardwareInfos *dev)
1080{ 1071{
1081 struct iwreq wrq; 1072 struct iwreq wrq;
1082 int fd; 1073 int fd;
@@ -1084,9 +1075,7 @@ linux_get_channel (const struct Hardware_Infos *dev)
1084 int chan; 1075 int chan;
1085 1076
1086 memset (&wrq, 0, sizeof (struct iwreq)); 1077 memset (&wrq, 0, sizeof (struct iwreq));
1087
1088 strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ); 1078 strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
1089
1090 fd = dev->fd_raw; 1079 fd = dev->fd_raw;
1091 if (0 > ioctl (fd, SIOCGIWFREQ, &wrq)) 1080 if (0 > ioctl (fd, SIOCGIWFREQ, &wrq))
1092 return (-1); 1081 return (-1);
@@ -1096,12 +1085,10 @@ linux_get_channel (const struct Hardware_Infos *dev)
1096 frequency /= 100000; 1085 frequency /= 100000;
1097 else if (1000000 < frequency) 1086 else if (1000000 < frequency)
1098 frequency /= 1000; 1087 frequency /= 1000;
1099
1100 if (1000 < frequency) 1088 if (1000 < frequency)
1101 chan = getChannelFromFrequency (frequency); 1089 chan = get_channel_from_frequency (frequency);
1102 else 1090 else
1103 chan = frequency; 1091 chan = frequency;
1104
1105 return chan; 1092 return chan;
1106} 1093}
1107 1094
@@ -1115,7 +1102,7 @@ linux_get_channel (const struct Hardware_Infos *dev)
1115 * @return size read from the buffer 1102 * @return size read from the buffer
1116 */ 1103 */
1117static ssize_t 1104static ssize_t
1118linux_read (struct Hardware_Infos *dev, unsigned char *buf, size_t buf_size, 1105linux_read (struct HardwareInfos *dev, unsigned char *buf, size_t buf_size,
1119 struct Radiotap_rx *ri) 1106 struct Radiotap_rx *ri)
1120{ 1107{
1121 unsigned char tmpbuf[buf_size]; 1108 unsigned char tmpbuf[buf_size];
@@ -1304,7 +1291,7 @@ linux_read (struct Hardware_Infos *dev, unsigned char *buf, size_t buf_size,
1304 * @return 0 on success 1291 * @return 0 on success
1305 */ 1292 */
1306static int 1293static int
1307openraw (struct Hardware_Infos *dev) 1294open_device_raw (struct HardwareInfos *dev)
1308{ 1295{
1309 struct ifreq ifr; 1296 struct ifreq ifr;
1310 struct iwreq wrq; 1297 struct iwreq wrq;
@@ -1418,7 +1405,7 @@ openraw (struct Hardware_Infos *dev)
1418 * @return 0 on success 1405 * @return 0 on success
1419 */ 1406 */
1420static int 1407static int
1421wlaninit (struct Hardware_Infos *dev, const char *iface) 1408wlan_initialize (struct HardwareInfos *dev, const char *iface)
1422{ 1409{
1423 char strbuf[512]; 1410 char strbuf[512];
1424 struct stat sbuf; 1411 struct stat sbuf;
@@ -1449,7 +1436,7 @@ wlaninit (struct Hardware_Infos *dev, const char *iface)
1449 return 1; 1436 return 1;
1450 } 1437 }
1451 strncpy (dev->iface, iface, IFNAMSIZ); 1438 strncpy (dev->iface, iface, IFNAMSIZ);
1452 if (0 != openraw (dev)) 1439 if (0 != open_device_raw (dev))
1453 { 1440 {
1454 close (dev->fd_raw); 1441 close (dev->fd_raw);
1455 return 1; 1442 return 1;
@@ -1467,7 +1454,7 @@ wlaninit (struct Hardware_Infos *dev, const char *iface)
1467 */ 1454 */
1468static int 1455static int
1469mac_test (const struct ieee80211_frame *uint8_taIeeeHeader, 1456mac_test (const struct ieee80211_frame *uint8_taIeeeHeader,
1470 const struct Hardware_Infos *dev) 1457 const struct HardwareInfos *dev)
1471{ 1458{
1472 if (0 != memcmp (uint8_taIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE)) 1459 if (0 != memcmp (uint8_taIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE))
1473 return 1; 1460 return 1;
@@ -1486,7 +1473,7 @@ mac_test (const struct ieee80211_frame *uint8_taIeeeHeader,
1486 */ 1473 */
1487static void 1474static void
1488mac_set (struct ieee80211_frame *uint8_taIeeeHeader, 1475mac_set (struct ieee80211_frame *uint8_taIeeeHeader,
1489 const struct Hardware_Infos *dev) 1476 const struct HardwareInfos *dev)
1490{ 1477{
1491 uint8_taIeeeHeader->i_fc[0] = 0x08; 1478 uint8_taIeeeHeader->i_fc[0] = 0x08;
1492 uint8_taIeeeHeader->i_fc[1] = 0x00; 1479 uint8_taIeeeHeader->i_fc[1] = 0x00;
@@ -1503,29 +1490,21 @@ mac_set (struct ieee80211_frame *uint8_taIeeeHeader,
1503static void 1490static void
1504stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) 1491stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1505{ 1492{
1506 struct Hardware_Infos *dev = cls; 1493 struct HardwareInfos *dev = cls;
1507 struct sendbuf *write_pout = &dev->write_pout; 1494 struct SendBuffer *write_pout = &dev->write_pout;
1508 struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1]; 1495 struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1];
1509 struct ieee80211_frame *wlanheader; 1496 struct ieee80211_frame *wlanheader;
1510 size_t sendsize; 1497 size_t sendsize;
1511 struct RadioTapheader rtheader; 1498 struct RadioTapheader rtheader;
1512 1499
1513 rtheader.header.it_version = 0; 1500 rtheader.header.it_version = 0; /* radiotap version */
1514 rtheader.header.it_len = GNUNET_htole16 (0x0c); 1501 rtheader.header.it_len = GNUNET_htole16 (0x0c); /* radiotap header length */
1515 rtheader.header.it_present = GNUNET_le16toh (0x00008004); 1502 rtheader.header.it_present = GNUNET_le16toh (0x00008004); /* our bitmap */
1516 rtheader.rate = 0x00; 1503 rtheader.rate = 0x00;
1517 rtheader.pad1 = 0x00; 1504 rtheader.pad1 = 0x00;
1518 rtheader.txflags = 1505 rtheader.txflags =
1519 GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ); 1506 GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
1520 1507
1521 /* { 0x00, 0x00, <-- radiotap version
1522 * 0x0c, 0x00, <- radiotap header length
1523 * 0x04, 0x80, 0x00, 0x00, <-- bitmap
1524 * 0x00, <-- rate
1525 * 0x00, <-- padding for natural alignment
1526 * 0x18, 0x00, <-- TX flags
1527 * }; */
1528
1529 sendsize = ntohs (hdr->size); 1508 sendsize = ntohs (hdr->size);
1530 if (sendsize < 1509 if (sendsize <
1531 sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader)) 1510 sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader))
@@ -1543,7 +1522,7 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1543 } 1522 }
1544 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type)) 1523 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type))
1545 { 1524 {
1546 fprintf (stderr, "Function stdin_send: wrong packet type\n"); 1525 fprintf (stderr, "Function stdin_send_hw: wrong packet type\n");
1547 exit (1); 1526 exit (1);
1548 } 1527 }
1549 1528
@@ -1569,9 +1548,9 @@ int
1569main (int argc, char *argv[]) 1548main (int argc, char *argv[])
1570{ 1549{
1571 uid_t uid; 1550 uid_t uid;
1572 struct Hardware_Infos dev; 1551 struct HardwareInfos dev;
1573 char readbuf[MAXLINE]; 1552 char readbuf[MAXLINE];
1574 struct sendbuf write_std; 1553 struct SendBuffer write_std;
1575 ssize_t ret; 1554 ssize_t ret;
1576 int maxfd; 1555 int maxfd;
1577 fd_set rfds; 1556 fd_set rfds;
@@ -1586,7 +1565,7 @@ main (int argc, char *argv[])
1586 "You must specify the name of the interface as the first and only argument to this program.\n"); 1565 "You must specify the name of the interface as the first and only argument to this program.\n");
1587 return 1; 1566 return 1;
1588 } 1567 }
1589 if (0 != wlaninit (&dev, argv[1])) 1568 if (0 != wlan_initialize (&dev, argv[1]))
1590 return 1; 1569 return 1;
1591 uid = getuid (); 1570 uid = getuid ();
1592 if (0 != setresuid (uid, uid, uid)) 1571 if (0 != setresuid (uid, uid, uid))