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
|
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
* SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <setjmp.h>
#include <netdb.h>
#include <ipmitool/ipmi.h>
#include <ipmitool/log.h>
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/helper.h>
#include <ipmitool/ipmi_constants.h>
#include <ipmitool/ipmi_strings.h>
#include <ipmitool/ipmi_lanp.h>
#include <ipmitool/ipmi_channel.h>
extern int verbose;
/* is_lan_channel - Check if channel is LAN medium
*
* return 1 if channel is LAN
* return 0 if channel is not LAN
*
* @intf: ipmi interface handle
* @chan: channel number to check
*/
static int
is_lan_channel(struct ipmi_intf * intf, uint8_t chan)
{
uint8_t medium;
if (chan < 1 || chan > IPMI_CHANNEL_NUMBER_MAX)
return 0;
medium = ipmi_get_channel_medium(intf, chan);
if (medium == IPMI_CHANNEL_MEDIUM_LAN ||
medium == IPMI_CHANNEL_MEDIUM_LAN_OTHER)
return 1;
return 0;
}
/* find_lan_channel - Find first channel that is LAN
*
* return channel number if successful
* return -1 if no lan channel found
*
* @intf: ipmi interface handle
* @start: channel number to start searching from
*/
static int
find_lan_channel(struct ipmi_intf * intf, int start)
{
uint8_t chan;
for (chan = start; chan < IPMI_CHANNEL_NUMBER_MAX; chan++) {
if (is_lan_channel(intf, chan)) {
return chan;
}
}
return -1;
}
/* get_lan_param_select - Query BMC for LAN parameter data
*
* return pointer to lan_param if successful
* if parameter not supported then
* return pointer to lan_param with
* lan_param->data == NULL and lan_param->data_len == 0
* return NULL on error
*
* @intf: ipmi interface handle
* @chan: ipmi channel
* @param: lan parameter id
* @select: lan parameter set selector
*/
static struct lan_param *
get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int select)
{
struct lan_param * p;
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t msg_data[4];
p = &ipmi_lan_params[param];
if (p == NULL)
return NULL;
msg_data[0] = chan;
msg_data[1] = p->cmd;
msg_data[2] = select;
msg_data[3] = 0;
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_TRANSPORT;
req.msg.cmd = IPMI_LAN_GET_CONFIG;
req.msg.data = msg_data;
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed", p->desc);
return NULL;
}
switch (rsp->ccode)
{
case 0x00: /* successful */
break;
case 0x80: /* parameter not supported */
case 0xc9: /* parameter out of range */
case 0xcc: /* invalid data field in request */
/* these completion codes usually mean parameter not supported */
lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed: %s",
p->desc, val2str(rsp->ccode, completion_code_vals));
p->data = NULL;
p->data_len = 0;
return p;
default:
/* other completion codes are treated as error */
lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed: %s",
p->desc, val2str(rsp->ccode, completion_code_vals));
return NULL;
}
p->data = rsp->data + 1;
p->data_len = rsp->data_len - 1;
return p;
}
/* get_lan_param - Query BMC for LAN parameter data
*
* return pointer to lan_param if successful
* if parameter not supported then
* return pointer to lan_param with
* lan_param->data == NULL and lan_param->data_len == 0
* return NULL on error
*
* @intf: ipmi interface handle
* @chan: ipmi channel
* @param: lan parameter id
*/
static struct lan_param *
get_lan_param(struct ipmi_intf * intf, uint8_t chan, int param)
{
return get_lan_param_select(intf, chan, param, 0);
}
/* set_lan_param_wait - Wait for Set LAN Parameter command to complete
*
* On some systems this can take unusually long so we wait for the write
* to take effect and verify that the data was written successfully
* before continuing or retrying.
*
* returns 0 on success
* returns -1 on error
*
* @intf: ipmi interface handle
* @chan: ipmi channel
* @param: lan parameter id
* @data: lan parameter data
* @len: length of lan parameter data
*/
static int
set_lan_param_wait(struct ipmi_intf * intf, uint8_t chan,
int param, uint8_t * data, int len)
{
struct lan_param * p;
int retry = 10; /* 10 retries */
lprintf(LOG_DEBUG, "Waiting for Set LAN Parameter to complete...");
if (verbose > 1)
printbuf(data, len, "SET DATA");
for (;;) {
p = get_lan_param(intf, chan, param);
if (p == NULL) {
sleep(IPMI_LANP_TIMEOUT);
if (retry-- == 0)
return -1;
continue;
}
if (verbose > 1)
printbuf(p->data, p->data_len, "READ DATA");
if (p->data_len != len) {
sleep(IPMI_LANP_TIMEOUT);
if (retry-- == 0) {
lprintf(LOG_WARNING, "Mismatched data lengths: %d != %d",
p->data_len, len);
return -1;
}
continue;
}
if (memcmp(data, p->data, len) != 0) {
sleep(IPMI_LANP_TIMEOUT);
if (retry-- == 0) {
lprintf(LOG_WARNING, "LAN Parameter Data does not match! "
"Write may have failed.");
return -1;
}
continue;
}
break;
}
return 0;
}
/* __set_lan_param - Write LAN Parameter data to BMC
*
* This function does the actual work of writing the LAN parameter
* to the BMC and calls set_lan_param_wait() if requested.
*
* returns 0 on success
* returns -1 on error
*
* @intf: ipmi interface handle
* @chan: ipmi channel
* @param: lan parameter id
* @data: lan parameter data
* @len: length of lan parameter data
* @wait: whether to wait for write completion
*/
static int
__set_lan_param(struct ipmi_intf * intf, uint8_t chan,
int param, uint8_t * data, int len, int wait)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t msg_data[32];
if (param < 0)
return -1;
msg_data[0] = chan;
msg_data[1] = param;
memcpy(&msg_data[2], data, len);
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_TRANSPORT;
req.msg.cmd = IPMI_LAN_SET_CONFIG;
req.msg.data = msg_data;
req.msg.data_len = len+2;
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_ERR, "Set LAN Parameter failed");
return -1;
}
if ((rsp->ccode > 0) && (wait != 0)) {
lprintf(LOG_DEBUG, "Warning: Set LAN Parameter failed: %s",
val2str(rsp->ccode, completion_code_vals));
if (rsp->ccode == 0xcc) {
/* retry hack for invalid data field ccode */
int retry = 10; /* 10 retries */
lprintf(LOG_DEBUG, "Retrying...");
for (;;) {
if (retry-- == 0)
break;
sleep(IPMI_LANP_TIMEOUT);
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL)
continue;
if (rsp->ccode > 0)
continue;
return set_lan_param_wait(intf, chan, param, data, len);
}
}
else if (rsp->ccode != 0xff) {
/* let 0xff ccode continue */
return -1;
}
}
if (wait == 0)
return 0;
return set_lan_param_wait(intf, chan, param, data, len);
}
/* ipmi_lanp_lock_state - Retrieve set-in-progress status
*
* returns one of:
* IPMI_LANP_WRITE_UNLOCK
* IPMI_LANP_WRITE_LOCK
* IPMI_LANP_WRITE_COMMIT
* -1 on error/if not supported
*
* @intf: ipmi interface handle
* @chan: ipmi channel
*/
static int
ipmi_lanp_lock_state(struct ipmi_intf * intf, uint8_t chan)
{
struct lan_param * p;
p = get_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS);
if (p == NULL)
return -1;
if (p->data == NULL)
return -1;
return (p->data[0] & 3);
}
/* ipmi_lanp_lock - Lock set-in-progress bits for our use
*
* Write to the Set-In-Progress LAN parameter to indicate
* to other management software that we are modifying parameters.
*
* No meaningful return value because this is an optional
* requirement in IPMI spec and not found on many BMCs.
*
* @intf: ipmi interface handle
* @chan: ipmi channel
*/
static void
ipmi_lanp_lock(struct ipmi_intf * intf, uint8_t chan)
{
uint8_t val = IPMI_LANP_WRITE_LOCK;
int retry = 3;
for (;;) {
int state = ipmi_lanp_lock_state(intf, chan);
if (state == -1)
break;
if (state == val)
break;
if (retry-- == 0)
break;
__set_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS,
&val, 1, 0);
}
}
/* ipmi_lanp_unlock - Unlock set-in-progress bits
*
* Write to the Set-In-Progress LAN parameter, first with
* a "commit" instruction and then unlocking it.
*
* No meaningful return value because this is an optional
* requirement in IPMI spec and not found on many BMCs.
*
* @intf: ipmi interface handle
* @chan: ipmi channel
*/
static void
ipmi_lanp_unlock(struct ipmi_intf * intf, uint8_t chan)
{
uint8_t val = IPMI_LANP_WRITE_COMMIT;
int rc;
rc = __set_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS, &val, 1, 0);
if (rc < 0) {
lprintf(LOG_DEBUG, "LAN Parameter Commit not supported");
}
val = IPMI_LANP_WRITE_UNLOCK;
__set_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS, &val, 1, 0);
}
/* set_lan_param - Wrap LAN parameter write with set-in-progress lock
*
* Returns value from __set_lan_param()
*
* @intf: ipmi interface handle
* @chan: ipmi channel
* @param: lan parameter id
* @data: lan parameter data
* @len: length of lan parameter data
*/
static int
set_lan_param(struct ipmi_intf * intf, uint8_t chan,
int param, uint8_t * data, int len)
{
int rc;
ipmi_lanp_lock(intf, chan);
rc = __set_lan_param(intf, chan, param, data, len, 1);
ipmi_lanp_unlock(intf, chan);
return rc;
}
/* set_lan_param_nowait - Wrap LAN parameter write without set-in-progress lock
*
* Returns value from __set_lan_param()
*
* @intf: ipmi interface handle
* @chan: ipmi channel
* @param: lan parameter id
* @data: lan parameter data
* @len: length of lan parameter data
*/
static int
set_lan_param_nowait(struct ipmi_intf * intf, uint8_t chan,
int param, uint8_t * data, int len)
{
int rc;
ipmi_lanp_lock(intf, chan);
rc = __set_lan_param(intf, chan, param, data, len, 0);
ipmi_lanp_unlock(intf, chan);
return rc;
}
static int
lan_set_arp_interval(struct ipmi_intf * intf,
uint8_t chan, uint8_t * ival)
{
struct lan_param *lp;
uint8_t interval;
int rc = 0;
lp = get_lan_param(intf, chan, IPMI_LANP_GRAT_ARP);
if (lp == NULL)
return -1;
if (lp->data == NULL)
return -1;
if (ival != 0) {
interval = ((uint8_t)atoi((const char *)ival) * 2) - 1;
rc = set_lan_param(intf, chan, IPMI_LANP_GRAT_ARP, &interval, 1);
} else {
interval = lp->data[0];
}
printf("BMC-generated Gratuitous ARP interval: %.1f seconds\n",
(float)((interval + 1) / 2));
return rc;
}
static int
lan_set_arp_generate(struct ipmi_intf * intf,
uint8_t chan, uint8_t ctl)
{
struct lan_param *lp;
uint8_t data;
lp = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
if (lp == NULL)
return -1;
if (lp->data == NULL)
return -1;
data = lp->data[0];
/* set arp generate bitflag */
if (ctl == 0)
data &= ~0x1;
else
data |= 0x1;
printf("%sabling BMC-generated Gratuitous ARPs\n", ctl ? "En" : "Dis");
return set_lan_param(intf, chan, IPMI_LANP_BMC_ARP, &data, 1);
}
static int
lan_set_arp_respond(struct ipmi_intf * intf,
uint8_t chan, uint8_t ctl)
{
struct lan_param *lp;
uint8_t data;
lp = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
if (lp == NULL)
return -1;
if (lp->data == NULL)
return -1;
data = lp->data[0];
/* set arp response bitflag */
if (ctl == 0)
data &= ~0x2;
else
data |= 0x2;
printf("%sabling BMC-generated ARP responses\n", ctl ? "En" : "Dis");
return set_lan_param(intf, chan, IPMI_LANP_BMC_ARP, &data, 1);
}
static char priv_level_to_char(unsigned char priv_level)
{
char ret = 'X';
switch (priv_level)
{
case IPMI_SESSION_PRIV_CALLBACK:
ret = 'c';
break;
case IPMI_SESSION_PRIV_USER:
ret = 'u';
break;
case IPMI_SESSION_PRIV_OPERATOR:
ret = 'o';
break;
case IPMI_SESSION_PRIV_ADMIN:
ret = 'a';
break;
case IPMI_SESSION_PRIV_OEM:
ret = 'O';
break;
}
return ret;
}
static int
ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
{
struct lan_param * p;
int rc = 0;
if (chan < 1 || chan > IPMI_CHANNEL_NUMBER_MAX) {
lprintf(LOG_ERR, "Invalid Channel %d", chan);
return -1;
}
/* find type of channel and only accept 802.3 LAN */
if (is_lan_channel(intf, chan) == 0) {
lprintf(LOG_ERR, "Channel %d is not a LAN channel", chan);
return -1;
}
p = get_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS);
if (p == NULL)
return -1;
if (p->data != NULL) {
printf("%-24s: ", p->desc);
p->data[0] &= 3;
switch (p->data[0]) {
case 0:
printf("Set Complete\n");
break;
case 1:
printf("Set In Progress\n");
break;
case 2:
printf("Commit Write\n");
break;
case 3:
printf("Reserved\n");
break;
default:
printf("Unknown\n");
}
}
p = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE);
if (p == NULL)
return -1;
if (p->data != NULL) {
printf("%-24s: %s%s%s%s%s\n", p->desc,
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
}
p = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE);
if (p == NULL)
return -1;
if (p->data != NULL) {
printf("%-24s: Callback : %s%s%s%s%s\n", p->desc,
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
printf("%-24s: User : %s%s%s%s%s\n", "",
(p->data[1] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
(p->data[1] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
(p->data[1] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
(p->data[1] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
(p->data[1] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
printf("%-24s: Operator : %s%s%s%s%s\n", "",
(p->data[2] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
(p->data[2] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
(p->data[2] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
(p->data[2] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
(p->data[2] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
printf("%-24s: Admin : %s%s%s%s%s\n", "",
(p->data[3] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
(p->data[3] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
(p->data[3] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
(p->data[3] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
(p->data[3] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
printf("%-24s: OEM : %s%s%s%s%s\n", "",
(p->data[4] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
(p->data[4] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
(p->data[4] & 1<<IPMI_SESSION_AUTHTYPE_MD5) ? "MD5 " : "",
(p->data[4] & 1<<IPMI_SESSION_AUTHTYPE_PASSWORD) ? "PASSWORD " : "",
(p->data[4] & 1<<IPMI_SESSION_AUTHTYPE_OEM) ? "OEM " : "");
}
p = get_lan_param(intf, chan, IPMI_LANP_IP_ADDR_SRC);
if (p == NULL)
return -1;
if (p->data != NULL) {
printf("%-24s: ", p->desc);
p->data[0] &= 0xf;
switch (p->data[0]) {
case 0:
printf("Unspecified\n");
break;
case 1:
printf("Static Address\n");
break;
case 2:
printf("DHCP Address\n");
break;
case 3:
printf("BIOS Assigned Address\n");
break;
default:
printf("Other\n");
break;
}
}
p = get_lan_param(intf, chan, IPMI_LANP_IP_ADDR);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_SUBNET_MASK);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_MAC_ADDR);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: %02x:%02x:%02x:%02x:%02x:%02x\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3], p->data[4], p->data[5]);
p = get_lan_param(intf, chan, IPMI_LANP_SNMP_STRING);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: %s\n", p->desc, p->data);
p = get_lan_param(intf, chan, IPMI_LANP_IP_HEADER);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: TTL=0x%02x Flags=0x%02x Precedence=0x%02x TOS=0x%02x\n",
p->desc, p->data[0], p->data[1] & 0xe0, p->data[2] & 0xe0, p->data[2] & 0x1e);
p = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: ARP Responses %sabled, Gratuitous ARP %sabled\n", p->desc,
(p->data[0] & 2) ? "En" : "Dis", (p->data[0] & 1) ? "En" : "Dis");
p = get_lan_param(intf, chan, IPMI_LANP_GRAT_ARP);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: %.1f seconds\n", p->desc, (float)((p->data[0] + 1) / 2));
p = get_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_IP);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_MAC);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: %02x:%02x:%02x:%02x:%02x:%02x\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3], p->data[4], p->data[5]);
p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_MAC);
if (p == NULL)
return -1;
if (p->data != NULL)
printf("%-24s: %02x:%02x:%02x:%02x:%02x:%02x\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3], p->data[4], p->data[5]);
p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID);
if (p != NULL && p->data != NULL) {
int id = ((p->data[1] & 0x0f) << 8) + p->data[0];
if (p->data[1] & 0x80)
printf("%-24s: %d\n", p->desc, id);
else
printf("%-24s: Disabled\n", p->desc);
}
p = get_lan_param(intf, chan, IPMI_LANP_VLAN_PRIORITY);
if (p != NULL && p->data != NULL)
printf("%-24s: %d\n", p->desc, p->data[0] & 0x07);
/* Determine supported Cipher Suites -- Requires two calls */
p = get_lan_param(intf, chan, IPMI_LANP_RMCP_CIPHER_SUPPORT);
if (p == NULL)
return -1;
else if (p->data != NULL)
{
unsigned char cipher_suite_count = p->data[0];
p = get_lan_param(intf, chan, IPMI_LANP_RMCP_CIPHERS);
if (p == NULL)
return -1;
printf("%-24s: ", p->desc);
/* Now we're dangerous. There are only 15 fixed cipher
suite IDs, but the spec allows for 16 in the return data.*/
if ((p->data != NULL) && (p->data_len <= 17))
{
unsigned int i;
for (i = 0; (i < 16) && (i < cipher_suite_count); ++i)
{
printf("%s%d",
(i > 0? ",": ""),
p->data[i + 1]);
}
printf("\n");
}
else
{
printf("None\n");
}
}
/* RMCP+ Messaging Cipher Suite Privilege Levels */
/* These are the privilege levels for the 15 fixed cipher suites */
p = get_lan_param(intf, chan, IPMI_LANP_RMCP_PRIV_LEVELS);
if (p == NULL)
return -1;
if ((p->data != NULL) && (p->data_len == 9))
{
printf("%-24s: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", p->desc,
priv_level_to_char(p->data[1] & 0x0F),
priv_level_to_char(p->data[1] >> 4),
priv_level_to_char(p->data[2] & 0x0F),
priv_level_to_char(p->data[2] >> 4),
priv_level_to_char(p->data[3] & 0x0F),
priv_level_to_char(p->data[3] >> 4),
priv_level_to_char(p->data[4] & 0x0F),
priv_level_to_char(p->data[4] >> 4),
priv_level_to_char(p->data[5] & 0x0F),
priv_level_to_char(p->data[5] >> 4),
priv_level_to_char(p->data[6] & 0x0F),
priv_level_to_char(p->data[6] >> 4),
priv_level_to_char(p->data[7] & 0x0F),
priv_level_to_char(p->data[7] >> 4),
priv_level_to_char(p->data[8] & 0x0F));
/* Now print a legend */
printf("%-24s: %s\n", "", " X=Cipher Suite Unused");
printf("%-24s: %s\n", "", " c=CALLBACK");
printf("%-24s: %s\n", "", " u=USER");
printf("%-24s: %s\n", "", " o=OPERATOR");
printf("%-24s: %s\n", "", " a=ADMIN");
printf("%-24s: %s\n", "", " O=OEM");
}
else
printf("%-24s: Not Available\n", p->desc);
return rc;
}
/* Configure Authentication Types */
static int
ipmi_lan_set_auth(struct ipmi_intf * intf, uint8_t chan, char * level, char * types)
{
uint8_t data[5];
uint8_t authtype = 0;
char * p;
struct lan_param * lp;
if (level == NULL || types == NULL)
return -1;
lp = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE);
if (lp == NULL)
return -1;
if (lp->data == NULL)
return -1;
lprintf(LOG_DEBUG, "%-24s: callback=0x%02x user=0x%02x operator=0x%02x admin=0x%02x oem=0x%02x",
lp->desc, lp->data[0], lp->data[1], lp->data[2], lp->data[3], lp->data[4]);
memset(data, 0, 5);
memcpy(data, lp->data, 5);
p = types;
while (p) {
if (strncasecmp(p, "none", 4) == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_NONE;
else if (strncasecmp(p, "md2", 3) == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_MD2;
else if (strncasecmp(p, "md5", 3) == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_MD5;
else if ((strncasecmp(p, "password", 8) == 0) ||
(strncasecmp(p, "key", 3) == 0))
authtype |= 1 << IPMI_SESSION_AUTHTYPE_KEY;
else if (strncasecmp(p, "oem", 3) == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_OEM;
else
lprintf(LOG_WARNING, "Invalid authentication type: %s", p);
p = strchr(p, ',');
if (p)
p++;
}
p = level;
while (p) {
if (strncasecmp(p, "callback", 8) == 0)
data[0] = authtype;
else if (strncasecmp(p, "user", 4) == 0)
data[1] = authtype;
else if (strncasecmp(p, "operator", 8) == 0)
data[2] = authtype;
else if (strncasecmp(p, "admin", 5) == 0)
data[3] = authtype;
else
lprintf(LOG_WARNING, "Invalid authentication level: %s", p);
p = strchr(p, ',');
if (p)
p++;
}
if (verbose > 1)
printbuf(data, 5, "authtype data");
return set_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE, data, 5);
}
static int
ipmi_lan_set_password(struct ipmi_intf * intf,
uint8_t userid, uint8_t * password)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t data[18];
memset(&data, 0, sizeof(data));
data[0] = userid & 0x3f;/* user ID */
data[1] = 0x02; /* set password */
if (password != NULL)
memcpy(data+2, password, __min(strlen((const char *)password), 16));
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = 0x47;
req.msg.data = data;
req.msg.data_len = 18;
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_ERR, "Unable to Set LAN Password for user %d", userid);
return -1;
}
if (rsp->ccode > 0) {
lprintf(LOG_ERR, "Set LAN Password for user %d failed: %s",
userid, val2str(rsp->ccode, completion_code_vals));
return -1;
}
/* adjust our session password
* or we will no longer be able to communicate with BMC
*/
ipmi_intf_session_set_password(intf, (char *)password);
printf("Password %s for user %d\n",
(password == NULL) ? "cleared" : "set", userid);
return 0;
}
static int
ipmi_set_alert_enable(struct ipmi_intf * intf, uint8_t channel, uint8_t enable)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t rqdata[3];
memset(&req, 0, sizeof(req));
/* update non-volatile access */
rqdata[0] = channel;
rqdata[1] = 0x40;
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = 0x41;
req.msg.data = rqdata;
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_ERR, "Unable to Get Channel Access for channel %d", channel);
return -1;
}
if (rsp->ccode > 0) {
lprintf(LOG_ERR, "Get Channel Access for channel %d failed: %s",
channel, val2str(rsp->ccode, completion_code_vals));
return -1;
}
/* SAVE TO NVRAM */
memset(rqdata, 0, 3);
rqdata[0] = channel & 0xf;
rqdata[1] = rsp->data[0];
if (enable != 0)
rqdata[1] &= ~0x20;
else
rqdata[1] |= 0x20;
rqdata[1] |= 0x40;
rqdata[2] = 0;
req.msg.cmd = 0x40;
req.msg.data_len = 3;
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_ERR, "Unable to Set Channel Access for channel %d", channel);
return -1;
}
if (rsp->ccode > 0) {
lprintf(LOG_ERR, "Set Channel Access for channel %d failed: %s",
channel, val2str(rsp->ccode, completion_code_vals));
return -1;
}
/* SAVE TO CURRENT */
rqdata[1] &= 0xc0;
rqdata[1] |= 0x80;
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_ERR, "Unable to Set Channel Access for channel %d", channel);
return -1;
}
if (rsp->ccode > 0) {
lprintf(LOG_ERR, "Set Channel Access for channel %d failed: %s",
channel, val2str(rsp->ccode, completion_code_vals));
return -1;
}
return 0;
}
static int
ipmi_set_channel_access(struct ipmi_intf * intf, uint8_t channel, uint8_t enable)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t rqdata[3];
uint8_t byteEnable;
memset(&req, 0, sizeof(req));
/* RETREIVE VALUE IN NVRAM */
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = 0x41; /* Get Channel Access Command */
req.msg.data = rqdata;
req.msg.data_len = 2;
memset(rqdata, 0, 2);
rqdata[0] = channel & 0xf;
rqdata[1] = 0x40; /* retreive NV */
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_ERR, "Unable to Get Channel Access for channel %d", channel);
return -1;
} else if (rsp->ccode > 0) {
lprintf(LOG_ERR, "Set Channel Access for channel %d failed: %s",
channel, val2str(rsp->ccode, completion_code_vals));
return -1;
} else {
byteEnable = *(rsp->data + 0);
}
/* SAVE TO NVRAM */
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = 0x40; /* Set Channel Access Command */
req.msg.data = rqdata;
req.msg.data_len = 3;
memset(rqdata, 0, 3);
rqdata[0] = channel & 0xf;
rqdata[1] = 0x40 | (byteEnable & 0x38); /* use previously set values */
if (enable != 0)
rqdata[1] |= 0x2; /* set always available if enable is set */
rqdata[2] = 0x44; /* set channel privilege limit to ADMIN */
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_ERR, "Unable to Set Channel Access for channel %d", channel);
return -1;
} else if (rsp->ccode > 0) {
lprintf(LOG_ERR, "Set Channel Access for channel %d failed: %s",
channel, val2str(rsp->ccode, completion_code_vals));
return -1;
}
/* RETREIVE VALUE IN NVRAM */
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = 0x41; /* Get Channel Access Command */
req.msg.data = rqdata;
req.msg.data_len = 2;
memset(rqdata, 0, 2);
rqdata[0] = channel & 0xf;
rqdata[1] = 0x80; /* retreive NV */
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_ERR, "Unable to Get Channel Access for channel %d", channel);
return -1;
} else if (rsp->ccode > 0) {
lprintf(LOG_ERR, "Set Channel Access for channel %d failed: %s",
channel, val2str(rsp->ccode, completion_code_vals));
return -1;
} else {
byteEnable = *(rsp->data + 0);
}
/* SAVE TO CURRENT */
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = 0x40; /* Set Channel Access Command */
req.msg.data = rqdata;
req.msg.data_len = 3;
memset(rqdata, 0, 3);
rqdata[0] = channel & 0xf;
rqdata[1] = 0x80 | (byteEnable & 0x38); /* use previously set values */
if (enable != 0)
rqdata[1] |= 0x2; /* set always available if enable is set */
rqdata[2] = 0x84; /* set channel privilege limit to ADMIN */
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_ERR, "Unable to Set Channel Access for channel %d", channel);
return -1;
} else if (rsp->ccode > 0) {
lprintf(LOG_ERR, "Set Channel Access for channel %d failed: %s",
channel, val2str(rsp->ccode, completion_code_vals));
return -1;
}
/* can't send close session if access off so abort instead */
if (enable == 0)
intf->abort = 1;
return 0;
}
static int
ipmi_set_user_access(struct ipmi_intf * intf, uint8_t channel, uint8_t userid)
{
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t rqdata[4];
memset(rqdata, 0, 4);
rqdata[0] = 0x90 | (channel & 0xf);
rqdata[1] = userid & 0x3f;
rqdata[2] = 0x4;
rqdata[3] = 0;
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_APP;
req.msg.cmd = 0x43;
req.msg.data = rqdata;
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_ERR, "Unable to Set User Access for channel %d", channel);
return -1;
}
if (rsp->ccode > 0) {
lprintf(LOG_ERR, "Set User Access for channel %d failed: %s",
channel, val2str(rsp->ccode, completion_code_vals));
return -1;
}
return 0;
}
static int
get_cmdline_macaddr(char * arg, uint8_t * buf)
{
uint32_t m1, m2, m3, m4, m5, m6;
if (sscanf(arg, "%02x:%02x:%02x:%02x:%02x:%02x",
&m1, &m2, &m3, &m4, &m5, &m6) != 6) {
lprintf(LOG_ERR, "Invalid MAC address: %s", arg);
return -1;
}
buf[0] = (uint8_t)m1;
buf[1] = (uint8_t)m2;
buf[2] = (uint8_t)m3;
buf[3] = (uint8_t)m4;
buf[4] = (uint8_t)m5;
buf[5] = (uint8_t)m6;
return 0;
}
static int
get_cmdline_cipher_suite_priv_data(char * arg, uint8_t * buf)
{
int i, ret = 0;
if (strlen(arg) != 15)
{
lprintf(LOG_ERR, "Invalid privilege specification length: %d",
strlen(arg));
return -1;
}
/*
* The first byte is reserved (0). The rest of the buffer is setup
* so that each nibble holds the maximum privilege level available for
* that cipher suite number. The number of nibbles (15) matches the number
* of fixed cipher suite IDs. This command documentation mentions 16 IDs
* but table 22-19 shows that there are only 15 (0-14).
*
* data 1 - reserved
* data 2 - maximum priv level for first (LSN) and second (MSN) ciphers
* data 3 - maximum priv level for third (LSN) and fourth (MSN) ciphers
* data 9 - maximum priv level for 15th (LSN) cipher.
*/
bzero(buf, 9);
for (i = 0; i < 15; ++i)
{
unsigned char priv_level = IPMI_SESSION_PRIV_ADMIN;
switch (arg[i])
{
case 'X':
priv_level = IPMI_SESSION_PRIV_UNSPECIFIED; /* 0 */
break;
case 'c':
priv_level = IPMI_SESSION_PRIV_CALLBACK; /* 1 */
break;
case 'u':
priv_level = IPMI_SESSION_PRIV_USER; /* 2 */
break;
case 'o':
priv_level = IPMI_SESSION_PRIV_OPERATOR; /* 3 */
break;
case 'a':
priv_level = IPMI_SESSION_PRIV_ADMIN; /* 4 */
break;
case 'O':
priv_level = IPMI_SESSION_PRIV_OEM; /* 5 */
break;
default:
lprintf(LOG_ERR, "Invalid privilege specification char: %c",
arg[i]);
ret = -1;
break;
}
if (ret != 0)
break;
else
{
if ((i + 1) % 2)
{
// Odd number cipher suites will be in the LSN
buf[1 + (i / 2)] += priv_level;
}
else
{
// Even number cipher suites will be in the MSN
buf[1 + (i / 2)] += (priv_level << 4);
}
}
}
return ret;
}
static int
get_cmdline_ipaddr(char * arg, uint8_t * buf)
{
uint32_t ip1, ip2, ip3, ip4;
if (sscanf(arg, "%d.%d.%d.%d", &ip1, &ip2, &ip3, &ip4) != 4) {
lprintf(LOG_ERR, "Invalid IP address: %s", arg);
return -1;
}
buf[0] = (uint8_t)ip1;
buf[1] = (uint8_t)ip2;
buf[2] = (uint8_t)ip3;
buf[3] = (uint8_t)ip4;
return 0;
}
static void ipmi_lan_set_usage(void)
{
lprintf(LOG_NOTICE, "\nusage: lan set <channel> <command> [option]\n");
lprintf(LOG_NOTICE, "LAN set commands:");
lprintf(LOG_NOTICE, " ipaddr <x.x.x.x> Set channel IP address");
lprintf(LOG_NOTICE, " netmask <x.x.x.x> Set channel IP netmask");
lprintf(LOG_NOTICE, " macaddr <x:x:x:x:x:x> Set channel MAC address");
lprintf(LOG_NOTICE, " defgw ipaddr <x.x.x.x> Set default gateway IP address");
lprintf(LOG_NOTICE, " defgw macaddr <x:x:x:x:x:x> Set default gateway MAC address");
lprintf(LOG_NOTICE, " bakgw ipaddr <x.x.x.x> Set backup gateway IP address");
lprintf(LOG_NOTICE, " bakgw macaddr <x:x:x:x:x:x> Set backup gateway MAC address");
lprintf(LOG_NOTICE, " password <password> Set session password for this channel");
lprintf(LOG_NOTICE, " snmp <community string> Set SNMP public community string");
lprintf(LOG_NOTICE, " user Enable default user for this channel");
lprintf(LOG_NOTICE, " access <on|off> Enable or disable access to this channel");
lprintf(LOG_NOTICE, " alert <on|off> Enable or disable PEF alerting for this channel");
lprintf(LOG_NOTICE, " arp respond <on|off> Enable or disable BMC ARP responding");
lprintf(LOG_NOTICE, " arp generate <on|off> Enable or disable BMC gratuitous ARP generation");
lprintf(LOG_NOTICE, " arp interval <seconds> Set gratuitous ARP generation interval");
lprintf(LOG_NOTICE, " vlan id <off|<id>> Disable or enable VLAN and set ID (1-4094)");
lprintf(LOG_NOTICE, " vlan priority <priority> Set vlan priority (0-7)");
lprintf(LOG_NOTICE, " auth <level> <type,..> Set channel authentication types");
lprintf(LOG_NOTICE, " level = CALLBACK, USER, OPERATOR, ADMIN");
lprintf(LOG_NOTICE, " type = NONE, MD2, MD5, PASSWORD, OEM");
lprintf(LOG_NOTICE, " ipsrc <source> Set IP Address source");
lprintf(LOG_NOTICE, " none = unspecified source");
lprintf(LOG_NOTICE, " static = address manually configured to be static");
lprintf(LOG_NOTICE, " dhcp = address obtained by BMC running DHCP");
lprintf(LOG_NOTICE, " bios = address loaded by BIOS or system software");
lprintf(LOG_NOTICE, " cipher_privs XXXXXXXXXXXXXXX Set RMCP+ cipher suite privilege levels");
lprintf(LOG_NOTICE, " X = Cipher Suite Unused");
lprintf(LOG_NOTICE, " c = CALLBACK");
lprintf(LOG_NOTICE, " u = USER");
lprintf(LOG_NOTICE, " o = OPERATOR");
lprintf(LOG_NOTICE, " a = ADMIN");
lprintf(LOG_NOTICE, " O = OEM\n");
}
static void
ipmi_lan_set_vlan_usage(void)
{
lprintf(LOG_NOTICE,
"lan set <channel> vlan id <id>\n"
"lan set <channel> vlan id off\n"
"lan set <channel> vlan priority <priority>\n");
}
static int
ipmi_lan_set_vlan_id(struct ipmi_intf * intf, uint8_t chan, char *string)
{
uint8_t data[2];
int rc;
if (string == NULL) {
data[0] = 0;
data[1] = 0;
}
else {
int id = atoi(string);
if (id < 1 || id > 4094) {
lprintf(LOG_NOTICE, "vlan id must be between 1 and 4094.");
return -1;
}
else {
data[0] = (uint8_t)id;
data[1] = (uint8_t)(id >> 8) | 0x80;
}
}
rc = set_lan_param(intf, chan, IPMI_LANP_VLAN_ID, data, 2);
return rc;
}
static int
ipmi_lan_set_vlan_priority(struct ipmi_intf * intf, uint8_t chan, char *string)
{
uint8_t data;
int rc;
int priority = atoi(string);
if (priority < 0 || priority > 7) {
lprintf(LOG_NOTICE, "vlan priority must be between 0 and 7.");
return -1;
}
data = (uint8_t)priority;
rc = set_lan_param(intf, chan, IPMI_LANP_VLAN_PRIORITY, &data, 1);
return rc;
}
static int
ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
{
uint8_t data[32];
uint8_t chan;
int rc = 0;
if (argc < 2) {
ipmi_lan_set_usage();
return 0;
}
if (strncmp(argv[0], "help", 4) == 0 ||
strncmp(argv[1], "help", 4) == 0) {
ipmi_lan_set_usage();
return 0;
}
chan = (uint8_t)strtol(argv[0], NULL, 0);
/* find type of channel and only accept 802.3 LAN */
if (is_lan_channel(intf, chan) == 0) {
lprintf(LOG_ERR, "Channel %d is not a LAN channel!", chan);
ipmi_lan_set_usage();
return -1;
}
memset(&data, 0, sizeof(data));
/* set user access */
if (strncmp(argv[1], "user", 4) == 0) {
rc = ipmi_set_user_access(intf, chan, 1);
}
/* set channel access mode */
else if (strncmp(argv[1], "access", 6) == 0) {
if (argc < 3 || (strncmp(argv[2], "help", 4) == 0)) {
lprintf(LOG_NOTICE, "lan set access <on|off>");
}
else if (strncmp(argv[2], "on", 2) == 0) {
rc = ipmi_set_channel_access(intf, chan, 1);
}
else if (strncmp(argv[2], "off", 3) == 0) {
rc = ipmi_set_channel_access(intf, chan, 0);
}
else {
lprintf(LOG_NOTICE, "lan set access <on|off>");
}
}
/* set ARP control */
else if (strncmp(argv[1], "arp", 3) == 0) {
if (argc < 3 || (strncmp(argv[2], "help", 4) == 0)) {
lprintf(LOG_NOTICE,
"lan set <channel> arp respond <on|off>\n"
"lan set <channel> arp generate <on|off>\n"
"lan set <channel> arp interval <seconds>\n\n"
"example: lan set 7 arp gratuitous off\n");
}
else if (strncmp(argv[2], "interval", 8) == 0) {
rc = lan_set_arp_interval(intf, chan, (uint8_t *)argv[3]);
}
else if (strncmp(argv[2], "generate", 8) == 0) {
if (argc < 4)
lprintf(LOG_NOTICE, "lan set <channel> arp generate <on|off>");
else if (strncmp(argv[3], "on", 2) == 0)
rc = lan_set_arp_generate(intf, chan, 1);
else if (strncmp(argv[3], "off", 3) == 0)
rc = lan_set_arp_generate(intf, chan, 0);
else
lprintf(LOG_NOTICE, "lan set <channel> arp generate <on|off>");
}
else if (strncmp(argv[2], "respond", 7) == 0) {
if (argc < 4)
lprintf(LOG_NOTICE, "lan set <channel> arp respond <on|off>");
else if (strncmp(argv[3], "on", 2) == 0)
rc = lan_set_arp_respond(intf, chan, 1);
else if (strncmp(argv[3], "off", 3) == 0)
rc = lan_set_arp_respond(intf, chan, 0);
else
lprintf(LOG_NOTICE, "lan set <channel> arp respond <on|off>");
}
else {
lprintf(LOG_NOTICE,
"lan set <channel> arp respond <on|off>\n"
"lan set <channel> arp generate <on|off>\n"
"lan set <channel> arp interval <seconds>\n");
}
}
/* set authentication types */
else if (strncmp(argv[1], "auth", 4) == 0) {
if (argc < 3 || (strncmp(argv[2], "help", 4) == 0)) {
lprintf(LOG_NOTICE,
"lan set <channel> auth <level> <type,type,...>\n"
" level = CALLBACK, USER, OPERATOR, ADMIN\n"
" types = NONE, MD2, MD5, PASSWORD, OEM\n"
"example: lan set 7 auth ADMIN PASSWORD,MD5\n");
} else {
rc = ipmi_lan_set_auth(intf, chan, argv[2], argv[3]);
}
}
/* ip address source */
else if (strncmp(argv[1], "ipsrc", 5) == 0) {
if (argc < 3 || (strncmp(argv[2], "help", 4) == 0)) {
lprintf(LOG_NOTICE,
"lan set <channel> ipsrc <source>\n"
" none = unspecified\n"
" static = static address (manually configured)\n"
" dhcp = address obtained by BMC running DHCP\n"
" bios = address loaded by BIOS or system software\n");
return 0;
}
else if (strncmp(argv[2], "none", 4) == 0)
data[0] = 0;
else if (strncmp(argv[2], "static", 5) == 0)
data[0] = 1;
else if (strncmp(argv[2], "dhcp", 4) == 0)
data[0] = 2;
else if (strncmp(argv[2], "bios", 4) == 0)
data[0] = 3;
else {
lprintf(LOG_NOTICE,
"lan set <channel> ipsrc <source>\n"
" none = unspecified\n"
" static = static address (manually configured)\n"
" dhcp = address obtained by BMC running DHCP\n"
" bios = address loaded by BIOS or system software\n");
return -1;
}
rc = set_lan_param(intf, chan, IPMI_LANP_IP_ADDR_SRC, data, 1);
}
/* session password
* not strictly a lan setting, but its used for lan connections */
else if (strncmp(argv[1], "password", 8) == 0) {
rc = ipmi_lan_set_password(intf, 1, (uint8_t *)argv[2]);
}
/* snmp community string */
else if (strncmp(argv[1], "snmp", 4) == 0) {
if (argc < 3 || (strncmp(argv[2], "help", 4) == 0)) {
lprintf(LOG_NOTICE, "lan set <channel> snmp <community string>");
} else {
memcpy(data, argv[2], __min(strlen(argv[2]), 18));
printf("Setting LAN %s to %s\n",
ipmi_lan_params[IPMI_LANP_SNMP_STRING].desc, data);
rc = set_lan_param(intf, chan, IPMI_LANP_SNMP_STRING, data, 18);
}
}
/* ip address */
else if ((strncmp(argv[1], "ipaddr", 6) == 0) &&
(get_cmdline_ipaddr(argv[2], data) == 0)) {
printf("Setting LAN %s to %d.%d.%d.%d\n",
ipmi_lan_params[IPMI_LANP_IP_ADDR].desc,
data[0], data[1], data[2], data[3]);
rc = set_lan_param(intf, chan, IPMI_LANP_IP_ADDR, data, 4);
}
/* network mask */
else if ((strncmp(argv[1], "netmask", 7) == 0) &&
(get_cmdline_ipaddr(argv[2], data) == 0)) {
printf("Setting LAN %s to %d.%d.%d.%d\n",
ipmi_lan_params[IPMI_LANP_SUBNET_MASK].desc,
data[0], data[1], data[2], data[3]);
rc = set_lan_param(intf, chan, IPMI_LANP_SUBNET_MASK, data, 4);
}
/* mac address */
else if ((strncmp(argv[1], "macaddr", 7) == 0) &&
(get_cmdline_macaddr(argv[2], data) == 0)) {
printf("Setting LAN %s to %02x:%02x:%02x:%02x:%02x:%02x\n",
ipmi_lan_params[IPMI_LANP_MAC_ADDR].desc,
data[0], data[1], data[2], data[3], data[4], data[5]);
rc = set_lan_param(intf, chan, IPMI_LANP_MAC_ADDR, data, 6);
}
/* default gateway settings */
else if (strncmp(argv[1], "defgw", 5) == 0) {
if (argc < 4 || (strncmp(argv[2], "help", 4) == 0)) {
lprintf(LOG_NOTICE, "LAN set default gateway Commands: ipaddr, macaddr");
}
else if ((strncmp(argv[2], "ipaddr", 5) == 0) &&
(get_cmdline_ipaddr(argv[3], data) == 0)) {
printf("Setting LAN %s to %d.%d.%d.%d\n",
ipmi_lan_params[IPMI_LANP_DEF_GATEWAY_IP].desc,
data[0], data[1], data[2], data[3]);
rc = set_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_IP, data, 4);
}
else if ((strncmp(argv[2], "macaddr", 7) == 0) &&
(get_cmdline_macaddr(argv[3], data) == 0)) {
printf("Setting LAN %s to %02x:%02x:%02x:%02x:%02x:%02x\n",
ipmi_lan_params[IPMI_LANP_DEF_GATEWAY_MAC].desc,
data[0], data[1], data[2], data[3], data[4], data[5]);
rc = set_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_MAC, data, 6);
}
}
/* backup gateway settings */
else if (strncmp(argv[1], "bakgw", 5) == 0) {
if (argc < 4 || (strncmp(argv[2], "help", 4) == 0)) {
lprintf(LOG_NOTICE, "LAN set backup gateway commands: ipaddr, macaddr");
}
else if ((strncmp(argv[2], "ipaddr", 5) == 0) &&
(get_cmdline_ipaddr(argv[3], data) == 0)) {
printf("Setting LAN %s to %d.%d.%d.%d\n",
ipmi_lan_params[IPMI_LANP_BAK_GATEWAY_IP].desc,
data[0], data[1], data[2], data[3]);
rc = set_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP, data, 4);
}
else if ((strncmp(argv[2], "macaddr", 7) == 0) &&
(get_cmdline_macaddr(argv[3], data) == 0)) {
printf("Setting LAN %s to %02x:%02x:%02x:%02x:%02x:%02x\n",
ipmi_lan_params[IPMI_LANP_BAK_GATEWAY_MAC].desc,
data[0], data[1], data[2], data[3], data[4], data[5]);
rc = set_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_MAC, data, 6);
}
}
else if (strncasecmp(argv[1], "vlan", 4) == 0) {
if (argc < 4 || strncmp(argv[2], "help", 4) == 0) {
ipmi_lan_set_vlan_usage();
}
else if (strncasecmp(argv[2], "id", 2) == 0) {
if (strncasecmp(argv[3], "off", 3) == 0) {
ipmi_lan_set_vlan_id(intf, chan, NULL);
}
else {
ipmi_lan_set_vlan_id(intf, chan, argv[3]);
}
}
else if (strncasecmp(argv[2], "priority", 8) == 0) {
ipmi_lan_set_vlan_priority(intf, chan, argv[3]);
}
else {
ipmi_lan_set_vlan_usage();
}
}
/* set PEF alerting on or off */
else if (strncasecmp(argv[1], "alert", 5) == 0) {
if (argc < 3) {
lprintf(LOG_NOTICE, "LAN set alert must be 'on' or 'off'");
}
else if (strncasecmp(argv[2], "on", 2) == 0 ||
strncasecmp(argv[2], "enable", 6) == 0) {
printf("Enabling PEF alerts for LAN channel %d\n", chan);
rc = ipmi_set_alert_enable(intf, chan, 1);
}
else if (strncasecmp(argv[2], "off", 3) == 0 ||
strncasecmp(argv[2], "disable", 7) == 0) {
printf("Disabling PEF alerts for LAN channel %d\n", chan);
rc = ipmi_set_alert_enable(intf, chan, 0);
}
else {
lprintf(LOG_NOTICE, "LAN set alert must be 'on' or 'off'");
}
}
/* RMCP+ cipher suite privilege levels */
else if (strncmp(argv[1], "cipher_privs", 12) == 0)
{
if ((argc != 3) ||
(strncmp(argv[2], "help", 4) == 0) ||
get_cmdline_cipher_suite_priv_data(argv[2], data))
{
lprintf(LOG_NOTICE, "lan set <channel> cipher_privs XXXXXXXXXXXXXXX");
lprintf(LOG_NOTICE, " X = Cipher Suite Unused");
lprintf(LOG_NOTICE, " c = CALLBACK");
lprintf(LOG_NOTICE, " u = USER");
lprintf(LOG_NOTICE, " o = OPERATOR");
lprintf(LOG_NOTICE, " a = ADMIN");
lprintf(LOG_NOTICE, " O = OEM\n");
}
else
{
rc = set_lan_param(intf, chan, IPMI_LANP_RMCP_PRIV_LEVELS, data, 9);
}
}
else {
ipmi_lan_set_usage();
}
return rc;
}
static int
is_alert_destination(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
{
struct lan_param * p;
p = get_lan_param(intf, channel, IPMI_LANP_NUM_DEST);
if (p == NULL)
return 0;
if (p->data == NULL)
return 0;
if (alert <= (p->data[0] & 0xf))
return 1;
else
return 0;
}
static int
ipmi_lan_alert_print(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
{
struct lan_param * ptype, * paddr;
int isack = 0;
ptype = get_lan_param_select(intf, channel, IPMI_LANP_DEST_TYPE, alert);
paddr = get_lan_param_select(intf, channel, IPMI_LANP_DEST_ADDR, alert);
if (ptype == NULL || paddr == NULL)
return -1;
if (ptype->data == NULL || paddr->data == NULL)
return -1;
printf("%-24s: %d\n", "Alert Destination",
ptype->data[0]);
if (ptype->data[1] & 0x80)
isack = 1;
printf("%-24s: %s\n", "Alert Acknowledge",
isack ? "Acknowledged" : "Unacknowledged");
printf("%-24s: ", "Destination Type");
switch (ptype->data[1] & 0x7) {
case 0:
printf("PET Trap\n");
break;
case 6:
printf("OEM 1\n");
break;
case 7:
printf("OEM 2\n");
break;
default:
printf("Unknown\n");
break;
}
printf("%-24s: %d\n",
isack ? "Acknowledge Timeout" : "Retry Interval",
ptype->data[2]);
printf("%-24s: %d\n", "Number of Retries",
ptype->data[3] & 0x7);
if ((paddr->data[1] & 0xf0) != 0) {
/* unknown address format */
printf("\n");
return 0;
}
printf("%-24s: %s\n", "Alert Gateway",
(paddr->data[2] & 1) ? "Backup" : "Default");
printf("%-24s: %d.%d.%d.%d\n", "Alert IP Address",
paddr->data[3], paddr->data[4], paddr->data[5], paddr->data[6]);
printf("%-24s: %02x:%02x:%02x:%02x:%02x:%02x\n", "Alert MAC Address",
paddr->data[7], paddr->data[8], paddr->data[9],
paddr->data[10], paddr->data[11], paddr->data[12]);
printf("\n");
return 0;
}
static int
ipmi_lan_alert_print_all(struct ipmi_intf * intf, uint8_t channel)
{
int j, ndest;
struct lan_param * p;
p = get_lan_param(intf, channel, IPMI_LANP_NUM_DEST);
if (p == NULL)
return -1;
if (p->data == NULL)
return -1;
ndest = p->data[0] & 0xf;
for (j=0; j<=ndest; j++) {
ipmi_lan_alert_print(intf, channel, j);
}
return 0;
}
static void
ipmi_lan_alert_print_usage(void)
{
lprintf(LOG_NOTICE, "\nusage: lan alert print [channel] [alert]\n");
lprintf(LOG_NOTICE, "Default will print all alerts for the first found LAN channel");
}
static void
ipmi_lan_alert_set_usage(void)
{
lprintf(LOG_NOTICE, "\nusage: lan alert set <channel> <alert> <command> <option>\n");
lprintf(LOG_NOTICE, " ipaddr <x.x.x.x> Set alert IP address");
lprintf(LOG_NOTICE, " macaddr <x:x:x:x:x:x> Set alert MAC address");
lprintf(LOG_NOTICE, " gateway <default|backup> Set channel gateway to use for alerts");
lprintf(LOG_NOTICE, " ack <on|off> Set Alert Acknowledge on or off");
lprintf(LOG_NOTICE, " type <pet|oem1|oem2> Set destination type as PET or OEM");
lprintf(LOG_NOTICE, " time <seconds> Set ack timeout or unack retry interval");
lprintf(LOG_NOTICE, " retry <number> Set number of alert retries");
lprintf(LOG_NOTICE, "");
}
static int
ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
int argc, char ** argv)
{
struct lan_param * p;
uint8_t data[32], temp[32];
int rc = 0;
if (argc < 2) {
ipmi_lan_alert_set_usage();
return 0;
}
if (strncmp(argv[0], "help", 4) == 0 ||
strncmp(argv[1], "help", 4) == 0) {
ipmi_lan_alert_set_usage();
return 0;
}
memset(data, 0, sizeof(data));
memset(temp, 0, sizeof(temp));
/* alert destination ip address */
if (strncasecmp(argv[0], "ipaddr", 6) == 0 &&
(get_cmdline_ipaddr(argv[1], temp) == 0)) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
memcpy(data, p->data, p->data_len);
/* set new ipaddr */
memcpy(data+3, temp, 4);
printf("Setting LAN Alert %d IP Address to %d.%d.%d.%d\n", alert,
data[3], data[4], data[5], data[6]);
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
}
/* alert destination mac address */
else if (strncasecmp(argv[0], "macaddr", 7) == 0 &&
(get_cmdline_macaddr(argv[1], temp) == 0)) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
memcpy(data, p->data, p->data_len);
/* set new macaddr */
memcpy(data+7, temp, 6);
printf("Setting LAN Alert %d MAC Address to "
"%02x:%02x:%02x:%02x:%02x:%02x\n", alert,
data[7], data[8], data[9], data[10], data[11], data[12]);
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
}
/* alert destination gateway selector */
else if (strncasecmp(argv[0], "gateway", 7) == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
memcpy(data, p->data, p->data_len);
if (strncasecmp(argv[1], "def", 3) == 0 ||
strncasecmp(argv[1], "default", 7) == 0) {
printf("Setting LAN Alert %d to use Default Gateway\n", alert);
data[2] = 0;
}
else if (strncasecmp(argv[1], "bak", 3) == 0 ||
strncasecmp(argv[1], "backup", 6) == 0) {
printf("Setting LAN Alert %d to use Backup Gateway\n", alert);
data[2] = 1;
}
else {
ipmi_lan_alert_set_usage();
return -1;
}
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
}
/* alert acknowledgement */
else if (strncasecmp(argv[0], "ack", 3) == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
memcpy(data, p->data, p->data_len);
if (strncasecmp(argv[1], "on", 2) == 0 ||
strncasecmp(argv[1], "yes", 3) == 0) {
printf("Setting LAN Alert %d to Acknowledged\n", alert);
data[1] |= 0x80;
}
else if (strncasecmp(argv[1], "off", 3) == 0 ||
strncasecmp(argv[1], "no", 2) == 0) {
printf("Setting LAN Alert %d to Unacknowledged\n", alert);
data[1] &= ~0x80;
}
else {
ipmi_lan_alert_set_usage();
return -1;
}
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
}
/* alert destination type */
else if (strncasecmp(argv[0], "type", 4) == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
memcpy(data, p->data, p->data_len);
if (strncasecmp(argv[1], "pet", 3) == 0) {
printf("Setting LAN Alert %d destination to PET Trap\n", alert);
data[1] &= ~0x07;
}
else if (strncasecmp(argv[1], "oem1", 4) == 0) {
printf("Setting LAN Alert %d destination to OEM 1\n", alert);
data[1] &= ~0x07;
data[1] |= 0x06;
}
else if (strncasecmp(argv[1], "oem2", 4) == 0) {
printf("Setting LAN Alert %d destination to OEM 2\n", alert);
data[1] |= 0x07;
}
else {
ipmi_lan_alert_set_usage();
return -1;
}
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
}
/* alert acknowledge timeout or retry interval */
else if (strncasecmp(argv[0], "time", 4) == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
memcpy(data, p->data, p->data_len);
data[2] = (uint8_t)strtol(argv[1], NULL, 0);
printf("Setting LAN Alert %d timeout/retry to %d seconds\n", alert, data[2]);
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
}
/* number of retries */
else if (strncasecmp(argv[0], "retry", 5) == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
memcpy(data, p->data, p->data_len);
data[3] = ((uint8_t)strtol(argv[1], NULL, 0)) & 0x7;
printf("Setting LAN Alert %d number of retries to %d\n", alert, data[3]);
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
}
else {
ipmi_lan_alert_set_usage();
return -1;
}
return rc;
}
static int
ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
{
uint8_t alert;
uint8_t channel = 1;
if (argc < 1 ||
strncasecmp(argv[0], "help", 4) == 0) {
ipmi_lan_alert_print_usage();
ipmi_lan_alert_set_usage();
return 0;
}
/* alert print [channel] [alert] */
if (strncasecmp(argv[0], "print", 5) == 0) {
if (argc < 2) {
channel = find_lan_channel(intf, 1);
if (is_lan_channel(intf, channel) == 0) {
lprintf(LOG_ERR, "Channel %d is not a LAN channel", channel);
return -1;
}
return ipmi_lan_alert_print_all(intf, channel);
}
if (strncasecmp(argv[1], "help", 4) == 0) {
ipmi_lan_alert_print_usage();
return 0;
}
channel = (uint8_t)strtol(argv[1], NULL, 0);
if (is_lan_channel(intf, channel) == 0) {
lprintf(LOG_ERR, "Channel %d is not a LAN channel", channel);
return -1;
}
if (argc < 3)
return ipmi_lan_alert_print_all(intf, channel);
alert = (uint8_t)strtol(argv[2], NULL, 0);
if (is_alert_destination(intf, channel, alert) == 0) {
lprintf(LOG_ERR, "Alert %d is not a valid destination", alert);
return -1;
}
return ipmi_lan_alert_print(intf, channel, alert);
}
/* alert set <channel> <alert> [option] */
if (strncasecmp(argv[0], "set", 3) == 0) {
if (argc < 5 || strncasecmp(argv[1], "help", 4) == 0) {
ipmi_lan_alert_set_usage();
return 0;
}
channel = (uint8_t)strtol(argv[1], NULL, 0);
if (is_lan_channel(intf, channel) == 0) {
lprintf(LOG_ERR, "Channel %d is not a LAN channel", channel);
return -1;
}
alert = (uint8_t)strtol(argv[2], NULL, 0);
if (is_alert_destination(intf, channel, alert) == 0) {
lprintf(LOG_ERR, "Alert %d is not a valid destination", alert);
return -1;
}
return ipmi_lan_alert_set(intf, channel, alert, argc-3, &(argv[3]));
}
return 0;
}
static int
ipmi_lan_stats_get(struct ipmi_intf * intf, uint8_t chan)
{
uint8_t medium;
int rc = 0;
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t msg_data[2];
uint16_t statsTemp;
if (chan < 1 || chan > IPMI_CHANNEL_NUMBER_MAX) {
lprintf(LOG_ERR, "Invalid Channel %d", chan);
return -1;
}
/* find type of channel and only accept 802.3 LAN */
medium = ipmi_get_channel_medium(intf, chan);
if (medium != IPMI_CHANNEL_MEDIUM_LAN &&
medium != IPMI_CHANNEL_MEDIUM_LAN_OTHER) {
lprintf(LOG_ERR, "Channel %d (%s) is not a LAN channel",
chan, val2str(medium, ipmi_channel_medium_vals), medium);
return -1;
}
/* From here, we are ready to get the stats */
msg_data[0] = chan;
msg_data[1] = 0; /* Don't clear */
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_TRANSPORT;
req.msg.cmd = IPMI_LAN_GET_STAT;
req.msg.data = msg_data;
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_INFO, "Get LAN Stats command failed");
return 0;
}
if (rsp->ccode > 0) {
lprintf(LOG_INFO, "Get LAN Stats command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return 0;
}
if (verbose > 1) {
uint8_t counter;
printf("--- Rx Stats ---\n");
for (counter=0; counter<18; counter+=2) {
printf("%02X", *(rsp->data + counter));
printf(" %02X - ", *(rsp->data + counter+1));
}
printf("\n");
}
statsTemp = ((*(rsp->data + 0)) << 8) | (*(rsp->data + 1));
printf("IP Rx Packet : %d\n", statsTemp);
statsTemp = ((*(rsp->data + 2)) << 8) | (*(rsp->data + 3));
printf("IP Rx Header Errors : %u\n", statsTemp);
statsTemp = ((*(rsp->data + 4)) << 8) | (*(rsp->data + 5));
printf("IP Rx Address Errors : %u\n", statsTemp);
statsTemp = ((*(rsp->data + 6)) << 8) | (*(rsp->data + 7));
printf("IP Rx Fragmented : %u\n", statsTemp);
statsTemp = ((*(rsp->data + 8)) << 8) | (*(rsp->data + 9));
printf("IP Tx Packet : %u\n", statsTemp);
statsTemp = ((*(rsp->data +10)) << 8) | (*(rsp->data +11));
printf("UDP Rx Packet : %u\n", statsTemp);
statsTemp = ((*(rsp->data + 12)) << 8) | (*(rsp->data + 13));
printf("RMCP Rx Valid : %u\n", statsTemp);
statsTemp = ((*(rsp->data + 14)) << 8) | (*(rsp->data + 15));
printf("UDP Proxy Packet Received : %u\n", statsTemp);
statsTemp = ((*(rsp->data + 16)) << 8) | (*(rsp->data + 17));
printf("UDP Proxy Packet Dropped : %u\n", statsTemp);
return rc;
}
static int
ipmi_lan_stats_clear(struct ipmi_intf * intf, uint8_t chan)
{
uint8_t medium;
int rc = 0;
struct ipmi_rs * rsp;
struct ipmi_rq req;
uint8_t msg_data[2];
if (chan < 1 || chan > IPMI_CHANNEL_NUMBER_MAX) {
lprintf(LOG_ERR, "Invalid Channel %d", chan);
return -1;
}
/* find type of channel and only accept 802.3 LAN */
medium = ipmi_get_channel_medium(intf, chan);
if (medium != IPMI_CHANNEL_MEDIUM_LAN &&
medium != IPMI_CHANNEL_MEDIUM_LAN_OTHER) {
lprintf(LOG_ERR, "Channel %d (%s) is not a LAN channel",
chan, val2str(medium, ipmi_channel_medium_vals), medium);
return -1;
}
/* From here, we are ready to get the stats */
msg_data[0] = chan;
msg_data[1] = 1; /* Clear */
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_TRANSPORT;
req.msg.cmd = IPMI_LAN_GET_STAT;
req.msg.data = msg_data;
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
if (rsp == NULL) {
lprintf(LOG_INFO, "Get LAN Stats command failed");
return 0;
}
if (rsp->ccode > 0) {
lprintf(LOG_INFO, "Get LAN Stats command failed: %s",
val2str(rsp->ccode, completion_code_vals));
return 0;
}
return rc;
}
/*
* print_lan_usage
*/
static void
print_lan_usage(void)
{
lprintf(LOG_NOTICE, "LAN Commands:");
lprintf(LOG_NOTICE, " print [<channel number>]");
lprintf(LOG_NOTICE, " set [<channel number>]");
lprintf(LOG_NOTICE, " alert [<channel number>]");
lprintf(LOG_NOTICE, " stats get [<channel number>]");
lprintf(LOG_NOTICE, " stats clear [<channel number>]");
}
int
ipmi_lanp_main(struct ipmi_intf * intf, int argc, char ** argv)
{
int rc = 0;
uint8_t chan = find_lan_channel(intf, 1);
if (argc == 0 || (strncmp(argv[0], "help", 4) == 0)) {
print_lan_usage();
return -1;
}
if (strncmp(argv[0], "printconf", 9) == 0 ||
strncmp(argv[0], "print", 5) == 0)
{
if (argc > 1)
chan = (uint8_t)strtol(argv[1], NULL, 0);
if (chan < 1 || chan > IPMI_CHANNEL_NUMBER_MAX)
{
lprintf(LOG_ERR, "Invalid channel: %d", chan);
return -1;
}
else
rc = ipmi_lan_print(intf, chan);
}
else if (strncmp(argv[0], "set", 3) == 0)
{
rc = ipmi_lan_set(intf, argc-1, &(argv[1]));
}
else if (strncmp(argv[0], "alert", 5) == 0)
{
rc = ipmi_lan_alert(intf, argc-1, &(argv[1]));
}
else if (strncmp(argv[0], "stats", 5) == 0)
{
if(argc == 1)
{
print_lan_usage();
return -1;
}
else if (argc > 2)
chan = (uint8_t)strtol(argv[2], NULL, 0);
if (chan < 1 || chan > IPMI_CHANNEL_NUMBER_MAX)
{
lprintf(LOG_ERR, "Invalid channel: %d", chan);
return -1;
}
else if (strncmp(argv[1], "get", 3) == 0)
rc = ipmi_lan_stats_get(intf, chan);
else if (strncmp(argv[1], "clear", 5) == 0)
rc = ipmi_lan_stats_clear(intf, chan);
else
print_lan_usage();
}
else
{
lprintf(LOG_NOTICE, "Invalid LAN command: %s", argv[0]);
rc = -1;
}
return rc;
}
|