hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Linux cfg80211 driver
 *
 * Copyright (C) 1999-2017, 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.
 *
 *
 * <<Broadcom-WL-IPTag/Open:>>
 *
 * $Id: wl_cfg80211.h 710862 2017-07-14 07:43:59Z $
 */
 
/**
 * Older Linux versions support the 'iw' interface, more recent ones the 'cfg80211' interface.
 */
 
#ifndef _wl_cfg80211_h_
#define _wl_cfg80211_h_
 
#include <linux/wireless.h>
#include <typedefs.h>
#include <ethernet.h>
#include <wlioctl.h>
#include <linux/wireless.h>
#include <net/cfg80211.h>
#include <linux/rfkill.h>
 
#include <dngl_stats.h>
#include <dhd.h>
#include <wl_cfgp2p.h>
#include <wl_android.h>
struct wl_conf;
struct wl_iface;
struct bcm_cfg80211;
struct wl_security;
struct wl_ibss;
 
#if !defined(WL_CLIENT_SAE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0))
#define WL_CLIENT_SAE
#endif
#if defined(WL_SAE) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
#error "Can not support WL_SAE befor kernel 3.14"
#endif
#if defined(WL_CLIENT_SAE) && (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
#error "Can not support WL_CLIENT_SAE before kernel 4.9"
#endif
#if defined(WL_CLIENT_SAE) && defined(WL_SAE)
#error "WL_SAE is for dongle-offload and WL_CLIENT_SAE is for wpa_supplicant. Please choose one."
#endif
 
#if defined(WL_CLIENT_SAE)
#ifndef WL_ASSOC_MGR_CMD_SEND_AUTH
#define WL_ASSOC_MGR_CMD_SEND_AUTH 3
#endif /* WL_ASSOC_MGR_CMD_SEND_AUTH */
#endif
 
#define htod32(i) (i)
#define htod16(i) (i)
#define dtoh64(i) (i)
#define dtoh32(i) (i)
#define dtoh16(i) (i)
#define htodchanspec(i) (i)
#define dtohchanspec(i) (i)
 
#define WL_DBG_NONE    0
#define WL_DBG_P2P_ACTION    (1 << 5)
#define WL_DBG_TRACE    (1 << 4)
#define WL_DBG_SCAN    (1 << 3)
#define WL_DBG_DBG    (1 << 2)
#define WL_DBG_INFO    (1 << 1)
#define WL_DBG_ERR    (1 << 0)
 
#ifdef DHD_LOG_DUMP
extern void dhd_log_dump_write(int type, const char *fmt, ...);
extern char *dhd_log_dump_get_timestamp(void);
#ifndef _DHD_LOG_DUMP_DEFINITIONS_
#define DLD_BUF_TYPE_GENERAL    0
#define DLD_BUF_TYPE_SPECIAL    1
#define DHD_LOG_DUMP_WRITE(fmt, ...)    dhd_log_dump_write(DLD_BUF_TYPE_GENERAL, fmt, ##__VA_ARGS__)
#define DHD_LOG_DUMP_WRITE_EX(fmt, ...)    dhd_log_dump_write(DLD_BUF_TYPE_SPECIAL, fmt, ##__VA_ARGS__)
#endif /* !_DHD_LOG_DUMP_DEFINITIONS_ */
#endif /* DHD_LOG_DUMP */
 
/* 0 invalidates all debug messages.  default is 1 */
#define WL_DBG_LEVEL 0xFF
 
#ifdef CUSTOMER_HW4_DEBUG
#define CFG80211_ERROR_TEXT        "[dhd] CFG80211-INFO2) "
#else
#define CFG80211_ERROR_TEXT        "[dhd] CFG80211-ERROR) "
#endif /* CUSTOMER_HW4_DEBUG */
 
#if defined(DHD_DEBUG)
#ifdef DHD_LOG_DUMP
#define    WL_ERR_MSG(x, args...)    \
do {    \
   if (wl_dbg_level & WL_DBG_ERR) {    \
       printk(KERN_INFO CFG80211_ERROR_TEXT "%s : " x, __func__, ## args);    \
       DHD_LOG_DUMP_WRITE("[%s] %s: ", dhd_log_dump_get_timestamp(), __func__);    \
       DHD_LOG_DUMP_WRITE(x, ## args);    \
   }    \
} while (0)
#define    WL_ERR_MEM(args)    \
do {    \
   if (wl_dbg_level & WL_DBG_ERR) {    \
       DHD_LOG_DUMP_WRITE("[%s] %s: ", dhd_log_dump_get_timestamp(), __func__);    \
       DHD_LOG_DUMP_WRITE(x, ## args);    \
   }    \
} while (0)
#define    WL_ERR_EX_MSG(x, args...)    \
do {    \
   if (wl_dbg_level & WL_DBG_ERR) {    \
       printk(KERN_INFO CFG80211_ERROR_TEXT "%s : " x, __func__, ## args);    \
       DHD_LOG_DUMP_WRITE_EX("[%s] %s: ", dhd_log_dump_get_timestamp(), __func__); \
       DHD_LOG_DUMP_WRITE_EX(x, ## args); \
   }    \
} while (0)
#define WL_ERR(x) WL_ERR_MSG x
#define WL_ERR_EX(args) WL_ERR_EX_MSG(args)
#else
#define    WL_ERR_MSG(x, args...)                                    \
do {                                        \
   if (wl_dbg_level & WL_DBG_ERR) {                \
       printk(KERN_INFO CFG80211_ERROR_TEXT "%s : " x, __func__, ## args);    \
   }                                \
} while (0)
#define WL_ERR(x) WL_ERR_MSG x
#define WL_ERR_MEM(args) WL_ERR(args)
#define WL_ERR_EX(args) WL_ERR(args)
#endif /* DHD_LOG_DUMP */
#else /* defined(DHD_DEBUG) */
#define    WL_ERR_MSG(x, args...)                                    \
do {                                        \
   if ((wl_dbg_level & WL_DBG_ERR) && net_ratelimit()) {                \
       printk(KERN_INFO CFG80211_ERROR_TEXT "%s : " x, __func__, ## args);    \
   }                                \
} while (0)
#define WL_ERR(x) WL_ERR_MSG x
#define WL_ERR_MEM(args) WL_ERR(args)
#define WL_ERR_EX(args) WL_ERR(args)
#endif /* defined(DHD_DEBUG) */
 
#define WL_PRINT_RATE_LIMIT_PERIOD 4000000000u /* 4s in units of ns */
#define WL_ERR_RLMT(args) \
do {    \
   if (wl_dbg_level & WL_DBG_ERR) {    \
       static uint64 __err_ts = 0; \
       static uint32 __err_cnt = 0; \
       uint64 __cur_ts = 0; \
       __cur_ts = local_clock(); \
       if (__err_ts == 0 || (__cur_ts > __err_ts && \
       (__cur_ts - __err_ts > WL_PRINT_RATE_LIMIT_PERIOD))) { \
           __err_ts = __cur_ts; \
           WL_ERR(args);    \
           WL_ERR(("[Repeats %u times]\n", __err_cnt)); \
           __err_cnt = 0; \
       } else { \
           ++__err_cnt; \
       } \
   }    \
} while (0)
 
#ifdef WL_INFORM
#undef WL_INFORM
#endif
 
#define    WL_INFORM_MSG(x, args...)                                    \
do {                                        \
   if (wl_dbg_level & WL_DBG_INFO) {                \
       printk(KERN_INFO "[dhd] CFG80211-INFO) %s : " x, __func__, ## args);    \
   }                                \
} while (0)
#define WL_INFORM(x) WL_INFORM_MSG x
 
#ifdef WL_SCAN
#undef WL_SCAN
#endif
#define    WL_SCAN_MSG(x, args...)                                \
do {                                    \
   if (wl_dbg_level & WL_DBG_SCAN) {            \
       printk(KERN_INFO "[dhd] CFG80211-SCAN) %s :" x, __func__, ## args);    \
   }                                    \
} while (0)
#define WL_SCAN(x) WL_SCAN_MSG x
#ifdef WL_TRACE
#undef WL_TRACE
#endif
#define    WL_TRACE_MSG(x, args...)                                \
do {                                    \
   if (wl_dbg_level & WL_DBG_TRACE) {            \
       printk(KERN_INFO "[dhd] CFG80211-TRACE) %s :" x, __func__, ## args);    \
   }                                    \
} while (0)
#define WL_TRACE(x) WL_TRACE_MSG x
#ifdef WL_TRACE_HW4
#undef WL_TRACE_HW4
#endif
#ifdef CUSTOMER_HW4_DEBUG
#define    WL_TRACE_HW4_MSG(x, args...)                    \
do {                                        \
   if (wl_dbg_level & WL_DBG_ERR) {                \
       printk(KERN_INFO "[dhd] CFG80211-TRACE) %s : " x, __func__, ## args);    \
   }                                 \
} while (0)
#define WL_TRACE_HW4(x) WL_TRACE_HW4_MSG x
#else
#define    WL_TRACE_HW4            WL_TRACE
#endif /* CUSTOMER_HW4_DEBUG */
#if (WL_DBG_LEVEL > 0)
#define    WL_DBG_MSG(x, args...)                                \
do {                                    \
   if (wl_dbg_level & WL_DBG_DBG) {            \
       printk(KERN_INFO "[dhd] CFG80211-DEBUG) %s :" x, __func__, ## args);    \
   }                                    \
} while (0)
#define WL_DBG(x) WL_DBG_MSG x
#else                /* !(WL_DBG_LEVEL > 0) */
#define    WL_DBG(args)
#endif                /* (WL_DBG_LEVEL > 0) */
#define WL_PNO(x)
#define WL_SD(x)
 
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
#define ieee80211_band nl80211_band
#define IEEE80211_BAND_2GHZ NL80211_BAND_2GHZ
#define IEEE80211_BAND_5GHZ NL80211_BAND_5GHZ
#define IEEE80211_NUM_BANDS NUM_NL80211_BANDS
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
#ifdef WLMESH_CFG80211
#undef WLMESH_CFG80211
#endif
#endif
 
#define WL_SCAN_RETRY_MAX    3
#define WL_NUM_PMKIDS_MAX    MAXPMKID
#define WL_SCAN_BUF_MAX     (1024 * 8)
#define WL_TLV_INFO_MAX     1500
#define WL_SCAN_IE_LEN_MAX      2048
#define WL_BSS_INFO_MAX        2048
#define WL_ASSOC_INFO_MAX    512
#define WL_IOCTL_LEN_MAX    2048
#define WL_EXTRA_BUF_MAX    2048
#define WL_SCAN_ERSULTS_LAST     (WL_SCAN_RESULTS_NO_MEM+1)
#define WL_AP_MAX            256
#define WL_FILE_NAME_MAX    256
#define WL_DWELL_TIME        200
#define WL_MED_DWELL_TIME    400
#define WL_MIN_DWELL_TIME    100
#define WL_LONG_DWELL_TIME    1000
#define IFACE_MAX_CNT    4
#define WL_SCAN_CONNECT_DWELL_TIME_MS        200
#define WL_SCAN_JOIN_PROBE_INTERVAL_MS        20
#define WL_SCAN_JOIN_ACTIVE_DWELL_TIME_MS    320
#define WL_SCAN_JOIN_PASSIVE_DWELL_TIME_MS    400
#define WL_AF_TX_MAX_RETRY    5
 
#define WL_AF_SEARCH_TIME_MAX        450
#define WL_AF_TX_EXTRA_TIME_MAX        200
 
#define WL_SCAN_TIMER_INTERVAL_MS    10000 /* Scan timeout */
#define WL_CHANNEL_SYNC_RETRY     5
#define WL_INVALID         -1
 
#ifdef DHD_LOSSLESS_ROAMING
#define WL_ROAM_TIMEOUT_MS    1000 /* Roam timeout */
#endif
/* Bring down SCB Timeout to 20secs from 60secs default */
#ifndef WL_SCB_TIMEOUT
#define WL_SCB_TIMEOUT    20
#endif
 
#ifndef WL_SCB_ACTIVITY_TIME
#define WL_SCB_ACTIVITY_TIME    5
#endif
 
#ifndef WL_SCB_MAX_PROBE
#define WL_SCB_MAX_PROBE    3
#endif
 
#ifndef WL_MIN_PSPRETEND_THRESHOLD
#define WL_MIN_PSPRETEND_THRESHOLD    2
#endif
 
/* Cipher suites */
#define WLAN_CIPHER_SUITE_PMK        0x00904C00
 
#ifndef WLAN_AKM_SUITE_FT_8021X
#define WLAN_AKM_SUITE_FT_8021X        0x000FAC03
#endif /* WLAN_AKM_SUITE_FT_8021X */
 
#ifndef WLAN_AKM_SUITE_FT_PSK
#define WLAN_AKM_SUITE_FT_PSK        0x000FAC04
#endif /* WLAN_AKM_SUITE_FT_PSK */
 
#define WLAN_AKM_SUITE_SAE_SHA256    0x000FAC08
 
/*
 * BRCM local.
 * Use a high number that's unlikely to clash with linux upstream for a while until we can
 * submit these changes to the community.
*/
#define NL80211_FEATURE_FW_4WAY_HANDSHAKE (1<<31)
 
/* SCAN_SUPPRESS timer values in ms */
#define WL_SCAN_SUPPRESS_TIMEOUT 31000 /* default Framwork DHCP timeout is 30 sec */
#define WL_SCAN_SUPPRESS_RETRY 3000
 
#define WL_PM_ENABLE_TIMEOUT 10000
 
/* cfg80211 wowlan definitions */
#define WL_WOWLAN_MAX_PATTERNS            8
#define WL_WOWLAN_MIN_PATTERN_LEN        1
#define WL_WOWLAN_MAX_PATTERN_LEN        255
#define WL_WOWLAN_PKT_FILTER_ID_FIRST    201
#define WL_WOWLAN_PKT_FILTER_ID_LAST    (WL_WOWLAN_PKT_FILTER_ID_FIRST + \
                                   WL_WOWLAN_MAX_PATTERNS - 1)
 
#ifdef WLTDLS
#define TDLS_TUNNELED_PRB_REQ    "\x7f\x50\x6f\x9a\04"
#define TDLS_TUNNELED_PRB_RESP    "\x7f\x50\x6f\x9a\05"
#define TDLS_MAX_IFACE_FOR_ENABLE 1
#endif /* WLTDLS */
 
 
/* driver status */
enum wl_status {
   WL_STATUS_READY = 0,
   WL_STATUS_SCANNING,
   WL_STATUS_SCAN_ABORTING,
   WL_STATUS_CONNECTING,
   WL_STATUS_CONNECTED,
   WL_STATUS_DISCONNECTING,
   WL_STATUS_AP_CREATING,
   WL_STATUS_AP_CREATED,
   /* whole sending action frame procedure:
    * includes a) 'finding common channel' for public action request frame
    * and b) 'sending af via 'actframe' iovar'
    */
   WL_STATUS_SENDING_ACT_FRM,
   /* find a peer to go to a common channel before sending public action req frame */
   WL_STATUS_FINDING_COMMON_CHANNEL,
   /* waiting for next af to sync time of supplicant.
    * it includes SENDING_ACT_FRM and WAITING_NEXT_ACT_FRM_LISTEN
    */
   WL_STATUS_WAITING_NEXT_ACT_FRM,
#ifdef WL_CFG80211_SYNC_GON
   /* go to listen state to wait for next af after SENDING_ACT_FRM */
   WL_STATUS_WAITING_NEXT_ACT_FRM_LISTEN,
#endif /* WL_CFG80211_SYNC_GON */
   /* it will be set when upper layer requests listen and succeed in setting listen mode.
    * if set, other scan request can abort current listen state
    */
   WL_STATUS_REMAINING_ON_CHANNEL,
#ifdef WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST
   /* it's fake listen state to keep current scan state.
    * it will be set when upper layer requests listen but scan is running. then just run
    * a expire timer without actual listen state.
    * if set, other scan request does not need to abort scan.
    */
   WL_STATUS_FAKE_REMAINING_ON_CHANNEL,
#endif /* WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST */
   WL_STATUS_NESTED_CONNECT
};
 
/* wi-fi mode */
enum wl_mode {
   WL_MODE_BSS,
   WL_MODE_IBSS,
   WL_MODE_AP,
#ifdef WLMESH_CFG80211
   WL_MODE_MESH
#endif
};
 
/* driver profile list */
enum wl_prof_list {
   WL_PROF_MODE,
   WL_PROF_SSID,
   WL_PROF_SEC,
   WL_PROF_IBSS,
   WL_PROF_BAND,
   WL_PROF_CHAN,
   WL_PROF_BSSID,
   WL_PROF_ACT,
   WL_PROF_BEACONINT,
   WL_PROF_DTIMPERIOD
};
 
/* donlge escan state */
enum wl_escan_state {
   WL_ESCAN_STATE_IDLE,
   WL_ESCAN_STATE_SCANING
};
/* fw downloading status */
enum wl_fw_status {
   WL_FW_LOADING_DONE,
   WL_NVRAM_LOADING_DONE
};
 
enum wl_management_type {
   WL_BEACON = 0x1,
   WL_PROBE_RESP = 0x2,
   WL_ASSOC_RESP = 0x4
};
 
enum wl_pm_workq_act_type {
   WL_PM_WORKQ_SHORT,
   WL_PM_WORKQ_LONG,
   WL_PM_WORKQ_DEL
};
 
enum wl_tdls_config {
    TDLS_STATE_AP_CREATE,
    TDLS_STATE_AP_DELETE,
    TDLS_STATE_CONNECT,
    TDLS_STATE_DISCONNECT,
    TDLS_STATE_SETUP,
    TDLS_STATE_TEARDOWN,
    TDLS_STATE_IF_CREATE,
    TDLS_STATE_IF_DELETE
};
 
/* beacon / probe_response */
struct beacon_proberesp {
   __le64 timestamp;
   __le16 beacon_int;
   __le16 capab_info;
   u8 variable[0];
} __attribute__ ((packed));
 
/* driver configuration */
struct wl_conf {
   u32 frag_threshold;
   u32 rts_threshold;
   u32 retry_short;
   u32 retry_long;
   s32 tx_power;
   struct ieee80211_channel channel;
};
 
typedef s32(*EVENT_HANDLER) (struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
                            const wl_event_msg_t *e, void *data);
 
/* bss inform structure for cfg80211 interface */
struct wl_cfg80211_bss_info {
   u16 band;
   u16 channel;
   s16 rssi;
   u16 frame_len;
   u8 frame_buf[1];
};
 
/* basic structure of scan request */
struct wl_scan_req {
   struct wlc_ssid ssid;
};
 
/* basic structure of information element */
struct wl_ie {
   u16 offset;
   u8 buf[WL_TLV_INFO_MAX];
};
 
/* event queue for cfg80211 main event */
struct wl_event_q {
   struct list_head eq_list;
   u32 etype;
   wl_event_msg_t emsg;
   s8 edata[1];
};
 
/* security information with currently associated ap */
struct wl_security {
   u32 wpa_versions;
   u32 auth_type;
   u32 cipher_pairwise;
   u32 cipher_group;
   u32 wpa_auth;
   u32 auth_assoc_res_status;
};
 
/* ibss information for currently joined ibss network */
struct wl_ibss {
   u8 beacon_interval;    /* in millisecond */
   u8 atim;        /* in millisecond */
   s8 join_only;
   u8 band;
   u8 channel;
};
 
typedef struct wl_bss_vndr_ies {
   u8  probe_req_ie[VNDR_IES_BUF_LEN];
   u8  probe_res_ie[VNDR_IES_MAX_BUF_LEN];
   u8  assoc_req_ie[VNDR_IES_BUF_LEN];
   u8  assoc_res_ie[VNDR_IES_BUF_LEN];
   u8  beacon_ie[VNDR_IES_MAX_BUF_LEN];
   u32 probe_req_ie_len;
   u32 probe_res_ie_len;
   u32 assoc_req_ie_len;
   u32 assoc_res_ie_len;
   u32 beacon_ie_len;
} wl_bss_vndr_ies_t;
 
typedef struct wl_cfgbss {
   u8 *wpa_ie;
   u8 *rsn_ie;
   u8 *wps_ie;
   bool security_mode;
   struct wl_bss_vndr_ies ies;    /* Common for STA, P2P GC, GO, AP, P2P Disc Interface */
} wl_cfgbss_t;
 
/* cfg driver profile */
struct wl_profile {
   u32 mode;
   s32 band;
   u32 channel;
   struct wlc_ssid ssid;
   struct wl_security sec;
   struct wl_ibss ibss;
   u8 bssid[ETHER_ADDR_LEN];
   u16 beacon_interval;
   u8 dtim_period;
   bool active;
};
 
struct net_info {
   struct net_device *ndev;
   struct wireless_dev *wdev;
   struct wl_profile profile;
   s32 mode;
   s32 roam_off;
   unsigned long sme_state;
   bool pm_restore;
   bool pm_block;
   s32 pm;
   s32 bssidx;
   wl_cfgbss_t bss;
   u32 ulb_bw;
   struct list_head list; /* list of all net_info structure */
};
 
/* association inform */
#define MAX_REQ_LINE 1024
struct wl_connect_info {
   u8 req_ie[MAX_REQ_LINE];
   s32 req_ie_len;
   u8 resp_ie[MAX_REQ_LINE];
   s32 resp_ie_len;
};
 
/* firmware /nvram downloading controller */
struct wl_fw_ctrl {
   const struct firmware *fw_entry;
   unsigned long status;
   u32 ptr;
   s8 fw_name[WL_FILE_NAME_MAX];
   s8 nvram_name[WL_FILE_NAME_MAX];
};
 
/* assoc ie length */
struct wl_assoc_ielen {
   u32 req_len;
   u32 resp_len;
};
 
#define MIN_PMKID_LIST_V3_FW_MAJOR 13
#define MIN_PMKID_LIST_V3_FW_MINOR 0
 
#define MIN_PMKID_LIST_V2_FW_MAJOR 12
#define MIN_PMKID_LIST_V2_FW_MINOR 0
 
#define MIN_ESCAN_PARAM_V2_FW_MAJOR 14
#define MIN_ESCAN_PARAM_V2_FW_MINOR 0
 
/* wpa2 pmk list */
struct wl_pmk_list {
   pmkid_list_v3_t pmkids;
   pmkid_v3_t foo[MAXPMKID - 1];
};
 
#define KEY_PERM_PMK 0xFFFFFFFF
 
#ifdef DHD_MAX_IFS
#define WL_MAX_IFS DHD_MAX_IFS
#else
#define WL_MAX_IFS 16
#endif
 
#define ESCAN_BUF_SIZE (64 * 1024)
 
struct escan_info {
   u32 escan_state;
#ifdef STATIC_WL_PRIV_STRUCT
#ifndef CONFIG_DHD_USE_STATIC_BUF
#error STATIC_WL_PRIV_STRUCT should be used with CONFIG_DHD_USE_STATIC_BUF
#endif /* CONFIG_DHD_USE_STATIC_BUF */
   u8 *escan_buf;
#else
   u8 escan_buf[ESCAN_BUF_SIZE];
#endif /* STATIC_WL_PRIV_STRUCT */
   struct wiphy *wiphy;
   struct net_device *ndev;
};
 
#ifdef ESCAN_BUF_OVERFLOW_MGMT
#define BUF_OVERFLOW_MGMT_COUNT 3
typedef struct {
   int RSSI;
   int length;
   struct ether_addr BSSID;
} removal_element_t;
#endif /* ESCAN_BUF_OVERFLOW_MGMT */
 
struct afx_hdl {
   wl_af_params_t *pending_tx_act_frm;
   struct ether_addr    tx_dst_addr;
   struct net_device *dev;
   struct work_struct work;
   s32 bssidx;
   u32 retry;
   s32 peer_chan;
   s32 peer_listen_chan; /* search channel: configured by upper layer */
   s32 my_listen_chan;    /* listen chanel: extract it from prb req or gon req */
   bool is_listen;
   bool ack_recv;
   bool is_active;
};
 
struct parsed_ies {
   wpa_ie_fixed_t *wps_ie;
   u32 wps_ie_len;
   wpa_ie_fixed_t *wpa_ie;
   u32 wpa_ie_len;
   bcm_tlv_t *wpa2_ie;
   u32 wpa2_ie_len;
};
 
 
#ifdef P2P_LISTEN_OFFLOADING
typedef struct {
   uint16    period;                 /* listen offload period */
   uint16    interval;               /* listen offload interval */
   uint16    count;            /* listen offload count */
   uint16    pad;                    /* pad for 32bit align */
} wl_p2plo_listen_t;
#endif /* P2P_LISTEN_OFFLOADING */
 
#ifdef WL11U
/* Max length of Interworking element */
#define IW_IES_MAX_BUF_LEN         9
#endif
#ifdef WLFBT
#define FBT_KEYLEN        32
#endif
#define MAX_EVENT_BUF_NUM 16
typedef struct wl_eventmsg_buf {
   u16 num;
   struct {
       u16 type;
       bool set;
   } event [MAX_EVENT_BUF_NUM];
} wl_eventmsg_buf_t;
 
typedef struct wl_if_event_info {
   bool valid;
   int ifidx;
   int bssidx;
   uint8 mac[ETHER_ADDR_LEN];
   char name[IFNAMSIZ+1];
   uint8 role;
} wl_if_event_info;
 
 
#ifdef SUPPORT_AP_RADIO_PWRSAVE
typedef struct ap_rps_info {
   bool enable;
   bool sta_assoc_check;
   int pps;
   int quiet_time;
   int level;
} ap_rps_info_t;
#endif /* SUPPORT_AP_RADIO_PWRSAVE */
 
#ifdef SUPPORT_RSSI_LOGGING
#define RSSILOG_FLAG_FEATURE_SW        0x1
#define RSSILOG_FLAG_REPORT_READY    0x2
typedef struct rssilog_set_param {
   uint8 enable;
   uint8 rssi_threshold;
   uint8 time_threshold;
   uint8 pad;
} rssilog_set_param_t;
 
typedef struct rssilog_get_param {
   uint8 report_count;
   uint8 enable;
   uint8 rssi_threshold;
   uint8 time_threshold;
} rssilog_get_param_t;
 
typedef struct rssi_ant_param {
   struct ether_addr ea;
   chanspec_t chanspec;
} rssi_ant_param_t;
 
typedef struct wl_rssi_ant_mimo {
   uint32 version;
   uint32 count;
   int8 rssi_ant[WL_RSSI_ANT_MAX];
   int8 rssi_sum;
   int8 PAD[3];
} wl_rssi_ant_mimo_t;
#endif /* SUPPORT_RSSI_LOGGING */
 
#if defined(DHD_ENABLE_BIGDATA_LOGGING)
#define GET_BSS_INFO_LEN 90
#endif /* DHD_ENABLE_BIGDATA_LOGGING */
 
 
/* private data of cfg80211 interface */
struct bcm_cfg80211 {
   struct wireless_dev *wdev;    /* representing cfg cfg80211 device */
 
   struct wireless_dev *p2p_wdev;    /* representing cfg cfg80211 device for P2P */
   struct net_device *p2p_net;    /* reference to p2p0 interface */
 
   struct wl_conf *conf;
   struct cfg80211_scan_request *scan_request;    /* scan request object */
   EVENT_HANDLER evt_handler[WLC_E_LAST];
   struct list_head eq_list;    /* used for event queue */
   struct list_head net_list;     /* used for struct net_info */
   spinlock_t net_list_sync;    /* to protect scan status (and others if needed) */
   spinlock_t eq_lock;    /* for event queue synchronization */
   spinlock_t cfgdrv_lock;    /* to protect scan status (and others if needed) */
   struct completion act_frm_scan;
   struct completion iface_disable;
   struct completion wait_next_af;
   struct mutex usr_sync;    /* maily for up/down synchronization */
   struct mutex if_sync;    /* maily for iface op synchronization */
   struct mutex scan_complete;    /* serialize scan_complete call */
   struct wl_scan_results *bss_list;
   struct wl_scan_results *scan_results;
 
   /* scan request object for internal purpose */
   struct wl_scan_req *scan_req_int;
   /* information element object for internal purpose */
#if defined(STATIC_WL_PRIV_STRUCT)
   struct wl_ie *ie;
#else
   struct wl_ie ie;
#endif
 
   /* association information container */
#if defined(STATIC_WL_PRIV_STRUCT)
   struct wl_connect_info *conn_info;
#else
   struct wl_connect_info conn_info;
#endif
#ifdef DEBUGFS_CFG80211
   struct dentry        *debugfs;
#endif /* DEBUGFS_CFG80211 */
   struct wl_pmk_list *pmk_list;    /* wpa2 pmk list */
   tsk_ctl_t event_tsk;          /* task of main event handler thread */
   dhd_pub_t *pub;
   u32 iface_cnt;
   u32 channel;        /* current channel */
   u32 af_sent_channel;    /* channel action frame is sent */
   /* next af subtype to cancel the remained dwell time in rx process */
   u8 next_af_subtype;
#ifdef WL_CFG80211_SYNC_GON
   ulong af_tx_sent_jiffies;
#endif /* WL_CFG80211_SYNC_GON */
   struct escan_info escan_info;   /* escan information */
   bool active_scan;    /* current scan mode */
   bool ibss_starter;    /* indicates this sta is ibss starter */
   bool link_up;        /* link/connection up flag */
 
   /* indicate whether chip to support power save mode */
   bool pwr_save;
   bool roam_on;        /* on/off switch for self-roaming */
   bool scan_tried;    /* indicates if first scan attempted */
#if defined(BCMSDIO) || defined(BCMDBUS)
   bool wlfc_on;
#endif 
   bool vsdb_mode;
#define WL_ROAM_OFF_ON_CONCURRENT     0x0001
#define WL_ROAM_REVERT_STATUS        0x0002
   u32 roam_flags;
   u8 *ioctl_buf;        /* ioctl buffer */
   struct mutex ioctl_buf_sync;
   u8 *escan_ioctl_buf;
   u8 *extra_buf;    /* maily to grab assoc information */
   struct dentry *debugfsdir;
   struct rfkill *rfkill;
   bool rf_blocked;
   struct ieee80211_channel remain_on_chan;
   enum nl80211_channel_type remain_on_chan_type;
   u64 send_action_id;
   u64 last_roc_id;
   wait_queue_head_t netif_change_event;
   wl_if_event_info if_event_info;
   struct completion send_af_done;
   struct afx_hdl *afx_hdl;
   struct p2p_info *p2p;
   bool p2p_supported;
   void *btcoex_info;
   timer_list_compat_t scan_timeout;   /* Timer for catch scan event timeout */
#if defined(P2P_IE_MISSING_FIX)
   bool p2p_prb_noti;
#endif
   s32(*state_notifier) (struct bcm_cfg80211 *cfg,
       struct net_info *_net_info, enum wl_status state, bool set);
   unsigned long interrested_state;
   wlc_ssid_t hostapd_ssid;
#ifdef WL11U
   bool wl11u;
#endif /* WL11U */
   bool sched_scan_running;    /* scheduled scan req status */
   struct cfg80211_sched_scan_request *sched_scan_req;    /* scheduled scan req */
   bool scan_suppressed;
   timer_list_compat_t scan_supp_timer;
   struct work_struct wlan_work;
   struct mutex event_sync;    /* maily for up/down synchronization */
   bool disable_roam_event;
   struct delayed_work pm_enable_work;
   struct workqueue_struct *event_workq;   /* workqueue for event */
   struct work_struct event_work;        /* work item for event */
   struct mutex pm_sync;    /* mainly for pm work synchronization */
 
   vndr_ie_setbuf_t *ibss_vsie;    /* keep the VSIE for IBSS */
   int ibss_vsie_len;
#ifdef WL_RELMCAST
   u32 rmc_event_pid;
   u32 rmc_event_seq;
#endif /* WL_RELMCAST */
#ifdef WLAIBSS_MCHAN
   struct ether_addr ibss_if_addr;
   bcm_struct_cfgdev *ibss_cfgdev; /* For AIBSS */
#endif /* WLAIBSS_MCHAN */
   bool bss_pending_op;        /* indicate where there is a pending IF operation */
#ifdef WLFBT
   uint8 fbt_key[FBT_KEYLEN];
#endif
   int roam_offload;
#ifdef WL_CFG80211_P2P_DEV_IF
   bool down_disc_if;
#endif /* WL_CFG80211_P2P_DEV_IF */
#ifdef P2PLISTEN_AP_SAMECHN
   bool p2p_resp_apchn_status;
#endif /* P2PLISTEN_AP_SAMECHN */
   struct wl_wsec_key wep_key;
#ifdef WLTDLS
   u8 *tdls_mgmt_frame;
   u32 tdls_mgmt_frame_len;
   s32 tdls_mgmt_freq;
#endif /* WLTDLS */
   bool need_wait_afrx;
#ifdef QOS_MAP_SET
   uint8     *up_table;    /* user priority table, size is UP_TABLE_MAX */
#endif /* QOS_MAP_SET */
   struct ether_addr last_roamed_addr;
   bool rcc_enabled;    /* flag for Roam channel cache feature */
#if defined(DHD_ENABLE_BIGDATA_LOGGING)
   char bss_info[GET_BSS_INFO_LEN];
   wl_event_msg_t event_auth_assoc;
   u32 assoc_reject_status;
   u32 roam_count;
#endif /* DHD_ENABLE_BIGDATA_LOGGING */
   u16 ap_oper_channel;
#if defined(SUPPORT_RANDOM_MAC_SCAN)
   bool random_mac_enabled;
#endif /* SUPPORT_RANDOM_MAC_SCAN */
#ifdef DHD_LOSSLESS_ROAMING
   timer_list_compat_t roam_timeout;   /* Timer for catch roam timeout */
#endif
   uint16 escan_sync_id_cntr;
#ifdef WLTDLS
   uint8 tdls_supported;
   struct mutex tdls_sync;    /* protect tdls config operations */
#endif /* WLTDLS */
#ifdef MFP
   uint8 *bip_pos;
   int mfp_mode;
#endif /* MFP */
#ifdef SUPPORT_AP_RADIO_PWRSAVE
   ap_rps_info_t ap_rps_info;
#endif /* SUPPORT_AP_RADIO_PWRSAVE */
   osl_t *osh;
#ifdef WBTEXT
   struct list_head wbtext_bssid_list;
#endif /* WBTEXT */
   struct list_head vndr_oui_list;
 
#ifdef STAT_REPORT
   void *stat_report_info;
#endif
   wl_wlc_version_t wlc_ver;
   bool scan_params_v2;
#ifdef WLMESH_CFG80211
   char sae_password[SAE_MAX_PASSWD_LEN];
   uint sae_password_len;
#endif /* WLMESH_CFG80211 */
#if defined(RSSIAVG)
   wl_rssi_cache_ctrl_t g_rssi_cache_ctrl;
   wl_rssi_cache_ctrl_t g_connected_rssi_cache_ctrl;
#endif
#if defined(BSSCACHE)
   wl_bss_cache_ctrl_t g_bss_cache_ctrl;
#endif
   int p2p_disconnected; // terence 20130703: Fix for wrong group_capab (timing issue)
   struct ether_addr disconnected_bssid;
   int autochannel;
   int best_2g_ch;
   int best_5g_ch;
   uint handshaking;
   int btc_mode;
   bool wps_done;
   wait_queue_head_t wps_done_event;
   struct mutex in4way_sync;
   ulong disconnected_jiffies;
};
 
#ifdef WL_SAE
typedef struct wl_sae_key_info {
   uint8 peer_mac[ETHER_ADDR_LEN];
   uint16 pmk_len;
   uint16 pmkid_len;
   const uint8 *pmk;
   const uint8 *pmkid;
} wl_sae_key_info_t;
#endif /* WL_SAE */
 
#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == \
   4 && __GNUC_MINOR__ >= 6))
#define GCC_DIAGNOSTIC_PUSH() \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
#define GCC_DIAGNOSTIC_POP() \
_Pragma("GCC diagnostic pop")
#else
#define GCC_DIAGNOSTIC_PUSH()
#define GCC_DIAGNOSTIC_POP()
#endif /* STRICT_GCC_WARNINGS */
 
#define BCM_LIST_FOR_EACH_ENTRY_SAFE(pos, next, head, member) \
   list_for_each_entry_safe((pos), (next), (head), member)
extern int ioctl_version;
 
static inline struct wl_bss_info *next_bss(struct wl_scan_results *list, struct wl_bss_info *bss)
{
   return bss = bss ?
       (struct wl_bss_info *)((uintptr) bss + dtoh32(bss->length)) : list->bss_info;
}
 
static inline void
wl_probe_wdev_all(struct bcm_cfg80211 *cfg)
{
   struct net_info *_net_info, *next;
   unsigned long int flags;
   int idx = 0;
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next,
       &cfg->net_list, list) {
       WL_ERR(("%s: net_list[%d] bssidx: %d, "
           "ndev: %p, wdev: %p \n", __FUNCTION__,
           idx++, _net_info->bssidx,
           _net_info->ndev, _net_info->wdev));
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return;
}
 
static inline struct net_info *
wl_get_netinfo_by_bssidx(struct bcm_cfg80211 *cfg, s32 bssidx)
{
   struct net_info *_net_info, *next, *info = NULL;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if ((bssidx >= 0) && (_net_info->bssidx == bssidx)) {
           info = _net_info;
           break;
       }
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return info;
}
 
static inline void
wl_dealloc_netinfo_by_wdev(struct bcm_cfg80211 *cfg, struct wireless_dev *wdev)
{
   struct net_info *_net_info, *next;
   unsigned long int flags;
 
#ifdef DHD_IFDEBUG
   WL_ERR(("dealloc_netinfo enter wdev=%p \n", wdev));
#endif
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (wdev && (_net_info->wdev == wdev)) {
           wl_cfgbss_t *bss = &_net_info->bss;
 
           kfree(bss->wpa_ie);
           bss->wpa_ie = NULL;
           kfree(bss->rsn_ie);
           bss->rsn_ie = NULL;
           kfree(bss->wps_ie);
           bss->wps_ie = NULL;
           list_del(&_net_info->list);
           cfg->iface_cnt--;
           kfree(_net_info);
       }
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
#ifdef DHD_IFDEBUG
   WL_ERR(("dealloc_netinfo exit iface_cnt=%d \n", cfg->iface_cnt));
#endif
}
 
static inline s32
wl_alloc_netinfo(struct bcm_cfg80211 *cfg, struct net_device *ndev,
   struct wireless_dev * wdev, s32 mode, bool pm_block, u8 bssidx)
{
   struct net_info *_net_info;
   s32 err = 0;
   unsigned long int flags;
#ifdef DHD_IFDEBUG
   WL_ERR(("alloc_netinfo enter bssidx=%d wdev=%p ndev=%p\n", bssidx, wdev, ndev));
#endif
   /* Check whether there is any duplicate entry for the
    *  same bssidx *
    */
   if ((_net_info = wl_get_netinfo_by_bssidx(cfg, bssidx))) {
       /* We have a duplicate entry for the same bssidx
        * already present which shouldn't have been the case.
        * Attempt recovery.
        */
       WL_ERR(("Duplicate entry for bssidx=%d present\n", bssidx));
       wl_probe_wdev_all(cfg);
#ifdef DHD_DEBUG
       ASSERT(0);
#endif /* DHD_DEBUG */
       WL_ERR(("Removing the Dup entry for bssidx=%d \n", bssidx));
       wl_dealloc_netinfo_by_wdev(cfg, _net_info->wdev);
   }
   if (cfg->iface_cnt == IFACE_MAX_CNT)
       return -ENOMEM;
   _net_info = kzalloc(sizeof(struct net_info), GFP_KERNEL);
   if (!_net_info)
       err = -ENOMEM;
   else {
       _net_info->mode = mode;
       _net_info->ndev = ndev;
       _net_info->wdev = wdev;
       _net_info->pm_restore = 0;
       _net_info->pm = 0;
       _net_info->pm_block = pm_block;
       _net_info->roam_off = WL_INVALID;
       _net_info->bssidx = bssidx;
       spin_lock_irqsave(&cfg->net_list_sync, flags);
       cfg->iface_cnt++;
       list_add(&_net_info->list, &cfg->net_list);
       spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   }
#ifdef DHD_IFDEBUG
   WL_ERR(("alloc_netinfo exit iface_cnt=%d \n", cfg->iface_cnt));
#endif
   return err;
}
 
static inline void
wl_delete_all_netinfo(struct bcm_cfg80211 *cfg)
{
   struct net_info *_net_info, *next;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       wl_cfgbss_t *bss = &_net_info->bss;
 
       kfree(bss->wpa_ie);
       bss->wpa_ie = NULL;
       kfree(bss->rsn_ie);
       bss->rsn_ie = NULL;
       kfree(bss->wps_ie);
       bss->wps_ie = NULL;
       list_del(&_net_info->list);
       if (_net_info->wdev)
           kfree(_net_info->wdev);
       kfree(_net_info);
   }
   cfg->iface_cnt = 0;
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
}
static inline u32
wl_get_status_all(struct bcm_cfg80211 *cfg, s32 status)
 
{
   struct net_info *_net_info, *next;
   u32 cnt = 0;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (_net_info->ndev &&
           test_bit(status, &_net_info->sme_state))
           cnt++;
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return cnt;
}
static inline void
wl_set_status_all(struct bcm_cfg80211 *cfg, s32 status, u32 op)
{
   struct net_info *_net_info, *next;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       switch (op) {
           case 1:
               break; /* set all status is not allowed */
           case 2:
               /*
                * Release the spinlock before calling notifier. Else there
                * will be nested calls
                */
               spin_unlock_irqrestore(&cfg->net_list_sync, flags);
               clear_bit(status, &_net_info->sme_state);
               if (cfg->state_notifier &&
                   test_bit(status, &(cfg->interrested_state)))
                   cfg->state_notifier(cfg, _net_info, status, false);
               return;
           case 4:
               break; /* change all status is not allowed */
           default:
               break; /* unknown operation */
       }
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
}
static inline void
wl_set_status_by_netdev(struct bcm_cfg80211 *cfg, s32 status,
   struct net_device *ndev, u32 op)
{
 
   struct net_info *_net_info, *next;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (ndev && (_net_info->ndev == ndev)) {
           switch (op) {
               case 1:
                   /*
                    * Release the spinlock before calling notifier. Else there
                    * will be nested calls
                    */
                   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
                   set_bit(status, &_net_info->sme_state);
                   if (cfg->state_notifier &&
                       test_bit(status, &(cfg->interrested_state)))
                       cfg->state_notifier(cfg, _net_info, status, true);
                   return;
               case 2:
                   /*
                    * Release the spinlock before calling notifier. Else there
                    * will be nested calls
                    */
                   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
                   clear_bit(status, &_net_info->sme_state);
                   if (cfg->state_notifier &&
                       test_bit(status, &(cfg->interrested_state)))
                       cfg->state_notifier(cfg, _net_info, status, false);
                   return;
               case 4:
                   change_bit(status, &_net_info->sme_state);
                   break;
           }
       }
 
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
 
}
 
static inline wl_cfgbss_t *
wl_get_cfgbss_by_wdev(struct bcm_cfg80211 *cfg,
   struct wireless_dev *wdev)
{
   struct net_info *_net_info, *next;
   wl_cfgbss_t *bss = NULL;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (wdev && (_net_info->wdev == wdev)) {
           bss = &_net_info->bss;
           break;
       }
   }
   GCC_DIAGNOSTIC_POP();
 
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return bss;
}
 
static inline u32
wl_get_status_by_netdev(struct bcm_cfg80211 *cfg, s32 status,
   struct net_device *ndev)
{
   struct net_info *_net_info, *next;
   u32 stat = 0;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (ndev && (_net_info->ndev == ndev)) {
           stat = test_bit(status, &_net_info->sme_state);
           break;
       }
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return stat;
}
 
static inline s32
wl_get_mode_by_netdev(struct bcm_cfg80211 *cfg, struct net_device *ndev)
{
   struct net_info *_net_info, *next;
   s32 mode = -1;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (ndev && (_net_info->ndev == ndev)) {
           mode = _net_info->mode;
           break;
       }
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return mode;
}
 
static inline void
wl_set_mode_by_netdev(struct bcm_cfg80211 *cfg, struct net_device *ndev,
   s32 mode)
{
   struct net_info *_net_info, *next;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (ndev && (_net_info->ndev == ndev))
           _net_info->mode = mode;
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
}
 
static inline s32
wl_get_bssidx_by_wdev(struct bcm_cfg80211 *cfg, struct wireless_dev *wdev)
{
   struct net_info *_net_info, *next;
   s32 bssidx = -1;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (_net_info->wdev && (_net_info->wdev == wdev)) {
           bssidx = _net_info->bssidx;
           break;
       }
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return bssidx;
}
 
static inline struct wireless_dev *
wl_get_wdev_by_bssidx(struct bcm_cfg80211 *cfg, s32 bssidx)
{
   struct net_info *_net_info, *next;
   struct wireless_dev *wdev = NULL;
   unsigned long int flags;
 
   if (bssidx < 0)
       return NULL;
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (_net_info->bssidx == bssidx) {
           wdev = _net_info->wdev;
           break;
       }
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return wdev;
}
 
static inline struct wl_profile *
wl_get_profile_by_netdev(struct bcm_cfg80211 *cfg, struct net_device *ndev)
{
   struct net_info *_net_info, *next;
   struct wl_profile *prof = NULL;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (ndev && (_net_info->ndev == ndev)) {
           prof = &_net_info->profile;
           break;
       }
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return prof;
}
static inline struct net_info *
wl_get_netinfo_by_netdev(struct bcm_cfg80211 *cfg, struct net_device *ndev)
{
   struct net_info *_net_info, *next, *info = NULL;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (ndev && (_net_info->ndev == ndev)) {
           info = _net_info;
           break;
       }
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return info;
}
 
static inline struct net_info *
wl_get_netinfo_by_wdev(struct bcm_cfg80211 *cfg, struct wireless_dev *wdev)
{
   struct net_info *_net_info, *next, *info = NULL;
   unsigned long int flags;
 
   spin_lock_irqsave(&cfg->net_list_sync, flags);
   GCC_DIAGNOSTIC_PUSH();
   BCM_LIST_FOR_EACH_ENTRY_SAFE(_net_info, next, &cfg->net_list, list) {
       if (wdev && (_net_info->wdev == wdev)) {
           info = _net_info;
           break;
       }
   }
   GCC_DIAGNOSTIC_POP();
   spin_unlock_irqrestore(&cfg->net_list_sync, flags);
   return info;
}
 
#define is_p2p_group_iface(wdev) (((wdev->iftype == NL80211_IFTYPE_P2P_GO) || \
       (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) ? 1 : 0)
#define bcmcfg_to_wiphy(cfg) (cfg->wdev->wiphy)
#define bcmcfg_to_prmry_ndev(cfg) (cfg->wdev->netdev)
#define bcmcfg_to_prmry_wdev(cfg) (cfg->wdev)
#define bcmcfg_to_p2p_wdev(cfg) (cfg->p2p_wdev)
#define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
#define ndev_to_wdev(ndev) (ndev->ieee80211_ptr)
#define wdev_to_ndev(wdev) (wdev->netdev)
 
#if defined(WL_ENABLE_P2P_IF)
#define ndev_to_wlc_ndev(ndev, cfg)    ((ndev == cfg->p2p_net) ? \
   bcmcfg_to_prmry_ndev(cfg) : ndev)
#else
#define ndev_to_wlc_ndev(ndev, cfg)    (ndev)
#endif /* WL_ENABLE_P2P_IF */
 
#define wdev_to_wlc_ndev(wdev, cfg)    \
   (wdev_to_ndev(wdev) ? \
   wdev_to_ndev(wdev) : bcmcfg_to_prmry_ndev(cfg))
#if defined(WL_CFG80211_P2P_DEV_IF)
#define cfgdev_to_wlc_ndev(cfgdev, cfg)    wdev_to_wlc_ndev(cfgdev, cfg)
#define bcmcfg_to_prmry_cfgdev(cfgdev, cfg) bcmcfg_to_prmry_wdev(cfg)
#elif defined(WL_ENABLE_P2P_IF)
#define cfgdev_to_wlc_ndev(cfgdev, cfg)    ndev_to_wlc_ndev(cfgdev, cfg)
#define bcmcfg_to_prmry_cfgdev(cfgdev, cfg) bcmcfg_to_prmry_ndev(cfg)
#else
#define cfgdev_to_wlc_ndev(cfgdev, cfg)    (cfgdev)
#define bcmcfg_to_prmry_cfgdev(cfgdev, cfg) (cfgdev)
#endif /* WL_CFG80211_P2P_DEV_IF */
 
#if defined(WL_CFG80211_P2P_DEV_IF)
#define cfgdev_to_wdev(cfgdev)    (cfgdev)
#define ndev_to_cfgdev(ndev)    ndev_to_wdev(ndev)
#define cfgdev_to_ndev(cfgdev)    (cfgdev ? (cfgdev->netdev) : NULL)
#define wdev_to_cfgdev(cfgdev)    (cfgdev)
#define discover_cfgdev(cfgdev, cfg) (cfgdev->iftype == NL80211_IFTYPE_P2P_DEVICE)
#else
#define cfgdev_to_wdev(cfgdev)    (cfgdev->ieee80211_ptr)
#define wdev_to_cfgdev(cfgdev)    cfgdev ? (cfgdev->netdev) : NULL
#define ndev_to_cfgdev(ndev)    (ndev)
#define cfgdev_to_ndev(cfgdev)    (cfgdev)
#define discover_cfgdev(cfgdev, cfg) (cfgdev == cfg->p2p_net)
#endif /* WL_CFG80211_P2P_DEV_IF */
 
#if defined(WL_CFG80211_P2P_DEV_IF)
#define scan_req_match(cfg)    (((cfg) && (cfg->scan_request) && \
   (cfg->scan_request->wdev == cfg->p2p_wdev)) ? true : false)
#elif defined(WL_ENABLE_P2P_IF)
#define scan_req_match(cfg)    (((cfg) && (cfg->scan_request) && \
   (cfg->scan_request->dev == cfg->p2p_net)) ? true : false)
#else
#define scan_req_match(cfg)    (((cfg) && p2p_is_on(cfg) && p2p_scan(cfg)) ? \
   true : false)
#endif /* WL_CFG80211_P2P_DEV_IF */
 
#define    PRINT_WDEV_INFO(cfgdev)    \
   { \
       struct wireless_dev *wdev = cfgdev_to_wdev(cfgdev); \
       struct net_device *netdev = wdev ? wdev->netdev : NULL; \
       WL_DBG(("wdev_ptr:%p ndev_ptr:%p ifname:%s iftype:%d\n", wdev, netdev,    \
           netdev ? netdev->name : "NULL (non-ndev device)",    \
           wdev ? wdev->iftype : 0xff)); \
   }
 
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
#define scan_req_iftype(req) (req->dev->ieee80211_ptr->iftype)
#else
#define scan_req_iftype(req) (req->wdev->iftype)
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0) */
 
#define wl_to_sr(w) (w->scan_req_int)
#if defined(STATIC_WL_PRIV_STRUCT)
#define wl_to_ie(w) (w->ie)
#define wl_to_conn(w) (w->conn_info)
#else
#define wl_to_ie(w) (&w->ie)
#define wl_to_conn(w) (&w->conn_info)
#endif
#define wiphy_from_scan(w) (w->escan_info.wiphy)
#define wl_get_drv_status_all(cfg, stat) \
   (wl_get_status_all(cfg, WL_STATUS_ ## stat))
#define wl_get_drv_status(cfg, stat, ndev)  \
   (wl_get_status_by_netdev(cfg, WL_STATUS_ ## stat, ndev))
#define wl_set_drv_status(cfg, stat, ndev)  \
   (wl_set_status_by_netdev(cfg, WL_STATUS_ ## stat, ndev, 1))
#define wl_clr_drv_status(cfg, stat, ndev)  \
   (wl_set_status_by_netdev(cfg, WL_STATUS_ ## stat, ndev, 2))
#define wl_clr_drv_status_all(cfg, stat)  \
   (wl_set_status_all(cfg, WL_STATUS_ ## stat, 2))
#define wl_chg_drv_status(cfg, stat, ndev)  \
   (wl_set_status_by_netdev(cfg, WL_STATUS_ ## stat, ndev, 4))
 
#define for_each_bss(list, bss, __i)    \
   for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
 
#define for_each_ndev(cfg, iter, next) \
   list_for_each_entry_safe(iter, next, &cfg->net_list, list)
 
/* In case of WPS from wpa_supplicant, pairwise siute and group suite is 0.
 * In addtion to that, wpa_version is WPA_VERSION_1
 */
#define is_wps_conn(_sme) \
   ((wl_cfgp2p_find_wpsie((u8 *)_sme->ie, _sme->ie_len) != NULL) && \
    (!_sme->crypto.n_ciphers_pairwise) && \
    (!_sme->crypto.cipher_group))
 
#ifdef WLFBT
#if defined(WLAN_AKM_SUITE_FT_8021X) && defined(WLAN_AKM_SUITE_FT_PSK)
#define IS_AKM_SUITE_FT(sec) (sec->wpa_auth == WLAN_AKM_SUITE_FT_8021X || \
       sec->wpa_auth == WLAN_AKM_SUITE_FT_PSK)
#elif defined(WLAN_AKM_SUITE_FT_8021X)
#define IS_AKM_SUITE_FT(sec) (sec->wpa_auth == WLAN_AKM_SUITE_FT_8021X)
#elif defined(WLAN_AKM_SUITE_FT_PSK)
#define IS_AKM_SUITE_FT(sec) (sec->wpa_auth == WLAN_AKM_SUITE_FT_PSK)
#else
#define IS_AKM_SUITE_FT(sec) ({BCM_REFERENCE(sec); FALSE;})
#endif /* WLAN_AKM_SUITE_FT_8021X && WLAN_AKM_SUITE_FT_PSK */
#else
#define IS_AKM_SUITE_FT(sec) ({BCM_REFERENCE(sec); FALSE;})
#endif /* WLFBT */
 
#define IS_AKM_SUITE_CCKM(sec) ({BCM_REFERENCE(sec); FALSE;})
 
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0))
#define STA_INFO_BIT(info) (1ul << NL80211_STA_ ## info)
#ifdef strnicmp
#undef strnicmp
#endif /* strnicmp */
#define strnicmp(str1, str2, len) strncasecmp((str1), (str2), (len))
#else
#define STA_INFO_BIT(info) (STATION_ ## info)
#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) */
 
extern s32 wl_cfg80211_attach(struct net_device *ndev, void *context);
extern void wl_cfg80211_detach(struct bcm_cfg80211 *cfg);
 
extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
            void *data);
void wl_cfg80211_set_parent_dev(void *dev);
struct device *wl_cfg80211_get_parent_dev(void);
 
/* clear IEs */
extern s32 wl_cfg80211_clear_mgmt_vndr_ies(struct bcm_cfg80211 *cfg);
extern s32 wl_cfg80211_clear_per_bss_ies(struct bcm_cfg80211 *cfg, s32 bssidx);
 
extern s32 wl_cfg80211_up(struct net_device *net);
extern s32 wl_cfg80211_down(struct net_device *net);
extern s32 wl_cfg80211_notify_ifadd(struct net_device * dev, int ifidx, char *name, uint8 *mac,
   uint8 bssidx);
extern s32 wl_cfg80211_notify_ifdel(struct net_device * dev, int ifidx, char *name, uint8 *mac,
   uint8 bssidx);
extern s32 wl_cfg80211_notify_ifchange(struct net_device * dev, int ifidx, char *name, uint8 *mac,
   uint8 bssidx);
extern struct net_device* wl_cfg80211_allocate_if(struct bcm_cfg80211 *cfg, int ifidx,
   const char *name, uint8 *mac, uint8 bssidx, const char *dngl_name);
extern int wl_cfg80211_register_if(struct bcm_cfg80211 *cfg,
   int ifidx, struct net_device* ndev, bool rtnl_lock_reqd);
extern int wl_cfg80211_remove_if(struct bcm_cfg80211 *cfg,
   int ifidx, struct net_device* ndev, bool rtnl_lock_reqd);
extern int wl_cfg80211_scan_stop(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev);
extern void wl_cfg80211_scan_abort(struct bcm_cfg80211 *cfg);
extern bool wl_cfg80211_is_concurrent_mode(struct net_device * dev);
extern void* wl_cfg80211_get_dhdp(struct net_device * dev);
extern bool wl_cfg80211_is_p2p_active(struct net_device * dev);
extern bool wl_cfg80211_is_roam_offload(struct net_device * dev);
extern bool wl_cfg80211_is_event_from_connected_bssid(struct net_device * dev,
       const wl_event_msg_t *e, int ifidx);
extern void wl_cfg80211_dbg_level(u32 level);
extern s32 wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr);
extern s32 wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len);
extern s32 wl_cfg80211_get_p2p_noa(struct net_device *net, char* buf, int len);
extern s32 wl_cfg80211_set_wps_p2p_ie(struct net_device *net, char *buf, int len,
   enum wl_management_type type);
extern s32 wl_cfg80211_set_p2p_ps(struct net_device *net, char* buf, int len);
extern s32 wl_cfg80211_set_p2p_ecsa(struct net_device *net, char* buf, int len);
extern s32 wl_cfg80211_increase_p2p_bw(struct net_device *net, char* buf, int len);
#ifdef WLMESH_CFG80211
extern s32 wl_cfg80211_set_sae_password(struct net_device *net, char* buf, int len);
#endif
#ifdef WL11ULB
extern s32 wl_cfg80211_set_ulb_mode(struct net_device *dev, int mode);
extern s32 wl_cfg80211_set_ulb_bw(struct net_device *dev,
   u32 ulb_bw,  char *ifname);
#endif /* WL11ULB */
#ifdef P2PLISTEN_AP_SAMECHN
extern s32 wl_cfg80211_set_p2p_resp_ap_chn(struct net_device *net, s32 enable);
#endif /* P2PLISTEN_AP_SAMECHN */
 
/* btcoex functions */
void* wl_cfg80211_btcoex_init(struct net_device *ndev);
void wl_cfg80211_btcoex_deinit(void);
 
extern chanspec_t wl_chspec_from_legacy(chanspec_t legacy_chspec);
extern chanspec_t wl_chspec_driver_to_host(chanspec_t chanspec);
 
#ifdef WL_SUPPORT_AUTO_CHANNEL
#define CHANSPEC_BUF_SIZE    1024
#define CHAN_SEL_IOCTL_DELAY    300
#define CHAN_SEL_RETRY_COUNT    15
#define CHANNEL_IS_RADAR(channel)    (((channel & WL_CHAN_RADAR) || \
   (channel & WL_CHAN_PASSIVE)) ? true : false)
#define CHANNEL_IS_2G(channel)    (((channel >= 1) && (channel <= 14)) ? \
   true : false)
#define CHANNEL_IS_5G(channel)    (((channel >= 36) && (channel <= 165)) ? \
   true : false)
extern s32 wl_cfg80211_get_best_channels(struct net_device *dev, char* command,
   int total_len);
#endif /* WL_SUPPORT_AUTO_CHANNEL */
extern int wl_cfg80211_ether_atoe(const char *a, struct ether_addr *n);
extern int wl_cfg80211_hang(struct net_device *dev, u16 reason);
extern s32 wl_mode_to_nl80211_iftype(s32 mode);
int wl_cfg80211_do_driver_init(struct net_device *net);
void wl_cfg80211_enable_trace(u32 level);
extern s32 wl_update_wiphybands(struct bcm_cfg80211 *cfg, bool notify);
extern s32 wl_cfg80211_if_is_group_owner(void);
extern chanspec_t wl_chspec_host_to_driver(chanspec_t chanspec);
extern chanspec_t wl_ch_host_to_driver(struct bcm_cfg80211 *cfg, s32 bssidx, u16 channel);
extern s32 wl_set_tx_power(struct net_device *dev,
   enum nl80211_tx_power_setting type, s32 dbm);
extern s32 wl_get_tx_power(struct net_device *dev, s32 *dbm);
extern s32 wl_add_remove_eventmsg(struct net_device *ndev, u16 event, bool add);
extern void wl_stop_wait_next_action_frame(struct bcm_cfg80211 *cfg, struct net_device *ndev,
   u8 bsscfgidx);
extern void wl_cfg80211_add_to_eventbuffer(wl_eventmsg_buf_t *ev, u16 event, bool set);
extern s32 wl_cfg80211_apply_eventbuffer(struct net_device *ndev,
   struct bcm_cfg80211 *cfg, wl_eventmsg_buf_t *ev);
extern void get_primary_mac(struct bcm_cfg80211 *cfg, struct ether_addr *mac);
extern void wl_cfg80211_update_power_mode(struct net_device *dev);
extern void wl_cfg80211_set_passive_scan(struct net_device *dev, char *command);
extern void wl_terminate_event_handler(struct net_device *dev);
#if defined(DHD_ENABLE_BIGDATA_LOGGING)
extern s32 wl_cfg80211_get_bss_info(struct net_device *dev, char* cmd, int total_len);
extern s32 wl_cfg80211_get_connect_failed_status(struct net_device *dev, char* cmd, int total_len);
#endif /* DHD_ENABLE_BIGDATA_LOGGING */
extern struct bcm_cfg80211 *wl_get_cfg(struct net_device *ndev);
extern s32 wl_cfg80211_set_if_band(struct net_device *ndev, int band);
 
#define SCAN_BUF_CNT    2
#define SCAN_BUF_NEXT    1
#define WL_SCANTYPE_LEGACY    0x1
#define WL_SCANTYPE_P2P        0x2
#define wl_escan_set_sync_id(a, b) ((a) = htod16((b)->escan_sync_id_cntr++))
#define wl_escan_set_type(a, b)
#define wl_escan_get_buf(a, b) ((wl_scan_results_t *) (a)->escan_info.escan_buf)
#define wl_escan_check_sync_id(a, b, c) 0
#define wl_escan_print_sync_id(a, b, c)
#define wl_escan_increment_sync_id(a, b)
#define wl_escan_init_sync_id(a)
extern void wl_cfg80211_ibss_vsie_set_buffer(struct net_device *dev, vndr_ie_setbuf_t *ibss_vsie,
   int ibss_vsie_len);
extern s32 wl_cfg80211_ibss_vsie_delete(struct net_device *dev);
#ifdef WL_RELMCAST
extern void wl_cfg80211_set_rmc_pid(struct net_device *dev, int pid);
#endif /* WL_RELMCAST */
extern int wl_cfg80211_set_mgmt_vndr_ies(struct bcm_cfg80211 *cfg,
   bcm_struct_cfgdev *cfgdev, s32 bssidx, s32 pktflag,
   const u8 *vndr_ie, u32 vndr_ie_len);
 
#ifdef WLFBT
extern int wl_cfg80211_get_fbt_key(struct net_device *dev, uint8 *key, int total_len);
#endif
 
/* Action frame specific functions */
extern u8 wl_get_action_category(void *frame, u32 frame_len);
extern int wl_get_public_action(void *frame, u32 frame_len, u8 *ret_action);
 
#ifdef WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST
struct net_device *wl_cfg80211_get_remain_on_channel_ndev(struct bcm_cfg80211 *cfg);
#endif /* WL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST */
 
#ifdef WL_SUPPORT_ACS
#define ACS_MSRMNT_DELAY 1000 /* dump_obss delay in ms */
#define IOCTL_RETRY_COUNT 5
#define CHAN_NOISE_DUMMY -80
#define OBSS_TOKEN_IDX 15
#define IBSS_TOKEN_IDX 15
#define TX_TOKEN_IDX 14
#define CTG_TOKEN_IDX 13
#define PKT_TOKEN_IDX 15
#define IDLE_TOKEN_IDX 12
#endif /* WL_SUPPORT_ACS */
 
 
extern int wl_cfg80211_get_ioctl_version(void);
extern int wl_cfg80211_enable_roam_offload(struct net_device *dev, int enable);
extern s32 wl_cfg80211_dfs_ap_move(struct net_device *ndev, char *data,
       char *command, int total_len);
#ifdef WBTEXT
extern s32 wl_cfg80211_wbtext_set_default(struct net_device *ndev);
extern s32 wl_cfg80211_wbtext_config(struct net_device *ndev, char *data,
       char *command, int total_len);
extern int wl_cfg80211_wbtext_weight_config(struct net_device *ndev, char *data,
       char *command, int total_len);
extern int wl_cfg80211_wbtext_table_config(struct net_device *ndev, char *data,
       char *command, int total_len);
extern s32 wl_cfg80211_wbtext_delta_config(struct net_device *ndev, char *data,
       char *command, int total_len);
#endif /* WBTEXT */
extern s32 wl_cfg80211_get_chanspecs_2g(struct net_device *ndev,
       void *buf, s32 buflen);
extern s32 wl_cfg80211_get_chanspecs_5g(struct net_device *ndev,
       void *buf, s32 buflen);
 
extern s32 wl_cfg80211_bss_up(struct bcm_cfg80211 *cfg,
   struct net_device *ndev, s32 bsscfg_idx, s32 up);
extern bool wl_cfg80211_bss_isup(struct net_device *ndev, int bsscfg_idx);
 
struct net_device *wl_cfg80211_post_ifcreate(struct net_device *ndev,
   wl_if_event_info *event, u8 *addr, const char *name, bool rtnl_lock_reqd);
extern s32 wl_cfg80211_post_ifdel(struct net_device *ndev, bool rtnl_lock_reqd);
#if defined(WL_VIRTUAL_APSTA)
extern int wl_cfg80211_interface_create(struct net_device *dev, char *name);
extern int wl_cfg80211_interface_delete(struct net_device *dev, char *name);
#if defined(PKT_FILTER_SUPPORT) && defined(APSTA_BLOCK_ARP_DURING_DHCP)
extern void wl_cfg80211_block_arp(struct net_device *dev, int enable);
#endif /* PKT_FILTER_SUPPORT && APSTA_BLOCK_ARP_DURING_DHCP */
#endif /* defined (WL_VIRTUAL_APSTA) */
 
 
#ifdef WL_CFG80211_P2P_DEV_IF
extern void wl_cfg80211_del_p2p_wdev(struct net_device *dev);
#endif /* WL_CFG80211_P2P_DEV_IF */
#if defined(WL_SUPPORT_AUTO_CHANNEL)
extern int wl_cfg80211_set_spect(struct net_device *dev, int spect);
extern int wl_cfg80211_get_sta_channel(struct net_device *dev);
#endif /* WL_SUPPORT_AUTO_CHANNEL */
 
#ifdef P2P_LISTEN_OFFLOADING
extern s32 wl_cfg80211_p2plo_listen_start(struct net_device *dev, u8 *buf, int len);
extern s32 wl_cfg80211_p2plo_listen_stop(struct net_device *dev);
#endif /* P2P_LISTEN_OFFLOADING */
 
#define RETURN_EIO_IF_NOT_UP(wlpriv)                        \
do {                                    \
   struct net_device *checkSysUpNDev = bcmcfg_to_prmry_ndev(wlpriv);           \
   if (unlikely(!wl_get_drv_status(wlpriv, READY, checkSysUpNDev))) {  \
       WL_INFORM(("device is not ready\n"));           \
       return -EIO;                        \
   }                               \
} while (0)
 
#ifdef QOS_MAP_SET
extern uint8 *wl_get_up_table(void);
#endif /* QOS_MAP_SET */
 
#define P2PO_COOKIE     65535
u64 wl_cfg80211_get_new_roc_id(struct bcm_cfg80211 *cfg);
 
#if defined(SUPPORT_RANDOM_MAC_SCAN)
int wl_cfg80211_set_random_mac(struct net_device *dev, bool enable);
int wl_cfg80211_random_mac_enable(struct net_device *dev);
int wl_cfg80211_random_mac_disable(struct net_device *dev);
#endif /* SUPPORT_RANDOM_MAC_SCAN */
#ifdef SUPPORT_AP_HIGHER_BEACONRATE
int wl_set_ap_beacon_rate(struct net_device *dev, int val, char *ifname);
int wl_get_ap_basic_rate(struct net_device *dev, char* command, char *ifname, int total_len);
#endif /* SUPPORT_AP_HIGHER_BEACONRATE */
#ifdef SUPPORT_AP_RADIO_PWRSAVE
int wl_get_ap_rps(struct net_device *dev, char* command, char *ifname, int total_len);
int wl_set_ap_rps(struct net_device *dev, bool enable, char *ifname);
int wl_update_ap_rps_params(struct net_device *dev, ap_rps_info_t* rps, char *ifname);
void wl_cfg80211_init_ap_rps(struct bcm_cfg80211 *cfg);
#endif /* SUPPORT_AP_RADIO_PWRSAVE */
#ifdef SUPPORT_RSSI_LOGGING
int wl_get_rssi_logging(struct net_device *dev, void *param);
int wl_set_rssi_logging(struct net_device *dev, void *param);
int wl_get_rssi_per_ant(struct net_device *dev, char *ifname, char *peer_mac, void *param);
#endif /* SUPPORT_RSSI_LOGGING */
int wl_cfg80211_iface_count(struct net_device *dev);
struct net_device* wl_get_ap_netdev(struct bcm_cfg80211 *cfg, char *ifname);
struct net_device* wl_get_netdev_by_name(struct bcm_cfg80211 *cfg, char *ifname);
int wl_cfg80211_get_vndr_ouilist(struct bcm_cfg80211 *cfg, uint8 *buf, int max_cnt);
s32 wl_cfg80211_autochannel(struct net_device *dev, char* command, int total_len);
#endif /* _wl_cfg80211_h_ */