diff options
author | David Brodski <david@brodski.eu> | 2011-04-05 09:02:16 +0000 |
---|---|---|
committer | David Brodski <david@brodski.eu> | 2011-04-05 09:02:16 +0000 |
commit | 71e79d72a1da156a1bde9b3346e40f7a7f547f26 (patch) | |
tree | b1bedd9856c58460e45ee6ae0af930856f03a8d5 /src/transport/gnunet-transport-wlan-helper.c | |
parent | b64c94d386f0fa6a057c96cf3906a24a39f27b2e (diff) | |
download | gnunet-71e79d72a1da156a1bde9b3346e40f7a7f547f26.tar.gz gnunet-71e79d72a1da156a1bde9b3346e40f7a7f547f26.zip |
Some fixes
Diffstat (limited to 'src/transport/gnunet-transport-wlan-helper.c')
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 106 |
1 files changed, 83 insertions, 23 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 |