diff options
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 106 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 452 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.h | 61 | ||||
-rw-r--r-- | src/transport/wlan/loopback_helper.c | 26 |
4 files changed, 363 insertions, 282 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index 9111a6666..6d1e4640a 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c | |||
@@ -259,14 +259,6 @@ usage() | |||
259 | exit(1); | 259 | exit(1); |
260 | } | 260 | } |
261 | 261 | ||
262 | void | ||
263 | packet_callback(unsigned char *Args, const struct pcap_pkthdr* Pkthdr, | ||
264 | unsigned char *Packet) | ||
265 | { | ||
266 | fprintf(stderr, "+"); | ||
267 | fflush(stderr); | ||
268 | } | ||
269 | |||
270 | unsigned long | 262 | unsigned long |
271 | calc_crc_osdep(unsigned char * buf, int len) | 263 | calc_crc_osdep(unsigned char * buf, int len) |
272 | { | 264 | { |
@@ -410,7 +402,7 @@ linux_get_channel(struct Hardware_Infos *dev) | |||
410 | 402 | ||
411 | static int | 403 | static int |
412 | linux_read(struct Hardware_Infos * dev, unsigned char *buf, int count, | 404 | linux_read(struct Hardware_Infos * dev, unsigned char *buf, int count, |
413 | struct rx_info * ri) | 405 | struct Radiotap_rx * ri) |
414 | { | 406 | { |
415 | unsigned char tmpbuf[4096]; | 407 | unsigned char tmpbuf[4096]; |
416 | 408 | ||
@@ -867,12 +859,62 @@ wlaninit(struct Hardware_Infos * dev, char *iface) | |||
867 | return 1; | 859 | return 1; |
868 | } | 860 | } |
869 | 861 | ||
862 | /** | ||
863 | * function to test incoming packets mac | ||
864 | * @param buf buffer of the packet | ||
865 | * @param dev pointer to the Hardware_Infos struct | ||
866 | * @return 0 if macs are okay, 1 if macs are wrong | ||
867 | */ | ||
868 | |||
869 | static int | ||
870 | mac_test(unsigned char * buf, struct Hardware_Infos * dev) | ||
871 | { | ||
872 | struct ieee80211_frame * u8aIeeeHeader; | ||
873 | u8aIeeeHeader = (struct ieee80211_frame *) buf; | ||
874 | if (0 == memcmp(u8aIeeeHeader->i_addr3, mac_bssid, 6)) | ||
875 | { | ||
876 | if (0 == memcmp(u8aIeeeHeader->i_addr2, dev->pl_mac, 6)) | ||
877 | { | ||
878 | return 0; | ||
879 | } | ||
880 | |||
881 | if (0 == memcmp(u8aIeeeHeader->i_addr2, bc_all_mac, 6)) | ||
882 | { | ||
883 | return 0; | ||
884 | } | ||
885 | } | ||
886 | |||
887 | return 1; | ||
888 | } | ||
889 | |||
890 | /** | ||
891 | * function to set the wlan header to make attacks more difficult | ||
892 | * @param buf buffer of the packet | ||
893 | * @param dev pointer to the Hardware_Infos struct | ||
894 | */ | ||
895 | |||
896 | static void | ||
897 | mac_set(unsigned char * buf, struct Hardware_Infos * dev) | ||
898 | { | ||
899 | struct ieee80211_frame * u8aIeeeHeader; | ||
900 | u8aIeeeHeader = (struct ieee80211_frame *) buf; | ||
901 | |||
902 | u8aIeeeHeader->i_fc[0] = 0x80; | ||
903 | u8aIeeeHeader->i_fc[1] = 0x00; | ||
904 | |||
905 | memcpy(u8aIeeeHeader->i_addr2, dev->pl_mac, 6); | ||
906 | memcpy(u8aIeeeHeader->i_addr3, mac_bssid, 6); | ||
907 | |||
908 | } | ||
909 | |||
870 | static void | 910 | static void |
871 | stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 911 | stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) |
872 | { | 912 | { |
873 | struct Hardware_Infos * dev = cls; | 913 | struct Hardware_Infos * dev = cls; |
874 | struct sendbuf *write_pout = dev->write_pout; | 914 | struct sendbuf *write_pout = dev->write_pout; |
875 | struct Radiotap_Send * header = (struct Radiotap_Send *) &hdr[1]; | 915 | struct Radiotap_Send * header = (struct Radiotap_Send *) &hdr[1]; |
916 | unsigned char * wlanheader; | ||
917 | |||
876 | int sendsize; | 918 | int sendsize; |
877 | 919 | ||
878 | unsigned char u8aRadiotap[] = | 920 | unsigned char u8aRadiotap[] = |
@@ -899,6 +941,15 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
899 | exit(1); | 941 | exit(1); |
900 | } | 942 | } |
901 | 943 | ||
944 | if (sendsize < sizeof(struct ieee80211_frame) + sizeof(struct WlanHeader) | ||
945 | + sizeof(struct FragmentationHeader) | ||
946 | + sizeof(struct GNUNET_MessageHeader)) | ||
947 | { | ||
948 | fprintf(stderr, "Function stdin_send: packet too small\n"); | ||
949 | exit(1); | ||
950 | } | ||
951 | |||
952 | u8aRadiotap[2] = htole16(sizeof(u8aRadiotap)); | ||
902 | u8aRadiotap[8] = header->rate; | 953 | u8aRadiotap[8] = header->rate; |
903 | 954 | ||
904 | switch (dev->drivertype) | 955 | switch (dev->drivertype) |
@@ -909,9 +960,12 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
909 | memcpy(write_pout->buf + sizeof(u8aRadiotap), write_pout->buf | 960 | memcpy(write_pout->buf + sizeof(u8aRadiotap), write_pout->buf |
910 | + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader), | 961 | + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader), |
911 | sendsize); | 962 | sendsize); |
963 | |||
964 | wlanheader = write_pout->buf + sizeof(u8aRadiotap); | ||
965 | mac_set(wlanheader, dev); | ||
966 | |||
912 | sendsize += sizeof(u8aRadiotap); | 967 | sendsize += sizeof(u8aRadiotap); |
913 | 968 | ||
914 | //usedrtap = 1; | ||
915 | break; | 969 | break; |
916 | default: | 970 | default: |
917 | break; | 971 | break; |
@@ -956,7 +1010,7 @@ maketest(unsigned char * buf, struct Hardware_Infos * dev) | |||
956 | 0x01, // <-- antenna | 1010 | 0x01, // <-- antenna |
957 | };*/ | 1011 | };*/ |
958 | 1012 | ||
959 | u8aRadiotap[8] = (rate/500000); | 1013 | u8aRadiotap[8] = (rate / 500000); |
960 | u8aRadiotap[2] = htole16(sizeof(u8aRadiotap)); | 1014 | u8aRadiotap[2] = htole16(sizeof(u8aRadiotap)); |
961 | 1015 | ||
962 | static struct ieee80211_frame u8aIeeeHeader; | 1016 | static struct ieee80211_frame u8aIeeeHeader; |
@@ -982,7 +1036,8 @@ maketest(unsigned char * buf, struct Hardware_Infos * dev) | |||
982 | } | 1036 | } |
983 | 1037 | ||
984 | tmp16 = (uint16_t*) u8aIeeeHeader.i_dur; | 1038 | tmp16 = (uint16_t*) u8aIeeeHeader.i_dur; |
985 | *tmp16 = (uint16_t) htole16((sizeof(txt) + sizeof(struct ieee80211_frame) * 1000000) / rate + 290); | 1039 | *tmp16 |
1040 | = (uint16_t) htole16((sizeof(txt) + sizeof(struct ieee80211_frame) * 1000000) / rate + 290); | ||
986 | tmp16 = (uint16_t*) u8aIeeeHeader.i_seq; | 1041 | tmp16 = (uint16_t*) u8aIeeeHeader.i_seq; |
987 | *tmp16 = (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16(seqenz) | 1042 | *tmp16 = (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16(seqenz) |
988 | << IEEE80211_SEQ_SEQ_SHIFT); | 1043 | << IEEE80211_SEQ_SEQ_SHIFT); |
@@ -1001,7 +1056,7 @@ hardwaremode(int argc, char *argv[]) | |||
1001 | 1056 | ||
1002 | struct Hardware_Infos dev; | 1057 | struct Hardware_Infos dev; |
1003 | struct ifreq ifreq; | 1058 | struct ifreq ifreq; |
1004 | struct rx_info * rxinfo; | 1059 | struct Radiotap_rx * rxinfo; |
1005 | uint8_t * mac = dev.pl_mac; | 1060 | uint8_t * mac = dev.pl_mac; |
1006 | int fdpin, fdpout; | 1061 | int fdpin, fdpout; |
1007 | 1062 | ||
@@ -1019,6 +1074,7 @@ hardwaremode(int argc, char *argv[]) | |||
1019 | 1074 | ||
1020 | //return 0; | 1075 | //return 0; |
1021 | 1076 | ||
1077 | unsigned char * datastart; | ||
1022 | char readbuf[MAXLINE]; | 1078 | char readbuf[MAXLINE]; |
1023 | int readsize = 0; | 1079 | int readsize = 0; |
1024 | struct sendbuf write_std; | 1080 | struct sendbuf write_std; |
@@ -1134,8 +1190,6 @@ hardwaremode(int argc, char *argv[]) | |||
1134 | { | 1190 | { |
1135 | 1191 | ||
1136 | ret = linux_write(&dev, write_pout.buf, write_pout.size); | 1192 | ret = linux_write(&dev, write_pout.buf, write_pout.size); |
1137 | //ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size | ||
1138 | // - write_pout.pos); | ||
1139 | 1193 | ||
1140 | if (0 > ret) | 1194 | if (0 > ret) |
1141 | { | 1195 | { |
@@ -1186,13 +1240,14 @@ hardwaremode(int argc, char *argv[]) | |||
1186 | 1240 | ||
1187 | if (FD_ISSET(fdpin, &rfds)) | 1241 | if (FD_ISSET(fdpin, &rfds)) |
1188 | { | 1242 | { |
1189 | rxinfo = (struct rx_info *) (write_pout.buf | 1243 | rxinfo = (struct Radiotap_rx *) (write_pout.buf |
1190 | + sizeof(struct GNUNET_MessageHeader)); | 1244 | + sizeof(struct GNUNET_MessageHeader)); |
1191 | readsize = linux_read(&dev, (unsigned char *) readbuf | 1245 | datastart = (unsigned char *) readbuf + sizeof(struct Radiotap_rx) |
1192 | + sizeof(struct rx_info) + sizeof(struct GNUNET_MessageHeader), | 1246 | + sizeof(struct GNUNET_MessageHeader); |
1193 | sizeof(readbuf) - sizeof(struct rx_info) | 1247 | |
1194 | - sizeof(struct GNUNET_MessageHeader), rxinfo); | 1248 | readsize = linux_read(&dev, datastart, sizeof(readbuf) |
1195 | //readsize = read(fdpin, readbuf, sizeof(readbuf)); | 1249 | - sizeof(struct Radiotap_rx) |
1250 | - sizeof(struct GNUNET_MessageHeader), rxinfo); | ||
1196 | 1251 | ||
1197 | if (0 > readsize) | 1252 | if (0 > readsize) |
1198 | { | 1253 | { |
@@ -1202,7 +1257,12 @@ hardwaremode(int argc, char *argv[]) | |||
1202 | } | 1257 | } |
1203 | else if (0 < readsize) | 1258 | else if (0 < readsize) |
1204 | { | 1259 | { |
1205 | 1260 | if (1 == mac_test(datastart, &dev)) | |
1261 | { | ||
1262 | // mac wrong | ||
1263 | write_pout.pos = 0; | ||
1264 | write_pout.size = 0; | ||
1265 | } | ||
1206 | } | 1266 | } |
1207 | else | 1267 | else |
1208 | { | 1268 | { |
@@ -1236,7 +1296,7 @@ main(int argc, char *argv[]) | |||
1236 | } | 1296 | } |
1237 | else | 1297 | else |
1238 | { | 1298 | { |
1239 | hardwaremode(argc, argv); | 1299 | return hardwaremode(argc, argv); |
1240 | } | 1300 | } |
1241 | 1301 | ||
1242 | #if 0 | 1302 | #if 0 |
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 124934b3c..a2e9bbe60 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -36,6 +36,8 @@ | |||
36 | #include "gnunet_crypto_lib.h" | 36 | #include "gnunet_crypto_lib.h" |
37 | #include "wlan/ieee80211.h" | 37 | #include "wlan/ieee80211.h" |
38 | 38 | ||
39 | #include <string.h> | ||
40 | |||
39 | #define PROTOCOL_PREFIX "wlan" | 41 | #define PROTOCOL_PREFIX "wlan" |
40 | 42 | ||
41 | /** | 43 | /** |
@@ -281,6 +283,7 @@ struct Receive_Fragment_Queue | |||
281 | uint16_t num; | 283 | uint16_t num; |
282 | const char * msg; | 284 | const char * msg; |
283 | uint16_t size; | 285 | uint16_t size; |
286 | struct Radiotap_rx rxinfo; | ||
284 | }; | 287 | }; |
285 | 288 | ||
286 | /** | 289 | /** |
@@ -544,56 +547,6 @@ struct FragmentMessage | |||
544 | /** | 547 | /** |
545 | * Header for messages which need fragmentation | 548 | * Header for messages which need fragmentation |
546 | */ | 549 | */ |
547 | struct WlanHeader | ||
548 | { | ||
549 | |||
550 | struct GNUNET_MessageHeader header; | ||
551 | |||
552 | /** | ||
553 | * checksum/error correction | ||
554 | */ | ||
555 | uint32_t crc GNUNET_PACKED; | ||
556 | |||
557 | /** | ||
558 | * To whom are we talking to (set to our identity | ||
559 | * if we are still waiting for the welcome message) | ||
560 | */ | ||
561 | struct GNUNET_PeerIdentity target; | ||
562 | |||
563 | // followed by payload | ||
564 | |||
565 | }; | ||
566 | |||
567 | /** | ||
568 | * Header for messages which need fragmentation | ||
569 | */ | ||
570 | struct FragmentationHeader | ||
571 | { | ||
572 | |||
573 | struct GNUNET_MessageHeader header; | ||
574 | |||
575 | /** | ||
576 | * ID of message, to distinguish between the messages, picked randomly. | ||
577 | */ | ||
578 | uint32_t message_id GNUNET_PACKED; | ||
579 | |||
580 | /** | ||
581 | * Offset or number of this fragment, for fragmentation/segmentation (design choice, TBD) | ||
582 | */ | ||
583 | uint16_t fragment_off_or_num GNUNET_PACKED; | ||
584 | |||
585 | /** | ||
586 | * CRC of fragment (for error checking) | ||
587 | */ | ||
588 | uint16_t message_crc GNUNET_PACKED; | ||
589 | |||
590 | // followed by payload | ||
591 | |||
592 | }; | ||
593 | |||
594 | /** | ||
595 | * Header for messages which need fragmentation | ||
596 | */ | ||
597 | struct FragmentationAckHeader | 550 | struct FragmentationAckHeader |
598 | { | 551 | { |
599 | 552 | ||
@@ -636,7 +589,7 @@ getcrc32(const char *msgbuf, size_t msgbuf_size); | |||
636 | 589 | ||
637 | static void | 590 | static void |
638 | free_receive_message(struct Plugin* plugin, | 591 | free_receive_message(struct Plugin* plugin, |
639 | struct Receive_Message_Queue * rec_message); | 592 | struct Receive_Message_Queue * rx_message); |
640 | 593 | ||
641 | struct Receive_Message_Queue * | 594 | struct Receive_Message_Queue * |
642 | get_receive_message_from_session(struct Plugin * plugin, | 595 | get_receive_message_from_session(struct Plugin * plugin, |
@@ -644,7 +597,7 @@ get_receive_message_from_session(struct Plugin * plugin, | |||
644 | 597 | ||
645 | static void | 598 | static void |
646 | wlan_data_helper(void *cls, struct Session_light * session_light, | 599 | wlan_data_helper(void *cls, struct Session_light * session_light, |
647 | const struct GNUNET_MessageHeader * hdr); | 600 | const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo); |
648 | 601 | ||
649 | static void | 602 | static void |
650 | wlan_process_helper(void *cls, void *client, | 603 | wlan_process_helper(void *cls, void *client, |
@@ -994,10 +947,10 @@ check_next_fragment_timeout(struct Plugin * const plugin) | |||
994 | { | 947 | { |
995 | next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time); | 948 | next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time); |
996 | if (fm != NULL) | 949 | if (fm != NULL) |
997 | { | 950 | { |
998 | next_send | 951 | next_send = GNUNET_TIME_relative_min(next_send, |
999 | = GNUNET_TIME_relative_min(next_send, get_next_frag_timeout(fm)); | 952 | get_next_frag_timeout(fm)); |
1000 | } | 953 | } |
1001 | } | 954 | } |
1002 | plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send, | 955 | plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed(next_send, |
1003 | &delay_fragment_task, plugin); | 956 | &delay_fragment_task, plugin); |
@@ -1624,15 +1577,18 @@ getRadiotapHeader(struct Plugin * plugin, struct Session * session, | |||
1624 | struct Radiotap_Send * header) | 1577 | struct Radiotap_Send * header) |
1625 | { | 1578 | { |
1626 | 1579 | ||
1627 | if (session != NULL){ | 1580 | if (session != NULL) |
1628 | header->rate = session->rate; | 1581 | { |
1629 | header->tx_power = session->tx_power; | 1582 | header->rate = session->rate; |
1630 | header->antenna = session->antenna; | 1583 | header->tx_power = session->tx_power; |
1631 | } else { | 1584 | header->antenna = session->antenna; |
1632 | header->rate = 255; | 1585 | } |
1633 | header->tx_power = 0; | 1586 | else |
1634 | header->antenna = 0; | 1587 | { |
1635 | } | 1588 | header->rate = 255; |
1589 | header->tx_power = 0; | ||
1590 | header->antenna = 0; | ||
1591 | } | ||
1636 | 1592 | ||
1637 | return GNUNET_YES; | 1593 | return GNUNET_YES; |
1638 | } | 1594 | } |
@@ -1650,6 +1606,8 @@ int | |||
1650 | getWlanHeader(struct ieee80211_frame * Header, const char * const to_mac_addr, | 1606 | getWlanHeader(struct ieee80211_frame * Header, const char * const to_mac_addr, |
1651 | struct Plugin * plugin) | 1607 | struct Plugin * plugin) |
1652 | { | 1608 | { |
1609 | Header->i_fc[0] = 0x80; | ||
1610 | Header->i_fc[1] = 0x00; | ||
1653 | memcpy(&Header->i_addr3, mac_bssid, sizeof(mac_bssid)); | 1611 | memcpy(&Header->i_addr3, mac_bssid, sizeof(mac_bssid)); |
1654 | memcpy(&Header->i_addr2, plugin->mac_address.mac, sizeof(plugin->mac_address)); | 1612 | memcpy(&Header->i_addr2, plugin->mac_address.mac, sizeof(plugin->mac_address)); |
1655 | memcpy(&Header->i_addr1, to_mac_addr, sizeof(plugin->mac_address)); | 1613 | memcpy(&Header->i_addr1, to_mac_addr, sizeof(plugin->mac_address)); |
@@ -2020,25 +1978,20 @@ wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen) | |||
2020 | * @return string representing the same address | 1978 | * @return string representing the same address |
2021 | */ | 1979 | */ |
2022 | static const char* | 1980 | static const char* |
2023 | wlan_plugin_address_to_string (void *cls, | 1981 | wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) |
2024 | const void *addr, | ||
2025 | size_t addrlen) | ||
2026 | { | 1982 | { |
2027 | static char ret[40]; | 1983 | static char ret[40]; |
2028 | const struct MacAddress *mac; | 1984 | const struct MacAddress *mac; |
2029 | 1985 | ||
2030 | if (addrlen != sizeof (struct MacAddress)) | 1986 | if (addrlen != sizeof(struct MacAddress)) |
2031 | { | 1987 | { |
2032 | GNUNET_break (0); | 1988 | GNUNET_break (0); |
2033 | return NULL; | 1989 | return NULL; |
2034 | } | 1990 | } |
2035 | mac = addr; | 1991 | mac = addr; |
2036 | GNUNET_snprintf(ret, sizeof(ret), | 1992 | GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %X:%X:%X:%X:%X:%X", |
2037 | "%s Mac-Address %X:%X:%X:%X:%X:%X", | 1993 | PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3], |
2038 | PROTOCOL_PREFIX, | 1994 | mac->mac[4], mac->mac[5]); |
2039 | mac->mac[0], mac->mac[1], | ||
2040 | mac->mac[2], mac->mac[3], | ||
2041 | mac->mac[4], mac->mac[5]); | ||
2042 | return ret; | 1995 | return ret; |
2043 | } | 1996 | } |
2044 | 1997 | ||
@@ -2133,10 +2086,10 @@ insert_fragment_in_queue(struct Receive_Message_Queue * rec_message, | |||
2133 | 2086 | ||
2134 | static void | 2087 | static void |
2135 | free_receive_message(struct Plugin* plugin, | 2088 | free_receive_message(struct Plugin* plugin, |
2136 | struct Receive_Message_Queue * rec_message) | 2089 | struct Receive_Message_Queue * rx_message) |
2137 | { | 2090 | { |
2138 | GNUNET_assert(rec_message !=NULL); | 2091 | GNUNET_assert(rx_message !=NULL); |
2139 | struct Receive_Fragment_Queue * rec_queue = rec_message->frag_head; | 2092 | struct Receive_Fragment_Queue * rec_queue = rx_message->frag_head; |
2140 | struct Receive_Fragment_Queue * rec_queue2; | 2093 | struct Receive_Fragment_Queue * rec_queue2; |
2141 | 2094 | ||
2142 | while (rec_queue != NULL) | 2095 | while (rec_queue != NULL) |
@@ -2146,14 +2099,14 @@ free_receive_message(struct Plugin* plugin, | |||
2146 | GNUNET_free(rec_queue2); | 2099 | GNUNET_free(rec_queue2); |
2147 | } | 2100 | } |
2148 | 2101 | ||
2149 | GNUNET_CONTAINER_DLL_remove(plugin->receive_messages_head,plugin->receive_messages_teil, rec_message); | 2102 | GNUNET_CONTAINER_DLL_remove(plugin->receive_messages_head,plugin->receive_messages_teil, rx_message); |
2150 | 2103 | ||
2151 | GNUNET_assert(plugin->pending_receive_messages > 0); | 2104 | GNUNET_assert(plugin->pending_receive_messages > 0); |
2152 | GNUNET_assert(rec_message->session->fragment_messages_in_count > 0); | 2105 | GNUNET_assert(rx_message->session->fragment_messages_in_count > 0); |
2153 | 2106 | ||
2154 | plugin->pending_receive_messages--; | 2107 | plugin->pending_receive_messages--; |
2155 | rec_message->session->fragment_messages_in_count--; | 2108 | rx_message->session->fragment_messages_in_count--; |
2156 | GNUNET_free(rec_message); | 2109 | GNUNET_free(rx_message); |
2157 | } | 2110 | } |
2158 | 2111 | ||
2159 | /** | 2112 | /** |
@@ -2167,12 +2120,12 @@ free_receive_message(struct Plugin* plugin, | |||
2167 | static void | 2120 | static void |
2168 | check_rec_finished_msg(struct Plugin* plugin, | 2121 | check_rec_finished_msg(struct Plugin* plugin, |
2169 | struct Session_light * session_light, struct Session * session, | 2122 | struct Session_light * session_light, struct Session * session, |
2170 | struct Receive_Message_Queue * rec_message) | 2123 | struct Receive_Message_Queue * rx_message) |
2171 | { | 2124 | { |
2172 | GNUNET_assert(rec_message !=NULL); | 2125 | GNUNET_assert(rx_message !=NULL); |
2173 | 2126 | ||
2174 | struct Receive_Fragment_Queue * rec_queue = rec_message->frag_head; | 2127 | struct Receive_Fragment_Queue * rx_frag = rx_message->frag_head; |
2175 | int packetsize = rec_message->rec_size; | 2128 | int packetsize = rx_message->rec_size; |
2176 | int sum = 0; | 2129 | int sum = 0; |
2177 | int aktnum = 0; | 2130 | int aktnum = 0; |
2178 | uint64_t bitfield = 0; | 2131 | uint64_t bitfield = 0; |
@@ -2188,56 +2141,60 @@ check_rec_finished_msg(struct Plugin* plugin, | |||
2188 | + sizeof(struct GNUNET_MessageHeader)) | 2141 | + sizeof(struct GNUNET_MessageHeader)) |
2189 | { | 2142 | { |
2190 | #if DEBUG_wlan | 2143 | #if DEBUG_wlan |
2191 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2144 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Message not big enough\n"); |
2192 | "Message not big enough\n"); | ||
2193 | #endif | 2145 | #endif |
2194 | free_receive_message(plugin, rec_message); | 2146 | free_receive_message(plugin, rx_message); |
2195 | return; | 2147 | return; |
2196 | } | 2148 | } |
2197 | 2149 | ||
2198 | #if DEBUG_wlan | 2150 | #if DEBUG_wlan |
2199 | check_message_fragment_bitfield(rec_message); | 2151 | check_message_fragment_bitfield(rx_message); |
2200 | #endif | 2152 | #endif |
2201 | 2153 | ||
2202 | bitfield = ~bitfield; | 2154 | if (rx_message->frag_tail->num == ffsl(rx_message->received_fragments)) |
2203 | bitfield = bitfield >> (63 - rec_message->frag_tail->num); | ||
2204 | if (rec_message->received_fragments == bitfield) | ||
2205 | { | 2155 | { |
2206 | 2156 | bitfield = ~bitfield; | |
2207 | while (rec_queue != NULL) | 2157 | bitfield = bitfield << (63 - ffsl(rx_message->received_fragments)); |
2208 | { | 2158 | if (rx_message->received_fragments == bitfield) |
2209 | sum += rec_queue->size; | ||
2210 | rec_queue = rec_queue->next; | ||
2211 | } | ||
2212 | //sum should always be smaller or equal of | ||
2213 | GNUNET_assert(sum <= packetsize); | ||
2214 | if (sum == packetsize) | ||
2215 | { | 2159 | { |
2216 | 2160 | ||
2161 | while (rx_frag != NULL) | ||
2162 | { | ||
2163 | sum += rx_frag->size; | ||
2164 | rx_frag = rx_frag->next; | ||
2165 | } | ||
2166 | //sum should always be smaller or equal of | ||
2167 | GNUNET_assert(sum <= packetsize); | ||
2168 | if (sum == packetsize) | ||
2169 | { | ||
2170 | |||
2217 | #if DEBUG_wlan | 2171 | #if DEBUG_wlan |
2218 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2172 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2219 | "check_rec_finished_msg: A message for %p is complete\n", session); | 2173 | "check_rec_finished_msg: A message for %p is complete\n", |
2174 | session); | ||
2220 | #endif | 2175 | #endif |
2221 | 2176 | ||
2222 | //TODO use mst | 2177 | //TODO use mst |
2223 | //copy fragments together | 2178 | //copy fragments together |
2224 | msg = GNUNET_malloc(packetsize); | 2179 | msg = GNUNET_malloc(packetsize); |
2225 | rec_queue = rec_message->frag_head; | 2180 | rx_frag = rx_message->frag_head; |
2226 | aktnum = 0; | 2181 | aktnum = 0; |
2227 | while (rec_queue != NULL) | 2182 | while (rx_frag != NULL) |
2228 | { | 2183 | { |
2229 | //TODO SAVE SOME COPY OPS AND CHECK CRC WITHOUT COPY | 2184 | //TODO SAVE SOME COPY OPS AND CHECK CRC WITHOUT COPY |
2230 | memcpy(msg + aktnum, rec_queue->msg, rec_queue->size); | 2185 | memcpy(msg + aktnum, rx_frag->msg, rx_frag->size); |
2231 | aktnum += rec_queue->size; | 2186 | aktnum += rx_frag->size; |
2232 | rec_queue = rec_queue->next; | 2187 | rx_frag = rx_frag->next; |
2233 | } | 2188 | } |
2234 | free_receive_message(plugin, rec_message); | 2189 | |
2235 | //call wlan_process_helper to process the message | 2190 | free_receive_message(plugin, rx_message); |
2236 | wlan_data_massage_handler(plugin, session_light, | 2191 | //call wlan_process_helper to process the message |
2237 | (struct GNUNET_MessageHeader*) msg); | 2192 | wlan_data_massage_handler(plugin, session_light, |
2238 | //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); | 2193 | (struct GNUNET_MessageHeader*) msg); |
2194 | //wlan_data_helper (plugin, session_light, (struct GNUNET_MessageHeader*) msg); | ||
2239 | 2195 | ||
2240 | GNUNET_free(msg); | 2196 | GNUNET_free(msg); |
2197 | } | ||
2241 | } | 2198 | } |
2242 | } | 2199 | } |
2243 | } | 2200 | } |
@@ -2476,10 +2433,10 @@ get_receive_message_from_session(struct Plugin * plugin, | |||
2476 | uint64_t | 2433 | uint64_t |
2477 | insert_fragment_in_in_message_queue(struct Plugin * plugin, | 2434 | insert_fragment_in_in_message_queue(struct Plugin * plugin, |
2478 | struct Session_light * session_light, struct Session * session, | 2435 | struct Session_light * session_light, struct Session * session, |
2479 | struct FragmentationHeader * fh) | 2436 | struct FragmentationHeader * fh, const struct Radiotap_rx * rxinfo) |
2480 | { | 2437 | { |
2481 | struct Receive_Fragment_Queue * rec_queue = NULL; | 2438 | struct Receive_Fragment_Queue * rx_frag = NULL; |
2482 | struct Receive_Message_Queue * rec_message; | 2439 | struct Receive_Message_Queue * rx_message; |
2483 | const char * tempmsg = (char*) &fh[1]; | 2440 | const char * tempmsg = (char*) &fh[1]; |
2484 | uint64_t retval = 0; | 2441 | uint64_t retval = 0; |
2485 | 2442 | ||
@@ -2487,23 +2444,23 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin, | |||
2487 | //check if message_id is right or it is a new msg | 2444 | //check if message_id is right or it is a new msg |
2488 | GNUNET_assert(fh != NULL); | 2445 | GNUNET_assert(fh != NULL); |
2489 | 2446 | ||
2490 | rec_message = get_receive_message(plugin, session, ntohs(fh->message_id)); | 2447 | rx_message = get_receive_message(plugin, session, ntohs(fh->message_id)); |
2491 | 2448 | ||
2492 | if (rec_message == NULL) | 2449 | if (rx_message == NULL) |
2493 | { | 2450 | { |
2494 | if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION) | 2451 | if (session->fragment_messages_in_count < MESSAGES_IN_QUEUE_PER_SESSION) |
2495 | { | 2452 | { |
2496 | 2453 | ||
2497 | //new message incoming | 2454 | //new message incoming |
2498 | rec_message = GNUNET_malloc(sizeof (struct Receive_Message_Queue)); | 2455 | rx_message = GNUNET_malloc(sizeof (struct Receive_Message_Queue)); |
2499 | rec_message->message_id_in = ntohs(fh->message_id); | 2456 | rx_message->message_id_in = ntohs(fh->message_id); |
2500 | rec_message->rec_size = MESSAGE_LENGHT_UNKNOWN; | 2457 | rx_message->rec_size = MESSAGE_LENGHT_UNKNOWN; |
2501 | rec_message->session = session; | 2458 | rx_message->session = session; |
2502 | rec_message->timeout = GNUNET_TIME_absolute_add( | 2459 | rx_message->timeout = GNUNET_TIME_absolute_add( |
2503 | GNUNET_TIME_absolute_get(), MESSAGE_IN_TIMEOUT); | 2460 | GNUNET_TIME_absolute_get(), MESSAGE_IN_TIMEOUT); |
2504 | rec_message->received_fragments = 0; | 2461 | rx_message->received_fragments = 0; |
2505 | 2462 | ||
2506 | GNUNET_CONTAINER_DLL_insert(plugin->receive_messages_head, plugin->receive_messages_teil, rec_message); | 2463 | GNUNET_CONTAINER_DLL_insert(plugin->receive_messages_head, plugin->receive_messages_teil, rx_message); |
2507 | 2464 | ||
2508 | session->fragment_messages_in_count++; | 2465 | session->fragment_messages_in_count++; |
2509 | plugin->pending_receive_messages++; | 2466 | plugin->pending_receive_messages++; |
@@ -2512,7 +2469,7 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin, | |||
2512 | GNUNET_log( | 2469 | GNUNET_log( |
2513 | GNUNET_ERROR_TYPE_DEBUG, | 2470 | GNUNET_ERROR_TYPE_DEBUG, |
2514 | "New fragmented message started: message id %u, messages in for this session %u, messages in %u\n", | 2471 | "New fragmented message started: message id %u, messages in for this session %u, messages in %u\n", |
2515 | rec_message->message_id_in, session->fragment_messages_in_count, | 2472 | rx_message->message_id_in, session->fragment_messages_in_count, |
2516 | plugin->pending_receive_messages); | 2473 | plugin->pending_receive_messages); |
2517 | #endif | 2474 | #endif |
2518 | } | 2475 | } |
@@ -2527,36 +2484,37 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin, | |||
2527 | } | 2484 | } |
2528 | } | 2485 | } |
2529 | 2486 | ||
2530 | if (is_double_msg(rec_message, fh) != GNUNET_YES) | 2487 | if (is_double_msg(rx_message, fh) != GNUNET_YES) |
2531 | { | 2488 | { |
2532 | 2489 | ||
2533 | //report size | 2490 | //report size |
2534 | rec_queue = GNUNET_malloc(sizeof (struct Receive_Fragment_Queue) + | 2491 | rx_frag = GNUNET_malloc(sizeof (struct Receive_Fragment_Queue) + |
2535 | ntohs(fh->header.size) - sizeof(struct FragmentationHeader)); | 2492 | ntohs(fh->header.size) - sizeof(struct FragmentationHeader)); |
2536 | rec_queue->size = ntohs(fh->header.size) | 2493 | rx_frag->size = ntohs(fh->header.size) |
2537 | - sizeof(struct FragmentationHeader); | 2494 | - sizeof(struct FragmentationHeader); |
2538 | rec_queue->num = ntohs(fh->fragment_off_or_num); | 2495 | rx_frag->num = ntohs(fh->fragment_off_or_num); |
2539 | rec_queue->msg = (char*) &(rec_queue[1]); | 2496 | rx_frag->msg = (char*) &(rx_frag[1]); |
2540 | //copy msg to buffer | 2497 | //copy msg to buffer |
2541 | memcpy((char *) rec_queue->msg, tempmsg, rec_queue->size); | 2498 | memcpy((char *) rx_frag->msg, tempmsg, rx_frag->size); |
2542 | insert_fragment_in_queue(rec_message, rec_queue); | 2499 | memcpy((char *) &(rx_frag->rxinfo), rxinfo, sizeof(rxinfo)); |
2500 | insert_fragment_in_queue(rx_message, rx_frag); | ||
2543 | //save bitfield | 2501 | //save bitfield |
2544 | retval = rec_message->received_fragments; | 2502 | retval = rx_message->received_fragments; |
2545 | 2503 | ||
2546 | #if DEBUG_wlan | 2504 | #if DEBUG_wlan |
2547 | GNUNET_log( | 2505 | GNUNET_log( |
2548 | GNUNET_ERROR_TYPE_DEBUG, | 2506 | GNUNET_ERROR_TYPE_DEBUG, |
2549 | "New fragment: size %u, fragsize %u, message id %u, bitfield %X, session %u\n", | 2507 | "New fragment: size %u, fragsize %u, message id %u, bitfield %X, session %u\n", |
2550 | rec_message->rec_size, rec_queue->size, | 2508 | rx_message->rec_size, rx_frag->size, rx_message->received_fragments, |
2551 | rec_message->received_fragments, rec_message->message_id_in, session); | 2509 | rx_message->message_id_in, session); |
2552 | #endif | 2510 | #endif |
2553 | 2511 | ||
2554 | check_rec_finished_msg(plugin, session_light, session, rec_message); | 2512 | check_rec_finished_msg(plugin, session_light, session, rx_message); |
2555 | } | 2513 | } |
2556 | else | 2514 | else |
2557 | { | 2515 | { |
2558 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN fragment is a clone\n"); | 2516 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "WLAN fragment is a clone\n"); |
2559 | retval = rec_message->received_fragments; | 2517 | retval = rx_message->received_fragments; |
2560 | 2518 | ||
2561 | } | 2519 | } |
2562 | return retval; | 2520 | return retval; |
@@ -2572,7 +2530,7 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin, | |||
2572 | */ | 2530 | */ |
2573 | static void | 2531 | static void |
2574 | wlan_data_helper(void *cls, struct Session_light * session_light, | 2532 | wlan_data_helper(void *cls, struct Session_light * session_light, |
2575 | const struct GNUNET_MessageHeader * hdr) | 2533 | const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo) |
2576 | { | 2534 | { |
2577 | struct Plugin *plugin = cls; | 2535 | struct Plugin *plugin = cls; |
2578 | struct Session * session = NULL; | 2536 | struct Session * session = NULL; |
@@ -2645,7 +2603,7 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2645 | if (session != NULL) | 2603 | if (session != NULL) |
2646 | { | 2604 | { |
2647 | fragment_bitfield = insert_fragment_in_in_message_queue(plugin, | 2605 | fragment_bitfield = insert_fragment_in_in_message_queue(plugin, |
2648 | session_light, session, fh); | 2606 | session_light, session, fh, rxinfo); |
2649 | } | 2607 | } |
2650 | else | 2608 | else |
2651 | { | 2609 | { |
@@ -2722,21 +2680,16 @@ wlan_data_helper(void *cls, struct Session_light * session_light, | |||
2722 | 2680 | ||
2723 | } | 2681 | } |
2724 | 2682 | ||
2725 | |||
2726 | const char * | 2683 | const char * |
2727 | macprinter(const u_int8_t * mac) | 2684 | macprinter(const u_int8_t * mac) |
2728 | { | 2685 | { |
2729 | static char macstr[20]; | 2686 | static char macstr[20]; |
2730 | 2687 | ||
2731 | GNUNET_snprintf (macstr, | 2688 | GNUNET_snprintf(macstr, sizeof(macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1], |
2732 | sizeof (macstr), | 2689 | mac[2], mac[3], mac[4], mac[5]); |
2733 | "%X:%X:%X:%X:%X:%X", | ||
2734 | mac[0], mac[1], mac[2], | ||
2735 | mac[3], mac[4], mac[5]); | ||
2736 | return macstr; | 2690 | return macstr; |
2737 | } | 2691 | } |
2738 | 2692 | ||
2739 | |||
2740 | /** | 2693 | /** |
2741 | * Function used for to process the data from the suid process | 2694 | * Function used for to process the data from the suid process |
2742 | * | 2695 | * |
@@ -2745,13 +2698,13 @@ macprinter(const u_int8_t * mac) | |||
2745 | * @param hdr header of the GNUNET_MessageHeader | 2698 | * @param hdr header of the GNUNET_MessageHeader |
2746 | */ | 2699 | */ |
2747 | static void | 2700 | static void |
2748 | wlan_process_helper (void *cls, | 2701 | wlan_process_helper(void *cls, void *client, |
2749 | void *client, | 2702 | const struct GNUNET_MessageHeader *hdr) |
2750 | const struct GNUNET_MessageHeader *hdr) | ||
2751 | { | 2703 | { |
2752 | struct Plugin *plugin = cls; | 2704 | struct Plugin *plugin = cls; |
2753 | struct ieee80211_frame * wlanIeeeHeader = NULL; | 2705 | struct ieee80211_frame * wlanIeeeHeader = NULL; |
2754 | struct Session_light * session_light = NULL; | 2706 | struct Session_light * session_light = NULL; |
2707 | struct Radiotap_rx * rxinfo; | ||
2755 | const struct GNUNET_MessageHeader * temp_hdr = NULL; | 2708 | const struct GNUNET_MessageHeader * temp_hdr = NULL; |
2756 | 2709 | ||
2757 | int datasize = 0; | 2710 | int datasize = 0; |
@@ -2759,109 +2712,108 @@ wlan_process_helper (void *cls, | |||
2759 | 2712 | ||
2760 | switch (ntohs(hdr->type)) | 2713 | switch (ntohs(hdr->type)) |
2761 | { | 2714 | { |
2762 | case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA: | 2715 | case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA: |
2763 | #if DEBUG_wlan | 2716 | #if DEBUG_wlan |
2764 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2717 | GNUNET_log( |
2765 | "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n", | 2718 | GNUNET_ERROR_TYPE_DEBUG, |
2766 | ntohs(hdr->size)); | 2719 | "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n", |
2720 | ntohs(hdr->size)); | ||
2767 | #endif | 2721 | #endif |
2768 | 2722 | ||
2769 | //call wlan_process_helper with the message inside, later with wlan: analyze signal | 2723 | //call wlan_process_helper with the message inside, later with wlan: analyze signal |
2770 | if (ntohs(hdr->size) < sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader)) | 2724 | if (ntohs(hdr->size) < sizeof(struct ieee80211_frame) |
2771 | { | 2725 | + sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_rx)) |
2772 | GNUNET_break (0); | 2726 | { |
2773 | /* FIXME: restart SUID process */ | 2727 | GNUNET_break (0); |
2774 | return; | 2728 | /* FIXME: restart SUID process */ |
2775 | } | 2729 | return; |
2776 | wlanIeeeHeader = (struct ieee80211_frame *) &hdr[1]; | 2730 | } |
2777 | 2731 | rxinfo = (struct Radiotap_rx *) &hdr[1]; | |
2778 | //process only if it is an broadcast or for this computer both with the gnunet bssid | 2732 | wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1]; |
2779 | 2733 | ||
2780 | //check for bssid | 2734 | //process only if it is an broadcast or for this computer both with the gnunet bssid |
2781 | if (memcmp(&(wlanIeeeHeader->i_addr3), mac_bssid, | 2735 | |
2782 | sizeof(struct MacAddress)) == 0) | 2736 | //check for bssid |
2783 | { | 2737 | if (memcmp(&(wlanIeeeHeader->i_addr3), mac_bssid, sizeof(struct MacAddress)) |
2784 | //check for broadcast or mac | 2738 | == 0) |
2785 | if (memcmp(&(wlanIeeeHeader->i_addr1), bc_all_mac, | 2739 | { |
2786 | sizeof(struct MacAddress) == 0) || memcmp( | 2740 | //check for broadcast or mac |
2787 | &(wlanIeeeHeader->i_addr1), &(plugin->mac_address), | 2741 | if (memcmp(&(wlanIeeeHeader->i_addr1), bc_all_mac, |
2788 | sizeof(struct MacAddress)) == 0) | 2742 | sizeof(struct MacAddress) == 0) || memcmp( |
2789 | { | 2743 | &(wlanIeeeHeader->i_addr1), &(plugin->mac_address), |
2790 | 2744 | sizeof(struct MacAddress)) == 0) | |
2791 | // process the inner data | 2745 | { |
2792 | 2746 | ||
2793 | 2747 | // process the inner data | |
2794 | datasize = ntohs(hdr->size) - sizeof(struct ieee80211_frame) | 2748 | |
2795 | - sizeof(struct GNUNET_MessageHeader); | 2749 | |
2796 | 2750 | datasize = ntohs(hdr->size) - sizeof(struct ieee80211_frame) | |
2797 | session_light = GNUNET_malloc(sizeof(struct Session_light)); | 2751 | - sizeof(struct GNUNET_MessageHeader); |
2798 | memcpy(session_light->addr, &(wlanIeeeHeader->i_addr2), | 2752 | |
2799 | sizeof(struct MacAddress)); | 2753 | session_light = GNUNET_malloc(sizeof(struct Session_light)); |
2800 | //session_light->session = search_session(plugin,session_light->addr); | 2754 | memcpy(session_light->addr, &(wlanIeeeHeader->i_addr2), |
2801 | 2755 | sizeof(struct MacAddress)); | |
2802 | pos = 0; | 2756 | //session_light->session = search_session(plugin,session_light->addr); |
2803 | temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1]; | 2757 | |
2804 | while (pos < datasize) | 2758 | pos = 0; |
2805 | { | 2759 | temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1]; |
2806 | temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] | 2760 | while (pos < datasize) |
2807 | + pos; | 2761 | { |
2808 | 2762 | temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] | |
2809 | wlan_data_helper(plugin, session_light, temp_hdr); | 2763 | + pos; |
2810 | pos += ntohs(temp_hdr->size); | 2764 | |
2811 | 2765 | wlan_data_helper(plugin, session_light, temp_hdr, rxinfo); | |
2812 | } | 2766 | pos += ntohs(temp_hdr->size); |
2813 | 2767 | ||
2814 | //clean up | 2768 | } |
2815 | GNUNET_free(session_light); | 2769 | |
2816 | } | 2770 | //clean up |
2817 | else | 2771 | GNUNET_free(session_light); |
2818 | { | 2772 | } |
2773 | else | ||
2774 | { | ||
2819 | #if DEBUG_wlan | 2775 | #if DEBUG_wlan |
2820 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2776 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2821 | "Func wlan_process_helper got wrong MAC: %s\n", macprinter( | 2777 | "Func wlan_process_helper got wrong MAC: %s\n", macprinter( |
2822 | wlanIeeeHeader->i_addr1)); | 2778 | wlanIeeeHeader->i_addr1)); |
2823 | #endif | 2779 | #endif |
2824 | } | 2780 | } |
2825 | } | 2781 | } |
2826 | else | 2782 | else |
2827 | { | 2783 | { |
2828 | #if DEBUG_wlan | 2784 | #if DEBUG_wlan |
2829 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2785 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2830 | "Func wlan_process_helper got wrong BSSID: %s\n", macprinter( | 2786 | "Func wlan_process_helper got wrong BSSID: %s\n", macprinter( |
2831 | wlanIeeeHeader->i_addr2)); | 2787 | wlanIeeeHeader->i_addr2)); |
2832 | #endif | 2788 | #endif |
2833 | } | 2789 | } |
2834 | break; | 2790 | break; |
2835 | case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL: | 2791 | case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL: |
2836 | //TODO more control messages | 2792 | //TODO more control messages |
2837 | //TODO use struct wlan_helper_control | 2793 | //TODO use struct wlan_helper_control |
2838 | if (ntohs(hdr->size) != sizeof(struct Wlan_Helper_Control_Message)) | 2794 | if (ntohs(hdr->size) != sizeof(struct Wlan_Helper_Control_Message)) |
2839 | { | 2795 | { |
2840 | GNUNET_break (0); | 2796 | GNUNET_break (0); |
2841 | /* FIXME: restart SUID process */ | 2797 | /* FIXME: restart SUID process */ |
2842 | return; | 2798 | return; |
2843 | } | 2799 | } |
2844 | memcpy (&plugin->mac_address, | 2800 | memcpy(&plugin->mac_address, &hdr[1], sizeof(struct MacAddress)); |
2845 | &hdr[1], | ||
2846 | sizeof(struct MacAddress)); | ||
2847 | #if DEBUG_WLAN | 2801 | #if DEBUG_WLAN |
2848 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2802 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2849 | "Received WLAN_HELPER_CONTROL message with transport of address %s\n", | 2803 | "Received WLAN_HELPER_CONTROL message with transport of address %s\n", |
2850 | wlan_plugin_address_to_string (cls, | 2804 | wlan_plugin_address_to_string (cls, |
2851 | &plugin->mac_address, | 2805 | &plugin->mac_address, |
2852 | sizeof (struct MacAddress))); | 2806 | sizeof (struct MacAddress))); |
2853 | #endif | 2807 | #endif |
2854 | plugin->env->notify_address(plugin->env->cls, "wlan", | 2808 | plugin->env->notify_address(plugin->env->cls, "wlan", &plugin->mac_address, |
2855 | &plugin->mac_address, sizeof(struct MacAddress), | 2809 | sizeof(struct MacAddress), GNUNET_TIME_UNIT_FOREVER_REL); |
2856 | GNUNET_TIME_UNIT_FOREVER_REL); | 2810 | break; |
2857 | break; | 2811 | default: |
2858 | default: | 2812 | GNUNET_break (0); |
2859 | GNUNET_break (0); | 2813 | return; |
2860 | return; | ||
2861 | } | 2814 | } |
2862 | } | 2815 | } |
2863 | 2816 | ||
2864 | |||
2865 | /** | 2817 | /** |
2866 | * We have been notified that wlan-helper has written something to stdout. | 2818 | * We have been notified that wlan-helper has written something to stdout. |
2867 | * Handle the output, then reschedule this function to be called again once | 2819 | * Handle the output, then reschedule this function to be called again once |
diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h index d03bacd82..979e466bf 100644 --- a/src/transport/plugin_transport_wlan.h +++ b/src/transport/plugin_transport_wlan.h | |||
@@ -43,7 +43,55 @@ struct Wlan_Helper_Control_Message | |||
43 | struct MacAddress mac; | 43 | struct MacAddress mac; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | /** | ||
47 | * Header for messages which need fragmentation | ||
48 | */ | ||
49 | struct FragmentationHeader | ||
50 | { | ||
51 | |||
52 | struct GNUNET_MessageHeader header; | ||
53 | |||
54 | /** | ||
55 | * ID of message, to distinguish between the messages, picked randomly. | ||
56 | */ | ||
57 | uint32_t message_id GNUNET_PACKED; | ||
58 | |||
59 | /** | ||
60 | * Offset or number of this fragment, for fragmentation/segmentation (design choice, TBD) | ||
61 | */ | ||
62 | uint16_t fragment_off_or_num GNUNET_PACKED; | ||
63 | |||
64 | /** | ||
65 | * CRC of fragment (for error checking) | ||
66 | */ | ||
67 | uint16_t message_crc GNUNET_PACKED; | ||
68 | |||
69 | // followed by payload | ||
70 | |||
71 | }; | ||
72 | |||
73 | /** | ||
74 | * Header for messages which need fragmentation | ||
75 | */ | ||
76 | struct WlanHeader | ||
77 | { | ||
46 | 78 | ||
79 | struct GNUNET_MessageHeader header; | ||
80 | |||
81 | /** | ||
82 | * checksum/error correction | ||
83 | */ | ||
84 | uint32_t crc GNUNET_PACKED; | ||
85 | |||
86 | /** | ||
87 | * To whom are we talking to (set to our identity | ||
88 | * if we are still waiting for the welcome message) | ||
89 | */ | ||
90 | struct GNUNET_PeerIdentity target; | ||
91 | |||
92 | // followed by payload | ||
93 | |||
94 | }; | ||
47 | 95 | ||
48 | /* Wlan IEEE80211 header default */ | 96 | /* Wlan IEEE80211 header default */ |
49 | //Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html | 97 | //Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html |
@@ -104,7 +152,18 @@ struct Radiotap_Send | |||
104 | uint16_t tx_power; | 152 | uint16_t tx_power; |
105 | }; | 153 | }; |
106 | 154 | ||
107 | struct rx_info { | 155 | // bit field defines for ri_present |
156 | |||
157 | #define has_noise 1 | ||
158 | #define has_power 2 | ||
159 | #define has_channel 4 | ||
160 | |||
161 | /** | ||
162 | * struct to represent infos gathered form the radiotap fields | ||
163 | */ | ||
164 | |||
165 | struct Radiotap_rx { | ||
166 | uint32_t ri_present; | ||
108 | uint64_t ri_mactime; | 167 | uint64_t ri_mactime; |
109 | int32_t ri_power; | 168 | int32_t ri_power; |
110 | int32_t ri_noise; | 169 | int32_t ri_noise; |
diff --git a/src/transport/wlan/loopback_helper.c b/src/transport/wlan/loopback_helper.c index d06911e45..8f56bc8d6 100644 --- a/src/transport/wlan/loopback_helper.c +++ b/src/transport/wlan/loopback_helper.c | |||
@@ -45,8 +45,12 @@ stdin_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
45 | struct sendbuf *write_pout = cls; | 45 | struct sendbuf *write_pout = cls; |
46 | int sendsize; | 46 | int sendsize; |
47 | struct GNUNET_MessageHeader newheader; | 47 | struct GNUNET_MessageHeader newheader; |
48 | unsigned char * from; | 48 | unsigned char * from_data; |
49 | unsigned char * to; | 49 | unsigned char * to_data; |
50 | //unsigned char * from_radiotap; | ||
51 | unsigned char * to_radiotap; | ||
52 | //unsigned char * from_start; | ||
53 | unsigned char * to_start; | ||
50 | 54 | ||
51 | sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send); | 55 | sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send); |
52 | 56 | ||
@@ -64,14 +68,20 @@ stdin_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
64 | newheader.size = htons(sendsize); | 68 | newheader.size = htons(sendsize); |
65 | newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | 69 | newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); |
66 | 70 | ||
67 | to = write_pout->buf + write_pout->size; | 71 | to_start = write_pout->buf + write_pout->size; |
68 | memcpy(to, &newheader, sizeof(struct GNUNET_MessageHeader)); | 72 | to_radiotap = to_start + sizeof(struct GNUNET_MessageHeader); |
73 | to_data = to_radiotap + sizeof(struct Radiotap_rx); | ||
74 | |||
75 | from_data = ((unsigned char *) hdr) + sizeof(struct Radiotap_Send) | ||
76 | + sizeof(struct GNUNET_MessageHeader); | ||
77 | |||
78 | |||
79 | memcpy(to_start, &newheader, sizeof(struct GNUNET_MessageHeader)); | ||
69 | write_pout->size += sizeof(struct GNUNET_MessageHeader); | 80 | write_pout->size += sizeof(struct GNUNET_MessageHeader); |
70 | 81 | ||
71 | from = ((unsigned char *) hdr) + sizeof(struct Radiotap_Send) | 82 | write_pout->size += sizeof(struct Radiotap_rx); |
72 | + sizeof(struct GNUNET_MessageHeader); | 83 | |
73 | to = write_pout->buf + write_pout->size; | 84 | memcpy(to_data, from_data, sendsize - sizeof(struct GNUNET_MessageHeader)); |
74 | memcpy(to, from, sendsize - sizeof(struct GNUNET_MessageHeader)); | ||
75 | write_pout->size += sendsize - sizeof(struct GNUNET_MessageHeader); | 85 | write_pout->size += sendsize - sizeof(struct GNUNET_MessageHeader); |
76 | } | 86 | } |
77 | 87 | ||