This repository has been archived by the owner on Mar 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
dhd_pno.c
1898 lines (1846 loc) · 62 KB
/
dhd_pno.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
/*
* Broadcom Dongle Host Driver (DHD)
* Prefered Network Offload and Wi-Fi Location Service(WLS) code.
*
* Copyright (C) 1999-2014, Broadcom Corporation
*
* Unless you and Broadcom execute a separate written software license
* agreement governing use of this software, this software is licensed to you
* under the terms of the GNU General Public License version 2 (the "GPL"),
* available at http://www.broadcom.com/licenses/GPLv2.php, with the
* following added to such license:
*
* As a special exception, the copyright holders of this software give you
* permission to link this software with independent modules, and to copy and
* distribute the resulting executable under terms of your choice, provided that
* you also meet, for each linked independent module, the terms and conditions of
* the license of that module. An independent module is a module which is not
* derived from this software. The special exception does not apply to any
* modifications of the software.
*
* Notwithstanding the above, under no circumstances may you combine this
* software in any way with any other Broadcom software provided under a license
* other than the GPL, without Broadcom's express prior written consent.
*
* $Id: dhd_pno.c 423669 2013-09-18 13:01:55Z yangj$
*/
#ifdef PNO_SUPPORT
#include <typedefs.h>
#include <osl.h>
#include <epivers.h>
#include <bcmutils.h>
#include <bcmendian.h>
#include <linuxver.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/sort.h>
#include <dngl_stats.h>
#include <wlioctl.h>
#include <proto/bcmevent.h>
#include <dhd.h>
#include <dhd_pno.h>
#include <dhd_dbg.h>
#ifdef __BIG_ENDIAN
#include <bcmendian.h>
#define htod32(i) (bcmswap32(i))
#define htod16(i) (bcmswap16(i))
#define dtoh32(i) (bcmswap32(i))
#define dtoh16(i) (bcmswap16(i))
#define htodchanspec(i) htod16(i)
#define dtohchanspec(i) dtoh16(i)
#else
#define htod32(i) (i)
#define htod16(i) (i)
#define dtoh32(i) (i)
#define dtoh16(i) (i)
#define htodchanspec(i) (i)
#define dtohchanspec(i) (i)
#endif /* IL_BIGENDINA */
#define NULL_CHECK(p, s, err) \
do { \
if (!(p)) { \
printf("NULL POINTER (%s) : %s\n", __FUNCTION__, (s)); \
err = BCME_ERROR; \
return err; \
} \
} while (0)
#define PNO_GET_PNOSTATE(dhd) ((dhd_pno_status_info_t *)dhd->pno_state)
#define PNO_BESTNET_LEN 1024
#define PNO_ON 1
#define PNO_OFF 0
#define CHANNEL_2G_MAX 14
#define MAX_NODE_CNT 5
#define WLS_SUPPORTED(pno_state) (pno_state->wls_supported == TRUE)
#define TIME_DIFF(timestamp1, timestamp2) (abs((uint32)(timestamp1/1000) \
- (uint32)(timestamp2/1000)))
#define ENTRY_OVERHEAD strlen("bssid=\nssid=\nfreq=\nlevel=\nage=\ndist=\ndistSd=\n====")
#define TIME_MIN_DIFF 5
static inline bool
is_dfs(uint16 channel)
{
if (channel >= 52 && channel <= 64) /* class 2 */
return TRUE;
else if (channel >= 100 && channel <= 140) /* class 4 */
return TRUE;
else
return FALSE;
}
int
dhd_pno_clean(dhd_pub_t *dhd)
{
int pfn = 0;
int err;
dhd_pno_status_info_t *_pno_state;
NULL_CHECK(dhd, "dhd is NULL", err);
NULL_CHECK(dhd->pno_state, "pno_state is NULL", err);
_pno_state = PNO_GET_PNOSTATE(dhd);
DHD_PNO(("%s enter\n", __FUNCTION__));
/* Disable PNO */
err = dhd_iovar(dhd, 0, "pfn", (char *)&pfn, sizeof(pfn), 1);
if (err < 0) {
DHD_ERROR(("%s : failed to execute pfn(error : %d)\n",
__FUNCTION__, err));
goto exit;
}
_pno_state->pno_status = DHD_PNO_DISABLED;
err = dhd_iovar(dhd, 0, "pfnclear", NULL, 0, 1);
if (err < 0) {
DHD_ERROR(("%s : failed to execute pfnclear(error : %d)\n",
__FUNCTION__, err));
}
exit:
return err;
}
static int
_dhd_pno_suspend(dhd_pub_t *dhd)
{
int err;
int suspend = 1;
dhd_pno_status_info_t *_pno_state;
NULL_CHECK(dhd, "dhd is NULL", err);
NULL_CHECK(dhd->pno_state, "pno_state is NULL", err);
DHD_PNO(("%s enter\n", __FUNCTION__));
_pno_state = PNO_GET_PNOSTATE(dhd);
err = dhd_iovar(dhd, 0, "pfn_suspend", (char *)&suspend, sizeof(suspend), 1);
if (err < 0) {
DHD_ERROR(("%s : failed to suspend pfn(error :%d)\n", __FUNCTION__, err));
goto exit;
}
_pno_state->pno_status = DHD_PNO_SUSPEND;
exit:
return err;
}
static int
_dhd_pno_enable(dhd_pub_t *dhd, int enable)
{
int err = BCME_OK;
dhd_pno_status_info_t *_pno_state;
NULL_CHECK(dhd, "dhd is NULL", err);
NULL_CHECK(dhd->pno_state, "pno_state is NULL", err);
_pno_state = PNO_GET_PNOSTATE(dhd);
DHD_PNO(("%s enter\n", __FUNCTION__));
if (enable & 0xfffe) {
DHD_ERROR(("%s invalid value\n", __FUNCTION__));
err = BCME_BADARG;
goto exit;
}
if (!dhd_support_sta_mode(dhd)) {
DHD_ERROR(("PNO is not allowed for non-STA mode"));
err = BCME_BADOPTION;
goto exit;
}
if (enable) {
if ((_pno_state->pno_mode & DHD_PNO_LEGACY_MODE) &&
dhd_is_associated(dhd, NULL, NULL)) {
DHD_ERROR(("%s Legacy PNO mode cannot be enabled "
"in assoc mode , ignore it\n", __FUNCTION__));
err = BCME_BADOPTION;
goto exit;
}
}
/* Enable/Disable PNO */
err = dhd_iovar(dhd, 0, "pfn", (char *)&enable, sizeof(enable), 1);
if (err < 0) {
DHD_ERROR(("%s : failed to execute pfn_set\n", __FUNCTION__));
goto exit;
}
_pno_state->pno_status = (enable)?
DHD_PNO_ENABLED : DHD_PNO_DISABLED;
if (!enable)
_pno_state->pno_mode = DHD_PNO_NONE_MODE;
DHD_PNO(("%s set pno as %s\n",
__FUNCTION__, enable ? "Enable" : "Disable"));
exit:
return err;
}
static int
_dhd_pno_set(dhd_pub_t *dhd, const dhd_pno_params_t *pno_params, dhd_pno_mode_t mode)
{
int err = BCME_OK;
wl_pfn_param_t pfn_param;
dhd_pno_params_t *_params;
dhd_pno_status_info_t *_pno_state;
bool combined_scan = FALSE;
DHD_PNO(("%s enter\n", __FUNCTION__));
NULL_CHECK(dhd, "dhd is NULL", err);
NULL_CHECK(dhd->pno_state, "pno_state is NULL", err);
_pno_state = PNO_GET_PNOSTATE(dhd);
memset(&pfn_param, 0, sizeof(pfn_param));
/* set pfn parameters */
pfn_param.version = htod32(PFN_VERSION);
pfn_param.flags = ((PFN_LIST_ORDER << SORT_CRITERIA_BIT) |
(ENABLE << IMMEDIATE_SCAN_BIT) | (ENABLE << REPORT_SEPERATELY_BIT));
if (mode == DHD_PNO_LEGACY_MODE) {
/* check and set extra pno params */
if ((pno_params->params_legacy.pno_repeat != 0) ||
(pno_params->params_legacy.pno_freq_expo_max != 0)) {
pfn_param.flags |= htod16(ENABLE << ENABLE_ADAPTSCAN_BIT);
pfn_param.repeat = (uchar) (pno_params->params_legacy.pno_repeat);
pfn_param.exp = (uchar) (pno_params->params_legacy.pno_freq_expo_max);
}
/* set up pno scan fr */
if (pno_params->params_legacy.scan_fr != 0)
pfn_param.scan_freq = htod32(pno_params->params_legacy.scan_fr);
if (_pno_state->pno_mode & DHD_PNO_BATCH_MODE) {
DHD_PNO(("will enable combined scan with BATCHIG SCAN MODE\n"));
mode |= DHD_PNO_BATCH_MODE;
combined_scan = TRUE;
} else if (_pno_state->pno_mode & DHD_PNO_HOTLIST_MODE) {
DHD_PNO(("will enable combined scan with HOTLIST SCAN MODE\n"));
mode |= DHD_PNO_HOTLIST_MODE;
combined_scan = TRUE;
}
}
if (mode & (DHD_PNO_BATCH_MODE | DHD_PNO_HOTLIST_MODE)) {
/* Scan frequency of 30 sec */
pfn_param.scan_freq = htod32(30);
/* slow adapt scan is off by default */
pfn_param.slow_freq = htod32(0);
/* RSSI margin of 30 dBm */
pfn_param.rssi_margin = htod16(30);
/* Network timeout 60 sec */
pfn_param.lost_network_timeout = htod32(60);
/* best n = 2 by default */
pfn_param.bestn = DEFAULT_BESTN;
/* mscan m=0 by default, so not record best networks by default */
pfn_param.mscan = DEFAULT_MSCAN;
/* default repeat = 10 */
pfn_param.repeat = DEFAULT_REPEAT;
/* by default, maximum scan interval = 2^2
* scan_freq when adaptive scan is turned on
*/
pfn_param.exp = DEFAULT_EXP;
if (mode == DHD_PNO_BATCH_MODE) {
/* In case of BATCH SCAN */
if (pno_params->params_batch.bestn)
pfn_param.bestn = pno_params->params_batch.bestn;
if (pno_params->params_batch.scan_fr)
pfn_param.scan_freq = htod32(pno_params->params_batch.scan_fr);
if (pno_params->params_batch.mscan)
pfn_param.mscan = pno_params->params_batch.mscan;
/* enable broadcast scan */
pfn_param.flags |= (ENABLE << ENABLE_BD_SCAN_BIT);
} else if (mode == DHD_PNO_HOTLIST_MODE) {
/* In case of HOTLIST SCAN */
if (pno_params->params_hotlist.scan_fr)
pfn_param.scan_freq = htod32(pno_params->params_hotlist.scan_fr);
pfn_param.bestn = 0;
pfn_param.repeat = 0;
/* enable broadcast scan */
pfn_param.flags |= (ENABLE << ENABLE_BD_SCAN_BIT);
}
if (combined_scan) {
/* Disable Adaptive Scan */
pfn_param.flags &= ~(htod16(ENABLE << ENABLE_ADAPTSCAN_BIT));
pfn_param.flags |= (ENABLE << ENABLE_BD_SCAN_BIT);
pfn_param.repeat = 0;
pfn_param.exp = 0;
if (_pno_state->pno_mode & DHD_PNO_BATCH_MODE) {
/* In case of Legacy PNO + BATCH SCAN */
_params = &(_pno_state->pno_params_arr[INDEX_OF_BATCH_PARAMS]);
if (_params->params_batch.bestn)
pfn_param.bestn = _params->params_batch.bestn;
if (_params->params_batch.scan_fr)
pfn_param.scan_freq = htod32(_params->params_batch.scan_fr);
if (_params->params_batch.mscan)
pfn_param.mscan = _params->params_batch.mscan;
} else if (_pno_state->pno_mode & DHD_PNO_HOTLIST_MODE) {
/* In case of Legacy PNO + HOTLIST SCAN */
_params = &(_pno_state->pno_params_arr[INDEX_OF_HOTLIST_PARAMS]);
if (_params->params_hotlist.scan_fr)
pfn_param.scan_freq = htod32(_params->params_hotlist.scan_fr);
pfn_param.bestn = 0;
pfn_param.repeat = 0;
}
}
}
if (pfn_param.scan_freq < htod32(PNO_SCAN_MIN_FW_SEC) ||
pfn_param.scan_freq > htod32(PNO_SCAN_MAX_FW_SEC)) {
DHD_ERROR(("%s pno freq(%d sec) is not valid \n",
__FUNCTION__, PNO_SCAN_MIN_FW_SEC));
err = BCME_BADARG;
goto exit;
}
if (mode == DHD_PNO_BATCH_MODE) {
int _tmp = pfn_param.bestn;
/* set bestn to calculate the max mscan which firmware supports */
err = dhd_iovar(dhd, 0, "pfnmem", (char *)&_tmp, sizeof(_tmp), 1);
if (err < 0) {
DHD_ERROR(("%s : failed to set pfnmem\n", __FUNCTION__));
goto exit;
}
/* get max mscan which the firmware supports */
err = dhd_iovar(dhd, 0, "pfnmem", (char *)&_tmp, sizeof(_tmp), 0);
if (err < 0) {
DHD_ERROR(("%s : failed to get pfnmem\n", __FUNCTION__));
goto exit;
}
DHD_PNO((" returned mscan : %d, set bestn : %d\n", _tmp, pfn_param.bestn));
pfn_param.mscan = MIN(pfn_param.mscan, _tmp);
}
err = dhd_iovar(dhd, 0, "pfn_set", (char *)&pfn_param, sizeof(pfn_param), 1);
if (err < 0) {
DHD_ERROR(("%s : failed to execute pfn_set\n", __FUNCTION__));
goto exit;
}
/* need to return mscan if this is for batch scan instead of err */
err = (mode == DHD_PNO_BATCH_MODE)? pfn_param.mscan : err;
exit:
return err;
}
static int
_dhd_pno_add_ssid(dhd_pub_t *dhd, wlc_ssid_t* ssids_list, int nssid)
{
int err = BCME_OK;
int i = 0;
wl_pfn_t pfn_element;
NULL_CHECK(dhd, "dhd is NULL", err);
if (nssid) {
NULL_CHECK(ssids_list, "ssid list is NULL", err);
}
memset(&pfn_element, 0, sizeof(pfn_element));
{
int j;
for (j = 0; j < nssid; j++) {
DHD_PNO(("%d: scan for %s size = %d\n", j,
ssids_list[j].SSID, ssids_list[j].SSID_len));
}
}
/* Check for broadcast ssid */
for (i = 0; i < nssid; i++) {
if (!ssids_list[i].SSID_len) {
DHD_ERROR(("%d: Broadcast SSID is ilegal for PNO setting\n", i));
err = BCME_ERROR;
goto exit;
}
}
/* set all pfn ssid */
for (i = 0; i < nssid; i++) {
pfn_element.infra = htod32(DOT11_BSSTYPE_INFRASTRUCTURE);
pfn_element.auth = (DOT11_OPEN_SYSTEM);
pfn_element.wpa_auth = htod32(WPA_AUTH_PFN_ANY);
pfn_element.wsec = htod32(0);
pfn_element.infra = htod32(1);
pfn_element.flags = htod32(ENABLE << WL_PFN_HIDDEN_BIT);
memcpy((char *)pfn_element.ssid.SSID, ssids_list[i].SSID,
ssids_list[i].SSID_len);
pfn_element.ssid.SSID_len = ssids_list[i].SSID_len;
err = dhd_iovar(dhd, 0, "pfn_add", (char *)&pfn_element,
sizeof(pfn_element), 1);
if (err < 0) {
DHD_ERROR(("%s : failed to execute pfn_add\n", __FUNCTION__));
goto exit;
}
}
exit:
return err;
}
/* qsort compare function */
static int
_dhd_pno_cmpfunc(const void *a, const void *b)
{
return (*(uint16*)a - *(uint16*)b);
}
static int
_dhd_pno_chan_merge(uint16 *d_chan_list, int *nchan,
uint16 *chan_list1, int nchan1, uint16 *chan_list2, int nchan2)
{
int err = BCME_OK;
int i = 0, j = 0, k = 0;
uint16 tmp;
NULL_CHECK(d_chan_list, "d_chan_list is NULL", err);
NULL_CHECK(nchan, "nchan is NULL", err);
NULL_CHECK(chan_list1, "chan_list1 is NULL", err);
NULL_CHECK(chan_list2, "chan_list2 is NULL", err);
/* chan_list1 and chan_list2 should be sorted at first */
while (i < nchan1 && j < nchan2) {
tmp = chan_list1[i] < chan_list2[j]?
chan_list1[i++] : chan_list2[j++];
for (; i < nchan1 && chan_list1[i] == tmp; i++);
for (; j < nchan2 && chan_list2[j] == tmp; j++);
d_chan_list[k++] = tmp;
}
while (i < nchan1) {
tmp = chan_list1[i++];
for (; i < nchan1 && chan_list1[i] == tmp; i++);
d_chan_list[k++] = tmp;
}
while (j < nchan2) {
tmp = chan_list2[j++];
for (; j < nchan2 && chan_list2[j] == tmp; j++);
d_chan_list[k++] = tmp;
}
*nchan = k;
return err;
}
static int
_dhd_pno_get_channels(dhd_pub_t *dhd, uint16 *d_chan_list,
int *nchan, uint8 band, bool skip_dfs)
{
int err = BCME_OK;
int i, j;
uint32 chan_buf[WL_NUMCHANNELS + 1];
wl_uint32_list_t *list;
NULL_CHECK(dhd, "dhd is NULL", err);
if (*nchan) {
NULL_CHECK(d_chan_list, "d_chan_list is NULL", err);
}
list = (wl_uint32_list_t *) (void *)chan_buf;
list->count = htod32(WL_NUMCHANNELS);
err = dhd_wl_ioctl_cmd(dhd, WLC_GET_VALID_CHANNELS, chan_buf, sizeof(chan_buf), FALSE, 0);
if (err < 0) {
DHD_ERROR(("failed to get channel list (err: %d)\n", err));
goto exit;
}
for (i = 0, j = 0; i < dtoh32(list->count) && i < *nchan; i++) {
if (band == WLC_BAND_2G) {
if (dtoh32(list->element[i]) > CHANNEL_2G_MAX)
continue;
} else if (band == WLC_BAND_5G) {
if (dtoh32(list->element[i]) <= CHANNEL_2G_MAX)
continue;
if (skip_dfs && is_dfs(dtoh32(list->element[i])))
continue;
} else { /* All channels */
if (skip_dfs && is_dfs(dtoh32(list->element[i])))
continue;
}
d_chan_list[j++] = dtoh32(list->element[i]);
}
*nchan = j;
exit:
return err;
}
static int
_dhd_pno_convert_format(dhd_pub_t *dhd, struct dhd_pno_batch_params *params_batch,
char *buf, int nbufsize)
{
int err = BCME_OK;
int bytes_written = 0, nreadsize = 0;
int t_delta = 0;
int nleftsize = nbufsize;
uint8 cnt = 0;
char *bp = buf;
char eabuf[ETHER_ADDR_STR_LEN];
#ifdef PNO_DEBUG
char *_base_bp;
char msg[150];
#endif
dhd_pno_bestnet_entry_t *iter, *next;
dhd_pno_scan_results_t *siter, *snext;
dhd_pno_best_header_t *phead, *pprev;
NULL_CHECK(params_batch, "params_batch is NULL", err);
if (nbufsize > 0)
NULL_CHECK(buf, "buf is NULL", err);
/* initialize the buffer */
memset(buf, 0, nbufsize);
DHD_PNO(("%s enter \n", __FUNCTION__));
/* # of scans */
if (!params_batch->get_batch.batch_started) {
bp += nreadsize = sprintf(bp, "scancount=%d\n",
params_batch->get_batch.expired_tot_scan_cnt);
nleftsize -= nreadsize;
params_batch->get_batch.batch_started = TRUE;
}
DHD_PNO(("%s scancount %d\n", __FUNCTION__, params_batch->get_batch.expired_tot_scan_cnt));
/* preestimate scan count until which scan result this report is going to end */
list_for_each_entry_safe(siter, snext,
¶ms_batch->get_batch.expired_scan_results_list, list) {
phead = siter->bestnetheader;
while (phead != NULL) {
/* if left_size is less than bestheader total size , stop this */
if (nleftsize <=
(phead->tot_size + phead->tot_cnt * ENTRY_OVERHEAD))
goto exit;
/* increase scan count */
cnt++;
/* # best of each scan */
DHD_PNO(("\n<loop : %d, apcount %d>\n", cnt - 1, phead->tot_cnt));
/* attribute of the scan */
if (phead->reason & PNO_STATUS_ABORT_MASK) {
bp += nreadsize = sprintf(bp, "trunc\n");
nleftsize -= nreadsize;
}
list_for_each_entry_safe(iter, next,
&phead->entry_list, list) {
t_delta = jiffies_to_msecs(jiffies - iter->recorded_time);
#ifdef PNO_DEBUG
_base_bp = bp;
memset(msg, 0, sizeof(msg));
#endif
/* BSSID info */
bp += nreadsize = sprintf(bp, "bssid=%s\n",
bcm_ether_ntoa((const struct ether_addr *)&iter->BSSID, eabuf));
nleftsize -= nreadsize;
/* SSID */
bp += nreadsize = sprintf(bp, "ssid=%s\n", iter->SSID);
nleftsize -= nreadsize;
/* channel */
bp += nreadsize = sprintf(bp, "freq=%d\n",
wf_channel2mhz(iter->channel,
iter->channel <= CH_MAX_2G_CHANNEL?
WF_CHAN_FACTOR_2_4_G : WF_CHAN_FACTOR_5_G));
nleftsize -= nreadsize;
/* RSSI */
bp += nreadsize = sprintf(bp, "level=%d\n", iter->RSSI);
nleftsize -= nreadsize;
/* add the time consumed in Driver to the timestamp of firmware */
iter->timestamp += t_delta;
bp += nreadsize = sprintf(bp, "age=%d\n", iter->timestamp);
nleftsize -= nreadsize;
/* RTT0 */
bp += nreadsize = sprintf(bp, "dist=%d\n",
(iter->rtt0 == 0)? -1 : iter->rtt0);
nleftsize -= nreadsize;
/* RTT1 */
bp += nreadsize = sprintf(bp, "distSd=%d\n",
(iter->rtt0 == 0)? -1 : iter->rtt1);
nleftsize -= nreadsize;
bp += nreadsize = sprintf(bp, "%s", AP_END_MARKER);
nleftsize -= nreadsize;
list_del(&iter->list);
MFREE(dhd->osh, iter, BESTNET_ENTRY_SIZE);
#ifdef PNO_DEBUG
memcpy(msg, _base_bp, bp - _base_bp);
DHD_PNO(("Entry : \n%s", msg));
#endif
}
bp += nreadsize = sprintf(bp, "%s", SCAN_END_MARKER);
DHD_PNO(("%s", SCAN_END_MARKER));
nleftsize -= nreadsize;
pprev = phead;
/* reset the header */
siter->bestnetheader = phead = phead->next;
MFREE(dhd->osh, pprev, BEST_HEADER_SIZE);
siter->cnt_header--;
}
if (phead == NULL) {
/* we store all entry in this scan , so it is ok to delete */
list_del(&siter->list);
MFREE(dhd->osh, siter, SCAN_RESULTS_SIZE);
}
}
exit:
if (cnt < params_batch->get_batch.expired_tot_scan_cnt) {
DHD_ERROR(("Buffer size is small to save all batch entry,"
" cnt : %d (remained_scan_cnt): %d\n",
cnt, params_batch->get_batch.expired_tot_scan_cnt - cnt));
}
params_batch->get_batch.expired_tot_scan_cnt -= cnt;
/* set FALSE only if the link list is empty after returning the data */
if (list_empty(¶ms_batch->get_batch.expired_scan_results_list)) {
params_batch->get_batch.batch_started = FALSE;
bp += sprintf(bp, "%s", RESULTS_END_MARKER);
DHD_PNO(("%s", RESULTS_END_MARKER));
DHD_PNO(("%s : Getting the batching data is complete\n", __FUNCTION__));
}
/* return used memory in buffer */
bytes_written = (int32)(bp - buf);
return bytes_written;
}
static int
_dhd_pno_clear_all_batch_results(dhd_pub_t *dhd, struct list_head *head, bool only_last)
{
int err = BCME_OK;
int removed_scan_cnt = 0;
dhd_pno_scan_results_t *siter, *snext;
dhd_pno_best_header_t *phead, *pprev;
dhd_pno_bestnet_entry_t *iter, *next;
NULL_CHECK(dhd, "dhd is NULL", err);
NULL_CHECK(head, "head is NULL", err);
NULL_CHECK(head->next, "head->next is NULL", err);
DHD_PNO(("%s enter\n", __FUNCTION__));
list_for_each_entry_safe(siter, snext,
head, list) {
if (only_last) {
/* in case that we need to delete only last one */
if (!list_is_last(&siter->list, head)) {
/* skip if the one is not last */
continue;
}
}
/* delete all data belong if the one is last */
phead = siter->bestnetheader;
while (phead != NULL) {
removed_scan_cnt++;
list_for_each_entry_safe(iter, next,
&phead->entry_list, list) {
list_del(&iter->list);
MFREE(dhd->osh, iter, BESTNET_ENTRY_SIZE);
}
pprev = phead;
phead = phead->next;
MFREE(dhd->osh, pprev, BEST_HEADER_SIZE);
}
if (phead == NULL) {
/* it is ok to delete top node */
list_del(&siter->list);
MFREE(dhd->osh, siter, SCAN_RESULTS_SIZE);
}
}
return removed_scan_cnt;
}
static int
_dhd_pno_cfg(dhd_pub_t *dhd, uint16 *channel_list, int nchan)
{
int err = BCME_OK;
int i = 0;
wl_pfn_cfg_t pfncfg_param;
NULL_CHECK(dhd, "dhd is NULL", err);
if (nchan) {
NULL_CHECK(channel_list, "nchan is NULL", err);
}
DHD_PNO(("%s enter : nchan : %d\n", __FUNCTION__, nchan));
memset(&pfncfg_param, 0, sizeof(wl_pfn_cfg_t));
/* Setup default values */
pfncfg_param.reporttype = htod32(WL_PFN_REPORT_ALLNET);
pfncfg_param.channel_num = htod32(0);
for (i = 0; i < nchan && nchan < WL_NUMCHANNELS; i++)
pfncfg_param.channel_list[i] = channel_list[i];
pfncfg_param.channel_num = htod32(nchan);
err = dhd_iovar(dhd, 0, "pfn_cfg", (char *)&pfncfg_param, sizeof(pfncfg_param), 1);
if (err < 0) {
DHD_ERROR(("%s : failed to execute pfn_cfg\n", __FUNCTION__));
goto exit;
}
exit:
return err;
}
static int
_dhd_pno_reinitialize_prof(dhd_pub_t *dhd, dhd_pno_params_t *params, dhd_pno_mode_t mode)
{
int err = BCME_OK;
dhd_pno_status_info_t *_pno_state;
NULL_CHECK(dhd, "dhd is NULL\n", err);
NULL_CHECK(dhd->pno_state, "pno_state is NULL\n", err);
DHD_PNO(("%s enter\n", __FUNCTION__));
_pno_state = PNO_GET_PNOSTATE(dhd);
mutex_lock(&_pno_state->pno_mutex);
switch (mode) {
case DHD_PNO_LEGACY_MODE: {
struct dhd_pno_ssid *iter, *next;
if (params->params_legacy.nssid > 0) {
list_for_each_entry_safe(iter, next,
¶ms->params_legacy.ssid_list, list) {
list_del(&iter->list);
kfree(iter);
}
}
params->params_legacy.nssid = 0;
params->params_legacy.scan_fr = 0;
params->params_legacy.pno_freq_expo_max = 0;
params->params_legacy.pno_repeat = 0;
params->params_legacy.nchan = 0;
memset(params->params_legacy.chan_list, 0,
sizeof(params->params_legacy.chan_list));
break;
}
case DHD_PNO_BATCH_MODE: {
params->params_batch.scan_fr = 0;
params->params_batch.mscan = 0;
params->params_batch.nchan = 0;
params->params_batch.rtt = 0;
params->params_batch.bestn = 0;
params->params_batch.nchan = 0;
params->params_batch.band = WLC_BAND_AUTO;
memset(params->params_batch.chan_list, 0,
sizeof(params->params_batch.chan_list));
params->params_batch.get_batch.batch_started = FALSE;
params->params_batch.get_batch.buf = NULL;
params->params_batch.get_batch.bufsize = 0;
params->params_batch.get_batch.reason = 0;
_dhd_pno_clear_all_batch_results(dhd,
¶ms->params_batch.get_batch.scan_results_list, FALSE);
_dhd_pno_clear_all_batch_results(dhd,
¶ms->params_batch.get_batch.expired_scan_results_list, FALSE);
params->params_batch.get_batch.tot_scan_cnt = 0;
params->params_batch.get_batch.expired_tot_scan_cnt = 0;
params->params_batch.get_batch.top_node_cnt = 0;
INIT_LIST_HEAD(¶ms->params_batch.get_batch.scan_results_list);
INIT_LIST_HEAD(¶ms->params_batch.get_batch.expired_scan_results_list);
break;
}
case DHD_PNO_HOTLIST_MODE: {
struct dhd_pno_bssid *iter, *next;
if (params->params_hotlist.nbssid > 0) {
list_for_each_entry_safe(iter, next,
¶ms->params_hotlist.bssid_list, list) {
list_del(&iter->list);
kfree(iter);
}
}
params->params_hotlist.scan_fr = 0;
params->params_hotlist.nbssid = 0;
params->params_hotlist.nchan = 0;
params->params_batch.band = WLC_BAND_AUTO;
memset(params->params_hotlist.chan_list, 0,
sizeof(params->params_hotlist.chan_list));
break;
}
default:
DHD_ERROR(("%s : unknown mode : %d\n", __FUNCTION__, mode));
break;
}
mutex_unlock(&_pno_state->pno_mutex);
return err;
}
static int
_dhd_pno_add_bssid(dhd_pub_t *dhd, wl_pfn_bssid_t *p_pfn_bssid, int nbssid)
{
int err = BCME_OK;
NULL_CHECK(dhd, "dhd is NULL", err);
if (nbssid) {
NULL_CHECK(p_pfn_bssid, "bssid list is NULL", err);
}
err = dhd_iovar(dhd, 0, "pfn_add_bssid", (char *)&p_pfn_bssid,
sizeof(wl_pfn_bssid_t) * nbssid, 1);
if (err < 0) {
DHD_ERROR(("%s : failed to execute pfn_cfg\n", __FUNCTION__));
goto exit;
}
exit:
return err;
}
int
dhd_pno_stop_for_ssid(dhd_pub_t *dhd)
{
int err = BCME_OK;
uint32 mode = 0;
dhd_pno_status_info_t *_pno_state;
dhd_pno_params_t *_params;
wl_pfn_bssid_t *p_pfn_bssid = NULL;
NULL_CHECK(dhd, "dev is NULL", err);
NULL_CHECK(dhd->pno_state, "pno_state is NULL", err);
_pno_state = PNO_GET_PNOSTATE(dhd);
if (!(_pno_state->pno_mode & DHD_PNO_LEGACY_MODE)) {
DHD_ERROR(("%s : LEGACY PNO MODE is not enabled\n", __FUNCTION__));
goto exit;
}
DHD_PNO(("%s enter\n", __FUNCTION__));
_pno_state->pno_mode &= ~DHD_PNO_LEGACY_MODE;
/* restart Batch mode if the batch mode is on */
if (_pno_state->pno_mode & (DHD_PNO_BATCH_MODE | DHD_PNO_HOTLIST_MODE)) {
/* retrieve the batching data from firmware into host */
dhd_pno_get_for_batch(dhd, NULL, 0, PNO_STATUS_DISABLE);
/* save current pno_mode before calling dhd_pno_clean */
mode = _pno_state->pno_mode;
dhd_pno_clean(dhd);
/* restore previous pno_mode */
_pno_state->pno_mode = mode;
if (_pno_state->pno_mode & DHD_PNO_BATCH_MODE) {
_params = &(_pno_state->pno_params_arr[INDEX_OF_BATCH_PARAMS]);
/* restart BATCH SCAN */
err = dhd_pno_set_for_batch(dhd, &_params->params_batch);
if (err < 0) {
_pno_state->pno_mode &= ~DHD_PNO_BATCH_MODE;
DHD_ERROR(("%s : failed to restart batch scan(err: %d)\n",
__FUNCTION__, err));
goto exit;
}
} else if (_pno_state->pno_mode & DHD_PNO_HOTLIST_MODE) {
/* restart HOTLIST SCAN */
struct dhd_pno_bssid *iter, *next;
_params = &(_pno_state->pno_params_arr[INDEX_OF_HOTLIST_PARAMS]);
p_pfn_bssid = kzalloc(sizeof(wl_pfn_bssid_t) *
_params->params_hotlist.nbssid, GFP_KERNEL);
if (p_pfn_bssid == NULL) {
DHD_ERROR(("%s : failed to allocate wl_pfn_bssid_t array"
" (count: %d)",
__FUNCTION__, _params->params_hotlist.nbssid));
err = BCME_ERROR;
_pno_state->pno_mode &= ~DHD_PNO_HOTLIST_MODE;
goto exit;
}
/* convert dhd_pno_bssid to wl_pfn_bssid */
list_for_each_entry_safe(iter, next,
&_params->params_hotlist.bssid_list, list) {
memcpy(&p_pfn_bssid->macaddr,
&iter->macaddr, ETHER_ADDR_LEN);
p_pfn_bssid->flags = iter->flags;
p_pfn_bssid++;
}
err = dhd_pno_set_for_hotlist(dhd, p_pfn_bssid, &_params->params_hotlist);
if (err < 0) {
_pno_state->pno_mode &= ~DHD_PNO_HOTLIST_MODE;
DHD_ERROR(("%s : failed to restart hotlist scan(err: %d)\n",
__FUNCTION__, err));
goto exit;
}
}
} else {
err = dhd_pno_clean(dhd);
if (err < 0) {
DHD_ERROR(("%s : failed to call dhd_pno_clean (err: %d)\n",
__FUNCTION__, err));
goto exit;
}
}
exit:
if (p_pfn_bssid)
kfree(p_pfn_bssid);
return err;
}
int
dhd_pno_enable(dhd_pub_t *dhd, int enable)
{
int err = BCME_OK;
NULL_CHECK(dhd, "dhd is NULL", err);
DHD_PNO(("%s enter\n", __FUNCTION__));
return (_dhd_pno_enable(dhd, enable));
}
int
dhd_pno_set_for_ssid(dhd_pub_t *dhd, wlc_ssid_t* ssid_list, int nssid,
uint16 scan_fr, int pno_repeat, int pno_freq_expo_max, uint16 *channel_list, int nchan)
{
struct dhd_pno_ssid *_pno_ssid;
dhd_pno_params_t *_params;
dhd_pno_params_t *_params2;
dhd_pno_status_info_t *_pno_state;
uint16 _chan_list[WL_NUMCHANNELS];
int32 tot_nchan = 0;
int err = BCME_OK;
int i;
int mode = 0;
NULL_CHECK(dhd, "dhd is NULL", err);
NULL_CHECK(dhd->pno_state, "pno_state is NULL", err);
_pno_state = PNO_GET_PNOSTATE(dhd);
if (!dhd_support_sta_mode(dhd)) {
err = BCME_BADOPTION;
goto exit;
}
DHD_PNO(("%s enter : scan_fr :%d, pno_repeat :%d,"
"pno_freq_expo_max: %d, nchan :%d\n", __FUNCTION__,
scan_fr, pno_repeat, pno_freq_expo_max, nchan));
_params = &(_pno_state->pno_params_arr[INDEX_OF_LEGACY_PARAMS]);
if (_pno_state->pno_mode & DHD_PNO_LEGACY_MODE) {
DHD_ERROR(("%s : Legacy PNO mode was already started, "
"will disable previous one to start new one\n", __FUNCTION__));
err = dhd_pno_stop_for_ssid(dhd);
if (err < 0) {
DHD_ERROR(("%s : failed to stop legacy PNO (err %d)\n",
__FUNCTION__, err));
goto exit;
}
}
_pno_state->pno_mode |= DHD_PNO_LEGACY_MODE;
err = _dhd_pno_reinitialize_prof(dhd, _params, DHD_PNO_LEGACY_MODE);
if (err < 0) {
DHD_ERROR(("%s : failed to reinitialize profile (err %d)\n",
__FUNCTION__, err));
goto exit;
}
memset(_chan_list, 0, sizeof(_chan_list));
tot_nchan = nchan;
if (tot_nchan > 0 && channel_list) {
for (i = 0; i < nchan; i++)
_params->params_legacy.chan_list[i] = _chan_list[i] = channel_list[i];
}
if (_pno_state->pno_mode & (DHD_PNO_BATCH_MODE | DHD_PNO_HOTLIST_MODE)) {
DHD_PNO(("BATCH SCAN is on progress in firmware\n"));
/* retrieve the batching data from firmware into host */
dhd_pno_get_for_batch(dhd, NULL, 0, PNO_STATUS_DISABLE);
/* store current pno_mode before disabling pno */
mode = _pno_state->pno_mode;
err = _dhd_pno_enable(dhd, PNO_OFF);
if (err < 0) {
DHD_ERROR(("%s : failed to disable PNO\n", __FUNCTION__));
goto exit;
}
/* restore the previous mode */
_pno_state->pno_mode = mode;
/* use superset of channel list between two mode */
if (_pno_state->pno_mode & DHD_PNO_BATCH_MODE) {
_params2 = &(_pno_state->pno_params_arr[INDEX_OF_BATCH_PARAMS]);
if (_params2->params_batch.nchan > 0 && nchan > 0) {
err = _dhd_pno_chan_merge(_chan_list, &tot_nchan,
&_params2->params_batch.chan_list[0],
_params2->params_batch.nchan,
&channel_list[0], nchan);
if (err < 0) {
DHD_ERROR(("%s : failed to merge channel list"
" between legacy and batch\n",
__FUNCTION__));
goto exit;
}
} else {
DHD_PNO(("superset channel will use"
" all channels in firmware\n"));
}
} else if (_pno_state->pno_mode & DHD_PNO_HOTLIST_MODE) {
_params2 = &(_pno_state->pno_params_arr[INDEX_OF_HOTLIST_PARAMS]);
if (_params2->params_hotlist.nchan > 0 && nchan > 0) {
err = _dhd_pno_chan_merge(_chan_list, &tot_nchan,
&_params2->params_hotlist.chan_list[0],
_params2->params_hotlist.nchan,
&channel_list[0], nchan);
if (err < 0) {
DHD_ERROR(("%s : failed to merge channel list"
" between legacy and hotlist\n",
__FUNCTION__));
goto exit;
}
}
}
}
_params->params_legacy.scan_fr = scan_fr;
_params->params_legacy.pno_repeat = pno_repeat;
_params->params_legacy.pno_freq_expo_max = pno_freq_expo_max;
_params->params_legacy.nchan = nchan;
_params->params_legacy.nssid = nssid;
INIT_LIST_HEAD(&_params->params_legacy.ssid_list);
if ((err = _dhd_pno_set(dhd, _params, DHD_PNO_LEGACY_MODE)) < 0) {
DHD_ERROR(("failed to set call pno_set (err %d) in firmware\n", err));
goto exit;
}
if ((err = _dhd_pno_add_ssid(dhd, ssid_list, nssid)) < 0) {
DHD_ERROR(("failed to add ssid list(err %d), %d in firmware\n", err, nssid));
goto exit;
}
for (i = 0; i < nssid; i++) {
_pno_ssid = kzalloc(sizeof(struct dhd_pno_ssid), GFP_KERNEL);
if (_pno_ssid == NULL) {
DHD_ERROR(("%s : failed to allocate struct dhd_pno_ssid\n",
__FUNCTION__));
goto exit;
}
_pno_ssid->SSID_len = ssid_list[i].SSID_len;
memcpy(_pno_ssid->SSID, ssid_list[i].SSID, _pno_ssid->SSID_len);
list_add_tail(&_pno_ssid->list, &_params->params_legacy.ssid_list);
}
if (tot_nchan > 0) {
if ((err = _dhd_pno_cfg(dhd, _chan_list, tot_nchan)) < 0) {
DHD_ERROR(("%s : failed to set call pno_cfg (err %d) in firmware\n",
__FUNCTION__, err));
goto exit;
}
}
if (_pno_state->pno_status == DHD_PNO_DISABLED) {
if ((err = _dhd_pno_enable(dhd, PNO_ON)) < 0)
DHD_ERROR(("%s : failed to enable PNO\n", __FUNCTION__));
}
exit:
/* clear mode in case of error */
if (err < 0)
_pno_state->pno_mode &= ~DHD_PNO_LEGACY_MODE;
return err;
}
int
dhd_pno_set_for_batch(dhd_pub_t *dhd, struct dhd_pno_batch_params *batch_params)
{
int err = BCME_OK;
uint16 _chan_list[WL_NUMCHANNELS];
int rem_nchan = 0, tot_nchan = 0;
int mode = 0, mscan = 0;
int i = 0;
dhd_pno_params_t *_params;
dhd_pno_params_t *_params2;
dhd_pno_status_info_t *_pno_state;
wlc_ssid_t *p_ssid_list = NULL;
NULL_CHECK(dhd, "dhd is NULL", err);
NULL_CHECK(dhd->pno_state, "pno_state is NULL", err);
NULL_CHECK(batch_params, "batch_params is NULL", err);
_pno_state = PNO_GET_PNOSTATE(dhd);
DHD_PNO(("%s enter\n", __FUNCTION__));
if (!dhd_support_sta_mode(dhd)) {
err = BCME_BADOPTION;
goto exit;
}
if (!WLS_SUPPORTED(_pno_state)) {
DHD_ERROR(("%s : wifi location service is not supported\n", __FUNCTION__));
err = BCME_UNSUPPORTED;
goto exit;