-
Notifications
You must be signed in to change notification settings - Fork 0
/
l2ping80211.c
916 lines (780 loc) · 21.3 KB
/
l2ping80211.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
/* This file is part of Lorcon
lorcon is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
lorcon is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with lorcon; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Copyright (c) 2005 dragorn and Joshua Wright
*/
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdint.h>
#include <time.h>
#include <pcap.h>
#include <signal.h>
#include <tx80211.h>
#include <lorcon_forge.h>
#include "l2ping80211.h"
#include "ieee80211.h"
/* Globals */
struct tx80211 tx;
pcap_t *p = NULL;
unsigned char *packet;
struct pcap_pkthdr *h;
char pcaperrbuf[PCAP_ERRBUF_SIZE];
int offset; /* Offset to the beginning of the 802.11 header */
int exitval=1;
void sigexit()
{
tx80211_close(&tx);
if (p != NULL) {
pcap_close(p);
}
exit(exitval);
}
void usage() {
struct tx80211_cardlist *cardlist = NULL;
int i;
cardlist = tx80211_getcardlist();
printf("l2ping80211\n"
"Usage : l2ping80211 [options] -i interface [-d driver] "
"-T targetmac -C testcase\n"
" [-S sourcemac -B bssidmac -D destmac -t usectimer"
" -n count -c channel -V]\n");
printf("\nSupported test cases:\n");
i=0;
while(testcases[i].testname != NULL) {
printf("\t%d\t%s\n", testcases[i].testnum,
testcases[i].testname);
i++;
}
if (cardlist == NULL) {
fprintf(stderr, "Error accessing supported cardlist\n");
} else {
printf("\nSupported drivers: ");
for (i = 1; i < cardlist->num_cards; i++) {
printf("%s ", cardlist->cardnames[i]);
}
printf("\n");
}
tx80211_freecardlist(cardlist);
}
/* Converts a string to uppercase */
void to_upper (char *s)
{
char *p, offset;
offset = 'A' - 'a';
for(p=s;*p != '\0';p++) {
if(islower(*p)) {
*p += offset;
}
}
}
/* Determine radiotap data length (including header) and return offset for the
beginning of the 802.11 header */
int radiotap_offset(pcap_t *p, struct pcap_pkthdr *h)
{
struct tx80211_radiotap_header *rtaphdr;
int rtaphdrlen=0;
/* Grab a packet to examine radiotap header */
if (pcap_next_ex(p, &h, (const u_char **) &packet) > -1) {
rtaphdr = (struct tx80211_radiotap_header *) packet;
rtaphdrlen = tx80211_le16(rtaphdr->it_len); /* rtap is LE */
/* Sanity check on header length */
if (rtaphdrlen > (h->len - 10)) {
return -2; /* Bad radiotap data */
}
return rtaphdrlen;
}
return -1;
}
void lamont_hdump(unsigned char *bp, unsigned int length) {
/* stolen from tcpdump, then kludged extensively */
static const char asciify[] = "................................ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~.................................................................................................................................";
const unsigned short *sp;
const unsigned char *ap;
unsigned int i, j;
int nshorts, nshorts2;
int padding;
printf("\n\t");
padding = 0;
sp = (unsigned short *)bp;
ap = (unsigned char *)bp;
nshorts = (unsigned int) length / sizeof(unsigned short);
nshorts2 = (unsigned int) length / sizeof(unsigned short);
i = 0;
j = 0;
while(1) {
while (--nshorts >= 0) {
printf(" %04x", tx80211_ntoh16(*sp));
sp++;
if ((++i % 8) == 0)
break;
}
if (nshorts < 0) {
if ((length & 1) && (((i-1) % 8) != 0)) {
printf(" %02x ", *(unsigned char *)sp);
padding++;
}
nshorts = (8 - (nshorts2 - nshorts));
while(--nshorts >= 0) {
printf(" ");
}
if (!padding) printf(" ");
}
printf(" ");
while (--nshorts2 >= 0) {
printf("%c%c", asciify[*ap], asciify[*(ap+1)]);
ap += 2;
if ((++j % 8) == 0) {
printf("\n\t");
break;
}
}
if (nshorts2 < 0) {
if ((length & 1) && (((j-1) % 8) != 0)) {
printf("%c", asciify[*ap]);
}
break;
}
}
if ((length & 1) && (((i-1) % 8) == 0)) {
printf(" %02x", *(unsigned char *)sp);
printf(" %c", asciify[*ap]);
}
printf("\n");
}
/* Converts a MAC address string to a u8 array, returns -1 on error */
int string2mac (char *string, uint8_t *mac_buf)
{
char *ptr, *next;
unsigned long val;
int i;
to_upper(string);
ptr = next = string;
for(i=0;i < 6;i++) {
if((val = strtoul(next, &ptr, 16)) > 255) {
return(-1);
}
mac_buf[i] = (unsigned char)val;
if((next == ptr) && (i != 6 - 1)) {
return(-1);
}
next = ptr + 1;
}
return(0);
}
char *printmac(unsigned char *mac)
{
static char macstring[18];
memset(&macstring, 0, sizeof(macstring));
(void)snprintf(macstring, sizeof(macstring),
"%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return (macstring);
}
/* Look for frames matching the specified attributes, returning the delta
* time. */
int watchfor(int type, int subtype, uint8_t *addr1,
uint8_t *addr2, uint8_t *addr3, int flags, int timeout) {
struct ieee80211_hdr *dot11hdr;
struct timeval starttime, now;
gettimeofday(&starttime, NULL);
unsigned int elapsed;
unsigned int finishtime = ((starttime.tv_sec * 1000000) + starttime.tv_usec + timeout);
gettimeofday(&now, NULL);
while ((unsigned int)((now.tv_sec * 1000000) + now.tv_usec) < finishtime) {
if (pcap_next_ex(p, &h, (const u_char **) &packet) != 1) {
return -1;
}
if (h->len < offset)
continue;
gettimeofday(&now, NULL);
dot11hdr = (struct ieee80211_hdr *) &(packet[offset]);
if (dot11hdr->u1.fc.type != type) continue;
if (dot11hdr->u1.fc.subtype != subtype) continue;
if ((dot11hdr->u1.fchdr & tx80211_hton16(0x00ff)) != flags)
continue;
if (addr1 != NULL && (memcmp(addr1, dot11hdr->addr1, 6) != 0))
continue;
if (addr2 != NULL && (memcmp(addr2, dot11hdr->addr2, 6) != 0))
continue;
if (addr3 != NULL && (memcmp(addr3, dot11hdr->addr3, 6) != 0))
continue;
elapsed = ((unsigned int)((now.tv_sec * 1000000) + (now.tv_usec)) - (unsigned int)((starttime.tv_sec * 1000000) + (starttime.tv_usec)));
return elapsed;
}
return 0;
}
/* Send a NULL data frame to the target with a false BSSID, watch for the
* DEAUTH that follows.
*/
void l2ping_test_datainvalidbssiddeauth(tx80211_t *in_tx, int npacks,
uint8_t *targetmac, uint32_t usectimeout)
{
int i, duration;
struct lcpa_metapack *metapack;
tx80211_packet_t txpack;
uint8_t sourcemac[6];
uint8_t bssidmac[6];
metapack = lcpa_init();
tx80211_initpacket(&txpack);
srand(time(NULL));
lcpf_randmac(sourcemac, 1);
lcpf_randmac(bssidmac, 1);
lcpf_80211headers(metapack,
WLAN_FC_TYPE_DATA,
WLAN_FC_SUBTYPE_DATANULL,
0x02, /* fcflags, FromDS */
0x00, /* duration */
targetmac,
bssidmac,
sourcemac,
NULL, /* addr4 */
0, /* Fragment number */
0); /* Sequence number */
lcpa_freeze(metapack, &txpack);
lcpa_free(metapack);
for(i=0; i < npacks; i++) {
if (tx80211_txpacket(in_tx, &txpack) < 0) {
fprintf(stderr, "Unable to inject packet: %s\n",
tx80211_geterrstr(in_tx));
return;
}
duration = watchfor(WLAN_FC_TYPE_MGMT, WLAN_FC_SUBTYPE_DEAUTH,
bssidmac, targetmac, NULL, 0, usectimeout);
if (duration > 0) {
print_response(targetmac, i+1, h->len, duration);
} else {
print_noresponse(targetmac, i+1, usectimeout);
}
sleep(1);
}
return;
}
/* Send a NULL data frame to the target with a false BSSID, watch for the
* ACK that follows.
*/
void l2ping_test_datainvalidbssid(tx80211_t *in_tx, int npacks,
uint8_t *targetmac, uint32_t usectimeout)
{
int i, duration;
struct lcpa_metapack *metapack;
tx80211_packet_t txpack;
uint8_t sourcemac[6];
uint8_t bssidmac[6];
metapack = lcpa_init();
tx80211_initpacket(&txpack);
srand(time(NULL));
lcpf_randmac(sourcemac, 1);
lcpf_randmac(bssidmac, 1);
lcpf_80211headers(metapack,
WLAN_FC_TYPE_DATA,
WLAN_FC_SUBTYPE_DATANULL,
0x02, /* fcflags, FromDS */
0x00, /* duration */
targetmac,
bssidmac,
sourcemac,
NULL, /* addr4 */
0, /* Fragment number */
0); /* Sequence number */
lcpa_freeze(metapack, &txpack);
lcpa_free(metapack);
for(i=0; i < npacks; i++) {
if (tx80211_txpacket(in_tx, &txpack) < 0) {
fprintf(stderr, "Unable to inject packet: %s\n",
tx80211_geterrstr(in_tx));
return;
}
duration = watchfor(WLAN_FC_TYPE_CTRL, WLAN_FC_SUBTYPE_ACK,
bssidmac, NULL, NULL, 0, usectimeout);
if (duration > 0) {
print_response(targetmac, i+1, h->len, duration);
} else {
print_noresponse(targetmac, i+1, usectimeout);
}
sleep(1);
}
return;
}
/*
* Send a NULL data frame to the AP target with a valid BSSID, valid source
* and a destination multicast address. Watch for the multicast data
* frame response with FromDS set that follows.
*/
void l2ping_test_nulldatamcast(tx80211_t *in_tx, int npacks,
uint8_t *bssid, uint8_t *source, uint32_t usectimeout)
{
int i, duration;
struct lcpa_metapack *metapack;
tx80211_packet_t txpack;
uint8_t mcastdest[6];
metapack = lcpa_init();
tx80211_initpacket(&txpack);
srand(time(NULL));
lcpf_randmac(mcastdest, 1);
mcastdest[0] = 0xff; /* multicast bit set */
lcpf_80211headers(metapack,
WLAN_FC_TYPE_DATA,
WLAN_FC_SUBTYPE_DATANULL,
0x01, /* fcflags, ToDS */
0x00, /* duration */
bssid, /* target */
source,
mcastdest,
NULL, /* addr4 */
0, /* Fragment number */
0); /* Sequence number */
lcpa_freeze(metapack, &txpack);
lcpa_free(metapack);
for(i=0; i < npacks; i++) {
if (tx80211_txpacket(in_tx, &txpack) < 0) {
fprintf(stderr, "Unable to inject packet: %s\n",
tx80211_geterrstr(in_tx));
return;
}
duration = watchfor(WLAN_FC_TYPE_DATA, WLAN_FC_SUBTYPE_DATANULL,
mcastdest, bssid, source, 0, usectimeout);
if (duration > 0) {
print_response(bssid, i+1, h->len, duration);
} else {
print_noresponse(bssid, i+1, usectimeout);
}
sleep(1);
}
return;
}
/*
* Send a NULL data frame to the target with a valid BSSID, watch for the
* ACK that follows.
*/
void l2ping_test_datavalidbssid(tx80211_t *in_tx, int npacks,
uint8_t *targetmac, uint8_t *bssid, uint32_t usectimeout)
{
int i, duration;
struct lcpa_metapack *metapack;
tx80211_packet_t txpack;
uint8_t sourcemac[6];
metapack = lcpa_init();
tx80211_initpacket(&txpack);
srand(time(NULL));
lcpf_randmac(sourcemac, 1);
lcpf_80211headers(metapack,
WLAN_FC_TYPE_DATA,
WLAN_FC_SUBTYPE_DATANULL,
0x02, /* fcflags, FromDS */
0x00, /* duration */
targetmac,
bssid,
sourcemac,
NULL, /* addr4 */
0, /* Fragment number */
0); /* Sequence number */
lcpa_freeze(metapack, &txpack);
lcpa_free(metapack);
for(i=0; i < npacks; i++) {
if (tx80211_txpacket(in_tx, &txpack) < 0) {
fprintf(stderr, "Unable to inject packet: %s\n",
tx80211_geterrstr(in_tx));
return;
}
duration = watchfor(WLAN_FC_TYPE_CTRL, WLAN_FC_SUBTYPE_ACK,
bssid, NULL, NULL, 0, usectimeout);
if (duration > 0) {
print_response(targetmac, i+1, h->len, duration);
} else {
print_noresponse(targetmac, i+1, usectimeout);
}
sleep(1);
}
return;
}
/* Send an RTS frame to the target station, watch for CTS response */
void l2ping_test_rtscts(tx80211_t *in_tx, int npacks, uint8_t *targetmac,
uint32_t usectimeout)
{
int i, duration;
struct lcpa_metapack *metapack;
tx80211_packet_t txpack;
uint8_t transmittermac[6];
metapack = lcpa_init();
tx80211_initpacket(&txpack);
srand(time(NULL));
lcpf_randmac(transmittermac, 1);
lcpf_rts(metapack,
targetmac,
transmittermac,
0x00, /* fcflags */
0x00); /* duration */
lcpa_freeze(metapack, &txpack);
lcpa_free(metapack);
//lamont_hdump(txpack.packet, txpack.plen);
for(i=0; i < npacks; i++) {
if (tx80211_txpacket(in_tx, &txpack) < 0) {
fprintf(stderr, "Unable to inject packet: %s\n",
tx80211_geterrstr(in_tx));
return;
}
duration = watchfor(WLAN_FC_TYPE_CTRL, WLAN_FC_SUBTYPE_CTS,
transmittermac, NULL, NULL, 0, usectimeout);
if (duration > 0) {
print_response(targetmac, i+1, h->len, duration);
} else {
print_noresponse(targetmac, i+1, usectimeout);
}
sleep(1);
}
return;
}
/*
* Send a NULL data frame to the AP target with a valid BSSID, invalid source
* and a destination broadcast address. Watch for the deauth
* frame response from the AP.
*/
void l2ping_test_nulldatainvalidsrc(tx80211_t *in_tx, int npacks,
uint8_t *targetmac, uint32_t usectimeout)
{
int i, duration;
struct lcpa_metapack *metapack;
tx80211_packet_t txpack;
uint8_t invalidsource[6];
uint8_t broadcastdest[] = "\xff\xff\xff\xff\xff\xff";
metapack = lcpa_init();
tx80211_initpacket(&txpack);
srand(time(NULL));
lcpf_randmac(invalidsource, 1);
lcpf_80211headers(metapack,
WLAN_FC_TYPE_DATA,
WLAN_FC_SUBTYPE_DATANULL,
0x01, /* fcflags, ToDS */
0x00, /* duration */
targetmac, /* target/BSSID */
invalidsource,
broadcastdest,
NULL, /* addr4 */
0, /* Fragment number */
0); /* Sequence number */
lcpa_freeze(metapack, &txpack);
lcpa_free(metapack);
//lamont_hdump(txpack.packet, txpack.plen);
for(i=0; i < npacks; i++) {
if (tx80211_txpacket(in_tx, &txpack) < 0) {
fprintf(stderr, "Unable to inject packet: %s\n",
tx80211_geterrstr(in_tx));
return;
}
duration = watchfor(WLAN_FC_TYPE_MGMT, WLAN_FC_SUBTYPE_DEAUTH,
invalidsource, targetmac, targetmac, 0,
usectimeout);
if (duration > 0) {
print_response(targetmac, i+1, h->len, duration);
} else {
print_noresponse(targetmac, i+1, usectimeout);
}
sleep(1);
}
return;
}
void print_noresponse(uint8_t *mac, int num, int timeout)
{
printf("No response from %s : num=%d time=%d usec\n",
printmac(mac), num, timeout);
}
void print_response(uint8_t *mac, int num, int len, int time)
{
/* Set exitval to 0 since we got a response */
exitval = 0;
printf("%d bytes from %s : num=%d time=%d usec\n",
len, printmac(mac), num, time);
}
void print_test_detail() {
int i=0;
while(testcases[i].testdesc != NULL) {
printf("Test Case:\t%d\n", testcases[i].testnum);
printf("Test Name:\t%s\n", testcases[i].testname);
printf("Test Desc:\t%s\n", testcases[i].testdesc);
printf("Test Reqs:\t");
if (testcases[i].asmac) printf("source (-S) ");
if (testcases[i].admac) printf("dest (-D) ");
if (testcases[i].abmac) printf("BSSID (-B) ");
if (!(testcases[i].abmac || testcases[i].admac,
testcases[i].asmac)) {
printf("None.");
}
printf("\n\n");
i++;
}
}
int main(int argc, char *argv[]) {
uint8_t smac[6], dmac[6], bmac[6], tmac[6];
int asmac = 0, admac = 0, abmac = 0, atmac = 0, atestcase = 0, i;
int optmissing = 0, pcaptype=0;
char *interface = NULL;
char *driver = NULL;
int channel = 0;
/* Default number of packets to send, override with -n */
int npacks = 4;
struct testcase *testc = NULL;
int txdrv = INJ_NODRIVER;
uint32_t usectimeout=10000; /* Default 10000 usec */
int c = 0;
while ((c = getopt(argc, argv, "i:t:c:d:S:B:D:n:h?C:T:V")) != EOF) {
switch (c) {
case 'V':
print_test_detail();
return 0;
break;
case 'C':
if (sscanf(optarg, "%d", &atestcase) != 1) {
fprintf(stderr, "%s: Illegal test case,"
" expected number\n",
argv[0]);
usage();
return -1;
}
break;
case 'i':
interface = strdup(optarg);
break;
case 't':
if (sscanf(optarg, "%d", &usectimeout) != 1) {
fprintf(stderr, "%s: Illegal usec time,"
" expected number\n",
argv[0]);
usage();
return -1;
}
break;
case 'c':
if (sscanf(optarg, "%d", &channel) != 1) {
fprintf(stderr, "%s: Illegal channel, "
"expected number\n",
argv[0]);
usage();
return -1;
}
break;
case 'd':
txdrv = tx80211_resolvecard(optarg);
break;
case 'T':
if (string2mac(optarg, tmac) < 0) {
fprintf(stderr, "%s: Illegal target "
"mac, expected "
"aa:bb:cc:dd:ee:ff or "
"aabbccddeeff\n",
argv[0]);
usage();
return -1;
}
atmac = 1;
break;
case 'S':
if (string2mac(optarg, smac) < 0) {
fprintf(stderr, "%s: Illegal sourcemac,"
" expected "
"aa:bb:cc:dd:ee:ff or "
"aabbccddeeff\n",
argv[0]);
usage();
return -1;
}
asmac = 1;
break;
case 'D':
if (string2mac(optarg, dmac) < 0) {
fprintf(stderr, "%s: Illegal destmac, "
"expected "
"aa:bb:cc:dd:ee:ff or "
"aabbccddeeff\n",
argv[0]);
usage();
return -1;
}
admac = 1;
break;
case 'B':
if (string2mac(optarg, bmac) < 0) {
fprintf(stderr, "%s: Illegal bssidmac, "
"expected "
"aa:bb:cc:dd:ee:ff or "
"aabbccddeeff\n",
argv[0]);
usage();
return -1;
}
abmac = 1;
break;
case 'n':
if (sscanf(optarg, "%d", &npacks) != 1) {
fprintf(stderr, "%s: Illegal number of "
" packets\n", argv[0]);
usage();
return -1;
}
break;
case '?':
case 'h':
default:
usage();
return -1;
break;
}
}
if (interface != NULL && txdrv == INJ_NODRIVER) {
fprintf(stderr, "%s: Attempting to detect driver type for "
"interface '%s'\n", argv[0], interface);
if ((txdrv = tx80211_resolveinterface(interface)) == INJ_NODRIVER) {
fprintf(stderr, "%s: Unable to autodetect a driver for '%s', "
"specify one using -d [driver name]\n", argv[0],
interface);
usage();
return -1;
}
driver = tx80211_getdrivername(txdrv);
fprintf(stderr, "%s: Found driver '%s' for interface '%s'\n",
argv[0], driver, interface);
}
if (interface == NULL || txdrv == INJ_NODRIVER ||
atmac == 0 || atestcase == 0) {
usage();
return -1;
}
/* See if this is a valid test case */
i=0;
testc = NULL;
while (testcases[i].testdesc != NULL) {
if (testcases[i].testnum == atestcase) {
testc = &testcases[i];
break;
}
i++;
}
if (testc == NULL) {
fprintf(stderr, "Unsupported test case selected (%d)\n",
atestcase);
usage();
return -1;
}
/*
* Examine the addresses supplied for the specified test case,
* error if we don't have the right addresses
*/
if (testc->abmac && testc->abmac != abmac) {
fprintf(stderr, "Must specify the BSSID address for this test "
"case.\n");
optmissing = 1;
}
if (testc->asmac && testc->asmac != asmac) {
fprintf(stderr, "Must specify the source address for this test "
"case.\n");
optmissing = 1;
}
if (testc->admac && testc->admac != admac) {
fprintf(stderr, "Must specify the destination address for "
"this test case.\n");
optmissing = 1;
}
if (optmissing == 1) {
usage();
return -1;
}
/* Setup the signal handler */
signal(SIGINT, sigexit);
signal(SIGTERM, sigexit);
signal(SIGQUIT, sigexit);
if (tx80211_init(&tx, interface, txdrv) < 0) {
fprintf(stderr, "Error initializing interface: %s\n",
tx80211_geterrstr(&tx));
return 1;
}
if (tx80211_setfunctionalmode(&tx, TX80211_FUNCMODE_INJMON) < 0) {
fprintf(stderr, "Error setting functional mode: %s\n",
tx80211_geterrstr(&tx));
tx80211_close(&tx);
return 1;
}
if (channel != 0) {
if (tx80211_setchannel(&tx, channel) < 0) {
fprintf(stderr, "Error setting channel: %s\n",
tx80211_geterrstr(&tx));
tx80211_close(&tx);
return 1;
}
}
if (tx80211_open(&tx) < 0) {
fprintf(stderr, "Unable to open interface: %s\n",
tx80211_geterrstr(&tx));
tx80211_close(&tx);
return 1;
}
/* Assume for now it's a libpcap file */
p = pcap_open_live(interface, SNAPLEN, PROMISC, TIMEOUT, pcaperrbuf);
if (p == NULL) {
perror("Unable to open capture file");
return (-1);
}
/* Determine link type */
pcaptype = pcap_datalink(p);
/* Determine offset to EAP frame based on link type */
switch (pcaptype) {
case DLT_PRISM_HEADER:
offset = 144;
break;
case DLT_IEEE802_11:
offset = 0;
break;
case DLT_IEEE802_11_RADIO:
offset = radiotap_offset(p, h);
if (offset < 0) {
fprintf(stderr, "Error determining size of the"
" radiotap header.\n");
tx80211_close(&tx);
pcap_close(p);
return -1;
}
break;
default:
fprintf(stderr, "Unsupported link type: %d\n",
pcaptype);
break;
}
printf("L2PING %s using test case %d (%s)\n", printmac(tmac),
atestcase, testc->testname);
switch(atestcase) {
case L2PING_TEST_NULLDATAMCAST:
l2ping_test_nulldatamcast(&tx, npacks, tmac, smac, usectimeout);
break;
case L2PING_TEST_RTSCTS:
l2ping_test_rtscts(&tx, npacks, tmac, usectimeout);
break;
case L2PING_TEST_DATAINVALIDBSSID:
l2ping_test_datainvalidbssid(&tx, npacks, tmac, usectimeout);
break;
case L2PING_TEST_DATAINVALIDBSSIDDEAUTH:
l2ping_test_datainvalidbssiddeauth(&tx, npacks, tmac,
usectimeout);
break;
case L2PING_TEST_DATAVALIDBSSID:
l2ping_test_datavalidbssid(&tx, npacks, tmac, bmac,
usectimeout);
break;
case L2PING_TEST_NULLDATAINVALIDSRC:
l2ping_test_nulldatainvalidsrc(&tx, npacks, tmac, usectimeout);
break;
default:
fprintf(stderr, "Unsupported test case: %d\n", atestcase);
return -1;
}
return exitval;
}