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
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
|
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
include ../Makefile.lib
HDRS= libipmi.h
HDRDIR= common
# Hammerhead: amd64-only
SUBDIRS = $(MACH64)
all : TARGET= all
clean : TARGET= clean
clobber : TARGET= clobber
install : TARGET= install
.KEEP_STATE:
all clean clobber install: $(SUBDIRS)
install_h: $(ROOTHDRS)
check: $(CHECKHDRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
FRC:
include ../Makefile.targ
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
LIBRARY= libipmi.a
VERS= .1
OBJECTS= ipmi_bmc.o \
ipmi_entity.o \
ipmi_event.o \
ipmi_fru.o \
ipmi_hash.o \
ipmi_lan.o \
ipmi_lancfg.o \
ipmi_list.o \
ipmi_misc.o \
ipmi_sdr.o \
ipmi_sel.o \
ipmi_sensor.o \
ipmi_sunoem.o \
ipmi_tables.o \
ipmi_user.o \
ipmi_util.o \
libipmi.o
include ../../Makefile.lib
LIBS= $(DYNLIB)
SRCDIR= ../common
CLEANFILES += $(SRCDIR)/ipmi_tables.c
INCS += -I$(SRCDIR)
LDLIBS += -lc -lm -lnvpair -lsocket -lnsl
CPPFLAGS += $(INCS)
CSTD = $(CSTD_GNU99)
CERRWARN += $(CNOWARN_UNINIT)
.KEEP_STATE:
all: $(LIBS)
$(SRCDIR)/ipmi_tables.c: $(SRCDIR)/mktables.sh $(SRCDIR)/libipmi.h
$(KSH93) $(SRCDIR)/mktables.sh $(SRCDIR)/libipmi.h > $@
include ../../Makefile.targ
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#ident "%Z%%M% %I% %E% SMI"
include ../Makefile.com
include ../../Makefile.lib.64
install: all $(ROOTLIBS64) $(ROOTLINKS64)
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2012 Joyent, Inc. All rights reserved.
*/
#include <errno.h>
#include <fcntl.h>
#include <libipmi.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stropts.h>
#include <unistd.h>
#include <sys/ipmi.h>
#include "ipmi_impl.h"
/*
* IPMI transport for the local BMC at /dev/ipmi0.
*/
typedef struct ipmi_bmc {
ipmi_handle_t *ib_ihp; /* ipmi handle */
int ib_fd; /* /dev/ipmi0 filedescriptor */
uint32_t ib_msgseq; /* message sequence number */
uint8_t *ib_msg; /* message buffer */
size_t ib_msglen; /* size of message buffer */
} ipmi_bmc_t;
#define BMC_DEV "/dev/ipmi0"
static void
ipmi_bmc_close(void *data)
{
ipmi_bmc_t *ibp = data;
ipmi_free(ibp->ib_ihp, ibp->ib_msg);
(void) close(ibp->ib_fd);
ipmi_free(ibp->ib_ihp, ibp);
}
/*ARGSUSED*/
static void *
ipmi_bmc_open(ipmi_handle_t *ihp, nvlist_t *params)
{
ipmi_bmc_t *ibp;
if ((ibp = ipmi_zalloc(ihp, sizeof (ipmi_bmc_t))) == NULL)
return (NULL);
ibp->ib_ihp = ihp;
/* open /dev/ipmi0 */
if ((ibp->ib_fd = open(BMC_DEV, O_RDWR)) < 0) {
ipmi_free(ihp, ibp);
(void) ipmi_set_error(ihp, EIPMI_BMC_OPEN_FAILED, "%s",
strerror(errno));
return (NULL);
}
if ((ibp->ib_msg = (uint8_t *)ipmi_zalloc(ihp, BUFSIZ)) == NULL) {
ipmi_bmc_close(ibp);
return (NULL);
}
ibp->ib_msglen = BUFSIZ;
return (ibp);
}
static int
ipmi_bmc_send(void *data, ipmi_cmd_t *cmd, ipmi_cmd_t *response,
int *completion)
{
ipmi_bmc_t *ibp = data;
struct ipmi_req req;
struct ipmi_recv recv;
struct ipmi_addr addr;
fd_set rset;
struct ipmi_system_interface_addr bmc_addr;
bmc_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
bmc_addr.channel = IPMI_BMC_CHANNEL;
bmc_addr.lun = cmd->ic_lun;
(void) memset(&req, 0, sizeof (struct ipmi_req));
req.addr = (unsigned char *) &bmc_addr;
req.addr_len = sizeof (bmc_addr);
req.msgid = ibp->ib_msgseq++;
req.msg.netfn = cmd->ic_netfn;
req.msg.cmd = cmd->ic_cmd;
req.msg.data = cmd->ic_data;
req.msg.data_len = cmd->ic_dlen;
if (ioctl(ibp->ib_fd, IPMICTL_SEND_COMMAND, &req) < 0) {
(void) ipmi_set_error(ibp->ib_ihp, EIPMI_BMC_PUTMSG, "%s",
strerror(errno));
return (-1);
}
/* get the response from the BMC */
FD_ZERO(&rset);
FD_SET(ibp->ib_fd, &rset);
if (select(ibp->ib_fd + 1, &rset, NULL, NULL, NULL) < 0) {
(void) ipmi_set_error(ibp->ib_ihp, EIPMI_BMC_GETMSG, "%s",
strerror(errno));
return (-1);
}
if (FD_ISSET(ibp->ib_fd, &rset) == 0) {
(void) ipmi_set_error(ibp->ib_ihp, EIPMI_BMC_GETMSG, "%s",
"No data available");
return (-1);
}
recv.addr = (unsigned char *) &addr;
recv.addr_len = sizeof (addr);
recv.msg.data = (unsigned char *)ibp->ib_msg;
recv.msg.data_len = ibp->ib_msglen;
/* get data */
if (ioctl(ibp->ib_fd, IPMICTL_RECEIVE_MSG_TRUNC, &recv) < 0) {
(void) ipmi_set_error(ibp->ib_ihp, EIPMI_BMC_GETMSG, "%s",
strerror(errno));
return (-1);
}
if (recv.recv_type != IPMI_RESPONSE_RECV_TYPE) {
(void) ipmi_set_error(ibp->ib_ihp, EIPMI_BMC_RESPONSE,
"unknown BMC message type %d", recv.recv_type);
return (-1);
}
response->ic_netfn = recv.msg.netfn;
/* The lun is not returned in addr, return the lun passed in */
response->ic_lun = cmd->ic_lun;
response->ic_cmd = recv.msg.cmd;
if (recv.msg.data[0] != 0) {
*completion = recv.msg.data[0];
response->ic_dlen = 0;
response->ic_data = NULL;
} else {
*completion = 0;
response->ic_dlen = (recv.msg.data_len > 0) ?
recv.msg.data_len - 1 : 0;
response->ic_data = &(recv.msg.data[1]);
}
return (0);
}
ipmi_transport_t ipmi_transport_bmc = {
ipmi_bmc_open,
ipmi_bmc_close,
ipmi_bmc_send
};
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* IPMI entities are a strange beast. A reasonable assumption for those
* unfamiliar with the spec would be that there was a command to iterate over
* all entities, and a command to iterate over sensors associated with each
* entity. Instead, the entire IPMI world is derived from the SDR repository.
* Entities only exist in the sense that they are referenced by a SDR record.
*
* In addition, entities can be associated into groups, and determining entity
* presence is quite complicated. The IPMI spec dedicates an entire chapter
* (40) to the process of handling sensor associations.
*
* The above logic is implemented via the ipmi_entity_present() function. We
* make a first pass over the SDR repository to discover entities, creating
* entity groups and associating SDR records with the each.
*
* We don't currently support device-relative entities.
*/
#include <libipmi.h>
#include <ipmi_impl.h>
#include <stddef.h>
typedef struct ipmi_entity_sdr {
ipmi_list_t ies_list;
const char *ies_name;
ipmi_sdr_t *ies_sdr;
} ipmi_entity_sdr_t;
typedef struct ipmi_entity_impl {
ipmi_list_t ie_list;
ipmi_entity_t ie_entity;
struct ipmi_entity_impl *ie_parent;
ipmi_hash_link_t ie_link;
ipmi_list_t ie_child_list;
ipmi_list_t ie_sdr_list;
} ipmi_entity_impl_t;
#define ENTITY_TO_IMPL(ep) \
((ipmi_entity_impl_t *)((char *)(ep) - \
offsetof(ipmi_entity_impl_t, ie_entity)))
static int
ipmi_entity_add_assoc(ipmi_handle_t *ihp, ipmi_entity_impl_t *eip,
uint8_t id, uint8_t instance)
{
ipmi_entity_impl_t *cp;
ipmi_entity_t search;
search.ie_type = id;
search.ie_instance = instance;
if ((cp = ipmi_hash_lookup(ihp->ih_entities, &search)) == NULL) {
if ((cp = ipmi_zalloc(ihp,
sizeof (ipmi_entity_impl_t))) == NULL)
return (-1);
cp->ie_entity.ie_type = id;
cp->ie_entity.ie_instance = instance;
ipmi_hash_insert(ihp->ih_entities, cp);
}
if (cp->ie_parent != NULL) {
/*
* This should never happen. However, we want to be tolerant of
* pathologically broken IPMI implementations, so we ignore this
* error, and the first parent wins.
*/
return (0);
}
cp->ie_parent = eip;
ipmi_list_append(&eip->ie_child_list, cp);
eip->ie_entity.ie_children++;
return (0);
}
static int
ipmi_entity_sdr_parse(ipmi_sdr_t *sdrp, uint8_t *id, uint8_t *instance,
boolean_t *logical)
{
switch (sdrp->is_type) {
case IPMI_SDR_TYPE_FULL_SENSOR:
{
ipmi_sdr_full_sensor_t *fsp =
(ipmi_sdr_full_sensor_t *)sdrp->is_record;
*id = fsp->is_fs_entity_id;
*instance = fsp->is_fs_entity_instance;
*logical = fsp->is_fs_entity_logical;
break;
}
case IPMI_SDR_TYPE_COMPACT_SENSOR:
{
ipmi_sdr_compact_sensor_t *csp =
(ipmi_sdr_compact_sensor_t *)sdrp->is_record;
*id = csp->is_cs_entity_id;
*instance = csp->is_cs_entity_instance;
*logical = csp->is_cs_entity_logical;
break;
}
case IPMI_SDR_TYPE_EVENT_ONLY:
{
ipmi_sdr_event_only_t *eop =
(ipmi_sdr_event_only_t *)sdrp->is_record;
*id = eop->is_eo_entity_id;
*instance = eop->is_eo_entity_instance;
*logical = eop->is_eo_entity_logical;
break;
}
case IPMI_SDR_TYPE_ENTITY_ASSOCIATION:
{
ipmi_sdr_entity_association_t *eap =
(ipmi_sdr_entity_association_t *)sdrp->is_record;
*id = eap->is_ea_entity_id;
*instance = eap->is_ea_entity_instance;
*logical = B_TRUE;
break;
}
case IPMI_SDR_TYPE_GENERIC_LOCATOR:
{
ipmi_sdr_generic_locator_t *glp =
(ipmi_sdr_generic_locator_t *)sdrp->is_record;
*id = glp->is_gl_entity;
*instance = glp->is_gl_instance;
*logical = B_FALSE;
break;
}
case IPMI_SDR_TYPE_FRU_LOCATOR:
{
ipmi_sdr_fru_locator_t *flp =
(ipmi_sdr_fru_locator_t *)sdrp->is_record;
*id = flp->is_fl_entity;
*instance = flp->is_fl_instance;
*logical = B_FALSE;
break;
}
case IPMI_SDR_TYPE_MANAGEMENT_LOCATOR:
{
ipmi_sdr_management_locator_t *mlp =
(ipmi_sdr_management_locator_t *)sdrp->is_record;
*id = mlp->is_ml_entity_id;
*instance = mlp->is_ml_entity_instance;
*logical = B_FALSE;
break;
}
default:
return (-1);
}
return (0);
}
/*
* This function is responsible for gathering all entities, inserting them into
* the global hash, and establishing any associations.
*/
/*ARGSUSED*/
static int
ipmi_entity_visit(ipmi_handle_t *ihp, const char *name, ipmi_sdr_t *sdrp,
void *unused)
{
uint8_t id, instance;
boolean_t logical;
ipmi_entity_t search;
ipmi_entity_impl_t *eip;
ipmi_entity_sdr_t *esp;
if (ipmi_entity_sdr_parse(sdrp, &id, &instance, &logical) != 0)
return (0);
search.ie_type = id;
search.ie_instance = instance;
if ((eip = ipmi_hash_lookup(ihp->ih_entities, &search)) == NULL) {
if ((eip = ipmi_zalloc(ihp,
sizeof (ipmi_entity_impl_t))) == NULL)
return (-1);
eip->ie_entity.ie_type = id;
eip->ie_entity.ie_instance = instance;
ipmi_hash_insert(ihp->ih_entities, eip);
}
eip->ie_entity.ie_logical |= logical;
if (sdrp->is_type == IPMI_SDR_TYPE_ENTITY_ASSOCIATION) {
uint8_t start, end;
uint8_t i, type;
ipmi_sdr_entity_association_t *eap =
(ipmi_sdr_entity_association_t *)sdrp->is_record;
if (eap->is_ea_range) {
type = eap->is_ea_sub[0].is_ea_sub_id;
start = eap->is_ea_sub[0].is_ea_sub_instance;
end = eap->is_ea_sub[1].is_ea_sub_instance;
if (type != 0) {
for (i = start; i <= end; i++) {
if (ipmi_entity_add_assoc(ihp, eip,
type, i) != 0)
return (-1);
}
}
type = eap->is_ea_sub[2].is_ea_sub_id;
start = eap->is_ea_sub[2].is_ea_sub_instance;
end = eap->is_ea_sub[3].is_ea_sub_instance;
if (type != 0) {
for (i = start; i <= end; i++) {
if (ipmi_entity_add_assoc(ihp, eip,
type, i) != 0)
return (-1);
}
}
} else {
for (i = 0; i < 4; i++) {
type = eap->is_ea_sub[i].is_ea_sub_id;
instance = eap->is_ea_sub[i].is_ea_sub_instance;
if (type == 0)
continue;
if (ipmi_entity_add_assoc(ihp, eip, type,
instance) != 0)
return (-1);
}
}
} else {
if ((esp = ipmi_zalloc(ihp,
sizeof (ipmi_entity_sdr_t))) == NULL)
return (-1);
esp->ies_sdr = sdrp;
esp->ies_name = name;
ipmi_list_append(&eip->ie_sdr_list, esp);
}
return (0);
}
/*
* Given a SDR record, return boolean values indicating whether the sensor
* indicates explicit presence.
*
* XXX this should really share code with entity_present()
*/
int
ipmi_entity_present_sdr(ipmi_handle_t *ihp, ipmi_sdr_t *sdrp,
boolean_t *valp)
{
uint16_t mask;
uint8_t number, sensor_type, reading_type;
ipmi_sdr_compact_sensor_t *csp;
ipmi_sdr_full_sensor_t *fsp;
ipmi_sensor_reading_t *srp;
switch (sdrp->is_type) {
case IPMI_SDR_TYPE_COMPACT_SENSOR:
csp = (ipmi_sdr_compact_sensor_t *)sdrp->is_record;
number = csp->is_cs_number;
sensor_type = csp->is_cs_type;
reading_type = csp->is_cs_reading_type;
break;
case IPMI_SDR_TYPE_FULL_SENSOR:
fsp = (ipmi_sdr_full_sensor_t *)sdrp->is_record;
number = fsp->is_fs_number;
sensor_type = fsp->is_fs_type;
reading_type = fsp->is_fs_reading_type;
break;
default:
*valp = B_FALSE;
return (0);
}
switch (reading_type) {
case IPMI_RT_PRESENT:
mask = IPMI_SR_PRESENT_ASSERT;
break;
case IPMI_RT_SPECIFIC:
switch (sensor_type) {
case IPMI_ST_PROCESSOR:
mask = IPMI_EV_PROCESSOR_PRESENT;
break;
case IPMI_ST_POWER_SUPPLY:
mask = IPMI_EV_POWER_SUPPLY_PRESENT;
break;
case IPMI_ST_MEMORY:
mask = IPMI_EV_MEMORY_PRESENT;
break;
case IPMI_ST_BAY:
mask = IPMI_EV_BAY_PRESENT;
break;
default:
*valp = B_FALSE;
return (0);
}
break;
default:
*valp = B_FALSE;
return (0);
}
/*
* If we've reached here, then we have a dedicated sensor that
* indicates presence.
*/
if ((srp = ipmi_get_sensor_reading(ihp, number)) == NULL) {
if (ipmi_errno(ihp) == EIPMI_NOT_PRESENT) {
*valp = B_FALSE;
return (0);
}
return (-1);
}
*valp = (srp->isr_state & mask) != 0;
return (0);
}
/*
* This function follows the procedure documented in section 40 of the spec.
* To quote the conclusion from section 40.2:
*
* Thus, the steps to detecting an Entity are:
*
* a) Scan the SDRs for sensors associated with the entity.
*
* b) If there is an active sensor that includes a presence bit, or the
* entity has an active Entity Presence sensor, use the sensor to
* determine the presence of the entity.
*
* c) Otherwise, check to see that there is at least one active sensor
* associated with the entity. Do this by doing 'Get Sensor Readings'
* to the sensors associated with the entity until a scanning sensor is
* found.
*
* d) If there are no active sensors directly associated with the entity,
* check the SDRs to see if the entity is a container entity in an
* entity-association. If so, check to see if any of the contained
* entities are present, if so, assume the container entity exists.
* Note that this may need to be iterative, since it's possible to have
* multi-level entity associations.
*
* e) If there are no active sensors for the entity, and the entity is not
* the container entity in an active entity-assocation, then the entity
* is present if (sic) there there is a FRU device for the entity, and
* the FRU device is present.
*
* It should not be considered an error if a FRU device locator record is
* present for a FRU device, but the FRU device is not there.
*
*/
int
ipmi_entity_present(ipmi_handle_t *ihp, ipmi_entity_t *ep, boolean_t *valp)
{
/* LINTED - alignment */
ipmi_entity_impl_t *eip = ENTITY_TO_IMPL(ep);
ipmi_entity_impl_t *cp;
ipmi_entity_sdr_t *esp;
ipmi_sdr_t *sdrp;
uint16_t mask;
uint8_t number, sensor_type, reading_type;
ipmi_sensor_reading_t *srp;
ipmi_sdr_compact_sensor_t *csp;
ipmi_sdr_full_sensor_t *fsp;
ipmi_sdr_fru_locator_t *frup;
char *frudata;
/*
* Search the sensors for a present sensor or a discrete sensor that
* indicates presence.
*/
for (esp = ipmi_list_next(&eip->ie_sdr_list); esp != NULL;
esp = ipmi_list_next(esp)) {
sdrp = esp->ies_sdr;
switch (sdrp->is_type) {
case IPMI_SDR_TYPE_COMPACT_SENSOR:
csp = (ipmi_sdr_compact_sensor_t *)sdrp->is_record;
number = csp->is_cs_number;
sensor_type = csp->is_cs_type;
reading_type = csp->is_cs_reading_type;
break;
case IPMI_SDR_TYPE_FULL_SENSOR:
fsp = (ipmi_sdr_full_sensor_t *)sdrp->is_record;
number = fsp->is_fs_number;
sensor_type = fsp->is_fs_type;
reading_type = fsp->is_fs_reading_type;
break;
default:
continue;
}
switch (reading_type) {
case IPMI_RT_PRESENT:
mask = IPMI_SR_PRESENT_ASSERT;
break;
case IPMI_RT_SPECIFIC:
switch (sensor_type) {
case IPMI_ST_PROCESSOR:
mask = IPMI_EV_PROCESSOR_PRESENT;
break;
case IPMI_ST_POWER_SUPPLY:
mask = IPMI_EV_POWER_SUPPLY_PRESENT;
break;
case IPMI_ST_MEMORY:
mask = IPMI_EV_MEMORY_PRESENT;
break;
case IPMI_ST_BAY:
mask = IPMI_EV_BAY_PRESENT;
break;
default:
continue;
}
break;
default:
continue;
}
/*
* If we've reached here, then we have a dedicated sensor that
* indicates presence.
*/
if ((srp = ipmi_get_sensor_reading(ihp, number)) == NULL) {
if (ipmi_errno(ihp) == EIPMI_NOT_PRESENT) {
*valp = B_FALSE;
return (0);
}
return (-1);
}
*valp = (srp->isr_state & mask) != 0;
return (0);
}
/*
* No explicit presence sensor was found. See if there is at least one
* active sensor associated with the entity.
*/
for (esp = ipmi_list_next(&eip->ie_sdr_list); esp != NULL;
esp = ipmi_list_next(esp)) {
sdrp = esp->ies_sdr;
switch (sdrp->is_type) {
case IPMI_SDR_TYPE_COMPACT_SENSOR:
csp = (ipmi_sdr_compact_sensor_t *)sdrp->is_record;
number = csp->is_cs_number;
break;
case IPMI_SDR_TYPE_FULL_SENSOR:
fsp = (ipmi_sdr_full_sensor_t *)sdrp->is_record;
number = fsp->is_fs_number;
break;
default:
continue;
}
if ((srp = ipmi_get_sensor_reading(ihp, number)) == NULL) {
if (ipmi_errno(ihp) == EIPMI_NOT_PRESENT)
continue;
return (-1);
}
if (srp->isr_scanning_enabled) {
*valp = B_TRUE;
return (0);
}
}
/*
* If this entity has children, then it is present if any of its
* children are present.
*/
for (cp = ipmi_list_next(&eip->ie_child_list); cp != NULL;
cp = ipmi_list_next(cp)) {
if (ipmi_entity_present(ihp, &cp->ie_entity, valp) != 0)
return (-1);
if (*valp)
return (0);
}
/*
* If the FRU device is present, then the entity is present.
*/
for (esp = ipmi_list_next(&eip->ie_sdr_list); esp != NULL;
esp = ipmi_list_next(esp)) {
sdrp = esp->ies_sdr;
if (sdrp->is_type != IPMI_SDR_TYPE_FRU_LOCATOR)
continue;
frup = (ipmi_sdr_fru_locator_t *)sdrp->is_record;
if (ipmi_fru_read(ihp, frup, &frudata) >= 0) {
ipmi_free(ihp, frudata);
*valp = B_TRUE;
return (0);
}
if (ipmi_errno(ihp) != EIPMI_NOT_PRESENT)
return (-1);
}
*valp = B_FALSE;
return (0);
}
static int
ipmi_entity_refresh(ipmi_handle_t *ihp)
{
if (ipmi_hash_first(ihp->ih_entities) != NULL &&
!ipmi_sdr_changed(ihp))
return (0);
if (ipmi_sdr_iter(ihp, ipmi_entity_visit, NULL) != 0)
return (-1);
return (0);
}
int
ipmi_entity_iter(ipmi_handle_t *ihp, int (*func)(ipmi_handle_t *,
ipmi_entity_t *, void *), void *data)
{
ipmi_entity_impl_t *eip;
int ret;
if (ipmi_entity_refresh(ihp) != 0)
return (-1);
for (eip = ipmi_hash_first(ihp->ih_entities); eip != NULL;
eip = ipmi_hash_next(ihp->ih_entities, eip)) {
if (eip->ie_parent != NULL)
continue;
if ((ret = func(ihp, &eip->ie_entity, data)) != 0)
return (ret);
}
return (0);
}
int
ipmi_entity_iter_sdr(ipmi_handle_t *ihp, ipmi_entity_t *ep,
int (*func)(ipmi_handle_t *, ipmi_entity_t *, const char *, ipmi_sdr_t *,
void *), void *data)
{
/* LINTED - alignment */
ipmi_entity_impl_t *eip = ENTITY_TO_IMPL(ep);
ipmi_entity_sdr_t *isp;
int ret;
for (isp = ipmi_list_next(&eip->ie_sdr_list); isp != NULL;
isp = ipmi_list_next(isp)) {
if ((ret = func(ihp, ep, isp->ies_name,
isp->ies_sdr, data)) != 0)
return (ret);
}
return (0);
}
int
ipmi_entity_iter_children(ipmi_handle_t *ihp, ipmi_entity_t *ep,
int (*func)(ipmi_handle_t *, ipmi_entity_t *, void *), void *data)
{
/* LINTED - alignment */
ipmi_entity_impl_t *eip = ENTITY_TO_IMPL(ep);
ipmi_entity_impl_t *cp;
int ret;
for (cp = ipmi_list_next(&eip->ie_child_list); cp != NULL;
cp = ipmi_list_next(cp)) {
if ((ret = func(ihp, &cp->ie_entity, data)) != 0)
return (ret);
}
return (0);
}
ipmi_entity_t *
ipmi_entity_parent(ipmi_handle_t *ihp, ipmi_entity_t *ep)
{
/* LINTED - alignment */
ipmi_entity_impl_t *eip = ENTITY_TO_IMPL(ep);
if (eip->ie_parent == NULL) {
(void) ipmi_set_error(ihp, EIPMI_NOT_PRESENT, NULL);
return (NULL);
}
return (&eip->ie_parent->ie_entity);
}
ipmi_entity_t *
ipmi_entity_lookup(ipmi_handle_t *ihp, uint8_t type, uint8_t instance)
{
ipmi_entity_t search;
ipmi_entity_impl_t *eip;
if (ipmi_entity_refresh(ihp) != 0)
return (NULL);
search.ie_type = type;
search.ie_instance = instance;
if ((eip = ipmi_hash_lookup(ihp->ih_entities, &search)) == NULL) {
(void) ipmi_set_error(ihp, EIPMI_NOT_PRESENT, NULL);
return (NULL);
}
return (&eip->ie_entity);
}
ipmi_entity_t *
ipmi_entity_lookup_sdr(ipmi_handle_t *ihp, const char *name)
{
ipmi_sdr_t *sdrp;
uint8_t id, instance;
boolean_t logical;
if ((sdrp = ipmi_sdr_lookup(ihp, name)) == NULL)
return (NULL);
if (ipmi_entity_sdr_parse(sdrp, &id, &instance, &logical) != 0) {
(void) ipmi_set_error(ihp, EIPMI_NOT_PRESENT,
"SDR record %s has no associated entity", name);
return (NULL);
}
return (ipmi_entity_lookup(ihp, id, instance));
}
static const void *
ipmi_entity_hash_convert(const void *p)
{
const ipmi_entity_impl_t *eip = p;
return (&eip->ie_entity);
}
static ulong_t
ipmi_entity_hash_compute(const void *p)
{
const ipmi_entity_t *ep = p;
return ((ep->ie_type << 8) | ep->ie_instance);
}
static int
ipmi_entity_hash_compare(const void *a, const void *b)
{
const ipmi_entity_t *ea = a;
const ipmi_entity_t *eb = b;
if (ea->ie_type == eb->ie_type &&
ea->ie_instance == eb->ie_instance)
return (0);
else
return (-1);
}
int
ipmi_entity_init(ipmi_handle_t *ihp)
{
if ((ihp->ih_entities = ipmi_hash_create(ihp,
offsetof(ipmi_entity_impl_t, ie_link),
ipmi_entity_hash_convert,
ipmi_entity_hash_compute,
ipmi_entity_hash_compare)) == NULL)
return (-1);
return (0);
}
void
ipmi_entity_clear(ipmi_handle_t *ihp)
{
ipmi_entity_impl_t *eip;
ipmi_entity_sdr_t *esp;
while ((eip = ipmi_hash_first(ihp->ih_entities)) != NULL) {
while ((esp = ipmi_list_next(&eip->ie_sdr_list)) != NULL) {
ipmi_list_delete(&eip->ie_sdr_list, esp);
ipmi_free(ihp, esp);
}
ipmi_hash_remove(ihp->ih_entities, eip);
ipmi_free(ihp, eip);
}
}
void
ipmi_entity_fini(ipmi_handle_t *ihp)
{
if (ihp->ih_entities != NULL) {
ipmi_entity_clear(ihp);
ipmi_hash_destroy(ihp->ih_entities);
}
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <libipmi.h>
int
ipmi_event_platform_message(ipmi_handle_t *ihp,
ipmi_platform_event_message_t *pem)
{
ipmi_cmd_t cmd = { 0 };
cmd.ic_netfn = IPMI_NETFN_SE;
cmd.ic_cmd = IPMI_CMD_PLATFORM_EVENT_MESSAGE;
cmd.ic_dlen = sizeof (ipmi_platform_event_message_t);
cmd.ic_data = pem;
if (ipmi_send(ihp, &cmd) == NULL)
return (-1);
else
return (0);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2017, Joyent, Inc.
*/
#include <libipmi.h>
#include <string.h>
#include "ipmi_impl.h"
/*
* Extracts bits between index h (high, inclusive) and l (low, exclusive) from
* u, which must be an unsigned integer.
*/
#define BITX(u, h, l) (((u) >> (l)) & ((1LU << ((h) - (l) + 1LU)) - 1LU))
/*
* The default and minimum size in bytes that will be used when reading
* the FRU inventory area.
*/
#define DEF_CHUNK_SZ 128
#define MIN_CHUNK_SZ 16
typedef struct ipmi_fru_read
{
uint8_t ifr_devid;
uint8_t ifr_offset_lsb;
uint8_t ifr_offset_msb;
uint8_t ifr_count;
} ipmi_fru_read_t;
/*
* returns: size of FRU inventory data in bytes, on success
* -1, otherwise
*/
int
ipmi_fru_read(ipmi_handle_t *ihp, ipmi_sdr_fru_locator_t *fru_loc, char **buf)
{
ipmi_cmd_t cmd, *resp;
int ierrno;
uint8_t count, devid, chunksz;
uint16_t sz, offset = 0;
ipmi_fru_read_t cmd_data_in;
char *tmp;
devid = fru_loc->_devid_or_slaveaddr._logical._is_fl_devid;
/*
* First we issue a command to retrieve the size of the specified FRU's
* inventory area
*/
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_cmd = IPMI_CMD_GET_FRU_INV_AREA;
cmd.ic_data = &devid;
cmd.ic_dlen = sizeof (uint8_t);
cmd.ic_lun = 0;
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (-1);
if (resp->ic_dlen != 3) {
(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
return (-1);
}
(void) memcpy(&sz, resp->ic_data, sizeof (uint16_t));
if ((tmp = malloc(sz)) == NULL) {
(void) ipmi_set_error(ihp, EIPMI_NOMEM, NULL);
return (-1);
}
chunksz = DEF_CHUNK_SZ;
while (offset < sz) {
cmd_data_in.ifr_devid = devid;
cmd_data_in.ifr_offset_lsb = BITX(offset, 7, 0);
cmd_data_in.ifr_offset_msb = BITX(offset, 15, 8);
if ((sz - offset) < chunksz)
cmd_data_in.ifr_count = sz - offset;
else
cmd_data_in.ifr_count = chunksz;
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_cmd = IPMI_CMD_READ_FRU_DATA;
cmd.ic_data = &cmd_data_in;
cmd.ic_dlen = sizeof (ipmi_fru_read_t);
cmd.ic_lun = 0;
/*
* The FRU area must be read in chunks as its total size will
* be larger than what would fit in a single message. The
* maximum size of a message can vary between platforms so
* if while attempting to read a chunk we receive an error code
* indicating that the requested chunk size is invalid, we will
* perform a reverse exponential backoff of the chunk size until
* either the read succeeds or we hit bottom, at which point
* we'll fail the operation.
*/
if ((resp = ipmi_send(ihp, &cmd)) == NULL) {
ierrno = ipmi_errno(ihp);
if (chunksz > MIN_CHUNK_SZ &&
(ierrno == EIPMI_DATA_LENGTH_EXCEEDED ||
ierrno == EIPMI_INVALID_REQUEST)) {
chunksz = chunksz >> 1;
continue;
}
free(tmp);
return (-1);
}
(void) memcpy(&count, resp->ic_data, sizeof (uint8_t));
if (count != cmd_data_in.ifr_count) {
(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH,
NULL);
free(tmp);
return (-1);
}
(void) memcpy(tmp+offset, (char *)(resp->ic_data)+1, count);
offset += count;
}
*buf = tmp;
return (sz);
}
int
ipmi_fru_parse_product(ipmi_handle_t *ihp, char *fru_area,
ipmi_fru_prod_info_t *buf)
{
ipmi_fru_hdr_t fru_hdr;
char *tmp;
uint8_t len, typelen;
(void) memcpy(&fru_hdr, fru_area, sizeof (ipmi_fru_hdr_t));
/*
* We get the offset to the product info area from the FRU common
* header which is at the start of the FRU inventory area.
*
* The product info area is optional, so if the offset is NULL,
* indicating that it doesn't exist, then we return an error.
*/
if (!fru_hdr.ifh_product_info_off) {
(void) ipmi_set_error(ihp, EIPMI_NOT_PRESENT, NULL);
return (-1);
}
tmp = fru_area + (fru_hdr.ifh_product_info_off * 8) + 3;
(void) memcpy(&typelen, tmp, sizeof (uint8_t));
len = BITX(typelen, 5, 0);
ipmi_decode_string((typelen >> 6), len, tmp+1, buf->ifpi_manuf_name);
tmp += len + 1;
(void) memcpy(&typelen, tmp, sizeof (uint8_t));
len = BITX(typelen, 5, 0);
ipmi_decode_string((typelen >> 6), len, tmp+1,
buf->ifpi_product_name);
tmp += len + 1;
(void) memcpy(&typelen, tmp, sizeof (uint8_t));
len = BITX(typelen, 5, 0);
ipmi_decode_string((typelen >> 6), len, tmp+1, buf->ifpi_part_number);
tmp += len + 1;
(void) memcpy(&typelen, tmp, sizeof (uint8_t));
len = BITX(typelen, 5, 0);
ipmi_decode_string((typelen >> 6), len, tmp+1,
buf->ifpi_product_version);
tmp += len + 1;
(void) memcpy(&typelen, tmp, sizeof (uint8_t));
len = BITX(typelen, 5, 0);
ipmi_decode_string((typelen >> 6), len, tmp+1,
buf->ifpi_product_serial);
tmp += len + 1;
(void) memcpy(&typelen, tmp, sizeof (uint8_t));
len = BITX(typelen, 5, 0);
ipmi_decode_string((typelen >> 6), len, tmp+1, buf->ifpi_asset_tag);
return (0);
}
/*
* The Board Info area is described in Sect 11 of the IPMI Platform Management
* FRU Information Storage Definition (v1.1).
*/
int
ipmi_fru_parse_board(ipmi_handle_t *ihp, char *fru_area,
ipmi_fru_brd_info_t *buf)
{
ipmi_fru_hdr_t fru_hdr;
char *tmp;
uint8_t len, typelen;
(void) memcpy(&fru_hdr, fru_area, sizeof (ipmi_fru_hdr_t));
/*
* We get the offset to the board info area from the FRU common
* header which is at the start of the FRU inventory area.
*
* The board info area is optional, so if the offset is NULL,
* indicating that it doesn't exist, then we return an error.
*/
if (!fru_hdr.ifh_board_info_off) {
(void) ipmi_set_error(ihp, EIPMI_NOT_PRESENT, NULL);
return (-1);
}
tmp = fru_area + (fru_hdr.ifh_board_info_off * 8) + 3;
(void) memcpy(buf->ifbi_manuf_date, tmp, 3);
tmp += 3;
(void) memcpy(&typelen, tmp, sizeof (uint8_t));
len = BITX(typelen, 5, 0);
ipmi_decode_string((typelen >> 6), len, tmp+1, buf->ifbi_manuf_name);
tmp += len + 1;
(void) memcpy(&typelen, tmp, sizeof (uint8_t));
len = BITX(typelen, 5, 0);
ipmi_decode_string((typelen >> 6), len, tmp+1, buf->ifbi_board_name);
tmp += len + 1;
(void) memcpy(&typelen, tmp, sizeof (uint8_t));
len = BITX(typelen, 5, 0);
ipmi_decode_string((typelen >> 6), len, tmp+1,
buf->ifbi_product_serial);
tmp += len + 1;
(void) memcpy(&typelen, tmp, sizeof (uint8_t));
len = BITX(typelen, 5, 0);
ipmi_decode_string((typelen >> 6), len, tmp+1, buf->ifbi_part_number);
return (0);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <strings.h>
#include <assert.h>
#include <ipmi_impl.h>
#include <string.h>
#include <strings.h>
/*
* The (prime) number 137 happens to have the nice property that -- when
* multiplied by two and added to 33 -- one gets a pretty long series of
* primes:
*
* 307, 647, 1327, 2687, 5407, 10847, 21727, 43487
*
* And beyond 43487, the numbers in the series have few factors or are prime.
* That is, one can have a prime number and roughly double it to get another
* prime number -- but the series starts at 137. A size of 137 buckets doesn't
* particularly accommodate small hash tables, but we note that 13 also yields
* a reasonable sequence when doubling it and adding 5:
*
* 13, 31, 67, 139, 283, 571
*
* So we start with this second sequence, crossing over to the first when
* the size is greater than 137. (And when reducing the size of the hash
* table, we cross back when the size gets below 67.)
*/
#define IPMI_HASHCROSSOVER 137
#define IPMI_HASHCROSSUNDER 67
#define IPMI_HASHMINSIZE 13
static ulong_t
ipmi_hash_double(ulong_t size)
{
ulong_t nsize;
if (size < IPMI_HASHCROSSOVER) {
nsize = (size * 2) + 5;
return (nsize < IPMI_HASHCROSSOVER ? nsize :
IPMI_HASHCROSSOVER);
}
return ((size * 2) + 33);
}
static ulong_t
ipmi_hash_half(ulong_t size)
{
ulong_t nsize;
if (size > IPMI_HASHCROSSUNDER) {
nsize = (size - 33) / 2;
return (nsize > IPMI_HASHCROSSUNDER ? nsize :
IPMI_HASHCROSSUNDER);
}
nsize = (size - 5) / 2;
return (nsize > IPMI_HASHMINSIZE ? nsize : IPMI_HASHMINSIZE);
}
ipmi_hash_t *
ipmi_hash_create(ipmi_handle_t *hp, size_t linkoffs,
const void *(*convert)(const void *elem),
ulong_t (*compute)(const void *key),
int (*compare)(const void *lkey, const void *rkey))
{
ipmi_hash_t *ihp;
if ((ihp = ipmi_zalloc(hp, sizeof (ipmi_hash_t))) == NULL)
return (NULL);
ihp->ih_handle = hp;
ihp->ih_nbuckets = IPMI_HASHMINSIZE;
ihp->ih_linkoffs = linkoffs;
ihp->ih_convert = convert;
ihp->ih_compute = compute;
ihp->ih_compare = compare;
if ((ihp->ih_buckets = ipmi_zalloc(hp,
ihp->ih_nbuckets * sizeof (void *))) == NULL) {
ipmi_free(hp, ihp);
return (NULL);
}
return (ihp);
}
void
ipmi_hash_destroy(ipmi_hash_t *ihp)
{
if (ihp != NULL) {
ipmi_free(ihp->ih_handle, ihp->ih_buckets);
ipmi_free(ihp->ih_handle, ihp);
}
}
ulong_t
ipmi_hash_strhash(const void *key)
{
ulong_t g, h = 0;
const char *p;
for (p = key; *p != '\0'; p++) {
h = (h << 4) + *p;
if ((g = (h & 0xf0000000)) != 0) {
h ^= (g >> 24);
h ^= g;
}
}
return (h);
}
int
ipmi_hash_strcmp(const void *lhs, const void *rhs)
{
return (strcmp(lhs, rhs));
}
ulong_t
ipmi_hash_ptrhash(const void *key)
{
return (*((const uintptr_t *)key) >> 4);
}
int
ipmi_hash_ptrcmp(const void *lhs, const void *rhs)
{
const uintptr_t *l = lhs, *r = rhs;
return (*l == *r ? 0 : -1);
}
static ulong_t
ipmi_hash_compute(ipmi_hash_t *ihp, const void *elem)
{
return (ihp->ih_compute(ihp->ih_convert(elem)) % ihp->ih_nbuckets);
}
static void
ipmi_hash_resize(ipmi_hash_t *ihp, ulong_t nsize)
{
size_t osize = ihp->ih_nbuckets;
ipmi_handle_t *hp = ihp->ih_handle;
ipmi_hash_link_t *link, **nbuckets;
ulong_t idx, nidx;
assert(nsize >= IPMI_HASHMINSIZE);
if (nsize == osize)
return;
if ((nbuckets = ipmi_zalloc(hp, nsize * sizeof (void *))) == NULL) {
/*
* This routine can't fail, so we just eat the failure here.
* The consequences of this failing are only for performance;
* correctness is not affected by our inability to resize
* the hash table.
*/
return;
}
ihp->ih_nbuckets = nsize;
for (idx = 0; idx < osize; idx++) {
while ((link = ihp->ih_buckets[idx]) != NULL) {
void *elem;
/*
* For every hash element, we need to remove it from
* this bucket, and rehash it given the new bucket
* size.
*/
ihp->ih_buckets[idx] = link->ihl_next;
elem = (void *)((uintptr_t)link - ihp->ih_linkoffs);
nidx = ipmi_hash_compute(ihp, elem);
link->ihl_next = nbuckets[nidx];
nbuckets[nidx] = link;
}
}
ipmi_free(hp, ihp->ih_buckets);
ihp->ih_buckets = nbuckets;
}
void *
ipmi_hash_lookup(ipmi_hash_t *ihp, const void *search)
{
ulong_t idx = ihp->ih_compute(search) % ihp->ih_nbuckets;
ipmi_hash_link_t *hl;
for (hl = ihp->ih_buckets[idx]; hl != NULL; hl = hl->ihl_next) {
void *elem = (void *)((uintptr_t)hl - ihp->ih_linkoffs);
if (ihp->ih_compare(ihp->ih_convert(elem), search) == 0)
return (elem);
}
return (NULL);
}
void *
ipmi_hash_first(ipmi_hash_t *ihp)
{
void *link = ipmi_list_next(&(ihp)->ih_list);
if (link == NULL)
return (NULL);
return ((void *)((uintptr_t)link - ihp->ih_linkoffs));
}
void *
ipmi_hash_next(ipmi_hash_t *ihp, void *elem)
{
void *link = ipmi_list_next((uintptr_t)elem + ihp->ih_linkoffs);
if (link == NULL)
return (NULL);
return ((void *)((uintptr_t)link - ihp->ih_linkoffs));
}
void
ipmi_hash_insert(ipmi_hash_t *ihp, void *elem)
{
ipmi_hash_link_t *link = (void *)((uintptr_t)elem + ihp->ih_linkoffs);
ulong_t idx = ipmi_hash_compute(ihp, elem);
assert(ipmi_hash_lookup(ihp, ihp->ih_convert(elem)) == NULL);
link->ihl_next = ihp->ih_buckets[idx];
ihp->ih_buckets[idx] = link;
ipmi_list_append(&ihp->ih_list, link);
if (++ihp->ih_nelements > ihp->ih_nbuckets / 2)
ipmi_hash_resize(ihp, ipmi_hash_double(ihp->ih_nbuckets));
}
void
ipmi_hash_remove(ipmi_hash_t *ihp, void *elem)
{
ulong_t idx = ipmi_hash_compute(ihp, elem);
ipmi_hash_link_t *link = (void *)((uintptr_t)elem + ihp->ih_linkoffs);
ipmi_hash_link_t **hlp = &ihp->ih_buckets[idx];
for (; *hlp != NULL; hlp = &(*hlp)->ihl_next) {
if (*hlp == link)
break;
}
assert(*hlp != NULL);
*hlp = (*hlp)->ihl_next;
ipmi_list_delete(&ihp->ih_list, link);
assert(ihp->ih_nelements > 0);
if (--ihp->ih_nelements < ihp->ih_nbuckets / 4)
ipmi_hash_resize(ihp, ipmi_hash_half(ihp->ih_nbuckets));
}
size_t
ipmi_hash_count(ipmi_hash_t *ihp)
{
return (ihp->ih_nelements);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _IPMI_IMPL_H
#define _IPMI_IMPL_H
#include <stdlib.h>
#include <sys/nvpair.h>
#include <libipmi.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ipmi_list {
struct ipmi_list *l_prev;
struct ipmi_list *l_next;
} ipmi_list_t;
typedef struct ipmi_hash_link {
ipmi_list_t ihl_list; /* next on list of all elements */
struct ipmi_hash_link *ihl_next; /* next on this bucket */
} ipmi_hash_link_t;
typedef struct ipmi_hash {
ipmi_handle_t *ih_handle; /* handle to library state */
ipmi_hash_link_t **ih_buckets; /* array of buckets */
size_t ih_nbuckets; /* number of buckets */
size_t ih_nelements; /* number of elements */
ipmi_list_t ih_list; /* list of all elements */
size_t ih_linkoffs; /* offset of ipmi_hash_link in elem */
const void *(*ih_convert)(const void *); /* key conversion function */
ulong_t (*ih_compute)(const void *); /* hash computing function */
int (*ih_compare)(const void *, const void *); /* compare function */
} ipmi_hash_t;
typedef struct ipmi_transport {
void * (*it_open)(struct ipmi_handle *, nvlist_t *);
void (*it_close)(void *);
int (*it_send)(void *, struct ipmi_cmd *, struct ipmi_cmd *,
int *);
} ipmi_transport_t;
struct ipmi_handle {
ipmi_transport_t *ih_transport;
void *ih_tdata;
ipmi_cmd_t ih_response;
int ih_errno;
uint16_t ih_reservation;
int ih_retries;
ipmi_hash_t *ih_sdr_cache;
uint32_t ih_sdr_ts;
ipmi_deviceid_t *ih_deviceid;
uint32_t ih_deviceid_len;
char *ih_firmware_rev;
char ih_errmsg[1024];
char ih_errbuf[1024];
ipmi_list_t ih_users;
ipmi_hash_t *ih_entities;
int ih_completion;
};
/*
* Error handling
*/
extern int ipmi_set_error(ipmi_handle_t *, int, const char *, ...);
/*
* Memory allocation
*/
extern void *ipmi_alloc(ipmi_handle_t *, size_t);
extern void *ipmi_zalloc(ipmi_handle_t *, size_t);
extern void ipmi_free(ipmi_handle_t *, void *);
extern void *impi_realloc(ipmi_handle_t *, void *, size_t);
extern char *ipmi_strdup(ipmi_handle_t *, const char *);
/*
* Supported transports
*/
extern ipmi_transport_t ipmi_transport_bmc;
extern ipmi_transport_t ipmi_transport_lan;
/*
* Primitives for converting
*/
typedef struct ipmi_name_trans {
int int_value;
const char *int_name;
} ipmi_name_trans_t;
typedef struct ipmi_sensor_trans {
uint8_t ist_key;
uint8_t ist_value;
ipmi_name_trans_t ist_mask[1];
} ipmi_sensor_trans_t;
extern ipmi_name_trans_t ipmi_entity_table[];
extern ipmi_name_trans_t ipmi_sensor_type_table[];
extern ipmi_name_trans_t ipmi_reading_type_table[];
extern ipmi_name_trans_t ipmi_errno_table[];
extern ipmi_name_trans_t ipmi_threshold_state_table[];
extern ipmi_name_trans_t ipmi_units_type_table[];
extern ipmi_sensor_trans_t ipmi_reading_state_table[];
extern ipmi_sensor_trans_t ipmi_specific_state_table[];
/*
* Miscellaneous routines
*/
extern int ipmi_sdr_init(ipmi_handle_t *);
extern void ipmi_sdr_clear(ipmi_handle_t *);
extern void ipmi_sdr_fini(ipmi_handle_t *);
extern void ipmi_user_clear(ipmi_handle_t *);
extern int ipmi_entity_init(ipmi_handle_t *);
extern void ipmi_entity_clear(ipmi_handle_t *);
extern void ipmi_entity_fini(ipmi_handle_t *);
extern int ipmi_convert_bcd(int);
extern void ipmi_decode_string(uint8_t type, uint8_t len, char *data,
char *buf);
extern boolean_t ipmi_is_sun_ilom(ipmi_deviceid_t *);
/*
* List routines
*/
#define ipmi_list_prev(elem) ((void *)(((ipmi_list_t *)(elem))->l_prev))
#define ipmi_list_next(elem) ((void *)(((ipmi_list_t *)(elem))->l_next))
extern void ipmi_list_append(ipmi_list_t *, void *);
extern void ipmi_list_prepend(ipmi_list_t *, void *);
extern void ipmi_list_insert_before(ipmi_list_t *, void *, void *);
extern void ipmi_list_insert_after(ipmi_list_t *, void *, void *);
extern void ipmi_list_delete(ipmi_list_t *, void *);
/*
* Hash table routines
*/
extern ipmi_hash_t *ipmi_hash_create(ipmi_handle_t *, size_t,
const void *(*convert)(const void *),
ulong_t (*compute)(const void *),
int (*compare)(const void *, const void *));
extern void ipmi_hash_destroy(ipmi_hash_t *);
extern void *ipmi_hash_lookup(ipmi_hash_t *, const void *);
extern void ipmi_hash_insert(ipmi_hash_t *, void *);
extern void ipmi_hash_remove(ipmi_hash_t *, void *);
extern size_t ipmi_hash_count(ipmi_hash_t *);
extern ulong_t ipmi_hash_strhash(const void *);
extern int ipmi_hash_strcmp(const void *, const void *);
extern ulong_t ipmi_hash_ptrhash(const void *);
extern int ipmi_hash_ptrcmp(const void *, const void *);
extern void *ipmi_hash_first(ipmi_hash_t *);
extern void *ipmi_hash_next(ipmi_hash_t *, void *);
#ifdef __cplusplus
}
#endif
#endif /* _IPMI_IMPL_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <inttypes.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#include <fcntl.h>
#include "libipmi.h"
#include "ipmi_lan.h"
#include "ipmi_impl.h"
#define DEF_IPMI_LAN_TIMEOUT 3 /* seconds */
#define DEF_IPMI_LAN_NUM_RETRIES 5
#define IPMI_LAN_CHANNEL_E 0x0e
typedef struct ipmi_rs {
uint8_t ir_data[IPMI_BUF_SIZE];
int ir_dlen;
ipmi_msg_hdr_t ir_ihdr;
uint8_t ir_ccode;
} ipmi_rs_t;
static ipmi_rs_t *ipmi_lan_poll_recv(ipmi_handle_t *);
typedef struct ipmi_rq_entry {
ipmi_list_t ire_list;
ipmi_cmd_t ire_req;
uint8_t ire_target_cmd;
uint8_t ire_rq_seq;
uint8_t *ire_msg_data;
int ire_msg_len;
} ipmi_rq_entry_t;
ipmi_rq_entry_t *ipmi_req_entries = NULL;
/*
* LAN transport-specific data
*/
typedef struct ipmi_lan {
ipmi_handle_t *il_ihp;
char il_host[MAXHOSTNAMELEN + 1];
uint16_t il_port;
char il_user[17];
char il_authcode[IPMI_AUTHCODE_BUF_SIZE + 1];
uint8_t il_challenge[16];
uint32_t il_session_id;
int il_sd;
boolean_t il_send_authcode;
boolean_t il_session_active;
uint8_t il_authtype;
uint8_t il_privlvl;
uint8_t il_num_retries;
uint32_t il_in_seq;
uint32_t il_timeout;
struct sockaddr_in il_addr;
socklen_t il_addrlen;
} ipmi_lan_t;
/*
* Calculate and returns IPMI checksum
*
* Checksum algorithm is described in Section 13.8
*
* d: buffer to check
* s: position in buffer to start checksum from
*/
static uint8_t
ipmi_csum(uint8_t *d, int s)
{
uint8_t c = 0;
for (; s > 0; s--, d++)
c += *d;
return (-c);
}
static ipmi_rq_entry_t *
ipmi_req_add_entry(ipmi_handle_t *ihp, ipmi_cmd_t *req)
{
ipmi_rq_entry_t *e;
if ((e = ipmi_zalloc(ihp, sizeof (ipmi_rq_entry_t))) == NULL)
return (NULL);
(void) memcpy(&e->ire_req, req, sizeof (ipmi_cmd_t));
ipmi_list_append(&ipmi_req_entries->ire_list, e);
return (e);
}
/*ARGSUSED*/
static ipmi_rq_entry_t *
ipmi_req_lookup_entry(ipmi_handle_t *ihp, uint8_t seq, uint8_t cmd)
{
ipmi_rq_entry_t *e;
for (e = ipmi_list_next(&ipmi_req_entries->ire_list); e != NULL;
e = ipmi_list_next(e))
if (e->ire_rq_seq == seq && e->ire_req.ic_cmd == cmd)
return (e);
return (NULL);
}
static void
ipmi_req_remove_entry(ipmi_handle_t *ihp, uint8_t seq, uint8_t cmd)
{
ipmi_rq_entry_t *e;
e = ipmi_req_lookup_entry(ihp, seq, cmd);
if (e) {
ipmi_list_delete(&ipmi_req_entries->ire_list, e);
ipmi_free(ihp, e->ire_msg_data);
ipmi_free(ihp, e);
}
}
static void
ipmi_req_clear_entries(ipmi_handle_t *ihp)
{
ipmi_rq_entry_t *e;
while ((e = ipmi_list_next(&ipmi_req_entries->ire_list)) != NULL) {
ipmi_list_delete(&ipmi_req_entries->ire_list, e);
ipmi_free(ihp, e);
}
}
static int
get_random(void *buf, uint_t len)
{
int fd;
assert(buf != NULL && len > 0);
if ((fd = open("/dev/urandom", O_RDONLY)) < 0)
return (-1);
if (read(fd, buf, len) < 0) {
(void) close(fd);
return (-1);
}
(void) close(fd);
return (0);
}
static int
ipmi_lan_send_packet(ipmi_handle_t *ihp, uint8_t *data, int dlen)
{
ipmi_lan_t *ilp = (ipmi_lan_t *)ihp->ih_tdata;
return (send(ilp->il_sd, data, dlen, 0));
}
static ipmi_rs_t *
ipmi_lan_recv_packet(ipmi_handle_t *ihp)
{
static ipmi_rs_t rsp;
fd_set read_set, err_set;
struct timeval tmout;
ipmi_lan_t *ilp = (ipmi_lan_t *)ihp->ih_tdata;
int ret;
FD_ZERO(&read_set);
FD_SET(ilp->il_sd, &read_set);
FD_ZERO(&err_set);
FD_SET(ilp->il_sd, &err_set);
tmout.tv_sec = ilp->il_timeout;
tmout.tv_usec = 0;
ret = select(ilp->il_sd + 1, &read_set, NULL, &err_set, &tmout);
if (ret < 0 || FD_ISSET(ilp->il_sd, &err_set) ||
!FD_ISSET(ilp->il_sd, &read_set))
return (NULL);
/*
* The first read may return ECONNREFUSED because the rmcp ping
* packet--sent to UDP port 623--will be processed by both the
* BMC and the OS.
*
* The problem with this is that the ECONNREFUSED takes
* priority over any other received datagram; that means that
* the Connection Refused shows up _before_ the response packet,
* regardless of the order they were sent out. (unless the
* response is read before the connection refused is returned)
*/
ret = recv(ilp->il_sd, &rsp.ir_data, IPMI_BUF_SIZE, 0);
if (ret < 0) {
FD_ZERO(&read_set);
FD_SET(ilp->il_sd, &read_set);
FD_ZERO(&err_set);
FD_SET(ilp->il_sd, &err_set);
tmout.tv_sec = ilp->il_timeout;
tmout.tv_usec = 0;
ret = select(ilp->il_sd + 1, &read_set, NULL, &err_set, &tmout);
if (ret < 0) {
if (FD_ISSET(ilp->il_sd, &err_set) ||
!FD_ISSET(ilp->il_sd, &read_set))
return (NULL);
ret = recv(ilp->il_sd, &rsp.ir_data, IPMI_BUF_SIZE, 0);
if (ret < 0)
return (NULL);
}
}
if (ret == 0)
return (NULL);
rsp.ir_data[ret] = '\0';
rsp.ir_dlen = ret;
return (&rsp);
}
/*
* ASF/RMCP Pong Message
*
* See section 13.2.4
*/
struct rmcp_pong {
rmcp_hdr_t rp_rmcp;
asf_hdr_t rp_asf;
uint32_t rp_iana;
uint32_t rp_oem;
uint8_t rp_sup_entities;
uint8_t rp_sup_interact;
uint8_t rp_reserved[6];
};
/*
* parse response RMCP "pong" packet
*
* return -1 if ping response not received
* returns 0 if IPMI is NOT supported
* returns 1 if IPMI is supported
*/
/*ARGSUSED*/
static int
ipmi_handle_pong(ipmi_handle_t *ihp, ipmi_rs_t *rsp)
{
struct rmcp_pong *pong;
if (rsp == NULL)
return (-1);
/*LINTED: E_BAD_PTR_CAST_ALIGN*/
pong = (struct rmcp_pong *)rsp->ir_data;
return ((pong->rp_sup_entities & 0x80) ? 1 : 0);
}
/*
* Build and send RMCP presence ping message
*/
static int
ipmi_lan_ping(ipmi_handle_t *ihp)
{
rmcp_hdr_t rmcp_ping;
asf_hdr_t asf_ping;
uint8_t *data;
int rv, dlen = sizeof (rmcp_ping) + sizeof (asf_ping);
(void) memset(&rmcp_ping, 0, sizeof (rmcp_ping));
rmcp_ping.rh_version = RMCP_VERSION_1;
rmcp_ping.rh_msg_class = RMCP_CLASS_ASF;
rmcp_ping.rh_seq = 0xff;
(void) memset(&asf_ping, 0, sizeof (asf_ping));
asf_ping.ah_iana = htonl(ASF_RMCP_IANA);
asf_ping.ah_msg_type = ASF_TYPE_PING;
if ((data = ipmi_zalloc(ihp, dlen)) == NULL)
return (-1);
(void) memcpy(data, &rmcp_ping, sizeof (rmcp_ping));
(void) memcpy(data + sizeof (rmcp_ping), &asf_ping, sizeof (asf_ping));
rv = ipmi_lan_send_packet(ihp, data, dlen);
ipmi_free(ihp, data);
if (rv < 0)
return (ipmi_set_error(ihp, EIPMI_LAN_PING_FAILED, NULL));
if (ipmi_lan_poll_recv(ihp) == NULL)
return (ipmi_set_error(ihp, EIPMI_LAN_PING_FAILED, NULL));
return (0);
}
static ipmi_rs_t *
ipmi_lan_poll_recv(ipmi_handle_t *ihp)
{
rmcp_hdr_t rmcp_rsp;
ipmi_rs_t *rsp;
ipmi_rq_entry_t *entry;
int off = 0, rv;
ipmi_lan_t *ilp = (ipmi_lan_t *)ihp->ih_tdata;
uint8_t rsp_authtype;
rsp = ipmi_lan_recv_packet(ihp);
while (rsp != NULL) {
/* parse response headers */
(void) memcpy(&rmcp_rsp, rsp->ir_data, 4);
switch (rmcp_rsp.rh_msg_class) {
case RMCP_CLASS_ASF:
/* ping response packet */
rv = ipmi_handle_pong(ihp, rsp);
return ((rv <= 0) ? NULL : rsp);
case RMCP_CLASS_IPMI:
/* handled by rest of function */
break;
default:
/* Invalid RMCP class */
rsp = ipmi_lan_recv_packet(ihp);
continue;
}
off = sizeof (rmcp_hdr_t);
rsp_authtype = rsp->ir_data[off];
if (ilp->il_send_authcode && (rsp_authtype || ilp->il_authtype))
off += 26;
else
off += 10;
(void) memcpy(&rsp->ir_ihdr, (void *)(rsp->ir_data + off),
sizeof (rsp->ir_ihdr));
rsp->ir_ihdr.imh_seq = rsp->ir_ihdr.imh_seq >> 2;
off += sizeof (rsp->ir_ihdr);
rsp->ir_ccode = rsp->ir_data[off++];
entry = ipmi_req_lookup_entry(ihp, rsp->ir_ihdr.imh_seq,
rsp->ir_ihdr.imh_cmd);
if (entry) {
ipmi_req_remove_entry(ihp, rsp->ir_ihdr.imh_seq,
rsp->ir_ihdr.imh_cmd);
} else {
rsp = ipmi_lan_recv_packet(ihp);
continue;
}
break;
}
/* shift response data to start of array */
if (rsp && rsp->ir_dlen > off) {
rsp->ir_dlen -= off + 1;
(void) memmove(rsp->ir_data, rsp->ir_data + off, rsp->ir_dlen);
(void) memset(rsp->ir_data + rsp->ir_dlen, 0,
IPMI_BUF_SIZE - rsp->ir_dlen);
}
return (rsp);
}
/*
* IPMI LAN Request Message Format
*
* See section 13.8
*
* +---------------------+
* | rmcp_hdr_t | 4 bytes
* +---------------------+
* | v15_session_hdr_t | 9 bytes
* +---------------------+
* | [authcode] | 16 bytes (if AUTHTYPE != none)
* +---------------------+
* | msg length | 1 byte
* +---------------------+
* | ipmi_msg_hdr_t | 6 bytes
* +---------------------+
* | [msg data] | variable
* +---------------------+
* | msg data checksum | 1 byte
* +---------------------+
*/
static ipmi_rq_entry_t *
ipmi_lan_build_cmd(ipmi_handle_t *ihp, ipmi_cmd_t *req)
{
ipmi_lan_t *ilp = (ipmi_lan_t *)ihp->ih_tdata;
rmcp_hdr_t rmcp_hdr;
v15_session_hdr_t session_hdr;
ipmi_msg_hdr_t msg_hdr;
uint8_t *msg;
int cs, tmp, off = 0, len;
ipmi_rq_entry_t *entry;
static int curr_seq = 0;
if (curr_seq >= 64)
curr_seq = 0;
if ((entry = ipmi_req_add_entry(ihp, req)) == NULL)
return (NULL);
len = req->ic_dlen + 29;
if (ilp->il_send_authcode && ilp->il_authtype)
len += 16;
if ((msg = ipmi_zalloc(ihp, len)) == NULL)
/* ipmi_errno set */
return (NULL);
/* RMCP header */
(void) memset(&rmcp_hdr, 0, sizeof (rmcp_hdr));
rmcp_hdr.rh_version = RMCP_VERSION_1;
rmcp_hdr.rh_msg_class = RMCP_CLASS_IPMI;
rmcp_hdr.rh_seq = 0xff;
(void) memcpy(msg, &rmcp_hdr, sizeof (rmcp_hdr));
off = sizeof (rmcp_hdr);
/* IPMI session header */
(void) memset(&session_hdr, 0, sizeof (session_hdr));
if (! ilp->il_send_authcode)
session_hdr.sh_authtype = 0x00;
else
/* hardcode passwd authentication */
session_hdr.sh_authtype = 0x04;
(void) memcpy(&session_hdr.sh_seq, &ilp->il_in_seq, sizeof (uint32_t));
(void) memcpy(&session_hdr.sh_id, &ilp->il_session_id,
sizeof (uint32_t));
(void) memcpy(msg + off, &session_hdr, sizeof (session_hdr));
off += sizeof (session_hdr);
/* IPMI session authcode */
if (ilp->il_send_authcode && ilp->il_authtype) {
(void) memcpy(msg + off, ilp->il_authcode, 16);
off += 16;
}
/* message length */
msg[off++] = req->ic_dlen + 7;
cs = off;
/* IPMI message header */
(void) memset(&msg_hdr, 0, sizeof (msg_hdr));
msg_hdr.imh_addr1 = IPMI_BMC_SLAVE_ADDR;
msg_hdr.imh_lun = req->ic_lun;
msg_hdr.imh_netfn = req->ic_netfn;
tmp = off - cs;
msg_hdr.imh_csum = ipmi_csum(msg + cs, tmp);
cs = off;
msg_hdr.imh_addr2 = IPMI_BMC_SLAVE_ADDR;
entry->ire_rq_seq = curr_seq++;
msg_hdr.imh_seq = entry->ire_rq_seq << 2;
msg_hdr.imh_cmd = req->ic_cmd;
(void) memcpy(msg + off, &msg_hdr, sizeof (msg_hdr));
off += sizeof (msg_hdr);
/* message data */
if (req->ic_dlen != 0) {
(void) memcpy(msg + off, req->ic_data, req->ic_dlen);
off += req->ic_dlen;
}
/* message data checksum */
tmp = off - cs;
msg[off++] = ipmi_csum(msg + cs, tmp);
if (ilp->il_in_seq) {
ilp->il_in_seq++;
if (ilp->il_in_seq == 0)
ilp->il_in_seq++;
}
entry->ire_msg_len = off;
entry->ire_msg_data = msg;
return (entry);
}
static int
ipmi_lan_send(void *data, ipmi_cmd_t *cmd, ipmi_cmd_t *response,
int *completion)
{
ipmi_lan_t *ilp = (ipmi_lan_t *)data;
ipmi_rq_entry_t *entry = NULL;
ipmi_rs_t *rsp = NULL;
uint_t try = 0;
for (;;) {
if ((entry = ipmi_lan_build_cmd(ilp->il_ihp, cmd)) == NULL)
return (-1);
if (ipmi_lan_send_packet(ilp->il_ihp, entry->ire_msg_data,
entry->ire_msg_len) < 0) {
if (++try >= ilp->il_num_retries)
return (-1);
(void) usleep(5000);
continue;
}
(void) usleep(100);
if ((rsp = ipmi_lan_poll_recv(ilp->il_ihp)) != NULL)
break;
(void) usleep(5000);
ipmi_req_remove_entry(ilp->il_ihp, entry->ire_rq_seq,
entry->ire_req.ic_cmd);
if (++try >= ilp->il_num_retries)
return (-1);
}
response->ic_netfn = rsp->ir_ihdr.imh_netfn;
response->ic_lun = rsp->ir_ihdr.imh_lun;
response->ic_cmd = rsp->ir_ihdr.imh_cmd;
if (rsp->ir_ccode != 0) {
*completion = rsp->ir_ccode;
response->ic_dlen = 0;
response->ic_data = NULL;
} else {
*completion = 0;
response->ic_dlen = rsp->ir_dlen;
response->ic_data = rsp->ir_data;
}
return (0);
}
/*
* IPMI Get Session Challenge Command
*
* Copies the returned session ID and 16-byte challenge string to the supplied
* buffers
*
* See section 22.16
*/
static int
ipmi_get_session_challenge_cmd(ipmi_handle_t *ihp, uint32_t *session_id,
uint8_t *challenge)
{
ipmi_cmd_t cmd, resp;
ipmi_lan_t *ilp = (ipmi_lan_t *)ihp->ih_tdata;
char msg_data[17];
int ccode;
(void) memset(msg_data, 0, 17);
switch (ilp->il_authtype) {
case IPMI_SESSION_AUTHTYPE_NONE:
msg_data[0] = 0x00;
break;
case IPMI_SESSION_AUTHTYPE_MD2:
msg_data[0] = 0x01;
break;
case IPMI_SESSION_AUTHTYPE_MD5:
msg_data[0] = 0x02;
break;
case IPMI_SESSION_AUTHTYPE_PASSWORD:
msg_data[0] = 0x04;
break;
case IPMI_SESSION_AUTHTYPE_OEM:
msg_data[0] = 0x05;
break;
}
(void) memcpy(msg_data + 1, ilp->il_user, 16);
cmd.ic_netfn = IPMI_NETFN_APP;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_SESSION_CHALLENGE;
cmd.ic_data = msg_data;
cmd.ic_dlen = 17;
if (ipmi_lan_send(ilp, &cmd, &resp, &ccode) != 0 || ccode)
return (ipmi_set_error(ihp, EIPMI_LAN_CHALLENGE, NULL));
(void) memcpy(session_id, resp.ic_data, 4);
(void) memcpy(challenge, (uint8_t *)resp.ic_data + 4, 16);
return (0);
}
/*
* IPMI Activate Session Command
*
* See section 22.17
*/
static int
ipmi_activate_session_cmd(ipmi_handle_t *ihp)
{
ipmi_cmd_t cmd, resp;
ipmi_lan_t *ilp = (ipmi_lan_t *)ihp->ih_tdata;
uint8_t msg_data[22], *resp_data;
int ccode;
cmd.ic_netfn = IPMI_NETFN_APP;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_ACTIVATE_SESSION;
switch (ilp->il_authtype) {
case IPMI_SESSION_AUTHTYPE_NONE:
msg_data[0] = 0x00;
break;
case IPMI_SESSION_AUTHTYPE_MD2:
msg_data[0] = 0x01;
break;
case IPMI_SESSION_AUTHTYPE_MD5:
msg_data[0] = 0x02;
break;
case IPMI_SESSION_AUTHTYPE_PASSWORD:
msg_data[0] = 0x04;
break;
case IPMI_SESSION_AUTHTYPE_OEM:
msg_data[0] = 0x05;
break;
}
msg_data[1] = ilp->il_privlvl;
(void) memcpy(msg_data + 2, ilp->il_challenge, 16);
/* setup initial outbound sequence number */
(void) get_random(msg_data + 18, 4);
cmd.ic_data = msg_data;
cmd.ic_dlen = 22;
ilp->il_send_authcode = B_TRUE;
if (ipmi_lan_send(ilp, &cmd, &resp, &ccode) != 0 || ccode) {
ilp->il_send_authcode = B_FALSE;
return (ipmi_set_error(ihp, EIPMI_LAN_SESSION, NULL));
}
resp_data = (uint8_t *)resp.ic_data;
(void) memcpy(&ilp->il_session_id, resp_data + 1, 4);
ilp->il_in_seq = resp_data[8] << 24 | resp_data[7] << 16 |
resp_data[6] << 8 | resp_data[5];
if (ilp->il_in_seq == 0)
++ilp->il_in_seq;
return (0);
}
/*
* See section 22.18
*
* returns privilege level or -1 on error
*/
static int
ipmi_set_session_privlvl_cmd(ipmi_handle_t *ihp, uint8_t privlvl)
{
ipmi_cmd_t cmd, resp;
int ret = 0, ccode;
if (privlvl > IPMI_SESSION_PRIV_OEM)
return (ipmi_set_error(ihp, EIPMI_BADPARAM, NULL));
cmd.ic_netfn = IPMI_NETFN_APP;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_SET_SESSION_PRIVLVL;
cmd.ic_data = &privlvl;
cmd.ic_dlen = 1;
if (ipmi_lan_send(ihp->ih_tdata, &cmd, &resp, &ccode) != 0)
ret = ipmi_set_error(ihp, EIPMI_LAN_SETPRIV, NULL);
return (ret);
}
/*
* See section 22.19
*/
static int
ipmi_close_session_cmd(ipmi_handle_t *ihp)
{
ipmi_lan_t *ilp = (ipmi_lan_t *)ihp->ih_tdata;
ipmi_cmd_t cmd, resp;
uint8_t msg_data[4];
int ret = 0, ccode;
if (! ilp->il_session_active)
return (-1);
(void) memcpy(&msg_data, &ilp->il_session_id, 4);
cmd.ic_netfn = IPMI_NETFN_APP;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_CLOSE_SESSION;
cmd.ic_data = msg_data;
cmd.ic_dlen = 4;
if (ipmi_lan_send(ilp, &cmd, &resp, &ccode) != 0)
ret = -1;
return (ret);
}
/*
* IPMI LAN Session Activation
*
* See section 13.14
*
* 1. send "RMCP Presence Ping" message, response message will
* indicate whether the platform supports IPMI
* 2. send "Get Channel Authentication Capabilities" command
* with AUTHTYPE = none, response packet will contain information
* about supported challenge/response authentication types
* 3. send "Get Session Challenge" command with AUTHTYPE = none
* and indicate the authentication type in the message, response
* packet will contain challenge string and temporary session ID.
* 4. send "Activate Session" command, authenticated with AUTHTYPE
* sent in previous message. Also sends the initial value for
* the outbound sequence number for BMC.
* 5. BMC returns response confirming session activation and
* session ID for this session and initial inbound sequence.
*/
static int
ipmi_lan_activate_session(ipmi_handle_t *ihp)
{
ipmi_lan_t *ilp = (ipmi_lan_t *)ihp->ih_tdata;
ipmi_channel_auth_caps_t *ac;
if (ipmi_lan_ping(ihp) != 0)
return (-1);
if ((ac = ipmi_get_channel_auth_caps(ihp, IPMI_LAN_CHANNEL_E,
ilp->il_privlvl)) == NULL)
return (-1);
/*
* For the sake of simplicity, we're just supporting basic password
* authentication. If this authentication type is not supported then
* we'll bail here.
*/
if (!(ac->cap_authtype & IPMI_SESSION_AUTHTYPE_PASSWORD)) {
free(ac);
return (ipmi_set_error(ihp, EIPMI_LAN_PASSWD_NOTSUP, NULL));
}
free(ac);
if (ipmi_get_session_challenge_cmd(ihp, &ilp->il_session_id,
ilp->il_challenge) != 0)
return (-1);
if (ipmi_activate_session_cmd(ihp) != 0)
return (-1);
ilp->il_session_active = B_TRUE;
if (ipmi_set_session_privlvl_cmd(ihp, ilp->il_privlvl) != 0)
return (-1);
return (0);
}
static void
ipmi_lan_close(void *data)
{
ipmi_lan_t *ilp = (ipmi_lan_t *)data;
if (ilp->il_session_active)
(void) ipmi_close_session_cmd(ilp->il_ihp);
if (ilp->il_sd >= 0)
(void) close(ilp->il_sd);
ipmi_req_clear_entries(ilp->il_ihp);
ipmi_free(ilp->il_ihp, ipmi_req_entries);
ipmi_free(ilp->il_ihp, ilp);
}
static void *
ipmi_lan_open(ipmi_handle_t *ihp, nvlist_t *params)
{
int rc;
struct hostent *host;
ipmi_lan_t *ilp;
char *hostname, *user, *authcode;
if ((ilp = ipmi_zalloc(ihp, sizeof (ipmi_lan_t))) == NULL) {
/* ipmi errno set */
return (NULL);
}
ilp->il_ihp = ihp;
ihp->ih_tdata = ilp;
/*
* Parse the parameters passed in the params nvlist. The following
* parameters are required
* IPMI_LAN_HOST, IPMI_LAN_USER and IPMI_LAN_PASSWD
*
* If any of these were not specified then we abort
*/
if (nvlist_lookup_string(params, IPMI_LAN_HOST, &hostname) ||
nvlist_lookup_string(params, IPMI_LAN_USER, &user) ||
nvlist_lookup_string(params, IPMI_LAN_PASSWD, &authcode)) {
ipmi_free(ihp, ilp);
(void) ipmi_set_error(ihp, EIPMI_BADPARAM, NULL);
return (NULL);
}
(void) strncpy(ilp->il_host, hostname, MAXHOSTNAMELEN);
(void) strncpy(ilp->il_user, user, 16);
(void) strncpy(ilp->il_authcode, authcode, 16);
/*
* IPMI_LAN_PORT is an optional parameter and defaults to port 623
* IPMI_LAN_PRIVLVL is also optional and defaults to admin
* IPMI_LAN_TIMEOUT is optional and will default to 3 seconds
* IPMI_LAN_NUM_RETIES is optional and will default to 5
*/
if (nvlist_lookup_uint16(params, IPMI_LAN_PORT, &ilp->il_port))
ilp->il_port = RMCP_UDP_PORT;
if (nvlist_lookup_uint8(params, IPMI_LAN_PRIVLVL, &ilp->il_privlvl))
ilp->il_privlvl = IPMI_SESSION_PRIV_ADMIN;
if (nvlist_lookup_uint32(params, IPMI_LAN_TIMEOUT, &ilp->il_timeout))
ilp->il_timeout = DEF_IPMI_LAN_TIMEOUT;
if (nvlist_lookup_uint8(params, IPMI_LAN_NUM_RETRIES,
&ilp->il_num_retries))
ilp->il_num_retries = DEF_IPMI_LAN_NUM_RETRIES;
ilp->il_authtype = IPMI_SESSION_AUTHTYPE_PASSWORD;
/*
* Open up and connect a UDP socket between us and the service
* processor
*/
ilp->il_addr.sin_family = AF_INET;
ilp->il_addr.sin_port = htons(ilp->il_port);
rc = inet_pton(AF_INET, (const char *)ilp->il_host,
&ilp->il_addr.sin_addr);
if (rc <= 0) {
if ((host = gethostbyname((const char *)ilp->il_host))
== NULL) {
ipmi_free(ihp, ilp);
(void) ipmi_set_error(ihp, EIPMI_LAN_OPEN_FAILED, NULL);
return (NULL);
}
ilp->il_addr.sin_family = host->h_addrtype;
(void) memcpy(&ilp->il_addr.sin_addr, host->h_addr,
host->h_length);
}
if ((ilp->il_sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
ipmi_free(ihp, ilp);
(void) ipmi_set_error(ihp, EIPMI_LAN_OPEN_FAILED, NULL);
return (NULL);
}
if (connect(ilp->il_sd, (struct sockaddr *)&ilp->il_addr,
sizeof (struct sockaddr_in)) < 0) {
ipmi_lan_close(ilp);
(void) ipmi_set_error(ihp, EIPMI_LAN_OPEN_FAILED, NULL);
return (NULL);
}
if ((ipmi_req_entries = ipmi_zalloc(ihp, sizeof (ipmi_rq_entry_t)))
== NULL)
return (NULL);
/*
* Finally we start up the IPMI LAN session
*/
if ((rc = ipmi_lan_activate_session(ihp)) < 0) {
ipmi_lan_close(ilp);
return (NULL);
}
return (ilp);
}
ipmi_transport_t ipmi_transport_lan = {
ipmi_lan_open,
ipmi_lan_close,
ipmi_lan_send
};
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef IPMI_LAN_H
#define IPMI_LAN_H
#ifdef __cplusplus
extern "C" {
#endif
#pragma pack(1)
#define IPMI_CMD_GET_SESSION_CHALLENGE 0x39
#define IPMI_CMD_ACTIVATE_SESSION 0x3a
#define IPMI_CMD_SET_SESSION_PRIVLVL 0x3b
#define IPMI_CMD_CLOSE_SESSION 0x3c
#define IPMI_AUTHCODE_BUF_SIZE 20
/*
* See section 22.13
*/
#define IPMI_SESSION_AUTHTYPE_NONE 0x01
#define IPMI_SESSION_AUTHTYPE_MD2 0x02
#define IPMI_SESSION_AUTHTYPE_MD5 0x04
#define IPMI_SESSION_AUTHTYPE_PASSWORD 0x10
#define IPMI_SESSION_AUTHTYPE_OEM 0x20
#define IPMI_SESSION_PRIV_UNSPECIFIED 0x0
#define IPMI_SESSION_PRIV_CALLBACK 0x1
#define IPMI_SESSION_PRIV_USER 0x2
#define IPMI_SESSION_PRIV_OPERATOR 0x3
#define IPMI_SESSION_PRIV_ADMIN 0x4
#define IPMI_SESSION_PRIV_OEM 0x5
#define IPMI_BMC_SLAVE_ADDR 0x20
#define IPMI_BUF_SIZE 1024
#define IPMI_REMOTE_SWID 0x81
/*
* The primary RMCP port
*/
#define RMCP_UDP_PORT 623
/*
* The ASF IANA Enterprise Number
*/
#define ASF_RMCP_IANA 4542
/*
* ASF Message Types for presence ping and pong
*/
#define ASF_TYPE_PING 0x80
#define ASF_TYPE_PONG 0x40
/*
* ASF message header
*
* See section 13.2.3
*/
typedef struct asf_hdr {
uint32_t ah_iana;
uint8_t ah_msg_type;
uint8_t ah_msg_tag;
uint8_t __reserved1;
uint8_t ah_dlen;
} asf_hdr_t;
/*
* RMCP message header
*
* See section 13.1.3
*/
#define RMCP_VERSION_1 0x06
#define RMCP_CLASS_ASF 0x06
#define RMCP_CLASS_IPMI 0x07
#define RMCP_CLASS_OEM 0x08
typedef struct rmcp_hdr {
uint8_t rh_version;
uint8_t __reserved1;
uint8_t rh_seq;
DECL_BITFIELD3(
rh_msg_class:5,
__reserved2:2,
rh_msg_type:1);
} rmcp_hdr_t;
/*
* IPMI Session Header
*
* The IPMI session header contains some optional payload fields that are only
* present in RMCP+ sessions or if the payload type is "OEM explicit". This
* structure is only intended to represent the session header for IPMI v1.5
* messages.
*
* See section 13.6
*/
typedef struct v15_session_hdr {
uint8_t sh_authtype;
uint32_t sh_seq;
uint32_t sh_id;
} v15_session_hdr_t;
/*
* IPMI Lan Message Header
*
* See section 13.8
*/
typedef struct ipmi_msg_hdr {
uint8_t imh_addr1;
DECL_BITFIELD2(
imh_lun:2,
imh_netfn:6);
uint8_t imh_csum;
uint8_t imh_addr2;
uint8_t imh_seq;
uint8_t imh_cmd;
} ipmi_msg_hdr_t;
#pragma pack()
#ifdef __cplusplus
}
#endif
#endif /* IPMI_LAN_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Query and configure LAN interfaces over IPMI. This is done through the
* complicated get/set LAN Configuration Parameters command. This queries or
* sets the parameters one per command in series. We hide this implementation
* detail and instead export a single structure to consumers.
*/
#include <stddef.h>
#include <strings.h>
#include <libipmi.h>
#include "ipmi_impl.h"
typedef struct ipmi_cmd_lan_get_config {
DECL_BITFIELD3(
ilgc_number :4,
__reserved :3,
ilgc_revonly :1);
uint8_t ilgc_param;
uint8_t ilgc_set;
uint8_t ilgc_block;
} ipmi_cmd_lan_get_config_t;
typedef struct ipmi_cmd_lan_set_config {
DECL_BITFIELD2(
ilsc_number :4,
__reserved :4);
uint8_t ilsc_param;
uint8_t ilsc_data[18];
} ipmi_cmd_lan_set_config_t;
#define IPMI_LAN_SET_LEN(dlen) \
(offsetof(ipmi_cmd_lan_set_config_t, ilsc_data) + (dlen))
#define IPMI_LAN_PARAM_SET_IN_PROGRESS 0
#define IPMI_LAN_PARAM_IP_ADDR 3
#define IPMI_LAN_PARAM_IP_SOURCE 4
#define IPMI_LAN_PARAM_MAC_ADDR 5
#define IPMI_LAN_PARAM_SUBNET_MASK 6
#define IPMI_LAN_PARAM_GATEWAY_ADDR 12
#define IPMI_LAN_SET_COMPLETE 0x0
#define IPMI_LAN_SET_INPROGRESS 0x1
#define IPMI_LAN_SET_COMMIT 0x2
typedef struct ipmi_lan_entry {
int ile_param;
int ile_mask;
int ile_set;
int ile_block;
size_t ile_offset;
size_t ile_len;
} ipmi_lan_entry_t;
static ipmi_lan_entry_t ipmi_lan_table[] = {
{ IPMI_LAN_PARAM_IP_ADDR, IPMI_LAN_SET_IPADDR, 0, 0,
offsetof(ipmi_lan_config_t, ilc_ipaddr), sizeof (uint32_t) },
{ IPMI_LAN_PARAM_IP_SOURCE, IPMI_LAN_SET_IPADDR_SOURCE, 0, 0,
offsetof(ipmi_lan_config_t, ilc_ipaddr_source), sizeof (uint8_t) },
{ IPMI_LAN_PARAM_MAC_ADDR, IPMI_LAN_SET_MACADDR, 0, 0,
offsetof(ipmi_lan_config_t, ilc_macaddr), 6 * sizeof (uint8_t) },
{ IPMI_LAN_PARAM_SUBNET_MASK, IPMI_LAN_SET_SUBNET, 0, 0,
offsetof(ipmi_lan_config_t, ilc_subnet), sizeof (uint32_t) },
{ IPMI_LAN_PARAM_GATEWAY_ADDR, IPMI_LAN_SET_GATEWAY_ADDR, 0, 0,
offsetof(ipmi_lan_config_t, ilc_gateway_addr), sizeof (uint32_t) }
};
#define IPMI_LAN_NENTRIES \
(sizeof (ipmi_lan_table) / sizeof (ipmi_lan_table[0]))
static int
ipmi_lan_get_param(ipmi_handle_t *ihp, int channel, int param, int set,
int block, void *data, size_t len)
{
ipmi_cmd_t cmd, *rsp;
ipmi_cmd_lan_get_config_t lcmd = { 0 };
lcmd.ilgc_number = channel;
lcmd.ilgc_param = param;
lcmd.ilgc_set = set;
lcmd.ilgc_block = block;
cmd.ic_netfn = IPMI_NETFN_TRANSPORT;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_LAN_CONFIG;
cmd.ic_data = &lcmd;
cmd.ic_dlen = sizeof (lcmd);
if ((rsp = ipmi_send(ihp, &cmd)) == NULL) {
switch (ihp->ih_completion) {
case 0x80:
(void) ipmi_set_error(ihp, EIPMI_BADPARAM, NULL);
break;
}
return (-1);
}
if (rsp->ic_dlen < len + 1)
return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
bcopy((uint8_t *)rsp->ic_data + 1, data, len);
return (0);
}
int
ipmi_lan_get_config(ipmi_handle_t *ihp, int channel, ipmi_lan_config_t *cfgp)
{
uint8_t set;
int i;
ipmi_lan_entry_t *lep;
if (ipmi_lan_get_param(ihp, channel, IPMI_LAN_PARAM_SET_IN_PROGRESS, 0,
0, &set, sizeof (set)) != 0)
return (-1);
if (set & IPMI_LAN_SET_INPROGRESS)
cfgp->ilc_set_in_progress = B_TRUE;
else
cfgp->ilc_set_in_progress = B_FALSE;
for (i = 0; i < IPMI_LAN_NENTRIES; i++) {
lep = &ipmi_lan_table[i];
if (ipmi_lan_get_param(ihp, channel, lep->ile_param,
lep->ile_set, lep->ile_block,
(char *)cfgp + lep->ile_offset, lep->ile_len) != 0)
return (-1);
}
return (0);
}
static int
ipmi_lan_set_param(ipmi_handle_t *ihp, int channel, int param, void *data,
size_t len)
{
ipmi_cmd_t cmd;
ipmi_cmd_lan_set_config_t lcmd = { 0 };
lcmd.ilsc_number = channel;
lcmd.ilsc_param = param;
bcopy(data, lcmd.ilsc_data, len);
cmd.ic_netfn = IPMI_NETFN_TRANSPORT;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_SET_LAN_CONFIG;
cmd.ic_data = &lcmd;
cmd.ic_dlen = IPMI_LAN_SET_LEN(len);
if (ipmi_send(ihp, &cmd) == NULL) {
switch (ihp->ih_completion) {
case 0x80:
(void) ipmi_set_error(ihp, EIPMI_BADPARAM, NULL);
break;
case 0x81:
(void) ipmi_set_error(ihp, EIPMI_BUSY, NULL);
break;
case 0x82:
(void) ipmi_set_error(ihp, EIPMI_READONLY, NULL);
break;
case 0x83:
(void) ipmi_set_error(ihp, EIPMI_WRITEONLY, NULL);
break;
}
return (-1);
}
return (0);
}
int
ipmi_lan_set_config(ipmi_handle_t *ihp, int channel, ipmi_lan_config_t *cfgp,
int mask)
{
uint8_t set;
int i;
ipmi_lan_entry_t *lep;
/*
* Cancel any pending transaction, then open a new transaction.
*/
set = IPMI_LAN_SET_COMPLETE;
if (ipmi_lan_set_param(ihp, channel, IPMI_LAN_PARAM_SET_IN_PROGRESS,
&set, sizeof (set)) != 0)
return (-1);
set = IPMI_LAN_SET_INPROGRESS;
if (ipmi_lan_set_param(ihp, channel, IPMI_LAN_PARAM_SET_IN_PROGRESS,
&set, sizeof (set)) != 0)
return (-1);
/*
* Iterate over all parameters and set them.
*/
for (i = 0; i < IPMI_LAN_NENTRIES; i++) {
lep = &ipmi_lan_table[i];
if (!(lep->ile_mask & mask))
continue;
if (ipmi_lan_set_param(ihp, channel, lep->ile_param,
(char *)cfgp + lep->ile_offset, lep->ile_len) != 0) {
/*
* On some systems, setting the mode to DHCP may cause
* the command to timeout, presumably because it is
* waiting for the setting to take effect. If we see
* completion code 0xc3 (command timeout) while setting
* the DHCP value, just ignore it.
*/
if (mask != IPMI_LAN_SET_IPADDR_SOURCE ||
cfgp->ilc_ipaddr_source != IPMI_LAN_SRC_DHCP ||
ihp->ih_completion != 0xC3)
return (-1);
}
}
/*
* Commit the transaction.
*/
set = IPMI_LAN_SET_COMPLETE;
if (ipmi_lan_set_param(ihp, channel, IPMI_LAN_PARAM_SET_IN_PROGRESS,
&set, sizeof (set)) != 0)
return (-1);
return (0);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Embedded Linked Lists
*
* Simple doubly-linked list implementation. This implementation assumes that
* each list element contains an embedded ipmi_list_t (previous and next
* pointers), which is typically the first member of the element struct.
* An additional ipmi_list_t is used to store the head (l_next) and tail
* (l_prev) pointers. The current head and tail list elements have their
* previous and next pointers set to NULL, respectively.
*/
#include <assert.h>
#include <ipmi_impl.h>
void
ipmi_list_append(ipmi_list_t *lp, void *new)
{
ipmi_list_t *p = lp->l_prev; /* p = tail list element */
ipmi_list_t *q = new; /* q = new list element */
lp->l_prev = q;
q->l_prev = p;
q->l_next = NULL;
if (p != NULL) {
assert(p->l_next == NULL);
p->l_next = q;
} else {
assert(lp->l_next == NULL);
lp->l_next = q;
}
}
void
ipmi_list_prepend(ipmi_list_t *lp, void *new)
{
ipmi_list_t *p = new; /* p = new list element */
ipmi_list_t *q = lp->l_next; /* q = head list element */
lp->l_next = p;
p->l_prev = NULL;
p->l_next = q;
if (q != NULL) {
assert(q->l_prev == NULL);
q->l_prev = p;
} else {
assert(lp->l_prev == NULL);
lp->l_prev = p;
}
}
void
ipmi_list_insert_before(ipmi_list_t *lp, void *before_me, void *new)
{
ipmi_list_t *p = before_me;
ipmi_list_t *q = new;
if (p == NULL || p->l_prev == NULL) {
ipmi_list_prepend(lp, new);
return;
}
q->l_prev = p->l_prev;
q->l_next = p;
p->l_prev = q;
q->l_prev->l_next = q;
}
void
ipmi_list_insert_after(ipmi_list_t *lp, void *after_me, void *new)
{
ipmi_list_t *p = after_me;
ipmi_list_t *q = new;
if (p == NULL || p->l_next == NULL) {
ipmi_list_append(lp, new);
return;
}
q->l_next = p->l_next;
q->l_prev = p;
p->l_next = q;
q->l_next->l_prev = q;
}
void
ipmi_list_delete(ipmi_list_t *lp, void *existing)
{
ipmi_list_t *p = existing;
if (p->l_prev != NULL)
p->l_prev->l_next = p->l_next;
else
lp->l_next = p->l_next;
if (p->l_next != NULL)
p->l_next->l_prev = p->l_prev;
else
lp->l_prev = p->l_prev;
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, Joyent, Inc.
*/
#include <libipmi.h>
#include <stdio.h>
#include <string.h>
#include "ipmi_impl.h"
ipmi_deviceid_t *
ipmi_get_deviceid(ipmi_handle_t *ihp)
{
ipmi_cmd_t cmd, *resp;
uint16_t id_prod;
if (ihp->ih_deviceid != NULL)
return (ihp->ih_deviceid);
cmd.ic_netfn = IPMI_NETFN_APP;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_DEVICEID;
cmd.ic_data = NULL;
cmd.ic_dlen = 0;
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (NULL);
if (resp->ic_dlen < sizeof (ipmi_deviceid_t)) {
(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
return (NULL);
}
/*
* The devid response data may include additional data beyond the end of
* the normal structure, so we copy the entire response.
*/
if ((ihp->ih_deviceid = ipmi_alloc(ihp, resp->ic_dlen)) == NULL)
return (NULL);
(void) memcpy(ihp->ih_deviceid, resp->ic_data, resp->ic_dlen);
id_prod = LE_IN16(&ihp->ih_deviceid->id_product);
(void) memcpy(&ihp->ih_deviceid->id_product, &id_prod,
sizeof (id_prod));
ihp->ih_deviceid_len = resp->ic_dlen;
return (ihp->ih_deviceid);
}
/*
* Returns the firmware revision as a string. This does the work of converting
* the deviceid data into a human readable string (decoding the BCD values).
* It also encodes the fact that Sun ILOM includes the additional micro revision
* at the end of the deviceid information.
*/
const char *
ipmi_firmware_version(ipmi_handle_t *ihp)
{
ipmi_deviceid_t *dp;
uint8_t *auxrev;
size_t len;
char rev[128];
int i;
if (ihp->ih_firmware_rev != NULL)
return (ihp->ih_firmware_rev);
if ((dp = ipmi_get_deviceid(ihp)) == NULL)
return (NULL);
/*
* Start with the major an minor revision numbers
*/
(void) snprintf(rev, sizeof (rev), "%d.%d", dp->id_firm_major,
ipmi_convert_bcd(dp->id_firm_minor));
if (ipmi_is_sun_ilom(dp) &&
ihp->ih_deviceid_len >= sizeof (ipmi_deviceid_t) + 4) {
/*
* With Sun ILOM we have the micro revision at the end of the
* deviceid. The first two bytes of the aux revision field are
* the platform version and release version.
*/
auxrev = (uint8_t *)dp + sizeof (ipmi_deviceid_t);
for (i = 0; i < 2; i++) {
if (auxrev[i] == 0)
continue;
len = strlen(rev);
(void) snprintf(rev + len, sizeof (rev) - len, ".%u",
auxrev[i]);
}
}
if ((ihp->ih_firmware_rev = ipmi_strdup(ihp, rev)) == NULL)
return (NULL);
return (ihp->ih_firmware_rev);
}
/*
* IPMI Get Channel Authentication Capabilities Command
* See Section 22.13
*
* Caller is responsible for free'ing returned ipmi_channel_auth_caps_t
*/
ipmi_channel_auth_caps_t *
ipmi_get_channel_auth_caps(ipmi_handle_t *ihp, uint8_t channel, uint8_t priv)
{
ipmi_cmd_t cmd, *resp;
uint8_t msg_data[2];
ipmi_channel_auth_caps_t *caps;
if (channel > 0xF) {
(void) ipmi_set_error(ihp, EIPMI_INVALID_REQUEST, NULL);
return (NULL);
}
msg_data[0] = channel;
msg_data[1] = priv;
cmd.ic_netfn = IPMI_NETFN_APP;
cmd.ic_cmd = IPMI_CMD_GET_CHANNEL_AUTH_CAPS;
cmd.ic_data = msg_data;
cmd.ic_dlen = sizeof (msg_data);
cmd.ic_lun = 0;
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (NULL);
if (resp->ic_dlen < sizeof (ipmi_channel_auth_caps_t)) {
(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
return (NULL);
}
if ((caps = ipmi_alloc(ihp, sizeof (ipmi_channel_auth_caps_t)))
== NULL)
/* ipmi errno set */
return (NULL);
(void) memcpy(caps, resp->ic_data, sizeof (ipmi_channel_auth_caps_t));
return (caps);
}
ipmi_channel_info_t *
ipmi_get_channel_info(ipmi_handle_t *ihp, int number)
{
ipmi_cmd_t cmd, *rsp;
uint8_t channel;
if (number > 0xF) {
(void) ipmi_set_error(ihp, EIPMI_INVALID_REQUEST, NULL);
return (NULL);
}
channel = (uint8_t)number;
cmd.ic_netfn = IPMI_NETFN_APP;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_CHANNEL_INFO;
cmd.ic_data = &channel;
cmd.ic_dlen = sizeof (channel);
if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
return (NULL);
if (rsp->ic_dlen < sizeof (ipmi_channel_info_t)) {
(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
return (NULL);
}
return (rsp->ic_data);
}
/*
* IPMI Chassis Identify Command
* See Section 28.5
*/
int
ipmi_chassis_identify(ipmi_handle_t *ihp, boolean_t enable)
{
ipmi_cmd_t cmd;
uint8_t msg_data[2];
if (enable) {
msg_data[0] = 0;
msg_data[1] = 1;
} else {
msg_data[0] = 0;
msg_data[1] = 0;
}
cmd.ic_netfn = IPMI_NETFN_CHASSIS;
cmd.ic_cmd = IPMI_CMD_CHASSIS_IDENTIFY;
cmd.ic_data = msg_data;
cmd.ic_dlen = sizeof (msg_data);
cmd.ic_lun = 0;
if (ipmi_send(ihp, &cmd) == NULL)
return (-1);
return (0);
}
/*
* caller is responsible for free'ing returned structure
*/
ipmi_chassis_status_t *
ipmi_chassis_status(ipmi_handle_t *ihp)
{
ipmi_cmd_t cmd, *rsp;
ipmi_chassis_status_t *chs;
cmd.ic_netfn = IPMI_NETFN_CHASSIS;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_CHASSIS_STATUS;
cmd.ic_data = NULL;
cmd.ic_dlen = 0;
if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
return (NULL);
if (rsp->ic_dlen < sizeof (ipmi_chassis_status_t)) {
(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
return (NULL);
}
if ((chs = ipmi_alloc(ihp, sizeof (ipmi_chassis_status_t))) == NULL) {
/* ipmi errno set */
return (NULL);
}
(void) memcpy(chs, rsp->ic_data, sizeof (ipmi_chassis_status_t));
return (chs);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2018, Joyent, Inc.
*/
#include <libipmi.h>
#include <stddef.h>
#include <string.h>
#include <strings.h>
#include <math.h>
#include "ipmi_impl.h"
/*
* This macros are used by ipmi_sdr_conv_reading. They were taken verbatim from
* the source for ipmitool (v1.88)
*/
#define tos32(val, bits) ((val & ((1<<((bits)-1)))) ? (-((val) & \
(1<<((bits)-1))) | (val)) : (val))
#define __TO_TOL(mtol) (uint16_t)(BSWAP_16(mtol) & 0x3f)
#define __TO_M(mtol) (int16_t)(tos32((((BSWAP_16(mtol) & 0xff00) >> 8) | \
((BSWAP_16(mtol) & 0xc0) << 2)), 10))
#define __TO_B(bacc) (int32_t)(tos32((((BSWAP_32(bacc) & \
0xff000000) >> 24) | \
((BSWAP_32(bacc) & 0xc00000) >> 14)), 10))
#define __TO_ACC(bacc) (uint32_t)(((BSWAP_32(bacc) & 0x3f0000) >> 16) | \
((BSWAP_32(bacc) & 0xf000) >> 6))
#define __TO_ACC_EXP(bacc) (uint32_t)((BSWAP_32(bacc) & 0xc00) >> 10)
#define __TO_R_EXP(bacc) (int32_t)(tos32(((BSWAP_32(bacc) & 0xf0) >> 4),\
4))
#define __TO_B_EXP(bacc) (int32_t)(tos32((BSWAP_32(bacc) & 0xf), 4))
#define SDR_SENSOR_L_LINEAR 0x00
#define SDR_SENSOR_L_LN 0x01
#define SDR_SENSOR_L_LOG10 0x02
#define SDR_SENSOR_L_LOG2 0x03
#define SDR_SENSOR_L_E 0x04
#define SDR_SENSOR_L_EXP10 0x05
#define SDR_SENSOR_L_EXP2 0x06
#define SDR_SENSOR_L_1_X 0x07
#define SDR_SENSOR_L_SQR 0x08
#define SDR_SENSOR_L_CUBE 0x09
#define SDR_SENSOR_L_SQRT 0x0a
#define SDR_SENSOR_L_CUBERT 0x0b
#define SDR_SENSOR_L_NONLINEAR 0x70
/*
* Analog sensor reading data formats
*
* See Section 43.1
*/
#define IPMI_DATA_FMT_UNSIGNED 0
#define IPMI_DATA_FMT_ONESCOMP 1
#define IPMI_DATA_FMT_TWOSCOMP 2
#define IPMI_SDR_HDR_SZ offsetof(ipmi_sdr_t, is_record)
typedef struct ipmi_sdr_cache_ent {
char *isc_name;
uint8_t isc_entity_id;
uint8_t isc_entity_inst;
struct ipmi_sdr *isc_sdr;
ipmi_hash_link_t isc_link;
} ipmi_sdr_cache_ent_t;
typedef struct ipmi_cmd_get_sdr {
uint16_t ic_gs_resid;
uint16_t ic_gs_recid;
uint8_t ic_gs_offset;
uint8_t ic_gs_len;
} ipmi_cmd_get_sdr_t;
typedef struct ipmi_rsp_get_sdr {
uint16_t ir_gs_next;
uint8_t ir_gs_record[1];
} ipmi_rsp_get_sdr_t;
/*
* "Get SDR Repostiory Info" command.
*/
ipmi_sdr_info_t *
ipmi_sdr_get_info(ipmi_handle_t *ihp)
{
ipmi_cmd_t cmd, *rsp;
ipmi_sdr_info_t *sip;
uint16_t tmp16;
uint32_t tmp32;
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_SDR_INFO;
cmd.ic_dlen = 0;
cmd.ic_data = NULL;
if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
return (NULL);
sip = rsp->ic_data;
tmp16 = LE_IN16(&sip->isi_record_count);
(void) memcpy(&sip->isi_record_count, &tmp16, sizeof (tmp16));
tmp16 = LE_IN16(&sip->isi_free_space);
(void) memcpy(&sip->isi_free_space, &tmp16, sizeof (tmp16));
tmp32 = LE_IN32(&sip->isi_add_ts);
(void) memcpy(&sip->isi_add_ts, &tmp32, sizeof (tmp32));
tmp32 = LE_IN32(&sip->isi_erase_ts);
(void) memcpy(&sip->isi_erase_ts, &tmp32, sizeof (tmp32));
return (sip);
}
/*
* Issue the "Reserve SDR Repository" command.
*/
static int
ipmi_sdr_reserve_repository(ipmi_handle_t *ihp)
{
ipmi_cmd_t cmd, *rsp;
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_RESERVE_SDR_REPOSITORY;
cmd.ic_dlen = 0;
cmd.ic_data = NULL;
if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
return (-1);
ihp->ih_reservation = *((uint16_t *)rsp->ic_data);
return (0);
}
/*
* Returns B_TRUE if the repository has changed since the cached copy was last
* referenced.
*/
boolean_t
ipmi_sdr_changed(ipmi_handle_t *ihp)
{
ipmi_sdr_info_t *sip;
if ((sip = ipmi_sdr_get_info(ihp)) == NULL)
return (B_TRUE);
return (sip->isi_add_ts > ihp->ih_sdr_ts ||
sip->isi_erase_ts > ihp->ih_sdr_ts ||
ipmi_hash_first(ihp->ih_sdr_cache) == NULL);
}
/*
* Refresh the cache of sensor data records.
*/
int
ipmi_sdr_refresh(ipmi_handle_t *ihp)
{
uint16_t id;
ipmi_sdr_t *sdr;
ipmi_sdr_cache_ent_t *ent;
size_t namelen;
uint8_t type, e_id = 0, e_inst = 0;
char *name;
ipmi_sdr_info_t *sip;
uint32_t isi_add_ts, isi_erase_ts;
if ((sip = ipmi_sdr_get_info(ihp)) == NULL)
return (-1);
(void) memcpy(&isi_add_ts, &sip->isi_add_ts, sizeof (uint32_t));
(void) memcpy(&isi_erase_ts, &sip->isi_erase_ts, sizeof (uint32_t));
if (isi_add_ts <= ihp->ih_sdr_ts &&
isi_erase_ts <= ihp->ih_sdr_ts &&
ipmi_hash_first(ihp->ih_sdr_cache) != NULL)
return (0);
ipmi_sdr_clear(ihp);
ipmi_entity_clear(ihp);
ihp->ih_sdr_ts = MAX(isi_add_ts, isi_erase_ts);
/*
* Iterate over all existing SDRs and add them to the cache.
*/
id = IPMI_SDR_FIRST;
while (id != IPMI_SDR_LAST) {
if ((sdr = ipmi_sdr_get(ihp, id, &id)) == NULL)
goto error;
/*
* Extract the name from the record-specific data.
*/
switch (sdr->is_type) {
case IPMI_SDR_TYPE_GENERIC_LOCATOR:
{
ipmi_sdr_generic_locator_t *glp =
(ipmi_sdr_generic_locator_t *)
sdr->is_record;
namelen = glp->is_gl_idlen;
type = glp->is_gl_idtype;
name = glp->is_gl_idstring;
e_id = glp->is_gl_entity;
e_inst = glp->is_gl_instance;
break;
}
case IPMI_SDR_TYPE_FRU_LOCATOR:
{
ipmi_sdr_fru_locator_t *flp =
(ipmi_sdr_fru_locator_t *)
sdr->is_record;
namelen = flp->is_fl_idlen;
name = flp->is_fl_idstring;
type = flp->is_fl_idtype;
e_id = flp->is_fl_entity;
e_inst = flp->is_fl_instance;
break;
}
case IPMI_SDR_TYPE_COMPACT_SENSOR:
{
ipmi_sdr_compact_sensor_t *csp =
(ipmi_sdr_compact_sensor_t *)
sdr->is_record;
uint16_t tmp;
namelen = csp->is_cs_idlen;
type = csp->is_cs_idtype;
name = csp->is_cs_idstring;
e_id = csp->is_cs_entity_id;
e_inst = csp->is_cs_entity_instance;
tmp = LE_IN16(&csp->is_cs_assert_mask);
(void) memcpy(&csp->is_cs_assert_mask, &tmp,
sizeof (tmp));
tmp = LE_IN16(&csp->is_cs_deassert_mask);
(void) memcpy(&csp->is_cs_deassert_mask, &tmp,
sizeof (tmp));
tmp = LE_IN16(&csp->is_cs_reading_mask);
(void) memcpy(&csp->is_cs_reading_mask, &tmp,
sizeof (tmp));
break;
}
case IPMI_SDR_TYPE_FULL_SENSOR:
{
ipmi_sdr_full_sensor_t *fsp =
(ipmi_sdr_full_sensor_t *)
sdr->is_record;
uint16_t tmp;
namelen = fsp->is_fs_idlen;
type = fsp->is_fs_idtype;
name = fsp->is_fs_idstring;
e_id = fsp->is_fs_entity_id;
e_inst = fsp->is_fs_entity_instance;
tmp = LE_IN16(&fsp->is_fs_assert_mask);
(void) memcpy(&fsp->is_fs_assert_mask, &tmp,
sizeof (tmp));
tmp = LE_IN16(&fsp->is_fs_deassert_mask);
(void) memcpy(&fsp->is_fs_deassert_mask, &tmp,
sizeof (tmp));
tmp = LE_IN16(&fsp->is_fs_reading_mask);
(void) memcpy(&fsp->is_fs_reading_mask, &tmp,
sizeof (tmp));
break;
}
case IPMI_SDR_TYPE_EVENT_ONLY:
{
ipmi_sdr_event_only_t *esp =
(ipmi_sdr_event_only_t *)
sdr->is_record;
namelen = esp->is_eo_idlen;
type = esp->is_eo_idtype;
name = esp->is_eo_idstring;
e_id = esp->is_eo_entity_id;
e_inst = esp->is_eo_entity_instance;
break;
}
case IPMI_SDR_TYPE_MANAGEMENT_LOCATOR:
{
ipmi_sdr_management_locator_t *msp =
(ipmi_sdr_management_locator_t *)
sdr->is_record;
namelen = msp->is_ml_idlen;
type = msp->is_ml_idtype;
name = msp->is_ml_idstring;
e_id = msp->is_ml_entity_id;
e_inst = msp->is_ml_entity_instance;
break;
}
case IPMI_SDR_TYPE_MANAGEMENT_CONFIRMATION:
{
ipmi_sdr_management_confirmation_t *mcp =
(ipmi_sdr_management_confirmation_t *)
sdr->is_record;
uint16_t tmp;
name = NULL;
tmp = LE_IN16(&mcp->is_mc_product);
(void) memcpy(&mcp->is_mc_product, &tmp,
sizeof (tmp));
break;
}
default:
name = NULL;
}
if ((ent = ipmi_zalloc(ihp,
sizeof (ipmi_sdr_cache_ent_t))) == NULL) {
free(sdr);
goto error;
}
ent->isc_sdr = sdr;
ent->isc_entity_id = e_id;
ent->isc_entity_inst = e_inst;
if (name != NULL) {
if ((ent->isc_name = ipmi_alloc(ihp, namelen + 1)) ==
NULL) {
ipmi_free(ihp, ent->isc_sdr);
ipmi_free(ihp, ent);
goto error;
}
ipmi_decode_string(type, namelen, name, ent->isc_name);
}
/*
* This should never happen. It means that the SP has returned
* a SDR record twice, with the same name and ID. This has
* been observed on service processors that don't correctly
* return SDR_LAST during iteration, so assume we've looped in
* the SDR and return gracefully.
*/
if (ipmi_hash_lookup(ihp->ih_sdr_cache, ent) != NULL) {
ipmi_free(ihp, ent->isc_sdr);
ipmi_free(ihp, ent->isc_name);
ipmi_free(ihp, ent);
break;
}
ipmi_hash_insert(ihp->ih_sdr_cache, ent);
}
return (0);
error:
ipmi_sdr_clear(ihp);
ipmi_entity_clear(ihp);
return (-1);
}
/*
* Hash routines. We allow lookup by name, but since not all entries have
* names, we fall back to the entry pointer, which is guaranteed to be unique.
* The end result is that entities without names cannot be looked up, but will
* show up during iteration.
*/
static const void *
ipmi_sdr_hash_convert(const void *p)
{
return (p);
}
static ulong_t
ipmi_sdr_hash_compute(const void *p)
{
const ipmi_sdr_cache_ent_t *ep = p;
if (ep->isc_name)
return (ipmi_hash_strhash(ep->isc_name));
else
return (ipmi_hash_ptrhash(ep));
}
static int
ipmi_sdr_hash_compare(const void *a, const void *b)
{
const ipmi_sdr_cache_ent_t *ap = a;
const ipmi_sdr_cache_ent_t *bp = b;
if (ap->isc_name == NULL || bp->isc_name == NULL)
return (-1);
if (strcmp(ap->isc_name, bp->isc_name) != 0)
return (-1);
/*
* When looking up only by name we return the first matching name. For
* a more precise match, callers can optionally specify an IPMI entity
* ID and instance that must also match.
*/
if (ap->isc_entity_id != IPMI_ET_UNSPECIFIED &&
bp->isc_entity_id != IPMI_ET_UNSPECIFIED) {
if (ap->isc_entity_id != bp->isc_entity_id ||
ap->isc_entity_inst != bp->isc_entity_inst)
return (-1);
}
return (0);
}
int
ipmi_sdr_init(ipmi_handle_t *ihp)
{
if ((ihp->ih_sdr_cache = ipmi_hash_create(ihp,
offsetof(ipmi_sdr_cache_ent_t, isc_link),
ipmi_sdr_hash_convert, ipmi_sdr_hash_compute,
ipmi_sdr_hash_compare)) == NULL)
return (-1);
return (0);
}
void
ipmi_sdr_clear(ipmi_handle_t *ihp)
{
ipmi_sdr_cache_ent_t *ent;
while ((ent = ipmi_hash_first(ihp->ih_sdr_cache)) != NULL) {
ipmi_hash_remove(ihp->ih_sdr_cache, ent);
ipmi_free(ihp, ent->isc_sdr);
ipmi_free(ihp, ent->isc_name);
ipmi_free(ihp, ent);
}
}
void
ipmi_sdr_fini(ipmi_handle_t *ihp)
{
if (ihp->ih_sdr_cache != NULL) {
ipmi_sdr_clear(ihp);
ipmi_hash_destroy(ihp->ih_sdr_cache);
}
}
ipmi_sdr_t *
ipmi_sdr_get(ipmi_handle_t *ihp, uint16_t id, uint16_t *next)
{
uint8_t offset = IPMI_SDR_HDR_SZ, count = 0, chunksz = 16, sdr_sz;
ipmi_cmd_t cmd, *rsp;
ipmi_cmd_get_sdr_t req;
ipmi_sdr_t *sdr;
int i = 0;
char *buf;
req.ic_gs_resid = ihp->ih_reservation;
req.ic_gs_recid = id;
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_SDR;
cmd.ic_dlen = sizeof (req);
cmd.ic_data = &req;
/*
* The size of the SDR is contained in the 5th byte of the SDR header,
* so we'll read the first 5 bytes to get the size, so we know how big
* to make the buffer.
*/
req.ic_gs_offset = 0;
req.ic_gs_len = IPMI_SDR_HDR_SZ;
for (i = 0; i < ihp->ih_retries; i++) {
if ((rsp = ipmi_send(ihp, &cmd)) != NULL)
break;
if (ipmi_errno(ihp) != EIPMI_INVALID_RESERVATION)
return (NULL);
if (ipmi_sdr_reserve_repository(ihp) != 0)
return (NULL);
req.ic_gs_resid = ihp->ih_reservation;
}
if (rsp == NULL)
return (NULL);
sdr = (ipmi_sdr_t *)((ipmi_rsp_get_sdr_t *)rsp->ic_data)->ir_gs_record;
sdr_sz = sdr->is_length;
if ((buf = ipmi_zalloc(ihp, sdr_sz + IPMI_SDR_HDR_SZ)) == NULL) {
(void) ipmi_set_error(ihp, EIPMI_NOMEM, NULL);
return (NULL);
}
(void) memcpy(buf, (void *)sdr, IPMI_SDR_HDR_SZ);
/*
* Some SDRs can be bigger than the buffer sizes for a given bmc
* interface. Therefore we break up the process of reading in an entire
* SDR into multiple smaller reads.
*/
while (count < sdr_sz) {
req.ic_gs_offset = offset;
if (chunksz > (sdr_sz - count))
chunksz = sdr_sz - count;
req.ic_gs_len = chunksz;
rsp = ipmi_send(ihp, &cmd);
if (rsp != NULL) {
count += chunksz;
sdr = (ipmi_sdr_t *)
((ipmi_rsp_get_sdr_t *)rsp->ic_data)->ir_gs_record;
(void) memcpy(buf+offset, (void *)sdr, chunksz);
offset += chunksz;
i = 0;
} else if (ipmi_errno(ihp) == EIPMI_INVALID_RESERVATION) {
if (i >= ihp->ih_retries ||
ipmi_sdr_reserve_repository(ihp) != 0) {
free(buf);
return (NULL);
}
req.ic_gs_resid = ihp->ih_reservation;
i++;
} else {
free(buf);
return (NULL);
}
}
*next = ((ipmi_rsp_get_sdr_t *)rsp->ic_data)->ir_gs_next;
return ((ipmi_sdr_t *)buf);
}
int
ipmi_sdr_iter(ipmi_handle_t *ihp, int (*func)(ipmi_handle_t *,
const char *, ipmi_sdr_t *, void *), void *data)
{
ipmi_sdr_cache_ent_t *ent;
int ret;
if (ipmi_hash_first(ihp->ih_sdr_cache) == NULL &&
ipmi_sdr_refresh(ihp) != 0)
return (-1);
for (ent = ipmi_hash_first(ihp->ih_sdr_cache); ent != NULL;
ent = ipmi_hash_next(ihp->ih_sdr_cache, ent)) {
if ((ret = func(ihp, ent->isc_name, ent->isc_sdr, data)) != 0)
return (ret);
}
return (0);
}
ipmi_sdr_t *
ipmi_sdr_lookup(ipmi_handle_t *ihp, const char *idstr)
{
return (ipmi_sdr_lookup_precise(ihp, idstr, IPMI_ET_UNSPECIFIED, 0));
}
ipmi_sdr_t *
ipmi_sdr_lookup_precise(ipmi_handle_t *ihp, const char *idstr, uint8_t e_id,
uint8_t e_inst)
{
ipmi_sdr_cache_ent_t *ent, search;
if (ipmi_hash_first(ihp->ih_sdr_cache) == NULL &&
ipmi_sdr_refresh(ihp) != 0)
return (NULL);
search.isc_name = (char *)idstr;
search.isc_sdr = NULL;
search.isc_entity_id = e_id;
search.isc_entity_inst = e_inst;
if ((ent = ipmi_hash_lookup(ihp->ih_sdr_cache, &search)) == NULL) {
(void) ipmi_set_error(ihp, EIPMI_NOT_PRESENT, NULL);
return (NULL);
}
return (ent->isc_sdr);
}
static void *
ipmi_sdr_lookup_common(ipmi_handle_t *ihp, const char *idstr,
uint8_t type)
{
ipmi_sdr_t *sdrp;
if ((sdrp = ipmi_sdr_lookup(ihp, idstr)) == NULL)
return (NULL);
if (sdrp->is_type != type) {
(void) ipmi_set_error(ihp, EIPMI_NOT_PRESENT, NULL);
return (NULL);
}
return (sdrp->is_record);
}
ipmi_sdr_fru_locator_t *
ipmi_sdr_lookup_fru(ipmi_handle_t *ihp, const char *idstr)
{
return (ipmi_sdr_lookup_common(ihp, idstr,
IPMI_SDR_TYPE_FRU_LOCATOR));
}
ipmi_sdr_generic_locator_t *
ipmi_sdr_lookup_generic(ipmi_handle_t *ihp, const char *idstr)
{
return (ipmi_sdr_lookup_common(ihp, idstr,
IPMI_SDR_TYPE_GENERIC_LOCATOR));
}
ipmi_sdr_compact_sensor_t *
ipmi_sdr_lookup_compact_sensor(ipmi_handle_t *ihp, const char *idstr)
{
return (ipmi_sdr_lookup_common(ihp, idstr,
IPMI_SDR_TYPE_COMPACT_SENSOR));
}
ipmi_sdr_full_sensor_t *
ipmi_sdr_lookup_full_sensor(ipmi_handle_t *ihp, const char *idstr)
{
return (ipmi_sdr_lookup_common(ihp, idstr,
IPMI_SDR_TYPE_FULL_SENSOR));
}
/*
* Mostly taken from ipmitool source v1.88
*
* This function converts the raw sensor reading returned by
* ipmi_get_sensor_reading to a unit-based value of type double.
*/
int
ipmi_sdr_conv_reading(ipmi_sdr_full_sensor_t *sensor, uint8_t val,
double *result)
{
int m, b, k1, k2;
m = __TO_M(sensor->is_fs_mtol);
b = __TO_B(sensor->is_fs_bacc);
k1 = __TO_B_EXP(sensor->is_fs_bacc);
k2 = __TO_R_EXP(sensor->is_fs_bacc);
switch (sensor->is_fs_analog_fmt) {
case IPMI_DATA_FMT_UNSIGNED:
*result = (double)(((m * val) +
(b * pow(10, k1))) * pow(10, k2));
break;
case IPMI_DATA_FMT_ONESCOMP:
if (val & 0x80)
val++;
/* FALLTHRU */
case IPMI_DATA_FMT_TWOSCOMP:
*result = (double)(((m * (int8_t)val) +
(b * pow(10, k1))) * pow(10, k2));
break;
default:
/* This sensor does not return a numeric reading */
return (-1);
}
switch (sensor->is_fs_sensor_linear_type) {
case SDR_SENSOR_L_LN:
*result = log(*result);
break;
case SDR_SENSOR_L_LOG10:
*result = log10(*result);
break;
case SDR_SENSOR_L_LOG2:
*result = (double)(log(*result) / log(2.0));
break;
case SDR_SENSOR_L_E:
*result = exp(*result);
break;
case SDR_SENSOR_L_EXP10:
*result = pow(10.0, *result);
break;
case SDR_SENSOR_L_EXP2:
*result = pow(2.0, *result);
break;
case SDR_SENSOR_L_1_X:
*result = pow(*result, -1.0); /* 1/x w/o exception */
break;
case SDR_SENSOR_L_SQR:
*result = pow(*result, 2.0);
break;
case SDR_SENSOR_L_CUBE:
*result = pow(*result, 3.0);
break;
case SDR_SENSOR_L_SQRT:
*result = sqrt(*result);
break;
case SDR_SENSOR_L_CUBERT:
*result = cbrt(*result);
break;
case SDR_SENSOR_L_LINEAR:
default:
break;
}
return (0);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <libipmi.h>
#include <stddef.h>
#include <string.h>
#include <strings.h>
#include "ipmi_impl.h"
/*
* 31.2 Get SEL Info Command.
*/
ipmi_sel_info_t *
ipmi_sel_get_info(ipmi_handle_t *ihp)
{
ipmi_cmd_t cmd, *rsp;
ipmi_sel_info_t *ip;
uint16_t tmp16;
uint32_t tmp32;
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_SEL_INFO;
cmd.ic_dlen = 0;
cmd.ic_data = NULL;
if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
return (NULL);
ip = (ipmi_sel_info_t *)rsp->ic_data;
tmp16 = LE_IN16(&ip->isel_entries);
(void) memcpy(&ip->isel_entries, &tmp16, sizeof (tmp16));
tmp16 = LE_IN16(&ip->isel_free);
(void) memcpy(&ip->isel_free, &tmp16, sizeof (tmp16));
tmp32 = LE_IN32(&ip->isel_add_ts);
(void) memcpy(&ip->isel_add_ts, &tmp32, sizeof (tmp32));
tmp32 = LE_IN32(&ip->isel_erase_ts);
(void) memcpy(&ip->isel_erase_ts, &tmp32, sizeof (tmp32));
return (ip);
}
typedef struct ipmi_cmd_get_sel_entry {
uint16_t ic_sel_ent_resid;
uint16_t ic_sel_ent_recid;
uint8_t ic_sel_ent_offset;
uint8_t ic_sel_ent_bytes;
} ipmi_cmd_get_sel_entry_t;
ipmi_sel_event_t *
ipmi_sel_get_entry(ipmi_handle_t *ihp, uint16_t id)
{
ipmi_cmd_t cmd, *rsp;
ipmi_sel_event_t *evp;
ipmi_cmd_get_sel_entry_t data;
uint32_t tmp;
data.ic_sel_ent_resid = 0;
data.ic_sel_ent_recid = LE_16(id);
data.ic_sel_ent_offset = 0;
data.ic_sel_ent_bytes = 0xFF;
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_SEL_ENTRY;
cmd.ic_dlen = sizeof (data);
cmd.ic_data = &data;
if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
return (NULL);
if (rsp->ic_dlen < sizeof (ipmi_sel_event_t)) {
(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
return (NULL);
}
evp = (ipmi_sel_event_t *)rsp->ic_data;
evp->isel_ev_next = LE_IN16(&evp->isel_ev_next);
evp->isel_ev_recid = LE_IN16(&evp->isel_ev_recid);
if (evp->isel_ev_rectype == IPMI_SEL_SYSTEM ||
evp->isel_ev_rectype >= IPMI_SEL_OEM_LO) {
tmp = LE_IN32(&evp->isel_ev_ts);
(void) memcpy(&evp->isel_ev_ts, &tmp, sizeof (tmp));
}
return (evp);
}
/*
* SEL time management. For the purposes of libipmi we assume that the SDR
* repository and SEL share the same timebase, even though the spec allows for
* separate time sources. Hence no function to set the SDR repository time.
*/
int
ipmi_sel_get_time(ipmi_handle_t *ihp, uint32_t *tp)
{
ipmi_cmd_t cmd, *rsp;
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_SEL_TIME;
cmd.ic_dlen = 0;
cmd.ic_data = NULL;
if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
return (-1);
if (rsp->ic_dlen < sizeof (uint32_t))
return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
*tp = LE_IN32(rsp->ic_data);
return (0);
}
int
ipmi_sel_set_time(ipmi_handle_t *ihp, uint32_t t)
{
ipmi_cmd_t cmd;
t = LE_32(t);
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_SET_SEL_TIME;
cmd.ic_dlen = sizeof (t);
cmd.ic_data = &t;
if (ipmi_send(ihp, &cmd) == NULL)
return (-1);
return (0);
}
int
ipmi_sel_get_utc_offset(ipmi_handle_t *ihp, int *offp)
{
ipmi_cmd_t cmd, *rsp;
int16_t off16;
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_GET_SEL_UTC_OFFSET;
cmd.ic_dlen = 0;
cmd.ic_data = NULL;
if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
return (-1);
if (rsp->ic_dlen < sizeof (uint16_t))
return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
off16 = LE_IN16(rsp->ic_data);
*offp = off16;
return (0);
}
int
ipmi_sel_set_utc_offset(ipmi_handle_t *ihp, int off)
{
ipmi_cmd_t cmd;
int16_t off16 = off;
off16 = LE_16(off16);
cmd.ic_netfn = IPMI_NETFN_STORAGE;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_SET_SEL_UTC_OFFSET;
cmd.ic_dlen = sizeof (off16);
cmd.ic_data = &off16;
if (ipmi_send(ihp, &cmd) == NULL)
return (-1);
return (0);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2018, Joyent, Inc.
*/
#include <libipmi.h>
#include <string.h>
#include "ipmi_impl.h"
ipmi_sensor_reading_t *
ipmi_get_sensor_reading(ipmi_handle_t *ihp, uint8_t id)
{
ipmi_cmd_t cmd, *resp;
ipmi_sensor_reading_t *srp;
cmd.ic_netfn = IPMI_NETFN_SE;
cmd.ic_cmd = IPMI_CMD_GET_SENSOR_READING;
cmd.ic_lun = 0;
cmd.ic_data = &id;
cmd.ic_dlen = sizeof (id);
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (NULL);
/*
* The upper half of the state field is optional, so if it's not
* present, then set it to zero. We also need to convert to the
* native endianness.
*/
if (resp->ic_dlen < sizeof (ipmi_sensor_reading_t) - sizeof (uint8_t)) {
(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
return (NULL);
}
srp = resp->ic_data;
if (resp->ic_dlen < sizeof (ipmi_sensor_reading_t))
(void) memset((char *)srp + resp->ic_dlen, '\0',
sizeof (ipmi_sensor_reading_t) - resp->ic_dlen);
srp->isr_state = LE_IN16(&srp->isr_state);
return (srp);
}
int
ipmi_set_sensor_reading(ipmi_handle_t *ihp, ipmi_set_sensor_reading_t *req)
{
ipmi_set_sensor_reading_t realreq;
ipmi_cmd_t cmd, *resp;
uint16_t tmp;
/*
* Convert states to little endian.
*/
(void) memcpy(&realreq, req, sizeof (realreq));
tmp = LE_IN16(&realreq.iss_assert_state);
(void) memcpy(&realreq.iss_assert_state, &tmp, sizeof (tmp));
tmp = LE_IN16(&realreq.iss_deassert_state);
(void) memcpy(&realreq.iss_deassert_state, &tmp, sizeof (tmp));
cmd.ic_netfn = IPMI_NETFN_SE;
cmd.ic_cmd = IPMI_CMD_SET_SENSOR_READING;
cmd.ic_lun = 0;
cmd.ic_data = &realreq;
cmd.ic_dlen = sizeof (realreq);
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (-1);
if (resp->ic_dlen != 0)
return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
return (0);
}
int
ipmi_get_sensor_thresholds(ipmi_handle_t *ihp, ipmi_sensor_thresholds_t *thresh,
uint8_t id)
{
ipmi_cmd_t cmd, *resp;
cmd.ic_netfn = IPMI_NETFN_SE;
cmd.ic_cmd = IPMI_CMD_GET_SENSOR_THRESHOLDS;
cmd.ic_lun = 0;
cmd.ic_data = &id;
cmd.ic_dlen = sizeof (id);
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (-1);
if (resp->ic_dlen < sizeof (ipmi_sensor_thresholds_t)) {
return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
}
(void) memcpy(thresh, resp->ic_data, sizeof (ipmi_sensor_thresholds_t));
return (0);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <libipmi.h>
#include <stddef.h>
#include "ipmi_impl.h"
#define IPMI_CMD_SUNOEM_LED_GET 0x21
#define IPMI_CMD_SUNOEM_LED_SET 0x22
typedef struct ipmi_cmd_sunoem_led_set {
DECL_BITFIELD2(
ic_sls_channel_msb :1, /* device slave address */
ic_sls_slaveaddr :7); /* (from SDR record) */
uint8_t ic_sls_type; /* led type */
DECL_BITFIELD2(
__reserved :1, /* device access address */
ic_sls_accessaddr :7); /* (from SDR record */
uint8_t ic_sls_hwinfo; /* OEM hardware info */
uint8_t ic_sls_mode; /* LED mode */
uint8_t ic_sls_eid; /* entity ID */
uint8_t ic_sls_einst; /* entity instance */
uint8_t ic_sls_force; /* force direct access */
uint8_t ic_sls_role; /* BMC authorization */
} ipmi_cmd_sunoem_led_set_t;
typedef struct ipmi_cmd_sunoem_led_get {
DECL_BITFIELD2(
ic_slg_channel_msb :1, /* device slave address */
ic_slg_slaveaddr :7); /* (from SDR record) */
uint8_t ic_slg_type; /* led type */
DECL_BITFIELD2(
__reserved :1, /* device access address */
ic_slg_accessaddr :7); /* (from SDR record */
uint8_t ic_slg_hwinfo; /* OEM hardware info */
uint8_t ic_slg_eid; /* entity ID */
uint8_t ic_slg_einst; /* entity instance */
uint8_t ic_slg_force; /* force direct access */
} ipmi_cmd_sunoem_led_get_t;
#define IPMI_SUNOEM_LED_TYPE_OK2RM 0
#define IPMI_SUNOEM_LED_TYPE_SERVICE 1
#define IPMI_SUNOEM_LED_TYPE_ACT 2
#define IPMI_SUNOEM_LED_TYPE_LOCATE 3
#define IPMI_SUNOEM_LED_TYPE_ANY 0xFF
boolean_t
ipmi_is_sun_ilom(ipmi_deviceid_t *dp)
{
return (ipmi_devid_manufacturer(dp) == IPMI_OEM_SUN &&
ipmi_devid_product(dp) == IPMI_PROD_SUN_ILOM);
}
static int
check_sunoem(ipmi_handle_t *ihp)
{
ipmi_deviceid_t *devid;
if ((devid = ipmi_get_deviceid(ihp)) == NULL)
return (-1);
if (!ipmi_is_sun_ilom(devid))
return (ipmi_set_error(ihp, EIPMI_INVALID_COMMAND, NULL));
return (0);
}
static int
ipmi_send_sunoem_led_set(ipmi_handle_t *ihp, ipmi_cmd_sunoem_led_set_t *req)
{
ipmi_cmd_t cmd, *resp;
cmd.ic_netfn = IPMI_NETFN_OEM;
cmd.ic_cmd = IPMI_CMD_SUNOEM_LED_SET;
cmd.ic_lun = 0;
cmd.ic_data = req;
cmd.ic_dlen = sizeof (*req);
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (-1);
if (resp->ic_dlen != 0)
return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
return (0);
}
static int
ipmi_send_sunoem_led_get(ipmi_handle_t *ihp, ipmi_cmd_sunoem_led_get_t *req,
uint8_t *result)
{
ipmi_cmd_t cmd, *resp;
cmd.ic_netfn = IPMI_NETFN_OEM;
cmd.ic_cmd = IPMI_CMD_SUNOEM_LED_GET;
cmd.ic_lun = 0;
cmd.ic_data = req;
cmd.ic_dlen = sizeof (*req);
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (-1);
if (resp->ic_dlen != 1)
return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
*result = *((uint8_t *)resp->ic_data);
return (0);
}
int
ipmi_sunoem_led_set(ipmi_handle_t *ihp, ipmi_sdr_generic_locator_t *dev,
uint8_t mode)
{
ipmi_cmd_sunoem_led_set_t cmd = { 0 };
if (check_sunoem(ihp) != 0)
return (-1);
cmd.ic_sls_slaveaddr = dev->is_gl_slaveaddr;
cmd.ic_sls_channel_msb = dev->is_gl_channel_msb;
cmd.ic_sls_type = dev->is_gl_oem;
cmd.ic_sls_accessaddr = dev->is_gl_accessaddr;
cmd.ic_sls_hwinfo = dev->is_gl_oem;
cmd.ic_sls_mode = mode;
cmd.ic_sls_eid = dev->is_gl_entity;
cmd.ic_sls_einst = dev->is_gl_instance;
return (ipmi_send_sunoem_led_set(ihp, &cmd));
}
int
ipmi_sunoem_led_get(ipmi_handle_t *ihp, ipmi_sdr_generic_locator_t *dev,
uint8_t *mode)
{
ipmi_cmd_sunoem_led_get_t cmd = { 0 };
if (check_sunoem(ihp) != 0)
return (-1);
cmd.ic_slg_slaveaddr = dev->is_gl_slaveaddr;
cmd.ic_slg_channel_msb = dev->is_gl_channel_msb;
cmd.ic_slg_type = dev->is_gl_oem;
cmd.ic_slg_accessaddr = dev->is_gl_accessaddr;
cmd.ic_slg_hwinfo = dev->is_gl_oem;
cmd.ic_slg_eid = dev->is_gl_entity;
cmd.ic_slg_einst = dev->is_gl_instance;
return (ipmi_send_sunoem_led_get(ihp, &cmd, mode));
}
int
ipmi_sunoem_uptime(ipmi_handle_t *ihp, uint32_t *uptime, uint32_t *gen)
{
ipmi_cmd_t cmd, *resp;
uint8_t unused;
if (check_sunoem(ihp) != 0)
return (-1);
cmd.ic_netfn = IPMI_NETFN_OEM;
cmd.ic_lun = 0;
cmd.ic_cmd = IPMI_CMD_SUNOEM_UPTIME;
cmd.ic_dlen = sizeof (unused);
cmd.ic_data = &unused;
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (-1);
if (resp->ic_dlen != 2 * sizeof (uint32_t))
return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
if (uptime)
*uptime = BE_IN32(&((uint32_t *)resp->ic_data)[0]);
if (gen)
*gen = BE_IN32(&((uint32_t *)resp->ic_data)[1]);
return (0);
}
int
ipmi_sunoem_update_fru(ipmi_handle_t *ihp, ipmi_sunoem_fru_t *req)
{
ipmi_cmd_t cmd, *resp;
if (check_sunoem(ihp) != 0)
return (-1);
switch (req->isf_type) {
case IPMI_SUNOEM_FRU_DIMM:
req->isf_datalen = sizeof (req->isf_data.dimm);
break;
case IPMI_SUNOEM_FRU_CPU:
req->isf_datalen = sizeof (req->isf_data.cpu);
break;
case IPMI_SUNOEM_FRU_BIOS:
req->isf_datalen = sizeof (req->isf_data.bios);
break;
case IPMI_SUNOEM_FRU_DISK:
req->isf_datalen = sizeof (req->isf_data.disk);
break;
}
cmd.ic_netfn = IPMI_NETFN_OEM;
cmd.ic_cmd = IPMI_CMD_SUNOEM_FRU_UPDATE;
cmd.ic_lun = 0;
cmd.ic_dlen = offsetof(ipmi_sunoem_fru_t, isf_data) +
req->isf_datalen;
cmd.ic_data = req;
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (-1);
if (resp->ic_dlen != 0)
return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
return (0);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <libipmi.h>
#include <string.h>
#include "ipmi_impl.h"
typedef struct ipmi_user_impl {
ipmi_list_t iu_list;
ipmi_user_t iu_user;
} ipmi_user_impl_t;
/*
* Get User Access. See section 22.27.
*
* See libipmi.h for a complete description of IPMI reference material.
*/
typedef struct ipmi_get_user_access_req {
DECL_BITFIELD2(
igua_channel :4,
__reserved1 :4);
DECL_BITFIELD2(
igua_uid :2,
__reserved2 :6);
} ipmi_get_user_access_req_t;
#define IPMI_CMD_GET_USER_ACCESS 0x44
typedef struct ipmi_get_user_access {
DECL_BITFIELD2(
igua_max_uid :4,
__reserved1 :4);
DECL_BITFIELD2(
igua_enable_status :4,
igua_enabled_uid :4);
DECL_BITFIELD2(
__reserved2 :4,
igua_fixed_uid :4);
DECL_BITFIELD5(
__reserved3 :1,
igua_only_callback :1,
igua_link_auth_enable :1,
igua_ipmi_msg_enable :1,
igua_privilege_level :4);
} ipmi_get_user_access_t;
#define IPMI_USER_ENABLE_UNSPECIFIED 0x00
#define IPMI_USER_ENABLE_SETPASSWD 0x01
#define IPMI_USER_DISABLE_SETPASSWD 0x02
#define IPMI_USER_CHANNEL_CURRENT 0xe
/*
* Get User Name. See section 22.29
*/
#define IPMI_CMD_GET_USER_NAME 0x46
/*
* Set User Password. See section 22.30
*/
#define IPMI_CMD_SET_USER_PASSWORD 0x47
typedef struct ipmi_set_user_password {
DECL_BITFIELD3(
isup_uid :6,
__reserved1 :1,
isup_len20 :1);
DECL_BITFIELD2(
isup_op :2,
__reserved2 :6);
char isup_passwd[20];
} ipmi_set_user_password_t;
#define IPMI_PASSWORD_OP_DISABLE 0x0
#define IPMI_PASSWORD_OP_ENABLE 0x1
#define IPMI_PASSWORD_OP_SET 0x2
#define IPMI_PASSWORD_OP_TEST 0x3
static ipmi_get_user_access_t *
ipmi_get_user_access(ipmi_handle_t *ihp, uint8_t channel, uint8_t uid)
{
ipmi_cmd_t cmd, *resp;
ipmi_get_user_access_req_t req = { 0 };
req.igua_channel = channel;
req.igua_uid = uid;
cmd.ic_netfn = IPMI_NETFN_APP;
cmd.ic_cmd = IPMI_CMD_GET_USER_ACCESS;
cmd.ic_lun = 0;
cmd.ic_data = &req;
cmd.ic_dlen = sizeof (req);
if ((resp = ipmi_send(ihp, &cmd)) == NULL) {
/*
* If sessions aren't supported on the current channel, some
* service processors (notably Sun's ILOM) will return an
* invalid request completion code (0xCC). For these SPs, we
* translate this to the more appropriate EIPMI_INVALID_COMMAND.
*/
if (ipmi_errno(ihp) == EIPMI_INVALID_REQUEST)
(void) ipmi_set_error(ihp, EIPMI_INVALID_COMMAND,
NULL);
return (NULL);
}
if (resp->ic_dlen < sizeof (ipmi_get_user_access_t)) {
(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
return (NULL);
}
return (resp->ic_data);
}
static const char *
ipmi_get_user_name(ipmi_handle_t *ihp, uint8_t uid)
{
ipmi_cmd_t cmd, *resp;
cmd.ic_netfn = IPMI_NETFN_APP;
cmd.ic_cmd = IPMI_CMD_GET_USER_NAME;
cmd.ic_lun = 0;
cmd.ic_data = &uid;
cmd.ic_dlen = sizeof (uid);
if ((resp = ipmi_send(ihp, &cmd)) == NULL)
return (NULL);
if (resp->ic_dlen < 16) {
(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
return (NULL);
}
return (resp->ic_data);
}
void
ipmi_user_clear(ipmi_handle_t *ihp)
{
ipmi_user_impl_t *uip;
while ((uip = ipmi_list_next(&ihp->ih_users)) != NULL) {
ipmi_list_delete(&ihp->ih_users, uip);
ipmi_free(ihp, uip->iu_user.iu_name);
ipmi_free(ihp, uip);
}
}
/*
* Returns user information in a well-defined structure.
*/
int
ipmi_user_iter(ipmi_handle_t *ihp, int (*func)(ipmi_user_t *, void *),
void *data)
{
ipmi_get_user_access_t *resp;
uint8_t i, uid_max;
ipmi_user_impl_t *uip;
ipmi_user_t *up;
const char *name;
uint8_t channel;
ipmi_deviceid_t *devid;
ipmi_user_clear(ihp);
channel = IPMI_USER_CHANNEL_CURRENT;
/*
* Get the number of active users on the system by requesting the first
* user ID (1).
*/
if ((resp = ipmi_get_user_access(ihp, channel, 1)) == NULL) {
/*
* Some versions of the Sun ILOM have a bug which prevent the
* GET USER ACCESS command from succeeding over the default
* channel. If this fails and we are on ILOM, then attempt to
* use the standard channel (1) instead.
*/
if ((devid = ipmi_get_deviceid(ihp)) == NULL)
return (-1);
if (!ipmi_is_sun_ilom(devid))
return (-1);
channel = 1;
if ((resp = ipmi_get_user_access(ihp, channel, 1)) == NULL)
return (-1);
}
uid_max = resp->igua_max_uid;
for (i = 1; i <= uid_max; i++) {
if (i != 1 && (resp = ipmi_get_user_access(ihp,
channel, i)) == NULL)
return (-1);
if ((uip = ipmi_zalloc(ihp, sizeof (ipmi_user_impl_t))) == NULL)
return (-1);
up = &uip->iu_user;
up->iu_enabled = resp->igua_enabled_uid;
up->iu_uid = i;
up->iu_ipmi_msg_enable = resp->igua_ipmi_msg_enable;
up->iu_link_auth_enable = resp->igua_link_auth_enable;
up->iu_priv = resp->igua_privilege_level;
ipmi_list_append(&ihp->ih_users, uip);
/*
* If we are requesting a username that doesn't have a
* supported username, we may get an INVALID REQUEST response.
* If this is the case, then continue as if there is no known
* username.
*/
if ((name = ipmi_get_user_name(ihp, i)) == NULL) {
if (ipmi_errno(ihp) == EIPMI_INVALID_REQUEST)
continue;
else
return (-1);
}
if (*name == '\0')
continue;
if ((up->iu_name = ipmi_strdup(ihp, name)) == NULL)
return (-1);
}
for (uip = ipmi_list_next(&ihp->ih_users); uip != NULL;
uip = ipmi_list_next(uip)) {
if (func(&uip->iu_user, data) != 0)
return (-1);
}
return (0);
}
typedef struct ipmi_user_cb {
const char *uic_name;
uint8_t uic_uid;
ipmi_user_t *uic_result;
} ipmi_user_cb_t;
static int
ipmi_user_callback(ipmi_user_t *up, void *data)
{
ipmi_user_cb_t *cbp = data;
if (cbp->uic_result != NULL)
return (0);
if (up->iu_name) {
if (strcmp(up->iu_name, cbp->uic_name) == 0)
cbp->uic_result = up;
} else if (up->iu_uid == cbp->uic_uid) {
cbp->uic_result = up;
}
return (0);
}
ipmi_user_t *
ipmi_user_lookup_name(ipmi_handle_t *ihp, const char *name)
{
ipmi_user_cb_t cb = { 0 };
cb.uic_name = name;
cb.uic_result = NULL;
if (ipmi_user_iter(ihp, ipmi_user_callback, &cb) != 0)
return (NULL);
if (cb.uic_result == NULL)
(void) ipmi_set_error(ihp, EIPMI_NOT_PRESENT,
"no such user");
return (cb.uic_result);
}
ipmi_user_t *
ipmi_user_lookup_id(ipmi_handle_t *ihp, uint8_t uid)
{
ipmi_user_cb_t cb = { 0 };
cb.uic_uid = uid;
cb.uic_result = NULL;
if (ipmi_user_iter(ihp, ipmi_user_callback, &cb) != 0)
return (NULL);
if (cb.uic_result == NULL)
(void) ipmi_set_error(ihp, EIPMI_NOT_PRESENT,
"no such user");
return (cb.uic_result);
}
int
ipmi_user_set_password(ipmi_handle_t *ihp, uint8_t uid, const char *passwd)
{
ipmi_set_user_password_t req = { 0 };
ipmi_cmd_t cmd;
req.isup_uid = uid;
req.isup_op = IPMI_PASSWORD_OP_SET;
if (strlen(passwd) > 19)
return (ipmi_set_error(ihp, EIPMI_INVALID_REQUEST,
"password length must be less than 20 characters"));
if (strlen(passwd) > 15)
req.isup_len20 = 1;
(void) strcpy(req.isup_passwd, passwd);
cmd.ic_netfn = IPMI_NETFN_APP;
cmd.ic_cmd = IPMI_CMD_SET_USER_PASSWORD;
cmd.ic_lun = 0;
cmd.ic_data = &req;
if (req.isup_len20)
cmd.ic_dlen = sizeof (req);
else
cmd.ic_dlen = sizeof (req) - 4;
if (ipmi_send(ihp, &cmd) == NULL)
return (-1);
return (0);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <libipmi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "ipmi_impl.h"
/*
* Extracts bits between index h (high, inclusive) and l (low, exclusive) from
* u, which must be an unsigned integer.
*/
#define BITX(u, h, l) (((u) >> (l)) & ((1LU << ((h) - (l) + 1LU)) - 1LU))
/*
* Error handling
*/
int
ipmi_set_error(ipmi_handle_t *ihp, int error, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
ihp->ih_errno = error;
if (fmt == NULL)
ihp->ih_errmsg[0] = '\0';
else
(void) vsnprintf(ihp->ih_errmsg, sizeof (ihp->ih_errmsg),
fmt, ap);
va_end(ap);
return (-1);
}
int
ipmi_errno(ipmi_handle_t *ihp)
{
return (ihp->ih_errno);
}
/* ARGSUSED */
const char *
ipmi_errmsg(ipmi_handle_t *ihp)
{
int i;
const char *str;
str = NULL;
for (i = 0; ipmi_errno_table[i].int_name != NULL; i++) {
if (ipmi_errno_table[i].int_value == ihp->ih_errno) {
str = ipmi_errno_table[i].int_name;
break;
}
}
if (str == NULL && (str = strerror(ihp->ih_errno)) == NULL)
str = "unknown failure";
if (ihp->ih_errmsg[0] == '\0')
return (str);
(void) snprintf(ihp->ih_errbuf, sizeof (ihp->ih_errbuf),
"%s: %s", str, ihp->ih_errmsg);
return (ihp->ih_errbuf);
}
/*
* Memory allocation
*/
void *
ipmi_alloc(ipmi_handle_t *ihp, size_t size)
{
void *ptr;
if ((ptr = malloc(size)) == NULL)
(void) ipmi_set_error(ihp, EIPMI_NOMEM, NULL);
return (ptr);
}
void *
ipmi_zalloc(ipmi_handle_t *ihp, size_t size)
{
void *ptr;
if ((ptr = calloc(size, 1)) == NULL)
(void) ipmi_set_error(ihp, EIPMI_NOMEM, NULL);
return (ptr);
}
char *
ipmi_strdup(ipmi_handle_t *ihp, const char *str)
{
char *ptr;
if ((ptr = strdup(str)) == NULL)
(void) ipmi_set_error(ihp, EIPMI_NOMEM, NULL);
return (ptr);
}
/* ARGSUSED */
void
ipmi_free(ipmi_handle_t *ihp, void *ptr)
{
free(ptr);
}
/*
* Translation between #defines and strings.
*/
void
ipmi_entity_name(uint8_t id, char *buf, size_t len)
{
ipmi_name_trans_t *ntp;
for (ntp = &ipmi_entity_table[0]; ntp->int_name != NULL; ntp++) {
if (ntp->int_value == id) {
(void) strlcpy(buf, ntp->int_name, len);
return;
}
}
(void) snprintf(buf, len, "0x%02x", id);
}
void
ipmi_sensor_type_name(uint8_t type, char *buf, size_t len)
{
ipmi_name_trans_t *ntp;
for (ntp = &ipmi_sensor_type_table[0]; ntp->int_name != NULL; ntp++) {
if (ntp->int_value == type) {
(void) strlcpy(buf, ntp->int_name, len);
return;
}
}
(void) snprintf(buf, len, "0x%02x", type);
}
void
ipmi_sensor_units_name(uint8_t type, char *buf, size_t len)
{
ipmi_name_trans_t *ntp;
for (ntp = &ipmi_units_type_table[0]; ntp->int_name != NULL; ntp++) {
if (ntp->int_value == type) {
(void) strlcpy(buf, ntp->int_name, len);
return;
}
}
(void) snprintf(buf, len, "0x%02x", type);
}
void
ipmi_sensor_reading_name(uint8_t sensor_type, uint8_t reading_type,
char *buf, size_t len)
{
uint8_t val;
ipmi_name_trans_t *ntp;
if (reading_type == IPMI_RT_SPECIFIC) {
val = sensor_type;
ntp = &ipmi_sensor_type_table[0];
} else {
val = reading_type;
ntp = &ipmi_reading_type_table[0];
}
for (; ntp->int_name != NULL; ntp++) {
if (ntp->int_value == val) {
(void) strlcpy(buf, ntp->int_name, len);
return;
}
}
if (reading_type == IPMI_RT_SPECIFIC)
(void) snprintf(buf, len, "%02x/%02x", reading_type,
sensor_type);
else
(void) snprintf(buf, len, "%02x", reading_type);
}
/*
* Converts a BCD decimal value to an integer.
*/
int
ipmi_convert_bcd(int value)
{
int ret = 0;
int digit;
int i;
for (i = 7; i >= 0; i--) {
digit = ((value & (0xf << (i * 4))) >> (i * 4));
ret += digit * 10 * i;
}
return (ret);
}
/*
* See sections 43.15 and 43.16
*
* This is a utility function for decoding the strings that are packed into
* sensor data records. If the type is 6-bit packed ASCII, then it converts
* the string to an 8-bit ASCII string and copies that into the suuplied buffer.
* If it is 8-bit ASCII, it copies the string into the supplied buffer as-is.
*/
void
ipmi_decode_string(uint8_t type, uint8_t len, char *data, char *buf)
{
int i, j = 0, chunks, leftovers;
uint8_t tmp, lo;
if (len == 0) {
*buf = '\0';
return;
}
/*
* If the type is 8-bit ASCII, we can simply copy the string and return
*/
if (type == 0x3) {
(void) strncpy(buf, data, len);
*(buf+len) = '\0';
return;
} else if (type == 0x1 || type == 0x0) {
/*
* Yuck - they either used BCD plus encoding, which we don't
* currently handle, or they used an unspecified encoding type.
* In these cases we'll set buf to an empty string. We still
* need to return the length so that we can get to the next
* record.
*/
*buf = '\0';
return;
}
/*
* Otherwise, it's 6-bit packed ASCII, so we have to convert the
* data first
*/
chunks = len / 3;
leftovers = len % 3;
/*
* First we decode the 6-bit string in chunks of 3 bytes as far as
* possible
*/
for (i = 0; i < chunks; i++) {
tmp = BITX(*(data+j), 5, 0);
*buf++ = (char)(tmp + 32);
lo = BITX(*(data+j++), 7, 6);
tmp = BITX(*(data+j), 3, 0);
tmp = (tmp << 2) | lo;
*buf++ = (char)(tmp + 32);
lo = BITX(*(data+j++), 7, 4);
tmp = BITX(*(data+j), 1, 0);
tmp = (tmp << 4) | lo;
*buf++ = (char)(tmp + 32);
tmp = BITX(*(data+j++), 7, 2);
*buf++ = (char)(tmp + 32);
}
switch (leftovers) {
case 1:
tmp = BITX(*(data+j), 5, 0);
*buf++ = (char)(tmp + 32);
break;
case 2:
tmp = BITX(*(data+j), 5, 0);
*buf++ = (char)(tmp + 32);
lo = BITX(*(data+j++), 7, 6);
tmp = BITX(*(data+j), 3, 0);
tmp = (tmp << 2) | lo;
*buf++ = (char)(tmp + 32);
break;
}
*buf = '\0';
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 2018, Joyent, Inc.
*/
#include <libipmi.h>
#include <string.h>
#include "ipmi_impl.h"
ipmi_handle_t *
ipmi_open(int *errp, char **msg, uint_t xport_type, nvlist_t *params)
{
ipmi_handle_t *ihp;
static char errmsg[48];
if (msg)
*msg = NULL;
if ((ihp = calloc(1, sizeof (ipmi_handle_t))) == NULL) {
*errp = EIPMI_NOMEM;
if (msg)
*msg = "memory allocation failure";
return (NULL);
}
switch (xport_type) {
case IPMI_TRANSPORT_BMC:
ihp->ih_transport = &ipmi_transport_bmc;
break;
case IPMI_TRANSPORT_LAN:
ihp->ih_transport = &ipmi_transport_lan;
break;
default:
*msg = "invalid transport type specified";
return (NULL);
}
ihp->ih_retries = 3;
if ((ihp->ih_tdata = ihp->ih_transport->it_open(ihp, params)) == NULL ||
ipmi_sdr_init(ihp) != 0 || ipmi_entity_init(ihp) != 0) {
*errp = ihp->ih_errno;
if (msg) {
(void) strncpy(errmsg, ipmi_errmsg(ihp), 47);
errmsg[47] = '\0';
*msg = errmsg;
}
ipmi_close(ihp);
return (NULL);
}
return (ihp);
}
void
ipmi_close(ipmi_handle_t *ihp)
{
if (ihp->ih_transport && ihp->ih_tdata)
ihp->ih_transport->it_close(ihp->ih_tdata);
ipmi_free(ihp, ihp->ih_deviceid);
ipmi_free(ihp, ihp->ih_firmware_rev);
ipmi_user_clear(ihp);
ipmi_sdr_fini(ihp);
ipmi_entity_fini(ihp);
free(ihp);
}
/*
* See section 5.2 for a description of the completion codes.
*/
static struct ipmi_err_conv {
int bmc_err;
int ipmi_err;
} ipmi_errtable[] = {
{ 0xC0, EIPMI_BUSY },
{ 0xC1, EIPMI_INVALID_COMMAND },
{ 0xC2, EIPMI_INVALID_COMMAND },
{ 0xC3, EIPMI_COMMAND_TIMEOUT },
{ 0xC4, EIPMI_NOSPACE },
{ 0xC5, EIPMI_INVALID_RESERVATION },
{ 0xC6, EIPMI_INVALID_REQUEST },
{ 0xC7, EIPMI_INVALID_REQUEST },
{ 0xC8, EIPMI_INVALID_REQUEST },
{ 0xC9, EIPMI_INVALID_REQUEST },
{ 0xCA, EIPMI_DATA_LENGTH_EXCEEDED },
{ 0xCB, EIPMI_NOT_PRESENT },
{ 0xCC, EIPMI_INVALID_REQUEST },
{ 0xCD, EIPMI_INVALID_COMMAND },
{ 0xCE, EIPMI_UNAVAILABLE },
{ 0xCF, EIPMI_UNAVAILABLE },
{ 0xD0, EIPMI_BUSY },
{ 0xD1, EIPMI_BUSY },
{ 0xD2, EIPMI_BUSY },
{ 0xD3, EIPMI_NOT_PRESENT },
{ 0xD4, EIPMI_ACCESS },
{ 0xD5, EIPMI_UNAVAILABLE },
{ 0xD6, EIPMI_UNAVAILABLE },
{ 0xFF, EIPMI_UNSPECIFIED },
};
#define IPMI_ERROR_COUNT \
(sizeof (ipmi_errtable) / sizeof (ipmi_errtable[0]))
ipmi_cmd_t *
ipmi_send(ipmi_handle_t *ihp, ipmi_cmd_t *cmd)
{
int i;
if (ihp->ih_transport->it_send(ihp->ih_tdata, cmd, &ihp->ih_response,
&ihp->ih_completion) != 0)
return (NULL);
if (ihp->ih_completion != 0) {
for (i = 0; i < IPMI_ERROR_COUNT; i++) {
if (ihp->ih_completion == ipmi_errtable[i].bmc_err) {
(void) ipmi_set_error(ihp,
ipmi_errtable[i].ipmi_err,
"IPMI completion code 0x%x",
ihp->ih_completion);
return (NULL);
}
}
(void) ipmi_set_error(ihp, EIPMI_UNKNOWN,
"IPMI completion code 0x%x", ihp->ih_completion);
return (NULL);
}
return (&ihp->ih_response);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, Joyent, Inc. All rights reserved.
*/
#ifndef _LIBIPMI_H
#define _LIBIPMI_H
#include <sys/byteorder.h>
#include <sys/nvpair.h>
#include <sys/sysmacros.h>
/*
* Private interfaces for communicating with attached services over IPMI. This
* library is designed for system software communicating with Illumos-supported
* service processors over /dev/ipmi0. It is not a generic IPMI library.
*
* Documentation references refer to "Intelligent Platform Management Interface
* Specification Second Generation v2.0", document revision 1.0 with Februrary
* 15, 2006 Markup from "IPMI v2.0 Addenda, Errata, and Clarifications Revision
* 3".
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ipmi_handle ipmi_handle_t;
#pragma pack(1)
/*
* Basic netfn definitions. See section 5.1.
*/
#define IPMI_NETFN_CHASSIS 0x0
#define IPMI_NETFN_BRIDGE 0x2
#define IPMI_NETFN_SE 0x4
#define IPMI_NETFN_APP 0x6
#define IPMI_NETFN_FIRMWARE 0x8
#define IPMI_NETFN_STORAGE 0xa
#define IPMI_NETFN_TRANSPORT 0x0C
#define IPMI_NETFN_OEM 0x2e
/*
* Error definitions
*/
#define EIPMI_BASE 2000
typedef enum {
EIPMI_NOMEM = EIPMI_BASE, /* memory allocation failure */
EIPMI_BMC_OPEN_FAILED, /* failed to open /dev/ipmi0 */
EIPMI_BMC_PUTMSG, /* failed to send message to /dev/ipmi0 */
EIPMI_BMC_GETMSG, /* failed to read response from /dev/ipmi0 */
EIPMI_BMC_RESPONSE, /* response from /dev/ipmi0 failed */
EIPMI_INVALID_COMMAND, /* invalid command */
EIPMI_COMMAND_TIMEOUT, /* command timeout */
EIPMI_DATA_LENGTH_EXCEEDED, /* maximum data length exceeded */
EIPMI_SEND_FAILED, /* failed to send BMC request */
EIPMI_UNSPECIFIED, /* unspecified BMC error */
EIPMI_UNKNOWN, /* unknown error */
EIPMI_BAD_RESPONSE, /* received unexpected response */
EIPMI_BAD_RESPONSE_LENGTH, /* unexpected response length */
EIPMI_INVALID_RESERVATION, /* invalid or cancelled reservation */
EIPMI_NOT_PRESENT, /* requested entity not present */
EIPMI_INVALID_REQUEST, /* malformed request data */
EIPMI_BUSY, /* service processor is busy */
EIPMI_NOSPACE, /* service processor is out of space */
EIPMI_UNAVAILABLE, /* service processor is unavailable */
EIPMI_ACCESS, /* insufficient privileges */
EIPMI_BADPARAM, /* parameter is not supported */
EIPMI_READONLY, /* attempt to write read-only param */
EIPMI_WRITEONLY, /* attempt to read write-only param */
EIPMI_LAN_OPEN_FAILED, /* failed to open socket */
EIPMI_LAN_PING_FAILED, /* RMCP Ping message failed */
EIPMI_LAN_PASSWD_NOTSUP, /* password authentication not supported */
EIPMI_LAN_CHALLENGE, /* failure getting challenge */
EIPMI_LAN_SESSION, /* failure activating session */
EIPMI_LAN_SETPRIV /* failure setting session privs */
} ipmi_errno_t;
/*
* Basic library functions.
*
* The ipmi_handle is the primary interface to the library. The library itself
* is not MT-safe, but it is safe within a single handle. Multithreaded clients
* should either open multiple handles, or otherwise synchronize access to the
* same handle.
*
* There is a single command response buffer that is stored with the handle, to
* simplify memory management in the caller. The memory referenced by a command
* response is only valid until the next command is issued. The caller is
* responsible for making a copy of the response if it is needed.
*/
extern ipmi_handle_t *ipmi_open(int *, char **, uint_t xport_type, nvlist_t *);
/*
* Constants for nvpair names for the params nvlist that is passed to
* ipmi_open(). If the IPMI_TRANSPORT_BMC is desired, then it is sufficient
* to just specify NULL for the params nvlist.
*
* For IPMI_TRANSPORT_LAN, the params nvlist must contain the following
* nvpairs:
*
* IPMI_LAN_HOST, IPMI_LAN_USER, IPMI_LAN_PASSWD
*
* IPMI_LAN_PORT is optional and will default to 623
* IPMI_LAN_PRIVLVL is optional and will default to admin
* IPMI_LAN_TIMEOUT is optional and will default to 3 seconds
* IPMI_LAN_NUM_RETIES is optional and will default to 5
*/
#define IPMI_TRANSPORT_TYPE "transport-type"
#define IPMI_TRANSPORT_BMC 0x01
#define IPMI_TRANSPORT_LAN 0x02
#define IPMI_LAN_HOST "lan-host"
#define IPMI_LAN_PORT "lan-port"
#define IPMI_LAN_USER "lan-user"
#define IPMI_LAN_PASSWD "lan-passwd"
#define IPMI_LAN_PRIVLVL "lan-privlvl"
#define IPMI_LAN_TIMEOUT "lan-timeout"
#define IPMI_LAN_NUM_RETRIES "lan-num-retries"
extern void ipmi_close(ipmi_handle_t *);
extern int ipmi_errno(ipmi_handle_t *);
extern const char *ipmi_errmsg(ipmi_handle_t *);
/*
* Raw requests. See section 5.
*/
typedef struct ipmi_cmd {
uint8_t ic_netfn:6;
uint8_t ic_lun:2;
uint8_t ic_cmd;
uint16_t ic_dlen;
void *ic_data;
} ipmi_cmd_t;
extern ipmi_cmd_t *ipmi_send(ipmi_handle_t *, ipmi_cmd_t *);
/*
* Retrieve basic information about the IPMI device. See section 20.1 "Get
* Device ID Command".
*/
#define IPMI_CMD_GET_DEVICEID 0x01
typedef struct ipmi_deviceid {
uint8_t id_devid;
DECL_BITFIELD3(
id_dev_rev :4,
__reserved :3,
id_dev_sdrs :1);
DECL_BITFIELD2(
id_firm_major :7,
id_dev_available :1);
uint8_t id_firm_minor;
uint8_t id_ipmi_rev;
uint8_t id_dev_support;
uint8_t id_manufacturer[3];
uint8_t id_product[2];
} ipmi_deviceid_t;
#define IPMI_OEM_SUN 0x2a
#define IPMI_PROD_SUN_ILOM 0x4701
ipmi_deviceid_t *ipmi_get_deviceid(ipmi_handle_t *);
#define ipmi_devid_manufacturer(dp) \
((dp)->id_manufacturer[0] | \
((dp)->id_manufacturer[1] << 8) | \
((dp)->id_manufacturer[2] << 16))
#define ipmi_devid_product(dp) \
((dp)->id_product[0] | \
((dp)->id_product[1] << 8))
const char *ipmi_firmware_version(ipmi_handle_t *);
/*
* Get Channel Auth Caps. See section 22.13.
*/
typedef struct ipmi_channel_auth_caps {
uint8_t cap_channel;
DECL_BITFIELD3(
cap_authtype :6,
__reserved1 :1,
cap_ipmirev2 :1);
DECL_BITFIELD5(
cap_anon :3,
cap_peruser :1,
cap_permesg :1,
cap_kgstatus :1,
__reserved2 :2);
uint8_t cap_ext;
uint8_t cap_oemid[3];
uint8_t cap_oemaux;
} ipmi_channel_auth_caps_t;
#define IPMI_CMD_GET_CHANNEL_AUTH_CAPS 0x38
extern ipmi_channel_auth_caps_t *ipmi_get_channel_auth_caps(ipmi_handle_t *,
uint8_t, uint8_t);
/*
* Get Channel Info. See section 22.24.
*/
typedef struct ipmi_channel_info {
DECL_BITFIELD2(
ici_number :4,
__reserved1 :4);
DECL_BITFIELD2(
ici_medium :7,
__reserved2 :1);
DECL_BITFIELD2(
ici_protocol :5,
__reserved3 :3);
DECL_BITFIELD3(
ici_session_count :6,
ici_single_session :1,
ici_multi_Session :1);
uint8_t ici_vendor[3];
uint8_t ici_auxinfo[2];
} ipmi_channel_info_t;
#define IPMI_CMD_GET_CHANNEL_INFO 0x42
/*
* Channel Numbers. See section 6.3.
*/
#define IPMI_CHANNEL_PRIMARY 0x0
#define IPMI_CHANNEL_MIN 0x1
#define IPMI_CHANNEL_MAX 0xB
#define IPMI_CHANNEL_CURRENT 0xE
#define IPMI_CHANNEL_SYSTEM 0xF
extern ipmi_channel_info_t *ipmi_get_channel_info(ipmi_handle_t *, int);
/*
* Channel Protocol Types. See section 6.4.
*/
#define IPMI_PROTOCOL_IPMB 0x1
#define IPMI_PROTOCOL_ICMB 0x2
#define IPMI_PROTOCOL_SMBUS 0x4
#define IPMI_PROTOCOL_KCS 0x5
#define IPMI_PROTOCOL_SMIC 0x6
#define IPMI_PROTOCOL_BT10 0x7
#define IPMI_PROTOCOL_BT15 0x8
#define IPMI_PROTOCOL_TMODE 0x9
#define IPMI_PROTOCOL_OEM1 0xC
#define IPMI_PROTOCOL_OEM2 0xD
#define IPMI_PROTOCOL_OEM3 0xE
#define IPMI_PROTOCOL_OEM4 0xF
/*
* Channel Medium Types. See section 6.5.
*/
#define IPMI_MEDIUM_IPMB 0x1
#define IPMI_MEDIUM_ICMB10 0x2
#define IPMI_MEDIUM_ICMB09 0x3
#define IPMI_MEDIUM_8023LAN 0x4
#define IPMI_MEDIUM_RS232 0x5
#define IPMI_MEDIUM_OTHERLAN 0x6
#define IPMI_MEDIUM_PCISMBUS 0x7
#define IPMI_MEDIUM_SMBUS10 0x8
#define IPMI_MEDIUM_SMBUS20 0x9
#define IPMI_MEDIUM_USB1 0xA
#define IPMI_MEDIUM_USB2 0xB
#define IPMI_MEDIUM_SYSTEM 0xC
/*
* LAN Configuration. See section 23. While the underlying mechanism is
* implemented via a sequence of get/set parameter commands, we assume that
* consumers prefer to get and set information in chunks, and therefore expose
* the configuration as a structure, with some of the less useful fields
* removed. When making changes, the consumer specifies which fields to apply
* along with the structure the library takes care of the rest of the work.
*
* This can be expanded in the future as needed.
*/
typedef struct ipmi_lan_config {
boolean_t ilc_set_in_progress;
uint32_t ilc_ipaddr;
uint8_t ilc_ipaddr_source;
uint8_t ilc_macaddr[6];
uint32_t ilc_subnet;
uint32_t ilc_gateway_addr;
} ipmi_lan_config_t;
#define IPMI_LAN_SRC_UNSPECIFIED 0x0
#define IPMI_LAN_SRC_STATIC 0x1
#define IPMI_LAN_SRC_DHCP 0x2
#define IPMI_LAN_SRC_BIOS 0x3
#define IPMI_LAN_SRC_OTHER 0x4
#define IPMI_LAN_SET_IPADDR 0x01
#define IPMI_LAN_SET_IPADDR_SOURCE 0x02
#define IPMI_LAN_SET_MACADDR 0x04
#define IPMI_LAN_SET_SUBNET 0x08
#define IPMI_LAN_SET_GATEWAY_ADDR 0x10
#define IPMI_CMD_SET_LAN_CONFIG 0x01
#define IPMI_CMD_GET_LAN_CONFIG 0x02
extern int ipmi_lan_get_config(ipmi_handle_t *, int,
ipmi_lan_config_t *);
extern int ipmi_lan_set_config(ipmi_handle_t *, int, ipmi_lan_config_t *, int);
/*
* SEL (System Event Log) commands. Currently the library only provides
* commands for reading the SEL.
*/
/*
* 31.2 Get SEL Info Command
*/
#define IPMI_CMD_GET_SEL_INFO 0x40
typedef struct ipmi_sel_info {
uint8_t isel_version;
uint16_t isel_entries;
uint16_t isel_free;
uint32_t isel_add_ts;
uint32_t isel_erase_ts;
DECL_BITFIELD6(
isel_supp_allocation :1,
isel_supp_reserve :1,
isel_supp_partial :1,
isel_supp_delete :1,
__reserved :3,
isel_overflow :1);
} ipmi_sel_info_t;
extern ipmi_sel_info_t *ipmi_sel_get_info(ipmi_handle_t *);
extern boolean_t ipmi_sdr_changed(ipmi_handle_t *);
extern int ipmi_sdr_refresh(ipmi_handle_t *);
/*
* 32.1 SEL Event Records
*/
typedef struct ipmi_sel_event {
uint16_t isel_ev_next;
uint16_t isel_ev_recid;
uint8_t isel_ev_rectype;
uint32_t isel_ev_ts;
DECL_BITFIELD2(
isel_ev_software :1,
isel_ev_addr_or_id :7);
DECL_BITFIELD3(
isel_ev_lun :2,
__reserved :2,
isel_ev_channel :4);
uint8_t isel_ev_rev;
uint8_t isel_ev_sensor_type;
uint8_t isel_ev_sensor_number;
DECL_BITFIELD2(
isel_ev_type :7,
isel_ev_dir :1);
uint8_t isel_ev_data[3];
} ipmi_sel_event_t;
#define IPMI_EV_REV15 0x04
#define IPMI_EV_REV1 0x03
#define IPMI_SEL_SYSTEM 0x02
#define IPMI_SEL_OEMTS_LO 0xC0
#define IPMI_SEL_OEMTS_HI 0xDF
#define IPMI_SEL_OEM_LO 0xE0
#define IPMI_SEL_OEM_HI 0xFF
#define IPMI_EV_ASSERT 0x0
#define IPMI_EV_DEASSERT 0x1
/*
* 32.2 OEM SEL Record (with timestamp)
*/
typedef struct ipmi_sel_oem_ts {
uint16_t isel_oem_next;
uint16_t isel_oem_id;
uint8_t isel_oem_type;
uint32_t isel_oem_ts;
uint8_t isel_oem_devid[3];
uint8_t isel_oem_data[6];
} ipmi_sel_oem_ts_t;
/*
* 32.3 OEM SEL Record (no timestamp)
*/
typedef struct ipmi_sel_oem {
uint16_t isel_oem_next;
uint16_t isel_oem_id;
uint8_t isel_oem_type;
uint8_t isel_oem_data[13];
} ipmi_sel_oem_t;
/*
* 29.3 Platform Event Message Command.
*/
typedef struct ipmi_platform_event_message {
uint8_t ipem_generator;
uint8_t ipem_rev;
uint8_t ipem_sensor_type;
uint8_t ipem_sensor_num;
DECL_BITFIELD2(
ipem_event_type :7,
ipem_event_dir :1);
uint8_t ipem_event_data[3];
} ipmi_platform_event_message_t;
#define IPMI_CMD_PLATFORM_EVENT_MESSAGE 0x02
extern int ipmi_event_platform_message(ipmi_handle_t *,
ipmi_platform_event_message_t *);
/*
* 29.7 Event Data Field Formats. Consumers can cast the data field of the
* event record to the appropriate type depending on the sensor class.
*/
typedef struct ipmi_event_threshold {
DECL_BITFIELD3(
iev_offset :4,
iev_desc_byte3 :2,
iev_desc_byte2 :2);
uint8_t iev_reading;
uint8_t iev_threshold;
} ipmi_event_threshold_t;
#define IPMI_EV_DESC_UNSPECIFIED 0x00
#define IPMI_EV_DESC_TRIGGER 0x01
#define IPMI_EV_DESC_OEM 0x02
#define IPMI_EV_DESC_SPECIFIC 0x03
typedef struct ipmi_event_discrete {
DECL_BITFIELD3(
iev_offset :4,
iev_desc_byte3 :2,
iev_desc_byte2 :2);
DECL_BITFIELD2(
iev_offset_type :4,
iev_offset_severity :4);
uint8_t iev_oem_code;
} ipmi_event_discrete_t;
#define IPMI_EV_DESC_PREVSTATE 0x01
#define IPMI_EV_DESC_SPECIFIC 0x03
typedef struct ipmi_event_oem {
DECL_BITFIELD3(
iev_offset :4,
iev_desc_byte3 :2,
iev_desc_byte2 :2);
DECL_BITFIELD2(
iev_offset_type :4,
iev_offset_severity :4);
uint8_t iev_oem_code;
} ipmi_event_oem_t;
/*
* Get SEL Entry Command. See section 31.5. We don't support partial reads, so
* this interface is quite a bit simpler than in the spec. We default to
* returning event records, though the consumer should check the type field and
* cast it to the appropriate type if it is no IPMI_SEL_SYSTEM.
*/
#define IPMI_CMD_GET_SEL_ENTRY 0x43
extern ipmi_sel_event_t *ipmi_sel_get_entry(ipmi_handle_t *, uint16_t);
#define IPMI_SEL_FIRST_ENTRY 0x0000
#define IPMI_SEL_LAST_ENTRY 0xFFFF
/*
* SEL time management. See sections 31.10 and 31.11.
*/
#define IPMI_CMD_GET_SEL_TIME 0x48
#define IPMI_CMD_SET_SEL_TIME 0x49
#define IPMI_CMD_GET_SEL_UTC_OFFSET 0x5C
#define IPMI_CMD_SET_SEL_UTC_OFFSET 0x5D
extern int ipmi_sel_get_time(ipmi_handle_t *, uint32_t *);
extern int ipmi_sel_set_time(ipmi_handle_t *, uint32_t);
extern int ipmi_sel_get_utc_offset(ipmi_handle_t *, int *);
extern int ipmi_sel_set_utc_offset(ipmi_handle_t *, int);
/*
* SDR (Sensor Device Record) requests. A cache of the current SDR repository
* is kept as part of the IPMI handle and updated when necessary. This does the
* work of processing the SDR names and providing an easy way to lookup
* individual records and iterate over all records.
*/
/*
* Get SDR Repository Info Command. See section 33.9.
*/
#define IPMI_CMD_GET_SDR_INFO 0x20
typedef struct ipmi_sdr_info {
uint8_t isi_version;
uint16_t isi_record_count;
uint16_t isi_free_space;
uint32_t isi_add_ts;
uint32_t isi_erase_ts;
DECL_BITFIELD7(
isi_supp_allocation :1,
isi_supp_reserve :1,
isi_supp_partial :1,
isi_supp_delete :1,
__reserved :1,
isi_modal :2,
isi_overflow :1);
} ipmi_sdr_info_t;
extern ipmi_sdr_info_t *ipmi_sdr_get_info(ipmi_handle_t *);
/*
* Reserve repository command. See section 33.11.
*/
#define IPMI_CMD_RESERVE_SDR_REPOSITORY 0x22
/*
* Get SDR command. See section 33.12. This command accesses the raw SDR
* repository. Clients can also use the lookup functions to retrieve a
* particular SDR record by name.
*
* The list of possible types is indicated in the sub-chapters of section 43.
*/
typedef struct ipmi_sdr {
uint16_t is_id;
uint8_t is_version;
uint8_t is_type;
uint8_t is_length;
uint8_t is_record[1];
} ipmi_sdr_t;
#define IPMI_CMD_GET_SDR 0x23
#define IPMI_SDR_FIRST 0x0000
#define IPMI_SDR_LAST 0xFFFF
extern ipmi_sdr_t *ipmi_sdr_get(ipmi_handle_t *, uint16_t, uint16_t *);
/*
* Full Sensor Record. See 43.1
*/
#define IPMI_SDR_TYPE_FULL_SENSOR 0x01
typedef struct ipmi_sdr_full_sensor {
/* RECORD KEY BYTES */
uint8_t is_fs_owner;
DECL_BITFIELD3(
is_fs_sensor_lun :2,
__reserved1 :2,
is_fs_channel :4);
uint8_t is_fs_number;
/* RECORD BODY BYTES */
uint8_t is_fs_entity_id;
DECL_BITFIELD2(
is_fs_entity_instance :7,
is_fs_entity_logical :1);
DECL_BITFIELD8(
is_fs_sensor_scanning_enabled :1,
is_fs_event_generation_enabled :1,
is_fs_init_sensor_type :1,
is_fs_init_hysteresis :1,
is_fs_init_thresholds :1,
is_fs_init_events :1,
is_fs_init_scanning :1,
is_fs_settable :1);
DECL_BITFIELD5(
is_fs_event_support :2,
is_fs_threshold_support :2,
is_fs_hysteresis_support :2,
is_fs_rearm_support :1,
is_fs_ignore :1);
uint8_t is_fs_type;
uint8_t is_fs_reading_type;
uint16_t is_fs_assert_mask;
uint16_t is_fs_deassert_mask;
uint16_t is_fs_reading_mask;
DECL_BITFIELD4(
is_fs_units_isprcnt :1,
is_fs_mod_unit :2,
is_fs_rate_unit :3,
is_fs_analog_fmt :2);
uint8_t is_fs_unit2;
uint8_t is_fs_unit3;
/* Linearization */
DECL_BITFIELD2(
is_fs_sensor_linear_type :7,
__reserved2 :1);
/* M, Tolerance */
uint16_t is_fs_mtol;
/* B, Accuracy, R exp, B exp */
uint32_t is_fs_bacc;
DECL_BITFIELD4(
is_fs_nominal_reading_spec :1,
is_fs_normal_max_spec :1,
is_fs_normal_min_spec :1,
__reserved3 :5);
uint8_t is_fs_nominal_reading;
uint8_t is_fs_normal_maximum;
uint8_t is_fs_normal_minimum;
uint8_t is_fs_max;
uint8_t is_fs_min;
uint8_t is_fs_upper_nonrecov;
uint8_t is_fs_upper_critical;
uint8_t is_fs_upper_noncrit;
uint8_t is_fs_lower_nonrecov;
uint8_t is_fs_lower_critical;
uint8_t is_fs_lower_noncrit;
uint8_t is_fs_hysteresis_positive;
uint8_t is_fs_hysteresis_negative;
uint16_t __reserved4;
uint8_t is_fs_oem;
DECL_BITFIELD3(
is_fs_idlen :5,
__reserved5 :1,
is_fs_idtype :2);
char is_fs_idstring[1];
} ipmi_sdr_full_sensor_t;
#define IPMI_SDR_TYPE_COMPACT_SENSOR 0x02
/*
* Compact Sensor Record. See section 43.2
*/
typedef struct ipmi_sdr_compact_sensor {
/* RECORD KEY BYTES */
uint8_t is_cs_owner;
DECL_BITFIELD3(
is_cs_sensor_lun :2,
is_cs_fru_lun :2,
is_cs_channel :4);
uint8_t is_cs_number;
/* RECORD BODY BYTES */
uint8_t is_cs_entity_id;
DECL_BITFIELD2(
is_cs_entity_instance :7,
is_cs_entity_logical :1);
DECL_BITFIELD8(
is_cs_sensor_scanning_enabled :1,
is_cs_event_generation_enabled :1,
is_cs_init_sensor_type :1,
is_cs_init_hysteresis :1,
__reserved1 :1,
is_cs_init_events :1,
is_cs_init_scanning :1,
is_cs_settable :1);
DECL_BITFIELD5(
is_cs_event_support :2,
is_cs_threshold_support :2,
is_cs_hysteresis_support :2,
is_cs_rearm_support :1,
is_cs_ignore :1);
uint8_t is_cs_type;
uint8_t is_cs_reading_type;
uint16_t is_cs_assert_mask;
uint16_t is_cs_deassert_mask;
uint16_t is_cs_reading_mask;
DECL_BITFIELD4(
is_cs_units_isprcnt :1,
is_cs_mod_unit :2,
is_cs_rate_unit :3,
__reserved2 :2);
uint8_t is_cs_unit2;
uint8_t is_cs_unit3;
DECL_BITFIELD3(
is_cs_share_count :4,
is_cs_modifier_type :2,
is_cs_direction :2);
DECL_BITFIELD2(
is_cs_modifier_offset :7,
is_cs_sharing :1);
uint8_t is_cs_hysteresis_positive;
uint8_t is_cs_hysteresis_negative;
uint16_t __reserved3;
uint8_t __reserved4;
uint8_t is_cs_oem;
DECL_BITFIELD3(
is_cs_idlen :5,
__reserved5 :1,
is_cs_idtype :2);
char is_cs_idstring[1];
} ipmi_sdr_compact_sensor_t;
/*
* Threshold sensor masks for is_cs_assert_mask and is_cs_deassert_mask.
*/
#define IPMI_SENSOR_RETURN_NONRECOV 0x4000
#define IPMI_SENSOR_RETURN_CRIT 0x2000
#define IPMI_SENSOR_RETURN_NONCRIT 0x1000
#define IPMI_SENSOR_MASK_UPPER_NONRECOV_HI 0x0800
#define IPMI_SENSOR_MASK_UPPER_NONRECOV_LO 0x0400
#define IPMI_SENSOR_MASK_UPPER_CRIT_HI 0x0200
#define IPMI_SENSOR_MASK_UPPER_CRIT_LO 0x0100
#define IPMI_SENSOR_MASK_UPPER_NONCRIT_HI 0x0080
#define IPMI_SENSOR_MASK_UPPER_NONCRIT_LO 0x0040
#define IPMI_SENSOR_MASK_LOWER_NONRECOV_HI 0x0020
#define IPMI_SENSOR_MASK_LOWER_NONRECOV_LO 0x0010
#define IPMI_SENSOR_MASK_LOWER_CRIT_HI 0x0008
#define IPMI_SENSOR_MASK_LOWER_CRIT_LO 0x0004
#define IPMI_SENSOR_MASK_LOWER_NONCRIT_HI 0x0002
#define IPMI_SENSOR_MASK_LOWER_NONCRIT_LO 0x0001
/*
* Threshold sensor masks for is_cs_reading_mask.
*/
#define IPMI_SENSOR_SETTABLE_UPPER_NONRECOV 0x2000
#define IPMI_SENSOR_SETTABLE_UPPER_CRIT 0x1000
#define IPMI_SENSOR_SETTABLE_UPPER_NONCRIT 0x0800
#define IPMI_SENSOR_SETTABLE_LOWER_NONRECOV 0x0400
#define IPMI_SENSOR_SETTABLE_LOWER_CRIT 0x0200
#define IPMI_SENSOR_SETTABLE_LOWER_NONCRIT 0x0100
#define IPMI_SENSOR_READABLE_UPPER_NONRECOV 0x0020
#define IPMI_SENSOR_READABLE_UPPER_CRIT 0x0010
#define IPMI_SENSOR_READABLE_UPPER_NONCRIT 0x0008
#define IPMI_SENSOR_READABLE_LOWER_NONRECOV 0x0004
#define IPMI_SENSOR_READABLE_LOWER_CRIT 0x0002
#define IPMI_SENSOR_READABLE_LOWER_NONCRIT 0x0001
/*
* Values for is_cs_reading_type. See table 42-2.
*/
#define IPMI_RT_THRESHOLD 0x01
#define IPMI_RT_USAGE 0x02
#define IPMI_RT_STATE 0x03
#define IPMI_RT_PREDFAIL 0x04
#define IPMI_RT_LIMIT 0x05
#define IPMI_RT_PERFORMANCE 0x06
#define IPMI_RT_SEVERITY 0x07
#define IPMI_RT_PRESENT 0x08
#define IPMI_RT_ENABLED 0x09
#define IPMI_RT_AVAILABILITY 0x0A
#define IPMI_RT_REDUNDANCY 0x0B
#define IPMI_RT_ACPI 0x0C
#define IPMI_RT_SPECIFIC 0x6F
/*
* Bitmasks based on above reading types. See table 42-2
*/
#define IPMI_SR_THRESHOLD_LOWER_NONCRIT_LOW 0x0001
#define IPMI_SR_THRESHOLD_LOWER_NONCRIT_HIGH 0x0002
#define IPMI_SR_THRESHOLD_LOWER_CRIT_LOW 0x0004
#define IPMI_SR_THRESHOLD_LOWER_CRIT_HIGH 0x0008
#define IPMI_SR_THRESHOLD_LOWER_NONRECOV_LOW 0x0010
#define IPMI_SR_THRESHOLD_LOWER_NONRECOV_HIGH 0x0020
#define IPMI_SR_THRESHOLD_UPPER_NONCRIT_LOW 0x0040
#define IPMI_SR_THRESHOLD_UPPER_NONCRIT_HIGH 0x0080
#define IPMI_SR_THRESHOLD_UPPER_CRIT_LOW 0x0100
#define IPMI_SR_THRESHOLD_UPPER_CRIT_HIGH 0x0200
#define IPMI_SR_THRESHOLD_UPPER_NONRECOV_LOW 0x0400
#define IPMI_SR_THRESHOLD_UPPER_NONRECOV_HIGH 0x0800
#define IPMI_SR_USAGE_IDLE 0x0001
#define IPMI_SR_USAGE_ACTIVE 0x0002
#define IPMI_SR_USAGE_BUSY 0x0004
#define IPMI_SR_STATE_DEASSERT 0x0001
#define IPMI_SR_STATE_ASSERT 0x0002
#define IPMI_SR_PREDFAIL_DEASSERT 0x0001
#define IPMI_SR_PREDFAIL_ASSERT 0x0002
#define IPMI_SR_LIMIT_NOTEXCEEDED 0x0001
#define IPMI_SR_LIMIT_EXCEEDED 0x0002
#define IPMI_SR_PERFORMANCE_MET 0x0001
#define IPMI_SR_PERFORMANCE_LAGS 0x0002
#define IPMI_SR_SEVERITY_TO_OK 0x0001
#define IPMI_SR_SEVERITY_OK_TO_NONCRIT 0x0002
#define IPMI_SR_SEVERITY_LESS_TO_CRIT 0x0004
#define IPMI_SR_SEVERITY_LESS_TO_NONRECOV 0x0008
#define IPMI_SR_SEVERITY_MORE_TO_NONCRIT 0x0010
#define IPMI_SR_SEVERITY_NONRECOV_TO_CRIT 0x0020
#define IPMI_SR_SEVERITY_TO_NONRECOV 0x0040
#define IPMI_SR_SEVERITY_MONITOR 0x0080
#define IPMI_SR_SEVERITY_INFO 0x0100
#define IPMI_SR_PRESENT_DEASSERT 0x0001
#define IPMI_SR_PRESENT_ASSERT 0x0002
#define IPMI_SR_ENABLED_DEASSERT 0x0001
#define IPMI_SR_ENABLED_ASSERT 0x0002
#define IPMI_SR_AVAILABILITY_RUNNING 0x0001
#define IPMI_SR_AVAILABILITY_INTEST 0x0002
#define IPMI_SR_AVAILABILITY_POWEROFF 0x0004
#define IPMI_SR_AVAILABILITY_ONLINE 0x0008
#define IPMI_SR_AVAILABILITY_OFFLINE 0x0010
#define IPMI_SR_AVAILABILITY_OFFDUTY 0x0020
#define IPMI_SR_AVAILABILITY_DEGRADED 0x0040
#define IPMI_SR_AVAILABILITY_POWERSAVE 0x0080
#define IPMI_SR_AVAILABILITY_INSTALLERR 0x0100
#define IPMI_SR_REDUNDANCY_FULL 0x0001
#define IPMI_SR_REDUNDANCY_LOST 0x0002
#define IPMI_SR_REDUNDANCY_DEGRADED 0x0004
#define IPMI_SR_REDUNDANCY_NONE_MINIMAL 0x0008
#define IPMI_SR_REDUNDANCY_NONE_REGAINED 0x0010
#define IPMI_SR_REDUNDANCY_NONE_INSUFFFICIENT 0x0020
#define IPMI_SR_REDUNDANCY_DEG_FROM_FULL 0x0040
#define IPMI_SR_REDUNDANCY_DEG_FROM_NON 0x0080
#define IPMI_SR_ACPI_DO 0x0001
#define IPMI_SR_ACPI_D1 0x0002
#define IPMI_SR_ACPI_D2 0x0004
#define IPMI_SR_ACPI_D3 0x0008
/*
* Bitmasks for sensor-specific reading type (0x6F). See section 42.2.
*/
#define IPMI_ST_RESERVED 0x00
#define IPMI_ST_TEMP 0x01
#define IPMI_ST_VOLTAGE 0x02
#define IPMI_ST_CURRENT 0x03
#define IPMI_ST_FAN 0x04
#define IPMI_ST_PHYSICAL 0x05
#define IPMI_EV_PHYSICAL_GENERAL 0x0001
#define IPMI_EV_PHYSICAL_BAY 0x0002
#define IPMI_EV_PHYSICAL_CARD 0x0004
#define IPMI_EV_PHYSICAL_PROCESSOR 0x0008
#define IPMI_EV_PHYSICAL_LAN 0x0010
#define IPMI_EV_PHYSICAL_DOCK 0x0020
#define IPMI_EV_PHYSICAL_FAN 0x0040
#define IPMI_ST_PLATFORM 0x06
#define IPMI_EV_PLATFORM_SECURE 0x0001
#define IPMI_EV_PLATFORM_USER_PASS 0x0002
#define IPMI_EV_PLATFORM_SETUP_PASS 0x0004
#define IPMI_EV_PLATFORM_NETWORK_PASS 0x0008
#define IPMI_EV_PLATFORM_OTHER_PASS 0x0010
#define IPMI_EV_PLATFORM_OUT_OF_BAND 0x0020
#define IPMI_ST_PROCESSOR 0x07
#define IPMI_EV_PROCESSOR_IERR 0x0001
#define IPMI_EV_PROCESSOR_THERMAL 0x0002
#define IPMI_EV_PROCESSOR_FRB1 0x0004
#define IPMI_EV_PROCESSOR_FRB2 0x0008
#define IPMI_EV_PROCESSOR_FRB3 0x0010
#define IPMI_EV_PROCESSOR_CONFIG 0x0020
#define IPMI_EV_PROCESSOR_SMBIOS 0x0040
#define IPMI_EV_PROCESSOR_PRESENT 0x0080
#define IPMI_EV_PROCESSOR_DISABLED 0x0100
#define IPMI_EV_PROCESSOR_TERMINATOR 0x0200
#define IPMI_EV_PROCESSOR_THROTTLED 0x0400
#define IPMI_ST_POWER_SUPPLY 0x08
#define IPMI_EV_POWER_SUPPLY_PRESENT 0x0001
#define IPMI_EV_POWER_SUPPLY_FAILURE 0x0002
#define IPMI_EV_POWER_SUPPLY_PREDFAIL 0x0004
#define IPMI_EV_POWER_SUPPLY_INPUT_LOST 0x0008
#define IPMI_EV_POWER_SUPPLY_INPUT_RANGE 0x0010
#define IPMI_EV_POWER_SUPPLY_INPUT_RANGE_PRES 0x0020
#define IPMI_EV_POWER_SUPPLY_CONFIG_ERR 0x0040
#define IPMI_ST_POWER_UNIT 0x09
#define IPMI_EV_POWER_UNIT_OFF 0x0001
#define IPMI_EV_POWER_UNIT_CYCLE 0x0002
#define IPMI_EV_POWER_UNIT_240_DOWN 0x0004
#define IPMI_EV_POWER_UNIT_INTERLOCK_DOWN 0x0008
#define IPMI_EV_POWER_UNIT_AC_LOST 0x0010
#define IPMI_EV_POWER_UNIT_SOFT_FAILURE 0x0020
#define IPMI_EV_POWER_UNIT_FAIL 0x0040
#define IPMI_EV_POWER_UNIT_PREDFAIL 0x0080
#define IPMI_ST_COOLING 0x0A
#define IPMI_ST_OTHER 0x0B
#define IPMI_ST_MEMORY 0x0C
#define IPMI_EV_MEMORY_CE 0x0001
#define IPMI_EV_MEMORY_UE 0x0002
#define IPMI_EV_MEMORY_PARITY 0x0004
#define IPMI_EV_MEMORY_SCRUB_FAIL 0x0008
#define IPMI_EV_MEMORY_DISABLED 0x0010
#define IPMI_EV_MEMORY_CE_LOG_LIMIT 0x0020
#define IPMI_EV_MEMORY_PRESENT 0x0040
#define IPMI_EV_MEMORY_CONFIG_ERR 0x0080
#define IPMI_EV_MEMORY_SPARE 0x0100
#define IPMI_EV_MEMORY_THROTTLED 0x0200
#define IPMI_EV_MEMORY_OVERTEMP 0x0400
#define IPMI_ST_BAY 0x0D
#define IPMI_EV_BAY_PRESENT 0x0001
#define IPMI_EV_BAY_FAULT 0x0002
#define IPMI_EV_BAY_PREDFAIL 0x0004
#define IPMI_EV_BAY_SPARE 0x0008
#define IPMI_EV_BAY_CHECK 0x0010
#define IPMI_EV_BAY_CRITICAL 0x0020
#define IPMI_EV_BAY_FAILED 0x0040
#define IPMI_EV_BAY_REBUILDING 0x0080
#define IPMI_EV_BAY_ABORTED 0x0100
#define IPMI_ST_POST_RESIZE 0x0E
#define IPMI_ST_FIRMWARE 0x0F
#define IPMI_EV_FIRMWARE_ERROR 0x0001
#define IPMI_EV_FIRMWARE_HANG 0x0002
#define IPMI_EV_FIRMWARE_PROGRESS 0x0004
#define IPMI_ST_EVENT_LOG 0x10
#define IPMI_EV_EVENT_LOG_CE 0x0001
#define IPMI_EV_EVENT_LOG_TYPE 0x0002
#define IPMI_EV_EVENT_LOG_RESET 0x0004
#define IPMI_EV_EVENT_LOG_ALL 0x0008
#define IPMI_EV_EVENT_LOG_FULL 0x0010
#define IPMI_EV_EVENT_LOG_ALMOST_FULL 0x0020
#define IPMI_ST_WATCHDOG1 0x11
#define IPMI_EV_WATCHDOG_BIOS_RESET 0x0001
#define IPMI_EV_WATCHDOG_OS_RESET 0x0002
#define IPMI_EV_WATCHDOG_OS_SHUTDOWN 0x0004
#define IPMI_EV_WATCHDOG_OS_PWR_DOWN 0x0008
#define IPMI_EV_WATCHDOG_OS_PWR_CYCLE 0x0010
#define IPMI_EV_WATCHDOG_OS_NMI_DIAG 0x0020
#define IPMI_EV_WATCHDOG_EXPIRED 0x0040
#define IPMI_EV_WATCHDOG_PRE_TIMEOUT_INT 0x0080
#define IPMI_ST_SYSTEM 0x12
#define IPMI_EV_STSTEM_RECONF 0x0001
#define IPMI_EV_STSTEM_BOOT 0x0002
#define IPMI_EV_STSTEM_UNKNOWN_HW_FAILURE 0x0004
#define IPMI_EV_STSTEM_AUX_LOG_UPDATED 0x0008
#define IPMI_EV_STSTEM_PEF_ACTION 0x0010
#define IPMI_EV_SYSTEM_TIMETAMP_CLOCKSYNC 0x0020
#define IPMI_ST_CRITICAL 0x13
#define IPMI_EV_CRITICAL_EXT_NMI 0x0001
#define IPMI_EV_CRITICAL_BUS_TIMOEOUT 0x0002
#define IPMI_EV_CRITICAL_IO_NMI 0x0004
#define IPMI_EV_CRITICAL_SW_NMI 0x0008
#define IPMI_EV_CRITICAL_PCI_PERR 0x0010
#define IPMI_EV_CRITICAL_PCI_SERR 0x0020
#define IPMI_EV_CRITICAL_EISA_FAILSAFE 0x0040
#define IPMI_EV_CRITICAL_BUS_CE 0x0080
#define IPMI_EV_CRITICAL_BUS_UE 0x0100
#define IPMI_EV_CRITICAL_FATAL_NMI 0x0200
#define IPMI_EV_CRITICAL_BUS_FATAL_ERR 0x0400
#define IPMI_EV_CRITICAL_BUS_DEGRADED 0x0800
#define IPMI_ST_BUTTON 0x14
#define IPMI_EV_BUTTON_PWR 0x0001
#define IPMI_EV_BUTTON_SLEEP 0x0002
#define IPMI_EV_BUTTON_RESET 0x0004
#define IPMI_EV_BUTTON_FRU_LATCH 0x0008
#define IPMI_EV_BUTTON_FRU_SERVICE 0x0010
#define IPMI_ST_MODULE 0x15
#define IPMI_ST_MICROCONTROLLER 0x16
#define IPMI_ST_CARD 0x17
#define IPMI_ST_CHASSIS 0x18
#define IPMI_ST_CHIPSET 0x19
#define IPMI_EV_CHIPSET_PWR_CTL_FAIL 0x0001
#define IPMI_ST_FRU 0x1A
#define IPMI_ST_CABLE 0x1B
#define IPMI_EV_CABLE_CONNECTED 0x0001
#define IPMI_EV_CABLE_CONFIG_ERR 0x0002
#define IPMI_ST_TERMINATOR 0x1C
#define IPMI_ST_BOOT 0x1D
#define IPMI_EV_BOOT_BIOS_PWR_UP 0x0001
#define IPMI_EV_BOOT_BIOS_HARD_RESET 0x0002
#define IPMI_EV_BOOT_BIOS_WARM_RESET 0x0004
#define IPMI_EV_BOOT_PXE_BOOT 0x0008
#define IPMI_EV_BOOT_DIAG_BOOT 0x0010
#define IPMI_EV_BOOT_OS_HARD_RESET 0x0020
#define IPMI_EV_BOOT_OS_WARM_RESET 0x0040
#define IPMI_EV_BOOT_SYS_RESTART 0x0080
#define IPMI_ST_BOOT_ERROR 0x1E
#define IPMI_EV_BOOT_ERROR_NOMEDIA 0x0001
#define IPMI_EV_BOOT_ERROR_NON_BOOTABLE_DISK 0x0002
#define IPMI_EV_BOOT_ERROR_NO_PXE_SERVER 0x0004
#define IPMI_EV_BOOT_ERROR_INV_BOOT_SECT 0x0008
#define IPMI_EV_BOOT_ERROR_USR_SELECT_TIMEOUT 0x0010
#define IPMI_ST_BOOT_OS 0x1F
#define IPMI_EV_BOOT_OS_A_DRV_BOOT_COMPLETE 0x0001
#define IPMI_EV_BOOT_OS_C_DRV_BOOT_COMPLETE 0x0002
#define IPMI_EV_BOOT_OS_PXE_BOOT_COMPLETE 0x0004
#define IPMI_EV_BOOT_OS_DIAG_BOOT_COMPLETE 0x0008
#define IPMI_EV_BOOT_OS_CDROM_BOOT_COMPLETE 0x0010
#define IPMI_EV_BOOT_OS_ROM_BOOT_COMPLETE 0x0020
#define IPMI_EV_BOOT_OS_UNSPEC_BOOT_COMPLETE 0x0040
#define IPMI_ST_OS_SHUTDOWN 0x20
#define IPMI_EV_OS_SHUTDOWN_LOADING 0x0001
#define IPMI_EV_OS_SHUTDOWN_CRASH 0x0002
#define IPMI_EV_OS_STOP_GRACEFUL 0x0004
#define IPMI_EV_OS_SHUTDOWN_GRACEFUL 0x0008
#define IPMI_EV_OS_SHUTDOWN_PEF 0x0010
#define IPMI_EV_OS_SHUTDOWN_BMC 0x0020
#define IPMI_ST_SLOT 0x21
#define IPMI_EV_SLOT_FAULT_ASSERTED 0x0001
#define IPMI_EV_SLOT_IDENTIFY_ASSERTED 0x0002
#define IPMI_EV_SLOT_CONNECTED 0x0004
#define IPMI_EV_SLOT_INSTALL_READY 0x0008
#define IPMI_EV_SLOT_REMOVE_READY 0x0010
#define IPMI_EV_SLOT_PWR_OFF 0x0020
#define IPMI_EV_SLOT_REMOVED 0x0040
#define IPMI_EV_SLOT_INTERLOCK_ASSERTED 0x0080
#define IPMI_EV_SLOT_DISABLED 0x0100
#define IPMI_EV_SLOT_SPARE_DEVICE 0x0200
#define IPMI_ST_ACPI 0x22
#define IPMI_EV_ACPI_PSTATE_S0_G0 0x0001
#define IPMI_EV_ACPI_PSTATE_S1 0x0002
#define IPMI_EV_ACPI_PSTATE_S2 0x0004
#define IPMI_EV_ACPI_PSTATE_S3 0x0008
#define IPMI_EV_ACPI_PSTATE_S4 0x0010
#define IPMI_EV_ACPI_PSTATE_S5_G2_SOFT_OFF 0x0020
#define IPMI_EV_ACPI_PSTATE_S4_S5_SOFT_OFF 0x0040
#define IPMI_EV_ACPI_PSATTE_G3_MECH_OFF 0x0080
#define IPMI_EV_ACPI_PSTATE_S1_S2_S3_SLEEP 0x0100
#define IPMI_EV_ACPI_PSTATE_G1_SLEEP 0x0200
#define IPMI_EV_ACPI_PSTATE_S5_OVERRIDE 0x0400
#define IPMI_EV_ACPI_PSTATE_LEGACY_ON 0x0800
#define IPMI_EV_ACPI_PSTATE_LEGACY_OFF 0x1000
#define IPMI_EV_ACPI_PSTATE_UNKNOWN 0x2000
#define IPMI_ST_WATCHDOG2 0x23
#define IPMI_EV_WATCHDOG2_EXPIRED 0x0001
#define IPMI_EV_WATCHDOG2_HARD_RESET 0x0002
#define IPMI_EV_WATCHDOG2_PWR_DOWN 0x0004
#define IPMI_EV_WATCHDOG2_PWR_CYCLE 0x0008
#define IPMI_EV_WATCHDOG2_RESERVED1 0x0010
#define IPMI_EV_WATCHDOG2_RESERVED2 0x0020
#define IPMI_EV_WATCHDOG2_RESERVED3 0x0040
#define IPMI_EV_WATCHDOG2_RESERVED4 0x0080
#define IPMI_EV_WATCHDOG2_TIMEOUT_INT 0x0100
#define IPMI_ST_ALERT 0x24
#define IPMI_EV_ALERT_PLAT_PAGE 0x0001
#define IPMI_EV_ALERT_PLAT_LAN_ALERT 0x0002
#define IPMI_EV_ALERT_PLAT_EVT_TRAP 0x0004
#define IPMI_EV_ALERT_PLAT_SNMP_TRAP 0x0008
#define IPMI_ST_PRESENCE 0x25
#define IPMI_EV_PRESENCE_PRESENT 0x0001
#define IPMI_EV_PRESENCE_ABSENT 0x0002
#define IPMI_EV_PRESENCE_DISABLED 0x0004
#define IPMI_ST_ASIC 0x26
#define IPMI_ST_LAN 0x27
#define IPMI_EV_LAN_HEARTBEAT_LOST 0x0001
#define IPMI_EV_LAN_HEARTBEAT 0x0002
#define IPMI_ST_HEALTH 0x28
#define IPMI_EV_HEALTH_SENSOR_ACC_DEGRADED 0x0001
#define IPMI_EV_HEALTH_CNTLR_ACC_DEGRADED 0x0002
#define IPMI_EV_HEALTH_CNTLR_OFFLINE 0x0004
#define IPMI_EV_HEALTH_CNTLR_UNAVAIL 0x0008
#define IPMI_EV_HEALTH_SENSOR_FAILURE 0x0010
#define IPMI_EV_HEALTH_FRU_FAILURE 0x0020
#define IPMI_ST_BATTERY 0x29
#define IPMI_EV_BATTERY_LOW 0x0001
#define IPMI_EV_BATTERY_FAILED 0x0002
#define IPMI_EV_BATTERY_PRESENCE 0x0004
#define IPMI_ST_AUDIT 0x2A
#define IPMI_EV_AUDIT_SESSION_ACTIVATED 0x0001
#define IPMI_EV_AUDIT_SESSION_DEACTIVATED 0x0002
#define IPMI_ST_VERSION 0x2B
#define IPMI_EV_VERSION_HW_CHANGE 0x0001
#define IPMI_EV_VERSION_SW_CHANGE 0x0002
#define IPMI_EV_VERSION_HW_INCOMPATIBLE 0x0004
#define IPMI_EV_VERSION_SW_INCOMPATIBLE 0x0008
#define IPMI_EV_VERSION_HW_INVAL 0x0010
#define IPMI_EV_VERSION_SW_INVAL 0x0020
#define IPMI_EV_VERSION_HW_CHANGE_SUCCESS 0x0040
#define IPMI_EV_VERSION_SW_CHANGE_SUCCESS 0x0080
#define IPMI_ST_FRU_STATE 0x2C
#define IPMI_EV_FRU_STATE_NOT_INSTALLED 0x0001
#define IPMI_EV_FRU_STATE_INACTIVE 0x0002
#define IPMI_EV_FRU_STATE_ACT_REQ 0x0004
#define IPMI_EV_FRU_STATE_ACT_INPROGRESS 0x0008
#define IPMI_EV_FRU_STATE_ACTIVE 0x0010
#define IPMI_EV_FRU_STATE_DEACT_REQ 0x0020
#define IPMI_EV_FRU_STATE_DEACT_INPROGRESS 0x0040
#define IPMI_EV_FRU_STATE_COMM_LOST 0x0080
/*
* Constants for unit type codes. See Table 43-15.
*/
#define IPMI_UNITS_UNSPECIFIED 0x00
#define IPMI_UNITS_DEGREES_C 0x01
#define IPMI_UNITS_DEGREES_F 0x02
#define IPMI_UNITS_DEGREES_K 0x03
#define IPMI_UNITS_VOLTS 0x04
#define IPMI_UNITS_AMPS 0x05
#define IPMI_UNITS_WATTS 0x06
#define IPMI_UNITS_JOULES 0x07
#define IPMI_UNITS_COULOMBS 0x08
#define IPMI_UNITS_VA 0x09
#define IPMI_UNITS_NITS 0x0A
#define IPMI_UNITS_LUMEN 0x0B
#define IPMI_UNITS_LUX 0x0C
#define IPMI_UNITS_CANDELA 0x0D
#define IPMI_UNITS_KPA 0x0E
#define IPMI_UNITS_PSI 0x0F
#define IPMI_UNITS_NEWTON 0x10
#define IPMI_UNITS_CFM 0x11
#define IPMI_UNITS_RPM 0x12
#define IPMI_UNITS_HZ 0x13
#define IPMI_UNITS_MICROSEC 0x14
#define IPMI_UNITS_MILLISEC 0x15
#define IPMI_UNITS_SECS 0x16
#define IPMI_UNITS_MIN 0x17
#define IPMI_UNITS_HOUR 0x18
#define IPMI_UNITS_DAY 0x19
#define IPMI_UNITS_WEEK 0x1A
#define IPMI_UNITS_MIL 0x1B
#define IPMI_UNITS_INCHES 0x1C
#define IPMI_UNITS_FEET 0x1D
#define IPMI_UNITS_CUB_INCH 0x1E
#define IPMI_UNITS_CUB_FEET 0x1F
#define IPMI_UNITS_MM 0x20
#define IPMI_UNITS_CM 0x21
#define IPMI_UNITS_METERS 0x22
#define IPMI_UNITS_CUB_CM 0x23
#define IPMI_UNITS_CUB_METER 0x24
#define IPMI_UNITS_LITERS 0x25
#define IPMI_UNITS_FLUID_OUNCE 0x26
#define IPMI_UNITS_RADIANS 0x27
#define IPMI_UNITS_STERADIANS 0x28
#define IPMI_UNITS_REVOLUTIONS 0x29
#define IPMI_UNITS_CYCLES 0x2A
#define IPMI_UNITS_GRAVITIES 0x2B
#define IPMI_UNITS_OUNCE 0x2C
#define IPMI_UNITS_POUND 0x2D
#define IPMI_UNITS_FOOT_POUND 0x2E
#define IPMI_UNITS_OZ_INCH 0x2F
#define IPMI_UNITS_GAUSS 0x30
#define IPMI_UNITS_GILBERTS 0x31
#define IPMI_UNITS_HENRY 0x32
#define IPMI_UNITS_MILHENRY 0x33
#define IPMI_UNITS_FARAD 0x34
#define IPMI_UNITS_MICROFARAD 0x35
#define IPMI_UNITS_OHMS 0x36
#define IPMI_UNITS_SIEMENS 0x37
#define IPMI_UNITS_MOLE 0x38
#define IPMI_UNITS_BECQUEREL 0x39
#define IPMI_UNITS_PPM 0x3A
/* 0x3B is reserved */
#define IPMI_UNITS_DECIBELS 0x3C
#define IPMI_UNITS_DBA 0x3D
#define IPMI_UNITS_DBC 0x3E
#define IPMI_UNITS_GRAY 0x3F
#define IPMI_UNITS_SIEVERT 0x40
#define IPMI_UNITS_COLOR_TEMP_K 0x41
#define IPMI_UNITS_BIT 0x42
#define IPMI_UNITS_KILOBIT 0x43
#define IPMI_UNITS_MEGABIT 0x44
#define IPMI_UNITS_GIGABIT 0x45
#define IPMI_UNITS_BYTE 0x46
#define IPMI_UNITS_KILOBYTE 0x47
#define IPMI_UNITS_MEGABYTE 0x48
#define IPMI_UNITS_GIGABYTE 0x49
#define IPMI_UNITS_WORD 0x4A
#define IPMI_UNITS_DWORD 0x4B
#define IPMI_UNITS_QWORD 0x4C
#define IPMI_UNITS_MEMLINE 0x4D
#define IPMI_UNITS_HIT 0x4E
#define IPMI_UNITS_MISS 0x4F
#define IPMI_UNITS_RETRY 0x50
#define IPMI_UNITS_RESET 0x51
#define IPMI_UNITS_OVERFLOW 0x52
#define IPMI_UNITS_UNDERRUN 0x53
#define IPMI_UNITS_COLLISION 0x54
#define IPMI_UNITS_PACKETS 0x55
#define IPMI_UNITS_MESSAGES 0x56
#define IPMI_UNITS_CHARACTERS 0x57
#define IPMI_UNITS_ERROR 0x58
#define IPMI_UNITS_CE 0x59
#define IPMI_UNITS_UE 0x5A
#define IPMI_UNITS_FATAL_ERROR 0x5B
#define IPMI_UNITS_GRAMS 0x5C
/*
* Event-Only Record. See section 43.3.
*/
#define IPMI_SDR_TYPE_EVENT_ONLY 0x03
typedef struct ipmi_sdr_event_only {
/* RECORD KEY BYTES */
uint8_t is_eo_owner;
DECL_BITFIELD3(
is_eo_sensor_lun :2,
is_eo_fru_lun :2,
is_eo_channel :4);
uint8_t is_eo_number;
/* RECORD BODY BYTES */
uint8_t is_eo_entity_id;
DECL_BITFIELD2(
is_eo_entity_instance :7,
is_eo_entity_logical :1);
uint8_t is_eo_sensor_type;
uint8_t is_eo_reading_type;
DECL_BITFIELD3(
is_eo_share_count :4,
is_eo_modifier_type :2,
is_eo_direction :2);
DECL_BITFIELD2(
is_eo_modifier_offset :7,
is_eo_sharing :1);
uint8_t __reserved;
uint8_t is_eo_oem;
DECL_BITFIELD3(
is_eo_idlen :5,
__reserved1 :1,
is_eo_idtype :2);
char is_eo_idstring[1];
} ipmi_sdr_event_only_t;
/*
* Entity Association Record. See section 43.4.
*/
#define IPMI_SDR_TYPE_ENTITY_ASSOCIATION 0x08
typedef struct ipmi_sdr_entity_association {
/* RECORD KEY BYTES */
uint8_t is_ea_entity_id;
uint8_t is_ea_entity_instance;
DECL_BITFIELD4(
__reserved :5,
is_ea_presence :1,
is_ea_record_link :1,
is_ea_range :1);
/* RECORD BODY BYTES */
struct {
uint8_t is_ea_sub_id;
uint8_t is_ea_sub_instance;
} is_ea_sub[4];
} ipmi_sdr_entity_association_t;
/*
* Device-relative Entity Association Record. See section 43.5.
*/
#define IPMI_SDR_TYPE_DEVICE_RELATIVE 0x09
typedef struct ipmi_sdr_device_relative {
/* RECORD KEY BYTES */
uint8_t is_dr_entity_id;
uint8_t is_dr_entity_instance;
DECL_BITFIELD2(
__reserved1 :1,
is_dr_slaveaddr :7);
DECL_BITFIELD2(
__reserved2 :4,
is_dr_channel :4);
DECL_BITFIELD4(
__reserved :5,
is_dr_presence :1,
is_dr_record_link :1,
is_dr_range :1);
/* RECORD BODY BYTES */
struct {
DECL_BITFIELD2(
__reserved3 :1,
is_dr_sub_slaveaddr :7);
DECL_BITFIELD2(
__reserved4 :4,
is_dr_sub_channel :4);
uint8_t is_ea_sub_id;
uint8_t is_ea_sub_instance;
} is_ea_sub[4];
} ipmi_sdr_device_relative_t;
/*
* Generic Device Locator Record. See section 43.7.
*/
#define IPMI_SDR_TYPE_GENERIC_LOCATOR 0x10
typedef struct ipmi_sdr_generic_locator {
/* RECORD KEY BYTES */
DECL_BITFIELD2(
__reserved1 :1,
is_gl_accessaddr :7);
DECL_BITFIELD2(
is_gl_channel_msb :1,
is_gl_slaveaddr :7);
DECL_BITFIELD3(
is_gl_bus :3,
is_gl_lun :2,
is_gl_channel :3);
/* RECORD BODY BYTES */
DECL_BITFIELD2(
is_gl_span :3,
__reserved2 :5);
uint8_t __reserved3;
uint8_t is_gl_type;
uint8_t is_gl_modifier;
uint8_t is_gl_entity;
uint8_t is_gl_instance;
uint8_t is_gl_oem;
DECL_BITFIELD3(
is_gl_idlen :5,
__reserved4 :1,
is_gl_idtype :2);
char is_gl_idstring[1];
} ipmi_sdr_generic_locator_t;
/*
* FRU Device Locator Record. See section 43.8.
*/
#define IPMI_SDR_TYPE_FRU_LOCATOR 0x11
typedef struct ipmi_sdr_fru_locator {
/* RECORD KEY BYTES */
DECL_BITFIELD2(
__reserved1 :1,
is_fl_accessaddr :7);
union {
struct {
uint8_t _is_fl_devid;
} _logical;
struct {
DECL_BITFIELD2(
__reserved :1,
_is_fl_slaveaddr :7);
} _nonintelligent;
} _devid_or_slaveaddr;
DECL_BITFIELD4(
is_fl_bus :3,
is_fl_lun :2,
__reserved2 :2,
is_fl_logical :1);
DECL_BITFIELD2(
__reserved3 :4,
is_fl_channel :4);
/* RECORD BODY BYTES */
uint8_t __reserved4;
uint8_t is_fl_type;
uint8_t is_fl_modifier;
uint8_t is_fl_entity;
uint8_t is_fl_instance;
uint8_t is_fl_oem;
DECL_BITFIELD3(
is_fl_idlen :5,
__reserved5 :1,
is_fl_idtype :2);
char is_fl_idstring[1];
} ipmi_sdr_fru_locator_t;
#define is_fl_devid _devid_or_slaveaddr._logical._is_fl_devid
#define is_fl_slaveaddr _devid_or_slaveaddr._nonintelligent._is_fl_slaveaddr
/*
* Management Controller Device Locator Record. See section 43.9
*/
#define IPMI_SDR_TYPE_MANAGEMENT_LOCATOR 0x12
typedef struct ipmi_sdr_management_locator {
/* RECORD KEY BYTES */
DECL_BITFIELD2(
__reserved1 :1,
is_ml_devaddr :7);
DECL_BITFIELD2(
is_ml_channel :4,
__reserved2 :4);
/* RECORD BODY BYTES */
DECL_BITFIELD7(
is_ml_init_message :2,
is_ml_init_log :1,
is_ml_init_controller_log :1,
__reserved3 :1,
is_ml_static :1,
is_ml_acpi_device :1,
is_ml_acpi_system :1);
DECL_BITFIELD8(
is_ml_supp_sensor :1,
is_ml_supp_sdr :1,
is_ml_supp_sel :1,
is_ml_supp_fru :1,
is_ml_supp_event_receiver :1,
is_ml_supp_event_generator :1,
is_ml_supp_bridge :1,
is_ml_supp_chassis :1);
uint8_t __reserved4;
uint16_t __reserved5;
uint8_t is_ml_entity_id;
uint8_t is_ml_entity_instance;
uint8_t is_ml_oem;
DECL_BITFIELD3(
is_ml_idlen :5,
__reserved6 :1,
is_ml_idtype :2);
char is_ml_idstring[1];
} ipmi_sdr_management_locator_t;
#define IPMI_MESSAGE_INIT_ENABLE 0x0
#define IPMI_MESSAGE_INIT_DISABLE 0x1
#define IPMI_MESSAGE_INIT_NONE 0x2
/*
* Management Controller Confirmation Record. See section 43.10
*/
#define IPMI_SDR_TYPE_MANAGEMENT_CONFIRMATION 0x13
typedef struct ipmi_sdr_management_confirmation {
/* RECORD KEY BYTES */
DECL_BITFIELD2(
__reserved1 :1,
is_mc_slaveaddr :7);
uint8_t is_mc_deviceid;
DECL_BITFIELD2(
is_mc_dev_revision :4,
is_mc_channel :4);
/* RECORD BODY BYTES */
DECL_BITFIELD2(
is_mc_major_rev :7,
__reserved2 :1);
uint8_t is_mc_minor_rev;
uint8_t is_mc_impi_ver;
uint8_t is_mc_manufacturer[3];
uint16_t is_mc_product;
uint8_t is_mc_guid[16];
} ipmi_sdr_management_confirmation_t;
/*
* BMC Message Channel Info Record. See esction 43.11.
*/
#define IPMI_SDR_TYPE_BMC_MESSAGE_CHANNEL 0x14
typedef struct ipmi_sdr_bmc_channel {
/* RECORD BODY BYTES */
struct {
DECL_BITFIELD3(
is_bc_protocol :4,
is_bc_receive_lun :3,
is_bc_transmit :1);
} is_bc_channel[8];
uint8_t is_bc_interrupt_type;
uint8_t is_bc_buffer_type;
uint8_t __reserved;
} ipmi_sdr_bmc_channel_t;
/*
* OEM Record. See ction 43.12.
*/
#define IPMI_SDR_TYPE_OEM 0xC0
typedef struct ipmi_sdr_oem {
uint8_t is_oem_manufacturer[3];
uint8_t is_oem_data[1];
} ipmi_sdr_oem_t;
/*
* Iterate over the SDR repository. This function does the work of parsing the
* name when available, and keeping the repository in a consistent state.
*/
extern int ipmi_sdr_iter(ipmi_handle_t *,
int (*)(ipmi_handle_t *, const char *, ipmi_sdr_t *, void *), void *);
/*
* Lookup the given sensor type by name or a combination of name and entity
* ID/instance. These functions automatically read in and cache the complete
* SDR repository.
*/
extern ipmi_sdr_t *ipmi_sdr_lookup(ipmi_handle_t *, const char *);
extern ipmi_sdr_t *ipmi_sdr_lookup_precise(ipmi_handle_t *, const char *,
uint8_t, uint8_t);
extern ipmi_sdr_fru_locator_t *ipmi_sdr_lookup_fru(ipmi_handle_t *,
const char *);
extern ipmi_sdr_generic_locator_t *ipmi_sdr_lookup_generic(ipmi_handle_t *,
const char *);
extern ipmi_sdr_compact_sensor_t *ipmi_sdr_lookup_compact_sensor(
ipmi_handle_t *, const char *);
extern ipmi_sdr_full_sensor_t *ipmi_sdr_lookup_full_sensor(
ipmi_handle_t *, const char *);
/*
* Entity ID codes. See table 43.13.
*/
#define IPMI_ET_UNSPECIFIED 0x00
#define IPMI_ET_OTHER 0x01
#define IPMI_ET_UNKNOWN 0x02
#define IPMI_ET_PROCESSOR 0x03
#define IPMI_ET_DISK 0x04
#define IPMI_ET_PERIPHERAL 0x05
#define IPMI_ET_MANAGEMENT_MODULE 0x06
#define IPMI_ET_MOTHERBOARD 0x07
#define IPMI_ET_MEMORY_MODULE 0x08
#define IPMI_ET_PROCESSOR_MODULE 0x09
#define IPMI_ET_PSU 0x0A
#define IPMI_ET_CARD 0x0B
#define IPMI_ET_FRONT_PANEL 0x0C
#define IPMI_ET_BACK_PANEL 0x0D
#define IPMI_ET_POWER_BOARD 0x0E
#define IPMI_ET_BACKPLANE 0x0F
#define IPMI_ET_EXPANSION_BOARD 0x10
#define IPMI_ET_OTHER_BOARD 0x11
#define IPMI_ET_PROCESSOR_BOARD 0x12
#define IPMI_ET_POWER_DOMAIN 0x13
#define IPMI_ET_POWER_CONVERTER 0x14
#define IPMI_ET_POWER_MANAGEMENT 0x15
#define IPMI_ET_BACK_CHASSIS 0x16
#define IPMI_ET_SYSTEM_CHASSIS 0x17
#define IPMI_ET_SUB_CHASSIS 0x18
#define IPMI_ET_OTHER_CHASSIS 0x19
#define IPMI_ET_DISK_BAY 0x1A
#define IPMI_ET_PERIPHERAL_BAY 0x1B
#define IPMI_ET_DEVICE_BAY 0x1C
#define IPMI_ET_FAN 0x1D
#define IPMI_ET_COOLING_DOMAIN 0x1E
#define IPMI_ET_CABLE 0x1F
#define IPMI_ET_MEMORY_DEVICE 0x20
#define IPMI_ET_MANAGEMENT_SOFTWARE 0x21
#define IPMI_ET_SYSTEM_FIRMWARE 0x22
#define IPMI_ET_OS 0x23
#define IPMI_ET_SYSTEM_BUS 0x24
#define IPMI_ET_GROUP 0x25
#define IPMI_ET_REMOTE 0x26
#define IPMI_ET_ENVIRONMENT 0x27
#define IPMI_ET_BATTERY 0x28
#define IPMI_ET_BLADE 0x29
#define IPMI_ET_SWITCH 0x2A
#define IPMI_ET_PROCMEM_MODULE 0x2B
#define IPMI_ET_IO_MODULE 0x2C
#define IPMI_ET_PROCIO_MODULE 0x2D
#define IPMI_ET_CONTROLLER_FIRMWARE 0x2E
#define IPMI_ET_CHANNEL 0x2F
#define IPMI_ET_PCI 0x30
#define IPMI_ET_PCIE 0x31
#define IPMI_ET_SCSI 0x32
#define IPMI_ET_SATA_SAS 0x33
#define IPMI_ET_FSB 0x34
#define IPMI_ET_RTC 0x35
/*
* Get Sensor Threshold. See section 35.9
*/
#define IPMI_CMD_GET_SENSOR_THRESHOLDS 0x27
typedef struct ipmi_sensor_thresholds {
uint8_t ithr_readable_mask;
uint8_t ithr_lower_noncrit;
uint8_t ithr_lower_crit;
uint8_t ithr_lower_nonrec;
uint8_t ithr_upper_noncrit;
uint8_t ithr_upper_crit;
uint8_t ithr_upper_nonrec;
} ipmi_sensor_thresholds_t;
extern int ipmi_get_sensor_thresholds(ipmi_handle_t *,
ipmi_sensor_thresholds_t *, uint8_t);
/*
* Get Sensor Reading. See section 35.14.
*/
#define IPMI_CMD_GET_SENSOR_READING 0x2d
typedef struct ipmi_sensor_reading {
uint8_t isr_reading;
DECL_BITFIELD4(
__reserved1 :5,
isr_state_unavailable :1,
isr_scanning_enabled :1,
isr_event_enabled :1);
uint16_t isr_state;
} ipmi_sensor_reading_t;
#define IPMI_SENSOR_THRESHOLD_LOWER_NONCRIT 0x0001
#define IPMI_SENSOR_THRESHOLD_LOWER_CRIT 0x0002
#define IPMI_SENSOR_THRESHOLD_LOWER_NONRECOV 0x0004
#define IPMI_SENSOR_THRESHOLD_UPPER_NONCRIT 0x0008
#define IPMI_SENSOR_THRESHOLD_UPPER_CRIT 0x0010
#define IPMI_SENSOR_THRESHOLD_UPPER_NONRECOV 0x0020
extern ipmi_sensor_reading_t *ipmi_get_sensor_reading(ipmi_handle_t *, uint8_t);
extern int ipmi_sdr_conv_reading(ipmi_sdr_full_sensor_t *, uint8_t,
double *);
/*
* Set Sensor Reading. See section 35.14.
*/
#define IPMI_CMD_SET_SENSOR_READING 0x30
#define IPMI_SENSOR_OP_CLEAR 0x3 /* clear '0' bits */
#define IPMI_SENSOR_OP_SET 0x2 /* set '1' bits */
#define IPMI_SENSOR_OP_EXACT 0x1 /* set bits exactly */
typedef struct ipmi_set_sensor_reading {
uint8_t iss_id;
DECL_BITFIELD5(
iss_set_reading :1,
__reserved :1,
iss_deassrt_op :2,
iss_assert_op :2,
iss_data_bytes :2);
uint8_t iss_sensor_reading;
uint16_t iss_assert_state; /* optional */
uint16_t iss_deassert_state; /* optional */
uint8_t iss_event_data1; /* optional */
uint8_t iss_event_data2; /* optional */
uint8_t iss_event_data3; /* optional */
} ipmi_set_sensor_reading_t;
extern int ipmi_set_sensor_reading(ipmi_handle_t *,
ipmi_set_sensor_reading_t *);
/*
* These IPMI message id/opcodes are documented in Appendix G in the IPMI spec.
*
* Payloads for these two commands are described in Sections 34.1 and 34.2 of
* the spec, respectively.
*/
#define IPMI_CMD_GET_FRU_INV_AREA 0x10
#define IPMI_CMD_READ_FRU_DATA 0x11
/*
* Structs to hold the FRU Common Header and the FRU Product Info Area, as
* described in the IPMI Platform Management FRU Information Storage
* Definition (v1.1).
*/
typedef struct ipmi_fru_hdr
{
uint8_t ifh_format;
uint8_t ifh_int_use_off;
uint8_t ifh_chassis_info_off;
uint8_t ifh_board_info_off;
uint8_t ifh_product_info_off;
uint8_t ifh_multi_rec_off;
uint8_t ifh_pad;
uint8_t ifh_chksum;
} ipmi_fru_hdr_t;
/*
* Because only 6 bits are used to specify the length of each field in the FRU
* product and board info areas, the biggest string we would ever need to hold
* would be 63 chars plus a NULL.
*/
#define FRU_INFO_MAXLEN 64
typedef struct ipmi_fru_brd_info
{
char ifbi_manuf_date[3];
char ifbi_manuf_name[FRU_INFO_MAXLEN];
char ifbi_board_name[FRU_INFO_MAXLEN];
char ifbi_product_serial[FRU_INFO_MAXLEN];
char ifbi_part_number[FRU_INFO_MAXLEN];
} ipmi_fru_brd_info_t;
typedef struct ipmi_fru_prod_info
{
char ifpi_manuf_name[FRU_INFO_MAXLEN];
char ifpi_product_name[FRU_INFO_MAXLEN];
char ifpi_part_number[FRU_INFO_MAXLEN];
char ifpi_product_version[FRU_INFO_MAXLEN];
char ifpi_product_serial[FRU_INFO_MAXLEN];
char ifpi_asset_tag[FRU_INFO_MAXLEN];
} ipmi_fru_prod_info_t;
extern int ipmi_fru_read(ipmi_handle_t *, ipmi_sdr_fru_locator_t *, char **);
extern int ipmi_fru_parse_board(ipmi_handle_t *, char *, ipmi_fru_brd_info_t *);
extern int ipmi_fru_parse_product(ipmi_handle_t *, char *,
ipmi_fru_prod_info_t *);
/*
* Routines to convert from entity and sensors defines into text strings.
*/
void ipmi_entity_name(uint8_t, char *, size_t);
void ipmi_sensor_type_name(uint8_t, char *, size_t);
void ipmi_sensor_units_name(uint8_t, char *, size_t);
void ipmi_sensor_reading_name(uint8_t, uint8_t, char *, size_t);
/*
* Entity management. IPMI has a notion of 'entities', but these are not
* directly accessible from any commands. Instead, their existence is inferred
* from examining the SDR repository. Since this is rather unwieldy, and
* iterating over entities is a common operation, libipmi provides an entity
* abstraction that hides the implementation details. This handles entity
* groupings as well as SDR associations.
*/
typedef struct ipmi_entity {
uint8_t ie_type;
uint8_t ie_instance;
uint8_t ie_children;
boolean_t ie_logical;
} ipmi_entity_t;
extern int ipmi_entity_iter(ipmi_handle_t *, int (*)(ipmi_handle_t *,
ipmi_entity_t *, void *), void *);
extern int ipmi_entity_iter_sdr(ipmi_handle_t *, ipmi_entity_t *,
int (*)(ipmi_handle_t *, ipmi_entity_t *, const char *, ipmi_sdr_t *,
void *), void *);
extern int ipmi_entity_iter_children(ipmi_handle_t *, ipmi_entity_t *,
int (*)(ipmi_handle_t *, ipmi_entity_t *, void *), void *);
extern ipmi_entity_t *ipmi_entity_lookup(ipmi_handle_t *, uint8_t,
uint8_t);
extern ipmi_entity_t *ipmi_entity_lookup_sdr(ipmi_handle_t *, const char *);
extern ipmi_entity_t *ipmi_entity_parent(ipmi_handle_t *, ipmi_entity_t *);
extern int ipmi_entity_present(ipmi_handle_t *, ipmi_entity_t *, boolean_t *);
extern int ipmi_entity_present_sdr(ipmi_handle_t *, ipmi_sdr_t *, boolean_t *);
/*
* User management. The raw functions are private to libipmi, and only the
* higher level abstraction (ipmi_user_t) is exported to consumers of the
* library.
*/
#define IPMI_USER_PRIV_CALLBACK 0x1
#define IPMI_USER_PRIV_USER 0x2
#define IPMI_USER_PRIV_OPERATOR 0x3
#define IPMI_USER_PRIV_ADMIN 0x4
#define IPMI_USER_PRIV_OEM 0x5
#define IPMI_USER_PRIV_NONE 0xf
typedef struct ipmi_user {
uint8_t iu_uid;
char *iu_name;
boolean_t iu_enabled;
boolean_t iu_ipmi_msg_enable;
boolean_t iu_link_auth_enable;
uint8_t iu_priv;
} ipmi_user_t;
extern int ipmi_user_iter(ipmi_handle_t *,
int (*)(ipmi_user_t *, void *), void *);
extern ipmi_user_t *ipmi_user_lookup_name(ipmi_handle_t *, const char *);
extern ipmi_user_t *ipmi_user_lookup_id(ipmi_handle_t *, uint8_t);
extern int ipmi_user_set_password(ipmi_handle_t *, uint8_t, const char *);
/*
* The remaining functions are private to the implementation of the Sun ILOM
* service processor. These function first check the manufacturer from the IPMI
* device ID, and will return EIPMI_NOT_SUPPORTED if attempted for non-Sun
* devices.
*/
boolean_t ipmi_is_sun_ilom(ipmi_deviceid_t *);
/*
* Sun OEM LED requests.
*/
#define IPMI_SUNOEM_LED_MODE_OFF 0
#define IPMI_SUNOEM_LED_MODE_ON 1
#define IPMI_SUNOEM_LED_MODE_STANDBY 2
#define IPMI_SUNOEM_LED_MODE_SLOW 3
#define IPMI_SUNOEM_LED_MODE_FAST 4
/*
* These functions take a SDR record and construct the appropriate form of the
* above commands.
*/
extern int ipmi_sunoem_led_set(ipmi_handle_t *,
ipmi_sdr_generic_locator_t *, uint8_t);
extern int ipmi_sunoem_led_get(ipmi_handle_t *,
ipmi_sdr_generic_locator_t *, uint8_t *);
/*
* Sun OEM uptime. Note that the underlying command returns the uptime in big
* endian form. This wrapper automatically converts to the appropriate native
* form.
*/
#define IPMI_CMD_SUNOEM_UPTIME 0x08
extern int ipmi_sunoem_uptime(ipmi_handle_t *, uint32_t *, uint32_t *);
/*
* Sun OEM FRU update. The FRU information is managed through a generic
* identifier, and then a type-specific data portion. The wrapper function will
* automatically fill in the data length field according to which type is
* specified.
*/
#define IPMI_CMD_SUNOEM_FRU_UPDATE 0x16
#define IPMI_SUNOEM_FRU_DIMM 0x00
#define IPMI_SUNOEM_FRU_CPU 0x01
#define IPMI_SUNOEM_FRU_BIOS 0x02
#define IPMI_SUNOEM_FRU_DISK 0x03
typedef struct ipmi_sunoem_fru {
uint8_t isf_type;
uint8_t isf_id;
uint8_t isf_datalen;
union {
struct {
uint8_t isf_data[128];
} dimm;
struct {
uint32_t isf_thermtrip;
uint32_t isf_eax;
char isf_product[48];
} cpu;
struct {
char isf_part[16];
char isf_version[16];
} bios;
struct {
char isf_manufacturer[16];
char isf_model[28];
char isf_serial[20];
char isf_version[8];
char isf_capacity[16];
} disk;
} isf_data;
} ipmi_sunoem_fru_t;
int ipmi_sunoem_update_fru(ipmi_handle_t *, ipmi_sunoem_fru_t *);
/*
* See section 28.2
*/
#define IPMI_CMD_GET_CHASSIS_STATUS 0x01
/*
* flags for ichs_current_pwr_state field
*/
#define IPMI_CURR_PWR_STATE_ON 0x01
#define IPMI_CURR_PWR_STATE_OVERLOAD 0x02
#define IPMI_CURR_PWR_STATE_INTERLOCK 0x04
#define IPMI_CURR_PWR_STATE_FAULT 0x08
#define IPMI_CURR_PWR_STATE_CNTL_FAULT 0x10
/*
* flags for ichs_last_pwr_state field
*/
#define IPMI_LAST_PWR_STATE_ACFAILED 0x01
#define IPMI_LAST_PWR_STATE_OVERLOAD 0x02
#define IPMI_LAST_PWR_STATE_INTERLOCK 0x04
#define IPMI_LAST_PWR_STATE_FAULT 0x08
#define IPMI_LAST_PWR_STATE_CMD_ON 0x10
/*
* flags for the ichs_pwr_restore_policy field
*/
#define IPMI_PWR_POLICY_REMAIN_OFF 0x0
#define IPMI_PWR_POLICY_RESTORE 0x1
#define IPMI_PWR_POLICY_POWER_ON 0x2
#define IPMI_PWR_POLICY_UNKNOWN 0x3
typedef struct ipmi_chassis_status {
DECL_BITFIELD3(
ichs_current_pwr_state :5,
ichs_pwr_restore_policy :2,
__reserved1 :1);
DECL_BITFIELD2(
ichs_last_pwr_state :5,
__reserved2 :3);
DECL_BITFIELD7(
ichs_intrusion_asserted :1,
ichs_front_panel_disabled :1,
ichs_drive_fault_asserted :1,
ichs_fan_fault_asserted :1,
ichs_identify_state :2,
ichs_identify_supported :1,
__reserved3 :1);
} ipmi_chassis_status_t;
extern ipmi_chassis_status_t *ipmi_chassis_status(ipmi_handle_t *);
/*
* See section 28.5
*/
#define IPMI_CMD_CHASSIS_IDENTIFY 0x04
int ipmi_chassis_identify(ipmi_handle_t *, boolean_t);
#pragma pack()
#ifdef __cplusplus
}
#endif
#endif /* _LIBIPMI_H */
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
#
#
# Copyright (c) 2018, Joyent, Inc.
#
#
# MAPFILE HEADER START
#
# WARNING: STOP NOW. DO NOT MODIFY THIS FILE.
# Object versioning must comply with the rules detailed in
#
# usr/src/lib/README.mapfiles
#
# You should not be making modifications here until you've read the most current
# copy of that file. If you need help, contact a gatekeeper for guidance.
#
# MAPFILE HEADER END
#
$mapfile_version 2
SYMBOL_VERSION SUNWprivate_1.1 {
global:
ipmi_chassis_identify;
ipmi_chassis_status;
ipmi_close;
ipmi_entity_iter;
ipmi_entity_iter_children;
ipmi_entity_iter_sdr;
ipmi_entity_lookup;
ipmi_entity_lookup_sdr;
ipmi_entity_name;
ipmi_entity_parent;
ipmi_entity_present;
ipmi_entity_present_sdr;
ipmi_errmsg;
ipmi_errno;
ipmi_event_platform_message;
ipmi_firmware_version;
ipmi_fru_parse_board;
ipmi_fru_parse_product;
ipmi_fru_read;
ipmi_get_channel_info;
ipmi_get_deviceid;
ipmi_get_sensor_reading;
ipmi_get_sensor_thresholds;
ipmi_is_sun_ilom;
ipmi_lan_get_config;
ipmi_lan_set_config;
ipmi_open;
ipmi_sdr_changed;
ipmi_sdr_conv_reading;
ipmi_sdr_get;
ipmi_sdr_iter;
ipmi_sdr_lookup;
ipmi_sdr_lookup_compact_sensor;
ipmi_sdr_lookup_full_sensor;
ipmi_sdr_lookup_fru;
ipmi_sdr_lookup_generic;
ipmi_sdr_lookup_precise;
ipmi_sdr_refresh;
ipmi_sel_get_entry;
ipmi_sel_get_info;
ipmi_sel_get_time;
ipmi_sel_get_utc_offset;
ipmi_sel_set_time;
ipmi_sel_set_utc_offset;
ipmi_sensor_reading_name;
ipmi_sensor_type_name;
ipmi_sensor_units_name;
ipmi_send;
ipmi_set_sensor_reading;
ipmi_sunoem_led_get;
ipmi_sunoem_led_set;
ipmi_sunoem_update_fru;
ipmi_sunoem_uptime;
ipmi_user_iter;
ipmi_user_lookup_id;
ipmi_user_lookup_name;
ipmi_user_set_password;
local:
*;
};
#!/bin/ksh93
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Construct translation tables for defines in libipmi.h to translate to readable
# strings.
#
if [ $# -ne 1 ]; then
echo >&2 "USAGE: $0 <path to libimpi.h>"
exit 1
fi
if [ -r $1 ]; then
libipmi_h=$1
else
echo >&2 "USAGE: $0 <path to libimpi.h>"
echo >&2 "Make sure libipmi.h exists and is readable"
exit 1
fi
echo "\
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <libipmi.h>
#include <ipmi_impl.h>"
#
# Error table.
#
echo "
ipmi_name_trans_t ipmi_errno_table[] = {"
pattern=" \(EIPMI_[0-9A-Z_]*\)[^ \/]*\/\* \(.*\) \*\/$"
replace=" { \1, \"\2\" },"
cat $libipmi_h | sed -n "s/$pattern/$replace/p" || exit 1
echo "\t{ 0, NULL }
};"
#
# Entity table.
#
echo "\nipmi_name_trans_t ipmi_entity_table[] = {"
pattern="#define IPMI_ET_\([A-Z0-9_]*\).*\$"
replace=" { IPMI_ET_\1, \"\1\" },"
cat $libipmi_h | sed -n "s/$pattern/$replace/p" || exit 1
echo "\t{ 0, NULL }
};"
#
# Sensor types.
#
echo "\nipmi_name_trans_t ipmi_sensor_type_table[] = {"
pattern="#define IPMI_ST_\([A-Z0-9_]*\).*\$"
replace=" { IPMI_ST_\1, \"\1\" },"
cat $libipmi_h | sed -n "s/$pattern/$replace/p" || exit 1
echo "\t{ 0, NULL }
};"
#
# Reading types.
#
echo "\nipmi_name_trans_t ipmi_reading_type_table[] = {"
pattern="#define IPMI_RT_\([A-Z0-9_]*\).*\$"
replace=" { IPMI_RT_\1, \"\1\" },"
cat $libipmi_h | sed -n "s/$pattern/$replace/p" || exit 1
echo "\t{ 0, NULL }
};"
#
# Units
#
echo "\nipmi_name_trans_t ipmi_units_type_table[] = {"
pattern="#define IPMI_UNITS_\([A-Z0-9_]*\).*\$"
replace=" { IPMI_UNITS_\1, \"\1\" },"
cat $libipmi_h | sed -n "s/$pattern/$replace/p" || exit 1
echo "\t{ 0, NULL }
};"
|