-
Notifications
You must be signed in to change notification settings - Fork 26
/
nan.c
3807 lines (3308 loc) · 114 KB
/
nan.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 (NAN functionality)
* Copyright (c) 2014-2017, Qualcomm Atheros, Inc.
* Copyright (c) 2018, The Linux Foundation
* Copyright (c) 2023, Qualcomm Innovation Center, Inc.
* All Rights Reserved.
* Licensed under the Clear BSD license. See README for more details.
*/
#include "sigma_dut.h"
#include <sys/stat.h>
#include "wpa_ctrl.h"
#include "wpa_helpers.h"
#include "nan_cert.h"
#if NAN_CERT_VERSION >= 2
#if ((NAN_MAJOR_VERSION > 2) || \
(NAN_MAJOR_VERSION == 2 && \
(NAN_MINOR_VERSION >= 1 || NAN_MICRO_VERSION >= 1))) && \
NAN_CERT_VERSION >= 5
#define NAN_NEW_CERT_VERSION
#endif
#if (NAN_MAJOR_VERSION >= 4 && NAN_CERT_VERSION >= 6)
#define WFA_CERT_NANR4
#endif
pthread_cond_t gCondition;
pthread_mutex_t gMutex;
static NanSyncStats global_nan_sync_stats;
static int nan_state = 0;
static int event_anyresponse = 0;
static int is_fam = 0;
static uint16_t global_ndp_instance_id = 0;
static uint16_t global_publish_id = 0;
static uint16_t global_subscribe_id = 0;
uint16_t global_header_handle = 0;
uint32_t global_match_handle = 0;
#define DEFAULT_SVC "QNanCluster"
#define MAC_ADDR_ARRAY(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MAC_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
#ifndef ETH_ALEN
#define ETH_ALEN 6
#endif
static const u8 nan_wfa_oui[] = { 0x50, 0x6f, 0x9a };
/* TLV header length = tag (1 byte) + length (2 bytes) */
#define WLAN_NAN_TLV_HEADER_SIZE (1 + 2)
#define NAN_INTF_ID_LEN 8
struct sigma_dut *global_dut = NULL;
static u8 global_nan_mac_addr[ETH_ALEN];
static u8 global_peer_mac_addr[ETH_ALEN];
static char global_event_resp_buf[1024];
static u8 global_publish_service_name[NAN_MAX_SERVICE_NAME_LEN];
static u32 global_publish_service_name_len = 0;
static u8 global_subscribe_service_name[NAN_MAX_SERVICE_NAME_LEN];
static u32 global_subscribe_service_name_len = 0;
#ifdef WFA_CERT_NANR4
static NanPairingConfig global_peer_pairing_cfg;
#endif /* WFA_CERT_NANR4 */
static int nan_further_availability_tx(struct sigma_dut *dut,
struct sigma_conn *conn,
struct sigma_cmd *cmd);
static int nan_further_availability_rx(struct sigma_dut *dut,
struct sigma_conn *conn,
struct sigma_cmd *cmd);
enum wlan_nan_tlv_type {
NAN_TLV_TYPE_IPV6_LINK_LOCAL = 0x00,
NAN_TLV_TYPE_SERVICE_INFO = 0x01,
NAN_TLV_TYPE_RSVD_START = 0x02,
NAN_TLV_TYPE_RSVD_START_END = 0xFF
};
enum wlan_nan_service_protocol_type {
NAN_TLV_SERVICE_PROTO_TYPE_RSVD1 = 0x00,
NAN_TLV_SERVICE_PROTO_TYPE_BONJOUR = 0x01,
NAN_TLV_SERVICE_PROTO_TYPE_GENERIC = 0x02,
NAN_TLV_SERVICE_PROTO_RSVD2_START = 0x03,
NAN_TLV_SERVICE_PROTO_TYPE_RSVD2_END = 0xFF
};
enum wlan_nan_generic_service_proto_sub_attr {
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_TRANS_PORT = 0x00,
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_TRANS_PROTO = 0x01,
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_SERVICE_NAME = 0x02,
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_TEXTINFO = 0x04,
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_UUID = 0x05,
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_BLOB = 0x06,
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_RSVD1_START = 0x07,
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_RSVD1_END = 0xDC,
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_VENDOR_SPEC_INFO= 0xDD,
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_RSVD2_START = 0xDE,
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_RSVD2_END = 0xFF
};
void nan_hex_dump(struct sigma_dut *dut, uint8_t *data, size_t len)
{
char buf[512];
uint16_t index;
uint8_t *ptr;
int pos;
memset(buf, 0, sizeof(buf));
ptr = data;
pos = 0;
for (index = 0; index < len; index++) {
pos += snprintf(&(buf[pos]), sizeof(buf) - pos,
"%02x ", *ptr++);
if (pos > 508)
break;
}
sigma_dut_print(dut, DUT_MSG_INFO, "HEXDUMP len=[%d]", (int) len);
sigma_dut_print(dut, DUT_MSG_INFO, "buf:%s", buf);
}
int nan_parse_hex(unsigned char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return 0;
}
int nan_parse_token(const char *tokenIn, u8 *tokenOut, int *filterLen)
{
int total_len = 0, len = 0;
char *saveptr = NULL;
tokenIn = strtok_r((char *) tokenIn, ":", &saveptr);
while (tokenIn != NULL) {
len = strlen(tokenIn);
if (len == 1 && *tokenIn == '*')
len = 0;
tokenOut[total_len++] = (u8) len;
if (len != 0)
memcpy((u8 *) tokenOut + total_len, tokenIn, len);
total_len += len;
tokenIn = strtok_r(NULL, ":", &saveptr);
}
*filterLen = total_len;
return 0;
}
int nan_parse_mac_address(struct sigma_dut *dut, const char *arg, u8 *addr)
{
if (strlen(arg) != 17) {
sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid mac address %s",
arg);
sigma_dut_print(dut, DUT_MSG_ERROR,
"expected format xx:xx:xx:xx:xx:xx");
return -1;
}
addr[0] = nan_parse_hex(arg[0]) << 4 | nan_parse_hex(arg[1]);
addr[1] = nan_parse_hex(arg[3]) << 4 | nan_parse_hex(arg[4]);
addr[2] = nan_parse_hex(arg[6]) << 4 | nan_parse_hex(arg[7]);
addr[3] = nan_parse_hex(arg[9]) << 4 | nan_parse_hex(arg[10]);
addr[4] = nan_parse_hex(arg[12]) << 4 | nan_parse_hex(arg[13]);
addr[5] = nan_parse_hex(arg[15]) << 4 | nan_parse_hex(arg[16]);
return 0;
}
int nan_parse_mac_address_list(struct sigma_dut *dut, const char *input,
u8 *output, u16 max_addr_allowed)
{
/*
* Reads a list of mac address separated by space. Each MAC address
* should have the format of aa:bb:cc:dd:ee:ff.
*/
char *saveptr;
char *token;
int i = 0;
for (i = 0; i < max_addr_allowed; i++) {
token = strtok_r((i == 0) ? (char *) input : NULL,
" ", &saveptr);
if (token) {
nan_parse_mac_address(dut, token, output);
output += NAN_MAC_ADDR_LEN;
} else
break;
}
sigma_dut_print(dut, DUT_MSG_INFO, "Num MacAddress:%d", i);
return i;
}
int nan_parse_hex_string(struct sigma_dut *dut, const char *input,
u8 *output, int *outputlen)
{
int i = 0;
int j = 0;
for (i = 0; i < (int) strlen(input) && j < *outputlen; i += 2) {
output[j] = nan_parse_hex(input[i]);
if (i + 1 < (int) strlen(input)) {
output[j] = ((output[j] << 4) |
nan_parse_hex(input[i + 1]));
}
j++;
}
*outputlen = j;
sigma_dut_print(dut, DUT_MSG_INFO, "Input:%s inputlen:%d outputlen:%d",
input, (int) strlen(input), (int) *outputlen);
return 0;
}
static size_t nan_build_ipv6_link_local_tlv(u8 *p_frame,
const u8 *p_ipv6_intf_addr)
{
/* fill attribute ID */
*p_frame++ = NAN_TLV_TYPE_IPV6_LINK_LOCAL;
/* Fill the length */
*p_frame++ = NAN_INTF_ID_LEN & 0xFF;
*p_frame++ = NAN_INTF_ID_LEN >> 8;
/* only the lower 8 bytes is needed */
memcpy(p_frame, &p_ipv6_intf_addr[NAN_INTF_ID_LEN], NAN_INTF_ID_LEN);
return NAN_INTF_ID_LEN + WLAN_NAN_TLV_HEADER_SIZE;
}
static size_t nan_build_service_info_tlv_sub_attr(
u8 *p_frame, const u8 *sub_attr, const u16 sub_attr_len,
enum wlan_nan_generic_service_proto_sub_attr sub_attr_id)
{
/* Fill Service Subattibute ID */
*p_frame++ = (u8) sub_attr_id;
/* Fill the length */
*p_frame++ = sub_attr_len & 0xFF;
*p_frame++ = sub_attr_len >> 8;
/* Fill the value */
memcpy(p_frame, sub_attr, sub_attr_len);
return sub_attr_len + WLAN_NAN_TLV_HEADER_SIZE;
}
static size_t nan_build_service_info_tlv(u8 *p_frame,
const NdpIpTransParams *p_ndp_attr)
{
u16 tlv_len = 0, len = 0;
u8 *p_offset_len;
if (p_ndp_attr->trans_port_present || p_ndp_attr->trans_proto_present) {
/* fill attribute ID */
*p_frame++ = NAN_TLV_TYPE_SERVICE_INFO;
p_offset_len = p_frame;
p_frame += 2;
/* Fill WFA Specific OUI */
memcpy(p_frame, nan_wfa_oui, sizeof(nan_wfa_oui));
p_frame += sizeof(nan_wfa_oui);
tlv_len += sizeof(nan_wfa_oui);
/* Fill Service protocol Type */
*p_frame++ = NAN_TLV_SERVICE_PROTO_TYPE_GENERIC;
tlv_len += 1;
if (p_ndp_attr->trans_port_present) {
len = nan_build_service_info_tlv_sub_attr(
p_frame,
(const u8 *) &p_ndp_attr->transport_port,
sizeof(p_ndp_attr->transport_port),
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_TRANS_PORT);
p_frame += len;
tlv_len += len;
}
if (p_ndp_attr->trans_proto_present) {
len = nan_build_service_info_tlv_sub_attr(
p_frame,
(const u8 *) &p_ndp_attr->transport_protocol,
sizeof(p_ndp_attr->transport_protocol),
NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_TRANS_PROTO);
p_frame += len;
tlv_len += len;
}
/* Fill the length */
*p_offset_len++ = tlv_len & 0xFF;
*p_offset_len = tlv_len >> 8;
tlv_len += WLAN_NAN_TLV_HEADER_SIZE;
}
return tlv_len;
}
int wait(struct timespec abstime)
{
struct timeval now;
gettimeofday(&now, NULL);
abstime.tv_sec += now.tv_sec;
if (((abstime.tv_nsec + now.tv_usec * 1000) > 1000 * 1000 * 1000) ||
(abstime.tv_nsec + now.tv_usec * 1000 < 0)) {
abstime.tv_sec += 1;
abstime.tv_nsec += now.tv_usec * 1000;
abstime.tv_nsec -= 1000 * 1000 * 1000;
} else {
abstime.tv_nsec += now.tv_usec * 1000;
}
return pthread_cond_timedwait(&gCondition, &gMutex, &abstime);
}
int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
struct sigma_conn *conn,
struct sigma_cmd *cmd)
{
const char *oper_chan = get_param(cmd, "oper_chn");
const char *pmk = get_param(cmd, "PMK");
#ifdef NAN_NEW_CERT_VERSION
const char *ndpe = get_param(cmd, "NDPE");
const char *trans_proto = get_param(cmd, "TransProtoType");
const char *ndp_attr = get_param(cmd, "ndpAttr");
#endif
if (oper_chan) {
sigma_dut_print(dut, DUT_MSG_INFO, "Operating Channel: %s",
oper_chan);
dut->sta_channel = atoi(oper_chan);
}
if (pmk) {
int pmk_len;
sigma_dut_print(dut, DUT_MSG_INFO, "%s given string pmk: %s",
__func__, pmk);
memset(dut->nan_pmk, 0, NAN_PMK_INFO_LEN);
dut->nan_pmk_len = 0;
pmk_len = NAN_PMK_INFO_LEN;
nan_parse_hex_string(dut, &pmk[2], &dut->nan_pmk[0], &pmk_len);
dut->nan_pmk_len = pmk_len;
sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
__func__, dut->nan_pmk_len);
sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex pmk", __func__);
nan_hex_dump(dut, &dut->nan_pmk[0], dut->nan_pmk_len);
}
#ifdef NAN_NEW_CERT_VERSION
if (ndpe) {
NanConfigRequest req;
wifi_error ret;
sigma_dut_print(dut, DUT_MSG_DEBUG, "%s: NDPE: %s",
__func__, ndpe);
memset(&req, 0, sizeof(NanConfigRequest));
dut->ndpe = strcasecmp(ndpe, "Enable") == 0;
req.config_ndpe_attr = 1;
req.use_ndpe_attr = dut->ndpe;
ret = nan_config_request(0, dut->wifi_hal_iface_handle, &req);
if (ret != WIFI_SUCCESS) {
send_resp(dut, conn, SIGMA_ERROR,
"NAN config request failed");
return 0;
}
}
if (trans_proto) {
sigma_dut_print(dut, DUT_MSG_INFO, "%s: Transport protocol: %s",
__func__, trans_proto);
if (strcasecmp(trans_proto, "TCP") == 0) {
dut->trans_proto = TRANSPORT_PROTO_TYPE_TCP;
} else if (strcasecmp(trans_proto, "UDP") == 0) {
dut->trans_proto = TRANSPORT_PROTO_TYPE_UDP;
} else {
sigma_dut_print(dut, DUT_MSG_ERROR,
"%s: Invalid protocol %s, set to TCP",
__func__, trans_proto);
dut->trans_proto = TRANSPORT_PROTO_TYPE_TCP;
}
}
if (dut->ndpe && ndp_attr) {
NanDebugParams cfg_debug;
int ndp_attr_val;
int ret, size;
sigma_dut_print(dut, DUT_MSG_DEBUG, "%s: NDP Attr: %s",
__func__, ndp_attr);
memset(&cfg_debug, 0, sizeof(NanDebugParams));
cfg_debug.cmd = NAN_TEST_MODE_CMD_ENABLE_NDP;
if (strcasecmp(ndp_attr, "Absent") == 0)
ndp_attr_val = NAN_NDP_ATTR_ABSENT;
else
ndp_attr_val = NAN_NDP_ATTR_PRESENT;
memcpy(cfg_debug.debug_cmd_data, &ndp_attr_val, sizeof(int));
size = sizeof(u32) + sizeof(int);
ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle,
cfg_debug, size);
if (ret != WIFI_SUCCESS) {
send_resp(dut, conn, SIGMA_ERROR,
"NAN config ndpAttr failed");
return 0;
}
}
#endif
send_resp(dut, conn, SIGMA_COMPLETE, NULL);
return 0;
}
void nan_print_further_availability_chan(struct sigma_dut *dut,
u8 num_chans,
NanFurtherAvailabilityChannel *fachan)
{
int idx;
sigma_dut_print(dut, DUT_MSG_INFO,
"********Printing FurtherAvailabilityChan Info******");
sigma_dut_print(dut, DUT_MSG_INFO, "Numchans:%d", num_chans);
for (idx = 0; idx < num_chans; idx++) {
sigma_dut_print(dut, DUT_MSG_INFO,
"[%d]: NanAvailDuration:%d class_val:%02x channel:%d",
idx, fachan->entry_control,
fachan->class_val, fachan->channel);
sigma_dut_print(dut, DUT_MSG_INFO,
"[%d]: mapid:%d Availability bitmap:%08x",
idx, fachan->mapid,
fachan->avail_interval_bitmap);
}
sigma_dut_print(dut, DUT_MSG_INFO,
"*********************Done**********************");
}
int sigma_nan_enable(struct sigma_dut *dut, struct sigma_conn *conn,
struct sigma_cmd *cmd)
{
const char *master_pref = get_param(cmd, "MasterPref");
const char *rand_fac = get_param(cmd, "RandFactor");
const char *hop_count = get_param(cmd, "HopCount");
const char *sdftx_band = get_param(cmd, "SDFTxBand");
const char *oper_chan = get_param(cmd, "oper_chn");
const char *further_avail_ind = get_param(cmd, "FurtherAvailInd");
const char *band = get_param(cmd, "Band");
const char *only_5g = get_param(cmd, "5GOnly");
const char *nan_availability = get_param(cmd, "NANAvailability");
#ifdef NAN_NEW_CERT_VERSION
const char *ndpe = get_param(cmd, "NDPE");
#endif
#ifdef WFA_CERT_NANR4
const char *unsync_srvdsc = get_param(cmd, "UnsyncServDisc");
const char *country_code = get_param(cmd, "CountryCode");
#endif /* WFA_CERT_NANR4 */
struct timespec abstime;
NanEnableRequest req;
memset(&req, 0, sizeof(NanEnableRequest));
req.cluster_low = 0;
req.cluster_high = 0xFFFF;
req.master_pref = 100;
/* This is a debug hack to beacon in channel 11 */
if (oper_chan) {
req.config_2dot4g_support = 1;
req.support_2dot4g_val = 111;
}
if (master_pref) {
int master_pref_val = strtoul(master_pref, NULL, 0);
req.master_pref = master_pref_val;
}
if (rand_fac) {
int rand_fac_val = strtoul(rand_fac, NULL, 0);
req.config_random_factor_force = 1;
req.random_factor_force_val = rand_fac_val;
}
if (hop_count) {
int hop_count_val = strtoul(hop_count, NULL, 0);
req.config_hop_count_force = 1;
req.hop_count_force_val = hop_count_val;
}
#ifdef WFA_CERT_NANR4
if (unsync_srvdsc) {
req.config_unsync_srvdsc = 1;
if (strcasecmp(unsync_srvdsc, "Enable") == 0)
req.enable_unsync_srvdsc = 1;
else
req.enable_unsync_srvdsc = 0;
}
if (country_code) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"%s - set country %s",
__func__, country_code);
wifi_set_country_code(dut->wifi_hal_iface_handle, country_code);
/*
* Intended sleep to trigger NAN enable after setting the
* country code.
*/
usleep(200000);
}
#endif /* WFA_CERT_NANR4 */
if (sdftx_band) {
if (strcasecmp(sdftx_band, "5G") == 0) {
req.config_2dot4g_support = 1;
req.support_2dot4g_val = 0;
}
}
#ifdef NAN_NEW_CERT_VERSION
if (ndpe) {
if (strcasecmp(ndpe, "Enable") == 0) {
dut->ndpe = 1;
req.config_ndpe_attr = 1;
req.use_ndpe_attr = 1;
} else {
dut->ndpe = 0;
req.config_ndpe_attr = 1;
req.use_ndpe_attr = 0;
}
req.config_disc_mac_addr_randomization = 1;
req.disc_mac_addr_rand_interval_sec = 0;
}
#endif
sigma_dut_print(dut, DUT_MSG_INFO,
"%s: Setting dual band 2.4 GHz and 5 GHz by default",
__func__);
/* Enable 2.4 GHz support */
req.config_2dot4g_support = 1;
req.support_2dot4g_val = 1;
req.config_2dot4g_beacons = 1;
req.beacon_2dot4g_val = 1;
req.config_2dot4g_sdf = 1;
req.sdf_2dot4g_val = 1;
/* Enable 5 GHz support */
req.config_support_5g = 1;
req.support_5g_val = 1;
req.config_5g_beacons = 1;
req.beacon_5g_val = 1;
req.config_5g_sdf = 1;
req.sdf_5g_val = 1;
if (band) {
if (strcasecmp(band, "24G") == 0) {
sigma_dut_print(dut, DUT_MSG_INFO,
"Band 2.4 GHz selected, disable 5 GHz");
/* Disable 5G support */
req.config_support_5g = 1;
req.support_5g_val = 0;
req.config_5g_beacons = 1;
req.beacon_5g_val = 0;
req.config_5g_sdf = 1;
req.sdf_5g_val = 0;
}
}
if (further_avail_ind) {
sigma_dut_print(dut, DUT_MSG_INFO, "FAM Test Enabled");
if (strcasecmp(further_avail_ind, "tx") == 0) {
is_fam = 1;
nan_further_availability_tx(dut, conn, cmd);
return 0;
} else if (strcasecmp(further_avail_ind, "rx") == 0) {
nan_further_availability_rx(dut, conn, cmd);
return 0;
}
}
if (only_5g && atoi(only_5g)) {
sigma_dut_print(dut, DUT_MSG_INFO, "5GHz only enabled");
req.config_2dot4g_support = 1;
req.support_2dot4g_val = 1;
req.config_2dot4g_beacons = 1;
req.beacon_2dot4g_val = 0;
req.config_2dot4g_sdf = 1;
req.sdf_2dot4g_val = 1;
}
if (if_nametoindex(NAN_AWARE_IFACE))
run_system_wrapper(dut, "ifconfig %s up", NAN_AWARE_IFACE);
nan_enable_request(0, dut->wifi_hal_iface_handle, &req);
if (nan_availability) {
int cmd_len, size;
NanDebugParams cfg_debug;
sigma_dut_print(dut, DUT_MSG_INFO,
"%s given string nan_availability: %s",
__func__, nan_availability);
memset(&cfg_debug, 0, sizeof(NanDebugParams));
cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_AVAILABILITY;
size = NAN_MAX_DEBUG_MESSAGE_DATA_LEN;
nan_parse_hex_string(dut, &nan_availability[2],
&cfg_debug.debug_cmd_data[0], &size);
sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex nan_availability",
__func__);
nan_hex_dump(dut, &cfg_debug.debug_cmd_data[0], size);
cmd_len = size + sizeof(u32);
nan_debug_command_config(0, dut->wifi_hal_iface_handle,
cfg_debug, cmd_len);
}
/* To ensure sta_get_events to get the events
* only after joining the NAN cluster. */
abstime.tv_sec = 30;
abstime.tv_nsec = 0;
wait(abstime);
return 0;
}
int sigma_nan_disable(struct sigma_dut *dut, struct sigma_conn *conn,
struct sigma_cmd *cmd)
{
struct timespec abstime;
nan_disable_request(0, dut->wifi_hal_iface_handle);
abstime.tv_sec = 4;
abstime.tv_nsec = 0;
wait(abstime);
return 0;
}
int sigma_nan_config_enable(struct sigma_dut *dut, struct sigma_conn *conn,
struct sigma_cmd *cmd)
{
const char *master_pref = get_param(cmd, "MasterPref");
const char *rand_fac = get_param(cmd, "RandFactor");
const char *hop_count = get_param(cmd, "HopCount");
wifi_error ret;
struct timespec abstime;
NanConfigRequest req;
memset(&req, 0, sizeof(NanConfigRequest));
req.config_rssi_proximity = 1;
req.rssi_proximity = 70;
if (master_pref) {
int master_pref_val = strtoul(master_pref, NULL, 0);
req.config_master_pref = 1;
req.master_pref = master_pref_val;
}
if (rand_fac) {
int rand_fac_val = strtoul(rand_fac, NULL, 0);
req.config_random_factor_force = 1;
req.random_factor_force_val = rand_fac_val;
}
if (hop_count) {
int hop_count_val = strtoul(hop_count, NULL, 0);
req.config_hop_count_force = 1;
req.hop_count_force_val = hop_count_val;
}
ret = nan_config_request(0, dut->wifi_hal_iface_handle, &req);
if (ret != WIFI_SUCCESS)
send_resp(dut, conn, SIGMA_ERROR, "NAN config request failed");
abstime.tv_sec = 4;
abstime.tv_nsec = 0;
wait(abstime);
return 0;
}
static int sigma_nan_subscribe_request(struct sigma_dut *dut,
struct sigma_conn *conn,
struct sigma_cmd *cmd)
{
const char *subscribe_type = get_param(cmd, "SubscribeType");
const char *service_name = get_param(cmd, "ServiceName");
const char *disc_range = get_param(cmd, "DiscoveryRange");
const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
const char *tx_match_filter = get_param(cmd, "txMatchFilter");
const char *sdftx_dw = get_param(cmd, "SDFTxDW");
const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
const char *include_bit = get_param(cmd, "IncludeBit");
const char *mac = get_param(cmd, "MAC");
const char *srf_type = get_param(cmd, "SRFType");
#if NAN_CERT_VERSION >= 3
const char *awake_dw_interval = get_param(cmd, "awakeDWint");
#endif
#ifdef WFA_CERT_NANR4
const char *npk_nik_cache = get_param(cmd, "NPKNIKCache");
const char *pairing_setup = get_param(cmd, "PairingSetupEnabled");
const char *bootstrap_method =
get_param(cmd, "Pairing_bootstrapmethod");
const char *cipher_suite = get_param(cmd, "CipherSuiteIdList");
const char *gtk_protection = get_param(cmd, "GTKProtection");
const char *cipher_capabilities = get_param(cmd, "CipherCapabilities");
#endif /* WFA_CERT_NANR4 */
NanSubscribeRequest req;
NanConfigRequest config_req;
int filter_len_rx = 0, filter_len_tx = 0;
u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
wifi_error ret;
memset(&req, 0, sizeof(NanSubscribeRequest));
memset(&config_req, 0, sizeof(NanConfigRequest));
req.ttl = 0;
req.period = 1;
req.subscribe_type = 1;
req.serviceResponseFilter = 1; /* MAC */
req.serviceResponseInclude = 0;
req.ssiRequiredForMatchIndication = 0;
req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
req.subscribe_count = 0;
if (global_subscribe_service_name_len &&
service_name &&
strcasecmp((char *) global_subscribe_service_name,
service_name) == 0 &&
global_subscribe_id) {
req.subscribe_id = global_subscribe_id;
sigma_dut_print(dut, DUT_MSG_INFO,
"%s: updating subscribe_id = %d in subscribe request",
__func__, req.subscribe_id);
}
if (subscribe_type) {
if (strcasecmp(subscribe_type, "Active") == 0) {
req.subscribe_type = 1;
} else if (strcasecmp(subscribe_type, "Passive") == 0) {
req.subscribe_type = 0;
} else if (strcasecmp(subscribe_type, "Cancel") == 0) {
NanSubscribeCancelRequest req;
memset(&req, 0, sizeof(NanSubscribeCancelRequest));
ret = nan_subscribe_cancel_request(
0, dut->wifi_hal_iface_handle, &req);
if (ret != WIFI_SUCCESS) {
send_resp(dut, conn, SIGMA_ERROR,
"NAN subscribe cancel request failed");
}
return 0;
}
}
if (disc_range)
req.rssi_threshold_flag = atoi(disc_range);
if (sdftx_dw)
req.subscribe_count = atoi(sdftx_dw);
/* Check this once again if config can be called here (TBD) */
if (discrange_ltd)
req.rssi_threshold_flag = atoi(discrange_ltd);
#ifdef WFA_CERT_NANR4
if (cipher_suite) {
if (!strchr(cipher_suite, ':')) {
req.cipher_type = atoi(cipher_suite);
} else {
char *saveptr = NULL;
char *ptr = strtok_r((char *) cipher_suite, ":",
&saveptr);
while (ptr) {
req.cipher_type |= BIT(atoi(ptr) - 1);
ptr = strtok_r(NULL, ":", &saveptr);
}
}
}
sigma_dut_print(dut, DUT_MSG_INFO, "cipher type %d", req.cipher_type);
#endif /* WFA_CERT_NANR4 */
if (include_bit) {
int include_bit_val = atoi(include_bit);
req.serviceResponseInclude = include_bit_val;
sigma_dut_print(dut, DUT_MSG_INFO, "Includebit set %d",
req.serviceResponseInclude);
}
if (srf_type) {
int srf_type_val = atoi(srf_type);
if (srf_type_val == 1)
req.serviceResponseFilter = 0; /* Bloom */
else
req.serviceResponseFilter = 1; /* MAC */
req.useServiceResponseFilter = 1;
sigma_dut_print(dut, DUT_MSG_INFO, "srfFilter %d",
req.serviceResponseFilter);
}
if (mac) {
sigma_dut_print(dut, DUT_MSG_INFO, "MAC_ADDR List %s", mac);
req.num_intf_addr_present = nan_parse_mac_address_list(
dut, mac, &req.intf_addr[0][0],
NAN_MAX_SUBSCRIBE_MAX_ADDRESS);
}
memset(input_rx, 0, sizeof(input_rx));
memset(input_tx, 0, sizeof(input_tx));
if (rx_match_filter) {
nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
filter_len_rx);
}
if (tx_match_filter) {
nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
filter_len_tx);
}
if (tx_match_filter) {
req.tx_match_filter_len = filter_len_tx;
memcpy(req.tx_match_filter, input_tx, filter_len_tx);
nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
}
if (rx_match_filter) {
req.rx_match_filter_len = filter_len_rx;
memcpy(req.rx_match_filter, input_rx, filter_len_rx);
nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
}
if (service_name) {
strlcpy((char *) req.service_name, service_name,
strlen(service_name) + 1);
req.service_name_len = strlen(service_name);
strlcpy((char *) global_subscribe_service_name, service_name,
sizeof(global_subscribe_service_name));
global_subscribe_service_name_len =
strlen((char *) global_subscribe_service_name);
}
#if NAN_CERT_VERSION >= 3
if (awake_dw_interval) {
int input_dw_interval_val = atoi(awake_dw_interval);
int awake_dw_int = 0;
if (input_dw_interval_val > NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL) {
sigma_dut_print(dut, DUT_MSG_INFO,
"%s: input active dw interval = %d overwritting dw interval to Max allowed dw interval 16",
__func__, input_dw_interval_val);
input_dw_interval_val =
NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL;
}
sigma_dut_print(dut, DUT_MSG_INFO,
"%s: input active DW interval = %d",
__func__, input_dw_interval_val);
/*
* Indicates the interval for Sync beacons and SDF's in 2.4 GHz
* or 5 GHz band. Valid values of DW Interval are: 1, 2, 3, 4,
* and 5; 0 is reserved. The SDF includes in OTA when enabled.
* The publish/subscribe period values don't override the device
* level configurations.
* input_dw_interval_val is provided by the user are in the
* format 2^n-1 = 1/2/4/8/16. Internal implementation expects n
* to be passed to indicate the awake_dw_interval.
*/
if (input_dw_interval_val == 1 ||
input_dw_interval_val % 2 == 0) {
while (input_dw_interval_val > 0) {
input_dw_interval_val >>= 1;
awake_dw_int++;
}
}
sigma_dut_print(dut, DUT_MSG_INFO,
"%s:converted active DW interval = %d",
__func__, awake_dw_int);
config_req.config_dw.config_2dot4g_dw_band = 1;
config_req.config_dw.dw_2dot4g_interval_val = awake_dw_int;
config_req.config_dw.config_5g_dw_band = 1;
config_req.config_dw.dw_5g_interval_val = awake_dw_int;
ret = nan_config_request(0, dut->wifi_hal_iface_handle,
&config_req);
if (ret != WIFI_SUCCESS) {
sigma_dut_print(dut, DUT_MSG_ERROR,
"%s:NAN config request failed",
__func__);
return -2;
}
}
#endif
#ifdef WFA_CERT_NANR4
if (gtk_protection)
req.sdea_params.gtk_protection = atoi(gtk_protection);
if (cipher_capabilities)
req.cipher_capabilities = strtoul(cipher_capabilities, NULL, 0);
if (pairing_setup) {
req.nan_pairing_config.enable_pairing_setup =
atoi(pairing_setup);
dut->dev_info.pairing_setup =
atoi(pairing_setup) ? true : false;
if (npk_nik_cache) {
req.nan_pairing_config.enable_pairing_cache =
atoi(npk_nik_cache);
dut->dev_info.npk_nik_caching =
atoi(npk_nik_cache) ? true : false;
}
req.sdea_params.security_cfg = NAN_DP_CONFIG_SECURITY;
sigma_dut_print(dut, DUT_MSG_INFO,
"%s: pairing_setup: %d, enable NIK cache: %d",
__func__, dut->dev_info.pairing_setup,
dut->dev_info.npk_nik_caching);
}
if (bootstrap_method) {
req.nan_pairing_config.enable_pairing_setup = 1;
dut->dev_info.pairing_setup = true;
req.nan_pairing_config.enable_pairing_cache = 1;
dut->dev_info.npk_nik_caching = true;
req.sdea_params.security_cfg = NAN_DP_CONFIG_SECURITY;
req.nan_pairing_config.supported_bootstrapping_methods =
strtoul(bootstrap_method, NULL, 0);
dut->dev_info.bootstrapping_methods =
req.nan_pairing_config.supported_bootstrapping_methods;
sigma_dut_print(dut, DUT_MSG_INFO,
"%s: NAN Bootstrapping Method: %d", __func__,
dut->dev_info.bootstrapping_methods);
}
if (dut->dev_info.npk_nik_caching && dut->dev_info.nik_valid) {
req.nan_pairing_config.enable_pairing_verification = 1;
memcpy(req.nan_identity_key, dut->dev_info.nik,
sizeof(req.nan_identity_key));
}
#endif /* WFA_CERT_NANR4 */
ret = nan_subscribe_request(0, dut->wifi_hal_iface_handle, &req);
if (ret != WIFI_SUCCESS) {
send_resp(dut, conn, SIGMA_ERROR,
"NAN subscribe request failed");
}
return 0;
}
static int sigma_ndp_configure_band(struct sigma_dut *dut,
struct sigma_conn *conn,
struct sigma_cmd *cmd,
NdpSupportedBand band_config_val)
{
wifi_error ret;
NanDebugParams cfg_debug;
int size;
memset(&cfg_debug, 0, sizeof(NanDebugParams));
cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SUPPORTED_BANDS;
memcpy(cfg_debug.debug_cmd_data, &band_config_val, sizeof(int));
sigma_dut_print(dut, DUT_MSG_INFO, "%s:setting debug cmd=0x%x",
__func__, cfg_debug.cmd);
size = sizeof(u32) + sizeof(int);
ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, cfg_debug,
size);
if (ret != WIFI_SUCCESS)
send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
return 0;
}