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 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157
|
/*
* ui.c
*
* MontaVista IPMI code, a simple curses UI for IPMI
*
* Author: MontaVista Software, Inc.
* Corey Minyard <minyard@mvista.com>
* source@mvista.com
*
* Copyright 2002,2003,2004 MontaVista Software Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR 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, WHETHER IN 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curses.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <time.h>
#include <sys/time.h>
#include <ctype.h>
#include <OpenIPMI/selector.h>
#include <OpenIPMI/ipmi_err.h>
#include <OpenIPMI/ipmi_msgbits.h>
#include <OpenIPMI/ipmi_mc.h>
#include <OpenIPMI/ipmiif.h>
#include <OpenIPMI/ipmi_ui.h>
#include <OpenIPMI/ipmi_fru.h>
#include <OpenIPMI/ipmi_pef.h>
#include <OpenIPMI/ipmi_lanparm.h>
#include <OpenIPMI/ipmi_pet.h>
#include <OpenIPMI/ipmi_conn.h>
#include <OpenIPMI/ipmi_debug.h>
#include <OpenIPMI/internal/ipmi_mc.h>
#include <OpenIPMI/internal/ipmi_malloc.h>
#include <OpenIPMI/internal/ipmi_event.h>
#include "ui_keypad.h"
#include "ui_command.h"
WINDOW *main_win;
WINDOW *cmd_win;
WINDOW *stat_win;
WINDOW *log_pad;
WINDOW *dummy_pad;
WINDOW *display_pad;
selector_t *ui_sel;
int log_pad_top_line;
int display_pad_top_line;
keypad_t keymap;
command_t commands;
ipmi_domain_id_t domain_id;
extern os_handler_t ipmi_ui_cb_handlers;
ipmi_pef_t *pef;
ipmi_pef_config_t *pef_config;
ipmi_lanparm_t *lanparm;
ipmi_lan_config_t *lanparm_config;
static int full_screen;
struct termios old_termios;
int old_flags;
#define STATUS_WIN_LINES 2
#define STATUS_WIN_COLS COLS
#define STATUS_WIN_TOP 0
#define STATUS_WIN_LEFT 0
#define CMD_WIN_LINES 3
#define CMD_WIN_COLS COLS
#define CMD_WIN_LEFT 0
#define CMD_WIN_TOP (LINES-CMD_WIN_LINES)
#define DISPLAY_WIN_LINES (LINES - STATUS_WIN_LINES - CMD_WIN_LINES - 2)
#define DISPLAY_WIN_COLS (COLS/2-1)
#define DISPLAY_WIN_TOP (STATUS_WIN_LINES+1)
#define DISPLAY_WIN_LEFT 0
#define DISPLAY_WIN_RIGHT (COLS/2-2)
#define DISPLAY_WIN_BOTTOM (CMD_WIN_TOP-2)
#define NUM_DISPLAY_LINES 1024
#define LOG_WIN_LINES (LINES - STATUS_WIN_LINES - CMD_WIN_LINES - 2)
#define LOG_WIN_COLS (COLS-(COLS/2))
#define LOG_WIN_LEFT (COLS/2)
#define LOG_WIN_RIGHT (COLS-1)
#define LOG_WIN_TOP (STATUS_WIN_LINES+1)
#define LOG_WIN_BOTTOM (CMD_WIN_TOP-2)
#define NUM_LOG_LINES 1024
#define TOP_LINE STATUS_WIN_LINES
#define BOTTOM_LINE (LINES-CMD_WIN_LINES-1)
#define MID_COL (COLS/2-1)
#define MID_LINES (LINES - STATUS_WIN_LINES - CMD_WIN_LINES - 2)
enum scroll_wins_e { LOG_WIN_SCROLL, DISPLAY_WIN_SCROLL };
enum scroll_wins_e curr_win = LOG_WIN_SCROLL;
/* The current thing display in the display pad. */
enum {
DISPLAY_NONE, DISPLAY_SENSOR, DISPLAY_SENSORS,
DISPLAY_CONTROLS, DISPLAY_CONTROL, DISPLAY_ENTITIES, DISPLAY_MCS,
DISPLAY_MC,
DISPLAY_RSP, DISPLAY_SDRS, HELP, EVENTS, DISPLAY_ENTITY, DISPLAY_FRU
} curr_display_type;
ipmi_sensor_id_t curr_sensor_id;
ipmi_control_id_t curr_control_id;
typedef struct pos_s {int y; int x; } pos_t;
typedef struct thr_pos_s
{
int set;
pos_t value;
pos_t enabled;
pos_t oor;
} thr_pos_t;
thr_pos_t threshold_positions[6];
pos_t value_pos;
pos_t enabled_pos;
pos_t scanning_pos;
pos_t discr_assert_enab;
pos_t discr_deassert_enab;
ipmi_entity_id_t curr_entity_id;
static char *line_buffer = NULL;
static int line_buffer_max = 0;
static int line_buffer_pos = 0;
sel_timer_t *redisplay_timer;
static void
conv_from_spaces(char *name)
{
while (*name) {
if (*name == ' ')
*name = '~';
name++;
}
}
static void
conv_to_spaces(char *name)
{
while (*name) {
if (*name == '~')
*name = ' ';
name++;
}
}
void
log_pad_refresh(int newlines)
{
if (full_screen) {
if (log_pad_top_line < 0)
log_pad_top_line = 0;
if (log_pad_top_line > (NUM_LOG_LINES - LOG_WIN_LINES))
log_pad_top_line = NUM_LOG_LINES - LOG_WIN_LINES;
if (log_pad_top_line != (NUM_LOG_LINES - LOG_WIN_LINES)) {
/* We are not at the bottom, so hold the same position. */
log_pad_top_line -= newlines;
}
prefresh(log_pad,
log_pad_top_line, 0,
LOG_WIN_TOP, LOG_WIN_LEFT,
LOG_WIN_BOTTOM, LOG_WIN_RIGHT);
wrefresh(cmd_win);
}
}
void
vlog_pad_out(const char *format, va_list ap)
{
if (full_screen)
vw_printw(log_pad, format, ap);
else
vprintf(format, ap);
}
void
log_pad_out(char *format, ...)
{
va_list ap;
va_start(ap, format);
vlog_pad_out(format, ap);
va_end(ap);
}
void
display_pad_refresh(void)
{
if (full_screen) {
if (display_pad_top_line >= NUM_DISPLAY_LINES)
display_pad_top_line = NUM_DISPLAY_LINES;
if (display_pad_top_line < 0)
display_pad_top_line = 0;
prefresh(display_pad,
display_pad_top_line, 0,
DISPLAY_WIN_TOP, DISPLAY_WIN_LEFT,
DISPLAY_WIN_BOTTOM, DISPLAY_WIN_RIGHT);
wrefresh(cmd_win);
}
}
void
display_pad_clear(void)
{
display_pad_top_line = 0;
if (full_screen) {
werase(display_pad);
wmove(display_pad, 0, 0);
}
}
void
display_pad_clear_nomove(void)
{
if (full_screen) {
werase(display_pad);
wmove(display_pad, 0, 0);
}
}
void
display_pad_out(char *format, ...)
{
va_list ap;
va_start(ap, format);
if (full_screen)
vw_printw(display_pad, format, ap);
else
vprintf(format, ap);
va_end(ap);
}
void
cmd_win_out(char *format, ...)
{
va_list ap;
va_start(ap, format);
if (full_screen)
vw_printw(cmd_win, format, ap);
else
vprintf(format, ap);
va_end(ap);
}
void
cmd_win_refresh(void)
{
if (full_screen)
wrefresh(cmd_win);
else
fflush(stdout);
}
static int
get_uchar(char **toks, unsigned char *val, char *errstr)
{
char *str, *tmpstr;
str = strtok_r(NULL, " \t\n", toks);
if (!str) {
if (errstr)
cmd_win_out("No %s given\n", errstr);
return EINVAL;
}
*val = strtoul(str, &tmpstr, 16);
if (*tmpstr != '\0') {
if (errstr)
cmd_win_out("Invalid %s given\n", errstr);
return EINVAL;
}
return 0;
}
static int
get_uint(char **toks, unsigned int *val, char *errstr)
{
char *str, *tmpstr;
str = strtok_r(NULL, " \t\n", toks);
if (!str) {
if (errstr)
cmd_win_out("No %s given\n", errstr);
return EINVAL;
}
*val = strtoul(str, &tmpstr, 16);
if (*tmpstr != '\0') {
if (errstr)
cmd_win_out("Invalid %s given\n", errstr);
return EINVAL;
}
return 0;
}
static int
get_ip_addr(char **toks, struct in_addr *ip_addr, char *errstr)
{
u_int32_t addr;
unsigned char val;
char *str, *tmpstr, *istr;
char *ntok;
int i;
str = strtok_r(NULL, " \t\n", toks);
if (!str) {
if (errstr)
cmd_win_out("No %s given\n", errstr);
return EINVAL;
}
addr = 0;
for (i=0; i<4; i++) {
istr = strtok_r(str, ".", &ntok);
str = NULL;
if (!istr) {
if (errstr)
cmd_win_out("%s: invalid IP address\n", errstr);
return EINVAL;
}
val = strtoul(istr, &tmpstr, 10);
if (*tmpstr != '\0') {
if (errstr)
cmd_win_out("%s: Invalid IP address\n", errstr);
return EINVAL;
}
addr = (addr << 8) | val;
}
ip_addr->s_addr = htonl(addr);
return 0;
}
static int
get_mac_addr(char **toks, unsigned char *mac_addr, char *errstr)
{
char *str, *tmpstr, *istr;
char *ntok;
int i;
str = strtok_r(NULL, " \t\n", toks);
if (!str) {
if (errstr)
cmd_win_out("No %s given\n", errstr);
return EINVAL;
}
for (i=0; i<6; i++) {
istr = strtok_r(str, ":", &ntok);
str = NULL;
if (!istr) {
if (errstr)
cmd_win_out("%s: invalid IP address\n", errstr);
return EINVAL;
}
mac_addr[i] = strtoul(istr, &tmpstr, 16);
if (*tmpstr != '\0') {
if (errstr)
cmd_win_out("%s: Invalid IP address\n", errstr);
return EINVAL;
}
}
return 0;
}
void
draw_lines()
{
werase(main_win);
wmove(main_win, TOP_LINE, 0);
whline(main_win, 0, COLS);
wmove(main_win, BOTTOM_LINE, 0);
whline(main_win, 0, COLS);
wmove(main_win, TOP_LINE, MID_COL);
wvline(main_win, ACS_TTEE, 1);
wmove(main_win, TOP_LINE+1, MID_COL);
wvline(main_win, 0, MID_LINES);
wmove(main_win, TOP_LINE+1+MID_LINES, MID_COL);
wvline(main_win, ACS_BTEE, 1);
wrefresh(main_win);
}
void
ui_vlog(const char *format, enum ipmi_log_type_e log_type, va_list ap)
{
int do_nl = 1;
struct timeval now;
gettimeofday(&now, NULL);
if (full_screen) {
int x = 0, y = 0, old_x = 0, old_y = 0;
int max_x, max_y, i, j;
/* Generate the output to the dummy pad to see how many lines we
will use. */
getyx(dummy_pad, old_y, old_x);
switch(log_type)
{
case IPMI_LOG_INFO:
wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
wprintw(dummy_pad, "INFO: ");
break;
case IPMI_LOG_WARNING:
wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
wprintw(dummy_pad, "WARN: ");
break;
case IPMI_LOG_SEVERE:
wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
wprintw(dummy_pad, "SEVR: ");
break;
case IPMI_LOG_FATAL:
wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
wprintw(dummy_pad, "FATL: ");
break;
case IPMI_LOG_ERR_INFO:
wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
wprintw(dummy_pad, "EINF: ");
break;
case IPMI_LOG_DEBUG_START:
do_nl = 0;
/* FALLTHROUGH */
case IPMI_LOG_DEBUG:
wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
wprintw(dummy_pad, "DEBG: ");
break;
case IPMI_LOG_DEBUG_CONT:
do_nl = 0;
/* FALLTHROUGH */
case IPMI_LOG_DEBUG_END:
break;
}
vw_printw(dummy_pad, format, ap);
if (do_nl)
wprintw(dummy_pad, "\n");
getyx(dummy_pad, y, x);
if (old_y == y) {
for (j=old_x; j<x; j++)
waddch(log_pad, mvwinch(dummy_pad, y, j));
} else {
getmaxyx(dummy_pad, max_y, max_x);
for (j=old_x; j<max_x; j++)
waddch(log_pad, mvwinch(dummy_pad, old_y, j));
for (i=old_y+1; i<y; i++) {
for (j=0; j<max_x; j++)
waddch(log_pad, mvwinch(dummy_pad, i, j));
}
for (j=0; j<x; j++)
waddch(log_pad, mvwinch(dummy_pad, y, j));
}
y -= old_y;
wmove(dummy_pad, 0, x);
log_pad_refresh(y);
} else {
switch(log_type)
{
case IPMI_LOG_INFO:
log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
log_pad_out("INFO: ");
break;
case IPMI_LOG_WARNING:
log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
log_pad_out("WARN: ");
break;
case IPMI_LOG_SEVERE:
log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
log_pad_out("SEVR: ");
break;
case IPMI_LOG_FATAL:
log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
log_pad_out("FATL: ");
break;
case IPMI_LOG_ERR_INFO:
log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
log_pad_out("EINF: ");
break;
case IPMI_LOG_DEBUG_START:
do_nl = 0;
/* FALLTHROUGH */
case IPMI_LOG_DEBUG:
log_pad_out("%d.%6.6d: ", now.tv_sec, now.tv_usec);
log_pad_out("DEBG: ");
break;
case IPMI_LOG_DEBUG_CONT:
do_nl = 0;
/* FALLTHROUGH */
case IPMI_LOG_DEBUG_END:
break;
}
vlog_pad_out(format, ap);
if (do_nl)
log_pad_out("\n");
log_pad_refresh(0);
}
cmd_win_refresh();
}
void
ui_log(char *format, ...)
{
int y = 0, x;
struct timeval now;
va_list ap;
gettimeofday(&now, NULL);
va_start(ap, format);
if (full_screen) {
/* Generate the output to the dummy pad to see how many lines we
will use. */
wprintw(dummy_pad, "%d.%6.6d: ", now.tv_sec, now.tv_usec);
vw_printw(dummy_pad, format, ap);
getyx(dummy_pad, y, x);
wmove(dummy_pad, 0, x);
va_end(ap);
va_start(ap, format);
}
log_pad_out("%ld.%6.6ld: ", now.tv_sec, now.tv_usec);
vlog_pad_out(format, ap);
log_pad_refresh(y);
cmd_win_refresh();
va_end(ap);
}
void
leave(int rv, char *format, ...)
{
va_list ap;
ipmi_shutdown();
sel_stop_timer(redisplay_timer);
sel_free_timer(redisplay_timer);
if (full_screen) {
endwin();
full_screen = 0;
} else {
tcsetattr(0, TCSADRAIN, &old_termios);
fcntl(0, F_SETFL, old_flags);
tcdrain(0);
}
if (pef_config) {
ipmi_pef_free_config(pef_config);
pef_config = NULL;
}
if (pef) {
ipmi_pef_destroy(pef, NULL, NULL);
pef = NULL;
}
if (lanparm_config) {
ipmi_lan_free_config(lanparm_config);
lanparm_config = NULL;
}
if (lanparm) {
ipmi_lanparm_destroy(lanparm, NULL, NULL);
lanparm = NULL;
}
if (line_buffer) {
ipmi_mem_free(line_buffer);
}
command_free(commands);
keypad_free(keymap);
sel_free_selector(ui_sel);
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
ipmi_debug_malloc_cleanup();
exit(rv);
}
void
leave_err(int err, char *format, ...)
{
va_list ap;
if (full_screen)
endwin();
else {
tcsetattr(0, TCSADRAIN, &old_termios);
fcntl(0, F_SETFL, old_flags);
tcdrain(0);
}
sel_free_selector(ui_sel);
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
if (IPMI_IS_OS_ERR(err)) {
fprintf(stderr, ": %s\n", strerror(IPMI_GET_OS_ERR(err)));
} else {
fprintf(stderr, ": IPMI Error %2.2x\n", IPMI_GET_IPMI_ERR(err));
}
ipmi_debug_malloc_cleanup();
exit(1);
}
void
recalc_windows(void)
{
draw_lines();
mvwin(stat_win, STATUS_WIN_TOP, STATUS_WIN_LEFT);
wresize(stat_win, STATUS_WIN_LINES, STATUS_WIN_COLS);
wrefresh(stat_win);
touchwin(stat_win);
wresize(display_pad, DISPLAY_WIN_LINES, DISPLAY_WIN_COLS);
mvwin(cmd_win, CMD_WIN_TOP, CMD_WIN_LEFT);
wresize(cmd_win, CMD_WIN_LINES, CMD_WIN_COLS);
wrefresh(cmd_win);
touchwin(cmd_win);
wresize(log_pad, NUM_LOG_LINES, LOG_WIN_COLS);
wresize(dummy_pad, NUM_LOG_LINES, LOG_WIN_COLS);
doupdate();
log_pad_refresh(0);
display_pad_refresh();
}
static
void handle_user_char(int c)
{
int err = keypad_handle_key(keymap, c, NULL);
if (err)
ui_log("Got error on char 0x%x 0%o %d\n", c, c, c);
}
void
user_input_ready(int fd, void *data)
{
int c;
if (full_screen) {
c = wgetch(cmd_win);
while (c != ERR) {
handle_user_char(c);
c = wgetch(cmd_win);
}
} else {
char rc;
int count;
count = read(0, &rc, 1);
if (count > 0)
handle_user_char(rc);
}
}
static int
normal_char(int key, void *cb_data)
{
char out[2];
if (line_buffer_pos >= line_buffer_max) {
char *new_line = ipmi_mem_alloc(line_buffer_max+10+1);
if (!new_line)
return ENOMEM;
line_buffer_max += 10;
if (line_buffer) {
memcpy(new_line, line_buffer, line_buffer_pos);
ipmi_mem_free(line_buffer);
}
line_buffer = new_line;
}
line_buffer[line_buffer_pos] = key;
line_buffer_pos++;
out[0] = key;
out[1] = '\0';
cmd_win_out(out);
cmd_win_refresh();
return 0;
}
static int
end_of_line(int key, void *cb_data)
{
int err;
if (!line_buffer)
return 0;
line_buffer[line_buffer_pos] = '\0';
cmd_win_out("\n");
err = command_handle(commands, line_buffer, NULL);
if (err)
cmd_win_out("Invalid command: %s\n> ", line_buffer);
else
cmd_win_out("> ");
line_buffer_pos = 0;
cmd_win_refresh();
return 0;
}
static int
backspace(int key, void *cb_data)
{
if (line_buffer_pos == 0)
return 0;
line_buffer_pos--;
cmd_win_out("\b \b");
cmd_win_refresh();
return 0;
}
static int
key_up(int key, void *cb_data)
{
return 0;
}
static int
key_down(int key, void *cb_data)
{
return 0;
}
static int
key_right(int key, void *cb_data)
{
return 0;
}
static int
key_left(int key, void *cb_data)
{
return 0;
}
static int
key_ppage(int key, void *cb_data)
{
if (curr_win == LOG_WIN_SCROLL) {
log_pad_top_line -= (LOG_WIN_LINES-1);
log_pad_refresh(0);
} else if (curr_win == DISPLAY_WIN_SCROLL) {
display_pad_top_line -= (DISPLAY_WIN_LINES-1);
display_pad_refresh();
}
return 0;
}
static int
key_npage(int key, void *cb_data)
{
if (curr_win == LOG_WIN_SCROLL) {
log_pad_top_line += (LOG_WIN_LINES-1);
log_pad_refresh(0);
} else if (curr_win == DISPLAY_WIN_SCROLL) {
display_pad_top_line += (DISPLAY_WIN_LINES-1);
display_pad_refresh();
}
return 0;
}
static int leave_count = 0;
static void
final_leave(void *cb_data)
{
leave_count--;
if (leave_count == 0)
leave(0, "");
}
static void
leave_cmder(ipmi_domain_t *domain, void *cb_data)
{
int rv;
rv = ipmi_domain_close(domain, final_leave, NULL);
if (!rv)
leave_count++;
}
static int
key_leave(int key, void *cb_data)
{
ipmi_domain_iterate_domains(leave_cmder, NULL);
if (leave_count == 0)
leave(0, "");
return 0;
}
static int
key_resize(int key, void *cb_data)
{
recalc_windows();
return 0;
}
static int
key_set_display(int key, void *cb_data)
{
curr_win = DISPLAY_WIN_SCROLL;
return 0;
}
static int
key_set_log(int key, void *cb_data)
{
curr_win = LOG_WIN_SCROLL;
return 0;
}
/* Includes 3 3-byte fields (entity id, entity instance, and slave
address) and 1 2-byte field (channel) and three periods and the nil
char at the end and possible a leading "r" for device-relative. */
#define MAX_ENTITY_LOC_SIZE 16
/* Convert an entity to a locator for the entity. This is either:
<num>.<num> for an absolute entity, or
r<num>.<num>.<num>.<num> for a device-relative entity. */
static char *
get_entity_loc(ipmi_entity_t *entity, char *str, int strlen)
{
ipmi_entity_id_t id;
id = ipmi_entity_convert_to_id(entity);
if (id.entity_instance >= 0x60)
snprintf(str, strlen, "r%d.%d.%d.%d",
id.channel,
id.address,
id.entity_id,
id.entity_instance - 0x60);
else
snprintf(str, strlen, "%d.%d",
id.entity_id,
id.entity_instance);
return str;
}
static void
entities_handler(ipmi_entity_t *entity,
void *cb_data)
{
char *present;
char loc[MAX_ENTITY_LOC_SIZE];
char name[33];
enum ipmi_dlr_type_e type;
static char *ent_types[] = { "unknown", "mc", "fru",
"generic", "invalid" };
type = ipmi_entity_get_type(entity);
if (type > IPMI_ENTITY_GENERIC)
type = IPMI_ENTITY_GENERIC + 1;
curr_entity_id = ipmi_entity_convert_to_id(entity);
ipmi_entity_get_id(entity, name, 32);
if (strlen(name) == 0)
strncpy(name, ipmi_entity_get_entity_id_string(entity), 33);
if (ipmi_entity_is_present(entity))
present = "present";
else
present = "not present";
display_pad_out(" %s (%s) %s %s\n",
get_entity_loc(entity, loc, sizeof(loc)),
name,
ent_types[type], present);
}
static void
entities_cmder(ipmi_domain_t *domain, void *cb_data)
{
if (cb_data)
display_pad_clear_nomove();
else
display_pad_clear();
display_pad_out("Entities:\n");
ipmi_domain_iterate_entities(domain, entities_handler, NULL);
display_pad_refresh();
}
static int
entities_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
rv = ipmi_domain_pointer_cb(domain_id, entities_cmder, NULL);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
curr_display_type = DISPLAY_ENTITIES;
return 0;
}
typedef void (*entity_handler_cb)(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data);
struct ent_rec {
int id, instance, found;
int channel, address;
entity_handler_cb handler;
char **toks, **toks2;
void *cb_data;
};
static void
entity_searcher(ipmi_entity_t *entity,
void *cb_data)
{
struct ent_rec *info = cb_data;
ipmi_entity_id_t id;
id = ipmi_entity_convert_to_id(entity);
if ((info->id == id.entity_id)
&& (info->instance == id.entity_instance)
&& (info->address == id.address)
&& (info->channel == id.channel))
{
info->found = 1;
info->handler(entity, info->toks, info->toks2, info->cb_data);
}
}
static void
entity_finder_d(ipmi_domain_t *domain, void *cb_data)
{
ipmi_domain_iterate_entities(domain, entity_searcher, cb_data);
}
int
entity_finder(char *cmd, char **toks,
entity_handler_cb handler,
void *cb_data)
{
struct ent_rec info;
char *ent_name;
char *id_name, *instance_name, *toks2, *estr;
int rv;
ent_name = strtok_r(NULL, " \t\n", toks);
if (!ent_name) {
cmd_win_out("No entity given\n");
return EINVAL;
}
if (ent_name[0] == 'r') {
/* Device-relative address. */
char *name;
name = strtok_r(ent_name+1, ".", &toks2);
info.channel = strtoul(name, &estr, 0);
if (*estr != '\0') {
cmd_win_out("Invalid entity channel given\n");
return EINVAL;
}
name = strtok_r(NULL, ".", &toks2);
info.address = strtoul(name, &estr, 0);
if (*estr != '\0') {
cmd_win_out("Invalid entity address given\n");
return EINVAL;
}
id_name = strtok_r(NULL, ".", &toks2);
} else {
info.address = 0;
info.channel = 0;
id_name = strtok_r(ent_name, ".", &toks2);
}
instance_name = strtok_r(NULL, ".", &toks2);
if (!instance_name) {
cmd_win_out("Invalid entity given\n");
return EINVAL;
}
info.id = strtoul(id_name, &estr, 0);
if (*estr != '\0') {
cmd_win_out("Invalid entity id given\n");
return EINVAL;
}
info.instance = strtoul(instance_name, &estr, 0);
if (*estr != '\0') {
cmd_win_out("Invalid entity instance given\n");
return EINVAL;
}
if (ent_name[0] == 'r')
info.instance += 0x60;
info.found = 0;
info.handler = handler;
info.cb_data = cb_data;
info.toks = toks;
info.toks2 = &toks2;
rv = ipmi_domain_pointer_cb(domain_id, entity_finder_d, &info);
if (!info.found) {
if (ent_name[0] == 'r')
cmd_win_out("Entity r%d.%d.%d.%d not found\n",
info.channel, info.address, info.id,
info.instance-0x60);
else
cmd_win_out("Entity %d.%d not found\n", info.id, info.instance);
return EINVAL;
}
return 0;
}
static void
entity_iterate_handler(ipmi_entity_t *o,
ipmi_entity_t *entity,
void *cb_data)
{
char name[33];
char loc[MAX_ENTITY_LOC_SIZE];
ipmi_entity_get_id(entity, name, 32);
display_pad_out(" %s (%s)\n",
get_entity_loc(entity, loc, sizeof(loc)),
name);
}
static void
entity_handler(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
char *present;
char name[33];
char ename[IPMI_ENTITY_NAME_LEN];
char loc[MAX_ENTITY_LOC_SIZE];
enum ipmi_dlr_type_e type;
static char *ent_types[] = { "unknown", "mc", "fru",
"generic", "invalid" };
display_pad_clear();
type = ipmi_entity_get_type(entity);
if (type > IPMI_ENTITY_GENERIC)
type = IPMI_ENTITY_GENERIC + 1;
curr_entity_id = ipmi_entity_convert_to_id(entity);
ipmi_entity_get_id(entity, name, 32);
if (ipmi_entity_is_present(entity))
present = "present";
else
present = "not present";
display_pad_out("Entity %s (%s) %s\n",
get_entity_loc(entity, loc, sizeof(loc)),
name, present);
ipmi_entity_get_name(entity, ename, sizeof(ename));
display_pad_out(" name = %s\n", ename);
display_pad_out(" type = %s\n", ent_types[type]);
display_pad_out(" entity id string = %s\n",
ipmi_entity_get_entity_id_string(entity));
display_pad_out(" is%s fru\n",
ipmi_entity_get_is_fru(entity) ? "" : " not");
display_pad_out(" present sensor%s always there\n",
ipmi_entity_get_presence_sensor_always_there(entity)
? "" : " not");
if (ipmi_entity_get_is_child(entity)) {
display_pad_out(" Parents:\n");
ipmi_entity_iterate_parents(entity, entity_iterate_handler, NULL);
}
if (ipmi_entity_get_is_parent(entity)) {
display_pad_out(" Children:\n");
ipmi_entity_iterate_children(entity, entity_iterate_handler, NULL);
}
switch (type) {
case IPMI_ENTITY_MC:
display_pad_out(" channel = 0x%x\n", ipmi_entity_get_channel(entity));
display_pad_out(" lun = 0x%x\n", ipmi_entity_get_lun(entity));
display_pad_out(" oem = 0x%x\n", ipmi_entity_get_oem(entity));
display_pad_out(" slave_address = 0x%x\n",
ipmi_entity_get_slave_address(entity));
display_pad_out(" ACPI_system_power_notify_required = 0x%x\n",
ipmi_entity_get_ACPI_system_power_notify_required(entity));
display_pad_out(" ACPI_device_power_notify_required = 0x%x\n",
ipmi_entity_get_ACPI_device_power_notify_required(entity));
display_pad_out(" controller_logs_init_agent_errors = 0x%x\n",
ipmi_entity_get_controller_logs_init_agent_errors(entity));
display_pad_out(" log_init_agent_errors_accessing = 0x%x\n",
ipmi_entity_get_log_init_agent_errors_accessing(entity));
display_pad_out(" global_init = 0x%x\n",
ipmi_entity_get_global_init(entity));
display_pad_out(" chassis_device = 0x%x\n",
ipmi_entity_get_chassis_device(entity));
display_pad_out(" bridge = 0x%x\n",
ipmi_entity_get_bridge(entity));
display_pad_out(" IPMB_event_generator = 0x%x\n",
ipmi_entity_get_IPMB_event_generator(entity));
display_pad_out(" IPMB_event_receiver = 0x%x\n",
ipmi_entity_get_IPMB_event_receiver(entity));
display_pad_out(" FRU_inventory_device = 0x%x\n",
ipmi_entity_get_FRU_inventory_device(entity));
display_pad_out(" SEL_device = 0x%x\n",
ipmi_entity_get_SEL_device(entity));
display_pad_out(" SDR_repository_device = 0x%x\n",
ipmi_entity_get_SDR_repository_device(entity));
display_pad_out(" sensor_device = 0x%x\n",
ipmi_entity_get_sensor_device(entity));
break;
case IPMI_ENTITY_FRU:
display_pad_out(" channel = 0x%x\n", ipmi_entity_get_channel(entity));
display_pad_out(" lun = 0x%x\n", ipmi_entity_get_lun(entity));
display_pad_out(" oem = 0x%x\n", ipmi_entity_get_oem(entity));
display_pad_out(" access_address = 0x%x\n",
ipmi_entity_get_access_address(entity));
display_pad_out(" private_bus_id = 0x%x\n",
ipmi_entity_get_private_bus_id(entity));
display_pad_out(" device_type = 0x%x\n",
ipmi_entity_get_device_type(entity));
display_pad_out(" device_modifier = 0x%x\n",
ipmi_entity_get_device_modifier(entity));
display_pad_out(" is_logical_fru = 0x%x\n",
ipmi_entity_get_is_logical_fru(entity));
display_pad_out(" fru_device_id = 0x%x\n",
ipmi_entity_get_fru_device_id(entity));
break;
case IPMI_ENTITY_GENERIC:
display_pad_out(" channel = 0x%x\n", ipmi_entity_get_channel(entity));
display_pad_out(" lun = 0x%x\n", ipmi_entity_get_lun(entity));
display_pad_out(" oem = 0x%x\n", ipmi_entity_get_oem(entity));
display_pad_out(" access_address = 0x%x\n",
ipmi_entity_get_access_address(entity));
display_pad_out(" private_bus_id = 0x%x\n",
ipmi_entity_get_private_bus_id(entity));
display_pad_out(" device_type = 0x%x\n",
ipmi_entity_get_device_type(entity));
display_pad_out(" device_modifier = 0x%x\n",
ipmi_entity_get_device_modifier(entity));
display_pad_out(" slave_address = 0x%x\n",
ipmi_entity_get_slave_address(entity));
display_pad_out(" address_span = 0x%x\n",
ipmi_entity_get_address_span(entity));
break;
default:
break;
}
display_pad_refresh();
}
int
entity_cmd(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, entity_handler, NULL);
curr_display_type = DISPLAY_ENTITY;
return 0;
}
static void
hs_get_act_time_cb(ipmi_entity_t *ent,
int err,
ipmi_timeout_t val,
void *cb_data)
{
char loc[MAX_ENTITY_LOC_SIZE];
if (err) {
ui_log("Could not get hot-swap act time: error 0x%x\n", err);
return;
}
ui_log("Hot-swap activate time for %s is %lld\n",
get_entity_loc(ent, loc, sizeof(loc)), val);
}
static void
hs_get_act_time_handler(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
int rv;
rv = ipmi_entity_get_auto_activate_time(entity, hs_get_act_time_cb, NULL);
if (rv)
cmd_win_out("Could not get auto-activate: error 0x%x\n", rv);
}
int
hs_get_act_time(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, hs_get_act_time_handler, NULL);
return 0;
}
static void
hs_set_act_time_cb(ipmi_entity_t *ent,
int err,
void *cb_data)
{
if (err)
ui_log("Could not get hot-swap act time: error 0x%x\n", err);
else
ui_log("hot-swap act time set\n");
}
static void
hs_set_act_time_handler(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
int rv;
unsigned int timeout;
if (get_uint(toks, &timeout, "Hot swap activate time"))
return;
rv = ipmi_entity_set_auto_activate_time(entity, timeout,
hs_set_act_time_cb, NULL);
if (rv)
cmd_win_out("Could not set auto-activate: error 0x%x\n", rv);
}
int
hs_set_act_time(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, hs_set_act_time_handler, NULL);
return 0;
}
static void
hs_get_deact_time_cb(ipmi_entity_t *ent,
int err,
ipmi_timeout_t val,
void *cb_data)
{
char loc[MAX_ENTITY_LOC_SIZE];
if (err) {
ui_log("Could not get hot-swap deact time: error 0x%x\n", err);
return;
}
ui_log("Hot-swap deactivate time for %s is %lld\n",
get_entity_loc(ent, loc, sizeof(loc)), val);
}
static void
hs_get_deact_time_handler(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
int rv;
rv = ipmi_entity_get_auto_deactivate_time(entity, hs_get_deact_time_cb, NULL);
if (rv)
cmd_win_out("Could not get auto-deactivate: error 0x%x\n", rv);
}
int
hs_get_deact_time(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, hs_get_deact_time_handler, NULL);
return 0;
}
static void
hs_set_deact_time_cb(ipmi_entity_t *ent,
int err,
void *cb_data)
{
if (err)
ui_log("Could not get hot-swap deact time: error 0x%x\n", err);
else
ui_log("hot-swap deact time set\n");
}
static void
hs_set_deact_time_handler(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
int rv;
unsigned int timeout;
if (get_uint(toks, &timeout, "Hot swap deactivate time"))
return;
rv = ipmi_entity_set_auto_deactivate_time(entity, timeout,
hs_set_deact_time_cb, NULL);
if (rv)
cmd_win_out("Could not set auto-deactivate: error 0x%x\n", rv);
}
int
hs_set_deact_time(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, hs_set_deact_time_handler, NULL);
return 0;
}
static void
hs_activation_request_cb(ipmi_entity_t *ent,
int err,
void *cb_data)
{
if (err)
ui_log("Could not activate entity: error 0x%x\n", err);
else
ui_log("entity activated\n");
}
static void
hs_activation_request_handler(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
int rv;
rv = ipmi_entity_set_activation_requested(entity,
hs_activation_request_cb,
NULL);
if (rv)
cmd_win_out("Could not set activation requested: error 0x%x\n", rv);
}
static int
hs_activation_request(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, hs_activation_request_handler, NULL);
return 0;
}
static void
hs_activate_cb(ipmi_entity_t *ent,
int err,
void *cb_data)
{
if (err)
ui_log("Could not activate entity: error 0x%x\n", err);
else
ui_log("entity activated\n");
}
static void
hs_activate_handler(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
int rv;
rv = ipmi_entity_activate(entity, hs_activate_cb, NULL);
if (rv)
cmd_win_out("Could not activate entity: error 0x%x\n", rv);
}
int
hs_activate(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, hs_activate_handler, NULL);
return 0;
}
static void
hs_deactivate_cb(ipmi_entity_t *ent,
int err,
void *cb_data)
{
if (err)
ui_log("Could not deactivate entity: error 0x%x\n", err);
else
ui_log("entity deactivated\n");
}
static void
hs_deactivate_handler(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
int rv;
rv = ipmi_entity_deactivate(entity, hs_deactivate_cb, NULL);
if (rv)
cmd_win_out("Could not deactivate entity: error 0x%x\n", rv);
}
int
hs_deactivate(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, hs_deactivate_handler, NULL);
return 0;
}
static void
hs_state_cb(ipmi_entity_t *ent,
int err,
enum ipmi_hot_swap_states state,
void *cb_data)
{
if (err)
ui_log("Could not get hot-swap state: error 0x%x\n", err);
else
ui_log("Hot-swap state is %s\n", ipmi_hot_swap_state_name(state));
}
static void
hs_state_handler(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
int rv;
rv = ipmi_entity_get_hot_swap_state(entity, hs_state_cb, NULL);
if (rv)
cmd_win_out("Could not get entity state: error 0x%x\n", rv);
}
int
hs_state(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, hs_state_handler, NULL);
return 0;
}
static void
hs_check_ent(ipmi_entity_t *entity, void *cb_data)
{
ipmi_entity_check_hot_swap_state(entity);
}
static void
hs_check_cmder(ipmi_domain_t *domain, void *cb_data)
{
ipmi_domain_iterate_entities(domain, hs_check_ent, NULL);
}
int
hs_check_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
rv = ipmi_domain_pointer_cb(domain_id, hs_check_cmder, NULL);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
return 0;
}
static void
sensors_handler(ipmi_entity_t *entity, ipmi_sensor_t *sensor, void *cb_data)
{
char name[33];
char name2[33];
char loc[MAX_ENTITY_LOC_SIZE];
ipmi_sensor_get_id(sensor, name, 33);
strcpy(name2, name);
conv_from_spaces(name2);
display_pad_out(" %s.%s - %s\n",
get_entity_loc(entity, loc, sizeof(loc)),
name2, name);
}
static void
found_entity_for_sensors(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
char loc[MAX_ENTITY_LOC_SIZE];
curr_display_type = DISPLAY_SENSORS;
display_pad_clear();
display_pad_out("Sensors for entity %s:\n",
get_entity_loc(entity, loc, sizeof(loc)));
ipmi_entity_iterate_sensors(entity, sensors_handler, NULL);
display_pad_refresh();
}
int
sensors_cmd(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, found_entity_for_sensors, NULL);
return 0;
}
struct sensor_info {
int found;
char *name;
};
/* Has this sensor been displayed yet? */
int sensor_displayed;
/* Decrement whenever the sensor is not displayed and data is
recevied, when this hits zero it's time to display. */
int sensor_ops_to_read_count;
/* Return value from ipmi_states_get or ipmi_reading_get. */
int sensor_read_err;
/* Values from ipmi_reading_get. */
enum ipmi_value_present_e sensor_value_present;
unsigned int sensor_raw_val;
double sensor_val;
/* Values from ipmi_states_get and ipmi_reading_get. */
ipmi_states_t *sensor_states;
/* Values from ipmi_sensor_event_enables_get. */
int sensor_event_states_err;
ipmi_event_state_t *sensor_event_states;
/* Values from ipmi_thresholds_get */
int sensor_read_thresh_err;
ipmi_thresholds_t *sensor_thresholds;
static void
display_sensor(ipmi_entity_t *entity, ipmi_sensor_t *sensor)
{
char loc[MAX_ENTITY_LOC_SIZE];
char name[33];
char sname[IPMI_SENSOR_NAME_LEN];
int rv;
if (sensor_displayed)
return;
sensor_ops_to_read_count--;
if (sensor_ops_to_read_count > 0)
return;
sensor_displayed = 1;
ipmi_sensor_get_name(sensor, sname, sizeof(sname));
ipmi_sensor_get_id(sensor, name, 33);
display_pad_clear();
conv_from_spaces(name);
display_pad_out("Sensor %s.%s:\n",
get_entity_loc(entity, loc, sizeof(loc)),
name);
if (ipmi_sensor_get_ignore_if_no_entity(sensor))
display_pad_out(" ignore if entity not present\n");
else
display_pad_out(" still there if entity not present\n");
display_pad_out(" name = %s\n", sname);
display_pad_out(" value = ");
getyx(display_pad, value_pos.y, value_pos.x);
if (!ipmi_entity_is_present(entity)
&& ipmi_sensor_get_ignore_if_no_entity(sensor))
{
display_pad_out("not present");
} else {
if (sensor_read_err) {
display_pad_out("unreadable");
} else if (ipmi_sensor_get_event_reading_type(sensor)
== IPMI_EVENT_READING_TYPE_THRESHOLD)
{
if (sensor_value_present == IPMI_BOTH_VALUES_PRESENT)
display_pad_out("%f (%2.2x)", sensor_val, sensor_raw_val);
else if (sensor_value_present == IPMI_RAW_VALUE_PRESENT)
display_pad_out("0x%x (RAW)", sensor_raw_val);
else
display_pad_out("unreadable");
} else {
int i;
for (i=0; i<15; i++) {
int val;
val = ipmi_is_state_set(sensor_states, i);
display_pad_out("%d", val != 0);
}
}
}
display_pad_out("\n Events = ");
getyx(display_pad, enabled_pos.y, enabled_pos.x);
if (sensor_event_states_err)
display_pad_out("? ");
else {
int global_enable;
global_enable = ipmi_event_state_get_events_enabled
(sensor_event_states);
if (global_enable)
display_pad_out("enabled");
else
display_pad_out("disabled");
}
display_pad_out("\n Scanning = ");
getyx(display_pad, scanning_pos.y, scanning_pos.x);
if (sensor_event_states_err)
display_pad_out("? ");
else {
int scanning_enable;
scanning_enable = ipmi_event_state_get_scanning_enabled
(sensor_event_states);
if (scanning_enable)
display_pad_out("enabled");
else
display_pad_out("disabled");
}
display_pad_out("\n Hysteresis = ");
switch (ipmi_sensor_get_hysteresis_support(sensor)) {
case IPMI_HYSTERESIS_SUPPORT_NONE: display_pad_out("none"); break;
case IPMI_HYSTERESIS_SUPPORT_READABLE: display_pad_out("readable"); break;
case IPMI_HYSTERESIS_SUPPORT_SETTABLE: display_pad_out("settable"); break;
case IPMI_HYSTERESIS_SUPPORT_FIXED: display_pad_out("fixed"); break;
default: display_pad_out("invalid"); break;
}
display_pad_out("\n");
display_pad_out(" sensor type = %s (0x%2.2x)\n",
ipmi_sensor_get_sensor_type_string(sensor),
ipmi_sensor_get_sensor_type(sensor));
display_pad_out(" event/reading type = %s (0x%2.2x)\n",
ipmi_sensor_get_event_reading_type_string(sensor),
ipmi_sensor_get_event_reading_type(sensor));
if (ipmi_sensor_get_event_reading_type(sensor)
== IPMI_EVENT_READING_TYPE_THRESHOLD)
{
enum ipmi_thresh_e t;
double val;
display_pad_out(" units = %s%s",
ipmi_sensor_get_base_unit_string(sensor),
ipmi_sensor_get_rate_unit_string(sensor));
switch(ipmi_sensor_get_modifier_unit_use(sensor)) {
case IPMI_MODIFIER_UNIT_BASE_DIV_MOD:
display_pad_out("/%s",
ipmi_sensor_get_modifier_unit_string(sensor));
break;
case IPMI_MODIFIER_UNIT_BASE_MULT_MOD:
display_pad_out("*%s",
ipmi_sensor_get_modifier_unit_string(sensor));
break;
case IPMI_MODIFIER_UNIT_NONE:
break;
}
display_pad_out("\n");
rv = ipmi_sensor_get_nominal_reading(sensor, &val);
if (!rv) display_pad_out(" nominal = %f\n", val);
rv = ipmi_sensor_get_normal_min(sensor, &val);
if (!rv) display_pad_out(" normal_min = %f\n", val);
rv = ipmi_sensor_get_normal_max(sensor, &val);
if (!rv) display_pad_out(" normal_max = %f\n", val);
rv = ipmi_sensor_get_sensor_min(sensor, &val);
if (!rv) display_pad_out(" sensor_min = %f\n", val);
rv = ipmi_sensor_get_sensor_max(sensor, &val);
if (!rv) display_pad_out(" sensor_max = %f\n", val);
display_pad_out("Thresholds:\n");
for (t=IPMI_LOWER_NON_CRITICAL; t<=IPMI_UPPER_NON_RECOVERABLE; t++){
int settable, readable;
int i;
int assert_sup[2], deassert_sup[2];
int anything_set = 0;
ipmi_sensor_threshold_settable(sensor, t, &settable);
anything_set |= settable;
ipmi_sensor_threshold_readable(sensor, t, &readable);
anything_set |= readable;
for (i=0; i<=1; i++) {
ipmi_sensor_threshold_event_supported(
sensor, t, i, IPMI_ASSERTION, &(assert_sup[i]));
anything_set |= assert_sup[i];
ipmi_sensor_threshold_event_supported(
sensor, t, i, IPMI_DEASSERTION, &(deassert_sup[i]));
anything_set |= deassert_sup[i];
}
if (anything_set) {
display_pad_out(" %s:", ipmi_get_threshold_string(t));
threshold_positions[t].set = 1;
display_pad_out("\n available: ");
if (readable) display_pad_out("R");
else display_pad_out(" ");
if (settable) display_pad_out("W");
else display_pad_out(" ");
if (assert_sup[0]) display_pad_out("L^");
else display_pad_out(" ");
if (deassert_sup[0]) display_pad_out("Lv");
else display_pad_out(" ");
if (assert_sup[1]) display_pad_out("H^");
else display_pad_out(" ");
if (deassert_sup[1]) display_pad_out("Hv");
else display_pad_out(" ");
display_pad_out("\n enabled: ");
getyx(display_pad,
threshold_positions[t].enabled.y,
threshold_positions[t].enabled.x);
if (sensor_event_states_err)
display_pad_out("? ");
else {
if (ipmi_is_threshold_event_set(sensor_event_states, t,
IPMI_GOING_LOW,
IPMI_ASSERTION))
display_pad_out("L^");
else
display_pad_out(" ");
if (ipmi_is_threshold_event_set(sensor_event_states, t,
IPMI_GOING_LOW,
IPMI_DEASSERTION))
display_pad_out("Lv");
else
display_pad_out(" ");
if (ipmi_is_threshold_event_set(sensor_event_states, t,
IPMI_GOING_HIGH,
IPMI_ASSERTION))
display_pad_out("H^");
else
display_pad_out(" ");
if (ipmi_is_threshold_event_set(sensor_event_states, t,
IPMI_GOING_HIGH,
IPMI_DEASSERTION))
display_pad_out("HV");
else
display_pad_out(" ");
}
display_pad_out("\n value: ");
getyx(display_pad,
threshold_positions[t].value.y,
threshold_positions[t].value.x);
if (sensor_read_thresh_err)
display_pad_out("?");
else {
double val;
rv = ipmi_threshold_get(sensor_thresholds, t, &val);
if (rv)
display_pad_out("?", val);
else
display_pad_out("%f", val);
}
display_pad_out("\n out of range: ");
getyx(display_pad,
threshold_positions[t].oor.y,
threshold_positions[t].oor.x);
if (!sensor_read_err) {
if (ipmi_is_threshold_out_of_range(sensor_states, t))
display_pad_out("true ");
else
display_pad_out("false");
}
display_pad_out("\n");
} else {
threshold_positions[t].set = 0;
}
}
} else {
int val;
int i;
/* A discrete sensor. */
display_pad_out("\n Assertion: ");
display_pad_out("\n available: ");
for (i=0; i<15; i++) {
ipmi_sensor_discrete_event_supported(sensor,
i,
IPMI_ASSERTION,
&val);
display_pad_out("%d", val != 0);
}
display_pad_out("\n enabled: ");
getyx(display_pad, discr_assert_enab.y, discr_assert_enab.x);
if (sensor_event_states_err)
display_pad_out("?");
else {
for (i=0; i<15; i++) {
val = ipmi_is_discrete_event_set(sensor_event_states,
i, IPMI_ASSERTION);
display_pad_out("%d", val != 0);
}
}
display_pad_out("\n Deasertion: ");
display_pad_out("\n available: ");
for (i=0; i<15; i++) {
ipmi_sensor_discrete_event_supported(sensor,
i,
IPMI_DEASSERTION,
&val);
display_pad_out("%d", val != 0);
}
display_pad_out("\n enabled: ");
getyx(display_pad, discr_deassert_enab.y, discr_deassert_enab.x);
if (sensor_event_states_err)
display_pad_out("?");
else {
for (i=0; i<15; i++) {
val = ipmi_is_discrete_event_set(sensor_event_states,
i, IPMI_DEASSERTION);
display_pad_out("%d", val != 0);
}
}
display_pad_out("\n");
}
display_pad_refresh();
}
static void
read_sensor(ipmi_sensor_t *sensor,
int err,
enum ipmi_value_present_e value_present,
unsigned int raw_val,
double val,
ipmi_states_t *states,
void *cb_data)
{
ipmi_sensor_id_t sensor_id;
enum ipmi_thresh_e t;
if (err) {
if (sensor_displayed) {
wmove(display_pad, value_pos.y, value_pos.x);
display_pad_out("unreadable: %x", err);
display_pad_refresh();
} else {
curr_display_type = DISPLAY_NONE;
}
return;
}
sensor_id = ipmi_sensor_convert_to_id(sensor);
if (!((curr_display_type == DISPLAY_SENSOR)
&& (ipmi_cmp_sensor_id(sensor_id, curr_sensor_id) == 0)))
return;
if (sensor_displayed) {
wmove(display_pad, value_pos.y, value_pos.x);
if (value_present == IPMI_BOTH_VALUES_PRESENT)
display_pad_out("%f (%2.2x)", val, raw_val);
else if (value_present == IPMI_RAW_VALUE_PRESENT)
display_pad_out("0x%x (RAW)", raw_val);
else
display_pad_out("unreadable");
for (t=IPMI_LOWER_NON_CRITICAL; t<=IPMI_UPPER_NON_RECOVERABLE; t++) {
if (threshold_positions[t].set) {
wmove(display_pad,
threshold_positions[t].oor.y,
threshold_positions[t].oor.x);
if (ipmi_is_threshold_out_of_range(states, t))
display_pad_out("true ");
else
display_pad_out("false");
}
}
display_pad_refresh();
} else {
sensor_read_err = err;
sensor_value_present = value_present;
sensor_raw_val = raw_val;
sensor_val = val;
if (states)
ipmi_copy_states(sensor_states, states);
display_sensor(ipmi_sensor_get_entity(sensor), sensor);
}
}
static void
read_thresholds(ipmi_sensor_t *sensor,
int err,
ipmi_thresholds_t *th,
void *cb_data)
{
ipmi_sensor_id_t sensor_id;
enum ipmi_thresh_e t;
double val;
int rv;
sensor_id = ipmi_sensor_convert_to_id(sensor);
if (!((curr_display_type == DISPLAY_SENSOR)
&& (ipmi_cmp_sensor_id(sensor_id, curr_sensor_id) == 0)))
return;
if (sensor_displayed) {
if (err) {
for (t=IPMI_LOWER_NON_CRITICAL; t<=IPMI_UPPER_NON_RECOVERABLE; t++)
{
if (threshold_positions[t].set) {
wmove(display_pad,
threshold_positions[t].value.y,
threshold_positions[t].value.x);
display_pad_out("?");
}
}
} else {
for (t=IPMI_LOWER_NON_CRITICAL; t<=IPMI_UPPER_NON_RECOVERABLE; t++) {
if (threshold_positions[t].set) {
rv = ipmi_threshold_get(th, t, &val);
wmove(display_pad,
threshold_positions[t].value.y,
threshold_positions[t].value.x);
if (rv)
display_pad_out("?", val);
else
display_pad_out("%f", val);
}
}
}
display_pad_refresh();
} else {
sensor_read_thresh_err = err;
if (th)
ipmi_copy_thresholds(sensor_thresholds, th);
display_sensor(ipmi_sensor_get_entity(sensor), sensor);
}
}
static void
read_thresh_event_enables(ipmi_sensor_t *sensor,
int err,
ipmi_event_state_t *states,
void *cb_data)
{
ipmi_sensor_id_t sensor_id;
enum ipmi_thresh_e t;
int global_enable;
int scanning_enable;
sensor_id = ipmi_sensor_convert_to_id(sensor);
if (!((curr_display_type == DISPLAY_SENSOR)
&& (ipmi_cmp_sensor_id(sensor_id, curr_sensor_id) == 0)))
return;
if (sensor_displayed) {
if (err)
return;
global_enable = ipmi_event_state_get_events_enabled(states);
scanning_enable = ipmi_event_state_get_scanning_enabled(states);
wmove(display_pad, enabled_pos.y, enabled_pos.x);
if (err)
display_pad_out("? ");
else if (global_enable)
display_pad_out("enabled");
else
display_pad_out("disabled");
wmove(display_pad, scanning_pos.y, scanning_pos.x);
if (err)
display_pad_out("? ");
else if (scanning_enable)
display_pad_out("enabled");
else
display_pad_out("disabled");
if (ipmi_sensor_get_event_support(sensor)
!= IPMI_EVENT_SUPPORT_PER_STATE)
goto out;
for (t=IPMI_LOWER_NON_CRITICAL; t<=IPMI_UPPER_NON_RECOVERABLE; t++) {
if (threshold_positions[t].set) {
wmove(display_pad,
threshold_positions[t].enabled.y,
threshold_positions[t].enabled.x);
if (err) {
display_pad_out("? ");
continue;
}
display_pad_out(" ");
if (ipmi_is_threshold_event_set(states, t,
IPMI_GOING_LOW,
IPMI_ASSERTION))
display_pad_out("L^");
else
display_pad_out(" ");
if (ipmi_is_threshold_event_set(states, t,
IPMI_GOING_LOW,
IPMI_DEASSERTION))
display_pad_out("Lv");
else
display_pad_out(" ");
if (ipmi_is_threshold_event_set(states, t,
IPMI_GOING_HIGH,
IPMI_ASSERTION))
display_pad_out("H^");
else
display_pad_out(" ");
if (ipmi_is_threshold_event_set(states, t,
IPMI_GOING_HIGH,
IPMI_DEASSERTION))
display_pad_out("HV");
else
display_pad_out(" ");
}
}
out:
display_pad_refresh();
} else {
sensor_event_states_err = err;
if (states)
ipmi_copy_event_state(sensor_event_states, states);
display_sensor(ipmi_sensor_get_entity(sensor), sensor);
}
}
static void
read_discrete_event_enables(ipmi_sensor_t *sensor,
int err,
ipmi_event_state_t *states,
void *cb_data)
{
ipmi_sensor_id_t sensor_id;
int i;
int val;
int global_enable;
int scanning_enable;
sensor_id = ipmi_sensor_convert_to_id(sensor);
if (!((curr_display_type == DISPLAY_SENSOR)
&& (ipmi_cmp_sensor_id(sensor_id, curr_sensor_id) == 0)))
return;
if (sensor_displayed) {
global_enable = ipmi_event_state_get_events_enabled(states);
scanning_enable = ipmi_event_state_get_scanning_enabled(states);
wmove(display_pad, enabled_pos.y, enabled_pos.x);
if (err)
display_pad_out("? ");
else if (global_enable)
display_pad_out("enabled");
else
display_pad_out("disabled");
wmove(display_pad, scanning_pos.y, scanning_pos.x);
if (err)
display_pad_out("? ");
else if (scanning_enable)
display_pad_out("enabled");
else
display_pad_out("disabled");
if (ipmi_sensor_get_event_support(sensor)
!= IPMI_EVENT_SUPPORT_PER_STATE)
goto out;
if (err) {
wmove(display_pad, discr_assert_enab.y, discr_assert_enab.x);
display_pad_out("?");
wmove(display_pad, discr_deassert_enab.y, discr_deassert_enab.x);
display_pad_out("?");
} else {
wmove(display_pad, discr_assert_enab.y, discr_assert_enab.x);
for (i=0; i<15; i++) {
val = ipmi_is_discrete_event_set(states, i, IPMI_ASSERTION);
display_pad_out("%d", val != 0);
}
wmove(display_pad, discr_deassert_enab.y, discr_deassert_enab.x);
for (i=0; i<15; i++) {
val = ipmi_is_discrete_event_set(states, i, IPMI_DEASSERTION);
display_pad_out("%d", val != 0);
}
}
out:
display_pad_refresh();
} else {
sensor_event_states_err = err;
if (states)
ipmi_copy_event_state(sensor_event_states, states);
display_sensor(ipmi_sensor_get_entity(sensor), sensor);
}
}
static void
read_states(ipmi_sensor_t *sensor,
int err,
ipmi_states_t *states,
void *cb_data)
{
ipmi_sensor_id_t sensor_id;
int i;
int val;
sensor_id = ipmi_sensor_convert_to_id(sensor);
if (!((curr_display_type == DISPLAY_SENSOR)
&& (ipmi_cmp_sensor_id(sensor_id, curr_sensor_id) == 0)))
return;
if (sensor_displayed) {
wmove(display_pad, value_pos.y, value_pos.x);
if (err) {
display_pad_out("?");
} else {
for (i=0; i<15; i++) {
val = ipmi_is_state_set(states, i);
display_pad_out("%d", val != 0);
}
}
display_pad_refresh();
} else {
sensor_read_err = err;
if (states)
ipmi_copy_states(sensor_states, states);
display_sensor(ipmi_sensor_get_entity(sensor), sensor);
}
}
static void
redisplay_sensor(ipmi_sensor_t *sensor, void *cb_data)
{
int rv;
ipmi_entity_t *entity;
entity = ipmi_sensor_get_entity(sensor);
if (!entity)
return;
if (!ipmi_entity_is_present(entity)
&& ipmi_sensor_get_ignore_if_no_entity(sensor))
{
wmove(display_pad, value_pos.y, value_pos.x);
display_pad_out("not present");
return;
}
if (ipmi_sensor_get_event_reading_type(sensor)
== IPMI_EVENT_READING_TYPE_THRESHOLD)
{
rv = ipmi_sensor_get_reading(sensor, read_sensor, NULL);
if (rv)
ui_log("redisplay_sensor: Unable to get sensor reading: 0x%x\n",
rv);
switch (ipmi_sensor_get_threshold_access(sensor))
{
case IPMI_THRESHOLD_ACCESS_SUPPORT_READABLE:
case IPMI_THRESHOLD_ACCESS_SUPPORT_SETTABLE:
rv = ipmi_sensor_get_thresholds(sensor, read_thresholds, NULL);
if (rv)
ui_log("Unable to get threshold values: 0x%x\n", rv);
break;
default:
break;
}
switch (ipmi_sensor_get_event_support(sensor))
{
case IPMI_EVENT_SUPPORT_PER_STATE:
case IPMI_EVENT_SUPPORT_ENTIRE_SENSOR:
rv = ipmi_sensor_get_event_enables(sensor,
read_thresh_event_enables,
NULL);
if (rv)
ui_log("Unable to get event values: 0x%x\n", rv);
break;
default:
break;
}
} else {
rv = ipmi_sensor_get_states(sensor, read_states, NULL);
if (rv)
ui_log("Unable to get sensor reading: 0x%x\n", rv);
switch (ipmi_sensor_get_event_support(sensor))
{
case IPMI_EVENT_SUPPORT_PER_STATE:
case IPMI_EVENT_SUPPORT_ENTIRE_SENSOR:
rv = ipmi_sensor_get_event_enables(sensor,
read_discrete_event_enables,
NULL);
if (rv)
ui_log("Unable to get event values: 0x%x\n", rv);
break;
default:
break;
}
}
}
static void
sensor_handler(ipmi_entity_t *entity, ipmi_sensor_t *sensor, void *cb_data)
{
char name[33];
struct sensor_info *sinfo = cb_data;
int rv;
int present = 1;
ipmi_sensor_get_id(sensor, name, 33);
if (strcmp(name, sinfo->name) == 0) {
sinfo->found = 1;
curr_display_type = DISPLAY_SENSOR;
curr_sensor_id = ipmi_sensor_convert_to_id(sensor);
sensor_displayed = 0;
sensor_ops_to_read_count = 1;
if (! ipmi_entity_is_present(entity)
&& ipmi_sensor_get_ignore_if_no_entity(sensor))
{
present = 0;
}
if (ipmi_sensor_get_event_reading_type(sensor)
== IPMI_EVENT_READING_TYPE_THRESHOLD)
{
if (present) {
sensor_ops_to_read_count++;
rv = ipmi_sensor_get_reading(sensor, read_sensor, NULL);
if (rv)
ui_log("Unable to get sensor reading: 0x%x\n", rv);
switch (ipmi_sensor_get_threshold_access(sensor))
{
case IPMI_THRESHOLD_ACCESS_SUPPORT_READABLE:
case IPMI_THRESHOLD_ACCESS_SUPPORT_SETTABLE:
sensor_ops_to_read_count++;
rv = ipmi_sensor_get_thresholds(sensor, read_thresholds,
NULL);
if (rv)
ui_log("Unable to get threshold values: 0x%x\n", rv);
break;
default:
break;
}
switch (ipmi_sensor_get_event_support(sensor))
{
case IPMI_EVENT_SUPPORT_PER_STATE:
case IPMI_EVENT_SUPPORT_ENTIRE_SENSOR:
sensor_ops_to_read_count++;
rv = ipmi_sensor_get_event_enables
(sensor,
read_thresh_event_enables,
NULL);
if (rv)
ui_log("Unable to get event values: 0x%x\n", rv);
break;
default:
break;
}
}
} else {
if (present) {
sensor_ops_to_read_count++;
rv = ipmi_sensor_get_states(sensor, read_states, NULL);
if (rv)
ui_log("Unable to get sensor reading: 0x%x\n", rv);
switch (ipmi_sensor_get_event_support(sensor))
{
case IPMI_EVENT_SUPPORT_PER_STATE:
case IPMI_EVENT_SUPPORT_ENTIRE_SENSOR:
sensor_ops_to_read_count++;
rv = ipmi_sensor_get_event_enables
(sensor,
read_discrete_event_enables,
NULL);
if (rv)
ui_log("Unable to get event values: 0x%x\n", rv);
break;
default:
break;
}
}
}
display_sensor(entity, sensor);
display_pad_refresh();
}
}
static void
found_entity_for_sensor(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
struct sensor_info sinfo;
sinfo.name = strtok_r(NULL, "", toks2);
if (!sinfo.name) {
cmd_win_out("Invalid sensor given\n");
return;
}
conv_to_spaces(sinfo.name);
sinfo.found = 0;
ipmi_entity_iterate_sensors(entity, sensor_handler, &sinfo);
if (!sinfo.found) {
char loc[MAX_ENTITY_LOC_SIZE];
conv_from_spaces(sinfo.name);
cmd_win_out("Sensor %s.%s not found\n",
get_entity_loc(entity, loc, sizeof(loc)),
sinfo.name);
return;
}
}
int
sensor_cmd(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, found_entity_for_sensor, NULL);
return 0;
}
typedef struct events_enable_info_s
{
ipmi_event_state_t *states;
} events_enable_info_t;
void
events_enable_done(ipmi_sensor_t *sensor,
int err,
void *cb_data)
{
if (err)
ui_log("Error setting events enable: 0x%x", err);
}
static void
events_enable(ipmi_sensor_t *sensor, void *cb_data)
{
events_enable_info_t *info = cb_data;
int rv;
rv = ipmi_sensor_set_event_enables(sensor, info->states,
events_enable_done, NULL);
if (rv)
ui_log("Error sending events enable: 0x%x", rv);
ipmi_mem_free(info);
}
static int
events_enable_cmd(char *cmd, char **toks, void *cb_data)
{
events_enable_info_t *info;
unsigned char enable;
int i;
char *enptr;
int rv;
info = ipmi_mem_alloc(sizeof(*info));
if (!info) {
cmd_win_out("Out of memory\n");
return 0;
}
info->states = ipmi_mem_alloc(ipmi_event_state_size());
if (!info->states) {
ipmi_mem_free(info);
cmd_win_out("Out of memory\n");
return 0;
}
ipmi_event_state_init(info->states);
if (get_uchar(toks, &enable, "events"))
return 0;
ipmi_event_state_set_events_enabled(info->states, enable);
if (get_uchar(toks, &enable, "scanning"))
return 0;
ipmi_event_state_set_scanning_enabled(info->states, enable);
enptr = strtok_r(NULL, " \t\n", toks);
if (!enptr) {
cmd_win_out("No assertion mask given\n");
return 0;
}
for (i=0; enptr[i]!='\0'; i++) {
if (enptr[i] == '1')
ipmi_discrete_event_set(info->states, i, IPMI_ASSERTION);
else if (enptr[i] == '0')
ipmi_discrete_event_clear(info->states, i, IPMI_ASSERTION);
else {
cmd_win_out("Invalid assertion value\n");
return 0;
}
}
enptr = strtok_r(NULL, " \t\n", toks);
if (!enptr) {
cmd_win_out("No deassertion mask given\n");
return 0;
}
for (i=0; enptr[i]!='\0'; i++) {
if (enptr[i] == '1')
ipmi_discrete_event_set(info->states, i, IPMI_DEASSERTION);
else if (enptr[i] == '0')
ipmi_discrete_event_clear(info->states, i, IPMI_DEASSERTION);
else {
cmd_win_out("Invalid deassertion value\n");
return 0;
}
}
rv = ipmi_sensor_pointer_cb(curr_sensor_id, events_enable, info);
if (rv) {
cmd_win_out("Unable to get sensor pointer: 0x%x\n", rv);
ipmi_mem_free(info);
}
return 0;
}
static void
controls_handler(ipmi_entity_t *entity, ipmi_control_t *control, void *cb_data)
{
char loc[MAX_ENTITY_LOC_SIZE];
char name[33];
char name2[33];
ipmi_control_get_id(control, name, 33);
strcpy(name2, name);
conv_from_spaces(name2);
display_pad_out(" %s.%s - %s\n",
get_entity_loc(entity, loc, sizeof(loc)),
name2, name);
}
static void
found_entity_for_controls(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
char loc[MAX_ENTITY_LOC_SIZE];
curr_display_type = DISPLAY_CONTROLS;
display_pad_clear();
display_pad_out("Controls for entity %s:\n",
get_entity_loc(entity, loc, sizeof(loc)));
ipmi_entity_iterate_controls(entity, controls_handler, NULL);
display_pad_refresh();
}
static int
controls_cmd(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, found_entity_for_controls, NULL);
return 0;
}
int control_displayed;
int control_ops_to_read_count;
int control_read_err;
int *normal_control_vals;
ipmi_light_setting_t *light_control_val;
int id_control_length;
unsigned char *id_control_vals;
static void
display_control(ipmi_entity_t *entity, ipmi_control_t *control)
{
char loc[MAX_ENTITY_LOC_SIZE];
int control_type;
char name[33];
char cname[IPMI_CONTROL_NAME_LEN];
int i;
int num_vals;
if (control_displayed)
return;
control_ops_to_read_count--;
if (control_ops_to_read_count > 0)
return;
control_displayed = 1;
ipmi_control_get_id(control, name, 33);
curr_control_id = ipmi_control_convert_to_id(control);
display_pad_clear();
conv_from_spaces(name);
display_pad_out("Control %s.%s:\n",
get_entity_loc(entity, loc, sizeof(loc)),
name);
if (ipmi_control_get_ignore_if_no_entity(control))
display_pad_out(" ignore if entity not present\n");
else
display_pad_out(" still there if entity not present\n");
ipmi_control_get_name(control, cname, sizeof(cname));
display_pad_out(" name = %s\n", cname);
control_type = ipmi_control_get_type(control);
display_pad_out(" type = %s (%d)\n",
ipmi_control_get_type_string(control), control_type);
num_vals = ipmi_control_get_num_vals(control);
switch (control_type) {
case IPMI_CONTROL_LIGHT:
case IPMI_CONTROL_RELAY:
case IPMI_CONTROL_ALARM:
case IPMI_CONTROL_RESET:
case IPMI_CONTROL_ONE_SHOT_RESET:
case IPMI_CONTROL_POWER:
case IPMI_CONTROL_FAN_SPEED:
case IPMI_CONTROL_OUTPUT:
case IPMI_CONTROL_ONE_SHOT_OUTPUT:
display_pad_out(" num entities = %d\n", num_vals);
break;
case IPMI_CONTROL_DISPLAY:
case IPMI_CONTROL_IDENTIFIER:
break;
}
display_pad_out(" value = ");
getyx(display_pad, value_pos.y, value_pos.x);
if (! ipmi_control_is_readable(control)) {
display_pad_out("not readable");
} else if (control_read_err) {
/* Nothing to do. */
} else {
switch (control_type) {
case IPMI_CONTROL_LIGHT:
if (ipmi_control_light_set_with_setting(control)) {
if (light_control_val) {
ipmi_light_setting_t *setting = light_control_val;
for (i=0; i<num_vals; ) {
int color, on, off, lc;
ipmi_light_setting_get_color(setting, i, &color);
ipmi_light_setting_get_on_time(setting, i, &on);
ipmi_light_setting_get_off_time(setting, i, &off);
ipmi_light_setting_in_local_control(setting, i,
&lc);
wmove(display_pad, value_pos.y+i, value_pos.x);
display_pad_out("0x%x 0x%x 0x%x %s",
color, on, off,
lc ? "local cnt": " ");
i++;
if (i < num_vals)
display_pad_out("\n ");
}
ipmi_free_light_settings(light_control_val);
light_control_val = NULL;
} else {
display_pad_out("error reading values");
}
break;
}
/* FALLTHRU */
case IPMI_CONTROL_RELAY:
case IPMI_CONTROL_ALARM:
case IPMI_CONTROL_RESET:
case IPMI_CONTROL_ONE_SHOT_RESET:
case IPMI_CONTROL_POWER:
case IPMI_CONTROL_FAN_SPEED:
case IPMI_CONTROL_OUTPUT:
case IPMI_CONTROL_ONE_SHOT_OUTPUT:
if (normal_control_vals) {
for (i=0; i<num_vals; ) {
display_pad_out("%d (0x%x)", normal_control_vals[i],
normal_control_vals[i]);
i++;
if (i < num_vals)
display_pad_out("\n ");
}
ipmi_mem_free(normal_control_vals);
normal_control_vals = NULL;
} else {
display_pad_out("error reading values");
}
break;
case IPMI_CONTROL_DISPLAY:
break;
case IPMI_CONTROL_IDENTIFIER:
if (id_control_vals) {
for (i=0; i<id_control_length;) {
display_pad_out("0x%2.2x\n", id_control_vals[i]);
i++;
if (i < num_vals)
display_pad_out("\n ");
}
ipmi_mem_free(id_control_vals);
id_control_vals = NULL;
} else {
display_pad_out("error reading values");
}
break;
}
}
display_pad_out("\n");
display_pad_refresh();
}
static void
light_control_val_read(ipmi_control_t *control,
int err,
ipmi_light_setting_t *setting,
void *cb_data)
{
ipmi_control_id_t control_id;
int num_vals;
int i;
if (control == NULL) {
/* The control went away, stop the operation. */
wmove(display_pad, value_pos.y, value_pos.x);
display_pad_out("invalid");
curr_display_type = DISPLAY_NONE;
return;
}
control_id = ipmi_control_convert_to_id(control);
if (!((curr_display_type == DISPLAY_CONTROL)
&& (ipmi_cmp_control_id(control_id, curr_control_id) == 0)))
return;
num_vals = ipmi_control_get_num_vals(control);
if (control_displayed) {
if (err) {
wmove(display_pad, value_pos.y, value_pos.x);
display_pad_out("?");
} else {
for (i=0; i<num_vals; i++) {
int color, on, off, lc;
ipmi_light_setting_get_color(setting, i, &color);
ipmi_light_setting_get_on_time(setting, i, &on);
ipmi_light_setting_get_off_time(setting, i, &off);
ipmi_light_setting_in_local_control(setting, i, &lc);
wmove(display_pad, value_pos.y+i, value_pos.x);
display_pad_out("0x%x 0x%x 0x%x %s",
color, on, off,
lc ? "local cnt": " ");
}
}
display_pad_refresh();
} else {
if (light_control_val)
ipmi_free_light_settings(light_control_val);
if (err) {
light_control_val = NULL;
} else {
light_control_val = ipmi_light_settings_dup(setting);
}
display_control(ipmi_control_get_entity(control), control);
}
}
static void
normal_control_val_read(ipmi_control_t *control,
int err,
int *val,
void *cb_data)
{
ipmi_control_id_t control_id;
int num_vals;
int i;
if (control == NULL) {
/* The control went away, stop the operation. */
wmove(display_pad, value_pos.y, value_pos.x);
display_pad_out("invalid");
curr_display_type = DISPLAY_NONE;
return;
}
control_id = ipmi_control_convert_to_id(control);
if (!((curr_display_type == DISPLAY_CONTROL)
&& (ipmi_cmp_control_id(control_id, curr_control_id) == 0)))
return;
num_vals = ipmi_control_get_num_vals(control);
if (control_displayed) {
if (err) {
wmove(display_pad, value_pos.y, value_pos.x);
display_pad_out("?");
} else {
for (i=0; i<num_vals; i++) {
wmove(display_pad, value_pos.y+i, value_pos.x);
display_pad_out("%d (0x%x)", val[i], val[i]);
}
}
display_pad_refresh();
} else {
if (err) {
if (normal_control_vals)
ipmi_mem_free(normal_control_vals);
normal_control_vals = NULL;
} else {
normal_control_vals = ipmi_mem_alloc(sizeof(int) * num_vals);
if (normal_control_vals) {
memcpy(normal_control_vals, val, sizeof(int) * num_vals);
}
}
display_control(ipmi_control_get_entity(control), control);
}
}
static void
identifier_control_val_read(ipmi_control_t *control,
int err,
unsigned char *val,
int length,
void *cb_data)
{
ipmi_control_id_t control_id;
int i;
if (control == NULL) {
/* The control went away, stop the operation. */
wmove(display_pad, value_pos.y, value_pos.x);
display_pad_out("invalid");
curr_display_type = DISPLAY_NONE;
return;
}
control_id = ipmi_control_convert_to_id(control);
if (!((curr_display_type == DISPLAY_CONTROL)
&& (ipmi_cmp_control_id(control_id, curr_control_id) == 0)))
return;
if (control_displayed) {
if (err) {
wmove(display_pad, value_pos.y, value_pos.x);
display_pad_out("?");
} else {
wmove(display_pad, value_pos.y, value_pos.x);
for (i=0; i<length; i++) {
display_pad_out("0x%2.2x", val[i]);
if (i < length)
display_pad_out("\n ");
}
}
display_pad_refresh();
} else {
if (err) {
if (id_control_vals)
ipmi_mem_free(id_control_vals);
id_control_vals = NULL;
} else {
id_control_length = length;
id_control_vals = ipmi_mem_alloc(sizeof(unsigned char) * length);
if (id_control_vals) {
memcpy(id_control_vals, val, sizeof(unsigned char) * length);
}
display_control(ipmi_control_get_entity(control), control);
}
}
}
static void
redisplay_control(ipmi_control_t *control, void *cb_data)
{
int control_type;
ipmi_entity_t *entity;
entity = ipmi_control_get_entity(control);
if (!entity)
return;
if (! ipmi_control_is_readable(control)) {
wmove(display_pad, value_pos.y, value_pos.x);
display_pad_out("not readable");
display_pad_refresh();
return;
}
if (!ipmi_entity_is_present(entity)
&& ipmi_control_get_ignore_if_no_entity(control))
{
wmove(display_pad, value_pos.y, value_pos.x);
display_pad_out("not present");
display_pad_refresh();
return;
}
control_type = ipmi_control_get_type(control);
switch (control_type) {
case IPMI_CONTROL_LIGHT:
if (ipmi_control_light_set_with_setting(control)) {
ipmi_control_get_light(control, light_control_val_read, NULL);
break;
}
/* FALLTHRU */
case IPMI_CONTROL_RELAY:
case IPMI_CONTROL_ALARM:
case IPMI_CONTROL_RESET:
case IPMI_CONTROL_ONE_SHOT_RESET:
case IPMI_CONTROL_POWER:
case IPMI_CONTROL_FAN_SPEED:
case IPMI_CONTROL_OUTPUT:
case IPMI_CONTROL_ONE_SHOT_OUTPUT:
ipmi_control_get_val(control, normal_control_val_read, NULL);
break;
case IPMI_CONTROL_DISPLAY:
break;
case IPMI_CONTROL_IDENTIFIER:
ipmi_control_identifier_get_val(control,
identifier_control_val_read,
NULL);
break;
}
}
struct control_info {
int found;
char *name;
};
static void
control_handler(ipmi_entity_t *entity, ipmi_control_t *control, void *cb_data)
{
struct control_info *iinfo = cb_data;
char name[33];
int control_type;
int rv;
ipmi_control_get_id(control, name, 33);
if (strcmp(name, iinfo->name) == 0) {
iinfo->found = 1;
curr_display_type = DISPLAY_CONTROL;
curr_control_id = ipmi_control_convert_to_id(control);
control_ops_to_read_count = 1;
control_displayed = 0;
if (! ipmi_control_is_readable(control)) {
/* If the control can't be read, then just display it now. */
display_control(entity, control);
return;
}
control_type = ipmi_control_get_type(control);
switch (control_type) {
case IPMI_CONTROL_LIGHT:
if (ipmi_control_light_set_with_setting(control)) {
control_ops_to_read_count++;
rv = ipmi_control_get_light(control, light_control_val_read,
NULL);
if (rv) {
ui_log("Unable to read light control val: 0x%x\n", rv);
}
break;
}
/* FALLTHRU */
case IPMI_CONTROL_RELAY:
case IPMI_CONTROL_ALARM:
case IPMI_CONTROL_RESET:
case IPMI_CONTROL_ONE_SHOT_RESET:
case IPMI_CONTROL_POWER:
case IPMI_CONTROL_FAN_SPEED:
case IPMI_CONTROL_OUTPUT:
case IPMI_CONTROL_ONE_SHOT_OUTPUT:
control_ops_to_read_count++;
rv = ipmi_control_get_val(control, normal_control_val_read, NULL);
if (rv) {
ui_log("Unable to read control val: 0x%x\n", rv);
}
break;
case IPMI_CONTROL_DISPLAY:
break;
case IPMI_CONTROL_IDENTIFIER:
control_ops_to_read_count++;
rv = ipmi_control_identifier_get_val(control,
identifier_control_val_read,
NULL);
if (rv) {
ui_log("Unable to read control val: 0x%x\n", rv);
}
break;
}
display_control(entity, control);
}
}
static void
found_entity_for_control(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
struct control_info iinfo;
iinfo.name = strtok_r(NULL, "", toks2);
if (!iinfo.name) {
cmd_win_out("Invalid control given\n");
return;
}
conv_to_spaces(iinfo.name);
iinfo.found = 0;
ipmi_entity_iterate_controls(entity, control_handler, &iinfo);
if (!iinfo.found) {
char loc[MAX_ENTITY_LOC_SIZE];
conv_from_spaces(iinfo.name);
cmd_win_out("Control %s.%s not found\n",
get_entity_loc(entity, loc, sizeof(loc)),
iinfo.name);
return;
}
}
int
control_cmd(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, found_entity_for_control, NULL);
return 0;
}
typedef struct rearm_info_s
{
int global;
ipmi_event_state_t *states;
} rearm_info_t;
void
rearm_done(ipmi_sensor_t *sensor,
int err,
void *cb_data)
{
if (err)
ui_log("Error rearming sensor: 0x%x", err);
}
static void
rearm(ipmi_sensor_t *sensor, void *cb_data)
{
rearm_info_t *info = cb_data;
int rv;
rv = ipmi_sensor_rearm(sensor, info->global, info->states,
rearm_done, NULL);
if (rv)
ui_log("Error sending rearm: 0x%x", rv);
if (info->states)
ipmi_mem_free(info->states);
ipmi_mem_free(info);
}
static int
rearm_cmd(char *cmd, char **toks, void *cb_data)
{
rearm_info_t *info;
unsigned char global;
int i;
char *enptr;
int rv;
info = ipmi_mem_alloc(sizeof(*info));
if (!info) {
cmd_win_out("Out of memory\n");
return 0;
}
info->states = NULL;
if (get_uchar(toks, &global, "global rearm"))
goto out_err;
info->global = global;
if (!global) {
info->states = ipmi_mem_alloc(ipmi_event_state_size());
if (!info->states) {
ipmi_mem_free(info);
cmd_win_out("Out of memory\n");
goto out_err;
}
ipmi_event_state_init(info->states);
enptr = strtok_r(NULL, " \t\n", toks);
if (!enptr) {
cmd_win_out("No assertion mask given\n");
goto out_err;
}
for (i=0; enptr[i]!='\0'; i++) {
if (enptr[i] == '1')
ipmi_discrete_event_set(info->states, i, IPMI_ASSERTION);
else if (enptr[i] == '0')
ipmi_discrete_event_clear(info->states, i, IPMI_ASSERTION);
else {
cmd_win_out("Invalid assertion value\n");
goto out_err;
}
}
enptr = strtok_r(NULL, " \t\n", toks);
if (!enptr) {
cmd_win_out("No deassertion mask given\n");
return 0;
}
for (i=0; enptr[i]!='\0'; i++) {
if (enptr[i] == '1')
ipmi_discrete_event_set(info->states, i, IPMI_DEASSERTION);
else if (enptr[i] == '0')
ipmi_discrete_event_clear(info->states, i, IPMI_DEASSERTION);
else {
cmd_win_out("Invalid deassertion value\n");
goto out_err;
}
}
}
rv = ipmi_sensor_pointer_cb(curr_sensor_id, rearm, info);
if (rv) {
cmd_win_out("Unable to get sensor pointer: 0x%x\n", rv);
goto out_err;
}
return 0;
out_err:
if (info) {
if (info->states)
ipmi_mem_free(info->states);
ipmi_mem_free(info);
}
return 0;
}
void
set_hysteresis_done(ipmi_sensor_t *sensor,
int err,
void *cb_data)
{
if (err)
ui_log("Error setting hysteresis: 0x%x", err);
else
ui_log("Hysteresis set");
}
static int
set_hysteresis_cmd(char *cmd, char **toks, void *cb_data)
{
unsigned char physt, nhyst;
int rv;
if (get_uchar(toks, &physt, "positive hysteresis value"))
goto out_err;
if (get_uchar(toks, &nhyst, "negative hysteresis value"))
goto out_err;
rv = ipmi_sensor_id_set_hysteresis(curr_sensor_id, physt, nhyst,
set_hysteresis_done, NULL);
if (rv) {
cmd_win_out("Unable to set hysteresis: 0x%x\n", rv);
goto out_err;
}
out_err:
return 0;
}
void
get_hysteresis_done(ipmi_sensor_t *sensor,
int err,
unsigned int positive_hysteresis,
unsigned int negative_hysteresis,
void *cb_data)
{
if (err)
ui_log("Error setting hysteresis: 0x%x", err);
else
ui_log("Hysteresis values: positive = 0x%x, negative = 0x%x",
positive_hysteresis, negative_hysteresis);
}
static int
get_hysteresis_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
rv = ipmi_sensor_id_get_hysteresis(curr_sensor_id,
get_hysteresis_done, NULL);
if (rv) {
cmd_win_out("Unable to get hysteresis: 0x%x\n", rv);
goto out_err;
}
out_err:
return 0;
}
static int
dump_fru_str(ipmi_fru_t *fru,
char *str,
int (*glen)(ipmi_fru_t *fru,
unsigned int *length),
int (*gtype)(ipmi_fru_t *fru,
enum ipmi_str_type_e *type),
int (*gstr)(ipmi_fru_t *fru,
char *str,
unsigned int *strlen))
{
enum ipmi_str_type_e type;
int rv;
char buf[128];
unsigned int len;
rv = gtype(fru, &type);
if (rv) {
if (rv != ENOSYS)
display_pad_out(" Error fetching type for %s: %x\n", str, rv);
return rv;
}
if (type == IPMI_BINARY_STR) {
display_pad_out(" %s is in binary\n", str);
return 0;
} else if (type == IPMI_UNICODE_STR) {
display_pad_out(" %s is in unicode\n", str);
return 0;
} else if (type != IPMI_ASCII_STR) {
display_pad_out(" %s is in unknown format\n", str);
return 0;
}
len = sizeof(buf);
rv = gstr(fru, buf, &len);
if (rv) {
display_pad_out(" Error fetching string for %s: %x\n", str, rv);
return rv;
}
display_pad_out(" %s: %s\n", str, buf);
return 0;
}
static int
dump_fru_custom_str(ipmi_fru_t *fru,
char *str,
int num,
int (*glen)(ipmi_fru_t *fru,
unsigned int num,
unsigned int *length),
int (*gtype)(ipmi_fru_t *fru,
unsigned int num,
enum ipmi_str_type_e *type),
int (*gstr)(ipmi_fru_t *fru,
unsigned int num,
char *str,
unsigned int *strlen))
{
enum ipmi_str_type_e type;
int rv;
char buf[128];
unsigned int len;
rv = gtype(fru, num, &type);
if (rv)
return rv;
if (type == IPMI_BINARY_STR) {
display_pad_out(" %s custom %d is in binary\n", str, num);
return 0;
} else if (type == IPMI_UNICODE_STR) {
display_pad_out(" %s custom %d is in unicode\n", str, num);
return 0;
} else if (type != IPMI_ASCII_STR) {
display_pad_out(" %s custom %d is in unknown format\n", str, num);
return 0;
}
len = sizeof(buf);
rv = gstr(fru, num, buf, &len);
if (rv) {
display_pad_out(" Error fetching string for %s custom %d: %x\n",
str, num, rv);
return rv;
}
display_pad_out(" %s custom %d: %s\n", str, num, buf);
return 0;
}
#define DUMP_FRU_STR(name, str) \
dump_fru_str(fru, str, ipmi_fru_get_ ## name ## _len, \
ipmi_fru_get_ ## name ## _type, \
ipmi_fru_get_ ## name)
#define DUMP_FRU_CUSTOM_STR(name, str) \
do { \
int i, _rv; \
for (i=0; ; i++) { \
_rv = dump_fru_custom_str(fru, str, i, \
ipmi_fru_get_ ## name ## _custom_len, \
ipmi_fru_get_ ## name ## _custom_type, \
ipmi_fru_get_ ## name ## _custom); \
if (_rv) \
break; \
} \
} while (0)
static int
traverse_fru_multi_record_tree(ipmi_fru_node_t *node,
int indent)
{
const char *name;
unsigned int i, k;
enum ipmi_fru_data_type_e dtype;
int intval, rv;
double floatval;
time_t time;
char *data;
unsigned int data_len;
ipmi_fru_node_t *sub_node;
for (i=0; ; i++) {
rv = ipmi_fru_node_get_field(node, i, &name, &dtype, &intval, &time,
&floatval, &data, &data_len, &sub_node);
if ((rv == EINVAL) || (rv == ENOSYS))
break;
else if (rv)
continue;
if (name)
display_pad_out("%*sName: %s \n", indent, "", name);
else
/* An array index. */
display_pad_out("%*%d: \n", indent, "", i);
switch (dtype) {
case IPMI_FRU_DATA_INT:
display_pad_out("%*sType: integer\n", indent, "");
display_pad_out("%*sData: %d\n", indent, "", intval);
break;
case IPMI_FRU_DATA_TIME:
display_pad_out("%*sType: time\n", indent, "");
display_pad_out("%*sData: %ld\n", indent, "", (long)time);
break;
case IPMI_FRU_DATA_BOOLEAN:
display_pad_out("%*sType: boolean\n", indent, "");
display_pad_out("%*sData: %ls\n", indent, "",
intval ? "true" : "false");
break;
case IPMI_FRU_DATA_FLOAT:
display_pad_out("%*sType: float\n", indent, "");
display_pad_out("%*sData: %lf\n", indent, "", floatval);
break;
case IPMI_FRU_DATA_BINARY:
display_pad_out("%*sType: binary\n", indent, "");
display_pad_out("%*sData:", indent, "");
for(k=0; k<data_len; k++)
display_pad_out(" %2.2x", data[k]);
display_pad_out("\n");
break;
case IPMI_FRU_DATA_ASCII:
display_pad_out("%*sType: ascii\n", indent, "");
display_pad_out("%*sData: %s\n", indent, "", data);
break;
case IPMI_FRU_DATA_UNICODE:
display_pad_out("%*sType: unicode\n", indent, "");
display_pad_out("%*sData:", indent, "");
for (k=0; k<data_len; k++)
display_pad_out(" %2.2x", data[k]);
display_pad_out("\n");
break;
case IPMI_FRU_DATA_SUB_NODE:
if (intval == -1)
display_pad_out("%*sType: Record\n", indent, "");
else
display_pad_out("%*sType: Array\n", indent, "");
traverse_fru_multi_record_tree(sub_node, indent+2);
break;
default:
display_pad_out("Type: unknown\n");
break;
}
}
ipmi_fru_put_node(node);
return 0;
}
static void
dump_fru_info(ipmi_fru_t *fru)
{
unsigned char ucval;
unsigned int uival;
time_t tval;
int rv;
int i, num_multi;
rv = ipmi_fru_get_internal_use_version(fru, &ucval);
if (!rv)
display_pad_out(" internal area version: 0x%2.2x\n", ucval);
rv = ipmi_fru_get_internal_use_length(fru, &uival);
if (!rv)
display_pad_out(" internal area length: %d\n", uival);
/* FIXME - dump internal use data. */
rv = ipmi_fru_get_chassis_info_version(fru, &ucval);
if (!rv)
display_pad_out(" chassis info version: 0x%2.2x\n", ucval);
rv = ipmi_fru_get_chassis_info_type(fru, &ucval);
if (!rv)
display_pad_out(" chassis info type: 0x%2.2x\n", ucval);
DUMP_FRU_STR(chassis_info_part_number, "chassis info part number");
DUMP_FRU_STR(chassis_info_serial_number, "chassis info serial number");
DUMP_FRU_CUSTOM_STR(chassis_info, "chassis info");
rv = ipmi_fru_get_board_info_version(fru, &ucval);
if (!rv)
display_pad_out(" board info version: 0x%2.2x\n", ucval);
rv = ipmi_fru_get_board_info_lang_code(fru, &ucval);
if (!rv)
display_pad_out(" board info lang code: 0x%2.2x\n", ucval);
rv = ipmi_fru_get_board_info_mfg_time(fru, &tval);
if (!rv)
display_pad_out(" board info mfg time: %ld\n", (long) tval);
DUMP_FRU_STR(board_info_board_manufacturer,
"board info board manufacturer");
DUMP_FRU_STR(board_info_board_product_name,
"board info board product name");
DUMP_FRU_STR(board_info_board_serial_number,
"board info board serial number");
DUMP_FRU_STR(board_info_board_part_number,
"board info board part number");
DUMP_FRU_STR(board_info_fru_file_id, "board info fru file id");
DUMP_FRU_CUSTOM_STR(board_info, "board info");
rv = ipmi_fru_get_product_info_version(fru, &ucval);
if (!rv)
display_pad_out(" product info version: 0x%2.2x\n", ucval);
rv = ipmi_fru_get_product_info_lang_code(fru, &ucval);
if (!rv)
display_pad_out(" product info lang code: 0x%2.2x\n", ucval);
DUMP_FRU_STR(product_info_manufacturer_name,
"product info manufacturer name");
DUMP_FRU_STR(product_info_product_name, "product info product name");
DUMP_FRU_STR(product_info_product_part_model_number,
"product info product part model number");
DUMP_FRU_STR(product_info_product_version, "product info product version");
DUMP_FRU_STR(product_info_product_serial_number,
"product info product serial number");
DUMP_FRU_STR(product_info_asset_tag, "product info asset tag");
DUMP_FRU_STR(product_info_fru_file_id, "product info fru file id");
DUMP_FRU_CUSTOM_STR(product_info, "product info");
num_multi = ipmi_fru_get_num_multi_records(fru);
for (i=0; i<num_multi; i++) {
unsigned char type, ver;
unsigned int j;
unsigned int len;
unsigned char *data;
ipmi_fru_node_t *node;
const char *name;
rv = ipmi_fru_get_multi_record_type(fru, i, &type);
if (rv)
display_pad_out(" multi-record %d, error getting type: %x\n", rv);
rv = ipmi_fru_get_multi_record_format_version(fru, i, &ver);
if (rv)
display_pad_out(" multi-record %d, error getting ver: %x\n", rv);
display_pad_out(" multi-record %d, type 0x%x, format version 0x%x:",
i, type, ver);
rv = ipmi_fru_get_multi_record_data_len(fru, i, &len);
if (rv) {
display_pad_out("\n multi-record %d, error getting length: %x\n",
rv);
continue;
}
data = ipmi_mem_alloc(len);
if (!data) {
display_pad_out("\n multi-record %d, error allocating data\n");
continue;
}
rv = ipmi_fru_get_multi_record_data(fru, i, data, &len);
if (rv) {
display_pad_out("\n multi-record %d, error getting data: %x\n",
rv);
} else {
for (j=0; j<len; j++) {
if ((j > 0) && ((j % 16) == 0))
display_pad_out("\n ");
display_pad_out(" %2.2x", data[j]);
}
display_pad_out("\n");
rv = ipmi_fru_multi_record_get_root_node(fru, i, &name, &node);
if ( !rv ) {
display_pad_out("Multi-record decode: %s", name);
traverse_fru_multi_record_tree(node, 2);
} else if ((rv != ENOSYS) && (rv != EINVAL)) {
display_pad_out(" multi-record %d, error get root obj: %x\n ",
i, rv);
}
}
ipmi_mem_free(data);
}
}
static void
found_entity_for_fru(ipmi_entity_t *entity,
char **toks,
char **toks2,
void *cb_data)
{
char loc[MAX_ENTITY_LOC_SIZE];
ipmi_fru_t *fru = ipmi_entity_get_fru(entity);
display_pad_clear();
if (!fru) {
cmd_win_out("No FRU for entity %s\n",
get_entity_loc(entity, loc, sizeof(loc)));
return;
}
display_pad_out("FRU for entity %s\n",
get_entity_loc(entity, loc, sizeof(loc)));
dump_fru_info(fru);
display_pad_refresh();
}
static int
fru_cmd(char *cmd, char **toks, void *cb_data)
{
entity_finder(cmd, toks, found_entity_for_fru, NULL);
curr_display_type = DISPLAY_ENTITY;
return 0;
}
static void
fru_fetched(ipmi_fru_t *fru, int err, void *cb_data)
{
display_pad_clear();
if (err)
display_pad_out("Error fetching fru: %x\n", err);
else
dump_fru_info(fru);
display_pad_refresh();
if (err != ECANCELED)
ipmi_fru_destroy(fru, NULL, NULL);
}
typedef struct fru_rec_s
{
unsigned char is_logical;
unsigned char device_address;
unsigned char device_id;
unsigned char lun;
unsigned char private_bus;
unsigned char channel;
} fru_rec_t;
static void
dump_fru_cmder(ipmi_domain_t *domain, void *cb_data)
{
fru_rec_t *info = cb_data;
int rv;
rv = ipmi_fru_alloc(domain,
info->is_logical,
info->device_address,
info->device_id,
info->lun,
info->private_bus,
info->channel,
fru_fetched,
NULL,
NULL);
if (rv)
cmd_win_out("Unable to allocate fru: %x\n", rv);
}
static int
dump_fru_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
fru_rec_t info;
if (get_uchar(toks, &info.is_logical, "is_logical"))
return 0;
if (get_uchar(toks, &info.device_address, "device_address"))
return 0;
if (get_uchar(toks, &info.device_id, "device_id"))
return 0;
if (get_uchar(toks, &info.lun, "lun"))
return 0;
if (get_uchar(toks, &info.private_bus, "private_bus"))
return 0;
if (get_uchar(toks, &info.channel, "channel"))
return 0;
rv = ipmi_domain_pointer_cb(domain_id, dump_fru_cmder, &info);
if (rv)
cmd_win_out("Unable to convert domain id to a pointer\n");
else
curr_display_type = DISPLAY_ENTITY;
return 0;
}
static char y_or_n(int val)
{
if (val)
return 'y';
else
return 'n';
}
#define MCCMD_DATA_SIZE 30
typedef struct mccmd_info_s
{
ipmi_mcid_t mc_id;
unsigned char lun;
ipmi_msg_t msg;
int found;
unsigned char val;
} mccmd_info_t;
void mc_handler(ipmi_mc_t *mc, void *cb_data)
{
unsigned char vals[4];
mccmd_info_t *info = cb_data;
curr_display_type = DISPLAY_MC;
info->found = 1;
display_pad_clear();
display_pad_out("MC (%x %x) - %s\n",
ipmi_mc_get_channel(mc),
ipmi_mc_get_address(mc),
ipmi_mc_is_active(mc) ? "active" : "inactive");
display_pad_out(" provides_device_sdrs: %c\n",
y_or_n(ipmi_mc_provides_device_sdrs(mc)));
display_pad_out(" device_available: %c\n",
y_or_n(ipmi_mc_device_available(mc)));
display_pad_out(" chassis_support: %c\n",
y_or_n(ipmi_mc_chassis_support(mc)));
display_pad_out(" bridge_support: %c\n",
y_or_n(ipmi_mc_bridge_support(mc)));
display_pad_out(" ipmb_event_generator: %c\n",
y_or_n(ipmi_mc_ipmb_event_generator_support(mc)));
display_pad_out(" ipmb_event_receiver: %c\n",
y_or_n(ipmi_mc_ipmb_event_receiver_support(mc)));
display_pad_out(" fru_inventory_support: %c\n",
y_or_n(ipmi_mc_fru_inventory_support(mc)));
display_pad_out(" sel_device_support: %c\n",
y_or_n(ipmi_mc_sel_device_support(mc)));
display_pad_out(" sdr_repository_support: %c\n",
y_or_n(ipmi_mc_sdr_repository_support(mc)));
display_pad_out(" sensor_device_support: %c\n",
y_or_n(ipmi_mc_sensor_device_support(mc)));
display_pad_out(" device_id: %2.2x\n",
ipmi_mc_device_id(mc));
display_pad_out(" device_revision: %1.1x\n",
ipmi_mc_device_revision(mc));
display_pad_out(" fw_revision: %d.%d%d\n",
ipmi_mc_major_fw_revision(mc),
ipmi_mc_minor_fw_revision(mc)>>4,
ipmi_mc_minor_fw_revision(mc)&0xf);
display_pad_out(" version: %d.%d\n",
ipmi_mc_major_version(mc),
ipmi_mc_minor_version(mc));
display_pad_out(" manufacturer_id: %6.6x\n",
ipmi_mc_manufacturer_id(mc));
display_pad_out(" product_id: %4.4x\n",
ipmi_mc_product_id(mc));
ipmi_mc_aux_fw_revision(mc, vals);
display_pad_out(" aux_fw_revision: %2.2x %2.2x %2.2x %2.2x\n",
vals[0], vals[1], vals[2], vals[3]);
display_pad_out(" SEL count: %d entries, %d slots used\n",
ipmi_mc_sel_count(mc), ipmi_mc_sel_entries_used(mc));
}
int
get_mc_id(char **toks, ipmi_mcid_t *mc_id)
{
unsigned char val;
if (get_uchar(toks, &val, "mc channel"))
return 1;
mc_id->channel = val;
if (get_uchar(toks, &val, "MC num"))
return 1;
mc_id->mc_num = val;
mc_id->domain_id = domain_id;
return 0;
}
int
mc_cmd(char *cmd, char **toks, void *cb_data)
{
mccmd_info_t info;
int rv;
if (get_mc_id(toks, &info.mc_id))
return 0;
info.found = 0;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, mc_handler, &info);
if (rv) {
cmd_win_out("Unable to find MC\n");
return 0;
}
if (!info.found) {
cmd_win_out("Unable to find MC (%d %x)\n",
info.mc_id.channel, info.mc_id.mc_num);
}
display_pad_refresh();
return 0;
}
void mcs_handler(ipmi_domain_t *domain,
ipmi_mc_t *mc,
void *cb_data)
{
int addr;
int channel;
addr = ipmi_mc_get_address(mc);
channel = ipmi_mc_get_channel(mc);
display_pad_out(" (%x %x) - %s\n", channel, addr,
ipmi_mc_is_active(mc) ? "active" : "inactive");
}
static void
mcs_cmder(ipmi_domain_t *domain, void *cb_data)
{
ipmi_domain_iterate_mcs(domain, mcs_handler, NULL);
}
int
mcs_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
display_pad_clear();
curr_display_type = DISPLAY_MCS;
display_pad_out("MCs:\n");
rv = ipmi_domain_pointer_cb(domain_id, mcs_cmder, NULL);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
display_pad_refresh();
return 0;
}
static void
mccmd_rsp_handler(ipmi_mc_t *src,
ipmi_msg_t *msg,
void *rsp_data)
{
unsigned int i;
unsigned char *data;
display_pad_clear();
curr_display_type = DISPLAY_RSP;
display_pad_out("Response:\n");
display_pad_out(" NetFN = 0x%2.2x\n", msg->netfn);
display_pad_out(" Command = 0x%2.2x\n", msg->cmd);
display_pad_out(" Completion code = 0x%2.2x\n", msg->data[0]);
display_pad_out(" data =");
data = msg->data + 1;
for (i=0; i+1<msg->data_len; i++) {
if ((i != 0) && ((i % 8) == 0))
display_pad_out("\n ");
display_pad_out(" %2.2x", data[i]);
}
display_pad_out("\n");
display_pad_refresh();
}
void mccmd_handler(ipmi_mc_t *mc,
void *cb_data)
{
mccmd_info_t *info = cb_data;
int rv;
info->found = 1;
rv = ipmi_mc_send_command(mc, info->lun, &(info->msg), mccmd_rsp_handler,
NULL);
if (rv)
cmd_win_out("Send command failure: %x\n", rv);
}
int
mccmd_cmd(char *cmd, char **toks, void *cb_data)
{
mccmd_info_t info;
unsigned char data[MCCMD_DATA_SIZE];
unsigned int data_len;
int rv;
if (get_mc_id(toks, &info.mc_id))
return 0;
if (get_uchar(toks, &info.lun, "LUN"))
return 0;
if (get_uchar(toks, &info.msg.netfn, "NetFN"))
return 0;
if (get_uchar(toks, &info.msg.cmd, "command"))
return 0;
for (data_len=0; ; data_len++) {
if (get_uchar(toks, data+data_len, NULL))
break;
}
info.msg.data_len = data_len;
info.msg.data = data;
info.found = 0;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, mccmd_handler, &info);
if (rv) {
cmd_win_out("Unable to convert MC id to a pointer\n");
return 0;
}
if (!info.found) {
cmd_win_out("Unable to find MC (%d %x)\n",
info.mc_id.channel, info.mc_id.mc_num);
}
display_pad_refresh();
return 0;
}
void
mc_events_enable_cb(ipmi_mc_t *mc, int err, void *cb_data)
{
if (err)
ui_log("Error setting events enable: 0x%x\n", err);
else
ui_log("Events enable set\n");
}
void
mc_events_enable_handler(ipmi_mc_t *mc,
void *cb_data)
{
mccmd_info_t *info = cb_data;
int rv;
info->found = 1;
rv = ipmi_mc_set_events_enable(mc, info->val, mc_events_enable_cb, NULL);
if (rv)
cmd_win_out("Set events enable failure: %x\n", rv);
}
int
mc_events_enable_cmd(char *cmd, char **toks, void *cb_data)
{
mccmd_info_t info;
int rv;
if (get_mc_id(toks, &info.mc_id))
return 0;
if (get_uchar(toks, &info.val, "enabled"))
return 0;
info.found = 0;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, mc_events_enable_handler, &info);
if (rv) {
cmd_win_out("Unable to convert MC id to a pointer\n");
return 0;
}
if (!info.found) {
cmd_win_out("Unable to find MC (%d %x)\n",
info.mc_id.channel, info.mc_id.mc_num);
}
display_pad_refresh();
return 0;
}
void
mc_events_enabled_handler(ipmi_mc_t *mc,
void *cb_data)
{
mccmd_info_t *info = cb_data;
info->found = 1;
if (ipmi_mc_get_events_enable(mc))
cmd_win_out("Events enabled\n");
else
cmd_win_out("Events not enabled\n");
}
int
mc_events_enabled_cmd(char *cmd, char **toks, void *cb_data)
{
mccmd_info_t info;
int rv;
if (get_mc_id(toks, &info.mc_id))
return 0;
info.found = 0;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, mc_events_enabled_handler, &info);
if (rv) {
cmd_win_out("Unable to convert MC id to a pointer\n");
return 0;
}
if (!info.found) {
cmd_win_out("Unable to find MC (%d %x)\n",
info.mc_id.channel, info.mc_id.mc_num);
}
display_pad_refresh();
return 0;
}
void
display_pef(void)
{
if (!pef) {
display_pad_out("No PEF read, use readpef to fetch one\n");
return;
}
display_pad_out("PEF\n");
display_pad_out(" Version: %d.%d", ipmi_pef_major_version(pef),
ipmi_pef_minor_version(pef));
display_pad_out(" Supports:");
if (ipmi_pef_supports_diagnostic_interrupt(pef))
display_pad_out(" diagnostic_interrupt");
if (ipmi_pef_supports_oem_action(pef))
display_pad_out(" oem_action");
if (ipmi_pef_supports_power_cycle(pef))
display_pad_out(" power_cycle");
if (ipmi_pef_supports_reset(pef))
display_pad_out(" reset");
if (ipmi_pef_supports_power_down(pef))
display_pad_out(" power_down");
if (ipmi_pef_supports_alert(pef))
display_pad_out(" alert");
display_pad_out("\n");
display_pad_out(" Num event filter table entries: %d\n",
num_event_filter_table_entries(pef));
}
typedef struct pef_table_s
{
char *name;
int (*get)(ipmi_pef_config_t *pefc,
unsigned int sel,
unsigned int *val);
char *fmt;
} pef_table_t;
#define X(n, f) { #n, ipmi_pefconfig_get_##n, f }
static pef_table_t eft_table[] =
{
X(enable_filter, "%d"),
X(filter_type, "%d"),
X(diagnostic_interrupt, "%d"),
X(oem_action, "%d"),
X(power_cycle, "%d"),
X(reset, "%d"),
X(power_down, "%d"),
X(alert, "%d"),
X(alert_policy_number, "%d"),
X(event_severity, "0x%x"),
X(generator_id_addr, "0x%x"),
X(generator_id_channel_lun, "0x%x"),
X(sensor_type, "0x%x"),
X(sensor_number, "0x%x"),
X(event_trigger, "%d"),
X(data1_offset_mask, "0x%x"),
X(data1_mask, "%d"),
X(data1_compare1, "%d"),
X(data1_compare2, "%d"),
X(data2_mask, "%d"),
X(data2_compare1, "%d"),
X(data2_compare2, "%d"),
X(data3_mask, "%d"),
X(data3_compare1, "%d"),
X(data3_compare2, "%d"),
{ NULL }
};
static pef_table_t apt_table[] =
{
X(policy_num, "%d"),
X(enabled, "%d"),
X(policy, "%d"),
X(channel, "0x%x"),
X(destination_selector, "%d"),
X(alert_string_event_specific, "%d"),
X(alert_string_selector, "%d"),
{ NULL }
};
static pef_table_t ask_table[] =
{
X(event_filter, "%d"),
X(alert_string_set, "%d"),
{ NULL }
};
void
display_pef_config(void)
{
unsigned int i, j;
unsigned int val;
unsigned int len;
unsigned char data[128];
int rv;
unsigned int count;
if (!pef_config) {
display_pad_out("No PEF config read, use readpef to fetch one\n");
return;
}
display_pad_out(" alert_startup_delay_enabled: %d\n",
ipmi_pefconfig_get_alert_startup_delay_enabled(pef_config));
display_pad_out(" startup_delay_enabled: %d\n",
ipmi_pefconfig_get_startup_delay_enabled(pef_config));
display_pad_out(" event_messages_enabled: %d\n",
ipmi_pefconfig_get_event_messages_enabled(pef_config));
display_pad_out(" pef_enabled: %d\n",
ipmi_pefconfig_get_pef_enabled(pef_config));
display_pad_out(" diagnostic_interrupt_enabled: %d\n",
ipmi_pefconfig_get_diagnostic_interrupt_enabled(pef_config));
display_pad_out(" oem_action_enabled: %d\n",
ipmi_pefconfig_get_oem_action_enabled(pef_config));
display_pad_out(" power_cycle_enabled: %d\n",
ipmi_pefconfig_get_power_cycle_enabled(pef_config));
display_pad_out(" reset_enabled: %d\n",
ipmi_pefconfig_get_reset_enabled(pef_config));
display_pad_out(" power_down_enabled: %d\n",
ipmi_pefconfig_get_power_down_enabled(pef_config));
display_pad_out(" alert_enabled: %d\n",
ipmi_pefconfig_get_alert_enabled(pef_config));
if (ipmi_pefconfig_get_startup_delay(pef_config, &val) == 0)
display_pad_out(" startup_delay: %d\n", val);
if (ipmi_pefconfig_get_alert_startup_delay(pef_config, &val) == 0)
display_pad_out(" alert_startup_delay: %d\n", val);
len = sizeof(data);
rv = ipmi_pefconfig_get_guid(pef_config, &val, data, &len);
if (!rv) {
display_pad_out(" guid_enabled: %d\n", val);
display_pad_out(" guid:", val);
for (i=0; i<len; i++)
display_pad_out(" %2.2x", data[i]);
display_pad_out("\n");
}
count = ipmi_pefconfig_get_num_event_filters(pef_config);
display_pad_out(" num_event_filters: %d\n", count);
for (i=0; i<count; i++) {
display_pad_out(" event filter %d:\n", i+1);
for (j=0; eft_table[j].name != NULL; j++) {
rv = eft_table[j].get(pef_config, i, &val);
display_pad_out(" %s: ", eft_table[j].name);
if (rv)
display_pad_out("error %x", rv);
else
display_pad_out(eft_table[j].fmt, val);
display_pad_out("\n");
}
}
count = ipmi_pefconfig_get_num_alert_policies(pef_config);
display_pad_out(" num_alert_policies: %d\n", count);
for (i=0; i<count; i++) {
display_pad_out(" alert policy %d:\n", i+1);
for (j=0; apt_table[j].name != NULL; j++) {
rv = apt_table[j].get(pef_config, i, &val);
display_pad_out(" %s: ", apt_table[j].name);
if (rv)
display_pad_out("error %x", rv);
else
display_pad_out(apt_table[j].fmt, val);
display_pad_out("\n");
}
}
count = ipmi_pefconfig_get_num_alert_strings(pef_config);
display_pad_out(" num_alert_strings: %d\n", count);
for (i=0; i<count; i++) {
display_pad_out(" alert string %d:\n", i);
for (j=0; ask_table[j].name != NULL; j++) {
rv = ask_table[j].get(pef_config, i, &val);
display_pad_out(" %s: ", ask_table[j].name);
if (rv)
display_pad_out("error %x", rv);
else
display_pad_out(ask_table[j].fmt, val);
display_pad_out("\n");
}
len = sizeof(data);
rv = ipmi_pefconfig_get_alert_string(pef_config, i, data, &len);
if (rv)
display_pad_out(" alert_string: error %x\n", rv);
else
display_pad_out(" alert_string: '%s'\n", data);
}
}
void
readpef_getconf_handler(ipmi_pef_t *pef,
int err,
ipmi_pef_config_t *config,
void *cb_data)
{
if (err) {
ui_log("Error reading PEF config: %x\n", err);
return;
}
pef_config = config;
display_pef_config();
display_pad_refresh();
}
void
readpef_alloc_handler(ipmi_pef_t *lpef,
int err,
void *cb_data)
{
if (err) {
ui_log("Error allocating PEF: %x\n", err);
return;
}
if (!ipmi_pef_valid(lpef)) {
display_pad_out("PEF is not valid\n");
ipmi_pef_destroy(pef, NULL, NULL);
pef = NULL;
return;
}
pef = lpef;
display_pad_clear();
display_pef();
ipmi_pef_get_config(pef, readpef_getconf_handler, NULL);
}
void
readpef_mc_handler(ipmi_mc_t *mc, void *cb_data)
{
int rv;
mccmd_info_t *info = cb_data;
info->found = 1;
if (pef) {
ipmi_pef_destroy(pef, NULL, NULL);
pef = NULL;
}
if (pef_config) {
ipmi_pef_free_config(pef_config);
pef_config = NULL;
}
rv = ipmi_pef_alloc(mc, readpef_alloc_handler, NULL, NULL);
if (rv)
cmd_win_out("Error allocating PEF");
}
int
readpef_cmd(char *cmd, char **toks, void *cb_data)
{
mccmd_info_t info;
int rv;
if (get_mc_id(toks, &info.mc_id))
return 0;
info.found = 0;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, readpef_mc_handler, &info);
if (rv) {
cmd_win_out("Unable to find MC\n");
return 0;
}
if (!info.found) {
cmd_win_out("Unable to find MC (%d %x)\n",
info.mc_id.channel, info.mc_id.mc_num);
}
display_pad_refresh();
return 0;
}
int
viewpef_cmd(char *cmd, char **toks, void *cb_data)
{
display_pad_clear();
display_pef();
display_pef_config();
display_pad_refresh();
return 0;
}
void writepef_done(ipmi_pef_t *pef,
int err,
void *cb_data)
{
if (err)
ui_log("Error writing PEF: %x\n", err);
else
ui_log("PEF written\n");
}
int
writepef_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
if (!pef) {
cmd_win_out("No PEF to write\n");
return 0;
}
if (!pef_config) {
cmd_win_out("No PEF config to write\n");
return 0;
}
rv = ipmi_pef_set_config(pef, pef_config, writepef_done, NULL);
if (rv) {
cmd_win_out("Error writing pef parms: %x\n", rv);
}
return 0;
}
void clearpeflock_done(ipmi_pef_t *pef,
int err,
void *cb_data)
{
if (err)
ui_log("Error clearing PEF lock: %x\n", err);
else
ui_log("PEF lock cleared\n");
}
static void
clearpeflock_rsp_handler(ipmi_mc_t *src,
ipmi_msg_t *msg,
void *rsp_data)
{
if (msg->data[0])
ui_log("Error clearing PEF lock: %x\n",
IPMI_IPMI_ERR_VAL(msg->data[0]));
else
ui_log("PEF lock cleared\n");
}
void
clearpeflock_mc_handler(ipmi_mc_t *mc, void *cb_data)
{
mccmd_info_t *info = cb_data;
unsigned char data[2];
ipmi_msg_t msg;
int rv;
info->found = 1;
data[0] = 0;
data[1] = 0;
msg.netfn = IPMI_SENSOR_EVENT_NETFN;
msg.cmd = IPMI_SET_PEF_CONFIG_PARMS_CMD;
msg.data = data;
msg.data_len = 2;
rv = ipmi_mc_send_command(mc, 0, &msg, clearpeflock_rsp_handler,
NULL);
if (rv)
cmd_win_out("Send PEF clear lock failure: %x\n", rv);
}
int
clearpeflock_cmd(char *cmd, char **toks, void *cb_data)
{
mccmd_info_t info;
int rv;
char *mc_toks;
char buf[100];
char *ntoks;
mc_toks = strtok_r(NULL, "", toks);
if (mc_toks) {
strncpy(buf+2, mc_toks, sizeof(buf)-2);
buf[0] = 'a';
buf[1] = ' ';
strtok_r(buf, " ", &ntoks);
if (get_mc_id(&ntoks, &info.mc_id))
return 0;
info.found = 0;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, clearpeflock_mc_handler,
&info);
if (rv) {
cmd_win_out("Unable to find MC\n");
return 0;
}
if (!info.found) {
cmd_win_out("Unable to find MC (%d %x)\n",
info.mc_id.channel, info.mc_id.mc_num);
}
display_pad_refresh();
} else {
if (!pef) {
ui_log("No PEF to write\n");
return 0;
}
ipmi_pef_clear_lock(pef, pef_config, clearpeflock_done, NULL);
}
return 0;
}
typedef struct setpef_parm_s
{
char *name;
int (*set_val)(ipmi_pef_config_t *, unsigned int);
int (*set_data)(ipmi_pef_config_t *, unsigned char *, unsigned int);
int (*set_val_sel)(ipmi_pef_config_t *, unsigned int, unsigned int);
int (*set_data_sel)(ipmi_pef_config_t *, unsigned int,
unsigned char *, unsigned int);
} setpef_parm_t;
#define N NULL
#define D(x) #x
#define C(x) D(x)
#define H(x) ipmi_pefconfig_set_ ## x
#define G(x) H(x)
static setpef_parm_t pef_conf[] =
{
#undef V
#define V startup_delay_enabled
{ C(V), G(V), N, N, N },
#undef V
#define V alert_startup_delay_enabled
{ C(V), G(V), N, N, N },
#undef V
#define V event_messages_enabled
{ C(V), G(V), N, N, N },
#undef V
#define V pef_enabled
{ C(V), G(V), N, N, N },
#undef V
#define V diagnostic_interrupt_enabled
{ C(V), G(V), N, N, N },
#undef V
#define V oem_action_enabled
{ C(V), G(V), N, N, N },
#undef V
#define V power_cycle_enabled
{ C(V), G(V), N, N, N },
#undef V
#define V reset_enabled
{ C(V), G(V), N, N, N },
#undef V
#define V power_down_enabled
{ C(V), G(V), N, N, N },
#undef V
#define V alert_enabled
{ C(V), G(V), N, N, N },
#undef V
#define V startup_delay
{ C(V), G(V), N, N, N },
#undef V
#define V alert_startup_delay
{ C(V), G(V), N, N, N },
#undef V
#define V enable_filter
{ C(V), N, N, G(V), N },
#undef V
#define V filter_type
{ C(V), N, N, G(V), N },
#undef V
#define V diagnostic_interrupt
{ C(V), N, N, G(V), N },
#undef V
#define V oem_action
{ C(V), N, N, G(V), N },
#undef V
#define V power_cycle
{ C(V), N, N, G(V), N },
#undef V
#define V reset
{ C(V), N, N, G(V), N },
#undef V
#define V power_down
{ C(V), N, N, G(V), N },
#undef V
#define V alert
{ C(V), N, N, G(V), N },
#undef V
#define V alert_policy_number
{ C(V), N, N, G(V), N },
#undef V
#define V event_severity
{ C(V), N, N, G(V), N },
#undef V
#define V generator_id_addr
{ C(V), N, N, G(V), N },
#undef V
#define V generator_id_channel_lun
{ C(V), N, N, G(V), N },
#undef V
#define V sensor_type
{ C(V), N, N, G(V), N },
#undef V
#define V sensor_number
{ C(V), N, N, G(V), N },
#undef V
#define V event_trigger
{ C(V), N, N, G(V), N },
#undef V
#define V data1_offset_mask
{ C(V), N, N, G(V), N },
#undef V
#define V data1_mask
{ C(V), N, N, G(V), N },
#undef V
#define V data1_compare1
{ C(V), N, N, G(V), N },
#undef V
#define V data1_compare2
{ C(V), N, N, G(V), N },
#undef V
#define V data2_mask
{ C(V), N, N, G(V), N },
#undef V
#define V data2_compare1
{ C(V), N, N, G(V), N },
#undef V
#define V data2_compare2
{ C(V), N, N, G(V), N },
#undef V
#define V data3_mask
{ C(V), N, N, G(V), N },
#undef V
#define V data3_compare1
{ C(V), N, N, G(V), N },
#undef V
#define V data3_compare2
{ C(V), N, N, G(V), N },
#undef V
#define V policy_num
{ C(V), N, N, G(V), N },
#undef V
#define V enabled
{ C(V), N, N, G(V), N },
#undef V
#define V channel
{ C(V), N, N, G(V), N },
#undef V
#define V destination_selector
{ C(V), N, N, G(V), N },
#undef V
#define V alert_string_event_specific
{ C(V), N, N, G(V), N },
#undef V
#define V alert_string_selector
{ C(V), N, N, G(V), N },
#undef V
#define V event_filter
{ C(V), N, N, G(V), N },
#undef V
#define V alert_string_set
{ C(V), N, N, G(V), N },
{ NULL }
};
static int
setpef_cmd(char *cmd, char **toks, void *cb_data)
{
unsigned int sel;
unsigned int val;
unsigned char data[30];
char *name;
char *str;
unsigned int i;
int rv = 0;
if (!pef_config) {
cmd_win_out("No PEF config read, use readpef to fetch one\n");
return 0;
}
name = strtok_r(NULL, " \t\n", toks);
if (!name) {
cmd_win_out("No PEF config name given\n");
return 0;
}
for (i=0; pef_conf[i].name != NULL; i++) {
if (strcmp(pef_conf[i].name, name) == 0)
break;
}
if (pef_conf[i].name == NULL) {
if (strcmp(name, "guid") == 0) {
for (i=0; i<sizeof(data); i++) {
if (get_uchar(toks, data+i, NULL))
break;
}
rv = ipmi_pefconfig_set_guid(pef_config, (i != 0), data, i);
} else if (strcmp(name, "alert_string") == 0) {
if (get_uint(toks, &sel, "selector"))
return 0;
str = strtok_r(NULL, "", toks);
rv = ipmi_pefconfig_set_alert_string(pef_config, sel,
(unsigned char *) str);
} else {
cmd_win_out("Invalid PEF config name: '%s'\n", name);
return 0;
}
} else if (pef_conf[i].set_val) {
if (get_uint(toks, &val, "value"))
return 0;
rv = pef_conf[i].set_val(pef_config, val);
} else if (pef_conf[i].set_data) {
for (i=0; i<sizeof(data); i++) {
if (get_uchar(toks, data+i, NULL))
break;
}
rv = pef_conf[i].set_data(pef_config, data, i);
} else if (pef_conf[i].set_val_sel) {
if (get_uint(toks, &sel, "selector"))
return 0;
if (get_uint(toks, &val, "value"))
return 0;
rv = pef_conf[i].set_val_sel(pef_config, sel, val);
} else if (pef_conf[i].set_data_sel) {
if (get_uint(toks, &sel, "selector"))
return 0;
for (i=0; i<sizeof(data); i++) {
if (get_uchar(toks, data+i, NULL))
break;
}
rv = pef_conf[i].set_data_sel(pef_config, sel, data, i);
}
if (rv)
cmd_win_out("Error setting parm: 0x%x\n", rv);
return 0;
}
static void
lanparm_out_val(char *name, int rv, char *fmt, unsigned int val)
{
if (rv == ENOTSUP)
return;
display_pad_out(" %s: ", name);
if (rv)
display_pad_out("err %x", rv);
else
display_pad_out(fmt, val);
display_pad_out("\n");
}
static void
lanparm_out_data(char *name, int rv, unsigned char *data, int len)
{
int i;
if (rv == ENOTSUP)
return;
display_pad_out(" %s: ", name);
if (rv)
display_pad_out("err %x\n", rv);
else {
for (i=0; i<len; i++)
display_pad_out("%2.2x", data[i]);
display_pad_out("\n");
}
}
void
display_lanparm_config(void)
{
unsigned int i;
unsigned int val;
unsigned int len;
unsigned char data[128];
int rv;
unsigned int count;
if (!lanparm_config) {
display_pad_out("No LANPARM config read, use readlanparm to fetch one\n");
return;
}
display_pad_out("LAN parameters:");
display_pad_out(" auth supported:");
if (ipmi_lanconfig_get_support_auth_oem(lanparm_config))
display_pad_out(" oem");
if (ipmi_lanconfig_get_support_auth_straight(lanparm_config))
display_pad_out(" straight");
if (ipmi_lanconfig_get_support_auth_md5(lanparm_config))
display_pad_out(" md5");
if (ipmi_lanconfig_get_support_auth_md2(lanparm_config))
display_pad_out(" md2");
if (ipmi_lanconfig_get_support_auth_none(lanparm_config))
display_pad_out(" none");
display_pad_out("\n");
display_pad_out(" ip_addr_source: %d\n",
ipmi_lanconfig_get_ip_addr_source(lanparm_config));
rv = ipmi_lanconfig_get_ipv4_ttl(lanparm_config, &val);
lanparm_out_val("ipv4_ttl", rv, "%d", val);
rv = ipmi_lanconfig_get_ipv4_flags(lanparm_config, &val);
lanparm_out_val("ipv4_flags", rv, "%d", val);
rv = ipmi_lanconfig_get_ipv4_precedence(lanparm_config, &val);
lanparm_out_val("ipv4_precedence", rv, "%d", val);
rv = ipmi_lanconfig_get_ipv4_tos(lanparm_config, &val);
lanparm_out_val("ipv4_tos", rv, "%d", val);
for (i=0; i<5; i++) {
display_pad_out(" auth enabled (%d):", i);
rv = ipmi_lanconfig_get_enable_auth_oem(lanparm_config, i, &val);
if (rv)
display_pad_out(" oemerr%x", rv);
else if (val)
display_pad_out(" oem");
rv = ipmi_lanconfig_get_enable_auth_straight(lanparm_config, i, &val);
if (rv)
display_pad_out(" straighterr%x", rv);
else if (val)
display_pad_out(" straight");
rv = ipmi_lanconfig_get_enable_auth_md5(lanparm_config, i, &val);
if (rv)
display_pad_out(" md5err%x", rv);
else if (val)
display_pad_out(" md5");
rv = ipmi_lanconfig_get_enable_auth_md2(lanparm_config, i, &val);
if (rv)
display_pad_out(" md2err%x", rv);
else if (val)
display_pad_out(" md2");
rv = ipmi_lanconfig_get_enable_auth_none(lanparm_config, i, &val);
if (rv)
display_pad_out(" noneerr%x", rv);
else if (val)
display_pad_out(" none");
display_pad_out("\n");
}
len = 4;
rv = ipmi_lanconfig_get_ip_addr(lanparm_config, data, &len);
lanparm_out_data("ip_addr", rv, data, len);
len = 6;
rv = ipmi_lanconfig_get_mac_addr(lanparm_config, data, &len);
lanparm_out_data("mac_addr", rv, data, len);
len = 4;
rv = ipmi_lanconfig_get_subnet_mask(lanparm_config, data, &len);
lanparm_out_data("subnet_mask", rv, data, len);
len = 2;
rv = ipmi_lanconfig_get_primary_rmcp_port(lanparm_config, data, &len);
lanparm_out_data("primary_rmcp_port", rv, data, len);
len = 2;
rv = ipmi_lanconfig_get_secondary_rmcp_port(lanparm_config, data, &len);
lanparm_out_data("secondary_rmcp_port", rv, data, len);
rv = ipmi_lanconfig_get_bmc_generated_arps(lanparm_config, &val);
lanparm_out_val("bmc_generated_arps", rv, "%d", val);
rv = ipmi_lanconfig_get_bmc_generated_garps(lanparm_config, &val);
lanparm_out_val("bmc_generated_garps", rv, "%d", val);
rv = ipmi_lanconfig_get_garp_interval(lanparm_config, &val);
lanparm_out_val("garp_interval", rv, "%d", val);
len = 4;
rv = ipmi_lanconfig_get_default_gateway_ip_addr(lanparm_config, data, &len);
lanparm_out_data("default_gateway_ip_addr", rv, data, len);
len = 6;
rv = ipmi_lanconfig_get_default_gateway_mac_addr(lanparm_config, data, &len);
lanparm_out_data("default_gateway_mac_addr", rv, data, len);
len = 4;
rv = ipmi_lanconfig_get_backup_gateway_ip_addr(lanparm_config, data, &len);
lanparm_out_data("backup_gateway_ip_addr", rv, data, len);
len = 6;
rv = ipmi_lanconfig_get_backup_gateway_mac_addr(lanparm_config, data, &len);
lanparm_out_data("backup_gateway_mac_addr", rv, data, len);
len = 18;
rv = ipmi_lanconfig_get_community_string(lanparm_config, data, &len);
display_pad_out(" community_string: ");
if (rv)
display_pad_out("err: %x\n", rv);
else
display_pad_out("%s\n", data);
count = ipmi_lanconfig_get_num_alert_destinations(lanparm_config);
display_pad_out(" num_alert_destinations: %d\n", count);
for (i=0; i<count; i++) {
display_pad_out(" destination %d:\n", i);
rv = ipmi_lanconfig_get_alert_ack(lanparm_config, i, &val);
lanparm_out_val(" alert_ack", rv, "%d", val);
rv = ipmi_lanconfig_get_dest_type(lanparm_config, i, &val);
lanparm_out_val(" dest_type", rv, "%d", val);
rv = ipmi_lanconfig_get_alert_retry_interval(lanparm_config, i, &val);
lanparm_out_val(" alert_retry_interval", rv, "%d", val);
rv = ipmi_lanconfig_get_max_alert_retries(lanparm_config, i, &val);
lanparm_out_val(" max_alert_retries", rv, "%d", val);
rv = ipmi_lanconfig_get_dest_format(lanparm_config, i, &val);
lanparm_out_val(" dest_format", rv, "%d", val);
rv = ipmi_lanconfig_get_gw_to_use(lanparm_config, i, &val);
lanparm_out_val(" gw_to_use", rv, "%d", val);
len = 4;
rv = ipmi_lanconfig_get_dest_ip_addr(lanparm_config, i, data, &len);
lanparm_out_data(" dest_ip_addr", rv, data, len);
len = 6;
rv = ipmi_lanconfig_get_dest_mac_addr(lanparm_config, i, data, &len);
lanparm_out_data(" dest_mac_addr", rv, data, len);
}
}
typedef struct lanparm_info_s
{
ipmi_mcid_t mc_id;
unsigned char lun;
unsigned char channel;
ipmi_msg_t msg;
int found;
} lanparm_info_t;
void
readlanparm_getconf_handler(ipmi_lanparm_t *lanparm,
int err,
ipmi_lan_config_t *config,
void *cb_data)
{
if (err) {
ui_log("Error reading LANPARM config: %x\n", err);
return;
}
lanparm_config = config;
display_pad_clear();
display_lanparm_config();
display_pad_refresh();
}
void
readlanparm_mc_handler(ipmi_mc_t *mc, void *cb_data)
{
int rv;
lanparm_info_t *info = cb_data;
info->found = 1;
if (lanparm) {
ipmi_lanparm_destroy(lanparm, NULL, NULL);
lanparm = NULL;
}
if (lanparm_config) {
ipmi_lan_free_config(lanparm_config);
lanparm_config = NULL;
}
rv = ipmi_lanparm_alloc(mc, info->channel, &lanparm);
if (rv) {
cmd_win_out("failed lanparm allocation: %x\n", rv);
return;
}
rv = ipmi_lan_get_config(lanparm, readlanparm_getconf_handler, NULL);
}
int
readlanparm_cmd(char *cmd, char **toks, void *cb_data)
{
lanparm_info_t info;
int rv;
unsigned char val;
if (get_mc_id(toks, &info.mc_id))
return 0;
if (get_uchar(toks, &val, "lanparm channel"))
return 0;
info.channel = val;
info.found = 0;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, readlanparm_mc_handler, &info);
if (rv) {
cmd_win_out("Unable to find MC\n");
return 0;
}
if (!info.found) {
cmd_win_out("Unable to find MC (%d %x)\n",
info.mc_id.channel, info.mc_id.mc_num);
}
display_pad_refresh();
return 0;
}
int
viewlanparm_cmd(char *cmd, char **toks, void *cb_data)
{
display_pad_clear();
display_lanparm_config();
display_pad_refresh();
return 0;
}
void writelanparm_done(ipmi_lanparm_t *lanparm,
int err,
void *cb_data)
{
if (err)
ui_log("Error writing LANPARM: %x\n", err);
else
ui_log("LANPARM written\n");
}
int
writelanparm_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
if (!lanparm) {
cmd_win_out("No LANPARM to write\n");
return 0;
}
if (!lanparm_config) {
cmd_win_out("No LANPARM config to write\n");
return 0;
}
rv = ipmi_lan_set_config(lanparm, lanparm_config, writelanparm_done, NULL);
if (rv) {
cmd_win_out("Error writing lan parms: %x\n", rv);
}
return 0;
}
void clearlanparmlock_done(ipmi_lanparm_t *lanparm,
int err,
void *cb_data)
{
if (err)
ui_log("Error clearing LANPARM lock: %x\n", err);
else
ui_log("LANPARM lock cleared\n");
}
static void
clearlanparmlock_rsp_handler(ipmi_mc_t *src,
ipmi_msg_t *msg,
void *rsp_data)
{
if (msg->data[0])
ui_log("Error clearing LANPARM lock: %x\n",
IPMI_IPMI_ERR_VAL(msg->data[0]));
else
ui_log("LANPARM lock cleared\n");
}
void
clearlanparmlock_mc_handler(ipmi_mc_t *mc, void *cb_data)
{
lanparm_info_t *info = cb_data;
unsigned char data[3];
ipmi_msg_t msg;
int rv;
info->found = 1;
data[0] = info->channel;
data[1] = 0;
data[2] = 0;
msg.netfn = IPMI_TRANSPORT_NETFN;
msg.cmd = IPMI_SET_LAN_CONFIG_PARMS_CMD;
msg.data = data;
msg.data_len = 3;
rv = ipmi_mc_send_command(mc, 0, &msg, clearlanparmlock_rsp_handler,
NULL);
if (rv)
cmd_win_out("Send LANPARM clear lock failure: %x\n", rv);
}
int
clearlanparmlock_cmd(char *cmd, char **toks, void *cb_data)
{
lanparm_info_t info;
int rv;
char *mc_toks;
char buf[100];
char *ntoks;
unsigned char val;
mc_toks = strtok_r(NULL, "", toks);
if (mc_toks) {
strncpy(buf+2, mc_toks, sizeof(buf)-2);
buf[0] = 'a';
buf[1] = ' ';
strtok_r(buf, " ", &ntoks);
if (get_mc_id(&ntoks, &info.mc_id))
return 0;
if (get_uchar(&ntoks, &val, "lanparm channel"))
return 0;
info.channel = val;
info.found = 0;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, clearlanparmlock_mc_handler,
&info);
if (rv) {
cmd_win_out("Unable to find MC\n");
return 0;
}
if (!info.found) {
cmd_win_out("Unable to find MC (%d %x)\n",
info.mc_id.channel, info.mc_id.mc_num);
}
display_pad_refresh();
} else {
if (!lanparm) {
ui_log("No LANPARM to write\n");
return 0;
}
ipmi_lan_clear_lock(lanparm, lanparm_config,
clearlanparmlock_done, NULL);
}
return 0;
}
typedef struct setlan_parm_s
{
char *name;
int (*set_val)(ipmi_lan_config_t *, unsigned int);
int (*set_data)(ipmi_lan_config_t *, unsigned char *, unsigned int);
int (*set_val_sel)(ipmi_lan_config_t *, unsigned int, unsigned int);
int (*set_data_sel)(ipmi_lan_config_t *, unsigned int,
unsigned char *, unsigned int);
} setlan_parm_t;
#undef N
#define N NULL
#undef D
#define D(x) #x
#undef C
#define C(x) D(x)
#undef H
#define H(x) ipmi_lanconfig_set_ ## x
#undef G
#define G(x) H(x)
static setlan_parm_t lan_conf[] =
{
#undef V
#define V ip_addr_source
{ C(V), G(V), N, N, N },
#undef V
#define V ipv4_ttl
{ C(V), G(V), N, N, N },
#undef V
#define V ipv4_flags
{ C(V), G(V), N, N, N },
#undef V
#define V ipv4_precedence
{ C(V), G(V), N, N, N },
#undef V
#define V ipv4_tos
{ C(V), G(V), N, N, N },
#undef V
#define V enable_auth_oem
{ C(V), N, N, G(V), N },
#undef V
#define V enable_auth_straight
{ C(V), N, N, G(V), N },
#undef V
#define V enable_auth_md5
{ C(V), N, N, G(V), N },
#undef V
#define V enable_auth_md2
{ C(V), N, N, G(V), N },
#undef V
#define V enable_auth_none
{ C(V), N, N, G(V), N },
#undef V
#define V ip_addr
{ C(V), N, G(V), N, N },
#undef V
#define V mac_addr
{ C(V), N, G(V), N, N },
#undef V
#define V subnet_mask
{ C(V), N, G(V), N, N },
#undef V
#define V primary_rmcp_port
{ C(V), N, G(V), N, N },
#undef V
#define V secondary_rmcp_port
{ C(V), N, G(V), N, N },
#undef V
#define V bmc_generated_arps
{ C(V), G(V), N, N, N },
#undef V
#define V bmc_generated_garps
{ C(V), G(V), N, N, N },
#undef V
#define V garp_interval
{ C(V), G(V), N, N, N },
#undef V
#define V default_gateway_ip_addr
{ C(V), N, G(V), N, N },
#undef V
#define V default_gateway_mac_addr
{ C(V), N, G(V), N, N },
#undef V
#define V backup_gateway_ip_addr
{ C(V), N, G(V), N, N },
#undef V
#define V backup_gateway_mac_addr
{ C(V), N, G(V), N, N },
#undef V
#define V alert_ack
{ C(V), N, N, G(V), N },
#undef V
#define V dest_type
{ C(V), N, N, G(V), N },
#undef V
#define V alert_retry_interval
{ C(V), N, N, G(V), N },
#undef V
#define V max_alert_retries
{ C(V), N, N, G(V), N },
#undef V
#define V dest_format
{ C(V), N, N, G(V), N },
#undef V
#define V gw_to_use
{ C(V), N, N, G(V), N },
#undef V
#define V dest_ip_addr
{ C(V), N, N, N, G(V) },
#undef V
#define V dest_mac_addr
{ C(V), N, N, N, G(V) },
};
static int
setlanparm_cmd(char *cmd, char **toks, void *cb_data)
{
unsigned int sel;
unsigned int val;
unsigned char data[30];
char *name;
char *str;
unsigned int i, j;
int rv = 0;
if (!lanparm_config) {
cmd_win_out("No LAN config read, use readlan to fetch one\n");
return 0;
}
name = strtok_r(NULL, " \t\n", toks);
if (!name) {
cmd_win_out("No LAN config name given\n");
return 0;
}
for (i=0; lan_conf[i].name != NULL; i++) {
if (strcmp(lan_conf[i].name, name) == 0)
break;
}
if (lan_conf[i].name == NULL) {
if (strcmp(name, "community_string") == 0) {
if (get_uint(toks, &sel, "selector"))
return 0;
str = strtok_r(NULL, "", toks);
rv = ipmi_lanconfig_set_community_string(lanparm_config,
(unsigned char *) str,
strlen(str));
} else {
cmd_win_out("Invalid LAN config name: '%s'\n", name);
return 0;
}
} else if (lan_conf[i].set_val) {
if (get_uint(toks, &val, "value"))
return 0;
rv = lan_conf[i].set_val(lanparm_config, val);
} else if (lan_conf[i].set_data) {
for (j=0; j<sizeof(data); j++) {
if (get_uchar(toks, data+j, NULL))
break;
}
rv = lan_conf[i].set_data(lanparm_config, data, j);
} else if (lan_conf[i].set_val_sel) {
if (get_uint(toks, &sel, "selector"))
return 0;
if (get_uint(toks, &val, "value"))
return 0;
rv = lan_conf[i].set_val_sel(lanparm_config, sel, val);
} else if (lan_conf[i].set_data_sel) {
if (get_uint(toks, &sel, "selector"))
return 0;
for (j=0; j<sizeof(data); j++) {
if (get_uchar(toks, data+j, NULL))
break;
}
rv = lan_conf[i].set_data_sel(lanparm_config, sel, data, j);
}
if (rv)
cmd_win_out("Error setting parm: 0x%x\n", rv);
return 0;
}
static ipmi_pet_t *pet;
typedef struct pet_info_s
{
unsigned int connection;
unsigned int channel;
struct in_addr ip_addr;
unsigned char mac_addr[6];
unsigned int eft_sel;
unsigned int policy_num;
unsigned int apt_sel;
unsigned int lan_dest_sel;
} pet_info_t;
static void
pet_done(ipmi_pet_t *pet, int err, void *cb_data)
{
if (err)
ui_log("Error setting pet: %x\n", err);
else
ui_log("PET set");
}
static void
pet_domain_cb(ipmi_domain_t *domain, void *cb_data)
{
pet_info_t *info = cb_data;
int rv;
rv = ipmi_pet_create(domain,
info->connection,
info->channel,
info->ip_addr,
info->mac_addr,
info->eft_sel,
info->policy_num,
info->apt_sel,
info->lan_dest_sel,
pet_done,
NULL,
&pet);
if (rv)
cmd_win_out("Error creating PET: %x\n", rv);
}
static int
pet_cmd(char *cmd, char **toks, void *cb_data)
{
pet_info_t info;
int rv;
if (pet) {
ipmi_pet_destroy(pet, NULL, NULL);
pet = NULL;
}
if (get_uint(toks, &info.connection, "connection"))
return 0;
if (get_uint(toks, &info.channel, "channel"))
return 0;
if (get_ip_addr(toks, &info.ip_addr, "IP address"))
return 0;
if (get_mac_addr(toks, info.mac_addr, "MAC address"))
return 0;
if (get_uint(toks, &info.eft_sel, "eft selector"))
return 0;
if (get_uint(toks, &info.policy_num, "policy_num"))
return 0;
if (get_uint(toks, &info.apt_sel, "apt selector"))
return 0;
if (get_uint(toks, &info.lan_dest_sel, "LAN dest selector"))
return 0;
rv = ipmi_domain_pointer_cb(domain_id, pet_domain_cb, &info);
if (rv)
cmd_win_out("Error converting domain");
return 0;
}
typedef struct msg_cmd_data_s
{
unsigned char data[MCCMD_DATA_SIZE];
unsigned int data_len;
ipmi_ipmb_addr_t addr;
ipmi_msg_t msg;
} msg_cmd_data_t;
static int
mccmd_addr_rsp_handler(ipmi_domain_t *domain, ipmi_msgi_t *rspi)
{
ipmi_msg_t *msg = &rspi->msg;
unsigned int i;
unsigned char *data;
display_pad_clear();
curr_display_type = DISPLAY_RSP;
display_pad_out("Response:\n");
display_pad_out(" NetFN = 0x%2.2x\n", msg->netfn);
display_pad_out(" Command = 0x%2.2x\n", msg->cmd);
display_pad_out(" Completion code = 0x%2.2x\n", msg->data[0]);
display_pad_out(" data =");
data = msg->data + 1;
for (i=0; i+1<msg->data_len; i++) {
if ((i != 0) && ((i % 8) == 0))
display_pad_out("\n ");
display_pad_out(" %2.2x", data[i]);
}
display_pad_out("\n");
display_pad_refresh();
return IPMI_MSG_ITEM_NOT_USED;
}
static void
msg_cmder(ipmi_domain_t *domain, void *cb_data)
{
msg_cmd_data_t *info = cb_data;
int rv;
rv = ipmi_send_command_addr(domain,
(ipmi_addr_t *) &(info->addr),
sizeof(info->addr),
&info->msg,
mccmd_addr_rsp_handler,
NULL, NULL);
if (rv)
cmd_win_out("Send command failure: %x\n", rv);
}
static int
msg_cmd(char *cmd, char **toks, void *cb_data)
{
msg_cmd_data_t info;
unsigned int channel;
int rv;
info.addr.addr_type = IPMI_IPMB_ADDR_TYPE;
if (get_uint(toks, &channel, "channel"))
return 0;
info.addr.channel = channel;
if (get_uchar(toks, &info.addr.slave_addr, "slave address"))
return 0;
if (info.addr.slave_addr == 0) {
info.addr.addr_type = IPMI_IPMB_BROADCAST_ADDR_TYPE;
if (get_uchar(toks, &info.addr.slave_addr, "slave address"))
return 0;
}
if (get_uchar(toks, &info.addr.lun, "LUN"))
return 0;
if (get_uchar(toks, &info.msg.netfn, "NetFN"))
return 0;
if (get_uchar(toks, &info.msg.cmd, "command"))
return 0;
for (info.data_len=0; ; info.data_len++) {
if (get_uchar(toks, info.data+info.data_len, NULL))
break;
}
info.msg.data_len = info.data_len;
info.msg.data = info.data;
rv = ipmi_domain_pointer_cb(domain_id, msg_cmder, &info);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
display_pad_refresh();
return 0;
}
static void
set_control(ipmi_control_t *control, void *cb_data)
{
char **toks = cb_data;
int num_vals;
int i;
int *vals = NULL;
unsigned char *cvals = NULL;
char *tok;
char *estr;
int rv;
int control_type;
control_type = ipmi_control_get_type(control);
switch (control_type) {
case IPMI_CONTROL_LIGHT:
if (ipmi_control_light_set_with_setting(control)) {
ipmi_light_setting_t *setting;
num_vals = ipmi_control_get_num_vals(control);
setting = ipmi_alloc_light_settings(num_vals);
if (!setting) {
cmd_win_out("set_control: out of memory\n");
goto out;
}
for (i=0; i<num_vals; i++) {
unsigned int val;
if (get_uint(toks, &val, "light color"))
goto out_free_light;
ipmi_light_setting_set_color(setting, i, val);
if (get_uint(toks, &val, "light on time"))
goto out_free_light;
ipmi_light_setting_set_on_time(setting, i, val);
if (get_uint(toks, &val, "light off time"))
goto out_free_light;
ipmi_light_setting_set_off_time(setting, i, val);
if (get_uint(toks, &val, "local control"))
goto out_free_light;
ipmi_light_setting_set_local_control(setting, i, val);
}
rv = ipmi_control_set_light(control, setting, NULL, NULL);
if (rv) {
cmd_win_out("set_control: Returned error 0x%x\n", rv);
}
out_free_light:
ipmi_free_light_settings(setting);
break;
}
/* FALLTHRU */
case IPMI_CONTROL_RELAY:
case IPMI_CONTROL_ALARM:
case IPMI_CONTROL_RESET:
case IPMI_CONTROL_ONE_SHOT_RESET:
case IPMI_CONTROL_POWER:
case IPMI_CONTROL_FAN_SPEED:
case IPMI_CONTROL_OUTPUT:
case IPMI_CONTROL_ONE_SHOT_OUTPUT:
num_vals = ipmi_control_get_num_vals(control);
vals = ipmi_mem_alloc(sizeof(*vals) * num_vals);
if (!vals) {
cmd_win_out("set_control: out of memory\n");
goto out;
}
for (i=0; i<num_vals; i++) {
tok = strtok_r(NULL, " \t\n", toks);
if (!tok) {
cmd_win_out("set_control: Value %d is not present\n", i);
goto out_bcon;
}
vals[i] = strtol(tok, &estr, 0);
if (*estr != '\0') {
cmd_win_out("set_control: Value %d is invalid\n", i);
goto out_bcon;
}
}
rv = ipmi_control_set_val(control, vals, NULL, NULL);
if (rv) {
cmd_win_out("set_control: Returned error 0x%x\n", rv);
}
out_bcon:
break;
case IPMI_CONTROL_DISPLAY:
break;
case IPMI_CONTROL_IDENTIFIER:
num_vals = ipmi_control_identifier_get_max_length(control);
cvals = ipmi_mem_alloc(sizeof(*cvals) * num_vals);
if (!cvals) {
cmd_win_out("set_control: out of memory\n");
goto out;
}
for (i=0; i<num_vals; i++) {
tok = strtok_r(NULL, " \t\n", toks);
if (!tok) {
cmd_win_out("set_control: Value %d is not present\n", i);
goto out;
}
cvals[i] = strtol(tok, &estr, 0);
if (*estr != '\0') {
cmd_win_out("set_control: Value %d is invalid\n", i);
goto out;
}
}
rv = ipmi_control_identifier_set_val(control, cvals, num_vals,
NULL, NULL);
if (rv) {
cmd_win_out("set_control: Returned error 0x%x\n", rv);
}
break;
}
out:
if (vals)
ipmi_mem_free(vals);
if (cvals)
ipmi_mem_free(cvals);
}
static int
set_control_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
if (curr_display_type != DISPLAY_CONTROL) {
cmd_win_out("The current displayed item is not a control\n");
goto out;
}
rv = ipmi_control_pointer_cb(curr_control_id, set_control, toks);
if (rv)
cmd_win_out("set_control: Unable to get control pointer: 0x%x\n", rv);
out:
return 0;
}
static void
delevent_cb(ipmi_domain_t *domain, int err, void *cb_data)
{
if (err)
ui_log("Error deleting log: %x\n", err);
else
ui_log("log deleted\n");
}
typedef struct delevent_info_s
{
ipmi_mcid_t mc_id;
unsigned int record_id;
int rv;
} delevent_info_t;
static void
delevent_cmder(ipmi_domain_t *domain, void *cb_data)
{
int rv;
delevent_info_t *info = cb_data;
ipmi_event_t *event, *n;
int found = 0;
info->mc_id.domain_id = domain_id;
event = ipmi_domain_first_event(domain);
while (event) {
if ((ipmi_cmp_mc_id_noseq(ipmi_event_get_mcid(event),info->mc_id) == 0)
&& (ipmi_event_get_record_id(event) == info->record_id))
{
rv = ipmi_domain_del_event(domain, event, delevent_cb, NULL);
if (rv)
cmd_win_out("error deleting log: %x\n", rv);
ipmi_event_free(event);
found = 1;
break;
} else {
n = ipmi_domain_next_event(domain, event);
ipmi_event_free(event);
event = n;
}
}
if (!found)
cmd_win_out("log not found\n");
}
static int
delevent_cmd(char *cmd, char **toks, void *cb_data)
{
delevent_info_t info;
int rv;
if (get_mc_id(toks, &info.mc_id))
return 0;
if (get_uint(toks, &info.record_id, "record id"))
return 0;
rv = ipmi_domain_pointer_cb(domain_id, delevent_cmder, &info);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
return 0;
}
static void
addevent_cb(ipmi_mc_t *mc, unsigned int record_id, int err, void *cb_data)
{
if (err)
ui_log("Error adding event: %x\n", err);
else
ui_log("event 0x%4.4x added\n", record_id);
}
typedef struct addevent_info_s
{
ipmi_mcid_t mc_id;
unsigned int record_id;
unsigned int type;
ipmi_time_t timestamp;
unsigned char data[13];
} addevent_info_t;
static void
addevent_cmder(ipmi_mc_t *mc, void *cb_data)
{
int rv;
addevent_info_t *info = cb_data;
ipmi_event_t *event;
event = ipmi_event_alloc(ipmi_mc_convert_to_id(mc),
info->record_id,
info->type,
info->timestamp,
info->data,
13);
if (!event) {
cmd_win_out("Could not allocate event\n");
return;
}
rv = ipmi_mc_add_event_to_sel(mc, event, addevent_cb, NULL);
if (rv)
cmd_win_out("Unable to send add event: %x\n", rv);
ipmi_event_free(event);
}
static int
addevent_cmd(char *cmd, char **toks, void *cb_data)
{
addevent_info_t info;
int rv;
int i;
struct timeval time;
if (get_mc_id(toks, &info.mc_id))
return 0;
if (get_uint(toks, &info.record_id, "record id"))
return 0;
if (get_uint(toks, &info.type, "record type"))
return 0;
for (i=0; i<13; i++) {
if (get_uchar(toks, &info.data[i], "data"))
return 0;
}
gettimeofday(&time, NULL);
info.timestamp = time.tv_sec * 1000000000;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, addevent_cmder, &info);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
return 0;
}
static int
debug_cmd(char *cmd, char **toks, void *cb_data)
{
char *type;
char *on_off;
int val;
type = strtok_r(NULL, " \t\n", toks);
if (!type) {
cmd_win_out("No debug type specified\n");
goto out;
}
on_off = strtok_r(NULL, " \t\n", toks);
if (!on_off) {
cmd_win_out("on or off not specified\n");
goto out;
} else if (strcmp(on_off, "on") == 0) {
val = 1;
} else if (strcmp(on_off, "off") == 0) {
val = 0;
} else {
cmd_win_out("on or off not specified, got '%s'\n", on_off);
goto out;
}
if (strcmp(type, "msg") == 0) {
if (val) DEBUG_MSG_ENABLE(); else DEBUG_MSG_DISABLE();
} else if (strcmp(type, "rawmsg") == 0) {
if (val) DEBUG_RAWMSG_ENABLE(); else DEBUG_RAWMSG_DISABLE();
} else if (strcmp(type, "locks") == 0) {
if (val) DEBUG_LOCKS_ENABLE(); else DEBUG_LOCKS_DISABLE();
} else if (strcmp(type, "events") == 0) {
if (val) DEBUG_EVENTS_ENABLE(); else DEBUG_EVENTS_DISABLE();
} else if (strcmp(type, "con0") == 0) {
if (val) DEBUG_CON_FAIL_ENABLE(0); else DEBUG_CON_FAIL_DISABLE(0);
} else if (strcmp(type, "con1") == 0) {
if (val) DEBUG_CON_FAIL_ENABLE(1); else DEBUG_CON_FAIL_DISABLE(1);
} else if (strcmp(type, "con2") == 0) {
if (val) DEBUG_CON_FAIL_ENABLE(2); else DEBUG_CON_FAIL_DISABLE(2);
} else if (strcmp(type, "con3") == 0) {
if (val) DEBUG_CON_FAIL_ENABLE(3); else DEBUG_CON_FAIL_DISABLE(3);
} else {
cmd_win_out("Invalid debug type specified: '%s'\n", type);
goto out;
}
out:
return 0;
}
static void
clear_sel_cmder(ipmi_domain_t *domain, void *cb_data)
{
ipmi_event_t *event, *event2;
event = ipmi_domain_first_event(domain);
while (event) {
event2 = event;
event = ipmi_domain_next_event(domain, event2);
ipmi_domain_del_event(domain, event2, NULL, NULL);
ipmi_event_free(event2);
}
}
static int
clear_sel_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
rv = ipmi_domain_pointer_cb(domain_id, clear_sel_cmder, NULL);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
return 0;
}
static void
list_sel_cmder(ipmi_domain_t *domain, void *cb_data)
{
int rv;
ipmi_event_t *event, *event2;
unsigned int count1, count2;
curr_display_type = EVENTS;
display_pad_clear();
rv = ipmi_domain_sel_count(domain, &count1);
if (rv)
count1 = -1;
rv = ipmi_domain_sel_entries_used(domain, &count2);
if (rv)
count2 = -1;
display_pad_out("Event counts: %d entries, %d slots used\n",
count1, count2);
display_pad_out("Events:\n");
event = ipmi_domain_first_event(domain);
while (event) {
ipmi_mcid_t mcid = ipmi_event_get_mcid(event);
unsigned int record_id = ipmi_event_get_record_id(event);
unsigned int type = ipmi_event_get_type(event);
ipmi_time_t timestamp = ipmi_event_get_timestamp(event);
unsigned int data_len = ipmi_event_get_data_len(event);
const unsigned char *data = ipmi_event_get_data_ptr(event);
unsigned int i;
display_pad_out(" (%x %x) %4.4x:%2.2x %lld:",
mcid.channel, mcid.mc_num, record_id, type, timestamp);
for (i=0; i<data_len; i++)
display_pad_out(" %2.2x", data[i]);
display_pad_out("\n");
event2 = ipmi_domain_next_event(domain, event);
ipmi_event_free(event);
event = event2;
}
display_pad_refresh();
}
static int
list_sel_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
rv = ipmi_domain_pointer_cb(domain_id, list_sel_cmder, NULL);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
return 0;
}
void
sel_time_fetched(ipmi_mc_t *mc,
int err,
unsigned long time,
void *cb_data)
{
if (!mc) {
display_pad_out("MC went away while fetching SEL time\n");
goto out;
}
if (err) {
display_pad_out("Error fetching SEL time: %x\n", err);
goto out;
}
display_pad_out("SEL time is 0x%x\n", time);
out:
display_pad_refresh();
}
void get_sel_time_handler(ipmi_mc_t *mc, void *cb_data)
{
mccmd_info_t *info = cb_data;
int rv;
info->found = 1;
rv = ipmi_mc_get_current_sel_time(mc, sel_time_fetched, NULL);
if (rv)
cmd_win_out("Error sending SEL time fetch: %x\n", rv);
}
int
get_sel_time_cmd(char *cmd, char **toks, void *cb_data)
{
mccmd_info_t info;
int rv;
if (get_mc_id(toks, &info.mc_id))
return 0;
info.found = 0;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, get_sel_time_handler, &info);
if (rv) {
cmd_win_out("Unable to find MC\n");
return 0;
}
if (!info.found) {
cmd_win_out("Unable to find MC (%d %x)\n",
info.mc_id.channel, info.mc_id.mc_num);
}
display_pad_refresh();
return 0;
}
static void
mc_reset_done(ipmi_mc_t *mc, int err, void *cb_data)
{
if (err)
ui_log("Error resetting mc: %x", err);
else
ui_log("MC reset");
}
static void
mc_reset_handler(ipmi_mc_t *mc, void *cb_data)
{
mccmd_info_t *info = cb_data;
int rv;
info->found = 1;
rv = ipmi_mc_reset(mc, info->msg.cmd, mc_reset_done, NULL);
if (rv)
cmd_win_out("Error sending MC reset: %x\n", rv);
}
static int
mc_reset_cmd(char *cmd, char **toks, void *cb_data)
{
mccmd_info_t info;
int rv;
char *type;
if (get_mc_id(toks, &info.mc_id))
return 0;
type = strtok_r(NULL, " \n\t", toks);
if (!type) {
cmd_win_out("No reset type given, must be 'cold' or 'warm'\n");
return 0;
}
if (strcmp(type, "warm") == 0) {
info.msg.cmd = IPMI_MC_RESET_WARM;
} else if (strcmp(type, "cold") == 0) {
info.msg.cmd = IPMI_MC_RESET_COLD;
} else {
cmd_win_out("Invalid reset type given, must be 'cold' or 'warm'\n");
return 0;
}
info.found = 0;
rv = ipmi_mc_pointer_noseq_cb(info.mc_id, mc_reset_handler, &info);
if (rv) {
cmd_win_out("Unable to find MC\n");
return 0;
}
if (!info.found) {
cmd_win_out("Unable to find MC (%d %x)\n",
info.mc_id.channel, info.mc_id.mc_num);
}
display_pad_refresh();
return 0;
}
typedef struct sdrs_info_s
{
int found;
ipmi_mcid_t mc_id;
unsigned char do_sensors;
} sdrs_info_t;
void sdrs_fetched(ipmi_sdr_info_t *sdrs,
int err,
int changed,
unsigned int count,
void *cb_data)
{
sdrs_info_t *info = cb_data;
unsigned int i;
int rv;
int total_size = 0;
if (err) {
ui_log("Error fetching sdrs: %x\n", err);
goto out;
}
if (!sdrs) {
ui_log("sdrs went away during fetch\n");
goto out;
}
display_pad_clear();
curr_display_type = DISPLAY_SDRS;
display_pad_out("%s SDRs for MC (%x %x)\n",
info->do_sensors ? "device" : "main",
info->mc_id.channel, info->mc_id.mc_num);
for (i=0; i<count; i++) {
ipmi_sdr_t sdr;
int j;
rv = ipmi_get_sdr_by_index(sdrs, i, &sdr);
if (rv) {
display_pad_out("*could not get index %d\n", i);
continue;
}
total_size += sdr.length+5;
display_pad_out("%4.4x: type %x, version %d.%d",
sdr.record_id, sdr.type, sdr.major_version, sdr.minor_version);
for (j=0; j<sdr.length; j++) {
if ((j % 8) == 0)
display_pad_out("\n ");
display_pad_out(" %2.2x", sdr.data[j]);
}
display_pad_out("\n");
}
display_pad_out("total bytes in SDRs: %d\n", total_size);
display_pad_refresh();
out:
ipmi_sdr_info_destroy(sdrs, NULL, NULL);
ipmi_mem_free(info);
}
void
start_sdr_dump(ipmi_mc_t *mc, sdrs_info_t *info)
{
ipmi_sdr_info_t *sdrs;
int rv;
rv = ipmi_sdr_info_alloc(ipmi_mc_get_domain(mc),
mc, 0, info->do_sensors, &sdrs);
if (rv) {
cmd_win_out("Unable to alloc sdr info: %x\n", rv);
ipmi_mem_free(info);
return;
}
rv = ipmi_sdr_fetch(sdrs, sdrs_fetched, info);
if (rv) {
cmd_win_out("Unable to start SDR fetch: %x\n", rv);
ipmi_sdr_info_destroy(sdrs, NULL, NULL);
ipmi_mem_free(info);
return;
}
}
void
sdrs_mcs_handler(ipmi_mc_t *mc,
void *cb_data)
{
sdrs_info_t *info = cb_data;
info->found = 1;
start_sdr_dump(mc, info);
}
static int
sdrs_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
sdrs_info_t *info;
info = ipmi_mem_alloc(sizeof(*info));
if (!info) {
ui_log("Could not allocate memory for SDR fetch\n");
return 0;
}
if (get_mc_id(toks, &info->mc_id)) {
ipmi_mem_free(info);
return 0;
}
if (get_uchar(toks, &info->do_sensors, "do_sensors")) {
ipmi_mem_free(info);
return 0;
}
info->found = 0;
rv = ipmi_mc_pointer_noseq_cb(info->mc_id, sdrs_mcs_handler, info);
if (rv) {
cmd_win_out("Unable to find MC\n");
ipmi_mem_free(info);
} else {
if (!info->found) {
cmd_win_out("Unable to find that mc\n");
ipmi_mem_free(info);
}
}
return 0;
}
typedef struct scan_cmd_info_s
{
unsigned char addr;
unsigned char channel;
} scan_cmd_info_t;
void scan_done(ipmi_domain_t *domain, int err, void *cb_data)
{
log_pad_out("Bus scan done\n");
}
static void
scan_cmder(ipmi_domain_t *domain, void *cb_data)
{
scan_cmd_info_t *info = cb_data;
ipmi_start_ipmb_mc_scan(domain, info->channel,
info->addr, info->addr,
scan_done, NULL);
}
static int
scan_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
scan_cmd_info_t info;
if (get_uchar(toks, &info.channel, "channel"))
return 0;
if (get_uchar(toks, &info.addr, "IPMB address"))
return 0;
rv = ipmi_domain_pointer_cb(domain_id, scan_cmder, &info);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
}
return 0;
}
static void
presence_cmder(ipmi_domain_t *domain, void *cb_data)
{
int rv;
rv = ipmi_detect_domain_presence_changes(domain, 1);
if (rv)
cmd_win_out("domain presence detect error: %x\n", rv);
}
int
presence_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
rv = ipmi_domain_pointer_cb(domain_id, presence_cmder, NULL);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
return 0;
}
static void
is_con_active_cmder(ipmi_domain_t *domain, void *cb_data)
{
int rv;
unsigned int *connection = cb_data;
unsigned int val;
rv = ipmi_domain_is_connection_active(domain, *connection, &val);
if (rv)
cmd_win_out("Invalid connection number %d: %x\n", *connection, rv);
else
cmd_win_out("Connection %d is%s active\n",
*connection, val ? "" : " not");
}
static int
is_con_active_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
unsigned int connection;
if (get_uint(toks, &connection, "connection"))
return 0;
rv = ipmi_domain_pointer_cb(domain_id, is_con_active_cmder, &connection);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
return 0;
}
static void
activate_con_cmder(ipmi_domain_t *domain, void *cb_data)
{
int rv;
unsigned int *connection = cb_data;
rv = ipmi_domain_activate_connection(domain, *connection);
if (rv)
cmd_win_out("Invalid connection number %d: %x\n", *connection, rv);
}
static int
activate_con_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
unsigned int connection;
if (get_uint(toks, &connection, "connection"))
return 0;
rv = ipmi_domain_pointer_cb(domain_id, activate_con_cmder, &connection);
if (rv) {
cmd_win_out("Unable to convert domain id to a pointer\n");
return 0;
}
return 0;
}
static int
quit_cmd(char *cmd, char **toks, void *cb_data)
{
int rv;
rv = ipmi_domain_pointer_cb(domain_id, leave_cmder, NULL);
if (rv) {
leave(0, "");
}
return 0;
}
static int
display_win_cmd(char *cmd, char **toks, void *cb_data)
{
curr_win = DISPLAY_WIN_SCROLL;
return 0;
}
static int
log_win_cmd(char *cmd, char **toks, void *cb_data)
{
curr_win = LOG_WIN_SCROLL;
return 0;
}
static int
new_domain_cmd(char *cmd, char **toks, void *cb_data)
{
char *parms[30];
int num_parms;
int curr_parm;
ipmi_args_t *con_parms[2];
int set = 0;
int i;
ipmi_con_t *con[2];
int rv;
for (num_parms=0; num_parms<30; num_parms++) {
parms[num_parms] = strtok_r(NULL, " \t\n", toks);
if (!parms[num_parms])
break;
/* Remove surrounding quotes, if any. */
if (parms[num_parms][0] == '"') {
(parms[num_parms])++;
if (parms[num_parms][0])
parms[num_parms][strlen(parms[num_parms])-1] = '\0';
}
}
if (num_parms < 2) {
cmd_win_out("Not enough parms given\n");
return 0;
}
curr_parm = 1;
rv = ipmi_parse_args(&curr_parm, num_parms, parms, &con_parms[set]);
if (rv) {
cmd_win_out("First connection parms are invalid\n");
return 0;
}
set++;
if (curr_parm > num_parms) {
rv = ipmi_parse_args(&curr_parm, num_parms, parms, &con_parms[set]);
if (rv) {
ipmi_free_args(con_parms[0]);
cmd_win_out("Second connection parms are invalid\n");
goto out;
}
set++;
}
for (i=0; i<set; i++) {
rv = ipmi_args_setup_con(con_parms[i],
&ipmi_ui_cb_handlers,
ui_sel,
&con[i]);
if (rv) {
cmd_win_out("ipmi_ip_setup_con: %s\n", strerror(rv));
goto out;
}
}
rv = ipmi_open_domain(parms[0], con, set, ipmi_ui_setup_done,
NULL, NULL, NULL, NULL, 0, NULL);
if (rv) {
cmd_win_out("ipmi_open_domain: %s\n", strerror(rv));
for (i=0; i<set; i++)
con[i]->close_connection(con[i]);
goto out;
}
cmd_win_out("Domain started\n");
out:
for (i=0; i<set; i++)
ipmi_free_args(con_parms[i]);
return 0;
}
static void
final_close(void *cb_data)
{
ui_log("Domain close");
}
typedef struct domain_scan_s
{
int err;
char *name;
} domain_scan_t;
static void
close_domain_handler(ipmi_domain_t *domain, void *cb_data)
{
domain_scan_t *info = cb_data;
char name[IPMI_DOMAIN_NAME_LEN];
ipmi_domain_get_name(domain, name, sizeof(name));
if (strcmp(name, info->name) == 0) {
/* Found it. */
info->err = ipmi_domain_close(domain, final_close, NULL);
if (info->err)
cmd_win_out("Could not close connection\n");
}
}
static int
close_domain_cmd(char *cmd, char **toks, void *cb_data)
{
domain_scan_t info;
info.err = ENODEV;
info.name = strtok_r(NULL, " \t\n", toks);
if (!info.name) {
cmd_win_out("No domain given\n");
return 0;
}
ipmi_domain_iterate_domains(close_domain_handler, &info);
return 0;
}
static void
set_domain_handler(ipmi_domain_t *domain, void *cb_data)
{
domain_scan_t *info = cb_data;
char name[IPMI_DOMAIN_NAME_LEN];
ipmi_domain_get_name(domain, name, sizeof(name));
if (strcmp(name, info->name) == 0) {
/* Found it. */
info->err = 0;
domain_id = ipmi_domain_convert_to_id(domain);
}
}
static int
set_domain_cmd(char *cmd, char **toks, void *cb_data)
{
domain_scan_t info;
info.err = ENODEV;
info.name = strtok_r(NULL, " \t\n", toks);
if (!info.name) {
cmd_win_out("No domain given\n");
return 0;
}
ipmi_domain_iterate_domains(set_domain_handler, &info);
if (info.err)
cmd_win_out("Error setting domain: 0x%x\n", info.err);
return 0;
}
static void
domains_handler(ipmi_domain_t *domain, void *cb_data)
{
char name[IPMI_DOMAIN_NAME_LEN];
ipmi_domain_get_name(domain, name, sizeof(name));
display_pad_out(" %s\n", name);
}
static int
domains_cmd(char *cmd, char **toks, void *cb_data)
{
display_pad_clear();
display_pad_out("Domains:\n");
ipmi_domain_iterate_domains(domains_handler, NULL);
display_pad_refresh();
return 0;
}
static int help_cmd(char *cmd, char **toks, void *cb_data);
static struct {
char *name;
cmd_handler_t handler;
char *help;
} cmd_list[] =
{
{ "display_win", display_win_cmd,
" - Sets the display window (left window) for scrolling" },
{ "log_win", log_win_cmd,
" - Sets the log window (right window) for scrolling" },
{ "entities", entities_cmd,
" - list all the entities the UI knows about" },
{ "entity", entity_cmd,
" <entity name> - list all the info about an entity" },
{ "hs_get_act_time", hs_get_act_time,
" <entity name>"
" - Get the host-swap auto-activate time" },
{ "hs_set_act_time", hs_set_act_time,
" <entity name> <time in nanoseconds>"
" - Set the host-swap auto-activate time" },
{ "hs_get_deact_time", hs_get_deact_time,
" <entity name>"
" - Get the host-swap auto-deactivate time" },
{ "hs_set_deact_time", hs_set_deact_time,
" <entity name> <time in nanoseconds>"
" - Set the host-swap auto-deactivate time" },
{ "hs_activation_request", hs_activation_request,
" <entity name> - Act like a user requested an activation of the"
" entity. This is generally equivalent to closing the handle"
" latch or something like that." },
{ "hs_activate", hs_activate,
" <entity name> - activate the given entity" },
{ "hs_deactivate", hs_deactivate,
" <entity name> - deactivate the given entity" },
{ "hs_state", hs_state,
" <entity name> - Return the current hot-swap state" },
{ "hs_check", hs_check_cmd,
" - Check all the entities hot-swap states" },
{ "sensors", sensors_cmd,
" <entity name> - list all the sensors that monitor the entity" },
{ "sensor", sensor_cmd,
" <sensor name> - Pull up all the information on the sensor and start"
" monitoring it" },
{ "fru", fru_cmd,
" <entity name> - dump fru information" },
{ "dump_fru", dump_fru_cmd,
" <is_logical> <device_address> <device_id> <lun> <private_bus>"
" <channel> - dump a fru given all it's insundry information" },
{ "rearm", rearm_cmd,
" - rearm the current sensor" },
{ "set_hysteresis", set_hysteresis_cmd,
" <val> - Sets the hysteresis for the current sensor" },
{ "get_hysteresis", get_hysteresis_cmd,
" - Gets the hysteresis for the current sensor" },
{ "controls", controls_cmd,
" <entity name> - list all the controls attached to the entity" },
{ "control", control_cmd,
" <control name> - Pull up all the information on the control and start"
" monitoring it" },
{ "set_control", set_control_cmd,
" <val1> [<val2> ...] - set the value(s) for the control" },
{ "mcs", mcs_cmd,
" - List all the management controllers in the system. They"
" are listed (<channel>, <mc num>)" },
{ "mc", mc_cmd,
" <channel> <mc num>"
" - Dump info on the given MC"},
{ "mc_reset", mc_reset_cmd,
" <channel> <mc num> [warm | cold]"
" - Do a warm or cold reset on the given MC"},
{ "mccmd", mccmd_cmd,
" <channel> <mc num> <LUN> <NetFN> <Cmd> [data...]"
" - Send the given command"
" to the management controller and display the response" },
{ "mc_events_enable", mc_events_enable_cmd,
" <channel> <mc num> <enabled> - set enabled to 0 to disable events,"
" 1 to enable them. This is the global event enable on the MC." },
{ "mc_events_enabled", mc_events_enabled_cmd,
" <channel> <mc num> - Prints out if the events are enabled for"
" the given MC." },
{ "msg", msg_cmd,
" <channel> <IPMB addr> <LUN> <NetFN> <Cmd> [data...] - Send a command"
" to the given IPMB address on the given channel and display the"
" response" },
{ "readpef", readpef_cmd,
" <channel> <mc num>"
" - read pef information from an MC" },
{ "clearpeflock", clearpeflock_cmd,
" [<channel> <mc num>]"
" - Clear a PEF lock. If the MC is given, then the PEF is directly"
" cleared. If not given, then the current PEF is cleared" },
{ "viewpef", viewpef_cmd,
" - show current pef information " },
{ "writepef", writepef_cmd,
" <channel> <mc num>"
" - write the current PEF information to an MC" },
{ "setpef", setpef_cmd,
" <config> [<selector>] <value>"
" - Set the given config item to the value. The optional selector"
" is used for items that take a selector" },
{ "readlanparm", readlanparm_cmd,
" <channel> <mc num> <channel>"
" - read lanparm information from an MC" },
{ "viewlanparm", viewlanparm_cmd,
" - show current lanparm information " },
{ "writelanparm", writelanparm_cmd,
" <channel> <mc num> <channel>"
" - write the current LANPARM information to an MC" },
{ "clearlanparmlock", clearlanparmlock_cmd,
" [<channel> <mc num> <channel>]"
" - Clear a LANPARM lock. If the MC is given, then the LANPARM is"
" directly"
" cleared. If not given, then the current LANPARM is cleared" },
{ "setlanparm", setlanparm_cmd,
" <config> [<selector>] <value>"
" - Set the given config item to the value. The optional selector"
" is used for items that take a selector" },
{ "pet", pet_cmd,
" <connection> <channel> <ip addr> <mac_addr> <eft selector>"
" <policy num> <apt selector>"
" <lan dest selector> - "
"Set up the domain to send PET traps from the given connection"
" to the given IP/MAC address over the given channel" },
{ "delevent", delevent_cmd,
" <channel> <mc num> <log number> - "
"Delete the given event number from the SEL" },
{ "addevent", addevent_cmd,
" <channel> <mc num> <record id> <type> <13 bytes of data> - "
"Add the event data to the SEL" },
{ "debug", debug_cmd,
" <type> on|off - Turn the given debugging type on or off." },
{ "clear_sel", clear_sel_cmd,
" - clear the system event log" },
{ "list_sel", list_sel_cmd,
" - list the local copy of the system event log" },
{ "get_sel_time", get_sel_time_cmd,
" <channel> <mc num> - Get the time in the SEL for the given MC" },
{ "sdrs", sdrs_cmd,
" <channel> <mc num> <do_sensors> - list the SDRs for the mc."
" If do_sensors is"
" 1, then the device SDRs are fetched. Otherwise the main SDRs are"
" fetched." },
{ "events_enable", events_enable_cmd,
" <events> <scanning> <assertion bitmask> <deassertion bitmask>"
" - set the events enable data for the sensor" },
{ "scan", scan_cmd,
" <ipmb addr> - scan an IPMB to add or remove it" },
{ "is_con_active", is_con_active_cmd,
" <connection> - print out if the given connection is active or not" },
{ "activate_con", activate_con_cmd,
" <connection> - Activate the given connection" },
{ "quit", quit_cmd,
" - leave the program" },
{ "check_presence", presence_cmd,
" - Check the presence of entities" },
{ "new_domain", new_domain_cmd,
" <domain name> <parms...> - Open a connection to a new domain" },
{ "close_domain", close_domain_cmd,
" <num> - close the given domain number" },
{ "set_domain", set_domain_cmd,
" <num> - Use the given domain number" },
{ "domains", domains_cmd,
" - List all the domains" },
{ "help", help_cmd,
" - This output"},
{ NULL, NULL}
};
int
init_commands(void)
{
int err;
int i;
commands = command_alloc();
if (!commands)
return ENOMEM;
for (i=0; cmd_list[i].name != NULL; i++) {
err = command_bind(commands, cmd_list[i].name, cmd_list[i].handler);
if (err)
goto out_err;
}
return 0;
out_err:
command_free(commands);
return err;
}
static int
help_cmd(char *cmd, char **toks, void *cb_data)
{
int i;
display_pad_clear();
curr_display_type = HELP;
display_pad_out("Welcome to the IPMI UI version %s\n", OPENIPMI_VERSION);
for (i=0; cmd_list[i].name != NULL; i++) {
display_pad_out(" %s%s\n", cmd_list[i].name, cmd_list[i].help);
}
display_pad_refresh();
return 0;
}
int
init_keypad(void)
{
int i;
int err = 0;
keymap = keypad_alloc();
if (!keymap)
return ENOMEM;
for (i=0x20; i<0x7f; i++) {
err = keypad_bind_key(keymap, i, normal_char);
if (err)
goto out_err;
}
err = keypad_bind_key(keymap, 0x7f, backspace);
if (!err)
err = keypad_bind_key(keymap, 9, normal_char);
if (!err)
err = keypad_bind_key(keymap, 8, backspace);
if (!err)
err = keypad_bind_key(keymap, 4, key_leave);
if (!err)
err = keypad_bind_key(keymap, 10, end_of_line);
if (!err)
err = keypad_bind_key(keymap, 13, end_of_line);
if (full_screen) {
if (!err)
err = keypad_bind_key(keymap, KEY_BACKSPACE, backspace);
if (!err)
err = keypad_bind_key(keymap, KEY_DC, backspace);
if (!err)
err = keypad_bind_key(keymap, KEY_UP, key_up);
if (!err)
err = keypad_bind_key(keymap, KEY_DOWN, key_down);
if (!err)
err = keypad_bind_key(keymap, KEY_RIGHT, key_right);
if (!err)
err = keypad_bind_key(keymap, KEY_LEFT, key_left);
if (!err)
err = keypad_bind_key(keymap, KEY_NPAGE, key_npage);
if (!err)
err = keypad_bind_key(keymap, KEY_PPAGE, key_ppage);
if (!err)
err = keypad_bind_key(keymap, KEY_RESIZE, key_resize);
if (!err)
err = keypad_bind_key(keymap, KEY_F(1), key_set_display);
if (!err)
err = keypad_bind_key(keymap, KEY_F(2), key_set_log);
} else {
if (!err)
err = keypad_bind_key(keymap, -1, key_leave);
}
if (err)
goto out_err;
return 0;
out_err:
keypad_free(keymap);
return err;
}
int
init_win(void)
{
main_win = initscr();
if (!main_win)
exit(1);
raw();
noecho();
stat_win = newwin(STATUS_WIN_LINES, STATUS_WIN_COLS,
STATUS_WIN_TOP, STATUS_WIN_LEFT);
if (!stat_win)
leave(1, "Could not allocate stat window\n");
display_pad = newpad(NUM_DISPLAY_LINES, DISPLAY_WIN_COLS);
if (!display_pad)
leave(1, "Could not allocate display window\n");
log_pad = newpad(NUM_LOG_LINES, LOG_WIN_COLS);
if (!log_pad)
leave(1, "Could not allocate log window\n");
scrollok(log_pad, TRUE);
wmove(log_pad, NUM_LOG_LINES-1, 0);
log_pad_top_line = NUM_LOG_LINES-LOG_WIN_LINES;
dummy_pad = newpad(NUM_LOG_LINES, LOG_WIN_COLS);
if (!dummy_pad)
leave(1, "Could not allocate dummy pad\n");
wmove(dummy_pad, 0, 0);
cmd_win = newwin(CMD_WIN_LINES, CMD_WIN_COLS, CMD_WIN_TOP, CMD_WIN_LEFT);
if (!cmd_win)
leave(1, "Could not allocate command window\n");
keypad(cmd_win, TRUE);
meta(cmd_win, TRUE);
nodelay(cmd_win, TRUE);
scrollok(cmd_win, TRUE);
draw_lines();
display_pad_refresh();
cmd_win_out("> ");
cmd_win_refresh();
return 0;
}
static void
report_error(char *str, int err)
{
if (IPMI_IS_OS_ERR(err)) {
ui_log("%s: %s\n", str, strerror(IPMI_GET_OS_ERR(err)));
} else {
ui_log("%s: IPMI Error %2.2x\n",
str, IPMI_GET_IPMI_ERR(err));
}
}
static int
sensor_threshold_event_handler(ipmi_sensor_t *sensor,
enum ipmi_event_dir_e dir,
enum ipmi_thresh_e threshold,
enum ipmi_event_value_dir_e high_low,
enum ipmi_value_present_e value_present,
unsigned int raw_value,
double value,
void *cb_data,
ipmi_event_t *event)
{
ipmi_entity_t *entity = ipmi_sensor_get_entity(sensor);
char loc[MAX_ENTITY_LOC_SIZE];
char name[33];
ipmi_sensor_get_id(sensor, name, 33);
ui_log("Sensor %s.%s: %s %s %s\n",
get_entity_loc(entity, loc, sizeof(loc)),
name,
ipmi_get_threshold_string(threshold),
ipmi_get_value_dir_string(high_low),
ipmi_get_event_dir_string(dir));
if (value_present == IPMI_BOTH_VALUES_PRESENT) {
ui_log(" value is %f (%2.2x)\n", value, raw_value);
} else if (value_present == IPMI_RAW_VALUE_PRESENT) {
ui_log(" raw value is 0x%x\n", raw_value);
}
if (event)
ui_log("Due to event 0x%4.4x\n", ipmi_event_get_record_id(event));
return IPMI_EVENT_NOT_HANDLED;
}
static int
sensor_discrete_event_handler(ipmi_sensor_t *sensor,
enum ipmi_event_dir_e dir,
int offset,
int severity,
int prev_severity,
void *cb_data,
ipmi_event_t *event)
{
ipmi_entity_t *entity = ipmi_sensor_get_entity(sensor);
char loc[MAX_ENTITY_LOC_SIZE];
char name[33];
ipmi_sensor_get_id(sensor, name, 33);
ui_log("Sensor %s.%s: %d %s\n",
get_entity_loc(entity, loc, sizeof(loc)),
name,
offset,
ipmi_get_event_dir_string(dir));
if (severity != -1)
ui_log(" severity is %d\n", severity);
if (prev_severity != -1)
ui_log(" prev severity is %d\n", prev_severity);
if (event)
ui_log("Due to event 0x%4.4x\n", ipmi_event_get_record_id(event));
return IPMI_EVENT_NOT_HANDLED;
}
static void
sensor_change(enum ipmi_update_e op,
ipmi_entity_t *ent,
ipmi_sensor_t *sensor,
void *cb_data)
{
ipmi_entity_t *entity = ipmi_sensor_get_entity(sensor);
char loc[MAX_ENTITY_LOC_SIZE];
char name[33];
char name2[33];
int rv;
ipmi_sensor_get_id(sensor, name, 32);
strcpy(name2, name);
conv_from_spaces(name2);
switch (op) {
case IPMI_ADDED:
ui_log("Sensor added: %s.%s (%s)\n",
get_entity_loc(entity, loc, sizeof(loc)),
name2, name);
if (ipmi_sensor_get_event_reading_type(sensor)
== IPMI_EVENT_READING_TYPE_THRESHOLD)
rv = ipmi_sensor_add_threshold_event_handler(
sensor,
sensor_threshold_event_handler,
NULL);
else
rv = ipmi_sensor_add_discrete_event_handler(
sensor,
sensor_discrete_event_handler,
NULL);
if (rv)
ui_log("Unable to register sensor event handler: 0x%x\n", rv);
break;
case IPMI_DELETED:
ui_log("Sensor deleted: %s.%s (%s)\n",
get_entity_loc(entity, loc, sizeof(loc)),
name2, name);
break;
case IPMI_CHANGED:
ui_log("Sensor changed: %s.%s (%s)\n",
get_entity_loc(entity, loc, sizeof(loc)),
name2, name);
break;
}
}
static void
control_change(enum ipmi_update_e op,
ipmi_entity_t *ent,
ipmi_control_t *control,
void *cb_data)
{
ipmi_entity_t *entity = ipmi_control_get_entity(control);
char loc[MAX_ENTITY_LOC_SIZE];
char name[33];
char name2[33];
ipmi_control_get_id(control, name, 32);
strcpy(name2, name);
conv_from_spaces(name2);
switch (op) {
case IPMI_ADDED:
ui_log("Control added: %s.%s (%s)\n",
get_entity_loc(entity, loc, sizeof(loc)),
name2, name);
break;
case IPMI_DELETED:
ui_log("Control deleted: %s.%s (%s)\n",
get_entity_loc(entity, loc, sizeof(loc)),
name2, name);
break;
case IPMI_CHANGED:
ui_log("Control changed: %s.%s (%s)\n",
get_entity_loc(entity, loc, sizeof(loc)),
name2, name);
break;
}
}
static int
entity_presence_handler(ipmi_entity_t *entity,
int present,
void *cb_data,
ipmi_event_t *event)
{
char loc[MAX_ENTITY_LOC_SIZE];
ui_log("Entity %s, presence is %d\n",
get_entity_loc(entity, loc, sizeof(loc)),
present);
if (event)
ui_log("Due to event 0x%4.4x\n", ipmi_event_get_record_id(event));
return IPMI_EVENT_NOT_HANDLED;
}
void fru_change(enum ipmi_update_e op,
ipmi_entity_t *entity,
void *cb_data)
{
char loc[MAX_ENTITY_LOC_SIZE];
switch (op) {
case IPMI_ADDED:
ui_log("FRU added for %s\n",
get_entity_loc(entity, loc, sizeof(loc)));
break;
case IPMI_DELETED:
ui_log("FRU deleted for %s\n",
get_entity_loc(entity, loc, sizeof(loc)));
break;
case IPMI_CHANGED:
ui_log("FRU changed for %s\n",
get_entity_loc(entity, loc, sizeof(loc)));
break;
}
}
static int
entity_hot_swap_handler(ipmi_entity_t *ent,
enum ipmi_hot_swap_states last_state,
enum ipmi_hot_swap_states curr_state,
void *cb_data,
ipmi_event_t *event)
{
char loc[MAX_ENTITY_LOC_SIZE];
ui_log("Entity hot swap state changed for %s, was %s, now %s\n",
get_entity_loc(ent, loc, sizeof(loc)),
ipmi_hot_swap_state_name(last_state),
ipmi_hot_swap_state_name(curr_state));
return IPMI_EVENT_NOT_HANDLED;
}
static void
entity_change(enum ipmi_update_e op,
ipmi_domain_t *domain,
ipmi_entity_t *entity,
void *cb_data)
{
int rv;
char loc[MAX_ENTITY_LOC_SIZE];
switch (op) {
case IPMI_ADDED:
ui_log("Entity added: %s\n",
get_entity_loc(entity, loc, sizeof(loc)));
rv = ipmi_entity_add_sensor_update_handler(entity,
sensor_change,
entity);
if (rv) {
report_error("ipmi_entity_add_sensor_update_handler", rv);
break;
}
rv = ipmi_entity_add_control_update_handler(entity,
control_change,
entity);
if (rv) {
report_error("ipmi_entity_add_control_update_handler", rv);
break;
}
rv = ipmi_entity_add_fru_update_handler(entity,
fru_change,
entity);
if (rv) {
report_error("ipmi_entity_add_control_fru_handler", rv);
break;
}
rv = ipmi_entity_add_presence_handler(entity,
entity_presence_handler,
NULL);
if (rv) {
report_error("ipmi_entity_add_presence_handler", rv);
}
rv = ipmi_entity_add_hot_swap_handler(entity,
entity_hot_swap_handler,
NULL);
if (rv) {
report_error("ipmi_entity_add_hot_swap_handler", rv);
}
break;
case IPMI_DELETED:
ui_log("Entity deleted: %s\n",
get_entity_loc(entity, loc, sizeof(loc)));
break;
case IPMI_CHANGED:
ui_log("Entity changed: %s\n",
get_entity_loc(entity, loc, sizeof(loc)));
break;
}
if (ipmi_entity_hot_swappable(entity))
ui_log("Entity is hot swappable\n");
else
ui_log("Entity is not hot swappable\n");
}
static void
mc_sels_read(ipmi_mc_t *mc, void *cb_data)
{
int addr = ipmi_mc_get_address(mc);
int channel = ipmi_mc_get_channel(mc);
ui_log("MC (%d %x) SELs read\n", channel, addr);
}
static void
mc_sdrs_read(ipmi_mc_t *mc, void *cb_data)
{
int addr = ipmi_mc_get_address(mc);
int channel = ipmi_mc_get_channel(mc);
ui_log("MC (%d %x) SDRs read\n", channel, addr);
}
static void
mc_active(ipmi_mc_t *mc, int active, void *cb_data)
{
int addr = ipmi_mc_get_address(mc);
int channel = ipmi_mc_get_channel(mc);
ui_log("MC is %s: (%d %x)\n",
active ? "active" : "inactive",
channel, addr);
ipmi_mc_set_sdrs_first_read_handler(mc, mc_sdrs_read, NULL);
ipmi_mc_set_sels_first_read_handler(mc, mc_sels_read, NULL);
}
static void
mc_change(enum ipmi_update_e op,
ipmi_domain_t *domain,
ipmi_mc_t *mc,
void *cb_data)
{
int addr = ipmi_mc_get_address(mc);
int channel = ipmi_mc_get_channel(mc);
int rv;
switch (op) {
case IPMI_ADDED:
rv = ipmi_mc_add_active_handler(mc, mc_active, NULL);
if (rv)
ui_log("Unable to add MC active handler: 0x%x\n", rv);
if (ipmi_mc_is_active(mc)) {
ipmi_mc_set_sdrs_first_read_handler(mc, mc_sdrs_read, NULL);
ipmi_mc_set_sels_first_read_handler(mc, mc_sels_read, NULL);
ui_log("MC added: (%d %x) - (active)\n", channel, addr);
} else {
ui_log("MC added: (%d %x) - (inactive)\n", channel, addr);
}
break;
case IPMI_DELETED:
ui_log("MC deleted: (%d %x)\n", channel, addr);
break;
case IPMI_CHANGED:
ui_log("MC changed: (%d %x)\n", channel, addr);
break;
}
}
static void
event_handler(ipmi_domain_t *domain,
ipmi_event_t *event,
void *event_data)
{
ipmi_mcid_t mcid = ipmi_event_get_mcid(event);
unsigned int record_id = ipmi_event_get_record_id(event);
unsigned int type = ipmi_event_get_type(event);
ipmi_time_t timestamp = ipmi_event_get_timestamp(event);
unsigned int data_len = ipmi_event_get_data_len(event);
const unsigned char *data = ipmi_event_get_data_ptr(event);
unsigned int i;
char str[200];
int pos;
pos = 0;
for (i=0; i<data_len; i++)
pos += snprintf(str+pos, 200-pos, " %2.2x", data[i]);
ui_log("Unknown event from mc (%x %x)\n"
"%4.4x:%2.2x %lld: %s\n",
mcid.channel, mcid.mc_num, record_id, type, (int64_t) timestamp,
str);
}
static void
redisplay_timeout(selector_t *sel,
sel_timer_t *timer,
void *data)
{
struct timeval now;
int rv;
if (!full_screen)
return;
if (curr_display_type == DISPLAY_ENTITIES) {
rv = ipmi_domain_pointer_cb(domain_id, entities_cmder, &rv);
if (rv)
ui_log("redisplay_timeout:"
" Unable to convert BMC id to a pointer\n");
} else if (curr_display_type == DISPLAY_SENSOR) {
rv = ipmi_sensor_pointer_cb(curr_sensor_id, redisplay_sensor, NULL);
if (rv)
ui_log("redisplay_timeout: Unable to get sensor pointer: 0x%x\n",
rv);
} else if (curr_display_type == DISPLAY_CONTROL) {
rv = ipmi_control_pointer_cb(curr_control_id, redisplay_control, NULL);
if (rv)
ui_log("redisplay_timeout: Unable to get sensor pointer: 0x%x\n",
rv);
}
gettimeofday(&now, NULL);
now.tv_sec += 1;
rv = sel_start_timer(timer, &now);
if (rv)
ui_log("Unable to restart redisplay timer: 0x%x\n", rv);
}
void
ipmi_ui_setup_done(ipmi_domain_t *domain,
int err,
unsigned int conn_num,
unsigned int port_num,
int still_connected,
void *cb_data)
{
int rv;
if (err)
ui_log("IPMI connection to con.port %d.%d is down"
" due to error 0x%x\n",
conn_num, port_num, err);
else
ui_log("IPMI connection to con.port %d.%d is up\n",
conn_num, port_num);
if (!still_connected) {
ui_log("All IPMI connections down\n");
return;
}
domain_id = ipmi_domain_convert_to_id(domain);
rv = ipmi_domain_add_event_handler(domain, event_handler, NULL);
if (rv)
leave_err(rv, "ipmi_register_for_events");
rv = ipmi_domain_enable_events(domain);
if (rv)
leave_err(rv, "ipmi_domain_enable_events");
rv = ipmi_domain_add_entity_update_handler(domain, entity_change, domain);
if (rv)
leave_err(rv, "ipmi_bmc_set_entity_update_handler");
rv = ipmi_domain_add_mc_updated_handler(domain, mc_change, domain);
if (rv)
leave_err(rv, "ipmi_bmc_set_entity_update_handler");
pef = NULL;
lanparm = NULL;
}
void
ipmi_ui_domain_ready(ipmi_domain_t *domain,
int err,
unsigned int conn_num,
unsigned int port_num,
int still_connected,
void *user_data)
{
}
int
ipmi_ui_init(selector_t **selector, int do_full_screen)
{
int rv;
full_screen = do_full_screen;
ipmi_init(&ipmi_ui_cb_handlers);
rv = sel_alloc_selector(&ipmi_ui_cb_handlers, &ui_sel);
if (rv) {
fprintf(stderr, "Could not allocate selector\n");
exit(1);
}
sel_set_fd_handlers(ui_sel, 0, NULL, user_input_ready, NULL, NULL, NULL);
sel_set_fd_read_handler(ui_sel, 0, SEL_FD_HANDLER_ENABLED);
/* This is a dummy allocation just to make sure that the malloc
debugger is working. */
ipmi_mem_alloc(10);
sensor_states = ipmi_mem_alloc(ipmi_states_size());
if (!sensor_states) {
fprintf(stderr, "Could not allocate sensor states\n");
exit(1);
}
sensor_event_states = ipmi_mem_alloc(ipmi_event_state_size());
if (!sensor_event_states) {
fprintf(stderr, "Could not allocate sensor event states\n");
exit(1);
}
sensor_thresholds = ipmi_mem_alloc(ipmi_thresholds_size());
if (!sensor_thresholds) {
fprintf(stderr, "Could not allocate sensor thresholds\n");
exit(1);
}
rv = init_commands();
if (rv) {
fprintf(stderr, "Could not initialize commands\n");
exit(1);
}
rv = init_keypad();
if (rv) {
fprintf(stderr, "Could not initialize keymap\n");
exit(1);
}
if (full_screen) {
rv = init_win();
if (rv) {
fprintf(stderr, "Could not initialize curses\n");
exit(1);
}
} else {
struct termios new_termios;
tcgetattr(0, &old_termios);
new_termios = old_termios;
new_termios.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
|INLCR|IGNCR|ICRNL|IXON);
new_termios.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
tcsetattr(0, TCSADRAIN, &new_termios);
old_flags = fcntl(0, F_GETFL) & O_ACCMODE;
// fcntl(0, F_SETFL, old_flags | O_NONBLOCK);
}
help_cmd(NULL, NULL, NULL);
ui_log("Starting setup, wait until complete before entering commands.\n");
{
struct timeval now;
rv = sel_alloc_timer(ui_sel, redisplay_timeout, NULL,
&redisplay_timer);
if (rv)
leave_err(rv, "sel_alloc_timer");
gettimeofday(&now, NULL);
now.tv_sec += 1;
rv = sel_start_timer(redisplay_timer, &now);
if (rv)
leave_err(rv, "Unable to restart redisplay timer");
}
*selector = ui_sel;
return 0;
}
void
ipmi_ui_shutdown(void)
{
ipmi_mem_free(sensor_states);
sensor_states = NULL;
ipmi_mem_free(sensor_event_states);
sensor_event_states = NULL;
ipmi_mem_free(sensor_thresholds);
sensor_thresholds = NULL;
leave(0, "");
}
|