summaryrefslogtreecommitdiff
path: root/drivers/net/wireless/sd8797/mlinux/moal_uap.c
blob: fb8e2a7d65716520f830b6046b4728f39fcddb0e (plain)
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
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
/** @file moal_uap.c
  *
  * @brief This file contains the major functions in UAP
  * driver. 
  *
  * Copyright (C) 2008-2012, Marvell International Ltd. 
  * 
  * This software file (the "File") is distributed by Marvell International 
  * Ltd. under the terms of the GNU General Public License Version 2, June 1991 
  * (the "License").  You may use, redistribute and/or modify this File in 
  * accordance with the terms and conditions of the License, a copy of which 
  * is available by writing to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  *
  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE 
  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE 
  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about 
  * this warranty disclaimer.
  *
  */

/********************************************************
Change log:
    10/21/2008: initial version
********************************************************/

#include    "moal_main.h"
#include    "moal_uap.h"
#include    "moal_sdio.h"
#include    "moal_eth_ioctl.h"
#if defined(STA_CFG80211) && defined(UAP_CFG80211)
#include    "moal_cfg80211.h"
#endif

/********************************************************
		Local Variables
********************************************************/

/********************************************************
		Global Variables
********************************************************/

/********************************************************
		Local Functions
********************************************************/
/**
 *  @brief uap addba parameter handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_addba_param(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ioctl_req *ioctl_req = NULL;
    mlan_ds_11n_cfg *cfg_11n = NULL;
    addba_param param;
    int ret = 0;

    ENTER();
    memset(&param, 0, sizeof(param));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_addba_param() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    PRINTM(MIOCTL,
           "addba param: action=%d, timeout=%d, txwinsize=%d, rxwinsize=%d txamsdu=%d rxamsdu=%d\n",
           (int) param.action, (int) param.timeout, (int) param.txwinsize,
           (int) param.rxwinsize, (int) param.txamsdu, (int) param.rxamsdu);
    ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_11n_cfg));
    if (ioctl_req == NULL) {
        LEAVE();
        return -ENOMEM;
    }
    cfg_11n = (mlan_ds_11n_cfg *) ioctl_req->pbuf;
    cfg_11n->sub_command = MLAN_OID_11N_CFG_ADDBA_PARAM;
    ioctl_req->req_id = MLAN_IOCTL_11N_CFG;

    if (!param.action) {
        /* Get addba param from MLAN */
        ioctl_req->action = MLAN_ACT_GET;
    } else {
        /* Set addba param in MLAN */
        ioctl_req->action = MLAN_ACT_SET;
        cfg_11n->param.addba_param.timeout = param.timeout;
        cfg_11n->param.addba_param.txwinsize = param.txwinsize;
        cfg_11n->param.addba_param.rxwinsize = param.rxwinsize;
        cfg_11n->param.addba_param.txamsdu = param.txamsdu;
        cfg_11n->param.addba_param.rxamsdu = param.rxamsdu;
    }
    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }
    param.timeout = cfg_11n->param.addba_param.timeout;
    param.txwinsize = cfg_11n->param.addba_param.txwinsize;
    param.rxwinsize = cfg_11n->param.addba_param.rxwinsize;
    param.txamsdu = cfg_11n->param.addba_param.txamsdu;
    param.rxamsdu = cfg_11n->param.addba_param.rxamsdu;

    /* Copy to user */
    if (copy_to_user(req->ifr_data, &param, sizeof(param))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
        goto done;
    }
  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

/**
 *  @brief uap aggr priority tbl
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_aggr_priotbl(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ioctl_req *ioctl_req = NULL;
    mlan_ds_11n_cfg *cfg_11n = NULL;
    aggr_prio_tbl param;
    int ret = 0;
    int i = 0;

    ENTER();
    memset(&param, 0, sizeof(param));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "woal_uap_aggr_priotbl() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    DBG_HEXDUMP(MCMD_D, "aggr_prio_tbl", (t_u8 *) & param, sizeof(param));

    ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_11n_cfg));
    if (ioctl_req == NULL) {
        LEAVE();
        return -ENOMEM;
    }
    cfg_11n = (mlan_ds_11n_cfg *) ioctl_req->pbuf;
    cfg_11n->sub_command = MLAN_OID_11N_CFG_AGGR_PRIO_TBL;
    ioctl_req->req_id = MLAN_IOCTL_11N_CFG;

    if (!param.action) {
        /* Get aggr_prio_tbl from MLAN */
        ioctl_req->action = MLAN_ACT_GET;
    } else {
        /* Set aggr_prio_tbl in MLAN */
        ioctl_req->action = MLAN_ACT_SET;
        for (i = 0; i < MAX_NUM_TID; i++) {
            cfg_11n->param.aggr_prio_tbl.ampdu[i] = param.ampdu[i];
            cfg_11n->param.aggr_prio_tbl.amsdu[i] = param.amsdu[i];
        }
    }
    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }
    for (i = 0; i < MAX_NUM_TID; i++) {
        param.ampdu[i] = cfg_11n->param.aggr_prio_tbl.ampdu[i];
        param.amsdu[i] = cfg_11n->param.aggr_prio_tbl.amsdu[i];
    }
    /* Copy to user */
    if (copy_to_user(req->ifr_data, &param, sizeof(param))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
        goto done;
    }
  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

/**
 *  @brief uap addba reject tbl
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_addba_reject(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ioctl_req *ioctl_req = NULL;
    mlan_ds_11n_cfg *cfg_11n = NULL;
    addba_reject_para param;
    int ret = 0;
    int i = 0;

    ENTER();
    memset(&param, 0, sizeof(param));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "woal_uap_addba_reject() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    DBG_HEXDUMP(MCMD_D, "addba_reject tbl", (t_u8 *) & param, sizeof(param));

    ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_11n_cfg));
    if (ioctl_req == NULL) {
        LEAVE();
        return -ENOMEM;
    }
    cfg_11n = (mlan_ds_11n_cfg *) ioctl_req->pbuf;
    cfg_11n->sub_command = MLAN_OID_11N_CFG_ADDBA_REJECT;
    ioctl_req->req_id = MLAN_IOCTL_11N_CFG;

    if (!param.action) {
        /* Get addba_reject tbl from MLAN */
        ioctl_req->action = MLAN_ACT_GET;
    } else {
        /* Set addba_reject tbl in MLAN */
        ioctl_req->action = MLAN_ACT_SET;
        for (i = 0; i < MAX_NUM_TID; i++) {
            cfg_11n->param.addba_reject[i] = param.addba_reject[i];
        }
    }
    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }
    for (i = 0; i < MAX_NUM_TID; i++) {
        param.addba_reject[i] = cfg_11n->param.addba_reject[i];
    }
    /* Copy to user */
    if (copy_to_user(req->ifr_data, &param, sizeof(param))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
        goto done;
    }
  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

/**
 *  @brief uap get_fw_info handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_get_fw_info(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    fw_info fw;
    mlan_fw_info fw_info;
    int ret = 0;

    ENTER();
    memset(&fw, 0, sizeof(fw));
    memset(&fw_info, 0, sizeof(fw_info));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "woal_uap_get_fw_info() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&fw, req->ifr_data, sizeof(fw))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    if (MLAN_STATUS_SUCCESS !=
        woal_request_get_fw_info(priv, MOAL_IOCTL_WAIT, &fw_info)) {
        ret = -EFAULT;
        goto done;
    }
    fw.fw_release_number = fw_info.fw_ver;
    fw.hw_dev_mcs_support = fw_info.hw_dev_mcs_support;
    /* Copy to user */
    if (copy_to_user(req->ifr_data, &fw, sizeof(fw))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
        goto done;
    }
  done:
    LEAVE();
    return ret;
}

/**
 *  @brief configure deep sleep
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_deep_sleep(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ioctl_req *ioctl_req = NULL;
    mlan_ds_pm_cfg *pm = NULL;
    deep_sleep_para param;
    int ret = 0;

    ENTER();
    memset(&param, 0, sizeof(param));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "woal_uap_deep_sleep() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    DBG_HEXDUMP(MCMD_D, "deep_sleep_para", (t_u8 *) & param, sizeof(param));

    ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_pm_cfg));
    if (ioctl_req == NULL) {
        LEAVE();
        return -ENOMEM;
    }
    pm = (mlan_ds_pm_cfg *) ioctl_req->pbuf;
    pm->sub_command = MLAN_OID_PM_CFG_DEEP_SLEEP;
    ioctl_req->req_id = MLAN_IOCTL_PM_CFG;

    if (!param.action) {
        /* Get deep_sleep status from MLAN */
        ioctl_req->action = MLAN_ACT_GET;
    } else {
        /* Set deep_sleep in MLAN */
        ioctl_req->action = MLAN_ACT_SET;
        if (param.deep_sleep == MTRUE) {
            pm->param.auto_deep_sleep.auto_ds = DEEP_SLEEP_ON;
            pm->param.auto_deep_sleep.idletime = param.idle_time;
        } else {
            pm->param.auto_deep_sleep.auto_ds = DEEP_SLEEP_OFF;
        }
    }
    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }
    if (pm->param.auto_deep_sleep.auto_ds == DEEP_SLEEP_ON)
        param.deep_sleep = MTRUE;
    else
        param.deep_sleep = MFALSE;
    param.idle_time = pm->param.auto_deep_sleep.idletime;
    /* Copy to user */
    if (copy_to_user(req->ifr_data, &param, sizeof(param))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
        goto done;
    }
  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

/**
 *  @brief configure tx_pause settings
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_txdatapause(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ioctl_req *ioctl_req = NULL;
    mlan_ds_misc_cfg *misc = NULL;
    tx_data_pause_para param;
    int ret = 0;

    ENTER();
    memset(&param, 0, sizeof(param));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "woal_uap_txdatapause corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    DBG_HEXDUMP(MCMD_D, "tx_data_pause_para", (t_u8 *) & param, sizeof(param));

    ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_misc_cfg));
    if (ioctl_req == NULL) {
        LEAVE();
        return -ENOMEM;
    }
    misc = (mlan_ds_misc_cfg *) ioctl_req->pbuf;
    misc->sub_command = MLAN_OID_MISC_TX_DATAPAUSE;
    ioctl_req->req_id = MLAN_IOCTL_MISC_CFG;

    if (!param.action) {
        /* Get Tx data pause status from MLAN */
        ioctl_req->action = MLAN_ACT_GET;
    } else {
        /* Set Tx data pause in MLAN */
        ioctl_req->action = MLAN_ACT_SET;
        misc->param.tx_datapause.tx_pause = param.txpause;
        misc->param.tx_datapause.tx_buf_cnt = param.txbufcnt;
    }
    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }

    param.txpause = misc->param.tx_datapause.tx_pause;
    param.txbufcnt = misc->param.tx_datapause.tx_buf_cnt;

    /* Copy to user */
    if (copy_to_user(req->ifr_data, &param, sizeof(param))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
        goto done;
    }
  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

/**
 *  @brief uap sdcmd52rw ioctl handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_sdcmd52_rw(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    sdcmd52_para param;
    t_u8 func, data = 0;
    int ret = 0, reg;

    ENTER();
    memset(&param, 0, sizeof(param));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "woal_uap_sdcmd52_rw() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }

    func = (t_u8) param.cmd52_params[0];
    reg = (t_u32) param.cmd52_params[1];

    if (!param.action) {
        PRINTM(MINFO, "Cmd52 read, func=%d, reg=0x%08X\n", func, reg);
        sdio_claim_host(((struct sdio_mmc_card *) priv->phandle->card)->func);
        if (func)
            data =
                sdio_readb(((struct sdio_mmc_card *) priv->phandle->card)->func,
                           reg, &ret);
        else
            data =
                sdio_f0_readb(((struct sdio_mmc_card *) priv->phandle->card)->
                              func, reg, &ret);
        sdio_release_host(((struct sdio_mmc_card *) priv->phandle->card)->func);
        if (ret) {
            PRINTM(MERROR, "sdio_readb: reading register 0x%X failed\n", reg);
            goto done;
        }
        param.cmd52_params[2] = data;
    } else {
        data = (t_u8) param.cmd52_params[2];
        PRINTM(MINFO, "Cmd52 write, func=%d, reg=0x%08X, data=0x%02X\n", func,
               reg, data);
        sdio_claim_host(((struct sdio_mmc_card *) priv->phandle->card)->func);
        if (func)
            sdio_writeb(((struct sdio_mmc_card *) priv->phandle->card)->func,
                        data, reg, &ret);
        else
            sdio_f0_writeb(((struct sdio_mmc_card *) priv->phandle->card)->func,
                           data, reg, &ret);
        sdio_release_host(((struct sdio_mmc_card *) priv->phandle->card)->func);
        if (ret) {
            PRINTM(MERROR, "sdio_writeb: writing register 0x%X failed\n", reg);
            goto done;
        }
    }
    /* Copy to user */
    if (copy_to_user(req->ifr_data, &param, sizeof(param))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
    }
  done:
    LEAVE();
    return ret;
}

/**
 *  @brief configure snmp mib
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_snmp_mib(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ioctl_req *ioctl_req = NULL;
    mlan_ds_snmp_mib *snmp = NULL;
    snmp_mib_para param;
    t_u8 value[MAX_SNMP_VALUE_SIZE];
    int ret = 0;

    ENTER();
    memset(&param, 0, sizeof(param));
    memset(value, 0, MAX_SNMP_VALUE_SIZE);

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "woal_uap_snmp_mib() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }

    /* Copy from user */
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    DBG_HEXDUMP(MCMD_D, "snmp_mib_para", (t_u8 *) & param, sizeof(param));
    if (param.action) {
        if (copy_from_user(value, req->ifr_data + sizeof(param),
                           MIN(param.oid_val_len, MAX_SNMP_VALUE_SIZE))) {
            PRINTM(MERROR, "Copy from user failed\n");
            ret = -EFAULT;
            goto done;
        }
        DBG_HEXDUMP(MCMD_D, "snmp_mib_para value", value,
                    MIN(param.oid_val_len, sizeof(t_u32)));
    }

    ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_snmp_mib));
    if (ioctl_req == NULL) {
        LEAVE();
        return -ENOMEM;
    }
    snmp = (mlan_ds_snmp_mib *) ioctl_req->pbuf;
    ioctl_req->req_id = MLAN_IOCTL_SNMP_MIB;
    switch (param.oid) {
    case OID_80211D_ENABLE:
        snmp->sub_command = MLAN_OID_SNMP_MIB_DOT11D;
        break;
    case OID_80211H_ENABLE:
        snmp->sub_command = MLAN_OID_SNMP_MIB_DOT11H;
        break;
    default:
        PRINTM(MERROR, "%s: Unsupported SNMP_MIB OID (%d).\n", __FUNCTION__,
               param.oid);
        goto done;
    }

    if (!param.action) {
        /* Get mib value from MLAN */
        ioctl_req->action = MLAN_ACT_GET;
    } else {
        /* Set mib value to MLAN */
        ioctl_req->action = MLAN_ACT_SET;
        snmp->param.oid_value = *(t_u32 *) value;
    }
    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }

    /* Copy to user */
    if (copy_to_user(req->ifr_data, &param, sizeof(param))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
        goto done;
    }
    if (!param.action) {        /* GET */
        if (copy_to_user(req->ifr_data + sizeof(param), &snmp->param.oid_value,
                         MIN(param.oid_val_len, sizeof(t_u32)))) {
            PRINTM(MERROR, "Copy from user failed\n");
            ret = -EFAULT;
            goto done;
        }
    }

  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

/**
 *  @brief configure domain info
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_domain_info(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ioctl_req *ioctl_req = NULL;
    mlan_ds_11d_cfg *cfg11d = NULL;
    domain_info_para param;
    t_u8 tlv[MAX_DOMAIN_TLV_LEN];
    t_u16 tlv_data_len = 0;
    int ret = 0;

    ENTER();
    memset(&param, 0, sizeof(param));
    memset(tlv, 0, MAX_DOMAIN_TLV_LEN);

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "woal_uap_domain_info() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }

    /* Copy from user */
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    DBG_HEXDUMP(MCMD_D, "domain_info_para", (t_u8 *) & param, sizeof(param));
    if (param.action) {
        /* get tlv header */
        if (copy_from_user(tlv, req->ifr_data + sizeof(param), TLV_HEADER_LEN)) {
            PRINTM(MERROR, "Copy from user failed\n");
            ret = -EFAULT;
            goto done;
        }
        tlv_data_len = ((t_u16 *) (tlv))[1];
        if ((TLV_HEADER_LEN + tlv_data_len) > sizeof(tlv)) {
            PRINTM(MERROR, "TLV buffer is overflowed");
            ret = -EINVAL;
            goto done;
        }
        /* get full tlv */
        if (copy_from_user(tlv, req->ifr_data + sizeof(param),
                           TLV_HEADER_LEN + tlv_data_len)) {
            PRINTM(MERROR, "Copy from user failed\n");
            ret = -EFAULT;
            goto done;
        }
        DBG_HEXDUMP(MCMD_D, "domain_info_para tlv", tlv,
                    TLV_HEADER_LEN + tlv_data_len);
    }

    ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_11d_cfg));
    if (ioctl_req == NULL) {
        LEAVE();
        return -ENOMEM;
    }
    cfg11d = (mlan_ds_11d_cfg *) ioctl_req->pbuf;
    ioctl_req->req_id = MLAN_IOCTL_11D_CFG;
    cfg11d->sub_command = MLAN_OID_11D_DOMAIN_INFO;

    if (!param.action) {
        /* Get mib value from MLAN */
        ioctl_req->action = MLAN_ACT_GET;
    } else {
        /* Set mib value to MLAN */
        ioctl_req->action = MLAN_ACT_SET;
        memcpy(cfg11d->param.domain_tlv, tlv,
               MIN(MAX_IE_SIZE, (TLV_HEADER_LEN + tlv_data_len)));
    }
    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }

    /* Copy to user */
    if (copy_to_user(req->ifr_data, &param, sizeof(param))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
        goto done;
    }
    if (!param.action) {        /* GET */
        tlv_data_len = ((t_u16 *) (cfg11d->param.domain_tlv))[1];
        if (copy_to_user
            (req->ifr_data + sizeof(param), &cfg11d->param.domain_tlv,
             TLV_HEADER_LEN + tlv_data_len)) {
            PRINTM(MERROR, "Copy from user failed\n");
            ret = -EFAULT;
            goto done;
        }
    }

  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

#if defined(DFS_TESTING_SUPPORT)
/**
 *  @brief configure dfs testing settings
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_dfs_testing(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ioctl_req *ioctl_req = NULL;
    mlan_ds_11h_cfg *cfg11h = NULL;
    dfs_testing_para param;
    int ret = 0;

    ENTER();
    memset(&param, 0, sizeof(param));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "woal_uap_dfs_testing() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }

    /* Copy from user */
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    DBG_HEXDUMP(MCMD_D, "dfs_testing_para", (t_u8 *) & param, sizeof(param));

    ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_11h_cfg));
    if (ioctl_req == NULL) {
        LEAVE();
        return -ENOMEM;
    }
    cfg11h = (mlan_ds_11h_cfg *) ioctl_req->pbuf;
    ioctl_req->req_id = MLAN_IOCTL_11H_CFG;
    cfg11h->sub_command = MLAN_OID_11H_DFS_TESTING;

    if (!param.action) {
        /* Get mib value from MLAN */
        ioctl_req->action = MLAN_ACT_GET;
    } else {
        /* Set mib value to MLAN */
        ioctl_req->action = MLAN_ACT_SET;
        cfg11h->param.dfs_testing.usr_cac_period_msec = param.usr_cac_period;
        cfg11h->param.dfs_testing.usr_nop_period_sec = param.usr_nop_period;
        cfg11h->param.dfs_testing.usr_no_chan_change = param.no_chan_change;
        cfg11h->param.dfs_testing.usr_fixed_new_chan = param.fixed_new_chan;
        priv->phandle->cac_period_jiffies = param.usr_cac_period * HZ / 1000;
    }
    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }

    if (!param.action) {        /* GET */
        param.usr_cac_period = cfg11h->param.dfs_testing.usr_cac_period_msec;
        param.usr_nop_period = cfg11h->param.dfs_testing.usr_nop_period_sec;
        param.no_chan_change = cfg11h->param.dfs_testing.usr_no_chan_change;
        param.fixed_new_chan = cfg11h->param.dfs_testing.usr_fixed_new_chan;
    }
    /* Copy to user */
    if (copy_to_user(req->ifr_data, &param, sizeof(param))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
        goto done;
    }

  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}
#endif

/**
 *  @brief Configure TX beamforming support
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_tx_bf_cfg(struct net_device *dev, struct ifreq *req)
{
    int ret = 0;
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ds_11n_tx_bf_cfg bf_cfg;
    tx_bf_cfg_para_hdr param;
    t_u16 action = 0;

    ENTER();

    memset(&param, 0, sizeof(param));
    memset(&bf_cfg, 0, sizeof(bf_cfg));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "woal_uap_tx_bf_cfg corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    if (!param.action) {
        /* Get BF configurations */
        action = MLAN_ACT_GET;
    } else {
        /* Set BF configurations */
        action = MLAN_ACT_SET;
    }
    if (copy_from_user(&bf_cfg, req->ifr_data + sizeof(tx_bf_cfg_para_hdr),
                       sizeof(bf_cfg))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    DBG_HEXDUMP(MCMD_D, "bf_cfg", (t_u8 *) & bf_cfg, sizeof(bf_cfg));

    if (MLAN_STATUS_SUCCESS != woal_set_get_tx_bf_cfg(priv, action, &bf_cfg)) {
        ret = -EFAULT;
        goto done;
    }

    /* Copy to user */
    if (copy_to_user(req->ifr_data + sizeof(tx_bf_cfg_para_hdr),
                     &bf_cfg, sizeof(bf_cfg))) {
        PRINTM(MERROR, "Copy to user failed!\n");
        ret = -EFAULT;
        goto done;
    }

  done:
    LEAVE();
    return ret;
}

/**
 *  @brief uap hs_cfg ioctl handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_hs_cfg(struct net_device *dev, struct ifreq *req,
                BOOLEAN invoke_hostcmd)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ds_hs_cfg hscfg;
    ds_hs_cfg hs_cfg;
    mlan_bss_info bss_info;
    t_u16 action;
    int ret = 0;

    ENTER();

    memset(&hscfg, 0, sizeof(mlan_ds_hs_cfg));
    memset(&hs_cfg, 0, sizeof(ds_hs_cfg));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_hs_cfg() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&hs_cfg, req->ifr_data, sizeof(ds_hs_cfg))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }

    PRINTM(MIOCTL, "ioctl hscfg: flags=0x%x condition=0x%x gpio=%d gap=0x%x\n",
           hs_cfg.flags, hs_cfg.conditions, (int) hs_cfg.gpio, hs_cfg.gap);

    /* HS config is blocked if HS is already activated */
    if ((hs_cfg.flags & HS_CFG_FLAG_CONDITION) &&
        (hs_cfg.conditions != HOST_SLEEP_CFG_CANCEL ||
         invoke_hostcmd == MFALSE)) {
        memset(&bss_info, 0, sizeof(bss_info));
        woal_get_bss_info(priv, MOAL_IOCTL_WAIT, &bss_info);
        if (bss_info.is_hs_configured) {
            PRINTM(MERROR, "HS already configured\n");
            ret = -EFAULT;
            goto done;
        }
    }

    if (hs_cfg.flags & HS_CFG_FLAG_SET) {
        action = MLAN_ACT_SET;
        if (hs_cfg.flags != HS_CFG_FLAG_ALL) {
            woal_set_get_hs_params(priv, MLAN_ACT_GET, MOAL_IOCTL_WAIT, &hscfg);
        }
        if (hs_cfg.flags & HS_CFG_FLAG_CONDITION)
            hscfg.conditions = hs_cfg.conditions;
        if (hs_cfg.flags & HS_CFG_FLAG_GPIO)
            hscfg.gpio = hs_cfg.gpio;
        if (hs_cfg.flags & HS_CFG_FLAG_GAP)
            hscfg.gap = hs_cfg.gap;

        if (invoke_hostcmd == MTRUE) {
            /* Issue IOCTL to set up parameters */
            hscfg.is_invoke_hostcmd = MFALSE;
            if (MLAN_STATUS_SUCCESS !=
                woal_set_get_hs_params(priv, action, MOAL_IOCTL_WAIT, &hscfg)) {
                ret = -EFAULT;
                goto done;
            }
        }
    } else {
        action = MLAN_ACT_GET;
    }

    /* Issue IOCTL to invoke hostcmd */
    hscfg.is_invoke_hostcmd = invoke_hostcmd;
    if (MLAN_STATUS_SUCCESS !=
        woal_set_get_hs_params(priv, action, MOAL_IOCTL_WAIT, &hscfg)) {
        ret = -EFAULT;
        goto done;
    }
    if (!(hs_cfg.flags & HS_CFG_FLAG_SET)) {
        hs_cfg.flags =
            HS_CFG_FLAG_CONDITION | HS_CFG_FLAG_GPIO | HS_CFG_FLAG_GAP;
        hs_cfg.conditions = hscfg.conditions;
        hs_cfg.gpio = hscfg.gpio;
        hs_cfg.gap = hscfg.gap;
        /* Copy to user */
        if (copy_to_user(req->ifr_data, &hs_cfg, sizeof(ds_hs_cfg))) {
            PRINTM(MERROR, "Copy to user failed!\n");
            ret = -EFAULT;
            goto done;
        }
    }

  done:
    LEAVE();
    return ret;
}

/**
 *  @brief Set Host Sleep parameters
 *
 *  @param priv         A pointer to moal_private structure
 *  @param wrq          A pointer to iwreq structure
 *
 *  @return             0 --success, otherwise fail
 */
static int
woal_uap_hs_set_para(struct net_device *dev, struct ifreq *req)
{
    int ret = 0;

    ENTER();

    if (req->ifr_data != NULL) {
        ret = woal_uap_hs_cfg(dev, req, MFALSE);
        goto done;
    } else {
        PRINTM(MERROR, "Invalid data\n");
        ret = -EINVAL;
        goto done;
    }
  done:
    LEAVE();
    return ret;
}

/**
 *  @brief uap mgmt_frame_control ioctl handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_mgmt_frame_control(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    int ret = 0;
    t_u16 action = 0;
    mgmt_frame_ctrl param;
    mlan_uap_bss_param sys_config;

    ENTER();

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_mgmt_frame_ctrl() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }

    /* Get user data */
    if (copy_from_user(&param, req->ifr_data, sizeof(param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    if (param.action) {
        action = MLAN_ACT_SET;
    } else {
        action = MLAN_ACT_GET;
    }
    if (action == MLAN_ACT_SET) {
        /* Initialize the invalid values so that the correct values below are
           downloaded to firmware */
        woal_set_sys_config_invalid_data(&sys_config);
        sys_config.mgmt_ie_passthru_mask = param.mask;
    }

    if (MLAN_STATUS_SUCCESS !=
        woal_set_get_sys_config(priv, action, MOAL_IOCTL_WAIT, &sys_config)) {
        ret = -EFAULT;
        goto done;
    }

    if (action == MLAN_ACT_GET) {
        param.mask = sys_config.mgmt_ie_passthru_mask;
        if (copy_to_user(req->ifr_data, &param, sizeof(param))) {
            PRINTM(MERROR, "Copy to user failed\n");
            ret = -EFAULT;
        }
    }
  done:
    LEAVE();
    return ret;
}

/**
 * @brief Set/Get tx rate
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *
 * @return           0 --success, otherwise fail
 */
static int
woal_uap_tx_rate_cfg(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    int ret = 0, i = 0;
    mlan_ds_rate *rate = NULL;
    mlan_ioctl_req *mreq = NULL;
    tx_rate_cfg_t tx_rate_config;

    ENTER();

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_tx_rate_cfg() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }

    memset(&tx_rate_config, 0, sizeof(tx_rate_cfg_t));
    /* Get user data */
    if (copy_from_user(&tx_rate_config, req->ifr_data, sizeof(tx_rate_cfg_t))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }

    mreq = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_rate));
    if (mreq == NULL) {
        ret = -ENOMEM;
        goto done;
    }
    rate = (mlan_ds_rate *) mreq->pbuf;
    rate->param.rate_cfg.rate_type = MLAN_RATE_INDEX;
    rate->sub_command = MLAN_OID_RATE_CFG;
    mreq->req_id = MLAN_IOCTL_RATE;
    if (!(tx_rate_config.action))
        mreq->action = MLAN_ACT_GET;
    else {
        mreq->action = MLAN_ACT_SET;
        if (tx_rate_config.rate == AUTO_RATE)
            rate->param.rate_cfg.is_rate_auto = 1;
        else {
            if ((tx_rate_config.rate != MLAN_RATE_INDEX_MCS32) &&
                ((tx_rate_config.rate < 0) ||
                 (tx_rate_config.rate > MLAN_RATE_INDEX_MCS15))) {
                ret = -EINVAL;
                goto done;
            }
        }
        rate->param.rate_cfg.rate = tx_rate_config.rate;
    }

    if (MLAN_STATUS_SUCCESS != woal_request_ioctl(priv, mreq, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }
    if (tx_rate_config.action) {
        priv->rate_index = tx_rate_config.action;
    } else {
        if (rate->param.rate_cfg.is_rate_auto)
            tx_rate_config.rate = AUTO_RATE;
        else
            tx_rate_config.rate = rate->param.rate_cfg.rate;
        for (i = 0; i < MAX_BITMAP_RATES_SIZE; i++) {
            tx_rate_config.bitmap_rates[i] =
                rate->param.rate_cfg.bitmap_rates[i];
        }

        if (copy_to_user(req->ifr_data, &tx_rate_config, sizeof(tx_rate_cfg_t))) {
            PRINTM(MERROR, "Copy to user failed\n");
            ret = -EFAULT;
        }
    }
  done:
    if (mreq)
        kfree(mreq);
    LEAVE();
    return ret;
}

/**
 * @brief Set/Get RF antenna mode
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *
 * @return           0 --success, otherwise fail
 */
static int
woal_uap_antenna_cfg(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    int ret = 0;
    mlan_ds_radio_cfg *radio = NULL;
    mlan_ioctl_req *mreq = NULL;
    ant_cfg_t antenna_config;

    ENTER();

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_antenna_cfg() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }

    memset(&antenna_config, 0, sizeof(ant_cfg_t));
    /* Get user data */
    if (copy_from_user(&antenna_config, req->ifr_data, sizeof(ant_cfg_t))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    mreq = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_radio_cfg));
    if (mreq == NULL) {
        ret = -ENOMEM;
        goto done;
    }
    radio = (mlan_ds_radio_cfg *) mreq->pbuf;
    radio->sub_command = MLAN_OID_ANT_CFG;
    mreq->req_id = MLAN_IOCTL_RADIO_CFG;
    if (!(antenna_config.action))
        mreq->action = MLAN_ACT_GET;
    else {
        mreq->action = MLAN_ACT_SET;
        radio->param.ant_cfg.tx_antenna = antenna_config.tx_mode;
        radio->param.ant_cfg.rx_antenna = antenna_config.rx_mode;
    }

    if (MLAN_STATUS_SUCCESS != woal_request_ioctl(priv, mreq, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }
    if (mreq->action == MLAN_ACT_GET) {
        antenna_config.tx_mode = radio->param.ant_cfg.tx_antenna;
        antenna_config.rx_mode = radio->param.ant_cfg.rx_antenna;
        if (copy_to_user(req->ifr_data, &antenna_config, sizeof(ant_cfg_t))) {
            PRINTM(MERROR, "Copy to user failed\n");
            ret = -EFAULT;
        }
    }
  done:
    if (mreq)
        kfree(mreq);
    LEAVE();
    return ret;
}

/**
 *  @brief uap ioctl handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_ioctl(struct net_device *dev, struct ifreq *req)
{
    int ret = 0;
    t_u32 subcmd = 0;
    ENTER();
    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_ioctl() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&subcmd, req->ifr_data, sizeof(subcmd))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }

    PRINTM(MIOCTL, "ioctl subcmd=%d\n", (int) subcmd);
    switch (subcmd) {
    case UAP_ADDBA_PARA:
        ret = woal_uap_addba_param(dev, req);
        break;
    case UAP_AGGR_PRIOTBL:
        ret = woal_uap_aggr_priotbl(dev, req);
        break;
    case UAP_ADDBA_REJECT:
        ret = woal_uap_addba_reject(dev, req);
        break;
    case UAP_FW_INFO:
        ret = woal_uap_get_fw_info(dev, req);
        break;
    case UAP_DEEP_SLEEP:
        ret = woal_uap_deep_sleep(dev, req);
        break;
    case UAP_TX_DATA_PAUSE:
        ret = woal_uap_txdatapause(dev, req);
        break;
    case UAP_SDCMD52_RW:
        ret = woal_uap_sdcmd52_rw(dev, req);
        break;
    case UAP_SNMP_MIB:
        ret = woal_uap_snmp_mib(dev, req);
        break;
    case UAP_DOMAIN_INFO:
        ret = woal_uap_domain_info(dev, req);
        break;
#ifdef DFS_TESTING_SUPPORT
    case UAP_DFS_TESTING:
        ret = woal_uap_dfs_testing(dev, req);
        break;
#endif
    case UAP_TX_BF_CFG:
        ret = woal_uap_tx_bf_cfg(dev, req);
        break;
    case UAP_HS_CFG:
        ret = woal_uap_hs_cfg(dev, req, MTRUE);
        break;
    case UAP_HS_SET_PARA:
        ret = woal_uap_hs_set_para(dev, req);
        break;
    case UAP_MGMT_FRAME_CONTROL:
        ret = woal_uap_mgmt_frame_control(dev, req);
        break;
    case UAP_TX_RATE_CFG:
        ret = woal_uap_tx_rate_cfg(dev, req);
        break;
    case UAP_ANTENNA_CFG:
        ret = woal_uap_antenna_cfg(dev, req);
        break;
    default:
        break;
    }
  done:
    LEAVE();
    return ret;
}

/**
 *  @brief uap station deauth ioctl handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_sta_deauth_ioctl(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ioctl_req *ioctl_req = NULL;
    mlan_ds_bss *bss = NULL;
    mlan_deauth_param deauth_param;
    int ret = 0;

    ENTER();

    memset(&deauth_param, 0, sizeof(mlan_deauth_param));
    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_sta_deauth_ioctl() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&deauth_param, req->ifr_data, sizeof(mlan_deauth_param))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }

    PRINTM(MIOCTL,
           "ioctl deauth station: %02x:%02x:%02x:%02x:%02x:%02x, reason=%d\n",
           deauth_param.mac_addr[0], deauth_param.mac_addr[1],
           deauth_param.mac_addr[2], deauth_param.mac_addr[3],
           deauth_param.mac_addr[4], deauth_param.mac_addr[5],
           deauth_param.reason_code);

    ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_bss));
    if (ioctl_req == NULL) {
        ret = -ENOMEM;
        goto done;
    }
    bss = (mlan_ds_bss *) ioctl_req->pbuf;

    bss->sub_command = MLAN_OID_UAP_DEAUTH_STA;
    ioctl_req->req_id = MLAN_IOCTL_BSS;
    ioctl_req->action = MLAN_ACT_SET;

    memcpy(&bss->param.deauth_param, &deauth_param, sizeof(mlan_deauth_param));
    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        if (copy_to_user(req->ifr_data, &ioctl_req->status_code, sizeof(t_u32)))
            PRINTM(MERROR, "Copy to user failed!\n");
        goto done;
    }

  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

/**
 * @brief Set/Get radio
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *
 * @return           0 --success, otherwise fail
 */
static int
woal_uap_radio_ctl(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    int ret = 0;
    mlan_ds_radio_cfg *radio = NULL;
    mlan_ioctl_req *mreq = NULL;
    int data[2] = { 0, 0 };
    mlan_bss_info bss_info;

    ENTER();

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_radio_ctl() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }

    /* Get user data */
    if (copy_from_user(&data, req->ifr_data, sizeof(data))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }

    if (data[0]) {
        mreq = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_radio_cfg));
        if (mreq == NULL) {
            ret = -ENOMEM;
            goto done;
        }
        radio = (mlan_ds_radio_cfg *) mreq->pbuf;
        radio->sub_command = MLAN_OID_RADIO_CTRL;
        mreq->req_id = MLAN_IOCTL_RADIO_CFG;
        mreq->action = MLAN_ACT_SET;
        radio->param.radio_on_off = (t_u32) data[1];
        if (MLAN_STATUS_SUCCESS !=
            woal_request_ioctl(priv, mreq, MOAL_IOCTL_WAIT)) {
            ret = -EFAULT;
        }
        if (mreq)
            kfree(mreq);
    } else {
        /* Get radio status */
        memset(&bss_info, 0, sizeof(bss_info));
        woal_get_bss_info(priv, MOAL_IOCTL_WAIT, &bss_info);

        data[1] = bss_info.radio_on;
        if (copy_to_user(req->ifr_data, data, sizeof(data))) {
            PRINTM(MERROR, "Copy to user failed\n");
            ret = -EFAULT;
        }
    }
  done:
    LEAVE();
    return ret;
}

/**
 *  @brief uap bss control ioctl handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_bss_ctrl_ioctl(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    int ret = 0, data = 0;

    ENTER();

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_bss_ctrl() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&data, req->ifr_data, sizeof(data))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }

    ret = woal_uap_bss_ctrl(priv, MOAL_IOCTL_WAIT, data);

  done:
    LEAVE();
    return ret;
}

/**
 *  @brief uap power mode ioctl handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_power_mode_ioctl(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    mlan_ioctl_req *ioctl_req = NULL;
    mlan_ds_pm_cfg *pm_cfg = NULL;
    mlan_ds_ps_mgmt ps_mgmt;
    int ret = 0;

    ENTER();

    memset(&ps_mgmt, 0, sizeof(mlan_ds_ps_mgmt));

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_power_mode_ioctl() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }
    if (copy_from_user(&ps_mgmt, req->ifr_data, sizeof(mlan_ds_ps_mgmt))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }

    PRINTM(MIOCTL,
           "ioctl power: flag=0x%x ps_mode=%d ctrl_bitmap=%d min_sleep=%d max_sleep=%d "
           "inact_to=%d min_awake=%d max_awake=%d\n", ps_mgmt.flags,
           (int) ps_mgmt.ps_mode, (int) ps_mgmt.sleep_param.ctrl_bitmap,
           (int) ps_mgmt.sleep_param.min_sleep,
           (int) ps_mgmt.sleep_param.max_sleep,
           (int) ps_mgmt.inact_param.inactivity_to,
           (int) ps_mgmt.inact_param.min_awake,
           (int) ps_mgmt.inact_param.max_awake);

    if (ps_mgmt.
        flags & ~(PS_FLAG_PS_MODE | PS_FLAG_SLEEP_PARAM |
                  PS_FLAG_INACT_SLEEP_PARAM)) {
        PRINTM(MERROR, "Invalid parameter: flags = 0x%x\n", ps_mgmt.flags);
        ret = -EINVAL;
        goto done;
    }

    if (ps_mgmt.ps_mode > PS_MODE_INACTIVITY) {
        PRINTM(MERROR, "Invalid parameter: ps_mode = %d\n",
               (int) ps_mgmt.flags);
        ret = -EINVAL;
        goto done;
    }

    ioctl_req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_pm_cfg));
    if (ioctl_req == NULL) {
        ret = -ENOMEM;
        goto done;
    }
    pm_cfg = (mlan_ds_pm_cfg *) ioctl_req->pbuf;
    pm_cfg->sub_command = MLAN_OID_PM_CFG_PS_MODE;
    ioctl_req->req_id = MLAN_IOCTL_PM_CFG;
    if (ps_mgmt.flags) {
        ioctl_req->action = MLAN_ACT_SET;
        memcpy(&pm_cfg->param.ps_mgmt, &ps_mgmt, sizeof(mlan_ds_ps_mgmt));
    } else {
        ioctl_req->action = MLAN_ACT_GET;
    }

    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        if (copy_to_user(req->ifr_data, &ioctl_req->status_code, sizeof(t_u32)))
            PRINTM(MERROR, "Copy to user failed!\n");
        goto done;
    }
    if (!ps_mgmt.flags) {
        /* Copy to user */
        if (copy_to_user
            (req->ifr_data, &pm_cfg->param.ps_mgmt, sizeof(mlan_ds_ps_mgmt))) {
            PRINTM(MERROR, "Copy to user failed!\n");
            ret = -EFAULT;
            goto done;
        }
    }
  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

/**
 *  @brief uap BSS config ioctl handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_bss_cfg_ioctl(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    int ret = 0;
    mlan_ds_bss *bss = NULL;
    mlan_ioctl_req *ioctl_req = NULL;
    int offset = 0;
    t_u32 action = 0;

    ENTER();

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_bss_cfg_ioctl() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }

    /* Get action */
    if (copy_from_user(&action, req->ifr_data + offset, sizeof(action))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }
    offset += sizeof(action);

    /* Allocate an IOCTL request buffer */
    ioctl_req =
        (mlan_ioctl_req *) woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_bss));
    if (ioctl_req == NULL) {
        ret = -ENOMEM;
        goto done;
    }

    bss = (mlan_ds_bss *) ioctl_req->pbuf;
    bss->sub_command = MLAN_OID_UAP_BSS_CONFIG;
    ioctl_req->req_id = MLAN_IOCTL_BSS;
    if (action == 1) {
        ioctl_req->action = MLAN_ACT_SET;
    } else {
        ioctl_req->action = MLAN_ACT_GET;
    }

    if (ioctl_req->action == MLAN_ACT_SET) {
        /* Get the BSS config from user */
        if (copy_from_user
            (&bss->param.bss_config, req->ifr_data + offset,
             sizeof(mlan_uap_bss_param))) {
            PRINTM(MERROR, "Copy from user failed\n");
            ret = -EFAULT;
            goto done;
        }
    }

    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }

    if (ioctl_req->action == MLAN_ACT_GET) {
        offset = sizeof(action);

        /* Copy to user : BSS config */
        if (copy_to_user
            (req->ifr_data + offset, &bss->param.bss_config,
             sizeof(mlan_uap_bss_param))) {
            PRINTM(MERROR, "Copy to user failed!\n");
            ret = -EFAULT;
            goto done;
        }
    }
  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

/**
 *  @brief uap get station list handler
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_get_sta_list_ioctl(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    int ret = 0;
    mlan_ds_get_info *info = NULL;
    mlan_ioctl_req *ioctl_req = NULL;

    ENTER();

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_get_sta_list_ioctl() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }

    /* Allocate an IOCTL request buffer */
    ioctl_req =
        (mlan_ioctl_req *) woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_get_info));
    if (ioctl_req == NULL) {
        ret = -ENOMEM;
        goto done;
    }

    info = (mlan_ds_get_info *) ioctl_req->pbuf;
    info->sub_command = MLAN_OID_UAP_STA_LIST;
    ioctl_req->req_id = MLAN_IOCTL_GET_INFO;
    ioctl_req->action = MLAN_ACT_GET;

    if (MLAN_STATUS_SUCCESS !=
        woal_request_ioctl(priv, ioctl_req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }

    if (ioctl_req->action == MLAN_ACT_GET) {
        /* Copy to user : sta_list */
        if (copy_to_user
            (req->ifr_data, &info->param.sta_list, sizeof(mlan_ds_sta_list))) {
            PRINTM(MERROR, "Copy to user failed!\n");
            ret = -EFAULT;
            goto done;
        }
    }
  done:
    if (ioctl_req)
        kfree(ioctl_req);
    LEAVE();
    return ret;
}

/**
 *  @brief uAP set WAPI key ioctl
 *
 *  @param priv      A pointer to moal_private structure
 *  @param msg       A pointer to wapi_msg structure
 *
 *  @return          0 --success, otherwise fail
 */
static int
woal_uap_set_wapi_key_ioctl(moal_private * priv, wapi_msg * msg)
{
    mlan_ioctl_req *req = NULL;
    mlan_ds_sec_cfg *sec = NULL;
    int ret = 0;
    wapi_key_msg *key_msg = NULL;
    t_u8 bcast_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

    ENTER();
    if (msg->msg_len != sizeof(wapi_key_msg)) {
        ret = -EINVAL;
        goto done;
    }
    key_msg = (wapi_key_msg *) msg->msg;

    req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_sec_cfg));
    if (req == NULL) {
        ret = -ENOMEM;
        goto done;
    }
    sec = (mlan_ds_sec_cfg *) req->pbuf;
    sec->sub_command = MLAN_OID_SEC_CFG_ENCRYPT_KEY;
    req->req_id = MLAN_IOCTL_SEC_CFG;
    req->action = MLAN_ACT_SET;

    sec->param.encrypt_key.is_wapi_key = MTRUE;
    sec->param.encrypt_key.key_len = MLAN_MAX_KEY_LENGTH;
    memcpy(sec->param.encrypt_key.mac_addr, key_msg->mac_addr, ETH_ALEN);
    sec->param.encrypt_key.key_index = key_msg->key_id;
    if (0 == memcmp(key_msg->mac_addr, bcast_addr, ETH_ALEN))
        sec->param.encrypt_key.key_flags = KEY_FLAG_GROUP_KEY;
    else
        sec->param.encrypt_key.key_flags = KEY_FLAG_SET_TX_KEY;
    memcpy(sec->param.encrypt_key.key_material, key_msg->key,
           sec->param.encrypt_key.key_len);

    if (MLAN_STATUS_SUCCESS != woal_request_ioctl(priv, req, MOAL_IOCTL_WAIT))
        ret = -EFAULT;
  done:
    if (req)
        kfree(req);
    LEAVE();
    return ret;
}

/**
 *  @brief Enable/Disable wapi in firmware
 *
 *  @param priv          A pointer to moal_private structure
 *  @param enable        MTRUE/MFALSE
 *
 *  @return              MLAN_STATUS_SUCCESS/MLAN_STATUS_PENDING -- success, otherwise fail
 */
static mlan_status
woal_enable_wapi(moal_private * priv, t_u8 enable)
{
    mlan_ioctl_req *req = NULL;
    mlan_ds_bss *bss = NULL;
    mlan_status status;

    ENTER();

    /* Allocate an IOCTL request buffer */
    req = (mlan_ioctl_req *) woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_bss));
    if (req == NULL) {
        status = MLAN_STATUS_FAILURE;
        goto done;
    }

    /* Fill request buffer */
    bss = (mlan_ds_bss *) req->pbuf;
    bss->sub_command = MLAN_OID_UAP_BSS_CONFIG;
    req->req_id = MLAN_IOCTL_BSS;
    req->action = MLAN_ACT_GET;

    /* Send IOCTL request to MLAN */
    status = woal_request_ioctl(priv, req, MOAL_IOCTL_WAIT);
    if (status != MLAN_STATUS_SUCCESS) {
        PRINTM(MERROR, "Get AP setting  failed! status=%d, error_code=0x%x\n",
               status, req->status_code);
    }

    /* Change AP default setting */
    req->action = MLAN_ACT_SET;
    if (enable == MFALSE) {
        bss->param.bss_config.auth_mode = MLAN_AUTH_MODE_OPEN;
        bss->param.bss_config.protocol = PROTOCOL_NO_SECURITY;
    } else {
        bss->param.bss_config.auth_mode = MLAN_AUTH_MODE_OPEN;
        bss->param.bss_config.protocol = PROTOCOL_WAPI;
    }

    /* Send IOCTL request to MLAN */
    status = woal_request_ioctl(priv, req, MOAL_IOCTL_WAIT);
    if (status != MLAN_STATUS_SUCCESS) {
        PRINTM(MERROR, "Set AP setting failed! status=%d, error_code=0x%x\n",
               status, req->status_code);
    }
    if (enable)
        woal_uap_bss_ctrl(priv, MOAL_IOCTL_WAIT, UAP_BSS_START);
  done:
    if (req)
        kfree(req);
    LEAVE();
    return status;
}

/**
 *  @brief uAP set WAPI flag ioctl
 *
 *  @param priv      A pointer to moal_private structure
 *  @param msg       A pointer to wapi_msg structure
 *
 *  @return          0 --success, otherwise fail
 */
static int
woal_uap_set_wapi_flag_ioctl(moal_private * priv, wapi_msg * msg)
{
    t_u8 wapi_psk_ie[] =
        { 0x44, 0x14, 0x01, 0x00, 0x01, 0x00, 0x00, 0x14, 0x72, 0x02,
        0x01, 0x00, 0x00, 0x14, 0x72, 0x01, 0x00, 0x14, 0x72, 0x01,
        0x00, 0x00
    };
    t_u8 wapi_cert_ie[] =
        { 0x44, 0x14, 0x01, 0x00, 0x01, 0x00, 0x00, 0x14, 0x72, 0x01,
        0x01, 0x00, 0x00, 0x14, 0x72, 0x01, 0x00, 0x14, 0x72, 0x01,
        0x00, 0x00
    };
    mlan_ds_misc_cfg *misc = NULL;
    mlan_ioctl_req *req = NULL;
    int ret = 0;

    ENTER();

    woal_uap_bss_ctrl(priv, MOAL_IOCTL_WAIT, UAP_BSS_STOP);

    req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_misc_cfg));
    if (req == NULL) {
        ret = -ENOMEM;
        goto done;
    }
    misc = (mlan_ds_misc_cfg *) req->pbuf;
    misc->sub_command = MLAN_OID_MISC_GEN_IE;
    req->req_id = MLAN_IOCTL_MISC_CFG;
    req->action = MLAN_ACT_SET;

    misc->param.gen_ie.type = MLAN_IE_TYPE_GEN_IE;
    misc->param.gen_ie.len = sizeof(wapi_psk_ie);
    if (msg->msg[0] & WAPI_MODE_PSK) {
        memcpy(misc->param.gen_ie.ie_data, wapi_psk_ie, misc->param.gen_ie.len);
    } else if (msg->msg[0] & WAPI_MODE_CERT) {
        memcpy(misc->param.gen_ie.ie_data, wapi_cert_ie,
               misc->param.gen_ie.len);
    } else if (msg->msg[0] == 0) {
        /* disable WAPI in driver */
        if (MLAN_STATUS_SUCCESS !=
            woal_set_wapi_enable(priv, MOAL_IOCTL_WAIT, 0))
            ret = -EFAULT;
        woal_enable_wapi(priv, MFALSE);
        goto done;
    } else {
        ret = -EINVAL;
        goto done;
    }
    if (MLAN_STATUS_SUCCESS != woal_request_ioctl(priv, req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }
    woal_enable_wapi(priv, MTRUE);
  done:
    if (req)
        kfree(req);
    LEAVE();
    return ret;
}

/**
 *  @brief set wapi ioctl function
 *
 *  @param dev      A pointer to net_device structure
 *  @param req      A pointer to ifreq structure
 *  @return         0 --success, otherwise fail
 */
static int
woal_uap_set_wapi(struct net_device *dev, struct ifreq *req)
{
    moal_private *priv = (moal_private *) netdev_priv(dev);
    wapi_msg msg;
    int ret = 0;

    ENTER();

    /* Sanity check */
    if (req->ifr_data == NULL) {
        PRINTM(MERROR, "uap_set_wapi() corrupt data\n");
        ret = -EFAULT;
        goto done;
    }

    memset(&msg, 0, sizeof(msg));

    if (copy_from_user(&msg, req->ifr_data, sizeof(msg))) {
        PRINTM(MERROR, "Copy from user failed\n");
        ret = -EFAULT;
        goto done;
    }

    PRINTM(MIOCTL, "set wapi msg_type = %d, msg_len=%d\n", msg.msg_type,
           msg.msg_len);
    DBG_HEXDUMP(MCMD_D, "wapi msg", msg.msg, MIN(msg.msg_len, sizeof(msg.msg)));

    switch (msg.msg_type) {
    case P80211_PACKET_WAPIFLAG:
        ret = woal_uap_set_wapi_flag_ioctl(priv, &msg);
        break;
    case P80211_PACKET_SETKEY:
        ret = woal_uap_set_wapi_key_ioctl(priv, &msg);
        break;
    default:
        ret = -EOPNOTSUPP;
        break;
    }
  done:
    LEAVE();
    return ret;
}

/********************************************************
		Global Functions
********************************************************/
/**
 *  @brief Initialize the members of mlan_uap_bss_param
 *  which are uploaded from firmware
 *
 *  @param priv     A pointer to moal_private structure
 *  @param sys_cfg  A pointer to mlan_uap_bss_param structure
 *  @param wait_option      Wait option
 *
 *  @return         MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
 */
mlan_status
woal_uap_get_bss_param(moal_private * priv, mlan_uap_bss_param * sys_cfg,
                       t_u8 wait_option)
{
    mlan_ds_bss *info = NULL;
    mlan_ioctl_req *req = NULL;
    mlan_status status = MLAN_STATUS_SUCCESS;

    ENTER();

    req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_bss));
    if (req == NULL) {
        LEAVE();
        return MLAN_STATUS_FAILURE;
    }

    info = (mlan_ds_bss *) req->pbuf;
    info->sub_command = MLAN_OID_UAP_BSS_CONFIG;
    req->req_id = MLAN_IOCTL_BSS;
    req->action = MLAN_ACT_GET;

    status = woal_request_ioctl(priv, req, wait_option);
    if (status != MLAN_STATUS_SUCCESS) {
        PRINTM(MERROR, "Get bss info failed!\n");
        status = MLAN_STATUS_FAILURE;
        goto done;
    }
    memcpy(sys_cfg, &info->param.bss_config, sizeof(mlan_uap_bss_param));

  done:
    if (req && (status != MLAN_STATUS_PENDING))
        kfree(req);

    LEAVE();
    return status;
}

/**
 *  @brief Set 11n status based on the configured security mode
 *
 *  @param sys_cfg  A pointer to mlan_uap_bss_param structure
 *  @param action   MLAN_ACT_DISABLE or MLAN_ACT_ENABLE
 *
 *  @return         MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
 */
mlan_status
woal_uap_set_11n_status(mlan_uap_bss_param * sys_cfg, t_u8 action)
{
    mlan_status status = MLAN_STATUS_SUCCESS;

    ENTER();
    if (action == MLAN_ACT_DISABLE) {
        if ((sys_cfg->supported_mcs_set[0] == 0)
            && (sys_cfg->supported_mcs_set[4] == 0)
            && (sys_cfg->supported_mcs_set[1] == 0)
            ) {
            goto done;
        } else {
            sys_cfg->supported_mcs_set[0] = 0;
            sys_cfg->supported_mcs_set[4] = 0;
            sys_cfg->supported_mcs_set[1] = 0;
        }
    }

    if (action == MLAN_ACT_ENABLE) {
        if ((sys_cfg->supported_mcs_set[0] != 0)
            || (sys_cfg->supported_mcs_set[4] != 0)
            || (sys_cfg->supported_mcs_set[1] != 0)
            ) {
            goto done;
        } else {
            sys_cfg->supported_mcs_set[0] = 0xFF;
            sys_cfg->supported_mcs_set[4] = 0x01;
            sys_cfg->supported_mcs_set[1] = 0xFF;
        }
    }

  done:
    LEAVE();
    return status;
}

/**
 *  @brief Parse AP configuration from ASCII string
 *
 *  @param ap_cfg   A pointer to mlan_uap_bss_param structure
 *  @param buf      A pointer to user data
 *
 *  @return         0 --success, otherwise fail
 */
int
woal_uap_ap_cfg_parse_data(mlan_uap_bss_param * ap_cfg, t_s8 * buf)
{
    int ret = 0, atoi_ret;
    int set_sec = 0, set_key = 0, set_chan = 0;
    int set_preamble = 0, set_scb = 0, set_ssid = 0;
    t_s8 *begin = buf, *value = NULL, *opt = NULL;

    ENTER();

    while (begin) {
        value = woal_strsep(&begin, ',', '/');
        opt = woal_strsep(&value, '=', '/');
        if (opt && !strncmp(opt, "END", strlen("END"))) {
            if (!ap_cfg->ssid.ssid_len) {
                PRINTM(MERROR, "Minimum option required is SSID\n");
                ret = -EINVAL;
                goto done;
            }
            PRINTM(MINFO, "Parsing terminated by string END\n");
            break;
        }
        if (!opt || !value || !value[0]) {
            PRINTM(MERROR, "Invalid option\n");
            ret = -EINVAL;
            goto done;
        } else if (!strncmp(opt, "ASCII_CMD", strlen("ASCII_CMD"))) {
            if (strncmp(value, "AP_CFG", strlen("AP_CFG"))) {
                PRINTM(MERROR, "ASCII_CMD: %s not matched with AP_CFG\n",
                       value);
                ret = -EFAULT;
                goto done;
            }
            value = woal_strsep(&begin, ',', '/');
            opt = woal_strsep(&value, '=', '/');
            if (!opt || !value || !value[0]) {
                PRINTM(MERROR, "Minimum option required is SSID\n");
                ret = -EINVAL;
                goto done;
            } else if (!strncmp(opt, "SSID", strlen("SSID"))) {
                if (set_ssid) {
                    PRINTM(MWARN, "Skipping SSID, found again!\n");
                    continue;
                }
                if (strlen(value) > MLAN_MAX_SSID_LENGTH) {
                    PRINTM(MERROR, "SSID length exceeds max length\n");
                    ret = -EFAULT;
                    goto done;
                }
                ap_cfg->ssid.ssid_len = strlen(value);
                strncpy((char *) ap_cfg->ssid.ssid, value, strlen(value));
                PRINTM(MINFO, "ssid=%s, len=%d\n", ap_cfg->ssid.ssid,
                       (int) ap_cfg->ssid.ssid_len);
                set_ssid = 1;
            } else {
                PRINTM(MERROR, "AP_CFG: Invalid option %s, "
                       "expect SSID\n", opt);
                ret = -EINVAL;
                goto done;
            }
        } else if (!strncmp(opt, "SEC", strlen("SEC"))) {
            if (set_sec) {
                PRINTM(MWARN, "Skipping SEC, found again!\n");
                continue;
            }
            if (!strnicmp(value, "open", strlen("open"))) {
                ap_cfg->auth_mode = MLAN_AUTH_MODE_OPEN;
                if (set_key)
                    ap_cfg->wpa_cfg.length = 0;
                ap_cfg->key_mgmt = KEY_MGMT_NONE;
                ap_cfg->protocol = PROTOCOL_NO_SECURITY;
            } else if (!strnicmp(value, "wpa2-psk", strlen("wpa2-psk"))) {
                ap_cfg->auth_mode = MLAN_AUTH_MODE_OPEN;
                ap_cfg->protocol = PROTOCOL_WPA2;
                ap_cfg->key_mgmt = KEY_MGMT_PSK;
                ap_cfg->wpa_cfg.pairwise_cipher_wpa = CIPHER_AES_CCMP;
                ap_cfg->wpa_cfg.pairwise_cipher_wpa2 = CIPHER_AES_CCMP;
                ap_cfg->wpa_cfg.group_cipher = CIPHER_AES_CCMP;
            } else if (!strnicmp(value, "wpa-psk", strlen("wpa-psk"))) {
                ap_cfg->auth_mode = MLAN_AUTH_MODE_OPEN;
                ap_cfg->protocol = PROTOCOL_WPA;
                ap_cfg->key_mgmt = KEY_MGMT_PSK;
                ap_cfg->wpa_cfg.pairwise_cipher_wpa = CIPHER_TKIP;
                ap_cfg->wpa_cfg.group_cipher = CIPHER_TKIP;
            } else if (!strnicmp(value, "wep128", strlen("wep128"))) {
                ap_cfg->auth_mode = MLAN_AUTH_MODE_OPEN;
                if (set_key)
                    ap_cfg->wpa_cfg.length = 0;
                ap_cfg->key_mgmt = KEY_MGMT_NONE;
                ap_cfg->protocol = PROTOCOL_STATIC_WEP;
            } else {
                PRINTM(MERROR, "AP_CFG: Invalid value=%s for %s\n", value, opt);
                ret = -EFAULT;
                goto done;
            }
            set_sec = 1;
        } else if (!strncmp(opt, "KEY", strlen("KEY"))) {
            if (set_key) {
                PRINTM(MWARN, "Skipping KEY, found again!\n");
                continue;
            }
            if (set_sec && ap_cfg->protocol == PROTOCOL_STATIC_WEP) {
                if (strlen(value) != MAX_WEP_KEY_SIZE) {
                    PRINTM(MERROR, "Invalid WEP KEY length\n");
                    ret = -EFAULT;
                    goto done;
                }
                ap_cfg->wep_cfg.key0.key_index = 0;
                ap_cfg->wep_cfg.key0.is_default = 1;
                ap_cfg->wep_cfg.key0.length = strlen(value);
                memcpy(ap_cfg->wep_cfg.key0.key, value, strlen(value));
                set_key = 1;
                continue;
            }
            if (set_sec && ap_cfg->protocol != PROTOCOL_WPA2
                && ap_cfg->protocol != PROTOCOL_WPA) {
                PRINTM(MWARN, "Warning! No KEY for open mode\n");
                set_key = 1;
                continue;
            }
            if (strlen(value) < MLAN_MIN_PASSPHRASE_LENGTH ||
                strlen(value) > MLAN_PMK_HEXSTR_LENGTH) {
                PRINTM(MERROR, "Invalid PSK/PMK length\n");
                ret = -EINVAL;
                goto done;
            }
            ap_cfg->wpa_cfg.length = strlen(value);
            memcpy(ap_cfg->wpa_cfg.passphrase, value, strlen(value));
            set_key = 1;
        } else if (!strncmp(opt, "CHANNEL", strlen("CHANNEL"))) {
            if (set_chan) {
                PRINTM(MWARN, "Skipping CHANNEL, found again!\n");
                continue;
            }
            if (woal_atoi(&atoi_ret, value)) {
                ret = -EINVAL;
                goto done;
            }
            if (atoi_ret < 1 || atoi_ret > MLAN_MAX_CHANNEL) {
                PRINTM(MERROR, "AP_CFG: Channel must be between 1 and %d"
                       "(both included)\n", MLAN_MAX_CHANNEL);
                ret = -EINVAL;
                goto done;
            }
            ap_cfg->channel = atoi_ret;
            set_chan = 1;
        } else if (!strncmp(opt, "PREAMBLE", strlen("PREAMBLE"))) {
            if (set_preamble) {
                PRINTM(MWARN, "Skipping PREAMBLE, found again!\n");
                continue;
            }
            if (woal_atoi(&atoi_ret, value)) {
                ret = -EINVAL;
                goto done;
            }
            /* This is a READ only value from FW, so we can not set this and
               pass it successfully */
            set_preamble = 1;
        } else if (!strncmp(opt, "MAX_SCB", strlen("MAX_SCB"))) {
            if (set_scb) {
                PRINTM(MWARN, "Skipping MAX_SCB, found again!\n");
                continue;
            }
            if (woal_atoi(&atoi_ret, value)) {
                ret = -EINVAL;
                goto done;
            }
            if (atoi_ret < 1 || atoi_ret > MAX_STA_COUNT) {
                PRINTM(MERROR, "AP_CFG: MAX_SCB must be between 1 to %d "
                       "(both included)\n", MAX_STA_COUNT);
                ret = -EINVAL;
                goto done;
            }
            ap_cfg->max_sta_count = (t_u16) atoi_ret;
            set_scb = 1;
        } else {
            PRINTM(MERROR, "Invalid option %s\n", opt);
            ret = -EINVAL;
            goto done;
        }
    }

  done:
    LEAVE();
    return ret;
}

/**
 *  @brief Set AP configuration
 *
 *  @param priv     A pointer to moal_private structure
 *  @param data     A pointer to user data
 *  @param len      Length of buf
 *
 *  @return         0 --success, otherwise fail
 */
int
woal_uap_set_ap_cfg(moal_private * priv, t_u8 * data, int len)
{
    int ret = 0;
    static t_s8 buf[MAX_BUF_LEN];
    mlan_uap_bss_param sys_config;
    int restart = 0;

    ENTER();

#define MIN_AP_CFG_CMD_LEN   16 /* strlen("ASCII_CMD=AP_CFG") */
    if ((len - 1) <= MIN_AP_CFG_CMD_LEN) {
        PRINTM(MERROR, "Invalid length of command\n");
        ret = -EINVAL;
        goto done;
    }

    memset(buf, 0, MAX_BUF_LEN);
    memcpy(buf, data, len);

    /* Initialize the uap bss values which are uploaded from firmware */
    woal_uap_get_bss_param(priv, &sys_config, MOAL_IOCTL_WAIT);

    /* Setting the default values */
    sys_config.channel = 6;
    sys_config.preamble_type = 0;

    if ((ret = woal_uap_ap_cfg_parse_data(&sys_config, buf)))
        goto done;

    /* If BSS already started stop it first and restart after changing the
       setting */
    if (priv->bss_started == MTRUE) {
        if ((ret = woal_uap_bss_ctrl(priv, MOAL_IOCTL_WAIT, UAP_BSS_STOP)))
            goto done;
        restart = 1;
    }

    /* If the security mode is configured as WEP or WPA-PSK, it will disable
       11n automatically, and if configured as open(off) or wpa2-psk, it will
       automatically enable 11n */
    if ((sys_config.protocol == PROTOCOL_STATIC_WEP) ||
        (sys_config.protocol == PROTOCOL_WPA)) {
        if (MLAN_STATUS_SUCCESS !=
            woal_uap_set_11n_status(&sys_config, MLAN_ACT_DISABLE)) {
            ret = -EFAULT;
            goto done;
        }
    } else {
        if (MLAN_STATUS_SUCCESS !=
            woal_uap_set_11n_status(&sys_config, MLAN_ACT_ENABLE)) {
            ret = -EFAULT;
            goto done;
        }
    }

    if (MLAN_STATUS_SUCCESS !=
        woal_set_get_sys_config(priv, MLAN_ACT_SET, MOAL_IOCTL_WAIT,
                                &sys_config)) {
        ret = -EFAULT;
        goto done;
    }

    /* Start the BSS after successful configuration */
    if (restart)
        ret = woal_uap_bss_ctrl(priv, MOAL_IOCTL_WAIT, UAP_BSS_START);

  done:
    LEAVE();
    return ret;
}

/**
 *  @brief uap BSS control ioctl handler
 *
 *  @param priv             A pointer to moal_private structure
 *  @param wait_option      Wait option
 *  @param data             BSS control type
 *  @return                 0 --success, otherwise fail
 */
int
woal_uap_bss_ctrl(moal_private * priv, t_u8 wait_option, int data)
{
    mlan_ioctl_req *req = NULL;
    mlan_ds_bss *bss = NULL;
    int ret = 0;

    ENTER();

    PRINTM(MIOCTL, "ioctl bss ctrl=%d\n", data);
    if ((data != UAP_BSS_START) && (data != UAP_BSS_STOP) &&
        (data != UAP_BSS_RESET)) {
        PRINTM(MERROR, "Invalid parameter: %d\n", data);
        ret = -EINVAL;
        goto done;
    }

    req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_bss));
    if (req == NULL) {
        ret = -ENOMEM;
        goto done;
    }
    bss = (mlan_ds_bss *) req->pbuf;
    switch (data) {
    case UAP_BSS_START:
        if (priv->bss_started == MTRUE) {
            PRINTM(MWARN, "Warning: BSS already started!\n");
            // goto done;
        } else {
            /* about to start bss: issue channel check */
            woal_11h_channel_check_ioctl(priv);
        }
        bss->sub_command = MLAN_OID_BSS_START;
        break;
    case UAP_BSS_STOP:
        if (priv->bss_started == MFALSE) {
            PRINTM(MWARN, "Warning: BSS already stopped!\n");
            // goto done;
        }
        bss->sub_command = MLAN_OID_BSS_STOP;
        break;
    case UAP_BSS_RESET:
        bss->sub_command = MLAN_OID_UAP_BSS_RESET;
        woal_cancel_cac_block(priv);
        break;
    }
    req->req_id = MLAN_IOCTL_BSS;
    req->action = MLAN_ACT_SET;

    if (MLAN_STATUS_SUCCESS != woal_request_ioctl(priv, req, MOAL_IOCTL_WAIT)) {
        ret = -EFAULT;
        goto done;
    }

    if (data == UAP_BSS_STOP || data == UAP_BSS_RESET)
        priv->bss_started = MFALSE;

  done:
    if (req)
        kfree(req);

    LEAVE();
    return ret;
}

/**
 *  @brief This function sets multicast addresses to firmware
 *
 *  @param dev     A pointer to net_device structure
 *  @return        N/A
 */
void
woal_uap_set_multicast_list(struct net_device *dev)
{
    ENTER();

    LEAVE();
}

/**
 *  @brief ioctl function - entry point
 *
 *  @param dev		A pointer to net_device structure
 *  @param req	   	A pointer to ifreq structure
 *  @param cmd 		Command
 *
 *  @return          0 --success, otherwise fail
 */
int
woal_uap_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
{
    int ret = 0;
    ENTER();
    PRINTM(MIOCTL, "uap_do_ioctl: ioctl cmd = 0x%x\n", cmd);
    switch (cmd) {
    case UAP_HOSTCMD:
        ret = woal_hostcmd_ioctl(dev, req);
        break;
    case UAP_IOCTL_CMD:
        ret = woal_uap_ioctl(dev, req);
        break;
    case UAP_POWER_MODE:
        ret = woal_uap_power_mode_ioctl(dev, req);
        break;
    case UAP_BSS_CTRL:
        ret = woal_uap_bss_ctrl_ioctl(dev, req);
        break;
    case UAP_WAPI_MSG:
        ret = woal_uap_set_wapi(dev, req);
        break;
    case UAP_BSS_CONFIG:
        ret = woal_uap_bss_cfg_ioctl(dev, req);
        break;
    case UAP_STA_DEAUTH:
        ret = woal_uap_sta_deauth_ioctl(dev, req);
        break;
    case UAP_RADIO_CTL:
        ret = woal_uap_radio_ctl(dev, req);
        break;
    case UAP_GET_STA_LIST:
        ret = woal_uap_get_sta_list_ioctl(dev, req);
        break;
    case UAP_CUSTOM_IE:
        ret = woal_custom_ie_ioctl(dev, req);
        break;
    case UAP_GET_BSS_TYPE:
        ret = woal_get_bss_type(dev, req);
        break;
    case WOAL_ANDROID_PRIV_CMD:
        ret = woal_android_priv_cmd(dev, req);
        break;
    default:
#ifdef UAP_WEXT
        ret = woal_uap_do_priv_ioctl(dev, req, cmd);
#else
        ret = -EOPNOTSUPP;
#endif
        break;
    }

    LEAVE();
    return ret;
}

/**
 *  @brief Get version
 *
 *  @param priv 		A pointer to moal_private structure
 *  @param version		A pointer to version buffer
 *  @param max_len		max length of version buffer
 *
 *  @return 	   		N/A
 */
void
woal_uap_get_version(moal_private * priv, char *version, int max_len)
{
    mlan_ds_get_info *info = NULL;
    mlan_ioctl_req *req = NULL;
    mlan_status status = MLAN_STATUS_SUCCESS;

    ENTER();

    req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_get_info));
    if (req == NULL) {
        LEAVE();
        return;
    }

    info = (mlan_ds_get_info *) req->pbuf;
    info->sub_command = MLAN_OID_GET_VER_EXT;
    req->req_id = MLAN_IOCTL_GET_INFO;
    req->action = MLAN_ACT_GET;

    status = woal_request_ioctl(priv, req, MOAL_PROC_WAIT);
    if (status == MLAN_STATUS_SUCCESS) {
        PRINTM(MINFO, "MOAL UAP VERSION: %s\n",
               info->param.ver_ext.version_str);
        snprintf(version, max_len, driver_version,
                 info->param.ver_ext.version_str);
    }

    if (req && (status != MLAN_STATUS_PENDING))
        kfree(req);

    LEAVE();
    return;
}

/**
 *  @brief Get uap statistics
 *
 *  @param priv 		        A pointer to moal_private structure
 *  @param wait_option          Wait option
 *  @param ustats               A pointer to mlan_ds_uap_stats structure
 *
 *  @return                     MLAN_STATUS_SUCCESS/MLAN_STATUS_PENDING -- success, otherwise fail
 */
mlan_status
woal_uap_get_stats(moal_private * priv, t_u8 wait_option,
                   mlan_ds_uap_stats * ustats)
{
    mlan_ds_get_info *info = NULL;
    mlan_ioctl_req *req = NULL;
    mlan_status status = MLAN_STATUS_SUCCESS;

    ENTER();

    req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_get_info));
    if (req == NULL) {
        LEAVE();
        return MLAN_STATUS_FAILURE;
    }

    info = (mlan_ds_get_info *) req->pbuf;
    info->sub_command = MLAN_OID_GET_STATS;
    req->req_id = MLAN_IOCTL_GET_INFO;
    req->action = MLAN_ACT_GET;

    status = woal_request_ioctl(priv, req, wait_option);
    if (status == MLAN_STATUS_SUCCESS) {
        if (ustats)
            memcpy(ustats, &info->param.ustats, sizeof(mlan_ds_uap_stats));
#ifdef UAP_WEXT
        priv->w_stats.discard.fragment = info->param.ustats.fcs_error_count;
        priv->w_stats.discard.retries = info->param.ustats.retry_count;
        priv->w_stats.discard.misc = info->param.ustats.ack_failure_count;
#endif
    }

    if (req && (status != MLAN_STATUS_PENDING))
        kfree(req);

    LEAVE();
    return status;
}

/**
 *  @brief Set/Get system configuration parameters
 *
 *  @param priv 		    A pointer to moal_private structure
 *  @param action           MLAN_ACT_SET or MLAN_ACT_GET
 *  @param wait_option      Wait option
 *  @param sys_cfg          A pointer to mlan_uap_bss_param structure
 *
 *  @return                 MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
 */
mlan_status
woal_set_get_sys_config(moal_private * priv, t_u16 action, t_u8 wait_option,
                        mlan_uap_bss_param * sys_cfg)
{
    mlan_status ret = MLAN_STATUS_SUCCESS;
    mlan_ds_bss *bss = NULL;
    mlan_ioctl_req *req = NULL;

    ENTER();

    req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_bss));
    if (req == NULL) {
        ret = MLAN_STATUS_FAILURE;
        goto done;
    }

    bss = (mlan_ds_bss *) req->pbuf;
    bss->sub_command = MLAN_OID_UAP_BSS_CONFIG;
    req->req_id = MLAN_IOCTL_BSS;
    req->action = action;

    if (action == MLAN_ACT_SET) {
        memcpy(&bss->param.bss_config, sys_cfg, sizeof(mlan_uap_bss_param));
    }

    if (MLAN_STATUS_SUCCESS != woal_request_ioctl(priv, req, wait_option)) {
        ret = MLAN_STATUS_FAILURE;
        goto done;
    }

    if (action == MLAN_ACT_GET) {
        memcpy(sys_cfg, &bss->param.bss_config, sizeof(mlan_uap_bss_param));
    }

  done:
    if (req)
        kfree(req);

    LEAVE();
    return ret;
}

/**
 *  @brief Set invalid data for each member of mlan_uap_bss_param
 *  structure
 *
 *  @param config   A pointer to mlan_uap_bss_param structure
 *
 *  @return         N/A
 */
void
woal_set_sys_config_invalid_data(mlan_uap_bss_param * config)
{
    ENTER();

    memset(config, 0, sizeof(mlan_uap_bss_param));
    config->bcast_ssid_ctl = 0x7F;
    config->radio_ctl = 0x7F;
    config->dtim_period = 0x7F;
    config->beacon_period = 0x7FFF;
    config->tx_data_rate = 0x7FFF;
    config->mcbc_data_rate = 0x7FFF;
    config->tx_power_level = 0x7F;
    config->tx_antenna = 0x7F;
    config->rx_antenna = 0x7F;
    config->pkt_forward_ctl = 0x7F;
    config->max_sta_count = 0x7FFF;
    config->auth_mode = 0x7F;
    config->sta_ageout_timer = 0x7FFFFFFF;
    config->pairwise_update_timeout = 0x7FFFFFFF;
    config->pwk_retries = 0x7FFFFFFF;
    config->groupwise_update_timeout = 0x7FFFFFFF;
    config->gwk_retries = 0x7FFFFFFF;
    config->mgmt_ie_passthru_mask = 0x7FFFFFFF;
    config->ps_sta_ageout_timer = 0x7FFFFFFF;
    config->rts_threshold = 0x7FFF;
    config->frag_threshold = 0x7FFF;
    config->retry_limit = 0x7FFF;
    config->filter.filter_mode = 0x7FFF;
    config->filter.mac_count = 0x7FFF;
    config->wpa_cfg.rsn_protection = 0x7F;
    config->wpa_cfg.gk_rekey_time = 0x7FFFFFFF;
    config->enable_2040coex = 0x7F;
    config->wmm_para.qos_info = 0x7F;

    LEAVE();
}