diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-12-11 15:10:48 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-12-11 15:10:48 +0000 |
commit | f8ae79bdfd193320a1db1ff3ead82c5e19d5d4e6 (patch) | |
tree | 12acf2d9d90bc5c855b7ad0ef901e1dc44a91808 | |
parent | cea4dcd2549e3cec42c57e741f650578e7a039c9 (diff) | |
download | gnunet-f8ae79bdfd193320a1db1ff3ead82c5e19d5d4e6.tar.gz gnunet-f8ae79bdfd193320a1db1ff3ead82c5e19d5d4e6.zip |
-careful WLAN code cleanup
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 133 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 30 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.h | 146 |
3 files changed, 116 insertions, 193 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 | */ |
216 | enum ieee80211_radiotap_type | 216 | enum 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 | */ |
324 | struct sendbuf | 324 | struct 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 | */ |
351 | struct Hardware_Infos | 351 | struct 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 | */ |
466 | typedef void (*MessageTokenizerCallback) (void *cls, | 466 | typedef 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 | */ |
518 | static struct MessageStreamTokenizer * | 518 | static struct MessageStreamTokenizer * |
519 | mst_create (MessageTokenizerCallback cb, | 519 | mst_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 | */ |
547 | static int | 547 | static int |
548 | mst_receive (struct MessageStreamTokenizer *mst, | 548 | mst_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 | */ |
707 | static int | 712 | static int |
708 | ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator, | 713 | ieee80211_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 | ||
890 | next_entry: | 886 | next_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: | |||
933 | static int | 928 | static int |
934 | send_mac_to_plugin (char *buffer, struct MacAddress *mac) | 929 | send_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 | */ |
953 | static int | 946 | static int |
954 | getChannelFromFrequency (int frequency) | 947 | get_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 | */ |
1078 | static int | 1069 | static int |
1079 | linux_get_channel (const struct Hardware_Infos *dev) | 1070 | linux_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 | */ |
1117 | static ssize_t | 1104 | static ssize_t |
1118 | linux_read (struct Hardware_Infos *dev, unsigned char *buf, size_t buf_size, | 1105 | linux_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 | */ |
1306 | static int | 1293 | static int |
1307 | openraw (struct Hardware_Infos *dev) | 1294 | open_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 | */ |
1420 | static int | 1407 | static int |
1421 | wlaninit (struct Hardware_Infos *dev, const char *iface) | 1408 | wlan_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 | */ |
1468 | static int | 1455 | static int |
1469 | mac_test (const struct ieee80211_frame *uint8_taIeeeHeader, | 1456 | mac_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 | */ |
1487 | static void | 1474 | static void |
1488 | mac_set (struct ieee80211_frame *uint8_taIeeeHeader, | 1475 | mac_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, | |||
1503 | static void | 1490 | static void |
1504 | stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) | 1491 | stdin_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 | |||
1569 | main (int argc, char *argv[]) | 1548 | main (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)) |
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index b5961ae38..e2af0da36 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -399,6 +399,36 @@ struct Plugin_Session_pair | |||
399 | struct Session *session; | 399 | struct Session *session; |
400 | }; | 400 | }; |
401 | 401 | ||
402 | |||
403 | /** | ||
404 | * Header for messages which need fragmentation | ||
405 | */ | ||
406 | struct WlanHeader | ||
407 | { | ||
408 | |||
409 | struct GNUNET_MessageHeader header; | ||
410 | |||
411 | /** | ||
412 | * checksum/error correction | ||
413 | */ | ||
414 | uint32_t crc GNUNET_PACKED; | ||
415 | |||
416 | /** | ||
417 | * To whom are we talking to (set to our identity | ||
418 | * if we are still waiting for the welcome message) | ||
419 | */ | ||
420 | struct GNUNET_PeerIdentity target; | ||
421 | |||
422 | /** | ||
423 | * Where the packet came from | ||
424 | */ | ||
425 | struct GNUNET_PeerIdentity source; | ||
426 | |||
427 | // followed by payload | ||
428 | |||
429 | }; | ||
430 | |||
431 | |||
402 | /** | 432 | /** |
403 | * Information kept for each message that is yet to | 433 | * Information kept for each message that is yet to |
404 | * be transmitted. | 434 | * be transmitted. |
diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h index 7f6668cd3..5a88cb836 100644 --- a/src/transport/plugin_transport_wlan.h +++ b/src/transport/plugin_transport_wlan.h | |||
@@ -23,7 +23,6 @@ | |||
23 | * @brief header for transport plugin and the helper for wlan | 23 | * @brief header for transport plugin and the helper for wlan |
24 | * @author David Brodski | 24 | * @author David Brodski |
25 | */ | 25 | */ |
26 | |||
27 | #ifndef PLUGIN_TRANSPORT_WLAN | 26 | #ifndef PLUGIN_TRANSPORT_WLAN |
28 | #define PLUGIN_TRANSPORT_WLAN | 27 | #define PLUGIN_TRANSPORT_WLAN |
29 | 28 | ||
@@ -35,81 +34,47 @@ | |||
35 | */ | 34 | */ |
36 | #define MAC_ADDR_SIZE 6 | 35 | #define MAC_ADDR_SIZE 6 |
37 | 36 | ||
37 | /** | ||
38 | * A MAC Address. | ||
39 | */ | ||
38 | struct MacAddress | 40 | struct MacAddress |
39 | { | 41 | { |
40 | uint8_t mac[MAC_ADDR_SIZE]; | 42 | uint8_t mac[MAC_ADDR_SIZE]; |
41 | }; | 43 | }; |
42 | 44 | ||
43 | struct Wlan_Helper_Control_Message | ||
44 | { | ||
45 | struct GNUNET_MessageHeader hdr; | ||
46 | struct MacAddress mac; | ||
47 | }; | ||
48 | |||
49 | 45 | ||
50 | /** | 46 | /** |
51 | * Header for messages which need fragmentation | 47 | * Format of a WLAN Control Message. |
52 | */ | 48 | */ |
53 | struct WlanHeader | 49 | struct Wlan_Helper_Control_Message |
54 | { | 50 | { |
55 | |||
56 | struct GNUNET_MessageHeader header; | ||
57 | |||
58 | /** | ||
59 | * checksum/error correction | ||
60 | */ | ||
61 | uint32_t crc GNUNET_PACKED; | ||
62 | |||
63 | /** | 51 | /** |
64 | * To whom are we talking to (set to our identity | 52 | * Message header. FIXME: type? |
65 | * if we are still waiting for the welcome message) | ||
66 | */ | 53 | */ |
67 | struct GNUNET_PeerIdentity target; | 54 | struct GNUNET_MessageHeader hdr; |
68 | 55 | ||
69 | /** | 56 | /** |
70 | * Where the packet came from | 57 | * MAC Address. FIXME: of what? |
71 | */ | 58 | */ |
72 | struct GNUNET_PeerIdentity source; | 59 | struct MacAddress mac; |
73 | |||
74 | // followed by payload | ||
75 | |||
76 | }; | 60 | }; |
77 | 61 | ||
78 | /* Wlan IEEE80211 header default */ | ||
79 | //Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html | ||
80 | static const uint8_t u8aIeeeHeader[] = { 0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0; | ||
81 | // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data | ||
82 | // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS; | ||
83 | 0x00, 0x00, // Duration/ID | ||
84 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver | ||
85 | 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender | ||
86 | 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid | ||
87 | 0x10, 0x86, //Sequence Control | ||
88 | }; | ||
89 | 62 | ||
90 | // gnunet bssid | 63 | /** |
64 | * GNUnet bssid | ||
65 | */ | ||
91 | static const struct MacAddress mac_bssid = { | 66 | static const struct MacAddress mac_bssid = { |
92 | {0x13, 0x22, 0x33, 0x44, 0x55, 0x66} | 67 | {0x13, 0x22, 0x33, 0x44, 0x55, 0x66} |
93 | }; | 68 | }; |
94 | 69 | ||
95 | // broadcast mac | 70 | |
71 | /** | ||
72 | * Broadcast MAC | ||
73 | */ | ||
96 | static const struct MacAddress bc_all_mac = { | 74 | static const struct MacAddress bc_all_mac = { |
97 | {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} | 75 | {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} |
98 | }; | 76 | }; |
99 | 77 | ||
100 | /* this is the template radiotap header we send packets out with */ | ||
101 | |||
102 | static const uint8_t u8aRadiotapHeader[] = { 0x00, 0x00, // <-- radiotap version | ||
103 | 0x19, 0x00, // <- radiotap header length | ||
104 | 0x6f, 0x08, 0x00, 0x00, // <-- bitmap | ||
105 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp | ||
106 | 0x00, // <-- flags (Offset +0x10) | ||
107 | 0x6c, // <-- rate (0ffset +0x11) | ||
108 | 0x71, 0x09, 0xc0, 0x00, // <-- channel | ||
109 | 0xde, // <-- antsignal | ||
110 | 0x00, // <-- antnoise | ||
111 | 0x01, // <-- antenna | ||
112 | }; | ||
113 | 78 | ||
114 | struct Radiotap_Send | 79 | struct Radiotap_Send |
115 | { | 80 | { |
@@ -119,7 +84,7 @@ struct Radiotap_Send | |||
119 | uint8_t rate; | 84 | uint8_t rate; |
120 | 85 | ||
121 | /** | 86 | /** |
122 | * antenna | 87 | * Antenna; the first antenna is 0. |
123 | */ | 88 | */ |
124 | uint8_t antenna; | 89 | uint8_t antenna; |
125 | 90 | ||
@@ -127,111 +92,60 @@ struct Radiotap_Send | |||
127 | * Transmit power expressed as unitless distance from max power set at factory calibration. | 92 | * Transmit power expressed as unitless distance from max power set at factory calibration. |
128 | * 0 is max power. Monotonically nondecreasing with lower power levels. | 93 | * 0 is max power. Monotonically nondecreasing with lower power levels. |
129 | */ | 94 | */ |
130 | |||
131 | uint16_t tx_power; | 95 | uint16_t tx_power; |
132 | }; | 96 | }; |
133 | 97 | ||
134 | // bit field defines for ri_present | ||
135 | |||
136 | #define has_noise 1 | ||
137 | #define has_power 2 | ||
138 | #define has_channel 4 | ||
139 | 98 | ||
140 | /** | 99 | /** |
141 | * struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos | 100 | * struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos |
142 | */ | 101 | */ |
143 | |||
144 | struct Radiotap_rx | 102 | struct Radiotap_rx |
145 | { | 103 | { |
104 | /** | ||
105 | * FIXME: not initialized properly so far. (supposed to contain | ||
106 | * information about which of the fields below are actually valid). | ||
107 | */ | ||
146 | uint32_t ri_present; | 108 | uint32_t ri_present; |
109 | |||
147 | /** | 110 | /** |
148 | * IEEE80211_RADIOTAP_TSFT | 111 | * IEEE80211_RADIOTAP_TSFT |
149 | */ | 112 | */ |
150 | uint64_t ri_mactime; | 113 | uint64_t ri_mactime; |
114 | |||
151 | /** | 115 | /** |
152 | * from radiotap | 116 | * from radiotap |
153 | * either IEEE80211_RADIOTAP_DBM_ANTSIGNAL | 117 | * either IEEE80211_RADIOTAP_DBM_ANTSIGNAL |
154 | * or IEEE80211_RADIOTAP_DB_ANTSIGNAL | 118 | * or IEEE80211_RADIOTAP_DB_ANTSIGNAL |
155 | */ | 119 | */ |
156 | int32_t ri_power; | 120 | int32_t ri_power; |
121 | |||
157 | /** | 122 | /** |
158 | * either IEEE80211_RADIOTAP_DBM_ANTNOISE | 123 | * either IEEE80211_RADIOTAP_DBM_ANTNOISE |
159 | * or IEEE80211_RADIOTAP_DB_ANTNOISE | 124 | * or IEEE80211_RADIOTAP_DB_ANTNOISE |
160 | */ | 125 | */ |
161 | int32_t ri_noise; | 126 | int32_t ri_noise; |
127 | |||
162 | /** | 128 | /** |
163 | * IEEE80211_RADIOTAP_CHANNEL | 129 | * IEEE80211_RADIOTAP_CHANNEL |
164 | */ | 130 | */ |
165 | uint32_t ri_channel; | 131 | uint32_t ri_channel; |
166 | 132 | ||
133 | /** | ||
134 | * Frequency we use. FIXME: not properly initialized so far! | ||
135 | */ | ||
167 | uint32_t ri_freq; | 136 | uint32_t ri_freq; |
137 | |||
168 | /** | 138 | /** |
169 | * IEEE80211_RADIOTAP_RATE * 50000 | 139 | * IEEE80211_RADIOTAP_RATE * 50000 |
170 | */ | 140 | */ |
171 | uint32_t ri_rate; | 141 | uint32_t ri_rate; |
142 | |||
172 | /** | 143 | /** |
173 | * IEEE80211_RADIOTAP_ANTENNA | 144 | * IEEE80211_RADIOTAP_ANTENNA |
174 | */ | 145 | */ |
175 | uint32_t ri_antenna; | 146 | uint32_t ri_antenna; |
176 | }; | 147 | }; |
177 | 148 | ||
178 | /** | ||
179 | * Radiotap Header | ||
180 | */ | ||
181 | struct RadiotapHeader | ||
182 | { | ||
183 | /** | ||
184 | * radiotap version | ||
185 | */ | ||
186 | u_int8_t version; | ||
187 | |||
188 | u_int8_t pad_version; | ||
189 | |||
190 | /** | ||
191 | * radiotap header length | ||
192 | */ | ||
193 | uint16_t length GNUNET_PACKED; | ||
194 | |||
195 | /** | ||
196 | * bitmap, fields present | ||
197 | */ | ||
198 | uint32_t bitmap GNUNET_PACKED; | ||
199 | |||
200 | /** | ||
201 | * timestamp | ||
202 | */ | ||
203 | uint64_t timestamp GNUNET_PACKED; | ||
204 | |||
205 | /** | ||
206 | * radiotap flags | ||
207 | */ | ||
208 | uint8_t flags; | ||
209 | 149 | ||
210 | /** | ||
211 | * wlan send rate | ||
212 | */ | ||
213 | uint8_t rate; | ||
214 | |||
215 | // FIXME: unaligned here, is this OK? | ||
216 | /** | ||
217 | * Wlan channel | ||
218 | */ | ||
219 | uint32_t channel GNUNET_PACKED; | ||
220 | |||
221 | /** | ||
222 | * antsignal | ||
223 | */ | ||
224 | uint8_t antsignal; | ||
225 | |||
226 | /** | ||
227 | * antnoise | ||
228 | */ | ||
229 | uint8_t antnoise; | ||
230 | |||
231 | /** | ||
232 | * antenna | ||
233 | */ | ||
234 | uint8_t antenna; | ||
235 | }; | ||
236 | 150 | ||
237 | #endif | 151 | #endif |