-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.c
2187 lines (1973 loc) · 53.1 KB
/
scan.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
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <net/if.h>
#include <errno.h>
#include <string.h>
#include <stdbool.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
#include <netlink/msg.h>
#include <netlink/attr.h>
#include "nl80211.h"
#include "iw.h"
#define WLAN_CAPABILITY_ESS (1<<0)
#define WLAN_CAPABILITY_IBSS (1<<1)
#define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
#define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
#define WLAN_CAPABILITY_PRIVACY (1<<4)
#define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
#define WLAN_CAPABILITY_PBCC (1<<6)
#define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
#define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
#define WLAN_CAPABILITY_QOS (1<<9)
#define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
#define WLAN_CAPABILITY_APSD (1<<11)
#define WLAN_CAPABILITY_RADIO_MEASURE (1<<12)
#define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
#define WLAN_CAPABILITY_DEL_BACK (1<<14)
#define WLAN_CAPABILITY_IMM_BACK (1<<15)
/* DMG (60gHz) 802.11ad */
/* type - bits 0..1 */
#define WLAN_CAPABILITY_DMG_TYPE_MASK (3<<0)
#define WLAN_CAPABILITY_DMG_TYPE_IBSS (1<<0) /* Tx by: STA */
#define WLAN_CAPABILITY_DMG_TYPE_PBSS (2<<0) /* Tx by: PCP */
#define WLAN_CAPABILITY_DMG_TYPE_AP (3<<0) /* Tx by: AP */
#define WLAN_CAPABILITY_DMG_CBAP_ONLY (1<<2)
#define WLAN_CAPABILITY_DMG_CBAP_SOURCE (1<<3)
#define WLAN_CAPABILITY_DMG_PRIVACY (1<<4)
#define WLAN_CAPABILITY_DMG_ECPAC (1<<5)
#define WLAN_CAPABILITY_DMG_SPECTRUM_MGMT (1<<8)
#define WLAN_CAPABILITY_DMG_RADIO_MEASURE (1<<12)
static unsigned char ms_oui[3] = { 0x00, 0x50, 0xf2 };
static unsigned char ieee80211_oui[3] = { 0x00, 0x0f, 0xac };
static unsigned char wfa_oui[3] = { 0x50, 0x6f, 0x9a };
struct scan_params {
bool unknown;
enum print_ie_type type;
bool show_both_ie_sets;
};
#define IEEE80211_COUNTRY_EXTENSION_ID 201
union ieee80211_country_ie_triplet {
struct {
__u8 first_channel;
__u8 num_channels;
__s8 max_power;
} __attribute__ ((packed)) chans;
struct {
__u8 reg_extension_id;
__u8 reg_class;
__u8 coverage_class;
} __attribute__ ((packed)) ext;
} __attribute__ ((packed));
static int parse_random_mac_addr(struct nl_msg *msg, char *arg)
{
char *a_addr, *a_mask, *sep;
unsigned char addr[ETH_ALEN], mask[ETH_ALEN];
char *addrs = arg + 9;
if (*addrs != '=')
return 0;
addrs++;
sep = strchr(addrs, '/');
a_addr = addrs;
if (!sep)
return 1;
*sep = 0;
a_mask = sep + 1;
if (mac_addr_a2n(addr, a_addr) || mac_addr_a2n(mask, a_mask))
return 1;
NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
NLA_PUT(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, mask);
return 0;
nla_put_failure:
return -ENOBUFS;
}
int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv)
{
struct nl_msg *matchset = NULL, *freqs = NULL, *ssids = NULL;
struct nl_msg *scan_plans = NULL;
struct nlattr *match = NULL, *plan = NULL;
enum {
ND_TOPLEVEL,
ND_MATCH,
ND_FREQS,
ND_ACTIVE,
ND_PLANS,
} parse_state = ND_TOPLEVEL;
int c = *argc;
char *end, **v = *argv;
int err = 0, i = 0;
unsigned int freq, interval = 0, delay = 0, iterations = 0;
bool have_matchset = false, have_freqs = false, have_ssids = false;
bool have_active = false, have_passive = false, have_plans = false;
uint32_t flags = 0;
matchset = nlmsg_alloc();
if (!matchset) {
err = -ENOBUFS;
goto out;
}
freqs = nlmsg_alloc();
if (!freqs) {
err = -ENOBUFS;
goto out;
}
ssids = nlmsg_alloc();
if (!ssids) {
err = -ENOMEM;
goto out;
}
scan_plans = nlmsg_alloc();
if (!scan_plans) {
err = -ENOBUFS;
goto out;
}
while (c) {
switch (parse_state) {
case ND_TOPLEVEL:
if (!strcmp(v[0], "interval")) {
c--; v++;
if (c == 0) {
err = -EINVAL;
goto nla_put_failure;
}
if (interval || have_plans) {
err = -EINVAL;
goto nla_put_failure;
}
interval = strtoul(v[0], &end, 10);
if (*end || !interval) {
err = -EINVAL;
goto nla_put_failure;
}
NLA_PUT_U32(msg,
NL80211_ATTR_SCHED_SCAN_INTERVAL,
interval);
} else if (!strcmp(v[0], "scan_plans")) {
parse_state = ND_PLANS;
if (have_plans || interval) {
err = -EINVAL;
goto nla_put_failure;
}
have_plans = true;
i = 0;
} else if (!strcmp(v[0], "delay")) {
c--; v++;
if (c == 0) {
err = -EINVAL;
goto nla_put_failure;
}
if (delay) {
err = -EINVAL;
goto nla_put_failure;
}
delay = strtoul(v[0], &end, 10);
if (*end) {
err = -EINVAL;
goto nla_put_failure;
}
NLA_PUT_U32(msg,
NL80211_ATTR_SCHED_SCAN_DELAY,
delay);
} else if (!strcmp(v[0], "matches")) {
parse_state = ND_MATCH;
if (have_matchset) {
err = -EINVAL;
goto nla_put_failure;
}
i = 0;
} else if (!strcmp(v[0], "freqs")) {
parse_state = ND_FREQS;
if (have_freqs) {
err = -EINVAL;
goto nla_put_failure;
}
have_freqs = true;
i = 0;
} else if (!strcmp(v[0], "active")) {
parse_state = ND_ACTIVE;
if (have_active || have_passive) {
err = -EINVAL;
goto nla_put_failure;
}
have_active = true;
i = 0;
} else if (!strcmp(v[0], "passive")) {
if (have_active || have_passive) {
err = -EINVAL;
goto nla_put_failure;
}
have_passive = true;
} else if (!strncmp(v[0], "randomise", 9) ||
!strncmp(v[0], "randomize", 9)) {
flags |= NL80211_SCAN_FLAG_RANDOM_ADDR;
if (c > 0) {
err = parse_random_mac_addr(msg, v[0]);
if (err)
goto nla_put_failure;
}
} else {
/* this element is not for us, so
* return to continue parsing.
*/
goto nla_put_failure;
}
c--; v++;
break;
case ND_MATCH:
if (!strcmp(v[0], "ssid")) {
c--; v++;
if (c == 0) {
err = -EINVAL;
goto nla_put_failure;
}
/* TODO: for now we can only have an
* SSID in the match, so we can start
* the match nest here.
*/
match = nla_nest_start(matchset, i);
if (!match) {
err = -ENOBUFS;
goto nla_put_failure;
}
NLA_PUT(matchset,
NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
strlen(v[0]), v[0]);
nla_nest_end(matchset, match);
match = NULL;
have_matchset = true;
i++;
c--; v++;
} else {
/* other element that cannot be part
* of a match indicates the end of the
* match. */
/* need at least one match in the matchset */
if (i == 0) {
err = -EINVAL;
goto nla_put_failure;
}
parse_state = ND_TOPLEVEL;
}
break;
case ND_FREQS:
freq = strtoul(v[0], &end, 10);
if (*end) {
if (i == 0) {
err = -EINVAL;
goto nla_put_failure;
}
parse_state = ND_TOPLEVEL;
} else {
NLA_PUT_U32(freqs, i, freq);
i++;
c--; v++;
}
break;
case ND_ACTIVE:
if (!strcmp(v[0], "ssid")) {
c--; v++;
if (c == 0) {
err = -EINVAL;
goto nla_put_failure;
}
NLA_PUT(ssids,
NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
strlen(v[0]), v[0]);
have_ssids = true;
i++;
c--; v++;
} else {
/* other element that cannot be part
* of a match indicates the end of the
* active set. */
/* need at least one item in the set */
if (i == 0) {
err = -EINVAL;
goto nla_put_failure;
}
parse_state = ND_TOPLEVEL;
}
break;
case ND_PLANS:
iterations = 0;
interval = strtoul(v[0], &end, 10);
if (*end) {
char *iter;
if (*end != ':') {
err = -EINVAL;
goto nla_put_failure;
}
iter = ++end;
iterations = strtoul(iter, &end, 10);
if (*end || !iterations) {
err = -EINVAL;
goto nla_put_failure;
}
}
plan = nla_nest_start(scan_plans, i + 1);
if (!plan) {
err = -ENOBUFS;
goto nla_put_failure;
}
NLA_PUT_U32(scan_plans,
NL80211_SCHED_SCAN_PLAN_INTERVAL,
interval);
if (iterations)
NLA_PUT_U32(scan_plans,
NL80211_SCHED_SCAN_PLAN_ITERATIONS,
iterations);
else
parse_state = ND_TOPLEVEL;
nla_nest_end(scan_plans, plan);
plan = NULL;
i++;
c--; v++;
break;
}
}
if (!have_ssids)
NLA_PUT(ssids, 1, 0, "");
if (!have_passive)
nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids);
if (have_freqs)
nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, freqs);
if (have_matchset)
nla_put_nested(msg, NL80211_ATTR_SCHED_SCAN_MATCH, matchset);
if (have_plans)
nla_put_nested(msg, NL80211_ATTR_SCHED_SCAN_PLANS, scan_plans);
if (flags)
NLA_PUT_U32(msg, NL80211_ATTR_SCAN_FLAGS, flags);
nla_put_failure:
if (match)
nla_nest_end(msg, match);
nlmsg_free(freqs);
nlmsg_free(matchset);
nlmsg_free(scan_plans);
out:
*argc = c;
*argv = v;
return err;
}
static int handle_scan(struct nl80211_state *state,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
{
struct nl_msg *ssids = NULL, *freqs = NULL;
char *eptr;
int err = -ENOBUFS;
int i;
enum {
NONE,
FREQ,
IES,
SSID,
MESHID,
DONE,
} parse = NONE;
int freq;
bool passive = false, have_ssids = false, have_freqs = false;
size_t ies_len = 0, meshid_len = 0;
unsigned char *ies = NULL, *meshid = NULL, *tmpies;
unsigned int flags = 0;
ssids = nlmsg_alloc();
if (!ssids)
return -ENOMEM;
freqs = nlmsg_alloc();
if (!freqs) {
nlmsg_free(ssids);
return -ENOMEM;
}
for (i = 0; i < argc; i++) {
switch (parse) {
case NONE:
if (strcmp(argv[i], "freq") == 0) {
parse = FREQ;
have_freqs = true;
break;
} else if (strcmp(argv[i], "ies") == 0) {
parse = IES;
break;
} else if (strcmp(argv[i], "lowpri") == 0) {
flags |= NL80211_SCAN_FLAG_LOW_PRIORITY;
break;
} else if (strcmp(argv[i], "flush") == 0) {
flags |= NL80211_SCAN_FLAG_FLUSH;
break;
} else if (strcmp(argv[i], "ap-force") == 0) {
flags |= NL80211_SCAN_FLAG_AP;
break;
} else if (strncmp(argv[i], "randomise", 9) == 0 ||
strncmp(argv[i], "randomize", 9) == 0) {
flags |= NL80211_SCAN_FLAG_RANDOM_ADDR;
err = parse_random_mac_addr(msg, argv[i]);
if (err)
goto nla_put_failure;
break;
} else if (strcmp(argv[i], "ssid") == 0) {
parse = SSID;
have_ssids = true;
break;
} else if (strcmp(argv[i], "passive") == 0) {
parse = DONE;
passive = true;
break;
} else if (strcmp(argv[i], "meshid") == 0) {
parse = MESHID;
break;
}
case DONE:
nlmsg_free(ssids);
nlmsg_free(freqs);
return 1;
case FREQ:
freq = strtoul(argv[i], &eptr, 10);
if (eptr != argv[i] + strlen(argv[i])) {
/* failed to parse as number -- maybe a tag? */
i--;
parse = NONE;
continue;
}
NLA_PUT_U32(freqs, i, freq);
break;
case IES:
ies = parse_hex(argv[i], &ies_len);
if (!ies)
goto nla_put_failure;
parse = NONE;
break;
case SSID:
NLA_PUT(ssids, i, strlen(argv[i]), argv[i]);
break;
case MESHID:
meshid_len = strlen(argv[i]);
meshid = (unsigned char *) malloc(meshid_len + 2);
if (!meshid)
goto nla_put_failure;
meshid[0] = 114; /* mesh element id */
meshid[1] = meshid_len;
memcpy(&meshid[2], argv[i], meshid_len);
meshid_len += 2;
parse = NONE;
break;
}
}
if (ies || meshid) {
tmpies = (unsigned char *) malloc(ies_len + meshid_len);
if (!tmpies) {
free(ies);
free(meshid);
goto nla_put_failure;
}
if (ies) {
memcpy(tmpies, ies, ies_len);
free(ies);
}
if (meshid) {
memcpy(&tmpies[ies_len], meshid, meshid_len);
free(meshid);
}
if (nla_put(msg, NL80211_ATTR_IE, ies_len + meshid_len, tmpies) < 0) {
free(tmpies);
goto nla_put_failure;
}
free(tmpies);
}
if (!have_ssids)
NLA_PUT(ssids, 1, 0, "");
if (!passive)
nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids);
if (have_freqs)
nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, freqs);
if (flags)
NLA_PUT_U32(msg, NL80211_ATTR_SCAN_FLAGS, flags);
err = 0;
nla_put_failure:
nlmsg_free(ssids);
nlmsg_free(freqs);
return err;
}
static void tab_on_first(bool *first)
{
if (!*first)
printf("\t");
else
*first = false;
}
static void print_ssid(const uint8_t type, uint8_t len, const uint8_t *data)
{
printf(" ");
print_ssid_escaped(len, data);
printf("\n");
}
#define BSS_MEMBERSHIP_SELECTOR_VHT_PHY 126
#define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127
static void print_supprates(const uint8_t type, uint8_t len, const uint8_t *data)
{
int i;
printf(" ");
for (i = 0; i < len; i++) {
int r = data[i] & 0x7f;
if (r == BSS_MEMBERSHIP_SELECTOR_VHT_PHY && data[i] & 0x80)
printf("VHT");
else if (r == BSS_MEMBERSHIP_SELECTOR_HT_PHY && data[i] & 0x80)
printf("HT");
else
printf("%d.%d", r/2, 5*(r&1));
printf("%s ", data[i] & 0x80 ? "*" : "");
}
printf("\n");
}
static void print_ds(const uint8_t type, uint8_t len, const uint8_t *data)
{
printf(" channel %d\n", data[0]);
}
static const char *country_env_str(char environment)
{
switch (environment) {
case 'I':
return "Indoor only";
case 'O':
return "Outdoor only";
case ' ':
return "Indoor/Outdoor";
default:
return "bogus";
}
}
static void print_country(const uint8_t type, uint8_t len, const uint8_t *data)
{
printf(" %.*s", 2, data);
printf("\tEnvironment: %s\n", country_env_str(data[2]));
data += 3;
len -= 3;
if (len < 3) {
printf("\t\tNo country IE triplets present\n");
return;
}
while (len >= 3) {
int end_channel;
union ieee80211_country_ie_triplet *triplet = (void *) data;
if (triplet->ext.reg_extension_id >= IEEE80211_COUNTRY_EXTENSION_ID) {
printf("\t\tExtension ID: %d Regulatory Class: %d Coverage class: %d (up to %dm)\n",
triplet->ext.reg_extension_id,
triplet->ext.reg_class,
triplet->ext.coverage_class,
triplet->ext.coverage_class * 450);
data += 3;
len -= 3;
continue;
}
/* 2 GHz */
if (triplet->chans.first_channel <= 14)
end_channel = triplet->chans.first_channel + (triplet->chans.num_channels - 1);
else
end_channel = triplet->chans.first_channel + (4 * (triplet->chans.num_channels - 1));
printf("\t\tChannels [%d - %d] @ %d dBm\n", triplet->chans.first_channel, end_channel, triplet->chans.max_power);
data += 3;
len -= 3;
}
return;
}
static void print_powerconstraint(const uint8_t type, uint8_t len, const uint8_t *data)
{
printf(" %d dB\n", data[0]);
}
static void print_tpcreport(const uint8_t type, uint8_t len, const uint8_t *data)
{
printf(" TX power: %d dBm\n", data[0]);
/* printf(" Link Margin (%d dB) is reserved in Beacons\n", data[1]); */
}
static void print_erp(const uint8_t type, uint8_t len, const uint8_t *data)
{
if (data[0] == 0x00)
printf(" <no flags>");
if (data[0] & 0x01)
printf(" NonERP_Present");
if (data[0] & 0x02)
printf(" Use_Protection");
if (data[0] & 0x04)
printf(" Barker_Preamble_Mode");
printf("\n");
}
static void print_cipher(const uint8_t *data)
{
if (memcmp(data, ms_oui, 3) == 0) {
switch (data[3]) {
case 0:
printf("Use group cipher suite");
break;
case 1:
printf("WEP-40");
break;
case 2:
printf("TKIP");
break;
case 4:
printf("CCMP");
break;
case 5:
printf("WEP-104");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else if (memcmp(data, ieee80211_oui, 3) == 0) {
switch (data[3]) {
case 0:
printf("Use group cipher suite");
break;
case 1:
printf("WEP-40");
break;
case 2:
printf("TKIP");
break;
case 4:
printf("CCMP");
break;
case 5:
printf("WEP-104");
break;
case 6:
printf("AES-128-CMAC");
break;
case 7:
printf("NO-GROUP");
break;
case 8:
printf("GCMP");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
}
static void print_auth(const uint8_t *data)
{
if (memcmp(data, ms_oui, 3) == 0) {
switch (data[3]) {
case 1:
printf("IEEE 802.1X");
break;
case 2:
printf("PSK");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else if (memcmp(data, ieee80211_oui, 3) == 0) {
switch (data[3]) {
case 1:
printf("IEEE 802.1X");
break;
case 2:
printf("PSK");
break;
case 3:
printf("FT/IEEE 802.1X");
break;
case 4:
printf("FT/PSK");
break;
case 5:
printf("IEEE 802.1X/SHA-256");
break;
case 6:
printf("PSK/SHA-256");
break;
case 7:
printf("TDLS/TPK");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else if (memcmp(data, wfa_oui, 3) == 0) {
switch (data[3]) {
case 1:
printf("OSEN");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
}
static void _print_rsn_ie(const char *defcipher, const char *defauth,
uint8_t len, const uint8_t *data, int is_osen)
{
bool first = true;
__u16 count, capa;
int i;
if (!is_osen) {
__u16 version;
version = data[0] + (data[1] << 8);
tab_on_first(&first);
printf("\t * Version: %d\n", version);
data += 2;
len -= 2;
}
if (len < 4) {
tab_on_first(&first);
printf("\t * Group cipher: %s\n", defcipher);
printf("\t * Pairwise ciphers: %s\n", defcipher);
return;
}
tab_on_first(&first);
printf("\t * Group cipher: ");
print_cipher(data);
printf("\n");
data += 4;
len -= 4;
if (len < 2) {
tab_on_first(&first);
printf("\t * Pairwise ciphers: %s\n", defcipher);
return;
}
count = data[0] | (data[1] << 8);
if (2 + (count * 4) > len)
goto invalid;
tab_on_first(&first);
printf("\t * Pairwise ciphers:");
for (i = 0; i < count; i++) {
printf(" ");
print_cipher(data + 2 + (i * 4));
}
printf("\n");
data += 2 + (count * 4);
len -= 2 + (count * 4);
if (len < 2) {
tab_on_first(&first);
printf("\t * Authentication suites: %s\n", defauth);
return;
}
count = data[0] | (data[1] << 8);
if (2 + (count * 4) > len)
goto invalid;
tab_on_first(&first);
printf("\t * Authentication suites:");
for (i = 0; i < count; i++) {
printf(" ");
print_auth(data + 2 + (i * 4));
}
printf("\n");
data += 2 + (count * 4);
len -= 2 + (count * 4);
if (len >= 2) {
capa = data[0] | (data[1] << 8);
tab_on_first(&first);
printf("\t * Capabilities:");
if (capa & 0x0001)
printf(" PreAuth");
if (capa & 0x0002)
printf(" NoPairwise");
switch ((capa & 0x000c) >> 2) {
case 0:
printf(" 1-PTKSA-RC");
break;
case 1:
printf(" 2-PTKSA-RC");
break;
case 2:
printf(" 4-PTKSA-RC");
break;
case 3:
printf(" 16-PTKSA-RC");
break;
}
switch ((capa & 0x0030) >> 4) {
case 0:
printf(" 1-GTKSA-RC");
break;
case 1:
printf(" 2-GTKSA-RC");
break;
case 2:
printf(" 4-GTKSA-RC");
break;
case 3:
printf(" 16-GTKSA-RC");
break;
}
if (capa & 0x0040)
printf(" MFP-required");
if (capa & 0x0080)
printf(" MFP-capable");
if (capa & 0x0200)
printf(" Peerkey-enabled");
if (capa & 0x0400)
printf(" SPP-AMSDU-capable");
if (capa & 0x0800)
printf(" SPP-AMSDU-required");
printf(" (0x%.4x)\n", capa);
data += 2;
len -= 2;
}
if (len >= 2) {
int pmkid_count = data[0] | (data[1] << 8);
if (len >= 2 + 16 * pmkid_count) {
tab_on_first(&first);
printf("\t * %d PMKIDs\n", pmkid_count);
/* not printing PMKID values */
data += 2 + 16 * pmkid_count;
len -= 2 + 16 * pmkid_count;
} else
goto invalid;
}
if (len >= 4) {
tab_on_first(&first);
printf("\t * Group mgmt cipher suite: ");
print_cipher(data);
printf("\n");
data += 4;
len -= 4;
}
invalid:
if (len != 0) {
printf("\t\t * bogus tail data (%d):", len);
while (len) {
printf(" %.2x", *data);
data++;
len--;
}
printf("\n");
}
}
static void print_rsn_ie(const char *defcipher, const char *defauth,
uint8_t len, const uint8_t *data)
{
_print_rsn_ie(defcipher, defauth, len, data, 0);
}
static void print_osen_ie(const char *defcipher, const char *defauth,
uint8_t len, const uint8_t *data)
{
printf("\n\t");
_print_rsn_ie(defcipher, defauth, len, data, 1);
}
static void print_rsn(const uint8_t type, uint8_t len, const uint8_t *data)
{
print_rsn_ie("CCMP", "IEEE 802.1X", len, data);
}
static void print_ht_capa(const uint8_t type, uint8_t len, const uint8_t *data)
{
printf("\n");
print_ht_capability(data[0] | (data[1] << 8));
print_ampdu_length(data[2] & 3);
print_ampdu_spacing((data[2] >> 2) & 7);
print_ht_mcs(data + 3);
}
static const char* ntype_11u(uint8_t t)
{
switch (t) {
case 0: return "Private";
case 1: return "Private with Guest";
case 2: return "Chargeable Public";
case 3: return "Free Public";
case 4: return "Personal Device";
case 5: return "Emergency Services Only";
case 14: return "Test or Experimental";
case 15: return "Wildcard";
default: return "Reserved";
}
}
static const char* vgroup_11u(uint8_t t)
{
switch (t) {
case 0: return "Unspecified";
case 1: return "Assembly";
case 2: return "Business";
case 3: return "Educational";
case 4: return "Factory and Industrial";
case 5: return "Institutional";