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
|
#include <net/if.h>
#include <errno.h>
#include <string.h>
#include <stdbool.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
#include <netlink/msg.h>
#include <netlink/attr.h>
#include "nl80211.h"
#include "iw.h"
#define WLAN_CAPABILITY_ESS (1<<0)
#define WLAN_CAPABILITY_IBSS (1<<1)
#define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
#define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
#define WLAN_CAPABILITY_PRIVACY (1<<4)
#define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
#define WLAN_CAPABILITY_PBCC (1<<6)
#define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
#define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
#define WLAN_CAPABILITY_QOS (1<<9)
#define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
#define WLAN_CAPABILITY_APSD (1<<11)
#define WLAN_CAPABILITY_RADIO_MEASURE (1<<12)
#define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
#define WLAN_CAPABILITY_DEL_BACK (1<<14)
#define WLAN_CAPABILITY_IMM_BACK (1<<15)
/* DMG (60gHz) 802.11ad */
/* type - bits 0..1 */
#define WLAN_CAPABILITY_DMG_TYPE_MASK (3<<0)
#define WLAN_CAPABILITY_DMG_TYPE_IBSS (1<<0) /* Tx by: STA */
#define WLAN_CAPABILITY_DMG_TYPE_PBSS (2<<0) /* Tx by: PCP */
#define WLAN_CAPABILITY_DMG_TYPE_AP (3<<0) /* Tx by: AP */
#define WLAN_CAPABILITY_DMG_CBAP_ONLY (1<<2)
#define WLAN_CAPABILITY_DMG_CBAP_SOURCE (1<<3)
#define WLAN_CAPABILITY_DMG_PRIVACY (1<<4)
#define WLAN_CAPABILITY_DMG_ECPAC (1<<5)
#define WLAN_CAPABILITY_DMG_SPECTRUM_MGMT (1<<8)
#define WLAN_CAPABILITY_DMG_RADIO_MEASURE (1<<12)
static unsigned char ms_oui[3] = { 0x00, 0x50, 0xf2 };
static unsigned char ieee80211_oui[3] = { 0x00, 0x0f, 0xac };
static unsigned char wfa_oui[3] = { 0x50, 0x6f, 0x9a };
struct scan_params {
bool unknown;
enum print_ie_type type;
bool show_both_ie_sets;
};
#define IEEE80211_COUNTRY_EXTENSION_ID 201
union ieee80211_country_ie_triplet {
struct {
__u8 first_channel;
__u8 num_channels;
__s8 max_power;
} __attribute__ ((packed)) chans;
struct {
__u8 reg_extension_id;
__u8 reg_class;
__u8 coverage_class;
} __attribute__ ((packed)) ext;
} __attribute__ ((packed));
int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv)
{
struct nl_msg *matchset = NULL, *freqs = NULL, *ssids = NULL;
struct nl_msg *scan_plans = NULL;
struct nlattr *match = NULL, *plan = NULL;
enum {
ND_TOPLEVEL,
ND_MATCH,
ND_FREQS,
ND_ACTIVE,
ND_PLANS,
} parse_state = ND_TOPLEVEL;
int c = *argc;
char *end, **v = *argv;
int err = 0, i = 0;
unsigned int freq, interval = 0, delay = 0, iterations = 0;
bool have_matchset = false, have_freqs = false, have_ssids = false;
bool have_active = false, have_passive = false, have_plans = false;
uint32_t flags = 0;
matchset = nlmsg_alloc();
if (!matchset) {
err = -ENOBUFS;
goto out;
}
freqs = nlmsg_alloc();
if (!freqs) {
err = -ENOBUFS;
goto out;
}
ssids = nlmsg_alloc();
if (!ssids) {
err = -ENOMEM;
goto out;
}
scan_plans = nlmsg_alloc();
if (!scan_plans) {
err = -ENOBUFS;
goto out;
}
while (c) {
switch (parse_state) {
case ND_TOPLEVEL:
if (!strcmp(v[0], "interval")) {
c--; v++;
if (c == 0) {
err = -EINVAL;
goto nla_put_failure;
}
if (interval || have_plans) {
err = -EINVAL;
goto nla_put_failure;
}
interval = strtoul(v[0], &end, 10);
if (*end || !interval) {
err = -EINVAL;
goto nla_put_failure;
}
NLA_PUT_U32(msg,
NL80211_ATTR_SCHED_SCAN_INTERVAL,
interval);
} else if (!strcmp(v[0], "scan_plans")) {
parse_state = ND_PLANS;
if (have_plans || interval) {
err = -EINVAL;
goto nla_put_failure;
}
have_plans = true;
i = 0;
} else if (!strcmp(v[0], "delay")) {
c--; v++;
if (c == 0) {
err = -EINVAL;
goto nla_put_failure;
}
if (delay) {
err = -EINVAL;
goto nla_put_failure;
}
delay = strtoul(v[0], &end, 10);
if (*end) {
err = -EINVAL;
goto nla_put_failure;
}
NLA_PUT_U32(msg,
NL80211_ATTR_SCHED_SCAN_DELAY,
delay);
} else if (!strcmp(v[0], "matches")) {
parse_state = ND_MATCH;
if (have_matchset) {
err = -EINVAL;
goto nla_put_failure;
}
i = 0;
} else if (!strcmp(v[0], "freqs")) {
parse_state = ND_FREQS;
if (have_freqs) {
err = -EINVAL;
goto nla_put_failure;
}
have_freqs = true;
i = 0;
} else if (!strcmp(v[0], "active")) {
parse_state = ND_ACTIVE;
if (have_active || have_passive) {
err = -EINVAL;
goto nla_put_failure;
}
have_active = true;
i = 0;
} else if (!strcmp(v[0], "passive")) {
if (have_active || have_passive) {
err = -EINVAL;
goto nla_put_failure;
}
have_passive = true;
} else if (!strncmp(v[0], "randomise", 9) ||
!strncmp(v[0], "randomize", 9)) {
flags |= NL80211_SCAN_FLAG_RANDOM_ADDR;
err = parse_random_mac_addr(msg, v[0] + 9);
if (err)
goto nla_put_failure;
} else if (!strncmp(v[0], "coloc", 5)) {
flags |= NL80211_SCAN_FLAG_COLOCATED_6GHZ;
} else if (!strncmp(v[0], "flush", 5)) {
flags |= NL80211_SCAN_FLAG_FLUSH;
} else {
/* this element is not for us, so
* return to continue parsing.
*/
goto nla_put_failure;
}
c--; v++;
break;
case ND_MATCH:
if (!strcmp(v[0], "ssid")) {
c--; v++;
if (c == 0) {
err = -EINVAL;
goto nla_put_failure;
}
/* TODO: for now we can only have an
* SSID in the match, so we can start
* the match nest here.
*/
match = nla_nest_start(matchset, i);
if (!match) {
err = -ENOBUFS;
goto nla_put_failure;
}
NLA_PUT(matchset,
NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
strlen(v[0]), v[0]);
nla_nest_end(matchset, match);
match = NULL;
have_matchset = true;
i++;
c--; v++;
} else {
/* other element that cannot be part
* of a match indicates the end of the
* match. */
/* need at least one match in the matchset */
if (i == 0) {
err = -EINVAL;
goto nla_put_failure;
}
parse_state = ND_TOPLEVEL;
}
break;
case ND_FREQS:
freq = strtoul(v[0], &end, 10);
if (*end) {
if (i == 0) {
err = -EINVAL;
goto nla_put_failure;
}
parse_state = ND_TOPLEVEL;
} else {
NLA_PUT_U32(freqs, i, freq);
i++;
c--; v++;
}
break;
case ND_ACTIVE:
if (!strcmp(v[0], "ssid")) {
c--; v++;
if (c == 0) {
err = -EINVAL;
goto nla_put_failure;
}
NLA_PUT(ssids,
NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
strlen(v[0]), v[0]);
have_ssids = true;
i++;
c--; v++;
} else {
/* other element that cannot be part
* of a match indicates the end of the
* active set. */
/* need at least one item in the set */
if (i == 0) {
err = -EINVAL;
goto nla_put_failure;
}
parse_state = ND_TOPLEVEL;
}
break;
case ND_PLANS:
iterations = 0;
interval = strtoul(v[0], &end, 10);
if (*end) {
char *iter;
if (*end != ':') {
err = -EINVAL;
goto nla_put_failure;
}
iter = ++end;
iterations = strtoul(iter, &end, 10);
if (*end || !iterations) {
err = -EINVAL;
goto nla_put_failure;
}
}
plan = nla_nest_start(scan_plans, i + 1);
if (!plan) {
err = -ENOBUFS;
goto nla_put_failure;
}
NLA_PUT_U32(scan_plans,
NL80211_SCHED_SCAN_PLAN_INTERVAL,
interval);
if (iterations)
NLA_PUT_U32(scan_plans,
NL80211_SCHED_SCAN_PLAN_ITERATIONS,
iterations);
else
parse_state = ND_TOPLEVEL;
nla_nest_end(scan_plans, plan);
plan = NULL;
i++;
c--; v++;
break;
}
}
if (!have_ssids)
NLA_PUT(ssids, 1, 0, "");
if (!have_passive)
nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids);
if (have_freqs)
nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, freqs);
if (have_matchset)
nla_put_nested(msg, NL80211_ATTR_SCHED_SCAN_MATCH, matchset);
if (have_plans)
nla_put_nested(msg, NL80211_ATTR_SCHED_SCAN_PLANS, scan_plans);
if (flags)
NLA_PUT_U32(msg, NL80211_ATTR_SCAN_FLAGS, flags);
nla_put_failure:
if (match)
nla_nest_end(msg, match);
out:
nlmsg_free(freqs);
nlmsg_free(matchset);
nlmsg_free(scan_plans);
nlmsg_free(ssids);
*argc = c;
*argv = v;
return err;
}
static int handle_scan(struct nl80211_state *state,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
{
struct nl_msg *ssids = NULL, *freqs = NULL;
char *eptr;
int err = -ENOBUFS;
int i;
enum {
NONE,
FREQ,
IES,
SSID,
MESHID,
DURATION,
DONE,
} parse = NONE;
int freq;
unsigned int duration = 0;
bool passive = false, have_ssids = false, have_freqs = false;
bool duration_mandatory = false;
size_t ies_len = 0, meshid_len = 0;
unsigned char *ies = NULL, *meshid = NULL, *tmpies = NULL;
unsigned int flags = 0;
ssids = nlmsg_alloc();
if (!ssids)
return -ENOMEM;
freqs = nlmsg_alloc();
if (!freqs) {
nlmsg_free(ssids);
return -ENOMEM;
}
for (i = 0; i < argc; i++) {
switch (parse) {
case NONE:
if (strcmp(argv[i], "freq") == 0) {
parse = FREQ;
have_freqs = true;
break;
} else if (strcmp(argv[i], "ies") == 0) {
parse = IES;
break;
} else if (strcmp(argv[i], "lowpri") == 0) {
flags |= NL80211_SCAN_FLAG_LOW_PRIORITY;
break;
} else if (strcmp(argv[i], "flush") == 0) {
flags |= NL80211_SCAN_FLAG_FLUSH;
break;
} else if (strcmp(argv[i], "ap-force") == 0) {
flags |= NL80211_SCAN_FLAG_AP;
break;
} else if (strcmp(argv[i], "coloc") == 0) {
flags |= NL80211_SCAN_FLAG_COLOCATED_6GHZ;
break;
} else if (strcmp(argv[i], "duration-mandatory") == 0) {
duration_mandatory = true;
break;
} else if (strncmp(argv[i], "randomise", 9) == 0 ||
strncmp(argv[i], "randomize", 9) == 0) {
flags |= NL80211_SCAN_FLAG_RANDOM_ADDR;
err = parse_random_mac_addr(msg, argv[i] + 9);
if (err)
goto nla_put_failure;
break;
} else if (strcmp(argv[i], "ssid") == 0) {
parse = SSID;
have_ssids = true;
break;
} else if (strcmp(argv[i], "passive") == 0) {
parse = DONE;
passive = true;
break;
} else if (strcmp(argv[i], "meshid") == 0) {
parse = MESHID;
break;
} else if (strcmp(argv[i], "duration") == 0) {
parse = DURATION;
break;
}
/* fall through - this is an error */
case DONE:
err = 1;
goto nla_put_failure;
case FREQ:
freq = strtoul(argv[i], &eptr, 10);
if (eptr != argv[i] + strlen(argv[i])) {
/* failed to parse as number -- maybe a tag? */
i--;
parse = NONE;
continue;
}
NLA_PUT_U32(freqs, i, freq);
break;
case IES:
if (ies)
free(ies);
ies = parse_hex(argv[i], &ies_len);
if (!ies)
goto nla_put_failure;
parse = NONE;
break;
case SSID:
NLA_PUT(ssids, i, strlen(argv[i]), argv[i]);
break;
case MESHID:
meshid_len = strlen(argv[i]);
meshid = (unsigned char *) malloc(meshid_len + 2);
if (!meshid)
goto nla_put_failure;
meshid[0] = 114; /* mesh element id */
meshid[1] = meshid_len;
memcpy(&meshid[2], argv[i], meshid_len);
meshid_len += 2;
parse = NONE;
break;
case DURATION:
duration = strtoul(argv[i], &eptr, 10);
parse = NONE;
break;
}
}
if (ies || meshid) {
tmpies = (unsigned char *) malloc(ies_len + meshid_len);
if (!tmpies)
goto nla_put_failure;
if (ies)
memcpy(tmpies, ies, ies_len);
if (meshid)
memcpy(&tmpies[ies_len], meshid, meshid_len);
if (nla_put(msg, NL80211_ATTR_IE, ies_len + meshid_len, tmpies) < 0)
goto nla_put_failure;
}
if (!have_ssids)
NLA_PUT(ssids, 1, 0, "");
if (!passive)
nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids);
if (have_freqs)
nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, freqs);
else
flags |= NL80211_SCAN_FLAG_COLOCATED_6GHZ;
if (flags)
NLA_PUT_U32(msg, NL80211_ATTR_SCAN_FLAGS, flags);
if (duration)
NLA_PUT_U16(msg, NL80211_ATTR_MEASUREMENT_DURATION, duration);
if (duration_mandatory) {
if (duration) {
NLA_PUT_FLAG(msg,
NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY);
} else {
err = -EINVAL;
goto nla_put_failure;
}
}
err = 0;
nla_put_failure:
nlmsg_free(ssids);
nlmsg_free(freqs);
if (meshid)
free(meshid);
if (ies)
free(ies);
if (tmpies)
free(tmpies);
return err;
}
static void tab_on_first(bool *first)
{
if (!*first)
printf("\t");
else
*first = false;
}
struct print_ies_data {
unsigned char *ie;
int ielen;
};
static void print_ssid(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf(" ");
print_ssid_escaped(len, data);
printf("\n");
}
#define BSS_MEMBERSHIP_SELECTOR_VHT_PHY 126
#define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127
static void print_supprates(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
int i;
printf(" ");
for (i = 0; i < len; i++) {
int r = data[i] & 0x7f;
if (r == BSS_MEMBERSHIP_SELECTOR_VHT_PHY && data[i] & 0x80)
printf("VHT");
else if (r == BSS_MEMBERSHIP_SELECTOR_HT_PHY && data[i] & 0x80)
printf("HT");
else
printf("%d.%d", r/2, 5*(r&1));
printf("%s ", data[i] & 0x80 ? "*" : "");
}
printf("\n");
}
static void print_rm_enabled_capabilities(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
__u64 capa = ((__u64) data[0]) |
((__u64) data[1]) << 8 |
((__u64) data[2]) << 16 |
((__u64) data[3]) << 24 |
((__u64) data[4]) << 32;
printf("\n");
printf("\t\tCapabilities: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
data[0], data[1],
data[2], data[3],
data[4]);
#define PRINT_RM_CAPA(_bit, _str) \
do { \
if (capa & BIT(_bit)) \
printf("\t\t\t" _str "\n"); \
} while (0)
PRINT_RM_CAPA(0, "Link Measurement");
PRINT_RM_CAPA(1, "Neighbor Report");
PRINT_RM_CAPA(2, "Parallel Measurements");
PRINT_RM_CAPA(3, "Repeated Measurements");
PRINT_RM_CAPA(4, "Beacon Passive Measurement");
PRINT_RM_CAPA(5, "Beacon Active Measurement");
PRINT_RM_CAPA(6, "Beacon Table Measurement");
PRINT_RM_CAPA(7, "Beacon Measurement Reporting Conditions");
PRINT_RM_CAPA(8, "Frame Measurement");
PRINT_RM_CAPA(9, "Channel Load");
PRINT_RM_CAPA(10, "Noise Histogram Measurement");
PRINT_RM_CAPA(11, "Statistics Measurement");
PRINT_RM_CAPA(12, "LCI Measurement");
PRINT_RM_CAPA(13, "LCI Azimuth");
PRINT_RM_CAPA(14, "Transmit Stream/Category Measurement");
PRINT_RM_CAPA(15, "Triggered Transmit Stream/Category");
PRINT_RM_CAPA(16, "AP Channel Report");
PRINT_RM_CAPA(17, "RM MIB Capability");
PRINT_RM_CAPA(27, "Measurement Pilot Transmission Information");
PRINT_RM_CAPA(28, "Neighbor Report TSF Offset");
PRINT_RM_CAPA(29, "RCPI Measurement");
PRINT_RM_CAPA(30, "RSNI Measurement");
PRINT_RM_CAPA(31, "BSS Average Access Delay");
PRINT_RM_CAPA(32, "BSS Available Admission");
PRINT_RM_CAPA(33, "Antenna");
PRINT_RM_CAPA(34, "FTM Range Report");
PRINT_RM_CAPA(35, "Civic Location Measurement");
printf("\t\tNonoperating Channel Max Measurement Duration: %i\n", data[3] >> 5);
printf("\t\tMeasurement Pilot Capability: %i\n", data[4] & 7);
}
static void print_ds(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf(" channel %d\n", data[0]);
}
static const char *country_env_str(char environment)
{
switch (environment) {
case 'I':
return "Indoor only";
case 'O':
return "Outdoor only";
case ' ':
return "Indoor/Outdoor";
default:
return "bogus";
}
}
static void print_country(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf(" %.*s", 2, data);
printf("\tEnvironment: %s\n", country_env_str(data[2]));
data += 3;
len -= 3;
if (len < 3) {
printf("\t\tNo country IE triplets present\n");
return;
}
while (len >= 3) {
int end_channel;
union ieee80211_country_ie_triplet *triplet = (void *) data;
if (triplet->ext.reg_extension_id >= IEEE80211_COUNTRY_EXTENSION_ID) {
printf("\t\tExtension ID: %d Regulatory Class: %d Coverage class: %d (up to %dm)\n",
triplet->ext.reg_extension_id,
triplet->ext.reg_class,
triplet->ext.coverage_class,
triplet->ext.coverage_class * 450);
data += 3;
len -= 3;
continue;
}
/* 2 GHz */
if (triplet->chans.first_channel <= 14)
end_channel = triplet->chans.first_channel + (triplet->chans.num_channels - 1);
else
end_channel = triplet->chans.first_channel + (4 * (triplet->chans.num_channels - 1));
printf("\t\tChannels [%d - %d] @ %d dBm\n", triplet->chans.first_channel, end_channel, triplet->chans.max_power);
data += 3;
len -= 3;
}
return;
}
static void print_powerconstraint(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf(" %d dB\n", data[0]);
}
static void print_tpcreport(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf(" TX power: %d dBm\n", data[0]);
/* printf(" Link Margin (%d dB) is reserved in Beacons\n", data[1]); */
}
static void print_erp(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
if (data[0] == 0x00)
printf(" <no flags>");
if (data[0] & 0x01)
printf(" NonERP_Present");
if (data[0] & 0x02)
printf(" Use_Protection");
if (data[0] & 0x04)
printf(" Barker_Preamble_Mode");
printf("\n");
}
static void print_ap_channel_report(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
uint8_t oper_class = data[0];
int i;
printf("\n");
printf("\t\t * operating class: %d\n", oper_class);
printf("\t\t * channel(s):");
for (i = 1; i < len; ++i) {
printf(" %d", data[i]);
}
printf("\n");
}
static void print_cipher(const uint8_t *data)
{
if (memcmp(data, ms_oui, 3) == 0) {
switch (data[3]) {
case 0:
printf("Use group cipher suite");
break;
case 1:
printf("WEP-40");
break;
case 2:
printf("TKIP");
break;
case 4:
printf("CCMP");
break;
case 5:
printf("WEP-104");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else if (memcmp(data, ieee80211_oui, 3) == 0) {
switch (data[3]) {
case 0:
printf("Use group cipher suite");
break;
case 1:
printf("WEP-40");
break;
case 2:
printf("TKIP");
break;
case 4:
printf("CCMP");
break;
case 5:
printf("WEP-104");
break;
case 6:
printf("AES-128-CMAC");
break;
case 7:
printf("NO-GROUP");
break;
case 8:
printf("GCMP");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
}
static void print_auth(const uint8_t *data)
{
if (memcmp(data, ms_oui, 3) == 0) {
switch (data[3]) {
case 1:
printf("IEEE 802.1X");
break;
case 2:
printf("PSK");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else if (memcmp(data, ieee80211_oui, 3) == 0) {
switch (data[3]) {
case 1:
printf("IEEE 802.1X");
break;
case 2:
printf("PSK");
break;
case 3:
printf("FT/IEEE 802.1X");
break;
case 4:
printf("FT/PSK");
break;
case 5:
printf("IEEE 802.1X/SHA-256");
break;
case 6:
printf("PSK/SHA-256");
break;
case 7:
printf("TDLS/TPK");
break;
case 8:
printf("SAE");
break;
case 9:
printf("FT/SAE");
break;
case 11:
printf("IEEE 802.1X/SUITE-B");
break;
case 12:
printf("IEEE 802.1X/SUITE-B-192");
break;
case 13:
printf("FT/IEEE 802.1X/SHA-384");
break;
case 14:
printf("FILS/SHA-256");
break;
case 15:
printf("FILS/SHA-384");
break;
case 16:
printf("FT/FILS/SHA-256");
break;
case 17:
printf("FT/FILS/SHA-384");
break;
case 18:
printf("OWE");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else if (memcmp(data, wfa_oui, 3) == 0) {
switch (data[3]) {
case 1:
printf("OSEN");
break;
case 2:
printf("DPP");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
}
static void _print_rsn_ie(const char *defcipher, const char *defauth,
uint8_t len, const uint8_t *data, int is_osen)
{
bool first = true;
__u16 count, capa;
int i;
if (!is_osen) {
__u16 version;
version = data[0] + (data[1] << 8);
tab_on_first(&first);
printf("\t * Version: %d\n", version);
data += 2;
len -= 2;
}
if (len < 4) {
tab_on_first(&first);
printf("\t * Group cipher: %s\n", defcipher);
printf("\t * Pairwise ciphers: %s\n", defcipher);
return;
}
tab_on_first(&first);
printf("\t * Group cipher: ");
print_cipher(data);
printf("\n");
data += 4;
len -= 4;
if (len < 2) {
tab_on_first(&first);
printf("\t * Pairwise ciphers: %s\n", defcipher);
return;
}
count = data[0] | (data[1] << 8);
if (2 + (count * 4) > len)
goto invalid;
tab_on_first(&first);
printf("\t * Pairwise ciphers:");
for (i = 0; i < count; i++) {
printf(" ");
print_cipher(data + 2 + (i * 4));
}
printf("\n");
data += 2 + (count * 4);
len -= 2 + (count * 4);
if (len < 2) {
tab_on_first(&first);
printf("\t * Authentication suites: %s\n", defauth);
return;
}
count = data[0] | (data[1] << 8);
if (2 + (count * 4) > len)
goto invalid;
tab_on_first(&first);
printf("\t * Authentication suites:");
for (i = 0; i < count; i++) {
printf(" ");
print_auth(data + 2 + (i * 4));
}
printf("\n");
data += 2 + (count * 4);
len -= 2 + (count * 4);
if (len >= 2) {
capa = data[0] | (data[1] << 8);
tab_on_first(&first);
printf("\t * Capabilities:");
if (capa & 0x0001)
printf(" PreAuth");
if (capa & 0x0002)
printf(" NoPairwise");
switch ((capa & 0x000c) >> 2) {
case 0:
printf(" 1-PTKSA-RC");
break;
case 1:
printf(" 2-PTKSA-RC");
break;
case 2:
printf(" 4-PTKSA-RC");
break;
case 3:
printf(" 16-PTKSA-RC");
break;
}
switch ((capa & 0x0030) >> 4) {
case 0:
printf(" 1-GTKSA-RC");
break;
case 1:
printf(" 2-GTKSA-RC");
break;
case 2:
printf(" 4-GTKSA-RC");
break;
case 3:
printf(" 16-GTKSA-RC");
break;
}
if (capa & 0x0040)
printf(" MFP-required");
if (capa & 0x0080)
printf(" MFP-capable");
if (capa & 0x0200)
printf(" Peerkey-enabled");
if (capa & 0x0400)
printf(" SPP-AMSDU-capable");
if (capa & 0x0800)
printf(" SPP-AMSDU-required");
if (capa & 0x2000)
printf(" Extended-Key-ID");
printf(" (0x%.4x)\n", capa);
data += 2;
len -= 2;
}
if (len >= 2) {
int pmkid_count = data[0] | (data[1] << 8);
if (len >= 2 + 16 * pmkid_count) {
tab_on_first(&first);
printf("\t * %d PMKIDs\n", pmkid_count);
/* not printing PMKID values */
data += 2 + 16 * pmkid_count;
len -= 2 + 16 * pmkid_count;
} else
goto invalid;
}
if (len >= 4) {
tab_on_first(&first);
printf("\t * Group mgmt cipher suite: ");
print_cipher(data);
printf("\n");
data += 4;
len -= 4;
}
invalid:
if (len != 0) {
printf("\t\t * bogus tail data (%d):", len);
while (len) {
printf(" %.2x", *data);
data++;
len--;
}
printf("\n");
}
}
static void print_rsn_ie(const char *defcipher, const char *defauth,
uint8_t len, const uint8_t *data)
{
_print_rsn_ie(defcipher, defauth, len, data, 0);
}
static void print_osen_ie(const char *defcipher, const char *defauth,
uint8_t len, const uint8_t *data)
{
printf("\n\t");
_print_rsn_ie(defcipher, defauth, len, data, 1);
}
static void print_rsn(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
print_rsn_ie("CCMP", "IEEE 802.1X", len, data);
}
static void print_ht_capa(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf("\n");
print_ht_capability(data[0] | (data[1] << 8));
print_ampdu_length(data[2] & 3);
print_ampdu_spacing((data[2] >> 2) & 7);
print_ht_mcs(data + 3);
}
static const char* ntype_11u(uint8_t t)
{
switch (t) {
case 0: return "Private";
case 1: return "Private with Guest";
case 2: return "Chargeable Public";
case 3: return "Free Public";
case 4: return "Personal Device";
case 5: return "Emergency Services Only";
case 14: return "Test or Experimental";
case 15: return "Wildcard";
default: return "Reserved";
}
}
static const char* vgroup_11u(uint8_t t)
{
switch (t) {
case 0: return "Unspecified";
case 1: return "Assembly";
case 2: return "Business";
case 3: return "Educational";
case 4: return "Factory and Industrial";
case 5: return "Institutional";
case 6: return "Mercantile";
case 7: return "Residential";
case 8: return "Storage";
case 9: return "Utility and Miscellaneous";
case 10: return "Vehicular";
case 11: return "Outdoor";
default: return "Reserved";
}
}
static void print_interworking(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
/* See Section 7.3.2.92 in the 802.11u spec. */
printf("\n");
if (len >= 1) {
uint8_t ano = data[0];
printf("\t\tNetwork Options: 0x%hx\n", (unsigned short)(ano));
printf("\t\t\tNetwork Type: %i (%s)\n",
(int)(ano & 0xf), ntype_11u(ano & 0xf));
if (ano & (1<<4))
printf("\t\t\tInternet\n");
if (ano & (1<<5))
printf("\t\t\tASRA\n");
if (ano & (1<<6))
printf("\t\t\tESR\n");
if (ano & (1<<7))
printf("\t\t\tUESA\n");
}
if ((len == 3) || (len == 9)) {
printf("\t\tVenue Group: %i (%s)\n",
(int)(data[1]), vgroup_11u(data[1]));
printf("\t\tVenue Type: %i\n", (int)(data[2]));
}
if (len == 9)
printf("\t\tHESSID: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
data[3], data[4], data[5], data[6], data[7], data[8]);
else if (len == 7)
printf("\t\tHESSID: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
data[1], data[2], data[3], data[4], data[5], data[6]);
}
static void print_11u_advert(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
/* See Section 7.3.2.93 in the 802.11u spec. */
/* TODO: This code below does not decode private protocol IDs */
int idx = 0;
printf("\n");
while (idx < (len - 1)) {
uint8_t qri = data[idx];
uint8_t proto_id = data[idx + 1];
printf("\t\tQuery Response Info: 0x%hx\n", (unsigned short)(qri));
printf("\t\t\tQuery Response Length Limit: %i\n",
(qri & 0x7f));
if (qri & (1<<7))
printf("\t\t\tPAME-BI\n");
switch(proto_id) {
case 0:
printf("\t\t\tANQP\n"); break;
case 1:
printf("\t\t\tMIH Information Service\n"); break;
case 2:
printf("\t\t\tMIH Command and Event Services Capability Discovery\n"); break;
case 3:
printf("\t\t\tEmergency Alert System (EAS)\n"); break;
case 221:
printf("\t\t\tVendor Specific\n"); break;
default:
printf("\t\t\tReserved: %i\n", proto_id); break;
}
idx += 2;
}
}
static void print_11u_rcon(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
/* See Section 7.3.2.96 in the 802.11u spec. */
int idx = 0;
int ln0 = data[1] & 0xf;
int ln1 = ((data[1] & 0xf0) >> 4);
int ln2 = 0;
printf("\n");
if (ln1)
ln2 = len - 2 - ln0 - ln1;
printf("\t\tANQP OIs: %i\n", data[0]);
if (ln0 > 0) {
printf("\t\tOI 1: ");
if (2 + ln0 > len) {
printf("Invalid IE length.\n");
} else {
for (idx = 0; idx < ln0; idx++) {
printf("%02hhx", data[2 + idx]);
}
printf("\n");
}
}
if (ln1 > 0) {
printf("\t\tOI 2: ");
if (2 + ln0 + ln1 > len) {
printf("Invalid IE length.\n");
} else {
for (idx = 0; idx < ln1; idx++) {
printf("%02hhx", data[2 + ln0 + idx]);
}
printf("\n");
}
}
if (ln2 > 0) {
printf("\t\tOI 3: ");
if (2 + ln0 + ln1 + ln2 > len) {
printf("Invalid IE length.\n");
} else {
for (idx = 0; idx < ln2; idx++) {
printf("%02hhx", data[2 + ln0 + ln1 + idx]);
}
printf("\n");
}
}
}
static void print_tx_power_envelope(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
const uint8_t local_max_tx_power_count = data[0] & 7;
const uint8_t local_max_tx_power_unit_interp = (data[0] >> 3) & 7;
int i;
static const char *power_names[] = {
"Local Maximum Transmit Power For 20 MHz",
"Local Maximum Transmit Power For 40 MHz",
"Local Maximum Transmit Power For 80 MHz",
"Local Maximum Transmit Power For 160/80+80 MHz",
};
printf("\n");
if (local_max_tx_power_count + 2 != len)
return;
if (local_max_tx_power_unit_interp != 0)
return;
for (i = 0; i < local_max_tx_power_count + 1; ++i) {
int8_t power_val = ((int8_t)data[1 + i]) >> 1;
int8_t point5 = data[1 + i] & 1;
if (point5)
printf("\t\t * %s: %i.5 dBm\n", power_names[i], power_val);
else
printf("\t\t * %s: %i dBm\n", power_names[i], power_val);
}
}
static const char *ht_secondary_offset[4] = {
"no secondary",
"above",
"[reserved!]",
"below",
};
static void print_ht_op(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
static const char *protection[4] = {
"no",
"nonmember",
"20 MHz",
"non-HT mixed",
};
static const char *sta_chan_width[2] = {
"20 MHz",
"any",
};
printf("\n");
printf("\t\t * primary channel: %d\n", data[0]);
printf("\t\t * secondary channel offset: %s\n",
ht_secondary_offset[data[1] & 0x3]);
printf("\t\t * STA channel width: %s\n", sta_chan_width[(data[1] & 0x4)>>2]);
printf("\t\t * RIFS: %d\n", (data[1] & 0x8)>>3);
printf("\t\t * HT protection: %s\n", protection[data[2] & 0x3]);
printf("\t\t * non-GF present: %d\n", (data[2] & 0x4) >> 2);
printf("\t\t * OBSS non-GF present: %d\n", (data[2] & 0x10) >> 4);
printf("\t\t * dual beacon: %d\n", (data[4] & 0x40) >> 6);
printf("\t\t * dual CTS protection: %d\n", (data[4] & 0x80) >> 7);
printf("\t\t * STBC beacon: %d\n", data[5] & 0x1);
printf("\t\t * L-SIG TXOP Prot: %d\n", (data[5] & 0x2) >> 1);
printf("\t\t * PCO active: %d\n", (data[5] & 0x4) >> 2);
printf("\t\t * PCO phase: %d\n", (data[5] & 0x8) >> 3);
}
static void print_capabilities(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
int i, base, bit, si_duration = 0, max_amsdu = 0;
bool s_psmp_support = false, is_vht_cap = false;
unsigned char *ie = ie_buffer->ie;
int ielen = ie_buffer->ielen;
while (ielen >= 2 && ielen >= ie[1]) {
if (ie[0] == 191) {
is_vht_cap = true;
break;
}
ielen -= ie[1] + 2;
ie += ie[1] + 2;
}
for (i = 0; i < len; i++) {
base = i * 8;
for (bit = 0; bit < 8; bit++) {
if (!(data[i] & (1 << bit)))
continue;
printf("\n\t\t *");
#define CAPA(bit, name) case bit: printf(" " name); break
/* if the capability 'cap' exists add 'val' to 'sum'
* otherwise print 'Reserved' */
#define ADD_BIT_VAL(bit, cap, sum, val) case (bit): do { \
if (!(cap)) { \
printf(" Reserved"); \
break; \
} \
sum += val; \
break; \
} while (0)
switch (bit + base) {
CAPA(0, "HT Information Exchange Supported");
CAPA(1, "reserved (On-demand Beacon)");
CAPA(2, "Extended Channel Switching");
CAPA(3, "reserved (Wave Indication)");
CAPA(4, "PSMP Capability");
CAPA(5, "reserved (Service Interval Granularity)");
case 6:
s_psmp_support = true;
printf(" S-PSMP Capability");
break;
CAPA(7, "Event");
CAPA(8, "Diagnostics");
CAPA(9, "Multicast Diagnostics");
CAPA(10, "Location Tracking");
CAPA(11, "FMS");
CAPA(12, "Proxy ARP Service");
CAPA(13, "Collocated Interference Reporting");
CAPA(14, "Civic Location");
CAPA(15, "Geospatial Location");
CAPA(16, "TFS");
CAPA(17, "WNM-Sleep Mode");
CAPA(18, "TIM Broadcast");
CAPA(19, "BSS Transition");
CAPA(20, "QoS Traffic Capability");
CAPA(21, "AC Station Count");
CAPA(22, "Multiple BSSID");
CAPA(23, "Timing Measurement");
CAPA(24, "Channel Usage");
CAPA(25, "SSID List");
CAPA(26, "DMS");
CAPA(27, "UTC TSF Offset");
CAPA(28, "TDLS Peer U-APSD Buffer STA Support");
CAPA(29, "TDLS Peer PSM Support");
CAPA(30, "TDLS channel switching");
CAPA(31, "Interworking");
CAPA(32, "QoS Map");
CAPA(33, "EBR");
CAPA(34, "SSPN Interface");
CAPA(35, "Reserved");
CAPA(36, "MSGCF Capability");
CAPA(37, "TDLS Support");
CAPA(38, "TDLS Prohibited");
CAPA(39, "TDLS Channel Switching Prohibited");
CAPA(40, "Reject Unadmitted Frame");
ADD_BIT_VAL(41, s_psmp_support, si_duration, 1);
ADD_BIT_VAL(42, s_psmp_support, si_duration, 2);
ADD_BIT_VAL(43, s_psmp_support, si_duration, 4);
CAPA(44, "Identifier Location");
CAPA(45, "U-APSD Coexistence");
CAPA(46, "WNM-Notification");
CAPA(47, "Reserved");
CAPA(48, "UTF-8 SSID");
CAPA(49, "QMFActivated");
CAPA(50, "QMFReconfigurationActivated");
CAPA(51, "Robust AV Streaming");
CAPA(52, "Advanced GCR");
CAPA(53, "Mesh GCR");
CAPA(54, "SCS");
CAPA(55, "QLoad Report");
CAPA(56, "Alternate EDCA");
CAPA(57, "Unprotected TXOP Negotiation");
CAPA(58, "Protected TXOP egotiation");
CAPA(59, "Reserved");
CAPA(60, "Protected QLoad Report");
CAPA(61, "TDLS Wider Bandwidth");
CAPA(62, "Operating Mode Notification");
ADD_BIT_VAL(63, is_vht_cap, max_amsdu, 1);
ADD_BIT_VAL(64, is_vht_cap, max_amsdu, 2);
CAPA(65, "Channel Schedule Management");
CAPA(66, "Geodatabase Inband Enabling Signal");
CAPA(67, "Network Channel Control");
CAPA(68, "White Space Map");
CAPA(69, "Channel Availability Query");
CAPA(70, "FTM Responder");
CAPA(71, "FTM Initiator");
CAPA(72, "Reserved");
CAPA(73, "Extended Spectrum Management Capable");
CAPA(74, "Reserved");
default:
printf(" %d", bit);
break;
}
#undef ADD_BIT_VAL
#undef CAPA
}
}
if (s_psmp_support)
printf("\n\t\t * Service Interval Granularity is %d ms",
(si_duration + 1) * 5);
if (is_vht_cap) {
printf("\n\t\t * Max Number Of MSDUs In A-MSDU is ");
switch (max_amsdu) {
case 0:
printf("unlimited");
break;
case 1:
printf("32");
break;
case 2:
printf("16");
break;
case 3:
printf("8");
break;
default:
break;
}
}
printf("\n");
}
static void print_tim(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf(" DTIM Count %u DTIM Period %u Bitmap Control 0x%x "
"Bitmap[0] 0x%x",
data[0], data[1], data[2], data[3]);
if (len - 4)
printf(" (+ %u octet%s)", len - 4, len - 4 == 1 ? "" : "s");
printf("\n");
}
static void print_ibssatim(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf(" %d TUs\n", (data[1] << 8) + data[0]);
}
static void print_vht_capa(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf("\n");
print_vht_info((__u32) data[0] | ((__u32)data[1] << 8) |
((__u32)data[2] << 16) | ((__u32)data[3] << 24),
data + 4);
}
static void print_vht_oper(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
const char *chandwidths[] = {
[0] = "20 or 40 MHz",
[1] = "80 MHz",
[3] = "80+80 MHz",
[2] = "160 MHz",
};
printf("\n");
printf("\t\t * channel width: %d (%s)\n", data[0],
data[0] < ARRAY_SIZE(chandwidths) ? chandwidths[data[0]] : "unknown");
printf("\t\t * center freq segment 1: %d\n", data[1]);
printf("\t\t * center freq segment 2: %d\n", data[2]);
printf("\t\t * VHT basic MCS set: 0x%.2x%.2x\n", data[4], data[3]);
}
static void print_supp_op_classes(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
uint8_t *p = (uint8_t*) data;
const uint8_t *next_data = p + len;
int zero_delimiter = 0;
int one_hundred_thirty_delimiter = 0;
printf("\n");
printf("\t\t * current operating class: %d\n", *p);
while (++p < next_data) {
if (*p == 130) {
one_hundred_thirty_delimiter = 1;
break;
}
if (*p == 0) {
zero_delimiter = 0;
break;
}
printf("\t\t * operating class: %d\n", *p);
}
if (one_hundred_thirty_delimiter)
while (++p < next_data) {
printf("\t\t * current operating class extension: %d\n", *p);
}
if (zero_delimiter)
while (++p < next_data - 1) {
printf("\t\t * operating class tuple: %d %d\n", p[0], p[1]);
if (*p == 0)
break;
}
}
static void print_measurement_pilot_tx(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
uint8_t *p, len_remaining;
printf("\n");
printf("\t\t * interval: %d TUs\n", data[0]);
if (len <= 1)
return;
p = (uint8_t *) data + 1;
len_remaining = len - 1;
while (len_remaining >=5) {
uint8_t subelement_id = *p, len, *end;
p++;
len = *p;
p++;
end = p + len;
len_remaining -= 2;
/* 802.11-2016 only allows vendor specific elements */
if (subelement_id != 221) {
printf("\t\t * <Invalid subelement ID %d>\n", subelement_id);
return;
}
if (len < 3 || len > len_remaining) {
printf(" <Parse error, element too short>\n");
return;
}
printf("\t\t * vendor specific: OUI %.2x:%.2x:%.2x, data:",
p[0], p[1], p[2]);
/* add only two here and use ++p in while loop */
p += 2;
while (++p < end)
printf(" %.2x", *p);
printf("\n");
len_remaining -= len;
}
}
static void print_obss_scan_params(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf("\n");
printf("\t\t * passive dwell: %d TUs\n", (data[1] << 8) | data[0]);
printf("\t\t * active dwell: %d TUs\n", (data[3] << 8) | data[2]);
printf("\t\t * channel width trigger scan interval: %d s\n", (data[5] << 8) | data[4]);
printf("\t\t * scan passive total per channel: %d TUs\n", (data[7] << 8) | data[6]);
printf("\t\t * scan active total per channel: %d TUs\n", (data[9] << 8) | data[8]);
printf("\t\t * BSS width channel transition delay factor: %d\n", (data[11] << 8) | data[10]);
printf("\t\t * OBSS Scan Activity Threshold: %d.%02d %%\n",
((data[13] << 8) | data[12]) / 100, ((data[13] << 8) | data[12]) % 100);
}
static void print_secchan_offs(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
if (data[0] < ARRAY_SIZE(ht_secondary_offset))
printf(" %s (%d)\n", ht_secondary_offset[data[0]], data[0]);
else
printf(" %d\n", data[0]);
}
static void print_bss_load(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf("\n");
printf("\t\t * station count: %d\n", (data[1] << 8) | data[0]);
printf("\t\t * channel utilisation: %d/255\n", data[2]);
printf("\t\t * available admission capacity: %d [*32us]\n", (data[4] << 8) | data[3]);
}
static void print_mesh_conf(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf("\n");
printf("\t\t * Active Path Selection Protocol ID: %d\n", data[0]);
printf("\t\t * Active Path Selection Metric ID: %d\n", data[1]);
printf("\t\t * Congestion Control Mode ID: %d\n", data[2]);
printf("\t\t * Synchronization Method ID: %d\n", data[3]);
printf("\t\t * Authentication Protocol ID: %d\n", data[4]);
printf("\t\t * Mesh Formation Info:\n");
printf("\t\t\t Number of Peerings: %d\n", (data[5] & 0x7E) >> 1);
if (data[5] & 0x01)
printf("\t\t\t Connected to Mesh Gate\n");
if (data[5] & 0x80)
printf("\t\t\t Connected to AS\n");
printf("\t\t * Mesh Capability\n");
if (data[6] & 0x01)
printf("\t\t\t Accepting Additional Mesh Peerings\n");
if (data[6] & 0x02)
printf("\t\t\t MCCA Supported\n");
if (data[6] & 0x04)
printf("\t\t\t MCCA Enabled\n");
if (data[6] & 0x08)
printf("\t\t\t Forwarding\n");
if (data[6] & 0x10)
printf("\t\t\t MBCA Supported\n");
if (data[6] & 0x20)
printf("\t\t\t TBTT Adjusting\n");
if (data[6] & 0x40)
printf("\t\t\t Mesh Power Save Level\n");
}
struct ie_print {
const char *name;
void (*print)(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer);
uint8_t minlen, maxlen;
uint8_t flags;
};
static void print_ie(const struct ie_print *p, const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
int i;
if (!p->print)
return;
printf("\t%s:", p->name);
if (len < p->minlen || len > p->maxlen) {
if (len > 1) {
printf(" <invalid: %d bytes:", len);
for (i = 0; i < len; i++)
printf(" %.02x", data[i]);
printf(">\n");
} else if (len)
printf(" <invalid: 1 byte: %.02x>\n", data[0]);
else
printf(" <invalid: no data>\n");
return;
}
p->print(type, len, data, ie_buffer);
}
#define PRINT_IGN { \
.name = "IGNORE", \
.print = NULL, \
.minlen = 0, \
.maxlen = 255, \
}
static const struct ie_print ieprinters[] = {
[0] = { "SSID", print_ssid, 0, 32, BIT(PRINT_SCAN) | BIT(PRINT_LINK), },
[1] = { "Supported rates", print_supprates, 0, 255, BIT(PRINT_SCAN), },
[3] = { "DS Parameter set", print_ds, 1, 1, BIT(PRINT_SCAN), },
[5] = { "TIM", print_tim, 4, 255, BIT(PRINT_SCAN), },
[6] = { "IBSS ATIM window", print_ibssatim, 2, 2, BIT(PRINT_SCAN), },
[7] = { "Country", print_country, 3, 255, BIT(PRINT_SCAN), },
[11] = { "BSS Load", print_bss_load, 5, 5, BIT(PRINT_SCAN), },
[32] = { "Power constraint", print_powerconstraint, 1, 1, BIT(PRINT_SCAN), },
[35] = { "TPC report", print_tpcreport, 2, 2, BIT(PRINT_SCAN), },
[42] = { "ERP", print_erp, 1, 255, BIT(PRINT_SCAN), },
[45] = { "HT capabilities", print_ht_capa, 26, 26, BIT(PRINT_SCAN), },
[47] = { "ERP D4.0", print_erp, 1, 255, BIT(PRINT_SCAN), },
[51] = { "AP Channel Report", print_ap_channel_report, 1, 255, BIT(PRINT_SCAN), },
[59] = { "Supported operating classes", print_supp_op_classes, 1, 255, BIT(PRINT_SCAN), },
[66] = { "Measurement Pilot Transmission", print_measurement_pilot_tx, 1, 255, BIT(PRINT_SCAN), },
[74] = { "Overlapping BSS scan params", print_obss_scan_params, 14, 255, BIT(PRINT_SCAN), },
[61] = { "HT operation", print_ht_op, 22, 22, BIT(PRINT_SCAN), },
[62] = { "Secondary Channel Offset", print_secchan_offs, 1, 1, BIT(PRINT_SCAN), },
[191] = { "VHT capabilities", print_vht_capa, 12, 255, BIT(PRINT_SCAN), },
[192] = { "VHT operation", print_vht_oper, 5, 255, BIT(PRINT_SCAN), },
[48] = { "RSN", print_rsn, 2, 255, BIT(PRINT_SCAN), },
[50] = { "Extended supported rates", print_supprates, 0, 255, BIT(PRINT_SCAN), },
[70] = { "RM enabled capabilities", print_rm_enabled_capabilities, 5, 5, BIT(PRINT_SCAN), },
[113] = { "MESH Configuration", print_mesh_conf, 7, 7, BIT(PRINT_SCAN), },
[114] = { "MESH ID", print_ssid, 0, 32, BIT(PRINT_SCAN) | BIT(PRINT_LINK), },
[127] = { "Extended capabilities", print_capabilities, 0, 255, BIT(PRINT_SCAN), },
[107] = { "802.11u Interworking", print_interworking, 0, 255, BIT(PRINT_SCAN), },
[108] = { "802.11u Advertisement", print_11u_advert, 0, 255, BIT(PRINT_SCAN), },
[111] = { "802.11u Roaming Consortium", print_11u_rcon, 2, 255, BIT(PRINT_SCAN), },
[195] = { "Transmit Power Envelope", print_tx_power_envelope, 2, 5, BIT(PRINT_SCAN), },
};
static void print_wifi_wpa(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
print_rsn_ie("TKIP", "IEEE 802.1X", len, data);
}
static void print_wifi_osen(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
print_osen_ie("OSEN", "OSEN", len, data);
}
static bool print_wifi_wmm_param(const uint8_t *data, uint8_t len)
{
int i;
static const char *aci_tbl[] = { "BE", "BK", "VI", "VO" };
if (len < 19)
goto invalid;
if (data[0] != 1) {
printf("Parameter: not version 1: ");
return false;
}
printf("\t * Parameter version 1");
data++;
if (data[0] & 0x80)
printf("\n\t\t * u-APSD");
data += 2;
for (i = 0; i < 4; i++) {
printf("\n\t\t * %s:", aci_tbl[(data[0] >> 5) & 3]);
if (data[0] & 0x10)
printf(" acm");
printf(" CW %d-%d", (1 << (data[1] & 0xf)) - 1,
(1 << (data[1] >> 4)) - 1);
printf(", AIFSN %d", data[0] & 0xf);
if (data[2] | data[3])
printf(", TXOP %d usec", (data[2] + (data[3] << 8)) * 32);
data += 4;
}
printf("\n");
return true;
invalid:
printf("invalid: ");
return false;
}
static void print_wifi_wmm(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
int i;
switch (data[0]) {
case 0x00:
printf(" information:");
break;
case 0x01:
if (print_wifi_wmm_param(data + 1, len - 1))
return;
break;
default:
printf(" type %d:", data[0]);
break;
}
for(i = 1; i < len; i++)
printf(" %.02x", data[i]);
printf("\n");
}
static const char * wifi_wps_dev_passwd_id(uint16_t id)
{
switch (id) {
case 0:
return "Default (PIN)";
case 1:
return "User-specified";
case 2:
return "Machine-specified";
case 3:
return "Rekey";
case 4:
return "PushButton";
case 5:
return "Registrar-specified";
default:
return "??";
}
}
static void print_wifi_wps(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
bool first = true;
__u16 subtype, sublen;
while (len >= 4) {
subtype = (data[0] << 8) + data[1];
sublen = (data[2] << 8) + data[3];
if (sublen > len - 4)
break;
switch (subtype) {
case 0x104a:
tab_on_first(&first);
if (sublen < 1) {
printf("\t * Version: (invalid "
"length %d)\n", sublen);
break;
}
printf("\t * Version: %d.%d\n", data[4] >> 4, data[4] & 0xF);
break;
case 0x1011:
tab_on_first(&first);
printf("\t * Device name: %.*s\n", sublen, data + 4);
break;
case 0x1012: {
uint16_t id;
tab_on_first(&first);
if (sublen != 2) {
printf("\t * Device Password ID: (invalid length %d)\n",
sublen);
break;
}
id = data[4] << 8 | data[5];
printf("\t * Device Password ID: %u (%s)\n",
id, wifi_wps_dev_passwd_id(id));
break;
}
case 0x1021:
tab_on_first(&first);
printf("\t * Manufacturer: %.*s\n", sublen, data + 4);
break;
case 0x1023:
tab_on_first(&first);
printf("\t * Model: %.*s\n", sublen, data + 4);
break;
case 0x1024:
tab_on_first(&first);
printf("\t * Model Number: %.*s\n", sublen, data + 4);
break;
case 0x103b: {
__u8 val;
if (sublen < 1) {
printf("\t * Response Type: (invalid length %d)\n",
sublen);
break;
}
val = data[4];
tab_on_first(&first);
printf("\t * Response Type: %d%s\n",
val, val == 3 ? " (AP)" : "");
break;
}
case 0x103c: {
__u8 val;
if (sublen < 1) {
printf("\t * RF Bands: (invalid length %d)\n",
sublen);
break;
}
val = data[4];
tab_on_first(&first);
printf("\t * RF Bands: 0x%x\n", val);
break;
}
case 0x1041: {
__u8 val;
if (sublen < 1) {
printf("\t * Selected Registrar: (invalid length %d)\n",
sublen);
break;
}
val = data[4];
tab_on_first(&first);
printf("\t * Selected Registrar: 0x%x\n", val);
break;
}
case 0x1042:
tab_on_first(&first);
printf("\t * Serial Number: %.*s\n", sublen, data + 4);
break;
case 0x1044: {
__u8 val;
if (sublen < 1) {
printf("\t * Wi-Fi Protected Setup State: (invalid length %d)\n",
sublen);
break;
}
val = data[4];
tab_on_first(&first);
printf("\t * Wi-Fi Protected Setup State: %d%s%s\n",
val,
val == 1 ? " (Unconfigured)" : "",
val == 2 ? " (Configured)" : "");
break;
}
case 0x1047:
tab_on_first(&first);
printf("\t * UUID: ");
if (sublen != 16) {
printf("(invalid, length=%d)\n", sublen);
break;
}
printf("%02x%02x%02x%02x-%02x%02x-%02x%02x-"
"%02x%02x-%02x%02x%02x%02x%02x%02x\n",
data[4], data[5], data[6], data[7],
data[8], data[9], data[10], data[11],
data[12], data[13], data[14], data[15],
data[16], data[17], data[18], data[19]);
break;
case 0x1049:
tab_on_first(&first);
if (sublen == 6 &&
data[4] == 0x00 &&
data[5] == 0x37 &&
data[6] == 0x2a &&
data[7] == 0x00 &&
data[8] == 0x01) {
uint8_t v2 = data[9];
printf("\t * Version2: %d.%d\n", v2 >> 4, v2 & 0xf);
} else {
printf("\t * Unknown vendor extension. len=%u\n",
sublen);
}
break;
case 0x1054: {
tab_on_first(&first);
if (sublen != 8) {
printf("\t * Primary Device Type: (invalid length %d)\n",
sublen);
break;
}
printf("\t * Primary Device Type: "
"%u-%02x%02x%02x%02x-%u\n",
data[4] << 8 | data[5],
data[6], data[7], data[8], data[9],
data[10] << 8 | data[11]);
break;
}
case 0x1057: {
__u8 val;
tab_on_first(&first);
if (sublen < 1) {
printf("\t * AP setup locked: (invalid length %d)\n",
sublen);
break;
}
val = data[4];
printf("\t * AP setup locked: 0x%.2x\n", val);
break;
}
case 0x1008:
case 0x1053: {
__u16 meth;
bool comma;
if (sublen < 2) {
printf("\t * Config methods: (invalid length %d)\n",
sublen);
break;
}
meth = (data[4] << 8) + data[5];
comma = false;
tab_on_first(&first);
printf("\t * %sConfig methods:",
subtype == 0x1053 ? "Selected Registrar ": "");
#define T(bit, name) do { \
if (meth & (1<<bit)) { \
if (comma) \
printf(","); \
comma = true; \
printf(" " name); \
} } while (0)
T(0, "USB");
T(1, "Ethernet");
T(2, "Label");
T(3, "Display");
T(4, "Ext. NFC");
T(5, "Int. NFC");
T(6, "NFC Intf.");
T(7, "PBC");
T(8, "Keypad");
printf("\n");
break;
#undef T
}
default: {
const __u8 *subdata = data + 4;
__u16 tmplen = sublen;
tab_on_first(&first);
printf("\t * Unknown TLV (%#.4x, %d bytes):",
subtype, tmplen);
while (tmplen) {
printf(" %.2x", *subdata);
subdata++;
tmplen--;
}
printf("\n");
break;
}
}
data += sublen + 4;
len -= sublen + 4;
}
if (len != 0) {
printf("\t\t * bogus tail data (%d):", len);
while (len) {
printf(" %.2x", *data);
data++;
len--;
}
printf("\n");
}
}
static const struct ie_print wifiprinters[] = {
[1] = { "WPA", print_wifi_wpa, 2, 255, BIT(PRINT_SCAN), },
[2] = { "WMM", print_wifi_wmm, 1, 255, BIT(PRINT_SCAN), },
[4] = { "WPS", print_wifi_wps, 0, 255, BIT(PRINT_SCAN), },
};
static inline void print_p2p(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
bool first = true;
__u8 subtype;
__u16 sublen;
while (len >= 3) {
subtype = data[0];
sublen = (data[2] << 8) + data[1];
if (sublen > len - 3)
break;
switch (subtype) {
case 0x02: /* capability */
tab_on_first(&first);
if (sublen < 2) {
printf("\t * malformed capability\n");
break;
}
printf("\t * Group capa: 0x%.2x, Device capa: 0x%.2x\n",
data[3], data[4]);
break;
case 0x0d: /* device info */
if (sublen < 6 + 2 + 8 + 1) {
printf("\t * malformed device info\n");
break;
}
/* fall through */
case 0x00: /* status */
case 0x01: /* minor reason */
case 0x03: /* device ID */
case 0x04: /* GO intent */
case 0x05: /* configuration timeout */
case 0x06: /* listen channel */
case 0x07: /* group BSSID */
case 0x08: /* ext listen timing */
case 0x09: /* intended interface address */
case 0x0a: /* manageability */
case 0x0b: /* channel list */
case 0x0c: /* NoA */
case 0x0e: /* group info */
case 0x0f: /* group ID */
case 0x10: /* interface */
case 0x11: /* operating channel */
case 0x12: /* invitation flags */
case 0xdd: /* vendor specific */
default: {
const __u8 *subdata = data + 3;
__u16 tmplen = sublen;
tab_on_first(&first);
printf("\t * Unknown TLV (%#.2x, %d bytes):",
subtype, tmplen);
while (tmplen) {
printf(" %.2x", *subdata);
subdata++;
tmplen--;
}
printf("\n");
break;
}
}
data += sublen + 3;
len -= sublen + 3;
}
if (len != 0) {
tab_on_first(&first);
printf("\t * bogus tail data (%d):", len);
while (len) {
printf(" %.2x", *data);
data++;
len--;
}
printf("\n");
}
}
static inline void print_hs20_ind(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
/* I can't find the spec for this...just going off what wireshark uses. */
printf("\n");
if (len > 0)
printf("\t\tDGAF: %i\n", (int)(data[0] & 0x1));
else
printf("\t\tUnexpected length: %i\n", len);
}
static void print_wifi_owe_tarns(const uint8_t type, uint8_t len,
const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
char mac_addr[20];
int ssid_len;
printf("\n");
if (len < 7)
return;
mac_addr_n2a(mac_addr, data);
printf("\t\tBSSID: %s\n", mac_addr);
ssid_len = data[6];
if (ssid_len > len - 7)
return;
printf("\t\tSSID: ");
print_ssid_escaped(ssid_len, data + 7);
printf("\n");
/* optional elements */
if (len >= ssid_len + 9) {
printf("\t\tBand Info: %u\n", data[ssid_len + 7]);
printf("\t\tChannel Info: %u\n", data[ssid_len + 8]);
}
}
static const struct ie_print wfa_printers[] = {
[9] = { "P2P", print_p2p, 2, 255, BIT(PRINT_SCAN), },
[16] = { "HotSpot 2.0 Indication", print_hs20_ind, 1, 255, BIT(PRINT_SCAN), },
[18] = { "HotSpot 2.0 OSEN", print_wifi_osen, 1, 255, BIT(PRINT_SCAN), },
[28] = { "OWE Transition Mode", print_wifi_owe_tarns, 7, 255, BIT(PRINT_SCAN), },
};
static void print_vendor(unsigned char len, unsigned char *data,
bool unknown, enum print_ie_type ptype)
{
int i;
if (len < 3) {
printf("\tVendor specific: <too short> data:");
for(i = 0; i < len; i++)
printf(" %.02x", data[i]);
printf("\n");
return;
}
if (len >= 4 && memcmp(data, ms_oui, 3) == 0) {
if (data[3] < ARRAY_SIZE(wifiprinters) &&
wifiprinters[data[3]].name &&
wifiprinters[data[3]].flags & BIT(ptype)) {
print_ie(&wifiprinters[data[3]],
data[3], len - 4, data + 4,
NULL);
return;
}
if (!unknown)
return;
printf("\tMS/WiFi %#.2x, data:", data[3]);
for(i = 0; i < len - 4; i++)
printf(" %.02x", data[i + 4]);
printf("\n");
return;
}
if (len >= 4 && memcmp(data, wfa_oui, 3) == 0) {
if (data[3] < ARRAY_SIZE(wfa_printers) &&
wfa_printers[data[3]].name &&
wfa_printers[data[3]].flags & BIT(ptype)) {
print_ie(&wfa_printers[data[3]],
data[3], len - 4, data + 4,
NULL);
return;
}
if (!unknown)
return;
printf("\tWFA %#.2x, data:", data[3]);
for(i = 0; i < len - 4; i++)
printf(" %.02x", data[i + 4]);
printf("\n");
return;
}
if (!unknown)
return;
printf("\tVendor specific: OUI %.2x:%.2x:%.2x, data:",
data[0], data[1], data[2]);
for (i = 3; i < len; i++)
printf(" %.2x", data[i]);
printf("\n");
}
static void print_he_capa(const uint8_t type, uint8_t len, const uint8_t *data,
const struct print_ies_data *ie_buffer)
{
printf("\n");
print_he_capability(data, len);
}
static const struct ie_print ext_printers[] = {
[35] = { "HE capabilities", print_he_capa, 21, 54, BIT(PRINT_SCAN), },
};
static void print_extension(unsigned char len, unsigned char *ie,
bool unknown, enum print_ie_type ptype)
{
unsigned char tag;
if (len < 1) {
printf("\tExtension IE: <empty>\n");
return;
}
tag = ie[0];
if (tag < ARRAY_SIZE(ext_printers) && ext_printers[tag].name &&
ext_printers[tag].flags & BIT(ptype)) {
print_ie(&ext_printers[tag], tag, len - 1, ie + 1, NULL);
return;
}
if (unknown) {
int i;
printf("\tUnknown Extension ID (%d):", ie[0]);
for (i = 1; i < len; i++)
printf(" %.2x", ie[i]);
printf("\n");
}
}
void print_ies(unsigned char *ie, int ielen, bool unknown,
enum print_ie_type ptype)
{
struct print_ies_data ie_buffer = {
.ie = ie,
.ielen = ielen };
if (ie == NULL || ielen < 0)
return;
while (ielen >= 2 && ielen - 2 >= ie[1]) {
if (ie[0] < ARRAY_SIZE(ieprinters) &&
ieprinters[ie[0]].name &&
ieprinters[ie[0]].flags & BIT(ptype)) {
print_ie(&ieprinters[ie[0]],
ie[0], ie[1], ie + 2, &ie_buffer);
} else if (ie[0] == 221 /* vendor */) {
print_vendor(ie[1], ie + 2, unknown, ptype);
} else if (ie[0] == 255 /* extension */) {
print_extension(ie[1], ie + 2, unknown, ptype);
} else if (unknown) {
int i;
printf("\tUnknown IE (%d):", ie[0]);
for (i=0; i<ie[1]; i++)
printf(" %.2x", ie[2+i]);
printf("\n");
}
ielen -= ie[1] + 2;
ie += ie[1] + 2;
}
}
static void print_capa_dmg(__u16 capa)
{
switch (capa & WLAN_CAPABILITY_DMG_TYPE_MASK) {
case WLAN_CAPABILITY_DMG_TYPE_AP:
printf(" DMG_ESS");
break;
case WLAN_CAPABILITY_DMG_TYPE_PBSS:
printf(" DMG_PCP");
break;
case WLAN_CAPABILITY_DMG_TYPE_IBSS:
printf(" DMG_IBSS");
break;
}
if (capa & WLAN_CAPABILITY_DMG_CBAP_ONLY)
printf(" CBAP_Only");
if (capa & WLAN_CAPABILITY_DMG_CBAP_SOURCE)
printf(" CBAP_Src");
if (capa & WLAN_CAPABILITY_DMG_PRIVACY)
printf(" Privacy");
if (capa & WLAN_CAPABILITY_DMG_ECPAC)
printf(" ECPAC");
if (capa & WLAN_CAPABILITY_DMG_SPECTRUM_MGMT)
printf(" SpectrumMgmt");
if (capa & WLAN_CAPABILITY_DMG_RADIO_MEASURE)
printf(" RadioMeasure");
}
static void print_capa_non_dmg(__u16 capa)
{
if (capa & WLAN_CAPABILITY_ESS)
printf(" ESS");
if (capa & WLAN_CAPABILITY_IBSS)
printf(" IBSS");
if (capa & WLAN_CAPABILITY_CF_POLLABLE)
printf(" CfPollable");
if (capa & WLAN_CAPABILITY_CF_POLL_REQUEST)
printf(" CfPollReq");
if (capa & WLAN_CAPABILITY_PRIVACY)
printf(" Privacy");
if (capa & WLAN_CAPABILITY_SHORT_PREAMBLE)
printf(" ShortPreamble");
if (capa & WLAN_CAPABILITY_PBCC)
printf(" PBCC");
if (capa & WLAN_CAPABILITY_CHANNEL_AGILITY)
printf(" ChannelAgility");
if (capa & WLAN_CAPABILITY_SPECTRUM_MGMT)
printf(" SpectrumMgmt");
if (capa & WLAN_CAPABILITY_QOS)
printf(" QoS");
if (capa & WLAN_CAPABILITY_SHORT_SLOT_TIME)
printf(" ShortSlotTime");
if (capa & WLAN_CAPABILITY_APSD)
printf(" APSD");
if (capa & WLAN_CAPABILITY_RADIO_MEASURE)
printf(" RadioMeasure");
if (capa & WLAN_CAPABILITY_DSSS_OFDM)
printf(" DSSS-OFDM");
if (capa & WLAN_CAPABILITY_DEL_BACK)
printf(" DelayedBACK");
if (capa & WLAN_CAPABILITY_IMM_BACK)
printf(" ImmediateBACK");
}
static int print_bss_handler(struct nl_msg *msg, void *arg)
{
struct nlattr *tb[NL80211_ATTR_MAX + 1];
struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
struct nlattr *bss[NL80211_BSS_MAX + 1];
char mac_addr[20], dev[20];
static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = {
[NL80211_BSS_TSF] = { .type = NLA_U64 },
[NL80211_BSS_FREQUENCY] = { .type = NLA_U32 },
[NL80211_BSS_BSSID] = { },
[NL80211_BSS_BEACON_INTERVAL] = { .type = NLA_U16 },
[NL80211_BSS_CAPABILITY] = { .type = NLA_U16 },
[NL80211_BSS_INFORMATION_ELEMENTS] = { },
[NL80211_BSS_SIGNAL_MBM] = { .type = NLA_U32 },
[NL80211_BSS_SIGNAL_UNSPEC] = { .type = NLA_U8 },
[NL80211_BSS_STATUS] = { .type = NLA_U32 },
[NL80211_BSS_SEEN_MS_AGO] = { .type = NLA_U32 },
[NL80211_BSS_BEACON_IES] = { },
};
struct scan_params *params = arg;
int show = params->show_both_ie_sets ? 2 : 1;
bool is_dmg = false;
nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
if (!tb[NL80211_ATTR_BSS]) {
fprintf(stderr, "bss info missing!\n");
return NL_SKIP;
}
if (nla_parse_nested(bss, NL80211_BSS_MAX,
tb[NL80211_ATTR_BSS],
bss_policy)) {
fprintf(stderr, "failed to parse nested attributes!\n");
return NL_SKIP;
}
if (!bss[NL80211_BSS_BSSID])
return NL_SKIP;
mac_addr_n2a(mac_addr, nla_data(bss[NL80211_BSS_BSSID]));
printf("BSS %s", mac_addr);
if (tb[NL80211_ATTR_IFINDEX]) {
if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
printf("(on %s)", dev);
}
if (bss[NL80211_BSS_STATUS]) {
switch (nla_get_u32(bss[NL80211_BSS_STATUS])) {
case NL80211_BSS_STATUS_AUTHENTICATED:
printf(" -- authenticated");
break;
case NL80211_BSS_STATUS_ASSOCIATED:
printf(" -- associated");
break;
case NL80211_BSS_STATUS_IBSS_JOINED:
printf(" -- joined");
break;
default:
printf(" -- unknown status: %d",
nla_get_u32(bss[NL80211_BSS_STATUS]));
break;
}
}
printf("\n");
if (bss[NL80211_BSS_LAST_SEEN_BOOTTIME]) {
unsigned long long bt;
bt = (unsigned long long)nla_get_u64(bss[NL80211_BSS_LAST_SEEN_BOOTTIME]);
printf("\tlast seen: %llu.%.3llus [boottime]\n", bt/1000000000, (bt%1000000000)/1000000);
}
if (bss[NL80211_BSS_TSF]) {
unsigned long long tsf;
tsf = (unsigned long long)nla_get_u64(bss[NL80211_BSS_TSF]);
printf("\tTSF: %llu usec (%llud, %.2lld:%.2llu:%.2llu)\n",
tsf, tsf/1000/1000/60/60/24, (tsf/1000/1000/60/60) % 24,
(tsf/1000/1000/60) % 60, (tsf/1000/1000) % 60);
}
if (bss[NL80211_BSS_FREQUENCY]) {
int freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
printf("\tfreq: %d\n", freq);
if (freq > 45000)
is_dmg = true;
}
if (bss[NL80211_BSS_BEACON_INTERVAL])
printf("\tbeacon interval: %d TUs\n",
nla_get_u16(bss[NL80211_BSS_BEACON_INTERVAL]));
if (bss[NL80211_BSS_CAPABILITY]) {
__u16 capa = nla_get_u16(bss[NL80211_BSS_CAPABILITY]);
printf("\tcapability:");
if (is_dmg)
print_capa_dmg(capa);
else
print_capa_non_dmg(capa);
printf(" (0x%.4x)\n", capa);
}
if (bss[NL80211_BSS_SIGNAL_MBM]) {
int s = nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]);
printf("\tsignal: %d.%.2d dBm\n", s/100, s%100);
}
if (bss[NL80211_BSS_SIGNAL_UNSPEC]) {
unsigned char s = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]);
printf("\tsignal: %d/100\n", s);
}
if (bss[NL80211_BSS_SEEN_MS_AGO]) {
int age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]);
printf("\tlast seen: %d ms ago\n", age);
}
if (bss[NL80211_BSS_INFORMATION_ELEMENTS] && show--) {
struct nlattr *ies = bss[NL80211_BSS_INFORMATION_ELEMENTS];
struct nlattr *bcnies = bss[NL80211_BSS_BEACON_IES];
if (bss[NL80211_BSS_PRESP_DATA] ||
(bcnies && (nla_len(ies) != nla_len(bcnies) ||
memcmp(nla_data(ies), nla_data(bcnies),
nla_len(ies)))))
printf("\tInformation elements from Probe Response "
"frame:\n");
print_ies(nla_data(ies), nla_len(ies),
params->unknown, params->type);
}
if (bss[NL80211_BSS_BEACON_IES] && show--) {
printf("\tInformation elements from Beacon frame:\n");
print_ies(nla_data(bss[NL80211_BSS_BEACON_IES]),
nla_len(bss[NL80211_BSS_BEACON_IES]),
params->unknown, params->type);
}
return NL_SKIP;
}
static struct scan_params scan_params;
static int handle_scan_dump(struct nl80211_state *state,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
{
if (argc > 1)
return 1;
memset(&scan_params, 0, sizeof(scan_params));
if (argc == 1 && !strcmp(argv[0], "-u"))
scan_params.unknown = true;
else if (argc == 1 && !strcmp(argv[0], "-b"))
scan_params.show_both_ie_sets = true;
scan_params.type = PRINT_SCAN;
register_handler(print_bss_handler, &scan_params);
return 0;
}
static int handle_scan_combined(struct nl80211_state *state,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
{
char **trig_argv;
static char *dump_argv[] = {
NULL,
"scan",
"dump",
NULL,
};
static const __u32 cmds[] = {
NL80211_CMD_NEW_SCAN_RESULTS,
NL80211_CMD_SCAN_ABORTED,
};
int trig_argc, dump_argc, err;
int i;
if (argc >= 3 && !strcmp(argv[2], "-u")) {
dump_argc = 4;
dump_argv[3] = "-u";
} else if (argc >= 3 && !strcmp(argv[2], "-b")) {
dump_argc = 4;
dump_argv[3] = "-b";
} else
dump_argc = 3;
trig_argc = 3 + (argc - 2) + (3 - dump_argc);
trig_argv = calloc(trig_argc, sizeof(*trig_argv));
if (!trig_argv)
return -ENOMEM;
trig_argv[0] = argv[0];
trig_argv[1] = "scan";
trig_argv[2] = "trigger";
for (i = 0; i < argc - 2 - (dump_argc - 3); i++)
trig_argv[i + 3] = argv[i + 2 + (dump_argc - 3)];
err = handle_cmd(state, id, trig_argc, trig_argv);
free(trig_argv);
if (err)
return err;
/*
* WARNING: DO NOT COPY THIS CODE INTO YOUR APPLICATION
*
* This code has a bug, which requires creating a separate
* nl80211 socket to fix:
* It is possible for a NL80211_CMD_NEW_SCAN_RESULTS or
* NL80211_CMD_SCAN_ABORTED message to be sent by the kernel
* before (!) we listen to it, because we only start listening
* after we send our scan request.
*
* Doing it the other way around has a race condition as well,
* if you first open the events socket you may get a notification
* for a previous scan.
*
* The only proper way to fix this would be to listen to events
* before sending the command, and for the kernel to send the
* scan request along with the event, so that you can match up
* whether the scan you requested was finished or aborted (this
* may result in processing a scan that another application
* requested, but that doesn't seem to be a problem).
*
* Alas, the kernel doesn't do that (yet).
*/
if (listen_events(state, ARRAY_SIZE(cmds), cmds) ==
NL80211_CMD_SCAN_ABORTED) {
printf("scan aborted!\n");
return 0;
}
dump_argv[0] = argv[0];
return handle_cmd(state, id, dump_argc, dump_argv);
}
TOPLEVEL(scan, "[-u] [freq <freq>*] [duration <dur>] [ies <hex as 00:11:..>] [meshid <meshid>] [lowpri,flush,ap-force,duration-mandatory] [randomise[=<addr>/<mask>]] [ssid <ssid>*|passive]", 0, 0,
CIB_NETDEV, handle_scan_combined,
"Scan on the given frequencies and probe for the given SSIDs\n"
"(or wildcard if not given) unless passive scanning is requested.\n"
"If -u is specified print unknown data in the scan results.\n"
"Specified (vendor) IEs must be well-formed.");
COMMAND(scan, dump, "[-u]",
NL80211_CMD_GET_SCAN, NLM_F_DUMP, CIB_NETDEV, handle_scan_dump,
"Dump the current scan results. If -u is specified, print unknown\n"
"data in scan results.");
COMMAND(scan, trigger, "[freq <freq>*] [duration <dur>] [ies <hex as 00:11:..>] [meshid <meshid>] [lowpri,flush,ap-force,duration-mandatory,coloc] [randomise[=<addr>/<mask>]] [ssid <ssid>*|passive]",
NL80211_CMD_TRIGGER_SCAN, 0, CIB_NETDEV, handle_scan,
"Trigger a scan on the given frequencies with probing for the given\n"
"SSIDs (or wildcard if not given) unless passive scanning is requested.\n"
"Duration(in TUs), if specified, will be used to set dwell times.\n");
static int handle_scan_abort(struct nl80211_state *state,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
{
return 0;
}
COMMAND(scan, abort, "",
NL80211_CMD_ABORT_SCAN, 0, CIB_NETDEV, handle_scan_abort,
"Abort ongoing scan");
static int handle_start_sched_scan(struct nl80211_state *state,
struct nl_msg *msg,
int argc, char **argv, enum id_input id)
{
return parse_sched_scan(msg, &argc, &argv);
}
static int handle_stop_sched_scan(struct nl80211_state *state,
struct nl_msg *msg, int argc, char **argv,
enum id_input id)
{
if (argc != 0)
return 1;
return 0;
}
COMMAND(scan, sched_start,
SCHED_SCAN_OPTIONS,
NL80211_CMD_START_SCHED_SCAN, 0, CIB_NETDEV, handle_start_sched_scan,
"Start a scheduled scan at the specified interval on the given frequencies\n"
"with probing for the given SSIDs (or wildcard if not given) unless passive\n"
"scanning is requested. If matches are specified, only matching results\n"
"will be returned.");
COMMAND(scan, sched_stop, "",
NL80211_CMD_STOP_SCHED_SCAN, 0, CIB_NETDEV, handle_stop_sched_scan,
"Stop an ongoing scheduled scan.");
|