diff options
author | David Brodski <david@brodski.eu> | 2011-03-23 12:00:20 +0000 |
---|---|---|
committer | David Brodski <david@brodski.eu> | 2011-03-23 12:00:20 +0000 |
commit | 5598af2681b330ef126664e835f02f750b1491cd (patch) | |
tree | d1fd74e6626982d30b76c868f08aa57188293b37 | |
parent | 3d36dbbfc2c9534a43272d96b5a43e893d768762 (diff) | |
download | gnunet-5598af2681b330ef126664e835f02f750b1491cd.tar.gz gnunet-5598af2681b330ef126664e835f02f750b1491cd.zip |
an error and some changes for the hardware
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 274 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 2 |
2 files changed, 262 insertions, 14 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index 214afe0b7..088a1fc85 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c | |||
@@ -301,7 +301,11 @@ int ieee80211_radiotap_iterator_next( | |||
301 | [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11, | 301 | [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11, |
302 | [IEEE80211_RADIOTAP_ANTENNA] = 0x11, | 302 | [IEEE80211_RADIOTAP_ANTENNA] = 0x11, |
303 | [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11, | 303 | [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11, |
304 | [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11 | 304 | [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11, |
305 | [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22, | ||
306 | [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22, | ||
307 | [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11, | ||
308 | [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11 | ||
305 | /* | 309 | /* |
306 | * add more here as they are defined in | 310 | * add more here as they are defined in |
307 | * include/net/ieee80211_radiotap.h | 311 | * include/net/ieee80211_radiotap.h |
@@ -478,6 +482,28 @@ file_in_send (void *cls, | |||
478 | write_std->size += sendsize; | 482 | write_std->size += sendsize; |
479 | } | 483 | } |
480 | 484 | ||
485 | /** | ||
486 | * function to create GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL message for plugin | ||
487 | * @param buffer pointer to buffer for the message | ||
488 | * @param mac pointer to the mac address | ||
489 | * @return number of bytes written | ||
490 | */ | ||
491 | |||
492 | int | ||
493 | send_mac_to_plugin(char* buffer, char * mac){ | ||
494 | |||
495 | struct Wlan_Helper_Control_Message macmsg; | ||
496 | |||
497 | |||
498 | |||
499 | memcpy(macmsg.mac.mac, mac, sizeof(struct MacAddress)); | ||
500 | macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message)); | ||
501 | macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); | ||
502 | |||
503 | memcpy(buffer, &macmsg, sizeof(struct Wlan_Helper_Control_Message)); | ||
504 | return sizeof(struct Wlan_Helper_Control_Message); | ||
505 | } | ||
506 | |||
481 | int | 507 | int |
482 | testmode(int argc, char *argv[]) | 508 | testmode(int argc, char *argv[]) |
483 | { | 509 | { |
@@ -599,20 +625,17 @@ testmode(int argc, char *argv[]) | |||
599 | 625 | ||
600 | //send mac first | 626 | //send mac first |
601 | 627 | ||
602 | struct Wlan_Helper_Control_Message macmsg; | 628 | struct MacAddress macaddr; |
603 | 629 | ||
604 | //Send random mac address | 630 | //Send random mac address |
605 | macmsg.mac.mac[0] = 0x13; | 631 | macaddr.mac[0] = 0x13; |
606 | macmsg.mac.mac[1] = 0x22; | 632 | macaddr.mac[1] = 0x22; |
607 | macmsg.mac.mac[2] = 0x33; | 633 | macaddr.mac[2] = 0x33; |
608 | macmsg.mac.mac[3] = 0x44; | 634 | macaddr.mac[3] = 0x44; |
609 | macmsg.mac.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256); | 635 | macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256); |
610 | macmsg.mac.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256); | 636 | macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256); |
611 | macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message)); | ||
612 | macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); | ||
613 | 637 | ||
614 | memcpy(&write_std.buf, &macmsg, sizeof(struct Wlan_Helper_Control_Message)); | 638 | write_std.size = send_mac_to_plugin((char *) &write_std.buf, macaddr.mac); |
615 | write_std.size = sizeof(struct Wlan_Helper_Control_Message); | ||
616 | 639 | ||
617 | /* | 640 | /* |
618 | //wait | 641 | //wait |
@@ -812,6 +835,229 @@ testmode(int argc, char *argv[]) | |||
812 | return (0); | 835 | return (0); |
813 | } | 836 | } |
814 | 837 | ||
838 | void packet_callback(unsigned char *Args, | ||
839 | const struct pcap_pkthdr* Pkthdr, | ||
840 | unsigned char *Packet) | ||
841 | { | ||
842 | fprintf(stderr, "+"); fflush(stderr); | ||
843 | } | ||
844 | |||
845 | |||
846 | int | ||
847 | hardwaremode(int argc, char *argv[]) | ||
848 | { | ||
849 | |||
850 | struct ifreq ifreq; | ||
851 | char mac[6]; | ||
852 | int SockFD; | ||
853 | |||
854 | int fdpin; | ||
855 | int fdpout; | ||
856 | |||
857 | pcap_t *ppcap = NULL; | ||
858 | char szErrbuf[PCAP_ERRBUF_SIZE]; | ||
859 | |||
860 | SockFD = socket(AF_INET, SOCK_DGRAM, 0); | ||
861 | |||
862 | strcpy(ifreq.ifr_name, argv[1]); | ||
863 | if (ioctl(SockFD, SIOCGIFHWADDR, &ifreq) < 0) | ||
864 | { | ||
865 | printf("SIOCGIFHWADDR(%s): %m\n", ifreq.ifr_name); | ||
866 | return 0; | ||
867 | } | ||
868 | |||
869 | //copy mac to mac array | ||
870 | memcpy(mac, ifreq.ifr_hwaddr.sa_data, sizeof(struct MacAddress)); | ||
871 | |||
872 | printf("Device %s -> Ethernet %02x:%02x:%02x:%02x:%02x:%02x\n", | ||
873 | ifreq.ifr_name, (int) mac[0], (int) mac[1], (int) mac[2], (int) mac[3], | ||
874 | (int) mac[4], (int) mac[5]); | ||
875 | |||
876 | return 0; | ||
877 | // open the interface in pcap | ||
878 | ppcap = pcap_open_live(argv[1], 800, 1, 20, szErrbuf); | ||
879 | if (ppcap == NULL) | ||
880 | { | ||
881 | printf("Unable to open interface %s in pcap: %s\n", argv[1], szErrbuf); | ||
882 | return (1); | ||
883 | } | ||
884 | |||
885 | char readbuf[MAXLINE]; | ||
886 | int readsize = 0; | ||
887 | struct sendbuf write_std; | ||
888 | write_std.size = 0; | ||
889 | write_std.pos = 0; | ||
890 | |||
891 | struct sendbuf write_pout; | ||
892 | write_pout.size = 0; | ||
893 | write_pout.pos = 0; | ||
894 | |||
895 | int ret = 0; | ||
896 | int maxfd = 0; | ||
897 | |||
898 | fd_set rfds; | ||
899 | fd_set wfds; | ||
900 | struct timeval tv; | ||
901 | int retval; | ||
902 | |||
903 | struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; | ||
904 | struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst; | ||
905 | |||
906 | fdpin = pcap_fileno(ppcap); | ||
907 | fdpout = pcap_fileno(ppcap); | ||
908 | |||
909 | stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout); | ||
910 | file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std); | ||
911 | |||
912 | //send mac first | ||
913 | |||
914 | write_std.size = send_mac_to_plugin((char *) &write_std.buf, mac); | ||
915 | |||
916 | //wait | ||
917 | tv.tv_sec = 2; | ||
918 | tv.tv_usec = 0; | ||
919 | retval = select(0, NULL, NULL, NULL, &tv); | ||
920 | |||
921 | while (0 == closeprog) | ||
922 | { | ||
923 | |||
924 | maxfd = 0; | ||
925 | |||
926 | //set timeout | ||
927 | tv.tv_sec = 5; | ||
928 | tv.tv_usec = 0; | ||
929 | |||
930 | FD_ZERO(&rfds); | ||
931 | // if output queue is empty | ||
932 | if (0 == write_pout.size) | ||
933 | { | ||
934 | FD_SET(STDIN_FILENO, &rfds); | ||
935 | |||
936 | } | ||
937 | if (0 == write_std.size) | ||
938 | { | ||
939 | FD_SET(fdpin, &rfds); | ||
940 | maxfd = fdpin; | ||
941 | } | ||
942 | FD_ZERO(&wfds); | ||
943 | // if there is something to write | ||
944 | if (0 < write_std.size) | ||
945 | { | ||
946 | FD_SET(STDOUT_FILENO, &wfds); | ||
947 | maxfd = MAX(maxfd, STDOUT_FILENO); | ||
948 | } | ||
949 | |||
950 | if (0 < write_pout.size) | ||
951 | { | ||
952 | FD_SET(fdpout, &wfds); | ||
953 | maxfd = MAX(maxfd, fdpout); | ||
954 | } | ||
955 | |||
956 | retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv); | ||
957 | |||
958 | if (-1 == retval && EINTR == errno) | ||
959 | { | ||
960 | continue; | ||
961 | } | ||
962 | if (0 > retval) | ||
963 | { | ||
964 | fprintf(stderr, "select failed: %s\n", strerror(errno)); | ||
965 | exit(1); | ||
966 | } | ||
967 | |||
968 | if (FD_ISSET(STDOUT_FILENO, &wfds)) | ||
969 | { | ||
970 | ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, | ||
971 | write_std.size - write_std.pos); | ||
972 | |||
973 | if (0 > ret) | ||
974 | { | ||
975 | closeprog = 1; | ||
976 | fprintf(stderr, "Write ERROR to STDOUT\n"); | ||
977 | exit(1); | ||
978 | } | ||
979 | else | ||
980 | { | ||
981 | write_std.pos += ret; | ||
982 | // check if finished | ||
983 | if (write_std.pos == write_std.size) | ||
984 | { | ||
985 | write_std.pos = 0; | ||
986 | write_std.size = 0; | ||
987 | } | ||
988 | } | ||
989 | } | ||
990 | |||
991 | if (FD_ISSET(fdpout, &wfds)) | ||
992 | { | ||
993 | ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size | ||
994 | - write_pout.pos); | ||
995 | |||
996 | if (0 > ret) | ||
997 | { | ||
998 | closeprog = 1; | ||
999 | fprintf(stderr, "Write ERROR to fdpout\n"); | ||
1000 | } | ||
1001 | else | ||
1002 | { | ||
1003 | write_pout.pos += ret; | ||
1004 | // check if finished | ||
1005 | if (write_pout.pos == write_pout.size) | ||
1006 | { | ||
1007 | write_pout.pos = 0; | ||
1008 | write_pout.size = 0; | ||
1009 | } | ||
1010 | } | ||
1011 | } | ||
1012 | |||
1013 | if (FD_ISSET(STDIN_FILENO, &rfds)) | ||
1014 | { | ||
1015 | readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf)); | ||
1016 | |||
1017 | if (0 > readsize) | ||
1018 | { | ||
1019 | closeprog = 1; | ||
1020 | fprintf(stderr, "Read ERROR to STDIN_FILENO\n"); | ||
1021 | } | ||
1022 | else if (0 < readsize) | ||
1023 | { | ||
1024 | GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize, | ||
1025 | GNUNET_NO, GNUNET_NO); | ||
1026 | |||
1027 | } | ||
1028 | else | ||
1029 | { | ||
1030 | //eof | ||
1031 | closeprog = 1; | ||
1032 | } | ||
1033 | } | ||
1034 | |||
1035 | if (FD_ISSET(fdpin, &rfds)) | ||
1036 | { | ||
1037 | readsize = read(fdpin, readbuf, sizeof(readbuf)); | ||
1038 | |||
1039 | if (0 > readsize) | ||
1040 | { | ||
1041 | closeprog = 1; | ||
1042 | fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno)); | ||
1043 | closeprog = 1; | ||
1044 | } | ||
1045 | else if (0 < readsize) | ||
1046 | { | ||
1047 | GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize, | ||
1048 | GNUNET_NO, GNUNET_NO); | ||
1049 | |||
1050 | } | ||
1051 | else | ||
1052 | { | ||
1053 | //eof | ||
1054 | closeprog = 1; | ||
1055 | } | ||
1056 | } | ||
1057 | |||
1058 | } | ||
1059 | |||
1060 | } | ||
815 | 1061 | ||
816 | int | 1062 | int |
817 | main(int argc, char *argv[]) | 1063 | main(int argc, char *argv[]) |
@@ -828,6 +1074,8 @@ main(int argc, char *argv[]) | |||
828 | { | 1074 | { |
829 | 1075 | ||
830 | return testmode(argc, argv); | 1076 | return testmode(argc, argv); |
1077 | } else { | ||
1078 | hardwaremode(argc, argv); | ||
831 | } | 1079 | } |
832 | 1080 | ||
833 | #if 0 | 1081 | #if 0 |
@@ -928,7 +1176,7 @@ main(int argc, char *argv[]) | |||
928 | 1176 | ||
929 | //get header type | 1177 | //get header type |
930 | nLinkEncap = pcap_datalink(ppcap); | 1178 | nLinkEncap = pcap_datalink(ppcap); |
931 | nCaptureHeaderLength = 0;home/mwachs/gnb/bin/ | 1179 | nCaptureHeaderLength = 0; |
932 | 1180 | ||
933 | switch (nLinkEncap) { | 1181 | switch (nLinkEncap) { |
934 | 1182 | ||
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 988ffed13..b96414a71 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -2801,7 +2801,7 @@ wlan_process_helper(void *cls, void *client, | |||
2801 | wlan_plugin_address_to_string(cls, &(plugin->mac_address), ntohs( | 2801 | wlan_plugin_address_to_string(cls, &(plugin->mac_address), ntohs( |
2802 | hdr->size) - sizeof(struct GNUNET_MessageHeader))); | 2802 | hdr->size) - sizeof(struct GNUNET_MessageHeader))); |
2803 | plugin->env->notify_address(plugin->env->cls, "wlan", | 2803 | plugin->env->notify_address(plugin->env->cls, "wlan", |
2804 | &plugin->mac_address, sizeof(struct MacAddress), | 2804 | &plugin->mac_address.mac, sizeof(struct MacAddress), |
2805 | GNUNET_TIME_UNIT_FOREVER_REL); | 2805 | GNUNET_TIME_UNIT_FOREVER_REL); |
2806 | } | 2806 | } |
2807 | else | 2807 | else |