diff options
Diffstat (limited to 'src/transport/gnunet_wlan_sender.c')
-rw-r--r-- | src/transport/gnunet_wlan_sender.c | 254 |
1 files changed, 135 insertions, 119 deletions
diff --git a/src/transport/gnunet_wlan_sender.c b/src/transport/gnunet_wlan_sender.c index 3aa32fb1c..f1a90178b 100644 --- a/src/transport/gnunet_wlan_sender.c +++ b/src/transport/gnunet_wlan_sender.c | |||
@@ -78,13 +78,13 @@ struct ieee80211_frame | |||
78 | * @return GNUNET_YES at success | 78 | * @return GNUNET_YES at success |
79 | */ | 79 | */ |
80 | static int | 80 | static int |
81 | getRadiotapHeader ( struct Radiotap_Send *header) | 81 | getRadiotapHeader (struct Radiotap_Send *header) |
82 | { | 82 | { |
83 | 83 | ||
84 | 84 | ||
85 | header->rate = 255; | 85 | header->rate = 255; |
86 | header->tx_power = 0; | 86 | header->tx_power = 0; |
87 | header->antenna = 0; | 87 | header->antenna = 0; |
88 | 88 | ||
89 | return GNUNET_YES; | 89 | return GNUNET_YES; |
90 | } | 90 | } |
@@ -98,9 +98,8 @@ getRadiotapHeader ( struct Radiotap_Send *header) | |||
98 | * @return GNUNET_YES if there was no error | 98 | * @return GNUNET_YES if there was no error |
99 | */ | 99 | */ |
100 | static int | 100 | static int |
101 | getWlanHeader (struct ieee80211_frame *Header, | 101 | getWlanHeader (struct ieee80211_frame *Header, const char *to_mac_addr, |
102 | const char *to_mac_addr, const char *mac, | 102 | const char *mac, unsigned int size) |
103 | unsigned int size) | ||
104 | { | 103 | { |
105 | uint16_t *tmp16; | 104 | uint16_t *tmp16; |
106 | const int rate = 11000000; | 105 | const int rate = 11000000; |
@@ -108,8 +107,7 @@ getWlanHeader (struct ieee80211_frame *Header, | |||
108 | Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA; | 107 | Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA; |
109 | Header->i_fc[1] = 0x00; | 108 | Header->i_fc[1] = 0x00; |
110 | memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid)); | 109 | memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid)); |
111 | memcpy (&Header->i_addr2, mac, | 110 | memcpy (&Header->i_addr2, mac, sizeof (mac_bssid)); |
112 | sizeof (mac_bssid)); | ||
113 | memcpy (&Header->i_addr1, to_mac_addr, sizeof (mac_bssid)); | 111 | memcpy (&Header->i_addr1, to_mac_addr, sizeof (mac_bssid)); |
114 | 112 | ||
115 | tmp16 = (uint16_t *) Header->i_dur; | 113 | tmp16 = (uint16_t *) Header->i_dur; |
@@ -120,115 +118,133 @@ getWlanHeader (struct ieee80211_frame *Header, | |||
120 | return GNUNET_YES; | 118 | return GNUNET_YES; |
121 | } | 119 | } |
122 | 120 | ||
123 | int main(int argc, char *argv[]){ | 121 | int |
122 | main (int argc, char *argv[]) | ||
123 | { | ||
124 | char msg_buf[WLAN_MTU]; | 124 | char msg_buf[WLAN_MTU]; |
125 | struct GNUNET_MessageHeader *msg; | 125 | struct GNUNET_MessageHeader *msg; |
126 | struct ieee80211_frame *wlan_header; | 126 | struct ieee80211_frame *wlan_header; |
127 | struct Radiotap_Send *radiotap; | 127 | struct Radiotap_Send *radiotap; |
128 | 128 | ||
129 | unsigned int temp[6]; | 129 | unsigned int temp[6]; |
130 | char inmac[6]; | 130 | char inmac[6]; |
131 | char outmac[6]; | 131 | char outmac[6]; |
132 | int pos; | 132 | int pos; |
133 | long long count; | 133 | long long count; |
134 | double bytes_per_s; | 134 | double bytes_per_s; |
135 | time_t start; | 135 | time_t start; |
136 | time_t akt; | 136 | time_t akt; |
137 | int i; | 137 | int i; |
138 | 138 | ||
139 | if (4 != argc) { | 139 | if (4 != argc) |
140 | fprintf( | 140 | { |
141 | stderr, | 141 | fprintf (stderr, |
142 | "This program must be started with the interface and the targets and source mac as argument.\nThis program was compiled at ----- %s ----\n", | 142 | "This program must be started with the interface and the targets and source mac as argument.\nThis program was compiled at ----- %s ----\n", |
143 | __TIMESTAMP__); | 143 | __TIMESTAMP__); |
144 | fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); | 144 | fprintf (stderr, |
145 | return 1; | 145 | "Usage: interface-name mac-target mac-source\n" |
146 | } | 146 | "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); |
147 | if (6 != | 147 | return 1; |
148 | sscanf(argv[3], "%x-%x-%x-%x-%x-%x", &temp[0],&temp[1],&temp[2],&temp[3],&temp[4],&temp[5])) | 148 | } |
149 | { | 149 | if (6 != |
150 | fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); | 150 | sscanf (argv[3], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], |
151 | return 1; | 151 | &temp[3], &temp[4], &temp[5])) |
152 | } | 152 | { |
153 | if (6 != | 153 | fprintf (stderr, |
154 | sscanf(argv[2], "%x-%x-%x-%x-%x-%x", &temp[0],&temp[1],&temp[2],&temp[3],&temp[4],&temp[5])) | 154 | "Usage: interface-name mac-target mac-source\n" |
155 | { | 155 | "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); |
156 | fprintf(stderr, "Usage: interface-name mac-target mac-source\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); | 156 | return 1; |
157 | return 1; | 157 | } |
158 | } | 158 | if (6 != |
159 | for (i = 0; i < 6; i++) | 159 | sscanf (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], |
160 | { | 160 | &temp[3], &temp[4], &temp[5])) |
161 | inmac[i] = temp[i]; | 161 | { |
162 | } | 162 | fprintf (stderr, |
163 | for (i = 0; i < 6; i++) | 163 | "Usage: interface-name mac-target mac-source\n" |
164 | { | 164 | "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); |
165 | outmac[i] = temp[i]; | 165 | return 1; |
166 | } | 166 | } |
167 | 167 | for (i = 0; i < 6; i++) | |
168 | 168 | { | |
169 | pid_t pid; | 169 | inmac[i] = temp[i]; |
170 | int commpipe[2]; /* This holds the fd for the input & output of the pipe */ | 170 | } |
171 | 171 | for (i = 0; i < 6; i++) | |
172 | /* Setup communication pipeline first */ | 172 | { |
173 | if(pipe(commpipe)){ | 173 | outmac[i] = temp[i]; |
174 | fprintf(stderr,"Pipe error!\n"); | 174 | } |
175 | exit(1); | 175 | |
176 | } | 176 | |
177 | 177 | pid_t pid; | |
178 | /* Attempt to fork and check for errors */ | 178 | int commpipe[2]; /* This holds the fd for the input & output of the pipe */ |
179 | if( (pid=fork()) == -1){ | 179 | |
180 | fprintf(stderr,"Fork error. Exiting.\n"); /* something went wrong */ | 180 | /* Setup communication pipeline first */ |
181 | exit(1); | 181 | if (pipe (commpipe)) |
182 | } | 182 | { |
183 | 183 | fprintf (stderr, "Pipe error!\n"); | |
184 | if(pid){ | 184 | exit (1); |
185 | /* A positive (non-negative) PID indicates the parent process */ | 185 | } |
186 | close(commpipe[0]); /* Close unused side of pipe (in side) */ | 186 | |
187 | setvbuf(stdout,(char*)NULL,_IONBF,0); /* Set non-buffered output on stdout */ | 187 | /* Attempt to fork and check for errors */ |
188 | 188 | if ((pid = fork ()) == -1) | |
189 | 189 | { | |
190 | msg = (struct GNUNET_MessageHeader*) msg_buf; | 190 | fprintf (stderr, "Fork error. Exiting.\n"); /* something went wrong */ |
191 | msg->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | 191 | exit (1); |
192 | msg->size = htons (WLAN_MTU); | 192 | } |
193 | radiotap = (struct Radiotap_Send *) &msg[1]; | 193 | |
194 | wlan_header = (struct ieee80211_frame *) &radiotap[1]; | 194 | if (pid) |
195 | pos = 0; | 195 | { |
196 | 196 | /* A positive (non-negative) PID indicates the parent process */ | |
197 | getRadiotapHeader(radiotap); | 197 | close (commpipe[0]); /* Close unused side of pipe (in side) */ |
198 | getWlanHeader(wlan_header, outmac, inmac, WLAN_MTU - sizeof(struct GNUNET_MessageHeader)); | 198 | setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */ |
199 | 199 | ||
200 | start = time(NULL); | 200 | |
201 | count = 0; | 201 | msg = (struct GNUNET_MessageHeader *) msg_buf; |
202 | while (1){ | 202 | msg->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); |
203 | pos += write(commpipe[1], msg, WLAN_MTU - pos); | 203 | msg->size = htons (WLAN_MTU); |
204 | if (pos % WLAN_MTU == 0){ | 204 | radiotap = (struct Radiotap_Send *) &msg[1]; |
205 | pos = 0; | 205 | wlan_header = (struct ieee80211_frame *) &radiotap[1]; |
206 | count ++; | 206 | pos = 0; |
207 | 207 | ||
208 | if (count % 1000 == 0){ | 208 | getRadiotapHeader (radiotap); |
209 | akt = time(NULL); | 209 | getWlanHeader (wlan_header, outmac, inmac, |
210 | bytes_per_s = count * WLAN_MTU / (akt - start); | 210 | WLAN_MTU - sizeof (struct GNUNET_MessageHeader)); |
211 | bytes_per_s /= 1024; | 211 | |
212 | printf("send %f kbytes/s\n", bytes_per_s); | 212 | start = time (NULL); |
213 | } | 213 | count = 0; |
214 | } | 214 | while (1) |
215 | 215 | { | |
216 | } | 216 | pos += write (commpipe[1], msg, WLAN_MTU - pos); |
217 | } | 217 | if (pos % WLAN_MTU == 0) |
218 | else{ | 218 | { |
219 | /* A zero PID indicates that this is the child process */ | 219 | pos = 0; |
220 | (void) close(0); | 220 | count++; |
221 | if (-1 == dup2(commpipe[0],0)) /* Replace stdin with the in side of the pipe */ | 221 | |
222 | fprintf (stderr, | 222 | if (count % 1000 == 0) |
223 | "dup2 failed: %s\n", | 223 | { |
224 | strerror (errno)); | 224 | akt = time (NULL); |
225 | (void) close(commpipe[1]); /* Close unused side of pipe (out side) */ | 225 | bytes_per_s = count * WLAN_MTU / (akt - start); |
226 | /* Replace the child fork with a new process */ | 226 | bytes_per_s /= 1024; |
227 | if (execl("gnunet-transport-wlan-helper","gnunet-transport-wlan-helper", argv[1], NULL) == -1) | 227 | printf ("send %f kbytes/s\n", bytes_per_s); |
228 | { | 228 | } |
229 | fprintf(stderr,"Could not start gnunet-transport-wlan-helper!"); | 229 | } |
230 | _exit(1); | 230 | |
231 | } | 231 | } |
232 | } | 232 | } |
233 | return 0; | 233 | else |
234 | { | ||
235 | /* A zero PID indicates that this is the child process */ | ||
236 | (void) close (0); | ||
237 | if (-1 == dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */ | ||
238 | fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); | ||
239 | (void) close (commpipe[1]); /* Close unused side of pipe (out side) */ | ||
240 | /* Replace the child fork with a new process */ | ||
241 | if (execl | ||
242 | ("gnunet-transport-wlan-helper", "gnunet-transport-wlan-helper", | ||
243 | argv[1], NULL) == -1) | ||
244 | { | ||
245 | fprintf (stderr, "Could not start gnunet-transport-wlan-helper!"); | ||
246 | _exit (1); | ||
247 | } | ||
248 | } | ||
249 | return 0; | ||
234 | } | 250 | } |