aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport-wlan-helper.c
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2011-03-31 22:56:34 +0000
committerDavid Brodski <david@brodski.eu>2011-03-31 22:56:34 +0000
commit8ffcd0209841579856e712fa9b0dc10e3049d286 (patch)
tree3a9702a579c331d075f46a5b376a2d73700cd33b /src/transport/gnunet-transport-wlan-helper.c
parent406f6b790cbc558d2ba6905c64a4ff8b90171daa (diff)
downloadgnunet-8ffcd0209841579856e712fa9b0dc10e3049d286.tar.gz
gnunet-8ffcd0209841579856e712fa9b0dc10e3049d286.zip
Some tests for wlan
Diffstat (limited to 'src/transport/gnunet-transport-wlan-helper.c')
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c88
1 files changed, 64 insertions, 24 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index f481a0fb6..9111a6666 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -86,6 +86,7 @@
86#include "wlan/ieee80211_radiotap.h" 86#include "wlan/ieee80211_radiotap.h"
87#include "wlan/crctable_osdep.h" 87#include "wlan/crctable_osdep.h"
88#include "wlan/loopback_helper.h" 88#include "wlan/loopback_helper.h"
89#include "wlan/ieee80211.h"
89 90
90#define ARPHRD_IEEE80211 801 91#define ARPHRD_IEEE80211 801
91#define ARPHRD_IEEE80211_PRISM 802 92#define ARPHRD_IEEE80211_PRISM 802
@@ -250,15 +251,10 @@ Dump(u8 * pu8, int nLength)
250void 251void
251usage() 252usage()
252{ 253{
253 printf("Usage: wlan-hwd [options] <interface>\n\nOptions\n" 254 printf("Usage: interface-name optins\n"
254 "-f/--fcs Mark as having FCS (CRC) already\n" 255 "options: 0 = with hardware\n"
255 " (pkt ends with 4 x sacrificial - chars)\n" 256 "1 = first loopback file\n"
256 "Example:\n" 257 "2 = second loopback file\n"
257 " echo -n mon0 > /sys/class/ieee80211/phy0/add_iface\n"
258 " iwconfig mon0 mode monitor\n"
259 " ifconfig mon0 up\n"
260 " wlan-hwd mon0 Spam down mon0 with\n"
261 " radiotap header first\n"
262 "\n"); 258 "\n");
263 exit(1); 259 exit(1);
264} 260}
@@ -925,34 +921,75 @@ stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
925} 921}
926 922
927int 923int
928maketest(unsigned char * buf) 924maketest(unsigned char * buf, struct Hardware_Infos * dev)
929{ 925{
926 uint16_t * tmp16;
927 static uint16_t seqenz = 0;
928 static int first = 0;
929
930 const int rate = 11000000;
931 static const char
932 txt[] =
933 "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211Hallo1Hallo2 Hallo3 Hallo4...998877665544332211";
934
930 unsigned char u8aRadiotap[] = 935 unsigned char u8aRadiotap[] =
931 { 0x00, 0x00, // <-- radiotap version 936 { 0x00, 0x00, // <-- radiotap version
932 0x0c, 0x00, // <- radiotap header length 937 0x00, 0x00, // <- radiotap header length
933 0x04, 0x80, 0x00, 0x00, // <-- bitmap 938 0x04, 0x80, 0x02, 0x00, // <-- bitmap
934 0x00, // <-- rate 939 0x00, // <-- rate
935 0x00, // <-- padding for natural alignment 940 0x00, // <-- padding for natural alignment
936 0x18, 0x00, // <-- TX flags 941 0x10, 0x00, // <-- TX flags
942 0x04 //retries
937 }; 943 };
938 944
939 static const uint8_t u8aIeeeHeader[] = 945 /*uint8_t u8aRadiotap[] =
940 { 0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0; 946 {
947 0x00, 0x00, // <-- radiotap version
948 0x19, 0x00, // <- radiotap header length
949 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
950 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
951 0x00, // <-- flags (Offset +0x10)
952 0x6c, // <-- rate (0ffset +0x11)
953 0x71, 0x09, 0xc0, 0x00, // <-- channel
954 0xde, // <-- antsignal
955 0x00, // <-- antnoise
956 0x01, // <-- antenna
957 };*/
958
959 u8aRadiotap[8] = (rate/500000);
960 u8aRadiotap[2] = htole16(sizeof(u8aRadiotap));
961
962 static struct ieee80211_frame u8aIeeeHeader;
963
964 uint8_t u8aIeeeHeader_def[] =
965 { 0x08, 0x00, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
941 // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data 966 // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
942 // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS; 967 // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
943 0x00, 0x00, // Duration/ID 968 0x00, 0x00, // Duration/ID
944 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver 969
945 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender 970 //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver
946 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid 971 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver
972 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender
973 0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4,
974 //0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
947 0x10, 0x86, //Sequence Control 975 0x10, 0x86, //Sequence Control
948 }; 976 };
977 if (first == 0)
978 {
979 memcpy(&u8aIeeeHeader, u8aIeeeHeader_def, sizeof(struct ieee80211_frame));
980 memcpy(u8aIeeeHeader.i_addr2, dev->pl_mac, 6);
981 first = 1;
982 }
949 983
950 static const char txt[] = "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211"; 984 tmp16 = (uint16_t*) u8aIeeeHeader.i_dur;
985 *tmp16 = (uint16_t) htole16((sizeof(txt) + sizeof(struct ieee80211_frame) * 1000000) / rate + 290);
986 tmp16 = (uint16_t*) u8aIeeeHeader.i_seq;
987 *tmp16 = (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16(seqenz)
988 << IEEE80211_SEQ_SEQ_SHIFT);
989 seqenz++;
951 990
952 u8aRadiotap[8] = 8;
953 memcpy(buf, u8aRadiotap, sizeof(u8aRadiotap)); 991 memcpy(buf, u8aRadiotap, sizeof(u8aRadiotap));
954 struct ieee80211_frame * ieee = (struct ieee80211_frame *) u8aIeeeHeader; 992 memcpy(buf + sizeof(u8aRadiotap), &u8aIeeeHeader, sizeof(u8aIeeeHeader));
955 memcpy(buf + sizeof(u8aRadiotap), ieee, sizeof(u8aIeeeHeader));
956 memcpy(buf + sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader), txt, sizeof(txt)); 993 memcpy(buf + sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader), txt, sizeof(txt));
957 return sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader) + sizeof(txt); 994 return sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader) + sizeof(txt);
958 995
@@ -1021,7 +1058,7 @@ hardwaremode(int argc, char *argv[])
1021 while (0 == closeprog) 1058 while (0 == closeprog)
1022 { 1059 {
1023 1060
1024 write_pout.size = maketest(write_pout.buf); 1061 write_pout.size = maketest(write_pout.buf, &dev);
1025 tv.tv_sec = 2; 1062 tv.tv_sec = 2;
1026 tv.tv_usec = 0; 1063 tv.tv_usec = 0;
1027 retval = select(0, NULL, NULL, NULL, &tv); 1064 retval = select(0, NULL, NULL, NULL, &tv);
@@ -1112,7 +1149,9 @@ hardwaremode(int argc, char *argv[])
1112 if (write_pout.pos != write_pout.size && ret != 0) 1149 if (write_pout.pos != write_pout.size && ret != 0)
1113 { 1150 {
1114 closeprog = 1; 1151 closeprog = 1;
1115 fprintf(stderr, "Write ERROR packet not in one piece send: %u, %u\n", write_pout.pos, write_pout.size); 1152 fprintf(stderr,
1153 "Write ERROR packet not in one piece send: %u, %u\n",
1154 write_pout.pos, write_pout.size);
1116 } 1155 }
1117 else if (write_pout.pos == write_pout.size) 1156 else if (write_pout.pos == write_pout.size)
1118 { 1157 {
@@ -1186,6 +1225,7 @@ main(int argc, char *argv[])
1186 fprintf( 1225 fprintf(
1187 stderr, 1226 stderr,
1188 "This program must be started with the interface and the operating mode as argument.\n"); 1227 "This program must be started with the interface and the operating mode as argument.\n");
1228 usage();
1189 return 1; 1229 return 1;
1190 } 1230 }
1191 1231