wl_wext.c 100 KB
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 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988
/*******************************************************************************
 * Agere Systems Inc.
 * Wireless device driver for Linux (wlags49).
 *
 * Copyright (c) 1998-2003 Agere Systems Inc.
 * All rights reserved.
 *   http://www.agere.com
 *
 * Initially developed by TriplePoint, Inc.
 *   http://www.triplepoint.com
 *
 *------------------------------------------------------------------------------
 *
 * SOFTWARE LICENSE
 *
 * This software is provided subject to the following terms and conditions,
 * which you should read carefully before using the software.  Using this
 * software indicates your acceptance of these terms and conditions.  If you do
 * not agree with these terms and conditions, do not use the software.
 *
 * Copyright ยฉ 2003 Agere Systems Inc.
 * All rights reserved.
 *
 * Redistribution and use in source or binary forms, with or without
 * modifications, are permitted provided that the following conditions are met:
 *
 * . Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following Disclaimer as comments in the code as
 *    well as in the documentation and/or other materials provided with the
 *    distribution.
 *
 * . Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following Disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * . Neither the name of Agere Systems Inc. nor the names of the contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * Disclaimer
 *
 * THIS SOFTWARE IS PROVIDED ย“AS ISย” AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  ANY
 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 ******************************************************************************/

/*******************************************************************************
 *  include files
 ******************************************************************************/
#include <wl_version.h>

#include <linux/if_arp.h>
#include <linux/ioport.h>
#include <linux/delay.h>
#include <asm/uaccess.h>

#include <debug.h>
#include <hcf.h>
#include <hcfdef.h>

#include <wl_if.h>
#include <wl_internal.h>
#include <wl_util.h>
#include <wl_main.h>
#include <wl_wext.h>
#include <wl_priv.h>

/*******************************************************************************
 * global definitions
 ******************************************************************************/
#if DBG
extern dbg_info_t *DbgInfo;
#endif  // DBG


/* Set up the LTV to program the appropriate key */
static int hermes_set_tkip_keys(ltv_t *ltv, u16 key_idx, u8 *addr,
				int set_tx, u8 *seq, u8 *key, size_t key_len)
{
	int ret = -EINVAL;
	int buf_idx = 0;
	hcf_8 tsc[IW_ENCODE_SEQ_MAX_SIZE] =
		{ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 };

	DBG_ENTER(DbgInfo);

	/*
	 * Check the key index here; if 0, load as Pairwise Key, otherwise,
	 * load as a group key. Note that for the Hermes, the RIDs for
	 * group/pairwise keys are different from each other and different
	 * than the default WEP keys as well.
	 */
	switch (key_idx) {
	case 0:
		ltv->len = 28;
		ltv->typ = CFG_ADD_TKIP_MAPPED_KEY;

		/* Load the BSSID */
		memcpy(&ltv->u.u8[buf_idx], addr, ETH_ALEN);
		buf_idx += ETH_ALEN;

		/* Load the TKIP key */
		memcpy(&ltv->u.u8[buf_idx], &key[0], 16);
		buf_idx += 16;

		/* Load the TSC */
		memcpy(&ltv->u.u8[buf_idx], tsc, IW_ENCODE_SEQ_MAX_SIZE);
		buf_idx += IW_ENCODE_SEQ_MAX_SIZE;

		/* Load the RSC */
		memcpy(&ltv->u.u8[buf_idx], seq, IW_ENCODE_SEQ_MAX_SIZE);
		buf_idx += IW_ENCODE_SEQ_MAX_SIZE;

		/* Load the TxMIC key */
		memcpy(&ltv->u.u8[buf_idx], &key[16], 8);
		buf_idx += 8;

		/* Load the RxMIC key */
		memcpy(&ltv->u.u8[buf_idx], &key[24], 8);

		ret = 0;
		break;
	case 1:
	case 2:
	case 3:
		ltv->len = 26;
		ltv->typ = CFG_ADD_TKIP_DEFAULT_KEY;

		/* Load the key Index */

		/* If this is a Tx Key, set bit 8000 */
		if (set_tx)
			key_idx |= 0x8000;
		ltv->u.u16[buf_idx] = cpu_to_le16(key_idx);
		buf_idx += 2;

		/* Load the RSC */
		memcpy(&ltv->u.u8[buf_idx], seq, IW_ENCODE_SEQ_MAX_SIZE);
		buf_idx += IW_ENCODE_SEQ_MAX_SIZE;

		/* Load the TKIP, TxMIC, and RxMIC keys in one shot, because in
		   CFG_ADD_TKIP_DEFAULT_KEY they are back-to-back */
		memcpy(&ltv->u.u8[buf_idx], key, key_len);
		buf_idx += key_len;

		/* Load the TSC */
		memcpy(&ltv->u.u8[buf_idx], tsc, IW_ENCODE_SEQ_MAX_SIZE);

		ret = 0;
		break;
	default:
		break;
	}

	DBG_LEAVE(DbgInfo);
	return ret;
}

/* Set up the LTV to clear the appropriate key */
static int hermes_clear_tkip_keys(ltv_t *ltv, u16 key_idx, u8 *addr)
{
	int ret;

	switch (key_idx) {
	case 0:
		if (memcmp(addr, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) {
			ltv->len = 7;
			ltv->typ = CFG_REMOVE_TKIP_MAPPED_KEY;
			memcpy(&ltv->u.u8[0], addr, ETH_ALEN);
			ret = 0;
		}
		break;
	case 1:
	case 2:
	case 3:
		/* Clear the Group TKIP keys by index */
		ltv->len = 2;
		ltv->typ = CFG_REMOVE_TKIP_DEFAULT_KEY;
		ltv->u.u16[0] = cpu_to_le16(key_idx);

		ret = 0;
		break;
	default:
		break;
	}

	return ret;
}

/* Set the WEP keys in the wl_private structure */
static int hermes_set_wep_keys(struct wl_private *lp, u16 key_idx,
			       u8 *key, size_t key_len,
			       bool enable, bool set_tx)
{
	hcf_8  encryption_state = lp->EnableEncryption;
	int tk = lp->TransmitKeyID - 1;	/* current key */
	int ret = 0;

	/* Is encryption supported? */
	if (!wl_has_wep(&(lp->hcfCtx))) {
		DBG_WARNING(DbgInfo, "WEP not supported on this device\n");
		ret = -EOPNOTSUPP;
		goto out;
	}

	DBG_NOTICE(DbgInfo, "pointer: %p, length: %d\n",
		   key, key_len);

	/* Check the size of the key */
	switch (key_len) {
	case MIN_KEY_SIZE:
	case MAX_KEY_SIZE:

		/* Check the index */
		if ((key_idx < 0) || (key_idx >= MAX_KEYS))
			key_idx = tk;

		/* Cleanup */
		memset(lp->DefaultKeys.key[key_idx].key, 0, MAX_KEY_SIZE);

		/* Copy the key in the driver */
		memcpy(lp->DefaultKeys.key[key_idx].key, key, key_len);

		/* Set the length */
		lp->DefaultKeys.key[key_idx].len = key_len;

		DBG_NOTICE(DbgInfo, "encoding.length: %d\n", key_len);
		DBG_NOTICE(DbgInfo, "set key: %s(%d) [%d]\n",
			   lp->DefaultKeys.key[key_idx].key,
			   lp->DefaultKeys.key[key_idx].len, key_idx);

		/* Enable WEP (if possible) */
		if ((key_idx == tk) && (lp->DefaultKeys.key[tk].len > 0))
			lp->EnableEncryption = 1;

		break;

	case 0:
		/* Do we want to just set the current transmit key? */
		if (set_tx && (key_idx >= 0) && (key_idx < MAX_KEYS)) {
			DBG_NOTICE(DbgInfo, "index: %d; len: %d\n", key_idx,
				   lp->DefaultKeys.key[key_idx].len);

			if (lp->DefaultKeys.key[key_idx].len > 0) {
				lp->TransmitKeyID    = key_idx + 1;
				lp->EnableEncryption = 1;
			} else {
				DBG_WARNING(DbgInfo, "Problem setting the current TxKey\n");
				ret = -EINVAL;
			}
		}
		break;

	default:
		DBG_WARNING(DbgInfo, "Invalid Key length\n");
		ret = -EINVAL;
		goto out;
	}

	/* Read the flags */
	if (enable) {
		lp->EnableEncryption = 1;
		lp->wext_enc = IW_ENCODE_ALG_WEP;
	} else {
		lp->EnableEncryption = 0;	/* disable encryption */
		lp->wext_enc = IW_ENCODE_ALG_NONE;
	}

	DBG_TRACE(DbgInfo, "encryption_state :     %d\n", encryption_state);
	DBG_TRACE(DbgInfo, "lp->EnableEncryption : %d\n", lp->EnableEncryption);
	DBG_TRACE(DbgInfo, "erq->length          : %d\n", key_len);

	/* Write the changes to the card */
	if (ret == 0) {
		DBG_NOTICE(DbgInfo, "encrypt: %d, ID: %d\n", lp->EnableEncryption,
			   lp->TransmitKeyID);

		if (lp->EnableEncryption == encryption_state) {
			if (key_len != 0) {
				/* Dynamic WEP key update */
				wl_set_wep_keys(lp);
			}
		} else {
			/* To switch encryption on/off, soft reset is
			 * required */
			wl_apply(lp);
		}
	}

out:
	return ret;
}

/*******************************************************************************
 *	wireless_commit()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Commit
 *  protocol used.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
static int wireless_commit(struct net_device *dev,
			   struct iw_request_info *info,
			   union iwreq_data *rqu, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;
	/*------------------------------------------------------------------------*/

	DBG_FUNC( "wireless_commit" );
	DBG_ENTER(DbgInfo);

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	wl_apply(lp);

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_commit
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_protocol()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Returns a vendor-defined string that should identify the wireless
 *  protocol used.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
static int wireless_get_protocol(struct net_device *dev, struct iw_request_info *info, char *name, char *extra)
{
	DBG_FUNC( "wireless_get_protocol" );
	DBG_ENTER( DbgInfo );

	/* Originally, the driver was placing the string "Wireless" here. However,
	   the wireless extensions (/linux/wireless.h) indicate this string should
	   describe the wireless protocol. */

	strcpy(name, "IEEE 802.11b");

	DBG_LEAVE(DbgInfo);
	return 0;
} // wireless_get_protocol
/*============================================================================*/




/*******************************************************************************
 *	wireless_set_frequency()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Sets the frequency (channel) on which the card should Tx/Rx.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_set_frequency(struct net_device *dev, struct iw_request_info *info, struct iw_freq *freq, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int channel = 0;
	int ret     = 0;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_set_frequency" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	if( !capable( CAP_NET_ADMIN )) {
		ret = -EPERM;
		DBG_LEAVE( DbgInfo );
		return ret;
	}


	/* If frequency specified, look up channel */
	if( freq->e == 1 ) {
		int f = freq->m / 100000;
		channel = wl_get_chan_from_freq( f );
	}


	/* Channel specified */
	if( freq->e == 0 ) {
		channel = freq->m;
	}


	/* If the channel is an 802.11a channel, set Bit 8 */
	if( channel > 14 ) {
		channel = channel | 0x100;
	}


	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	lp->Channel = channel;


	/* Commit the adapter parameters */
	wl_apply( lp );

	/* Send an event that channel/freq has been set */
	wl_wext_event_freq( lp->dev );

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_set_frequency
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_frequency()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Gets the frequency (channel) on which the card is Tx/Rx.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
static int wireless_get_frequency(struct net_device *dev, struct iw_request_info *info, struct iw_freq *freq, char *extra)

{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = -1;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_frequency" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	lp->ltvRecord.len = 2;
	lp->ltvRecord.typ = CFG_CUR_CHANNEL;

	ret = hcf_get_info( &(lp->hcfCtx), (LTVP)&( lp->ltvRecord ));
	if( ret == HCF_SUCCESS ) {
		hcf_16 channel = CNV_LITTLE_TO_INT( lp->ltvRecord.u.u16[0] );

		freq->m = wl_get_freq_from_chan( channel ) * 100000;
		freq->e = 1;
	}

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

	ret = (ret == HCF_SUCCESS ? 0 : -EFAULT);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_frequency
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_range()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to provide misc info and statistics about the
 *  wireless device.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_range(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long      flags;
	struct iw_range   *range = (struct iw_range *) extra;
	int                ret = 0;
	int                status = -1;
	int                count;
	__u16             *pTxRate;
	int                retries = 0;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_range" );
	DBG_ENTER( DbgInfo );

	/* Set range information */
	data->length = sizeof(struct iw_range);
	memset(range, 0, sizeof(struct iw_range));

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/* Set range information */
	memset( range, 0, sizeof( struct iw_range ));

retry:
	/* Get the current transmit rate from the adapter */
	lp->ltvRecord.len = 1 + (sizeof(*pTxRate) / sizeof(hcf_16));
	lp->ltvRecord.typ = CFG_CUR_TX_RATE;

	status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
	if( status != HCF_SUCCESS ) {
		/* Recovery action: reset and retry up to 10 times */
		DBG_TRACE( DbgInfo, "Get CFG_CUR_TX_RATE failed: 0x%x\n", status );

		if (retries < 10) {
			retries++;

			/* Holding the lock too long, make a gap to allow other processes */
			wl_unlock(lp, &flags);
			wl_lock( lp, &flags );

			status = wl_reset( dev );
			if ( status != HCF_SUCCESS ) {
				DBG_TRACE( DbgInfo, "reset failed: 0x%x\n", status );

				ret = -EFAULT;
				goto out_unlock;
			}

			/* Holding the lock too long, make a gap to allow other processes */
			wl_unlock(lp, &flags);
			wl_lock( lp, &flags );

			goto retry;

		} else {
			DBG_TRACE( DbgInfo, "Get CFG_CUR_TX_RATE failed: %d retries\n", retries );
			ret = -EFAULT;
			goto out_unlock;
		}
	}

	/* Holding the lock too long, make a gap to allow other processes */
	wl_unlock(lp, &flags);
	wl_lock( lp, &flags );

	pTxRate = (__u16 *)&( lp->ltvRecord.u.u32 );

	range->throughput = CNV_LITTLE_TO_INT( *pTxRate ) * MEGABIT;

	if (retries > 0) {
		DBG_TRACE( DbgInfo, "Get CFG_CUR_TX_RATE succes: %d retries\n", retries );
	}

	// NWID - NOT SUPPORTED


	/* Channel/Frequency Info */
	range->num_channels = RADIO_CHANNELS;


	/* Signal Level Thresholds */
	range->sensitivity = RADIO_SENSITIVITY_LEVELS;


	/* Link quality */
	range->max_qual.qual     = (u_char)HCF_MAX_COMM_QUALITY;

	/* If the value returned in /proc/net/wireless is greater than the maximum range,
	   iwconfig assumes that the value is in dBm. Because an unsigned char is used,
	   it requires a bit of contorsion... */

	range->max_qual.level   = (u_char)( dbm( HCF_MIN_SIGNAL_LEVEL ) - 1 );
	range->max_qual.noise   = (u_char)( dbm( HCF_MIN_NOISE_LEVEL ) - 1 );


	/* Set available rates */
	range->num_bitrates = 0;

	lp->ltvRecord.len = 6;
	lp->ltvRecord.typ = CFG_SUPPORTED_DATA_RATES;

	status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
	if( status == HCF_SUCCESS ) {
		for( count = 0; count < MAX_RATES; count++ )
			if( lp->ltvRecord.u.u8[count+2] != 0 ) {
				range->bitrate[count] = lp->ltvRecord.u.u8[count+2] * MEGABIT / 2;
				range->num_bitrates++;
			}
	} else {
		DBG_TRACE( DbgInfo, "CFG_SUPPORTED_DATA_RATES: 0x%x\n", status );
		ret = -EFAULT;
		goto out_unlock;
	}

	/* RTS Threshold info */
	range->min_rts   = MIN_RTS_BYTES;
	range->max_rts   = MAX_RTS_BYTES;

	// Frag Threshold info - NOT SUPPORTED

	// Power Management info - NOT SUPPORTED

	/* Encryption */

	/* Holding the lock too long, make a gap to allow other processes */
	wl_unlock(lp, &flags);
	wl_lock( lp, &flags );

	/* Is WEP supported? */

	if( wl_has_wep( &( lp->hcfCtx ))) {
		/* WEP: RC4 40 bits */
		range->encoding_size[0]      = MIN_KEY_SIZE;

		/* RC4 ~128 bits */
		range->encoding_size[1]      = MAX_KEY_SIZE;
		range->num_encoding_sizes    = 2;
		range->max_encoding_tokens   = MAX_KEYS;
	}

	/* Tx Power Info */
	range->txpower_capa  = IW_TXPOW_MWATT;
	range->num_txpower   = 1;
	range->txpower[0]    = RADIO_TX_POWER_MWATT;

	/* Wireless Extension Info */
	range->we_version_compiled   = WIRELESS_EXT;
	range->we_version_source     = WIRELESS_SUPPORT;

	// Retry Limits and Lifetime - NOT SUPPORTED

	/* Holding the lock too long, make a gap to allow other processes */
	wl_unlock(lp, &flags);
	wl_lock( lp, &flags );

	DBG_TRACE( DbgInfo, "calling wl_wireless_stats\n" );
	wl_wireless_stats( lp->dev );
	range->avg_qual = lp->wstats.qual;
	DBG_TRACE( DbgInfo, "wl_wireless_stats done\n" );

	/* Event capability (kernel + driver) */
	IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
	IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
	IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
	IW_EVENT_CAPA_SET(range->event_capa, IWEVREGISTERED);
	IW_EVENT_CAPA_SET(range->event_capa, IWEVEXPIRED);
	IW_EVENT_CAPA_SET(range->event_capa, IWEVMICHAELMICFAILURE);
	IW_EVENT_CAPA_SET(range->event_capa, IWEVASSOCREQIE);
	IW_EVENT_CAPA_SET(range->event_capa, IWEVASSOCRESPIE);

	range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
	range->scan_capa = IW_SCAN_CAPA_NONE;

out_unlock:
    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

	DBG_LEAVE(DbgInfo);
	return ret;
} // wireless_get_range
/*============================================================================*/


/*******************************************************************************
 *	wireless_get_bssid()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Gets the BSSID the wireless device is currently associated with.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_bssid(struct net_device *dev, struct iw_request_info *info, struct sockaddr *ap_addr, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;
#if 1 //;? (HCF_TYPE) & HCF_TYPE_STA
	int status = -1;
#endif /* (HCF_TYPE) & HCF_TYPE_STA */
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_bssid" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	memset( &ap_addr->sa_data, 0, ETH_ALEN );

	ap_addr->sa_family = ARPHRD_ETHER;

	/* Assume AP mode here, which means the BSSID is our own MAC address. In
	   STA mode, this address will be overwritten with the actual BSSID using
	   the code below. */
	memcpy(&ap_addr->sa_data, lp->dev->dev_addr, ETH_ALEN);


#if 1 //;? (HCF_TYPE) & HCF_TYPE_STA
					//;?should we return an error status in AP mode

	if ( CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_STA  ) {
		/* Get Current BSSID */
		lp->ltvRecord.typ = CFG_CUR_BSSID;
		lp->ltvRecord.len = 4;
		status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));

		if( status == HCF_SUCCESS ) {
			/* Copy info into sockaddr struct */
			memcpy(&ap_addr->sa_data, lp->ltvRecord.u.u8, ETH_ALEN);
		} else {
			ret = -EFAULT;
		}
	}

#endif // (HCF_TYPE) & HCF_TYPE_STA

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE(DbgInfo);
	return ret;
} // wireless_get_bssid
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_ap_list()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Gets the results of a network scan.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 *  NOTE: SIOCGIWAPLIST has been deprecated by SIOCSIWSCAN. This function
 *       implements SIOCGIWAPLIST only to provide backwards compatibility. For
 *       all systems using WIRELESS_EXT v14 and higher, use SIOCSIWSCAN!
 *
 ******************************************************************************/
static int wireless_get_ap_list (struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long	  flags;
	int                 ret;
	int                 num_aps = -1;
	int                 sec_count = 0;
	hcf_32              count;
	struct sockaddr     *hwa = NULL;
	struct iw_quality   *qual = NULL;
#ifdef WARP
	ScanResult			*p = &lp->scan_results;
#else
	ProbeResult         *p = &lp->probe_results;
#endif  // WARP
	/*------------------------------------------------------------------------*/

	DBG_FUNC( "wireless_get_ap_list" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/* Set the completion state to FALSE */
	lp->scan_results.scan_complete = FALSE;
	lp->probe_results.scan_complete = FALSE;
	/* Channels to scan */
	lp->ltvRecord.len       = 2;
	lp->ltvRecord.typ       = CFG_SCAN_CHANNELS_2GHZ;
	lp->ltvRecord.u.u16[0]  = CNV_INT_TO_LITTLE( 0x7FFF );
	ret = hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
	DBG_TRACE( DbgInfo, "CFG_SCAN_CHANNELS_2GHZ result: 0x%x\n", ret );

	/* Set the SCAN_SSID to "ANY". Using this RID for scan prevents the need to
	   disassociate from the network we are currently on */
	lp->ltvRecord.len       = 2;
	lp->ltvRecord.typ       = CFG_SCAN_SSID;
	lp->ltvRecord.u.u16[0]  = CNV_INT_TO_LITTLE( 0 );
	ret = hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
	DBG_TRACE( DbgInfo, "CFG_SCAN_SSID to 'any' ret: 0x%x\n", ret );

	/* Initiate the scan */
#ifdef WARP
	ret = hcf_action( &( lp->hcfCtx ), MDD_ACT_SCAN );
#else
	ret = hcf_action( &( lp->hcfCtx ), HCF_ACT_ACS_SCAN );
#endif  // WARP

    	wl_act_int_on( lp );

	//;? unlock? what about the access to lp below? is it broken?
	wl_unlock(lp, &flags);

	if( ret == HCF_SUCCESS ) {
		DBG_TRACE( DbgInfo, "SUCCESSFULLY INITIATED SCAN...\n" );
		while( (*p).scan_complete == FALSE && ret == HCF_SUCCESS ) {
			DBG_TRACE( DbgInfo, "Waiting for scan results...\n" );
			/* Abort the scan if we've waited for more than MAX_SCAN_TIME_SEC */
			if( sec_count++ > MAX_SCAN_TIME_SEC ) {
				ret = -EIO;
			} else {
				/* Wait for 1 sec in 10ms intervals, scheduling the kernel to do
				   other things in the meantime, This prevents system lockups by
				   giving some time back to the kernel */
				for( count = 0; count < 100; count ++ ) {
					mdelay( 10 );
					schedule( );
				}
			}
		}

		rmb();

		if ( ret != HCF_SUCCESS ) {
			DBG_ERROR( DbgInfo, "timeout waiting for scan results\n" );
		} else {
			num_aps             = (*p)/*lp->probe_results*/.num_aps;
			if (num_aps > IW_MAX_AP) {
				num_aps = IW_MAX_AP;
			}
			data->length = num_aps;
			hwa = (struct sockaddr *)extra;
			qual = (struct iw_quality *) extra +
					( sizeof( struct sockaddr ) * num_aps );

			/* This flag is used to tell the user if we provide quality
			   information. Since we provide signal/noise levels but no
			   quality info on a scan, this is set to 0. Setting to 1 and
			   providing a quality of 0 produces weird results. If we ever
			   provide quality (or can calculate it), this can be changed */
			data->flags = 0;

			for( count = 0; count < num_aps; count++ ) {
#ifdef WARP
				memcpy( hwa[count].sa_data,
						(*p)/*lp->scan_results*/.APTable[count].bssid, ETH_ALEN );
#else  //;?why use BSSID and bssid as names in seemingly very comparable situations
				DBG_PRINT("BSSID: %pM\n",
						(*p).ProbeTable[count].BSSID);
				memcpy( hwa[count].sa_data,
						(*p)/*lp->probe_results*/.ProbeTable[count].BSSID, ETH_ALEN );
#endif // WARP
			}
			/* Once the data is copied to the wireless struct, invalidate the
			   scan result to initiate a rescan on the next request */
			(*p)/*lp->probe_results*/.scan_complete = FALSE;
			/* Send the wireless event that the scan has completed, just in case
			   it's needed */
			wl_wext_event_scan_complete( lp->dev );
		}
	}
out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_ap_list
/*============================================================================*/




/*******************************************************************************
 *	wireless_set_sensitivity()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Sets the sensitivity (distance between APs) of the wireless card.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_set_sensitivity(struct net_device *dev, struct iw_request_info *info, struct iw_param *sens, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;
	int dens = sens->value;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_set_sensitivity" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	if(( dens < 1 ) || ( dens > 3 )) {
		ret = -EINVAL;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	lp->DistanceBetweenAPs = dens;
	wl_apply( lp );

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_set_sensitivity
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_sensitivity()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Gets the sensitivity (distance between APs) of the wireless card.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_sensitivity(struct net_device *dev, struct iw_request_info *info, struct iw_param *sens, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	int ret = 0;
	/*------------------------------------------------------------------------*/
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_sensitivity" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	/* not worth locking ... */
	sens->value = lp->DistanceBetweenAPs;
	sens->fixed = 0;	/* auto */
out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_sensitivity
/*============================================================================*/




/*******************************************************************************
 *	wireless_set_essid()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Sets the ESSID (network name) that the wireless device should associate
 *  with.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_set_essid(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *ssid)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;

	DBG_FUNC( "wireless_set_essid" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	if (data->flags != 0 && data->length > HCF_MAX_NAME_LEN + 1) {
		ret = -EINVAL;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	memset( lp->NetworkName, 0, sizeof( lp->NetworkName ));

	/* data->flags is zero to ask for "any" */
	if( data->flags == 0 ) {
		/* Need this because in STAP build PARM_DEFAULT_SSID is "LinuxAP"
		 * ;?but there ain't no STAP anymore*/
		if ( CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_STA  ) {
			strcpy( lp->NetworkName, "ANY" );
		} else {
			//strcpy( lp->NetworkName, "ANY" );
			strcpy( lp->NetworkName, PARM_DEFAULT_SSID );
		}
	} else {
		memcpy( lp->NetworkName, ssid, data->length );
	}

	DBG_NOTICE( DbgInfo, "set NetworkName: %s\n", ssid );

	/* Commit the adapter parameters */
	wl_apply( lp );

	/* Send an event that ESSID has been set */
	wl_wext_event_essid( lp->dev );

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_set_essid
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_essid()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Gets the ESSID (network name) that the wireless device is associated
 *  with.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_essid(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *essid)

{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int         ret = 0;
	int         status = -1;
	wvName_t    *pName;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_essid" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/* Get the desired network name */
	lp->ltvRecord.len = 1 + ( sizeof( *pName ) / sizeof( hcf_16 ));


#if 1 //;? (HCF_TYPE) & HCF_TYPE_STA
					//;?should we return an error status in AP mode

	lp->ltvRecord.typ = CFG_DESIRED_SSID;

#endif


#if 1 //;? (HCF_TYPE) & HCF_TYPE_AP
		//;?should we restore this to allow smaller memory footprint

	if ( CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_AP  ) {
		lp->ltvRecord.typ = CFG_CNF_OWN_SSID;
	}

#endif // HCF_AP


	status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
	if( status == HCF_SUCCESS ) {
		pName = (wvName_t *)&( lp->ltvRecord.u.u32 );

		/* Endian translate the string length */
		pName->length = CNV_LITTLE_TO_INT( pName->length );

		/* Copy the information into the user buffer */
		data->length = pName->length;

		if( pName->length < HCF_MAX_NAME_LEN ) {
			pName->name[pName->length] = '\0';
		}

		data->flags = 1;


#if 1 //;? (HCF_TYPE) & HCF_TYPE_STA
					//;?should we return an error status in AP mode

		/* if desired is null ("any"), return current or "any" */
		if( pName->name[0] == '\0' ) {
			/* Get the current network name */
			lp->ltvRecord.len = 1 + ( sizeof(*pName ) / sizeof( hcf_16 ));
			lp->ltvRecord.typ = CFG_CUR_SSID;

			status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));

			if( status == HCF_SUCCESS ) {
				pName = (wvName_t *)&( lp->ltvRecord.u.u32 );

				/* Endian translate the string length */
				pName->length = CNV_LITTLE_TO_INT( pName->length );

				/* Copy the information into the user buffer */
				data->length = pName->length;
				data->flags = 1;
			} else {
				ret = -EFAULT;
				goto out_unlock;
			}
		}

#endif // HCF_STA

		if (pName->length > IW_ESSID_MAX_SIZE) {
			ret = -EFAULT;
			goto out_unlock;
		}

		memcpy(essid, pName->name, pName->length);
	} else {
		ret = -EFAULT;
		goto out_unlock;
	}

out_unlock:
    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_essid
/*============================================================================*/




/*******************************************************************************
 *	wireless_set_encode()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Sets the encryption keys and status (enable or disable).
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_set_encode(struct net_device *dev, struct iw_request_info *info, struct iw_point *erq, char *keybuf)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int key_idx = (erq->flags & IW_ENCODE_INDEX) - 1;
	int ret = 0;
	bool enable = true;

	DBG_ENTER(DbgInfo);

	if (lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	if (erq->flags & IW_ENCODE_DISABLED)
		enable = false;

	wl_lock(lp, &flags);

	wl_act_int_off(lp);

	ret = hermes_set_wep_keys(lp, key_idx, keybuf, erq->length,
				  enable, true);

	/* Send an event that Encryption has been set */
	if (ret == 0)
		wl_wext_event_encode(dev);

	wl_act_int_on(lp);

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE(DbgInfo);
	return ret;
}

/*******************************************************************************
 *	wireless_get_encode()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Gets the encryption keys and status.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_encode(struct net_device *dev, struct iw_request_info *info, struct iw_point *erq, char *key)

{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;
	int index;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_encode" );
	DBG_ENTER( DbgInfo );
	DBG_NOTICE(DbgInfo, "GIWENCODE: encrypt: %d, ID: %d\n", lp->EnableEncryption, lp->TransmitKeyID);

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	/* Only super-user can see WEP key */
	if( !capable( CAP_NET_ADMIN )) {
		ret = -EPERM;
		DBG_LEAVE( DbgInfo );
		return ret;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/* Is it supported? */
	if( !wl_has_wep( &( lp->hcfCtx ))) {
		ret = -EOPNOTSUPP;
		goto out_unlock;
	}

	/* Basic checking */
	index = (erq->flags & IW_ENCODE_INDEX ) - 1;


	/* Set the flags */
	erq->flags = 0;

	if( lp->EnableEncryption == 0 ) {
		erq->flags |= IW_ENCODE_DISABLED;
	}

	/* Which key do we want */
	if(( index < 0 ) || ( index >= MAX_KEYS )) {
		index = lp->TransmitKeyID - 1;
	}

	erq->flags |= index + 1;

	/* Copy the key to the user buffer */
	erq->length = lp->DefaultKeys.key[index].len;

	memcpy(key, lp->DefaultKeys.key[index].key, erq->length);

out_unlock:

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_encode
/*============================================================================*/




/*******************************************************************************
 *	wireless_set_nickname()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Sets the nickname, or station name, of the wireless device.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_set_nickname(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *nickname)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_set_nickname" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

#if 0 //;? Needed, was present in original code but not in 7.18 Linux 2.6 kernel version
	if( !capable(CAP_NET_ADMIN )) {
		ret = -EPERM;
		DBG_LEAVE( DbgInfo );
		return ret;
	}
#endif

	/* Validate the new value */
	if(data->length > HCF_MAX_NAME_LEN) {
		ret = -EINVAL;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	memset( lp->StationName, 0, sizeof( lp->StationName ));

	memcpy( lp->StationName, nickname, data->length );

	/* Commit the adapter parameters */
	wl_apply( lp );

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_set_nickname
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_nickname()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Gets the nickname, or station name, of the wireless device.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_nickname(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *nickname)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int         ret = 0;
	int         status = -1;
	wvName_t    *pName;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_nickname" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/* Get the current station name */
	lp->ltvRecord.len = 1 + ( sizeof( *pName ) / sizeof( hcf_16 ));
	lp->ltvRecord.typ = CFG_CNF_OWN_NAME;

	status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));

	if( status == HCF_SUCCESS ) {
		pName = (wvName_t *)&( lp->ltvRecord.u.u32 );

		/* Endian translate the length */
		pName->length = CNV_LITTLE_TO_INT( pName->length );

		if ( pName->length > IW_ESSID_MAX_SIZE ) {
			ret = -EFAULT;
		} else {
			/* Copy the information into the user buffer */
			data->length = pName->length;
			memcpy(nickname, pName->name, pName->length);
		}
	} else {
		ret = -EFAULT;
	}

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE(DbgInfo);
	return ret;
} // wireless_get_nickname
/*============================================================================*/




/*******************************************************************************
 *	wireless_set_porttype()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Sets the port type of the wireless device.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_set_porttype(struct net_device *dev, struct iw_request_info *info, __u32 *mode, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;
	hcf_16  portType;
	hcf_16	createIBSS;
	/*------------------------------------------------------------------------*/

	DBG_FUNC( "wireless_set_porttype" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/* Validate the new value */
	switch( *mode ) {
	case IW_MODE_ADHOC:

		/* When user requests ad-hoc, set IBSS mode! */
		portType         = 1;
		createIBSS       = 1;

		lp->DownloadFirmware = WVLAN_DRV_MODE_STA; //1;

		break;


	case IW_MODE_AUTO:
	case IW_MODE_INFRA:

		/* Both automatic and infrastructure set port to BSS/STA mode */
		portType         = 1;
		createIBSS       = 0;

		lp->DownloadFirmware = WVLAN_DRV_MODE_STA; //1;

		break;


#if 0 //;? (HCF_TYPE) & HCF_TYPE_AP

	case IW_MODE_MASTER:

		/* Set BSS/AP mode */
		portType             = 1;

		lp->CreateIBSS       = 0;
		lp->DownloadFirmware = WVLAN_DRV_MODE_AP; //2;

		break;

#endif /* (HCF_TYPE) & HCF_TYPE_AP */


	default:

		portType   = 0;
		createIBSS = 0;
		ret = -EINVAL;
	}

	if( portType != 0 ) {
		/* Only do something if there is a mode change */
		if( ( lp->PortType != portType ) || (lp->CreateIBSS != createIBSS)) {
			lp->PortType   = portType;
			lp->CreateIBSS = createIBSS;

			/* Commit the adapter parameters */
			wl_go( lp );

			/* Send an event that mode has been set */
			wl_wext_event_mode( lp->dev );
		}
	}

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_set_porttype
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_porttype()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Gets the port type of the wireless device.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_porttype(struct net_device *dev, struct iw_request_info *info, __u32 *mode, char *extra)

{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int     ret = 0;
	int     status = -1;
	hcf_16  *pPortType;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_porttype" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/* Get the current port type */
	lp->ltvRecord.len = 1 + ( sizeof( *pPortType ) / sizeof( hcf_16 ));
	lp->ltvRecord.typ = CFG_CNF_PORT_TYPE;

	status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));

	if( status == HCF_SUCCESS ) {
		pPortType = (hcf_16 *)&( lp->ltvRecord.u.u32 );

		*pPortType = CNV_LITTLE_TO_INT( *pPortType );

		switch( *pPortType ) {
		case 1:

#if 0
#if (HCF_TYPE) & HCF_TYPE_AP

			if ( CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_AP  ) {
				*mode = IW_MODE_MASTER;
			} else {
				*mode = IW_MODE_INFRA;
			}

#else

			*mode = IW_MODE_INFRA;

#endif  /* (HCF_TYPE) & HCF_TYPE_AP */
#endif

			if ( CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_AP  ) {
				*mode =  IW_MODE_MASTER;
			} else {
				if( lp->CreateIBSS ) {
					*mode = IW_MODE_ADHOC;
				} else {
					*mode = IW_MODE_INFRA;
				}
			}

			break;


		case 3:
			*mode = IW_MODE_ADHOC;
			break;

		default:
			ret = -EFAULT;
			break;
		}
	} else {
		ret = -EFAULT;
	}

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_porttype
/*============================================================================*/




/*******************************************************************************
 *	wireless_set_power()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Sets the power management settings of the wireless device.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_set_power(struct net_device *dev, struct iw_request_info *info, struct iw_param *wrq, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_set_power" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	DBG_PRINT( "THIS CORRUPTS PMEnabled ;?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );

#if 0 //;? Needed, was present in original code but not in 7.18 Linux 2.6 kernel version
	if( !capable( CAP_NET_ADMIN )) {
		ret = -EPERM;

		DBG_LEAVE( DbgInfo );
		return ret;
	}
#endif

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/* Set the power management state based on the 'disabled' value */
	if( wrq->disabled ) {
		lp->PMEnabled = 0;
	} else {
		lp->PMEnabled = 1;
	}

	/* Commit the adapter parameters */
	wl_apply( lp );

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_set_power
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_power()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Gets the power management settings of the wireless device.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_power(struct net_device *dev, struct iw_request_info *info, struct iw_param *rrq, char *extra)

{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;
	/*------------------------------------------------------------------------*/
	DBG_FUNC( "wireless_get_power" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	DBG_PRINT( "THIS IS PROBABLY AN OVER-SIMPLIFICATION ;?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	rrq->flags = 0;
	rrq->value = 0;

	if( lp->PMEnabled ) {
		rrq->disabled = 0;
	} else {
		rrq->disabled = 1;
	}

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_power
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_tx_power()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Gets the transmit power of the wireless device's radio.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_tx_power(struct net_device *dev, struct iw_request_info *info, struct iw_param *rrq, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;
	/*------------------------------------------------------------------------*/
	DBG_FUNC( "wireless_get_tx_power" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

#ifdef USE_POWER_DBM
	rrq->value = RADIO_TX_POWER_DBM;
	rrq->flags = IW_TXPOW_DBM;
#else
	rrq->value = RADIO_TX_POWER_MWATT;
	rrq->flags = IW_TXPOW_MWATT;
#endif
	rrq->fixed = 1;
	rrq->disabled = 0;

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_tx_power
/*============================================================================*/




/*******************************************************************************
 *	wireless_set_rts_threshold()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Sets the RTS threshold for the wireless card.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_set_rts_threshold (struct net_device *dev, struct iw_request_info *info, struct iw_param *rts, char *extra)
{
	int ret = 0;
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int rthr = rts->value;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_set_rts_threshold" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	if(rts->fixed == 0) {
		ret = -EINVAL;
		goto out;
	}

	if( rts->disabled ) {
		rthr = 2347;
	}

	if(( rthr < 256 ) || ( rthr > 2347 )) {
		ret = -EINVAL;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	lp->RTSThreshold = rthr;

	wl_apply( lp );

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_set_rts_threshold
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_rts_threshold()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *     Gets the RTS threshold for the wireless card.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_rts_threshold (struct net_device *dev, struct iw_request_info *info, struct iw_param *rts, char *extra)
{
	int ret = 0;
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	/*------------------------------------------------------------------------*/

	DBG_FUNC( "wireless_get_rts_threshold" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	rts->value = lp->RTSThreshold;

	rts->disabled = ( rts->value == 2347 );

	rts->fixed = 1;

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_rts_threshold
/*============================================================================*/





/*******************************************************************************
 *	wireless_set_rate()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Set the default data rate setting used by the wireless device.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_set_rate(struct net_device *dev, struct iw_request_info *info, struct iw_param *rrq, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret = 0;
#ifdef WARP
	int status = -1;
	int index = 0;
#endif  // WARP
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_set_rate" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

#ifdef WARP

	/* Determine if the card is operating in the 2.4 or 5.0 GHz band; check
	   if Bit 9 is set in the current channel RID */
	lp->ltvRecord.len = 2;
	lp->ltvRecord.typ = CFG_CUR_CHANNEL;

	status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));

	if( status == HCF_SUCCESS ) {
		index = ( CNV_LITTLE_TO_INT( lp->ltvRecord.u.u16[0] ) & 0x100 ) ? 1 : 0;

		DBG_PRINT( "Index: %d\n", index );
	} else {
		DBG_ERROR( DbgInfo, "Could not determine radio frequency\n" );
		DBG_LEAVE( DbgInfo );
		ret = -EINVAL;
		goto out_unlock;
	}

	if( rrq->value > 0 &&
		rrq->value <= 1 * MEGABIT ) {
		lp->TxRateControl[index] = 0x0001;
	}
	else if( rrq->value > 1 * MEGABIT &&
			rrq->value <= 2 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0002;
		} else {
			lp->TxRateControl[index] = 0x0003;
		}
	}
	else if( rrq->value > 2 * MEGABIT &&
			rrq->value <= 5 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0004;
		} else {
			lp->TxRateControl[index] = 0x0007;
		}
	}
	else if( rrq->value > 5 * MEGABIT &&
			rrq->value <= 6 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0010;
		} else {
			lp->TxRateControl[index] = 0x0017;
		}
	}
	else if( rrq->value > 6 * MEGABIT &&
			rrq->value <= 9 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0020;
		} else {
			lp->TxRateControl[index] = 0x0037;
		}
	}
	else if( rrq->value > 9 * MEGABIT &&
			rrq->value <= 11 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0008;
		} else {
			lp->TxRateControl[index] = 0x003F;
		}
	}
	else if( rrq->value > 11 * MEGABIT &&
			rrq->value <= 12 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0040;
		} else {
			lp->TxRateControl[index] = 0x007F;
		}
	}
	else if( rrq->value > 12 * MEGABIT &&
			rrq->value <= 18 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0080;
		} else {
			lp->TxRateControl[index] = 0x00FF;
		}
	}
	else if( rrq->value > 18 * MEGABIT &&
			rrq->value <= 24 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0100;
		} else {
			lp->TxRateControl[index] = 0x01FF;
		}
	}
	else if( rrq->value > 24 * MEGABIT &&
			rrq->value <= 36 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0200;
		} else {
			lp->TxRateControl[index] = 0x03FF;
		}
	}
	else if( rrq->value > 36 * MEGABIT &&
			rrq->value <= 48 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0400;
		} else {
			lp->TxRateControl[index] = 0x07FF;
		}
	}
	else if( rrq->value > 48 * MEGABIT &&
			rrq->value <= 54 * MEGABIT ) {
		if( rrq->fixed == 1 ) {
			lp->TxRateControl[index] = 0x0800;
		} else {
			lp->TxRateControl[index] = 0x0FFF;
		}
	}
	else if( rrq->fixed == 0 ) {
		/* In this case, the user has not specified a bitrate, only the "auto"
		   moniker. So, set to all supported rates */
		lp->TxRateControl[index] = PARM_MAX_TX_RATE;
	} else {
		rrq->value = 0;
		ret = -EINVAL;
		goto out_unlock;
	}


#else

	if( rrq->value > 0 &&
			rrq->value <= 1 * MEGABIT ) {
		lp->TxRateControl[0] = 1;
	}
	else if( rrq->value > 1 * MEGABIT &&
			rrq->value <= 2 * MEGABIT ) {
		if( rrq->fixed ) {
			lp->TxRateControl[0] = 2;
		} else {
			lp->TxRateControl[0] = 6;
		}
	}
	else if( rrq->value > 2 * MEGABIT &&
			rrq->value <= 5 * MEGABIT ) {
		if( rrq->fixed ) {
			lp->TxRateControl[0] = 4;
		} else {
			lp->TxRateControl[0] = 7;
		}
	}
	else if( rrq->value > 5 * MEGABIT &&
			rrq->value <= 11 * MEGABIT ) {
		if( rrq->fixed)  {
			lp->TxRateControl[0] = 5;
		} else {
			lp->TxRateControl[0] = 3;
		}
	}
	else if( rrq->fixed == 0 ) {
		/* In this case, the user has not specified a bitrate, only the "auto"
		   moniker. So, set the rate to 11Mb auto */
		lp->TxRateControl[0] = 3;
	} else {
		rrq->value = 0;
		ret = -EINVAL;
		goto out_unlock;
	}

#endif  // WARP


	/* Commit the adapter parameters */
	wl_apply( lp );

out_unlock:

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_set_rate
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_rate()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Get the default data rate setting used by the wireless device.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_rate(struct net_device *dev, struct iw_request_info *info, struct iw_param *rrq, char *extra)

{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int     ret = 0;
	int     status = -1;
	hcf_16  txRate;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_rate" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/* Get the current transmit rate from the adapter */
	lp->ltvRecord.len = 1 + ( sizeof(txRate)/sizeof(hcf_16));
	lp->ltvRecord.typ = CFG_CUR_TX_RATE;

	status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));

	if( status == HCF_SUCCESS ) {
#ifdef WARP

		txRate = CNV_LITTLE_TO_INT( lp->ltvRecord.u.u16[0] );

		if( txRate & 0x0001 ) {
			txRate = 1;
		}
		else if( txRate & 0x0002 ) {
			txRate = 2;
		}
		else if( txRate & 0x0004 ) {
			txRate = 5;
		}
		else if( txRate & 0x0008 ) {
			txRate = 11;
		}
		else if( txRate & 0x00010 ) {
			txRate = 6;
		}
		else if( txRate & 0x00020 ) {
			txRate = 9;
		}
		else if( txRate & 0x00040 ) {
			txRate = 12;
		}
		else if( txRate & 0x00080 ) {
			txRate = 18;
		}
		else if( txRate & 0x00100 ) {
			txRate = 24;
		}
		else if( txRate & 0x00200 ) {
			txRate = 36;
		}
		else if( txRate & 0x00400 ) {
			txRate = 48;
		}
		else if( txRate & 0x00800 ) {
			txRate = 54;
		}

#else

		txRate = (hcf_16)CNV_LITTLE_TO_LONG( lp->ltvRecord.u.u32[0] );

#endif  // WARP

		rrq->value = txRate * MEGABIT;
	} else {
		rrq->value = 0;
		ret = -EFAULT;
	}

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_rate
/*============================================================================*/




#if 0 //;? Not used anymore
/*******************************************************************************
 *	wireless_get_private_interface()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Returns the Linux Wireless Extensions' compatible private interface of
 *  the driver.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
int wireless_get_private_interface( struct iwreq *wrq, struct wl_private *lp )
{
	int ret = 0;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_private_interface" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	if( wrq->u.data.pointer != NULL ) {
		struct iw_priv_args priv[] =
		{
			{ SIOCSIWNETNAME, IW_PRIV_TYPE_CHAR | HCF_MAX_NAME_LEN, 0, "snetwork_name" },
			{ SIOCGIWNETNAME, 0, IW_PRIV_TYPE_CHAR | HCF_MAX_NAME_LEN, "gnetwork_name" },
			{ SIOCSIWSTANAME, IW_PRIV_TYPE_CHAR | HCF_MAX_NAME_LEN, 0, "sstation_name" },
			{ SIOCGIWSTANAME, 0, IW_PRIV_TYPE_CHAR | HCF_MAX_NAME_LEN, "gstation_name" },
			{ SIOCSIWPORTTYPE, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "sport_type" },
			{ SIOCGIWPORTTYPE, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "gport_type" },
		};

		/* Verify the user buffer */
		ret = verify_area( VERIFY_WRITE, wrq->u.data.pointer, sizeof( priv ));

		if( ret != 0 ) {
			DBG_LEAVE( DbgInfo );
			return ret;
		}

		/* Copy the data into the user's buffer */
		wrq->u.data.length = NELEM( priv );
		copy_to_user( wrq->u.data.pointer, &priv, sizeof( priv ));
	}

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_private_interface
/*============================================================================*/
#endif



/*******************************************************************************
 *	wireless_set_scan()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Instructs the driver to initiate a network scan.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_set_scan(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int                 ret = 0;
	int                 status = -1;
	int		    retries = 0;
	/*------------------------------------------------------------------------*/

	//;? Note: shows results as trace, retruns always 0 unless BUSY

	DBG_FUNC( "wireless_set_scan" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/*
         * This looks like a nice place to test if the HCF is still
         * communicating with the card. It seems that sometimes BAP_1
         * gets corrupted. By looking at the comments in HCF the
         * cause is still a mystery. Okay, the communication to the
         * card is dead, reset the card to revive.
         */
	if((lp->hcfCtx.IFB_CardStat & CARD_STAT_DEFUNCT) != 0)
	{
		DBG_TRACE( DbgInfo, "CARD is in DEFUNCT mode, reset it to bring it back to life\n" );
		wl_reset( dev );
	}

retry:
	/* Set the completion state to FALSE */
	lp->probe_results.scan_complete = FALSE;


	/* Channels to scan */
#ifdef WARP
	lp->ltvRecord.len       = 5;
	lp->ltvRecord.typ       = CFG_SCAN_CHANNEL;
	lp->ltvRecord.u.u16[0]  = CNV_INT_TO_LITTLE( 0x3FFF );  // 2.4 GHz Band
	lp->ltvRecord.u.u16[1]  = CNV_INT_TO_LITTLE( 0xFFFF );  // 5.0 GHz Band
	lp->ltvRecord.u.u16[2]  = CNV_INT_TO_LITTLE( 0xFFFF );  //      ..
	lp->ltvRecord.u.u16[3]  = CNV_INT_TO_LITTLE( 0x0007 );  //      ..
#else
	lp->ltvRecord.len       = 2;
	lp->ltvRecord.typ       = CFG_SCAN_CHANNEL;
	lp->ltvRecord.u.u16[0]  = CNV_INT_TO_LITTLE( 0x7FFF );
#endif  // WARP

	status = hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));

	DBG_TRACE( DbgInfo, "CFG_SCAN_CHANNEL result      : 0x%x\n", status );

	// Holding the lock too long, make a gap to allow other processes
	wl_unlock(lp, &flags);
	wl_lock( lp, &flags );

	if( status != HCF_SUCCESS ) {
		//Recovery
		retries++;
		if(retries <= 10) {
			DBG_TRACE( DbgInfo, "Reset card to recover, attempt: %d\n", retries );
			wl_reset( dev );

			// Holding the lock too long, make a gap to allow other processes
			wl_unlock(lp, &flags);
			wl_lock( lp, &flags );

			goto retry;
		}
	}

	/* Set the SCAN_SSID to "ANY". Using this RID for scan prevents the need to
	   disassociate from the network we are currently on */
	lp->ltvRecord.len       = 18;
	lp->ltvRecord.typ       = CFG_SCAN_SSID;
	lp->ltvRecord.u.u16[0]  = CNV_INT_TO_LITTLE( 0 );
	lp->ltvRecord.u.u16[1]  = CNV_INT_TO_LITTLE( 0 );

	status = hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));

	// Holding the lock too long, make a gap to allow other processes
	wl_unlock(lp, &flags);
	wl_lock( lp, &flags );

	DBG_TRACE( DbgInfo, "CFG_SCAN_SSID to 'any' status: 0x%x\n", status );

	/* Initiate the scan */
	/* NOTE: Using HCF_ACT_SCAN has been removed, as using HCF_ACT_ACS_SCAN to
	   retrieve probe responses must always be used to support WPA */
	status = hcf_action( &( lp->hcfCtx ), HCF_ACT_ACS_SCAN );

	if( status == HCF_SUCCESS ) {
		DBG_TRACE( DbgInfo, "SUCCESSFULLY INITIATED SCAN...\n" );
	} else {
		DBG_TRACE( DbgInfo, "INITIATE SCAN FAILED...\n" );
	}

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE(DbgInfo);
	return ret;
} // wireless_set_scan
/*============================================================================*/




/*******************************************************************************
 *	wireless_get_scan()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Instructs the driver to gather and return the results of a network scan.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
static int wireless_get_scan(struct net_device *dev, struct iw_request_info *info, struct iw_point *data, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int                 ret = 0;
	int                 count;
	char                *buf;
	char                *buf_end;
	struct iw_event     iwe;
	PROBE_RESP          *probe_resp;
	hcf_8               msg[512];
	hcf_8               *wpa_ie;
	hcf_16              wpa_ie_len;
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wireless_get_scan" );
	DBG_ENTER( DbgInfo );

	if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	/* If the scan is not done, tell the calling process to try again later */
	if( !lp->probe_results.scan_complete ) {
		ret = -EAGAIN;
		goto out_unlock;
	}

	DBG_TRACE( DbgInfo, "SCAN COMPLETE, Num of APs: %d\n",
			   lp->probe_results.num_aps );

	buf     = extra;
	buf_end = extra + IW_SCAN_MAX_DATA;

	for( count = 0; count < lp->probe_results.num_aps; count++ ) {
		/* Reference the probe response from the table */
		probe_resp = (PROBE_RESP *)&lp->probe_results.ProbeTable[count];


		/* First entry MUST be the MAC address */
		memset( &iwe, 0, sizeof( iwe ));

		iwe.cmd                 = SIOCGIWAP;
		iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
		memcpy( iwe.u.ap_addr.sa_data, probe_resp->BSSID, ETH_ALEN);
		iwe.len                 = IW_EV_ADDR_LEN;

		buf = iwe_stream_add_event(info, buf, buf_end,
					   &iwe, IW_EV_ADDR_LEN);

		/* Use the mode to indicate if it's a station or AP */
		/* Won't always be an AP if in IBSS mode */
		memset( &iwe, 0, sizeof( iwe ));

		iwe.cmd = SIOCGIWMODE;

		if( probe_resp->capability & CAPABILITY_IBSS ) {
			iwe.u.mode = IW_MODE_INFRA;
		} else {
			iwe.u.mode = IW_MODE_MASTER;
		}

		iwe.len = IW_EV_UINT_LEN;

		buf = iwe_stream_add_event(info, buf, buf_end,
					   &iwe, IW_EV_UINT_LEN);

		/* Any quality information */
		memset(&iwe, 0, sizeof(iwe));

		iwe.cmd             = IWEVQUAL;
		iwe.u.qual.level    = dbm(probe_resp->signal);
		iwe.u.qual.noise    = dbm(probe_resp->silence);
		iwe.u.qual.qual     = iwe.u.qual.level - iwe.u.qual.noise;
		iwe.u.qual.updated  = lp->probe_results.scan_complete | IW_QUAL_DBM;
		iwe.len             = IW_EV_QUAL_LEN;

		buf = iwe_stream_add_event(info, buf, buf_end,
					   &iwe, IW_EV_QUAL_LEN);


		/* ESSID information */
		if( probe_resp->rawData[1] > 0 ) {
			memset( &iwe, 0, sizeof( iwe ));

			iwe.cmd = SIOCGIWESSID;
			iwe.u.data.length = probe_resp->rawData[1];
			iwe.u.data.flags = 1;

			buf = iwe_stream_add_point(info, buf, buf_end,
					       &iwe, &probe_resp->rawData[2]);
		}


		/* Encryption Information */
		memset( &iwe, 0, sizeof( iwe ));

		iwe.cmd             = SIOCGIWENCODE;
		iwe.u.data.length   = 0;

		/* Check the capabilities field of the Probe Response to see if
		   'privacy' is supported on the AP in question */
		if( probe_resp->capability & CAPABILITY_PRIVACY ) {
			iwe.u.data.flags |= IW_ENCODE_ENABLED;
		} else {
			iwe.u.data.flags |= IW_ENCODE_DISABLED;
		}

		buf = iwe_stream_add_point(info, buf, buf_end, &iwe, NULL);


		/* Frequency Info */
		memset( &iwe, 0, sizeof( iwe ));

		iwe.cmd = SIOCGIWFREQ;
		iwe.len = IW_EV_FREQ_LEN;
		iwe.u.freq.m = wl_parse_ds_ie( probe_resp );
		iwe.u.freq.e = 0;

		buf = iwe_stream_add_event(info, buf, buf_end,
					   &iwe, IW_EV_FREQ_LEN);


		/* Custom info (Beacon Interval) */
		memset( &iwe, 0, sizeof( iwe ));
		memset( msg, 0, sizeof( msg ));

		iwe.cmd = IWEVCUSTOM;
		sprintf( msg, "beacon_interval=%d", probe_resp->beaconInterval );
		iwe.u.data.length = strlen( msg );

		buf = iwe_stream_add_point(info, buf, buf_end, &iwe, msg);


		/* WPA-IE */
		wpa_ie = NULL;
		wpa_ie_len = 0;

		wpa_ie = wl_parse_wpa_ie( probe_resp, &wpa_ie_len );
		if( wpa_ie != NULL ) {
			memset(&iwe, 0, sizeof(iwe));

			iwe.cmd = IWEVGENIE;
			iwe.u.data.length = wpa_ie_len;

			buf = iwe_stream_add_point(info, buf, buf_end,
						   &iwe, wpa_ie);
		}

		/* Add other custom info in formatted string format as needed... */
	}

	data->length = buf - extra;

out_unlock:

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_get_scan
/*============================================================================*/

#if DBG
static const char * const auth_names[] = {
	"IW_AUTH_WPA_VERSION",
	"IW_AUTH_CIPHER_PAIRWISE",
	"IW_AUTH_CIPHER_GROUP",
	"IW_AUTH_KEY_MGMT",
	"IW_AUTH_TKIP_COUNTERMEASURES",
	"IW_AUTH_DROP_UNENCRYPTED",
	"IW_AUTH_80211_AUTH_ALG",
	"IW_AUTH_WPA_ENABLED",
	"IW_AUTH_RX_UNENCRYPTED_EAPOL",
	"IW_AUTH_ROAMING_CONTROL",
	"IW_AUTH_PRIVACY_INVOKED",
	"IW_AUTH_CIPHER_GROUP_MGMT",
	"IW_AUTH_MFP",
	"Unsupported"
};
#endif

static int wireless_set_auth(struct net_device *dev,
			  struct iw_request_info *info,
			  struct iw_param *data, char *extra)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	ltv_t ltv;
	int ret;
	int iwa_idx = data->flags & IW_AUTH_INDEX;
	int iwa_val = data->value;

	DBG_FUNC( "wireless_set_auth" );
	DBG_ENTER( DbgInfo );

	if (lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

	if (iwa_idx > IW_AUTH_MFP)
		iwa_idx = IW_AUTH_MFP + 1;
	DBG_TRACE(DbgInfo, "%s\n", auth_names[iwa_idx]);
	switch (iwa_idx) {
	case IW_AUTH_WPA_VERSION:
		/* We do support WPA */
		if ((iwa_val == IW_AUTH_WPA_VERSION_WPA) ||
		    (iwa_val == IW_AUTH_WPA_VERSION_DISABLED))
			ret = 0;
		else
			ret = -EINVAL;
		break;

	case IW_AUTH_WPA_ENABLED:
		DBG_TRACE(DbgInfo, "val = %d\n", iwa_val);
		if (iwa_val)
			lp->EnableEncryption = 2;
		else
			lp->EnableEncryption = 0;

		/* Write straight to the card */
		ltv.len = 2;
		ltv.typ = CFG_CNF_ENCRYPTION;
		ltv.u.u16[0] = cpu_to_le16(lp->EnableEncryption);
		ret = hcf_put_info(&lp->hcfCtx, (LTVP)&ltv);

		break;

	case IW_AUTH_TKIP_COUNTERMEASURES:

		/* Immediately disable card */
		lp->driverEnable = !iwa_val;
		if (lp->driverEnable)
			hcf_cntl(&(lp->hcfCtx), HCF_CNTL_ENABLE | HCF_PORT_0);
		else
			hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISABLE | HCF_PORT_0);
		ret = 0;
		break;

	case IW_AUTH_MFP:
		/* Management Frame Protection not supported.
		 * Only fail if set to required.
		 */
		if (iwa_val == IW_AUTH_MFP_REQUIRED)
			ret = -EINVAL;
		else
			ret = 0;
		break;

	case IW_AUTH_KEY_MGMT:

		/* Record required management suite.
		 * Will take effect on next commit */
		if (iwa_val != 0)
			lp->AuthKeyMgmtSuite = 4;
		else
			lp->AuthKeyMgmtSuite = 0;

		ret = -EINPROGRESS;
		break;

	case IW_AUTH_80211_AUTH_ALG:

		/* Just record whether open or shared is required.
		 * Will take effect on next commit */
		ret = -EINPROGRESS;

		if (iwa_val & IW_AUTH_ALG_SHARED_KEY)
			lp->authentication = 1;
		else if (iwa_val & IW_AUTH_ALG_OPEN_SYSTEM)
			lp->authentication = 0;
		else
			ret = -EINVAL;
		break;

	case IW_AUTH_DROP_UNENCRYPTED:
		/* Only needed for AP */
		lp->ExcludeUnencrypted = iwa_val;
		ret = -EINPROGRESS;
		break;

	case IW_AUTH_CIPHER_PAIRWISE:
	case IW_AUTH_CIPHER_GROUP:
	case IW_AUTH_RX_UNENCRYPTED_EAPOL:
	case IW_AUTH_ROAMING_CONTROL:
	case IW_AUTH_PRIVACY_INVOKED:
		/* Not used. May need to do something with
		 * CIPHER_PAIRWISE and CIPHER_GROUP*/
		ret = -EINPROGRESS;
		break;

	default:
		DBG_TRACE(DbgInfo, "IW_AUTH_?? (%d) unknown\n", iwa_idx);
		/* return an error */
		ret = -EOPNOTSUPP;
		break;
	}

    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE( DbgInfo );
	return ret;
} // wireless_set_auth
/*============================================================================*/


static void flush_tx(struct wl_private *lp)
{
	ltv_t ltv;
	int count;

	/*
	 * Make sure that there is no data queued up in the firmware
	 * before setting the TKIP keys. If this check is not
	 * performed, some data may be sent out with incorrect MIC
	 * and cause synchronizarion errors with the AP
	 */
	/* Check every 1ms for 100ms */
	for (count = 0; count < 100; count++) {
		udelay(1000);

		ltv.len = 2;
		ltv.typ = 0xFD91;  /* This RID not defined in HCF yet!!! */
		ltv.u.u16[0] = 0;

		hcf_get_info(&(lp->hcfCtx), (LTVP)&ltv);

		if (ltv.u.u16[0] == 0)
			break;
	}

	if (count >= 100)
		DBG_TRACE(DbgInfo, "Timed out waiting for TxQ flush!\n");

}

static int wireless_set_encodeext(struct net_device *dev,
				  struct iw_request_info *info,
				  struct iw_point *erq, char *keybuf)
{
	struct wl_private *lp = wl_priv(dev);
	unsigned long flags;
	int ret;
	int key_idx = (erq->flags & IW_ENCODE_INDEX) - 1;
	ltv_t ltv;
	struct iw_encode_ext *ext = (struct iw_encode_ext *)keybuf;
	bool enable = true;
	bool set_tx = false;

	DBG_ENTER(DbgInfo);

	if (lp->portState == WVLAN_PORT_STATE_DISABLED) {
		ret = -EBUSY;
		goto out;
	}

	if (erq->flags & IW_ENCODE_DISABLED) {
		ext->alg = IW_ENCODE_ALG_NONE;
		enable = false;
	}

	if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
		set_tx = true;

	wl_lock(lp, &flags);

	wl_act_int_off(lp);

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

	switch (ext->alg) {
	case IW_ENCODE_ALG_TKIP:
		DBG_TRACE(DbgInfo, "IW_ENCODE_ALG_TKIP: key(%d)\n", key_idx);

		if (sizeof(ext->rx_seq) != 8) {
			DBG_TRACE(DbgInfo, "rx_seq size mismatch\n");
			DBG_LEAVE(DbgInfo);
			ret = -EINVAL;
			goto out_unlock;
		}

		ret = hermes_set_tkip_keys(&ltv, key_idx, ext->addr.sa_data,
					   set_tx,
					   ext->rx_seq, ext->key, ext->key_len);

		if (ret != 0) {
			DBG_TRACE(DbgInfo, "hermes_set_tkip_keys returned != 0, key not set\n");
			goto out_unlock;
		}

		flush_tx(lp);

		lp->wext_enc = IW_ENCODE_ALG_TKIP;

		/* Write the key */
		ret = hcf_put_info(&(lp->hcfCtx), (LTVP)&ltv);
		break;

	case IW_ENCODE_ALG_WEP:
		DBG_TRACE(DbgInfo, "IW_ENCODE_ALG_WEP: key(%d)\n", key_idx);

		if (erq->flags & IW_ENCODE_RESTRICTED) {
			DBG_WARNING(DbgInfo, "IW_ENCODE_RESTRICTED invalid\n");
			ret = -EINVAL;
			goto out_unlock;
		}

		ret = hermes_set_wep_keys(lp, key_idx, ext->key, ext->key_len,
					  enable, set_tx);

		break;

	case IW_ENCODE_ALG_CCMP:
		DBG_TRACE(DbgInfo, "IW_ENCODE_ALG_CCMP: key(%d)\n", key_idx);
		ret = -EOPNOTSUPP;
		break;

	case IW_ENCODE_ALG_NONE:
		DBG_TRACE(DbgInfo, "IW_ENCODE_ALG_NONE: key(%d)\n", key_idx);

		if (lp->wext_enc == IW_ENCODE_ALG_TKIP) {
			ret = hermes_clear_tkip_keys(&ltv, key_idx,
						     ext->addr.sa_data);
			flush_tx(lp);
			lp->wext_enc = IW_ENCODE_ALG_NONE;
			ret = hcf_put_info(&(lp->hcfCtx), (LTVP)&ltv);

		} else if (lp->wext_enc == IW_ENCODE_ALG_WEP) {
			ret = hermes_set_wep_keys(lp, key_idx,
						  ext->key, ext->key_len,
						  false, false);
		} else {
			ret = 0;
		}

		break;

	default:
		DBG_TRACE( DbgInfo, "IW_ENCODE_??: key(%d)\n", key_idx);
		ret = -EOPNOTSUPP;
		break;
	}

out_unlock:

	wl_act_int_on(lp);

	wl_unlock(lp, &flags);

out:
	DBG_LEAVE(DbgInfo);
	return ret;
}
/*============================================================================*/



static int wireless_set_genie(struct net_device *dev,
			      struct iw_request_info *info,
			      struct iw_point *data, char *extra)

{
	int   ret = 0;

	DBG_ENTER(DbgInfo);

	/* We can't write this to the card, but apparently this
	 * operation needs to succeed */
	ret = 0;

	DBG_LEAVE(DbgInfo);
	return ret;
}
/*============================================================================*/


/*******************************************************************************
 *	wl_wireless_stats()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Return the current device wireless statistics.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
struct iw_statistics * wl_wireless_stats( struct net_device *dev )
{
	struct iw_statistics    *pStats;
	struct wl_private       *lp = wl_priv(dev);
	/*------------------------------------------------------------------------*/


	DBG_FUNC( "wl_wireless_stats" );
	DBG_ENTER(DbgInfo);
	DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);

	pStats = NULL;

	/* Initialize the statistics */
	pStats			= &( lp->wstats );
	pStats->qual.updated    = 0x00;

	if( !( lp->flags & WVLAN2_UIL_BUSY ))
	{
		CFG_COMMS_QUALITY_STRCT *pQual;
		CFG_HERMES_TALLIES_STRCT tallies;
		int                         status;

		/* Update driver status */
		pStats->status = 0;

		/* Get the current link quality information */
		lp->ltvRecord.len = 1 + ( sizeof( *pQual ) / sizeof( hcf_16 ));
		lp->ltvRecord.typ = CFG_COMMS_QUALITY;
		status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));

		if( status == HCF_SUCCESS ) {
			pQual = (CFG_COMMS_QUALITY_STRCT *)&( lp->ltvRecord );

			pStats->qual.qual  = (u_char) CNV_LITTLE_TO_INT( pQual->coms_qual );
			pStats->qual.level = (u_char) dbm( CNV_LITTLE_TO_INT( pQual->signal_lvl ));
			pStats->qual.noise = (u_char) dbm( CNV_LITTLE_TO_INT( pQual->noise_lvl ));

			pStats->qual.updated |= (IW_QUAL_QUAL_UPDATED  |
                                                 IW_QUAL_LEVEL_UPDATED |
                                                 IW_QUAL_NOISE_UPDATED |
                                                 IW_QUAL_DBM);
		} else {
			memset( &( pStats->qual ), 0, sizeof( pStats->qual ));
		}

		/* Get the current tallies from the adapter */
                /* Only possible when the device is open */
		if(lp->portState == WVLAN_PORT_STATE_DISABLED) {
			if( wl_get_tallies( lp, &tallies ) == 0 ) {
				/* No endian translation is needed here, as CFG_TALLIES is an
				   MSF RID; all processing is done on the host, not the card! */
				pStats->discard.nwid = 0L;
				pStats->discard.code = tallies.RxWEPUndecryptable;
				pStats->discard.misc = tallies.TxDiscards +
						       tallies.RxFCSErrors +
						       //tallies.RxDiscardsNoBuffer +
						       tallies.TxDiscardsWrongSA;
				//;? Extra taken over from Linux driver based on 7.18 version
				pStats->discard.retries = tallies.TxRetryLimitExceeded;
				pStats->discard.fragment = tallies.RxMsgInBadMsgFragments;
			} else {
				memset( &( pStats->discard ), 0, sizeof( pStats->discard ));
			}
		} else {
			memset( &( pStats->discard ), 0, sizeof( pStats->discard ));
		}
	}

	DBG_LEAVE( DbgInfo );
	return pStats;
} // wl_wireless_stats
/*============================================================================*/




/*******************************************************************************
 *	wl_get_wireless_stats()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Return the current device wireless statistics. This function calls
 *      wl_wireless_stats, but acquires spinlocks first as it can be called
 *      directly by the network layer.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
struct iw_statistics * wl_get_wireless_stats( struct net_device *dev )
{
	unsigned long           flags;
	struct wl_private       *lp = wl_priv(dev);
	struct iw_statistics    *pStats = NULL;
	/*------------------------------------------------------------------------*/

	DBG_FUNC( "wl_get_wireless_stats" );
	DBG_ENTER(DbgInfo);

	wl_lock( lp, &flags );

    	wl_act_int_off( lp );

#ifdef USE_RTS
	if( lp->useRTS == 1 ) {
		DBG_TRACE( DbgInfo, "Skipping wireless stats, in RTS mode\n" );
	} else
#endif
	{
		pStats = wl_wireless_stats( dev );
	}
    	wl_act_int_on( lp );

	wl_unlock(lp, &flags);

	DBG_LEAVE( DbgInfo );
	return pStats;
} // wl_get_wireless_stats


/*******************************************************************************
 *	wl_spy_gather()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      Gather wireless spy statistics.
 *
 *  PARAMETERS:
 *
 *      wrq - the wireless request buffer
 *      lp  - the device's private adapter structure
 *
 *  RETURNS:
 *
 *      0 on success
 *      errno value otherwise
 *
 ******************************************************************************/
inline void wl_spy_gather( struct net_device *dev, u_char *mac )
{
	struct iw_quality wstats;
	int                     status;
	u_char                  stats[2];
	DESC_STRCT              desc[1];
	struct wl_private   *lp = wl_priv(dev);
	/*------------------------------------------------------------------------*/

	/* shortcut */
	if (!lp->spy_data.spy_number) {
		return;
	}

	/* Gather wireless spy statistics: for each packet, compare the source
	   address with out list, and if match, get the stats. */
	memset( stats, 0, sizeof(stats));
	memset( desc, 0, sizeof(DESC_STRCT));

	desc[0].buf_addr	= stats;
	desc[0].BUF_SIZE	= sizeof(stats);
	desc[0].next_desc_addr  = 0;		// terminate list

	status = hcf_rcv_msg( &( lp->hcfCtx ), &desc[0], 0 );

	if( status == HCF_SUCCESS ) {
		wstats.level = (u_char) dbm(stats[1]);
		wstats.noise = (u_char) dbm(stats[0]);
		wstats.qual  = wstats.level > wstats.noise ? wstats.level - wstats.noise : 0;

		wstats.updated = (IW_QUAL_QUAL_UPDATED  |
				  IW_QUAL_LEVEL_UPDATED |
				  IW_QUAL_NOISE_UPDATED |
				  IW_QUAL_DBM);

		wireless_spy_update( dev, mac, &wstats );
	}
} // wl_spy_gather
/*============================================================================*/




/*******************************************************************************
 *	wl_wext_event_freq()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to send an event that the channel/freq
 *      configuration for a specific device has changed.
 *
 *
 *  PARAMETERS:
 *
 *      dev - the network device for which this event is to be issued
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void wl_wext_event_freq( struct net_device *dev )
{
	union iwreq_data wrqu;
	struct wl_private *lp = wl_priv(dev);
	/*------------------------------------------------------------------------*/


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

	wrqu.freq.m = lp->Channel;
	wrqu.freq.e = 0;

	wireless_send_event( dev, SIOCSIWFREQ, &wrqu, NULL );

	return;
} // wl_wext_event_freq
/*============================================================================*/




/*******************************************************************************
 *	wl_wext_event_mode()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to send an event that the mode of operation
 *      for a specific device has changed.
 *
 *
 *  PARAMETERS:
 *
 *      dev - the network device for which this event is to be issued
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void wl_wext_event_mode( struct net_device *dev )
{
	union iwreq_data wrqu;
	struct wl_private *lp = wl_priv(dev);
	/*------------------------------------------------------------------------*/


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

	if ( CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_STA  ) {
		wrqu.mode = IW_MODE_INFRA;
	} else {
		wrqu.mode = IW_MODE_MASTER;
	}

	wireless_send_event( dev, SIOCSIWMODE, &wrqu, NULL );

	return;
} // wl_wext_event_mode
/*============================================================================*/




/*******************************************************************************
 *	wl_wext_event_essid()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to send an event that the ESSID configuration for
 *      a specific device has changed.
 *
 *
 *  PARAMETERS:
 *
 *      dev - the network device for which this event is to be issued
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void wl_wext_event_essid( struct net_device *dev )
{
	union iwreq_data wrqu;
	struct wl_private *lp = wl_priv(dev);
	/*------------------------------------------------------------------------*/


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

	/* Fill out the buffer. Note that the buffer doesn't actually contain the
	   ESSID, but a pointer to the contents. In addition, the 'extra' field of
	   the call to wireless_send_event() must also point to where the ESSID
	   lives */
	wrqu.essid.length  = strlen( lp->NetworkName );
	wrqu.essid.pointer = (caddr_t)lp->NetworkName;
	wrqu.essid.flags   = 1;

	wireless_send_event( dev, SIOCSIWESSID, &wrqu, lp->NetworkName );

	return;
} // wl_wext_event_essid
/*============================================================================*/




/*******************************************************************************
 *	wl_wext_event_encode()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to send an event that the encryption configuration
 *      for a specific device has changed.
 *
 *
 *  PARAMETERS:
 *
 *      dev - the network device for which this event is to be issued
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void wl_wext_event_encode( struct net_device *dev )
{
	union iwreq_data wrqu;
	struct wl_private *lp = wl_priv(dev);
	int index = 0;
	/*------------------------------------------------------------------------*/


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

	if( lp->EnableEncryption == 0 ) {
		wrqu.encoding.flags = IW_ENCODE_DISABLED;
	} else {
		wrqu.encoding.flags |= lp->TransmitKeyID;

		index = lp->TransmitKeyID - 1;

		/* Only set IW_ENCODE_RESTRICTED/OPEN flag using lp->ExcludeUnencrypted
		   if we're in AP mode */
#if 1 //;? (HCF_TYPE) & HCF_TYPE_AP
		//;?should we restore this to allow smaller memory footprint

		if ( CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_AP  ) {
			if( lp->ExcludeUnencrypted ) {
				wrqu.encoding.flags |= IW_ENCODE_RESTRICTED;
			} else {
				wrqu.encoding.flags |= IW_ENCODE_OPEN;
			}
		}

#endif  // HCF_TYPE_AP

		/* Only provide the key if permissions allow */
		if( capable( CAP_NET_ADMIN )) {
			wrqu.encoding.pointer = (caddr_t)lp->DefaultKeys.key[index].key;
			wrqu.encoding.length  = lp->DefaultKeys.key[index].len;
		} else {
			wrqu.encoding.flags |= IW_ENCODE_NOKEY;
		}
	}

	wireless_send_event( dev, SIOCSIWENCODE, &wrqu,
						 lp->DefaultKeys.key[index].key );

	return;
} // wl_wext_event_encode
/*============================================================================*/




/*******************************************************************************
 *	wl_wext_event_ap()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to send an event that the device has been
 *      associated to a new AP.
 *
 *
 *  PARAMETERS:
 *
 *      dev - the network device for which this event is to be issued
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void wl_wext_event_ap( struct net_device *dev )
{
	union iwreq_data wrqu;
	struct wl_private *lp = wl_priv(dev);
	int status;
	/*------------------------------------------------------------------------*/


	/* Retrieve the WPA-IEs used by the firmware and send an event. We must send
	   this event BEFORE sending the association event, as there are timing
	   issues with the hostap supplicant. The supplicant will attempt to process
	   an EAPOL-Key frame from an AP before receiving this information, which
	   is required properly process the said frame. */
	wl_wext_event_assoc_ie( dev );

	/* Get the BSSID */
	lp->ltvRecord.typ = CFG_CUR_BSSID;
	lp->ltvRecord.len = 4;

	status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
	if( status == HCF_SUCCESS ) {
		memset( &wrqu, 0, sizeof( wrqu ));

		memcpy( wrqu.addr.sa_data, lp->ltvRecord.u.u8, ETH_ALEN );

		wrqu.addr.sa_family = ARPHRD_ETHER;

		wireless_send_event( dev, SIOCGIWAP, &wrqu, NULL );
	}

	return;
} // wl_wext_event_ap
/*============================================================================*/



/*******************************************************************************
 *	wl_wext_event_scan_complete()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to send an event that a request for a network scan
 *      has completed.
 *
 *
 *  PARAMETERS:
 *
 *      dev - the network device for which this event is to be issued
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void wl_wext_event_scan_complete( struct net_device *dev )
{
	union iwreq_data wrqu;
	/*------------------------------------------------------------------------*/


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

	wrqu.addr.sa_family = ARPHRD_ETHER;
	wireless_send_event( dev, SIOCGIWSCAN, &wrqu, NULL );

	return;
} // wl_wext_event_scan_complete
/*============================================================================*/




/*******************************************************************************
 *	wl_wext_event_new_sta()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to send an event that an AP has registered a new
 *      station.
 *
 *
 *  PARAMETERS:
 *
 *      dev - the network device for which this event is to be issued
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void wl_wext_event_new_sta( struct net_device *dev )
{
	union iwreq_data wrqu;
	/*------------------------------------------------------------------------*/


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

	/* Send the station's mac address here */
	memcpy( wrqu.addr.sa_data, dev->dev_addr, ETH_ALEN );
	wrqu.addr.sa_family = ARPHRD_ETHER;
	wireless_send_event( dev, IWEVREGISTERED, &wrqu, NULL );

	return;
} // wl_wext_event_new_sta
/*============================================================================*/




/*******************************************************************************
 *	wl_wext_event_expired_sta()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to send an event that an AP has deregistered a
 *      station.
 *
 *
 *  PARAMETERS:
 *
 *      dev - the network device for which this event is to be issued
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void wl_wext_event_expired_sta( struct net_device *dev )
{
	union iwreq_data wrqu;
	/*------------------------------------------------------------------------*/


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

	memcpy( wrqu.addr.sa_data, dev->dev_addr, ETH_ALEN );
	wrqu.addr.sa_family = ARPHRD_ETHER;
	wireless_send_event( dev, IWEVEXPIRED, &wrqu, NULL );

	return;
} // wl_wext_event_expired_sta
/*============================================================================*/




/*******************************************************************************
 *	wl_wext_event_mic_failed()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to send an event that MIC calculations failed.
 *
 *
 *  PARAMETERS:
 *
 *      dev - the network device for which this event is to be issued
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void wl_wext_event_mic_failed( struct net_device *dev )
{
	union iwreq_data   wrqu;
	struct wl_private *lp = wl_priv(dev);
	struct iw_michaelmicfailure wxmic;
	int                key_idx;
	char              *addr1;
	char              *addr2;
	WVLAN_RX_WMP_HDR  *hdr;
	/*------------------------------------------------------------------------*/


	key_idx = lp->lookAheadBuf[HFS_STAT+1] >> 3;
	key_idx &= 0x03;

	/* Cast the lookahead buffer into a RFS format */
	hdr = (WVLAN_RX_WMP_HDR *)&lp->lookAheadBuf[HFS_STAT];

	/* Cast the addresses to byte buffers, as in the above RFS they are word
	   length */
	addr1 = (char *)hdr->address1;
	addr2 = (char *)hdr->address2;

	DBG_PRINT( "MIC FAIL - KEY USED : %d, STATUS : 0x%04x\n", key_idx,
			   hdr->status );

	memset(&wrqu, 0, sizeof(wrqu));
	memset(&wxmic, 0, sizeof(wxmic));

	wxmic.flags = key_idx & IW_MICFAILURE_KEY_ID;
	wxmic.flags |= (addr1[0] & 1) ?
		IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
	wxmic.src_addr.sa_family = ARPHRD_ETHER;
	memcpy(wxmic.src_addr.sa_data, addr2, ETH_ALEN);

	wrqu.data.length = sizeof(wxmic);
	wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&wxmic);

	return;
} // wl_wext_event_mic_failed
/*============================================================================*/




/*******************************************************************************
 *	wl_wext_event_assoc_ie()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function is used to send an event containing the WPA-IE generated
 *      by the firmware in an association request.
 *
 *
 *  PARAMETERS:
 *
 *      dev - the network device for which this event is to be issued
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void wl_wext_event_assoc_ie( struct net_device *dev )
{
	union iwreq_data   wrqu;
	struct wl_private *lp = wl_priv(dev);
	int status;
	PROBE_RESP         data;
	hcf_16             length;
	hcf_8              *wpa_ie;
	/*------------------------------------------------------------------------*/


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

	/* Retrieve the Association Request IE */
	lp->ltvRecord.len = 45;
	lp->ltvRecord.typ = CFG_CUR_ASSOC_REQ_INFO;

	status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
	if( status == HCF_SUCCESS )
	{
		length = 0;
		memcpy( &data.rawData, &( lp->ltvRecord.u.u8[1] ), 88 );
		wpa_ie = wl_parse_wpa_ie( &data, &length );

		if( length != 0 )
		{
			wrqu.data.length = wpa_ie[1] + 2;
			wireless_send_event(dev, IWEVASSOCREQIE,
					    &wrqu, wpa_ie);

			/* This bit is a hack. We send the respie
			 * event at the same time */
			wireless_send_event(dev, IWEVASSOCRESPIE,
					    &wrqu, wpa_ie);
		}
	}

	return;
}  // wl_wext_event_assoc_ie
/*============================================================================*/
/* Structures to export the Wireless Handlers */

static const iw_handler wl_handler[] =
{
	IW_HANDLER(SIOCSIWCOMMIT, (iw_handler) wireless_commit),
	IW_HANDLER(SIOCGIWNAME, (iw_handler) wireless_get_protocol),
	IW_HANDLER(SIOCSIWFREQ, (iw_handler) wireless_set_frequency),
	IW_HANDLER(SIOCGIWFREQ, (iw_handler) wireless_get_frequency),
	IW_HANDLER(SIOCSIWMODE, (iw_handler) wireless_set_porttype),
	IW_HANDLER(SIOCGIWMODE, (iw_handler) wireless_get_porttype),
	IW_HANDLER(SIOCSIWSENS, (iw_handler) wireless_set_sensitivity),
	IW_HANDLER(SIOCGIWSENS, (iw_handler) wireless_get_sensitivity),
	IW_HANDLER(SIOCGIWRANGE, (iw_handler) wireless_get_range),
	IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
	IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
#if 1 //;? (HCF_TYPE) & HCF_TYPE_STA
	IW_HANDLER(SIOCGIWAP, (iw_handler) wireless_get_bssid),
#endif
	IW_HANDLER(SIOCGIWAPLIST, (iw_handler) wireless_get_ap_list),
	IW_HANDLER(SIOCSIWSCAN, (iw_handler) wireless_set_scan),
	IW_HANDLER(SIOCGIWSCAN, (iw_handler) wireless_get_scan),
	IW_HANDLER(SIOCSIWESSID, (iw_handler) wireless_set_essid),
	IW_HANDLER(SIOCGIWESSID, (iw_handler) wireless_get_essid),
	IW_HANDLER(SIOCSIWNICKN, (iw_handler) wireless_set_nickname),
	IW_HANDLER(SIOCGIWNICKN, (iw_handler) wireless_get_nickname),
	IW_HANDLER(SIOCSIWRATE, (iw_handler) wireless_set_rate),
	IW_HANDLER(SIOCGIWRATE, (iw_handler) wireless_get_rate),
	IW_HANDLER(SIOCSIWRTS, (iw_handler) wireless_set_rts_threshold),
	IW_HANDLER(SIOCGIWRTS, (iw_handler) wireless_get_rts_threshold),
	IW_HANDLER(SIOCGIWTXPOW, (iw_handler) wireless_get_tx_power),
	IW_HANDLER(SIOCSIWENCODE, (iw_handler) wireless_set_encode),
	IW_HANDLER(SIOCGIWENCODE, (iw_handler) wireless_get_encode),
	IW_HANDLER(SIOCSIWPOWER, (iw_handler) wireless_set_power),
	IW_HANDLER(SIOCGIWPOWER, (iw_handler) wireless_get_power),
	IW_HANDLER(SIOCSIWGENIE, (iw_handler) wireless_set_genie),
	IW_HANDLER(SIOCSIWAUTH, (iw_handler) wireless_set_auth),
	IW_HANDLER(SIOCSIWENCODEEXT, (iw_handler) wireless_set_encodeext),
};

static const iw_handler wl_private_handler[] =
{                                                       /* SIOCIWFIRSTPRIV + */
                wvlan_set_netname,                      /* 0: SIOCSIWNETNAME */
                wvlan_get_netname,                      /* 1: SIOCGIWNETNAME */
                wvlan_set_station_nickname,             /* 2: SIOCSIWSTANAME */
                wvlan_get_station_nickname,             /* 3: SIOCGIWSTANAME */
#if 1 //;? (HCF_TYPE) & HCF_TYPE_STA
                wvlan_set_porttype,                     /* 4: SIOCSIWPORTTYPE */
                wvlan_get_porttype,                     /* 5: SIOCGIWPORTTYPE */
#endif
};

struct iw_priv_args wl_priv_args[] = {
        {SIOCSIWNETNAME,    IW_PRIV_TYPE_CHAR | HCF_MAX_NAME_LEN, 0, "snetwork_name" },
        {SIOCGIWNETNAME, 0, IW_PRIV_TYPE_CHAR | HCF_MAX_NAME_LEN,    "gnetwork_name" },
        {SIOCSIWSTANAME,    IW_PRIV_TYPE_CHAR | HCF_MAX_NAME_LEN, 0, "sstation_name" },
        {SIOCGIWSTANAME, 0, IW_PRIV_TYPE_CHAR | HCF_MAX_NAME_LEN,    "gstation_name" },
#if 1 //;? #if (HCF_TYPE) & HCF_TYPE_STA
        {SIOCSIWPORTTYPE,    IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "sport_type" },
        {SIOCGIWPORTTYPE, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,    "gport_type" },
#endif
};

const struct iw_handler_def wl_iw_handler_def =
{
        .num_private        = sizeof(wl_private_handler) / sizeof(iw_handler),
        .private            = (iw_handler *) wl_private_handler,
        .private_args       = (struct iw_priv_args *) wl_priv_args,
        .num_private_args   = sizeof(wl_priv_args) / sizeof(struct iw_priv_args),
        .num_standard       = sizeof(wl_handler) / sizeof(iw_handler),
        .standard           = (iw_handler *) wl_handler,
        .get_wireless_stats = wl_get_wireless_stats,
};