forked from qca/sigma-dut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ap.c
13714 lines (11998 loc) · 364 KB
/
ap.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
/*
* Sigma Control API DUT (station/AP)
* Copyright (c) 2010-2011, Atheros Communications, Inc.
* Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
* Copyright (c) 2018-2019, The Linux Foundation
* All Rights Reserved.
* Licensed under the Clear BSD license. See README for more details.
*/
#include "sigma_dut.h"
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/utsname.h>
#include <sys/ioctl.h>
#ifdef __linux__
#include <limits.h>
#include <dirent.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#endif /* __linux__ */
#ifdef __QNXNTO__
#include <ifaddrs.h>
#include <net/if_dl.h>
#endif /* __QNXNTO__ */
#include "wpa_ctrl.h"
#include "wpa_helpers.h"
#ifdef ANDROID
#include <hardware_legacy/wifi.h>
#include <grp.h>
#include <pwd.h>
#endif /* ANDROID */
/* Temporary files for ap_send_addba_req */
#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
#define VI_QOS_FILE "/tmp/vi-qos.txt"
#define VI_QOS_REFFILE "/etc/vi-qos.txt"
/* Configuration file name on Android */
#ifndef ANDROID_CONFIG_FILE
#define ANDROID_CONFIG_FILE "/data/misc/wifi/hostapd.conf"
#endif /* ANDROID_CONFIG_FILE */
/* Maximum length of the line in the configuration file */
#define MAX_CONF_LINE_LEN (156)
#ifndef SIGMA_DUT_HOSTAPD_PID_FILE
#define SIGMA_DUT_HOSTAPD_PID_FILE "/tmp/sigma_dut-ap-hostapd.pid"
#endif /* SIGMA_DUT_HOSTAPD_PID_FILE */
/* The following is taken from Hotspot 2.0 testplan Appendix B.1 */
#define ANQP_VENUE_NAME_1 "02019c0002083d656e6757692d466920416c6c69616e63650a3239383920436f7070657220526f61640a53616e746120436c6172612c2043412039353035312c205553415b63686957692d4669e88194e79b9fe5ae9ee9aa8ce5aea40ae4ba8ce4b99de585abe4b99de5b9b4e5ba93e69f8fe8b7af0ae59ca3e5858be68b89e68b892c20e58aa0e588a9e7a68fe5b0bce4ba9a39353035312c20e7be8ee59bbd"
#define ANQP_VENUE_NAME_1_CHI "P\"\x63\x68\x69\x3a\x57\x69\x2d\x46\x69\xe8\x81\x94\xe7\x9b\x9f\xe5\xae\x9e\xe9\xaa\x8c\xe5\xae\xa4\\n\xe4\xba\x8c\xe4\xb9\x9d\xe5\x85\xab\xe4\xb9\x9d\xe5\xb9\xb4\xe5\xba\x93\xe6\x9f\x8f\xe8\xb7\xaf\\n\xe5\x9c\xa3\xe5\x85\x8b\xe6\x8b\x89\xe6\x8b\x89\x2c\x20\xe5\x8a\xa0\xe5\x88\xa9\xe7\xa6\x8f\xe5\xb0\xbc\xe4\xba\x9a\x39\x35\x30\x35\x31\x2c\x20\xe7\xbe\x8e\xe5\x9b\xbd\""
#define ANQP_IP_ADDR_TYPE_1 "060101000c"
#define ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "dddd2700506f9a11030011656e6757692d466920416c6c69616e63650e63686957692d4669e88194e79b9f"
#define ANQP_HS20_WAN_METRICS_1 "dddd1300506f9a11040001c40900008001000000000000"
#define ANQP_HS20_CONNECTION_CAPABILITY_1 "dddd3200506f9a1105000100000006140001061600000650000106bb010106bb060006c4130011f4010111c413001194110132000001"
#define QOS_MAP_SET_1 "53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,255"
#define QOS_MAP_SET_2 "8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,63"
#define ADV_OF_CHARGE_1 \
"bc01000000d200454e475553443c3f786d6c2076657273696f6e3d22312e30222065" \
"6e636f64696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f77" \
"77772e77692d66692e6f72672f73706563696669636174696f6e732f686f7473706f7432646f" \
"74302f76312e302f616f637069223e3c4465736372697074696f6e3e57692d46692061636365" \
"737320666f72203120686f75722c207768696c6520796f752077616974206174207468652067" \
"6174652c2024302e39393c2f4465736372697074696f6e3e3c2f506c616e3ee3004652414341" \
"443c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d38223f" \
"3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77692d66692e6f72672f737065" \
"63696669636174696f6e732f686f7473706f7432646f74302f76312e302f616f637069223e3c" \
"4465736372697074696f6e3e416363c3a8732057692d46692070656e64616e74203120686575" \
"72652c2070656e64616e742071756520766f757320617474656e64657a20c3a0206c6120706f" \
"7274652c20302c393920243c2f4465736372697074696f6e3e3c2f506c616e3ea101010000c7" \
"00454e475553443c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d2255" \
"54462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77692d66692e6f" \
"72672f73706563696669636174696f6e732f686f7473706f7432646f74302f76312e302f616f" \
"637069223e3c4465736372697074696f6e3e446f776e6c6f616420766964656f7320666f7220" \
"796f757220666c696768742c2024322e393920666f7220313047423c2f446573637269707469" \
"6f6e3e3c2f506c616e3ed3004652414341443c3f786d6c2076657273696f6e3d22312e302220" \
"656e636f64696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f" \
"7777772e77692d66692e6f72672f73706563696669636174696f6e732f686f7473706f743264" \
"6f74302f76312e302f616f637069223e3c4465736372697074696f6e3e54c3a96cc3a9636861" \
"7267657a2064657320766964c3a96f7320706f757220766f74726520766f6c2c20322c393920" \
"2420706f757220313020476f3c2f4465736372697074696f6e3e3c2f506c616e3ee40003002b" \
"736572766963652d70726f76696465722e636f6d3b66656465726174696f6e2e6578616d706c" \
"652e636f6db400454e475553443c3f786d6c2076657273696f6e3d22312e302220656e636f64" \
"696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77" \
"692d66692e6f72672f73706563696669636174696f6e732f686f7473706f7432646f74302f76" \
"312e302f616f637069223e3c4465736372697074696f6e3e46726565207769746820796f7572" \
"20737562736372697074696f6e213c2f4465736372697074696f6e3e3c2f506c616e3e"
#define SAE_PK_KEY_1 \
"MHcCAQEEIDNNDttjdQmLVyr1DOrWiapbMt15LDn4hnMLIXrBLAN+oAoGCCqGSM49AwEHoUQDQgAENAv4e3IlpYkqQjc/9KM4O4Athh6iY25wlT8Gdg+EhR7yoMR03nHri6QaaLogXxTsa9qGyXj1K9G8DEOyHMQCbg=="
#define SAE_PK_KEY_2 \
"MHcCAQEEIF4LGkE30VdIeJe1ZVOo3TmkvT9RKRx30+yOx/9nhQY9oAoGCCqGSM49AwEHoUQDQgAE3PNzZH4m41vT5q6W7p5Q6B9owz5MHLwCUnpK84YRTVDLKKZXOPYxSHRh/O5Kz0OnVeOq1QfjEZRhNH79XhHCQQ=="
#define SAE_PK_KEY_P256 \
"MHcCAQEEIAJIGlfnteonDb7rQyP/SGQjwzrZAnfrXIm4280VWajYoAoGCCqGSM49AwEHoUQDQgAEeRkstKQV+FSAMqBayqFknn2nAQsdsh/MhdX6tiHOTAFin/sUMFRMyspPtIu7YvlKdsexhI0jPVhaYZn1jKWhZg=="
#define SAE_PK_KEY_P384 \
"MIGkAgEBBDB7iMoR2se0sWriXYCEsiLd8WFEblxWlCqb5kD7JgZfQjjylGwqOgIE7JShOOjE0Z2gBwYFK4EEACKhZANiAATntlmb7rlUopsaA/w5Uhut9jLlcY2sJdT6IzCdQ8uzuxk9Fgh+dwS25pd+lWC91rQ7kyjfZRpoePhwQasnjGRAl6rH2VWI/XtI5Q9iFXbhEaWEdKzWjetd6B5OPWy/BQg="
#define SAE_PK_KEY_P521 \
"MIHcAgEBBEIBuNKSnOQY5ZVdBgWiXcL1Gr/W+VCw69nOte1gT4sqdVeV3grCl5HJxogVG2LFdtnEDLJrs0AtFoFN9nWnIuMu+ZWgBwYFK4EEACOhgYkDgYYABADuDQkFO2102xXwNnoGpBU+13kNuxZ/gwy8+G0UG75h6iiTqNWRaQIpSWgTmPNER7Ubb7etyXaoOTnsq4v4f9m8wgDt2LMZptHvUkHCq522rRK43ITmCayelbHWY1FhhAE1ETXRItSV8nLymjliEtjdfP45dsr25ySlkSaVCBNUFrAtfw=="
/*
* MTU for Ethernet need to take into account 8-byte SNAP header
* to be added when encapsulating Ethernet frame into 802.11.
*/
#ifndef IEEE80211_MAX_DATA_LEN_DMG
#define IEEE80211_MAX_DATA_LEN_DMG 7920
#endif /* IEEE80211_MAX_DATA_LEN_DMG */
#ifndef IEEE80211_SNAP_LEN_DMG
#define IEEE80211_SNAP_LEN_DMG 8
#endif /* IEEE80211_SNAP_LEN_DMG */
extern char *sigma_wpas_ctrl;
extern char *sigma_hapd_ctrl;
extern char *ap_inet_addr;
extern char *ap_inet_mask;
extern char *sigma_radio_ifname[];
static int ath_ap_start_hostapd(struct sigma_dut *dut);
static void ath_ap_set_params(struct sigma_dut *dut);
static int kill_process(struct sigma_dut *dut, char *proc_name,
unsigned char is_proc_instance_one, int sig);
static int fwtest_cmd_wrapper(struct sigma_dut *dut, const char *arg,
const char *ifname)
{
int ret = -1;
if (strcmp(dut->device_driver, "ath11k") == 0)
ret = run_system_wrapper(dut, "ath11k-fwtest -i %s %s",
ifname, arg);
return ret;
}
static int ap_ft_enabled(struct sigma_dut *dut)
{
return dut->ap_ft_oa == 1 ||
dut->ap_ft_ds == VALUE_ENABLED ||
dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
dut->ap_key_mgmt == AP_WPA2_FT_PSK ||
dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP ||
(dut->ap_akm_values &
((1 << AKM_FT_EAP) |
(1 << AKM_FT_PSK) |
(1 << AKM_FT_SAE) |
(1 << AKM_FT_SUITE_B) |
(1 << AKM_FT_FILS_SHA256) |
(1 << AKM_FT_FILS_SHA384)));
}
static enum sigma_cmd_result cmd_ap_ca_version(struct sigma_dut *dut,
struct sigma_conn *conn,
struct sigma_cmd *cmd)
{
/* const char *name = get_param(cmd, "NAME"); */
send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0");
return 0;
}
static void kill_hostapd_process_pid(struct sigma_dut *dut)
{
FILE *f;
int pid, res;
char path[100];
int count;
f = fopen(SIGMA_DUT_HOSTAPD_PID_FILE, "r");
if (!f)
return;
res = fscanf(f, "%d", &pid);
fclose(f);
if (res != 1)
return;
sigma_dut_print(dut, DUT_MSG_INFO, "Killing hostapd pid %d", pid);
kill(pid, SIGTERM);
snprintf(path, sizeof(path), "/proc/%d", pid);
for (count = 0; count < 20 && file_exists(path); count++)
usleep(100000);
}
int get_hwaddr(const char *ifname, unsigned char *hwaddr)
{
#ifndef __QNXNTO__
struct ifreq ifr;
int s;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
return -1;
memset(&ifr, 0, sizeof(ifr));
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
perror("ioctl");
close(s);
return -1;
}
close(s);
memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6);
#else /* __QNXNTO__ */
struct ifaddrs *ifaddrshead = NULL;
int found = 0;
struct ifaddrs *temp_ifap = NULL;
struct sockaddr_dl *sdl = NULL;
if (getifaddrs(&ifaddrshead) != 0) {
perror("getifaddrs failed");
return -1;
}
for (temp_ifap = ifaddrshead; ifaddrshead && !found;
ifaddrshead = ifaddrshead->ifa_next) {
if (ifaddrshead->ifa_addr->sa_family == AF_LINK &&
strcmp(ifaddrshead->ifa_name, ifname) == 0) {
found = 1;
sdl = (struct sockaddr_dl *) ifaddrshead->ifa_addr;
if (sdl)
memcpy(hwaddr, LLADDR(sdl), sdl->sdl_alen);
}
}
if (temp_ifap)
freeifaddrs(temp_ifap);
if (!found) {
perror("Failed to get the interface");
return -1;
}
#endif /* __QNXNTO__ */
return 0;
}
static void ath_ap_set_group_id(struct sigma_dut *dut, const char *ifname,
const char *val)
{
char buf[60];
snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 55 %d",
ifname, atoi(val));
if (system(buf) != 0) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"wifitool ap_group_id failed");
}
}
void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
const char *val)
{
char buf[60];
/* TODO: Enable support for other values */
if (strcasecmp(val, "40") == 0) {
snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 1",
ifname);
if (system(buf) != 0) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"wifitool cts_width failed");
}
snprintf(buf, sizeof(buf),
"athdiag --set --address=0x10024 --val=0xd90b8a14");
if (system(buf) != 0) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"disabling phy restart failed");
}
} else {
sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported CTS_WIDTH");
}
}
void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
const char *val)
{
char buf[60];
if (strcasecmp(val, "enable") == 0) {
dut->ap_dyn_bw_sig = VALUE_ENABLED;
run_iwpriv(dut, ifname, "cwmenable 1");
snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 96 1",
ifname);
if (system(buf) != 0) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"disabling RTS from rate control logic failed");
}
} else if (strcasecmp(val, "disable") == 0) {
dut->ap_dyn_bw_sig = VALUE_DISABLED;
run_iwpriv(dut, ifname, "cwmenable 0");
} else {
sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported DYN_BW_SGL");
}
}
static void wcn_config_ap_ldpc(struct sigma_dut *dut, const char *ifname)
{
if (dut->ap_ldpc == VALUE_NOT_SET)
return;
run_iwpriv(dut, ifname, "ldpc %d", dut->ap_ldpc != VALUE_DISABLED);
}
static int wcn_config_ap_fils_dscv(struct sigma_dut *dut, const char *ifname)
{
#ifdef NL80211_SUPPORT
uint8_t enable_fils_dscv = dut->ap_filsdscv == VALUE_ENABLED;
if (dut->ap_filsdscv == VALUE_NOT_SET)
return 0;
return wcn_wifi_test_config_set_u8(
dut, ifname,
QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FILS_DISCOVERY_FRAMES_TX,
enable_fils_dscv);
#else /* NL80211_SUPPORT */
sigma_dut_print(dut, DUT_MSG_ERROR,
"FILS Discovery frames configuration can't be set without NL80211_SUPPORT defined");
if (dut->ap_filsdscv == VALUE_NOT_SET)
return 0;
return -1;
#endif /* NL80211_SUPPORT */
}
static void mac80211_config_rts_force(struct sigma_dut *dut, const char *ifname,
const char *val)
{
char buf[60];
char fname[128], path[128], *pos;
ssize_t res;
res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
ifname);
if (res < 0 || res >= sizeof(fname))
return;
res = readlink(fname, path, sizeof(path));
if (res < 0)
return;
if (res >= (int) sizeof(path))
res = sizeof(path) - 1;
path[res] = '\0';
pos = strrchr(path, '/');
if (!pos)
pos = path;
else
pos++;
if (strcasecmp(val, "enable") == 0) {
dut->ap_sig_rts = VALUE_ENABLED;
res = snprintf(buf, sizeof(buf), "iw %s set rts 64", pos);
if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"iw set rts 64 failed");
}
} else if (strcasecmp(val, "disable") == 0) {
dut->ap_sig_rts = VALUE_DISABLED;
res = snprintf(buf, sizeof(buf), "iw %s set rts 2347", pos);
if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"iw rts 2347 failed");
}
} else {
sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
}
}
static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
const char *val)
{
char buf[60];
if (strcasecmp(val, "enable") == 0) {
dut->ap_sig_rts = VALUE_ENABLED;
snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
if (system(buf) != 0) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"iwconfig rts 64 failed");
}
snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
ifname);
if (system(buf) != 0) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"wifitool beeliner_fw_test 100 1 failed");
}
} else if (strcasecmp(val, "disable") == 0) {
dut->ap_sig_rts = VALUE_DISABLED;
snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
if (system(buf) != 0) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"iwconfig rts 2347 failed");
}
} else {
sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
}
}
static void ath_radio(struct sigma_dut *dut, const char *val)
{
if (strcasecmp(val, "on") == 0) {
if (dut->ap_interface_5g == 1) {
run_system(dut, "uci set wireless.wifi0.disabled=0");
} else if (dut->ap_interface_2g == 1) {
run_system(dut, "uci set wireless.wifi1.disabled=0");
} else {
run_system(dut, "uci set wireless.wifi0.disabled=0");
run_system(dut, "uci set wireless.wifi1.disabled=0");
}
run_system(dut, "uci commit");
run_system(dut, "wifi down");
run_system(dut, "wifi up");
} else if (strcasecmp(val, "off") == 0) {
if (dut->ap_interface_5g == 1) {
run_system(dut, "uci set wireless.wifi0.disabled=1");
} else if (dut->ap_interface_2g == 1) {
run_system(dut, "uci set wireless.wifi1.disabled=1");
} else {
run_system(dut, "uci set wireless.wifi0.disabled=1");
run_system(dut, "uci set wireless.wifi1.disabled=1");
}
run_system(dut, "uci commit");
run_system(dut, "wifi down");
run_system(dut, "wifi up");
}
}
static void deauth_disassoc(struct sigma_dut *dut, const char *ifname,
const char *val)
{
if (strcasecmp(val, "disable") == 0)
run_iwpriv(dut, ifname, "stealthdown 1");
}
static void ath_set_txpower(struct sigma_dut *dut, const char *ifname,
const char *val)
{
char buf[60];
if (strcasecmp(val, "high") == 0)
snprintf(buf, sizeof(buf), "iwconfig %s txpower 29", ifname);
else if (strcasecmp(val, "low") == 0)
snprintf(buf, sizeof(buf), "iwconfig %s txpower 1", ifname);
else
sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported txpower");
if (system(buf) != 0)
sigma_dut_print(dut, DUT_MSG_ERROR, "setting txpower failed");
}
static enum ap_mode get_mode(const char *str)
{
if (strcasecmp(str, "11a") == 0)
return AP_11a;
else if (strcasecmp(str, "11g") == 0)
return AP_11g;
else if (strcasecmp(str, "11b") == 0)
return AP_11b;
else if (strcasecmp(str, "11na") == 0)
return AP_11na;
else if (strcasecmp(str, "11ng") == 0)
return AP_11ng;
else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
return AP_11ac;
else if (strcasecmp(str, "11ad") == 0)
return AP_11ad;
else if (strcasecmp(str, "11ax") == 0)
return AP_11ax;
else
return AP_inval;
}
static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
{
char command[1000];
const char *bin;
enum driver_type drv = get_driver_type(dut);
char *sigma_hapd_file = sigma_hapd_ctrl;
if (file_exists("hostapd_cli"))
bin = "./hostapd_cli";
else if (file_exists("../../hostapd/hostapd_cli"))
bin = "../../hostapd/hostapd_cli";
else
bin = "hostapd_cli";
if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
sigma_hapd_file = "/var/run/hostapd-wifi0";
if (sigma_radio_ifname[0] &&
strcmp(sigma_radio_ifname[0], "wifi1") == 0)
sigma_hapd_file = "/var/run/hostapd-wifi1";
else if (sigma_radio_ifname[0] &&
strcmp(sigma_radio_ifname[0], "wifi2") == 0)
sigma_hapd_file = "/var/run/hostapd-wifi2";
}
if (sigma_hapd_file)
snprintf(command, sizeof(command), "%s -p %s %s",
bin, sigma_hapd_file, buf);
else
snprintf(command, sizeof(command), "%s %s", bin, buf);
return run_system(dut, command);
}
static int ath_set_lci_config(struct sigma_dut *dut, const char *val,
struct sigma_cmd *cmd)
{
FILE *f;
int i;
f = fopen("/tmp/lci_cfg.txt", "w");
if (!f) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"Failed to open /tmp/lci_cfg.txt");
return -1;
}
for (i = 2; i < cmd->count; i++)
fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]);
fprintf(f, "\n");
fclose(f);
return 0;
}
static void set_ap_country_code(struct sigma_dut *dut)
{
#if defined(ANDROID) || defined(LINUX_EMBEDDED)
char buf[256];
if (dut->ap_countrycode[0]) {
snprintf(buf, sizeof(buf), "DRIVER COUNTRY %s",
dut->ap_countrycode);
if (wpa_command(get_station_ifname(dut), buf) < 0)
sigma_dut_print(dut, DUT_MSG_ERROR,
"Failed to set country code");
else
sigma_dut_print(dut, DUT_MSG_INFO,
"Successfully set country code to %s",
dut->ap_countrycode);
}
#endif
}
static void set_vht_mcsmap_nss(struct sigma_dut *dut, int nss, int mcs)
{
switch (nss) {
case 1:
switch (mcs) {
case 7:
dut->ap_vhtmcs_map = 0xfffc;
break;
case 8:
dut->ap_vhtmcs_map = 0xfffd;
break;
case 9:
dut->ap_vhtmcs_map = 0xfffe;
break;
default:
dut->ap_vhtmcs_map = 0xfffe;
break;
}
break;
case 2:
switch (mcs) {
case 7:
dut->ap_vhtmcs_map = 0xfff0;
break;
case 8:
dut->ap_vhtmcs_map = 0xfff5;
break;
case 9:
dut->ap_vhtmcs_map = 0xfffa;
break;
default:
dut->ap_vhtmcs_map = 0xfffa;
break;
}
break;
case 3:
switch (mcs) {
case 7:
dut->ap_vhtmcs_map = 0xffc0;
break;
case 8:
dut->ap_vhtmcs_map = 0xffd5;
break;
case 9:
dut->ap_vhtmcs_map = 0xffea;
break;
default:
dut->ap_vhtmcs_map = 0xffea;
break;
}
default:
dut->ap_vhtmcs_map = 0xffea;
break;
}
}
/* Get 2*nss bitmask */
/* We are trying to pack 2-bit MCS values per NSS in a 16-bit wide field.
* IEEE P802.11ax/D5.0, 9.4.2.247.4 supported HE-MCS And NSS Set field
* defines the following format for the 16 bit value. */
#define HE_GET_MCS_NSS_PACK_MASK(nss) ((1 << ((nss) << 1)) - 1)
static void he_reset_mcs_values_for_unsupported_ss(uint8_t *mcsnssmap,
uint8_t nss)
{
uint8_t nssmask;
if (nss <= 4) {
nssmask = ~HE_GET_MCS_NSS_PACK_MASK(nss);
mcsnssmap[0] |= nssmask;
mcsnssmap[1] = 0xff;
} else if (nss > 4 && nss <= 8) {
nssmask = ~HE_GET_MCS_NSS_PACK_MASK(nss - 4);
mcsnssmap[0] &= 0xff;
mcsnssmap[1] |= nssmask;
}
}
static void get_he_mcs_nssmap(uint8_t *mcsnssmap, uint8_t nss,
uint8_t mcs)
{
switch (mcs) {
case 11:
mcsnssmap[0] = 0xaa;
mcsnssmap[1] = 0xaa;
break;
case 9:
mcsnssmap[0] = 0x55;
mcsnssmap[1] = 0x55;
break;
case 7:
mcsnssmap[0] = 0x0;
mcsnssmap[1] = 0x0;
break;
}
he_reset_mcs_values_for_unsupported_ss(mcsnssmap, nss);
}
static enum sigma_cmd_result cmd_ap_set_wireless(struct sigma_dut *dut,
struct sigma_conn *conn,
struct sigma_cmd *cmd)
{
/* const char *name = get_param(cmd, "NAME"); */
/* const char *ifname = get_param(cmd, "INTERFACE"); */
const char *val;
unsigned int wlan_tag = 1;
const char *ifname = get_main_ifname(dut);
char buf[128];
/* Allow program to be overridden if specified in the ap_set_wireless
* to support some 60 GHz test scripts where the program may be 60 GHz
* or WPS. */
val = get_param(cmd, "PROGRAM");
if (val)
dut->program = sigma_program_to_enum(val);
val = get_param(cmd, "WLAN_TAG");
if (val) {
wlan_tag = atoi(val);
if (wlan_tag < 1 || wlan_tag > 3) {
/*
* The only valid WLAN Tags as of now as per the latest
* WFA scripts are 1, 2, and 3.
*/
send_resp(dut, conn, SIGMA_INVALID,
"errorCode,Invalid WLAN_TAG");
return STATUS_SENT;
}
}
val = get_param(cmd, "Interface");
if (val) {
if (strcasecmp(val, "5G") == 0)
dut->ap_interface_5g = 1;
else
dut->ap_interface_2g = 1;
if (dut->ap_interface_5g && dut->ap_interface_2g)
dut->ap_is_dual = 1;
}
val = get_param(cmd, "CountryCode");
if (val) {
if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
return INVALID_SEND_STATUS;
snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
"%s", val);
/*
* Regdomain self-managed driver does not accept hostapd country
* code setting in all cases. Try to use wpa_supplicant DRIVER
* command first to set the driver to a specific country code
* before starting AP functionality. This is targeting cases
* where wpa_supplicant is running on the device as well for
* non-AP mode functionality.
*/
if (get_driver_type(dut) == DRIVER_LINUX_WCN)
set_ap_country_code(dut);
}
val = get_param(cmd, "regulatory_mode");
if (val) {
if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
}
val = get_param(cmd, "SSID");
if (val) {
if (strlen(val) > sizeof(dut->ap_ssid) - 1)
return INVALID_SEND_STATUS;
if (wlan_tag == 1) {
/*
* If tag is not specified, it is deemed to be 1.
* Hence tag of 1 is a special case and the values
* corresponding to wlan-tag=1 are stored separately
* from the values corresponding tags 2 and 3.
* This approach minimises the changes to existing code
* since most of the sigma_dut code does not deal with
* WLAN-TAG CAPI variable.
*/
snprintf(dut->ap_ssid,
sizeof(dut->ap_ssid), "%s", val);
} else {
snprintf(dut->ap_tag_ssid[wlan_tag - 2],
sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
"%s", val);
}
}
val = get_param(cmd, "CHANNEL");
if (val) {
const char *pos;
dut->ap_channel = atoi(val);
pos = strchr(val, ';');
if (pos) {
pos++;
dut->ap_channel_1 = atoi(pos);
}
}
val = get_param(cmd, "ChnlFreq");
if (val) {
if (atoi(val) >= 5935 && atoi(val) <= 7115)
dut->ap_band_6g = 1;
else
dut->ap_band_6g = 0;
}
/* Overwrite the AP channel with DFS channel if configured */
val = get_param(cmd, "dfs_chan");
if (val) {
dut->ap_channel = atoi(val);
}
val = get_param(cmd, "dfs_mode");
if (val) {
if (strcasecmp(val, "Enable") == 0)
dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
else if (strcasecmp(val, "Disable") == 0)
dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
else
sigma_dut_print(dut, DUT_MSG_ERROR,
"Unsupported dfs_mode value: %s", val);
}
val = get_param(cmd, "MODE");
if (val) {
char *str, *pos;
str = strdup(val);
if (str == NULL)
return INVALID_SEND_STATUS;
pos = strchr(str, ';');
if (pos)
*pos++ = '\0';
dut->ap_is_dual = 0;
dut->ap_mode = get_mode(str);
if (dut->ap_mode == AP_inval) {
send_resp(dut, conn, SIGMA_INVALID,
"errorCode,Unsupported MODE");
free(str);
return STATUS_SENT;
}
if (dut->ap_mode == AP_11ac && dut->ap_80plus80 != 1)
dut->ap_chwidth = AP_80;
if (pos) {
dut->ap_mode_1 = get_mode(pos);
if (dut->ap_mode_1 == AP_inval) {
send_resp(dut, conn, SIGMA_INVALID,
"errorCode,Unsupported MODE");
free(str);
return STATUS_SENT;
}
if (dut->ap_mode_1 == AP_11ac)
dut->ap_chwidth_1 = AP_80;
dut->ap_is_dual = 1;
}
free(str);
} else if (dut->ap_mode == AP_inval) {
if (dut->ap_channel <= 11)
dut->ap_mode = AP_11ng;
else if (dut->program == PROGRAM_VHT)
dut->ap_mode = AP_11ac;
else
dut->ap_mode = AP_11na;
}
/* Override the AP mode in case of 60 GHz */
if (dut->program == PROGRAM_60GHZ) {
dut->ap_mode = AP_11ad;
/* Workaround to force channel 2 if not specified */
if (!dut->ap_channel)
dut->ap_channel = 2;
}
switch (dut->ap_mode) {
case AP_11g:
case AP_11b:
case AP_11ng:
dut->use_5g = 0;
break;
case AP_11a:
case AP_11na:
case AP_11ac:
dut->use_5g = 1;
break;
case AP_11ax:
if (dut->ap_band_6g)
dut->use_5g = 1;
else if (dut->ap_channel >= 1 && dut->ap_channel <= 14)
dut->use_5g = 0;
else if (dut->ap_channel >= 36 && dut->ap_channel <= 171)
dut->use_5g = 1;
break;
case AP_11ad:
case AP_inval:
break;
}
val = get_param(cmd, "WME");
if (val) {
if (strcasecmp(val, "on") == 0)
dut->ap_wme = AP_WME_ON;
else if (strcasecmp(val, "off") == 0)
dut->ap_wme = AP_WME_OFF;
else
sigma_dut_print(dut, DUT_MSG_ERROR,
"Unsupported WME value: %s", val);
}
val = get_param(cmd, "WMMPS");
if (val) {
if (strcasecmp(val, "on") == 0)
dut->ap_wmmps = AP_WMMPS_ON;
else if (strcasecmp(val, "off") == 0)
dut->ap_wmmps = AP_WMMPS_OFF;
else
sigma_dut_print(dut, DUT_MSG_ERROR,
"Unsupported WMMPS value: %s", val);
}
val = get_param(cmd, "RTS");
if (val)
dut->ap_rts = atoi(val);
val = get_param(cmd, "FRGMNT");
if (val)
dut->ap_frgmnt = atoi(val);
/* TODO: PWRSAVE */
val = get_param(cmd, "BCNINT");
if (val)
dut->ap_bcnint = atoi(val);
val = get_param(cmd, "RADIO");
if (val) {
enum driver_type drv = get_driver_type(dut);
if (strcasecmp(val, "on") == 0) {
if (drv == DRIVER_OPENWRT)
ath_radio(dut, val);
if (drv == DRIVER_ATHEROS)
ath_ap_start_hostapd(dut);
else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
return STATUS_SENT;
} else if (strcasecmp(val, "off") == 0) {
if (drv == DRIVER_OPENWRT) {
ath_radio(dut, val);
} else if (dut->use_hostapd_pid_file) {
kill_hostapd_process_pid(dut);
} else if (kill_process(dut, "(hostapd)", 1,
SIGTERM) == 0 ||
system("killall hostapd") == 0) {
sigma_dut_print(dut, DUT_MSG_INFO,
"Killed hostapd on radio,off");
}
} else {
send_resp(dut, conn, SIGMA_INVALID,
"errorCode,Unsupported RADIO value");
return STATUS_SENT;
}
}
val = get_param(cmd, "P2PMgmtBit");
if (val)
dut->ap_p2p_mgmt = atoi(val);
/* TODO: ChannelUsage */
/* TODO: 40_INTOLERANT */
val = get_param(cmd, "ADDBA_REJECT");
if (val) {
if (strcasecmp(val, "Enable") == 0)
dut->ap_addba_reject = VALUE_ENABLED;
else if (strcasecmp(val, "Disable") == 0)
dut->ap_addba_reject = VALUE_DISABLED;
}
val = get_param(cmd, "AMPDU");
if (val) {
if (strcasecmp(val, "Enable") == 0)
dut->ap_ampdu = VALUE_ENABLED;
else if (strcasecmp(val, "Disable") == 0)
dut->ap_ampdu = VALUE_DISABLED;
}
val = get_param(cmd, "AMPDU_EXP");
if (val)
dut->ap_ampdu_exp = atoi(val);
val = get_param(cmd, "AMSDU");
if (val) {
if (strcasecmp(val, "Enable") == 0)
dut->ap_amsdu = VALUE_ENABLED;
else if (strcasecmp(val, "Disable") == 0)
dut->ap_amsdu = VALUE_DISABLED;
}
val = get_param(cmd, "NoAck");
if (val) {
if (strcasecmp(val, "on") == 0)
dut->ap_noack = VALUE_ENABLED;
else if (strcasecmp(val, "off") == 0)
dut->ap_noack = VALUE_DISABLED;
}
/* TODO: GREENFIELD */
/* TODO: MCS_32 */
val = get_param(cmd, "OFFSET");
if (val) {
if (strcasecmp(val, "Above") == 0)
dut->ap_chwidth_offset = SEC_CH_40ABOVE;
else if (strcasecmp(val, "Below") == 0)
dut->ap_chwidth_offset = SEC_CH_40BELOW;
}
val = get_param(cmd, "MCS_FIXEDRATE");
if (val) {
dut->ap_fixed_rate = 1;
dut->ap_mcs = atoi(val);
}
val = get_param(cmd, "SPATIAL_RX_STREAM");
if (val) {
if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
dut->ap_rx_streams = 1;