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
|
/*
* Copyright (c) 2005-2021, Douglas Gilbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#define __STDC_FORMAT_MACROS 1
#include <inttypes.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "sg_lib.h"
#include "sg_cmds_basic.h"
#include "sg_unaligned.h"
#include "sdparm.h"
#include "sg_pr2serr.h"
/* sdparm_vpd.c : does mainly VPD page processing associated with the
* INQUIRY SCSI command.
*/
/* VPD_DEVICE_ID 0x83 */
/* Prints outs an abridged set of device identification designators
selected by association, designator type and/or code set. */
static int
decode_dev_ids_quiet(uint8_t * buff, int len, int m_assoc,
int m_desig_type, int m_code_set)
{
int m, p_id, c_set, assoc, desig_type, i_len, naa, off, u, rtp;
bool piv, is_sas;
const uint8_t * bp;
const uint8_t * ip;
uint8_t sas_tport_addr[8];
static const int sas_tport_addr_sz = sizeof(sas_tport_addr);
rtp = 0;
memset(sas_tport_addr, 0, sas_tport_addr_sz);
off = -1;
while ((u = sg_vpd_dev_id_iter(buff, len, &off, m_assoc, m_desig_type,
m_code_set)) == 0) {
bp = buff + off;
i_len = bp[3];
if ((off + i_len + 4) > len) {
pr2serr(" VPD page error: designator length longer than\n"
" remaining response length=%d\n", (len - off));
return SG_LIB_CAT_MALFORMED;
}
ip = bp + 4;
p_id = ((bp[0] >> 4) & 0xf);
c_set = (bp[0] & 0xf);
piv = !!(bp[1] & 0x80);
is_sas = (piv && (6 == p_id));
assoc = ((bp[1] >> 4) & 0x3);
desig_type = (bp[1] & 0xf);
switch (desig_type) {
case 0: /* vendor specific */
break;
case 1: /* T10 vendor identification */
break;
case 2: /* EUI-64 based */
if ((8 != i_len) && (12 != i_len) && (16 != i_len))
pr2serr(" << expect 8, 12 and 16 byte EUI, got %d >>\n",
i_len);
printf("0x");
for (m = 0; m < i_len; ++m)
printf("%02x", (unsigned int)ip[m]);
printf("\n");
break;
case 3: /* NAA <n> */
naa = (ip[0] >> 4) & 0xff;
if (1 != c_set) {
pr2serr(" << unexpected code set %d for NAA=%d >>\n",
c_set, naa);
hex2stderr(ip, i_len, 0);
break;
}
switch (naa) {
case 2: /* NAA 2: IEEE Extended */
if (8 != i_len) {
pr2serr(" << unexpected NAA 2 identifier length: "
"0x%x >>\n", i_len);
hex2stderr(ip, i_len, 0);
break;
}
printf("0x");
for (m = 0; m < 8; ++m)
printf("%02x", (unsigned int)ip[m]);
printf("\n");
break;
case 3: /* NAA 3: Locally assigned */
if (8 != i_len) {
pr2serr(" << unexpected NAA 3 identifier "
"length: 0x%x >>\n", i_len);
hex2stderr(ip, i_len, 0);
break;
}
printf("0x");
for (m = 0; m < 8; ++m)
printf("%02x", (unsigned int)ip[m]);
printf("\n");
break;
case 5: /* NAA 5: IEEE Registered */
if (8 != i_len) {
pr2serr(" << unexpected NAA 5 identifier "
"length: 0x%x >>\n", i_len);
hex2stderr(ip, i_len, 0);
break;
}
if ((! is_sas) || (1 != assoc)) {
printf("0x");
for (m = 0; m < 8; ++m)
printf("%02x", (unsigned int)ip[m]);
printf("\n");
} else if (rtp) {
printf("0x");
for (m = 0; m < 8; ++m)
printf("%02x", (unsigned int)ip[m]);
printf(",0x%x\n", rtp);
rtp = 0;
} else {
if (sas_tport_addr[0]) {
printf("0x");
for (m = 0; m < 8; ++m)
printf("%02x", (unsigned int)sas_tport_addr[m]);
printf("\n");
}
memcpy(sas_tport_addr, ip, sas_tport_addr_sz);
}
break;
case 6: /* NAA 5: IEEE Registered Extended */
if (16 != i_len) {
pr2serr(" << unexpected NAA 6 identifier length: "
"0x%x >>\n", i_len);
hex2stderr(ip, i_len, 0);
break;
}
printf("0x");
for (m = 0; m < 16; ++m)
printf("%02x", (unsigned int)ip[m]);
printf("\n");
break;
default:
pr2serr(" << expected NAA nibble of 2, 3, 5 or 6, got "
"%d >>\n", naa);
hex2stderr(ip, i_len, 0);
break;
}
break;
case 4: /* Relative target port */
if ((! is_sas) || (1 != c_set) || (1 != assoc) || (4 != i_len))
break;
rtp = sg_get_unaligned_be16(ip + 2);
if (sas_tport_addr[0]) {
printf("0x");
for (m = 0; m < 8; ++m)
printf("%02x", (unsigned int)sas_tport_addr[m]);
printf(",0x%x\n", rtp);
memset(sas_tport_addr, 0, sas_tport_addr_sz);
rtp = 0;
}
break;
case 5: /* (primary) Target port group */
break;
case 6: /* Logical unit group */
break;
case 7: /* MD5 logical unit identifier */
break;
case 8: /* SCSI name string */
if (c_set < 2) { /* accept ASCII as subset of UTF-8 */
pr2serr(" << expected UTF-8 code_set >>\n");
hex2stderr(ip, i_len, 0);
break;
}
/* does %s print out UTF-8 ok??
* Seems to depend on the locale. Looks ok here with my
* locale setting: en_AU.UTF-8
*/
printf("%.*s\n", i_len, (const char *)ip);
break;
case 9: /* Protocol specific port identifier */
break;
case 0xa: /* UUID identifier [spc5r08] RFC 4122 */
if ((1 != c_set) || (18 != i_len) || (1 != ((ip[0] >> 4) & 0xf)))
break;
for (m = 0; m < 16; ++m) {
if ((4 == m) || (6 == m) || (8 == m) || (10 == m))
printf("-");
printf("%02x", (unsigned int)ip[2 + m]);
}
printf("\n");
break;
default: /* reserved */
break;
}
}
if (sas_tport_addr[0]) {
printf("0x");
for (m = 0; m < 8; ++m)
printf("%02x", (unsigned int)sas_tport_addr[m]);
printf("\n");
}
if (-2 == u) {
pr2serr("VPD page error: short designator near offset %d\n", off);
return SG_LIB_CAT_MALFORMED;
}
return 0;
}
#define SDPARM_DECODE_DESC_SZ 2048
static void
decode_designation_descriptor(const uint8_t * bp, int i_len,
bool print_assoc,
const struct sdparm_opt_coll * op)
{
char b[SDPARM_DECODE_DESC_SZ];
sg_get_designation_descriptor_str(NULL, bp, i_len + 4, print_assoc,
op->do_long, SDPARM_DECODE_DESC_SZ, b);
printf("%s", b);
}
/* VPD_DEVICE_ID 0x83 */
/* Prints outs device identification designators selected by association,
designator type and/or code set. */
static int
decode_dev_ids(const char * print_if_found, int num_leading, uint8_t * buff,
int len, int m_assoc, int m_desig_type, int m_code_set,
const struct sdparm_opt_coll * op)
{
bool printed;
int i_len, assoc, off, u;
const uint8_t * bp;
char b[1024];
char sp[82];
if (op->do_quiet)
return decode_dev_ids_quiet(buff, len, m_assoc, m_desig_type,
m_code_set);
if (num_leading > (int)(sizeof(sp) - 2))
num_leading = sizeof(sp) - 2;
if (num_leading > 0)
snprintf(sp, sizeof(sp), "%*c", num_leading, ' ');
else
sp[0] = '\0';
off = -1;
printed = false;
while ((u = sg_vpd_dev_id_iter(buff, len, &off, m_assoc, m_desig_type,
m_code_set)) == 0) {
bp = buff + off;
i_len = bp[3];
if ((off + i_len + 4) > len) {
pr2serr(" VPD page error: designator length longer than\n"
" remaining response length=%d\n", (len - off));
return SG_LIB_CAT_MALFORMED;
}
assoc = ((bp[1] >> 4) & 0x3);
if (print_if_found && (! printed)) {
printed = true;
if (strlen(print_if_found) > 0)
printf(" %s:\n", print_if_found);
}
if (NULL == print_if_found)
printf(" %s%s:\n", sp, sg_get_desig_assoc_str(assoc));
sg_get_designation_descriptor_str(sp, bp, i_len + 4, false,
op->do_long, sizeof(b), b);
printf("%s", b);
}
if (-2 == u) {
pr2serr("VPD page error: short designator around offset %d\n", off);
return SG_LIB_CAT_MALFORMED;
}
return 0;
}
/* VPD_MODE_PG_POLICY 0x87 */
static int
decode_mode_policy_vpd(uint8_t * buff, int len)
{
int k, bump;
uint8_t * bp;
if (len < 4) {
pr2serr("Mode page policy VPD page length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
len -= 4;
bp = buff + 4;
for (k = 0; k < len; k += bump, bp += bump) {
bump = 4;
if ((k + bump) > len) {
pr2serr("Mode page policy VPD page, short descriptor length=%d, "
"left=%d\n", bump, (len - k));
return SG_LIB_CAT_MALFORMED;
}
printf(" Policy page code: 0x%x", (bp[0] & 0x3f));
if (bp[1])
printf(", subpage code: 0x%x\n", bp[1]);
else
printf("\n");
printf(" MLUS=%d (multiple LUs (in a target) share), Policy: "
"%s\n", !!(bp[2] & 0x80),
sdparm_mode_page_policy_arr[bp[2] & 0x3]);
}
return 0;
}
static const char * constituent_type_arr[] = {
"Reserved",
"Virtual tape library",
"Virtual tape drive",
"Direct access block device",
};
/* VPD_DEVICE_CONSTITUENTS 0x8b, can recurse at least one level */
static int
decode_dev_constit_vpd(uint8_t * buff, int len, int req_pdt, bool protect,
const struct sdparm_opt_coll * op)
{
int k, j, res, bump, csd_len;
uint16_t constit_type;
const uint8_t * bp;
const char * dcp = "Device constituents VPD page";
char b[64];
if (len < 4) {
pr2serr("%s length too short=%d\n", dcp, len);
return SG_LIB_CAT_MALFORMED;
}
len -= 4;
bp = buff + 4;
for (k = 0, j = 0; k < len; k += bump, bp += bump, ++j) {
if (j > 0)
printf("\n");
printf(" Constituent descriptor %d:\n", j + 1);
if ((k + 36) > len) {
pr2serr("%s, short descriptor length=36, left=%d\n", dcp,
(len - k));
return SG_LIB_CAT_MALFORMED;
}
constit_type = sg_get_unaligned_be16(bp + 0);
if (constit_type >= SG_ARRAY_SIZE(constituent_type_arr))
printf(" Constituent type: unknown [0x%x]\n", constit_type);
else
printf(" Constituent type: %s [0x%x]\n",
constituent_type_arr[constit_type], constit_type);
printf(" Constituent device type: ");
if (0xff == bp[2])
printf("Unknown [0xff]\n");
else if (bp[2] >= 0x20)
printf("Reserved [0x%x]\n", bp[2]);
else
printf("%s [0x%x]\n", sg_get_pdt_str(0x1f & bp[2], sizeof(b), b),
bp[2]);
printf(" Vendor_identification: %.8s\n", bp + 4);
printf(" Product_identification: %.16s\n", bp + 12);
printf(" Product_revision_level: %.4s\n", bp + 28);
csd_len = sg_get_unaligned_be16(bp + 34);
bump = 36 + csd_len;
if ((k + bump) > len) {
pr2serr("%s, short descriptor length=%d, left=%d\n", dcp, bump,
(len - k));
return SG_LIB_CAT_MALFORMED;
}
if (csd_len > 0) {
int m, q, cs_bump;
uint8_t cs_type;
uint8_t cs_len;
const uint8_t * cs_bp;
printf(" Constituent specific descriptors:\n");
for (m = 0, q = 0, cs_bp = bp + 36; m < csd_len;
m += cs_bump, ++q, cs_bp += cs_bump) {
cs_type = cs_bp[0];
cs_len = sg_get_unaligned_be16(cs_bp + 2);
cs_bump = cs_len + 4;
if (1 == cs_type) { /* VPD page */
int off = cs_bp + 4 - buff;
printf(" Constituent VPD page %d:\n", q + 1);
/* SPC-5 says these shall _not_ themselves be Device
* Constituent VPD pages. So no infinite recursion. */
res = sdp_process_vpd_page(-1, 0 /* pn */, 0, op,
req_pdt, protect, NULL, 0,
buff, off);
if (res)
return res;
} else {
if (0xff == cs_type)
printf(" Vendor specific data (in hex):\n");
else
printf(" Reserved [0x%x] specific data (in "
"hex):\n", cs_type);
hex2stdout(cs_bp + 4, cs_len, 0 /* plus ASCII */);
}
} /* end of Constituent specific descriptor loop */
}
} /* end Constituent descriptor loop */
return 0;
}
/* VPD_MAN_NET_ADDR 0x85 */
static int
decode_man_net_vpd(uint8_t * buff, int len)
{
int k, bump, na_len;
uint8_t * bp;
if (len < 4) {
pr2serr("Management network addresses VPD page length too short=%d\n",
len);
return SG_LIB_CAT_MALFORMED;
}
len -= 4;
bp = buff + 4;
for (k = 0; k < len; k += bump, bp += bump) {
printf(" %s, Service type: %s\n",
sg_get_desig_assoc_str((bp[0] >> 5) & 0x3),
sdparm_network_service_type_arr[bp[0] & 0x1f]);
na_len = sg_get_unaligned_be16(bp + 2);
bump = 4 + na_len;
if ((k + bump) > len) {
pr2serr("Management network addresses VPD page, short descriptor "
"length=%d, left=%d\n", bump, (len - k));
return SG_LIB_CAT_MALFORMED;
}
if (na_len > 0) {
printf(" %s\n", bp + 4);
}
}
return 0;
}
/* This is xcopy(LID4) related: "ROD" == Representation Of Data
* Used by VPD_3PARTY_COPY */
static void
decode_rod_descriptor(const uint8_t * buff, int len)
{
const uint8_t * bp = buff;
int k, bump;
uint64_t ul;
for (k = 0; k < len; k += bump, bp += bump) {
bump = sg_get_unaligned_be16(bp + 2) + 4;
switch (bp[0]) {
case 0:
/* Block ROD device type specific descriptor */
printf(" Optimal block ROD length granularity: %d\n",
sg_get_unaligned_be16(bp + 6));
printf(" Maximum Bytes in block ROD: %" PRIu64 "\n",
sg_get_unaligned_be64(bp + 8));
ul = sg_get_unaligned_be64(bp + 16);
printf(" Optimal Bytes in block ROD transfer: ");
if (SG_LIB_UNBOUNDED_64BIT == ul)
printf("-1 [no limit]\n");
else
printf("%" PRIu64 "\n", ul);
ul = sg_get_unaligned_be64(bp + 24);
printf(" Optimal Bytes to token per segment: ");
if (SG_LIB_UNBOUNDED_64BIT == ul)
printf("-1 [no limit]\n");
else
printf("%" PRIu64 "\n", ul);
ul = sg_get_unaligned_be64(bp + 32);
printf(" Optimal Bytes from token per segment: ");
if (SG_LIB_UNBOUNDED_64BIT == ul)
printf("-1 [no limit]\n");
else
printf("%" PRIu64 "\n", ul);
break;
case 1:
/* Stream ROD device type specific descriptor */
printf(" Maximum Bytes in stream ROD: %" PRIu64 "\n",
sg_get_unaligned_be64(bp + 8));
ul = sg_get_unaligned_be64(bp + 16);
printf(" Optimal Bytes in stream ROD transfer: ");
if (SG_LIB_UNBOUNDED_64BIT == ul)
printf("-1 [no limit]\n");
else
printf("%" PRIu64 "\n", ul);
break;
case 3:
/* Copy manager ROD device type specific descriptor */
printf(" Maximum Bytes in processor ROD: %" PRIu64 "\n",
sg_get_unaligned_be64(bp + 8));
ul = sg_get_unaligned_be64(bp + 16);
printf(" Optimal Bytes in processor ROD transfer: ");
if (SG_LIB_UNBOUNDED_64BIT == ul)
printf("-1 [no limit]\n");
else
printf("%" PRIu64 "\n", ul);
break;
default:
printf(" Unhandled descriptor (format %d, device type %d)\n",
bp[0] >> 5, bp[0] & 0x1F);
break;
}
}
}
struct tpc_desc_type {
uint8_t code;
const char * name;
};
struct tpc_desc_type tpc_desc_arr[] = {
{0x0, "block -> stream"},
{0x1, "stream -> block"},
{0x2, "block -> block"},
{0x3, "stream -> stream"},
{0x4, "inline -> stream"},
{0x5, "embedded -> stream"},
{0x6, "stream -> discard"},
{0x7, "verify CSCD"},
{0x8, "block<o> -> stream"},
{0x9, "stream -> block<o>"},
{0xa, "block<o> -> block<o>"},
{0xb, "block -> stream & application_client"},
{0xc, "stream -> block & application_client"},
{0xd, "block -> block & application_client"},
{0xe, "stream -> stream&application_client"},
{0xf, "stream -> discard&application_client"},
{0x10, "filemark -> tape"},
{0x11, "space -> tape"}, /* obsolete: spc5r02 */
{0x12, "locate -> tape"}, /* obsolete: spc5r02 */
{0x13, "<i>tape -> <i>tape"},
{0x14, "register persistent reservation key"},
{0x15, "third party persistent reservation source I_T nexus"},
{0x16, "<i>block -> <i>block"},
{0x17, "positioning -> tape"}, /* this and next added spc5r02 */
{0x18, "<loi>tape -> <loi>tape"}, /* loi: logical object identifier */
{0xbe, "ROD <- block range(n)"},
{0xbf, "ROD <- block range(1)"},
{0xe0, "CSCD: FC N_Port_Name"},
{0xe1, "CSCD: FC N_Port_ID"},
{0xe2, "CSCD: FC N_Port_ID with N_Port_Name, checking"},
{0xe3, "CSCD: Parallel interface: I_T"},
{0xe4, "CSCD: Identification Descriptor"},
{0xe5, "CSCD: IPv4"},
{0xe6, "CSCD: Alias"},
{0xe7, "CSCD: RDMA"},
{0xe8, "CSCD: IEEE 1394 EUI-64"},
{0xe9, "CSCD: SAS SSP"},
{0xea, "CSCD: IPv6"},
{0xeb, "CSCD: IP copy service"},
{0xfe, "CSCD: ROD"},
{0xff, "CSCD: extension"},
{0x0, NULL},
};
static const char *
get_tpc_desc_name(uint8_t code)
{
const struct tpc_desc_type * dtp;
for (dtp = tpc_desc_arr; dtp->name; ++dtp) {
if (code == dtp->code)
return dtp->name;
}
return "";
}
struct tpc_rod_type {
uint32_t type;
const char * name;
};
static struct tpc_rod_type tpc_rod_arr[] = {
{0x0, "copy manager internal"},
{0x10000, "access upon reference"},
{0x800000, "point in time copy - default"},
{0x800001, "point in time copy - change vulnerable"},
{0x800002, "point in time copy - persistent"},
{0x80ffff, "point in time copy - any"},
{0xffff0001, "block device zero"},
{0x0, NULL},
};
static const char *
get_tpc_rod_name(uint32_t rod_type)
{
const struct tpc_rod_type * rtp;
for (rtp = tpc_rod_arr; rtp->name; ++rtp) {
if (rod_type == rtp->type)
return rtp->name;
}
return "";
}
struct cscd_desc_id_t {
uint16_t id;
const char * name;
};
static struct cscd_desc_id_t cscd_desc_id_arr[] = {
/* only values higher than 0x7ff are listed */
{0xc000, "copy src or dst null LU, pdt=0"},
{0xc001, "copy src or dst null LU, pdt=1"},
{0xf800, "copy src or dst in ROD token"},
{0xffff, "copy src or dst is copy manager LU"},
{0x0, NULL},
};
static const char *
get_cscd_desc_id_name(uint16_t cscd_desc_id)
{
const struct cscd_desc_id_t * cdip;
for (cdip = cscd_desc_id_arr; cdip->name; ++cdip) {
if (cscd_desc_id == cdip->id)
return cdip->name;
}
return "";
}
/* VPD_3PARTY_COPY (3PC, THIRD PARTY COPY, SPC-4, SBC-3) 0x8f */
static void
decode_3party_copy_vpd(uint8_t * buff, int len, int do_hex, int pdt,
int verbose)
{
int j, k, m, bump, desc_type, desc_len, sa_len, blen;
unsigned int u;
const uint8_t * bp;
const char * cp;
uint64_t ull;
char b[120];
if (len < 4) {
pr2serr("Third-party Copy VPD page length too short=%d\n", len);
return;
}
blen = sizeof(b);
len -= 4;
bp = buff + 4;
for (k = 0; k < len; k += bump, bp += bump) {
desc_type = sg_get_unaligned_be16(bp);
desc_len = sg_get_unaligned_be16(bp + 2);
if (verbose)
printf("Descriptor type=%d, len %d\n", desc_type, desc_len);
bump = 4 + desc_len;
if ((k + bump) > len) {
pr2serr("Third-party Copy VPD page, short descriptor length=%d, "
"left=%d\n", bump, (len - k));
return;
}
if (0 == desc_len)
continue;
if (2 == do_hex)
hex2stdout(bp + 4, desc_len, 1);
else if (do_hex > 2)
hex2stdout(bp, bump, 1);
else {
int csll;
switch (desc_type) {
case 0x0000: /* Required if POPULATE TOKEN (or friend) used */
printf(" Block Device ROD Token Limits:\n");
u = sg_get_unaligned_be16(bp + 10);
printf(" Maximum range descriptors: ");
if (0 == u)
printf("0 [not reported]\n");
else
printf("%u\n", u);
u = sg_get_unaligned_be32(bp + 12);
printf(" Maximum inactivity timeout: ");
if (0 == u)
printf("0 [not reported]\n");
else if (SG_LIB_UNBOUNDED_32BIT == u)
printf("-1 [no maximum given]\n");
else
printf("%u seconds\n", u);
u = sg_get_unaligned_be32(bp + 16);
printf(" Default inactivity timeout: ");
if (0 == u)
printf("0 [not reported]\n");
else
printf("%u seconds\n", u);
ull = sg_get_unaligned_be64(bp + 20);
printf(" Maximum token transfer size: ");
if (0 == ull)
printf("0 [not reported]\n");
else
printf("%" PRIu64 "\n", ull);
ull = sg_get_unaligned_be64(bp + 28);
printf(" Optimal transfer count: ");
if (0 == ull)
printf("0 [not reported]\n");
else
printf("%" PRIu64 "\n", ull);
break;
case 0x0001: /* Mandatory (SPC-4) */
printf(" Supported Commands:\n");
j = 0;
csll = bp[4];
if (csll >= desc_len) {
pr2serr("Command supported list length (%d) >= "
"descriptor length (%d), wrong so trim\n",
csll, desc_len);
csll = desc_len - 1;
}
while (j < csll) {
sa_len = bp[6 + j];
for (m = 0; (m < sa_len) && ((j + m) < csll); ++m) {
sg_get_opcode_sa_name(bp[5 + j], bp[7 + j + m],
pdt, blen, b);
printf(" %s\n", b);
}
if (0 == sa_len) {
sg_get_opcode_name(bp[5 + j], pdt, blen, b);
printf(" %s\n", b);
} else if (m < sa_len)
pr2serr("Supported service actions list length (%d) "
"is too large\n", sa_len);
j += m + 2;
}
break;
case 0x0004:
printf(" Parameter data:\n");
printf(" Maximum CSCD descriptor count: %d\n",
sg_get_unaligned_be16(bp + 8));
printf(" Maximum segment descriptor count: %d\n",
sg_get_unaligned_be16(bp + 10));;
u = sg_get_unaligned_be32(bp + 12);
printf(" Maximum descriptor list length: %u\n", u);
u = sg_get_unaligned_be32(bp + 16);
printf(" Maximum inline data length: %u\n", u);
break;
case 0x0008:
printf(" Supported descriptors:\n");
for (j = 0; j < bp[4]; j++) {
cp = get_tpc_desc_name(bp[5 + j]);
if (strlen(cp) > 0)
printf(" %s [0x%x]\n", cp, bp[5 + j]);
else
printf(" 0x%x\n", bp[5 + j]);
}
break;
case 0x000C:
printf(" Supported CSCD IDs (above 0x7ff):\n");
for (j = 0; j < sg_get_unaligned_be16(bp + 4); j += 2) {
u = sg_get_unaligned_be16(bp + 6 + j);
cp = get_cscd_desc_id_name(u);
if (strlen(cp) > 0)
printf(" %s [0x%04x]\n", cp, u);
else
printf(" 0x%04x\n", u);
}
break;
case 0x000D:
printf(" Copy group identifier:\n");
u = bp[4];
sg_t10_uuid_desig2str(bp + 5, u, 1 /* c_set */, false,
false, NULL, blen, b);
printf("%s", b);
break;
case 0x0106:
printf(" ROD token features:\n");
printf(" Remote tokens: %d\n", bp[4] & 0x0f);
u = sg_get_unaligned_be32(bp + 16);
printf(" Minimum token lifetime: %u seconds\n", u);
u = sg_get_unaligned_be32(bp + 20);
printf(" Maximum token lifetime: %u seconds\n", u);
u = sg_get_unaligned_be32(bp + 24);
printf(" Maximum token inactivity timeout: %u\n", u);
decode_rod_descriptor(bp + 48,
sg_get_unaligned_be16(bp + 46));
break;
case 0x0108:
printf(" Supported ROD token and ROD types:\n");
for (j = 0; j < sg_get_unaligned_be16(bp + 6); j+= 64) {
u = sg_get_unaligned_be32(bp + 8 + j);
cp = get_tpc_rod_name(u);
if (strlen(cp) > 0)
printf(" ROD type: %s [0x%x]\n", cp, u);
else
printf(" ROD type: 0x%x\n", u);
printf(" Internal: %s\n",
(bp[8 + j + 4] & 0x80) ? "yes" : "no");
printf(" Token in: %s\n",
(bp[8 + j + 4] & 0x02) ? "yes" : "no");
printf(" Token out: %s\n",
(bp[8 + j + 4] & 0x01) ? "yes" : "no");
printf(" preference: %d\n",
sg_get_unaligned_be16(bp + 8 + j + 6));
}
break;
case 0x8001: /* Mandatory (SPC-4) */
printf(" General copy operations:\n");
u = sg_get_unaligned_be32(bp + 4);
printf(" Total concurrent copies: %u\n", u);
u = sg_get_unaligned_be32(bp + 8);
printf(" Maximum identified concurrent copies: %u\n", u);
u = sg_get_unaligned_be32(bp + 12);
printf(" Maximum segment length: %u\n", u);
ull = (1 << bp[16]); /* field is power of 2 */
printf(" Data segment granularity: %" PRIu64 "\n", ull);
ull = (1 << bp[17]);
printf(" Inline data granularity: %" PRIu64 "\n", ull);
break;
case 0x9101:
printf(" Stream copy operations:\n");
u = sg_get_unaligned_be32(bp + 4);
printf(" Maximum stream device transfer size: %u\n", u);
break;
case 0xC001:
printf(" Held data:\n");
u = sg_get_unaligned_be32(bp + 4);
printf(" Held data limit: %u\n", u);
ull = (1 << bp[8]);
printf(" Held data granularity: %" PRIu64 "\n", ull);
break;
default:
pr2serr("Unexpected type=%d\n", desc_type);
hex2stderr(bp, bump, 1);
break;
}
}
}
}
/* VPD_PROTO_LU 0x90 */
static int
decode_proto_lu_vpd(uint8_t * buff, int len)
{
int k, bump, rel_port, desc_len, proto;
uint8_t * bp;
if (len < 4) {
pr2serr("Protocol-specific logical unit information VPD page length "
"too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
len -= 4;
bp = buff + 4;
for (k = 0; k < len; k += bump, bp += bump) {
rel_port = sg_get_unaligned_be16(bp);
printf("Relative port=%d\n", rel_port);
proto = bp[2] & 0xf;
desc_len = sg_get_unaligned_be16(bp + 6);
bump = 8 + desc_len;
if ((k + bump) > len) {
pr2serr("Protocol-specific logical unit information VPD page, "
"short descriptor length=%d, left=%d\n", bump, (len - k));
return SG_LIB_CAT_MALFORMED;
}
if (desc_len > 0) {
switch (proto) {
case TPROTO_SAS:
printf(" Protocol identifier: SAS\n");
printf(" TLR control supported: %d\n", !!(bp[8] & 0x1));
break;
default:
pr2serr("Unexpected proto=%d\n", proto);
hex2stderr(bp, bump, 1);
break;
}
}
}
return 0;
}
/* VPD_PROTO_PORT 0x91 */
static int
decode_proto_port_vpd(uint8_t * buff, int len)
{
int k, j, bump, rel_port, desc_len, proto;
uint8_t * bp;
uint8_t * pidp;
if (len < 4) {
pr2serr("Protocol-specific port information VPD page length too "
"short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
len -= 4;
bp = buff + 4;
for (k = 0; k < len; k += bump, bp += bump) {
rel_port = sg_get_unaligned_be16(bp);
printf("Relative port=%d\n", rel_port);
proto = bp[2] & 0xf;
desc_len = sg_get_unaligned_be16(bp + 6);
bump = 8 + desc_len;
if ((k + bump) > len) {
pr2serr("Protocol-specific port information VPD page, short "
"descriptor length=%d, left=%d\n", bump, (len - k));
return SG_LIB_CAT_MALFORMED;
}
if (desc_len > 0) {
switch (proto) {
case TPROTO_SAS: /* page added in spl3r02 */
printf(" power disable supported (pwr_d_s)=%d\n",
!!(bp[3] & 0x1)); /* added spl3r03 */
pidp = bp + 8;
for (j = 0; j < desc_len; j += 4, pidp += 4)
printf(" phy id=%d, SSP persistent capable=%d\n",
pidp[1], (0x1 & pidp[2]));
break;
default:
pr2serr("Unexpected proto=%d\n", proto);
hex2stderr(bp, bump, 1);
break;
}
}
}
return 0;
}
/* VPD_SCSI_FEATURE_SETS [0x92] (sfs) */
static int
decode_feature_sets_vpd(uint8_t * buff, int len,
const struct sdparm_opt_coll * op)
{
int k, bump;
uint16_t sf_code;
bool found;
uint8_t * bp;
char b[64];
if (len < 4) {
pr2serr("SCSI Feature sets VPD page length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
len -= 8;
bp = buff + 8;
for (k = 0; k < len; k += bump, bp += bump) {
sf_code = sg_get_unaligned_be16(bp);
bump = 2;
if ((k + bump) > len) {
pr2serr("SCSI Feature sets, short descriptor length=%d, "
"left=%d\n", bump, (len - k));
return SG_LIB_CAT_MALFORMED;
}
printf(" %s", sg_get_sfs_str(sf_code, -2, sizeof(b), b,
&found, op->verbose));
if (op->verbose == 1)
printf(" [0x%x]\n", (unsigned int)sf_code);
else if (op->verbose > 1)
printf(" [0x%x] found=%s\n", (unsigned int)sf_code,
found ? "true" : "false");
else
printf("\n");
}
return 0;
}
/* VPD_SCSI_PORTS 0x88 */
static int
decode_scsi_ports_vpd(uint8_t * buff, int len,
const struct sdparm_opt_coll * op)
{
int k, bump, rel_port, ip_tid_len, tpd_len, res;
uint8_t * bp;
if (len < 4) {
pr2serr("SCSI Ports VPD page length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
len -= 4;
bp = buff + 4;
for (k = 0; k < len; k += bump, bp += bump) {
rel_port = sg_get_unaligned_be16(bp + 2);
printf(" Relative port=%d\n", rel_port);
ip_tid_len = sg_get_unaligned_be16(bp + 6);
bump = 8 + ip_tid_len;
if ((k + bump) > len) {
pr2serr("SCSI Ports VPD page, short descriptor length=%d, "
"left=%d\n", bump, (len - k));
return SG_LIB_CAT_MALFORMED;
}
if (ip_tid_len > 0) {
char b[1024];
printf("%s", sg_decode_transportid_str(" ", bp + 8,
ip_tid_len, true, sizeof(b), b));
}
tpd_len = sg_get_unaligned_be16(bp + bump + 2);
if ((k + bump + tpd_len + 4) > len) {
pr2serr("SCSI Ports VPD page, short descriptor(tgt) length=%d, "
"left=%d\n", bump, (len - k));
return SG_LIB_CAT_MALFORMED;
}
if (tpd_len > 0) {
printf(" Target port descriptor(s):\n");
res = decode_dev_ids("", 2, bp + bump + 4, tpd_len,
VPD_ASSOC_TPORT, -1, -1, op);
if (res)
return res;
}
bump += tpd_len + 4;
}
return 0;
}
/* VPD_EXT_INQ Extended Inquiry page 0x86 */
static int
decode_ext_inq_vpd(uint8_t * b, int len, int do_long, bool protect)
{
int n;
if (len < 7) {
pr2serr("Extended INQUIRY data VPD page length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
if (do_long) {
n = (b[4] >> 6) & 0x3;
printf(" ACTIVATE_MICROCODE=%d", n);
if (1 == n)
printf(" [before final WRITE BUFFER]\n");
else if (2 == n)
printf(" [after power on or hard reset]\n");
else
printf("\n");
n = (b[4] >> 3) & 0x7;
printf(" SPT=%d", n);
if (protect) {
switch (n)
{
case 0:
printf(" [protection type 1 supported]\n");
break;
case 1:
printf(" [protection types 1 and 2 supported]\n");
break;
case 2:
printf(" [protection type 2 supported]\n");
break;
case 3:
printf(" [protection types 1 and 3 supported]\n");
break;
case 4:
printf(" [protection type 3 supported]\n");
break;
case 5:
printf(" [protection types 2 and 3 supported]\n");
break;
case 6:
printf(" [see Supported block lengths and protection types "
"VPD page]\n");
break;
case 7:
printf(" [protection types 1, 2 and 3 supported]\n");
break;
default:
printf("\n");
break;
}
} else
printf("\n");
printf(" GRD_CHK=%d\n", !!(b[4] & 0x4));
printf(" APP_CHK=%d\n", !!(b[4] & 0x2));
printf(" REF_CHK=%d\n", !!(b[4] & 0x1));
printf(" UASK_SUP=%d\n", !!(b[5] & 0x20));
printf(" GROUP_SUP=%d\n", !!(b[5] & 0x10));
printf(" PRIOR_SUP=%d\n", !!(b[5] & 0x8));
printf(" HEADSUP=%d\n", !!(b[5] & 0x4));
printf(" ORDSUP=%d\n", !!(b[5] & 0x2));
printf(" SIMPSUP=%d\n", !!(b[5] & 0x1));
printf(" WU_SUP=%d\n", !!(b[6] & 0x8));
printf(" CRD_SUP=%d\n", !!(b[6] & 0x4));
printf(" NV_SUP=%d\n", !!(b[6] & 0x2));
printf(" V_SUP=%d\n", !!(b[6] & 0x1));
printf(" NO_PI_CHK=%d\n", !!(b[7] & 0x20)); /* spc5r02 */
printf(" P_I_I_SUP=%d\n", !!(b[7] & 0x10));
printf(" LUICLR=%d\n", !!(b[7] & 0x1));
printf(" LU_COLL_TYPE=%d\n", (b[8] >> 5) & 0x7); /* spc5r09 */
printf(" R_SUP=%d\n", !!(b[8] & 0x10));
printf(" HSSRELEF=%d\n", !!(b[8] & 0x2)); /* spc5r02 */
printf(" CBCS=%d\n", !!(b[8] & 0x1)); /* obsolete in spc5r01 */
printf(" Multi I_T nexus microcode download=%d\n", b[9] & 0xf);
printf(" Extended self-test completion minutes=%d\n",
sg_get_unaligned_be16(b + 10));
printf(" POA_SUP=%d\n", !!(b[12] & 0x80)); /* spc4r32 */
printf(" HRA_SUP=%d\n", !!(b[12] & 0x40)); /* spc4r32 */
printf(" VSA_SUP=%d\n", !!(b[12] & 0x20)); /* spc4r32 */
printf(" DMS_VALID=%d\n", !!(b[12] & 0x10)); /* spc5r20 */
printf(" Maximum supported sense data length=%d\n",
b[13]); /* spc4r34 */
printf(" IBS=%d\n", !!(b[14] & 0x80)); /* spc5r09 */
printf(" IAS=%d\n", !!(b[14] & 0x40)); /* spc5r09 */
printf(" SAC=%d\n", !!(b[14] & 0x4)); /* spc5r09 */
printf(" NRD1=%d\n", !!(b[14] & 0x2)); /* spc5r09 */
printf(" NRD0=%d\n", !!(b[14] & 0x1)); /* spc5r09 */
printf(" Maximum inquiry change logs=%u\n",
sg_get_unaligned_be16(b + 15)); /* spc5r17 */
printf(" Maximum mode page change logs=%u\n",
sg_get_unaligned_be16(b + 17)); /* spc5r17 */
printf(" DM_MD_4=%d\n", !!(b[19] & 0x80)); /* spc5r20 */
printf(" DM_MD_5=%d\n", !!(b[19] & 0x40)); /* spc5r20 */
printf(" DM_MD_6=%d\n", !!(b[19] & 0x20)); /* spc5r20 */
printf(" DM_MD_7=%d\n", !!(b[19] & 0x10)); /* spc5r20 */
printf(" DM_MD_D=%d\n", !!(b[19] & 0x8)); /* spc5r20 */
printf(" DM_MD_E=%d\n", !!(b[19] & 0x4)); /* spc5r20 */
printf(" DM_MD_F=%d\n", !!(b[19] & 0x2)); /* spc5r20 */
} else {
printf(" ACTIVATE_MICROCODE=%d SPT=%d GRD_CHK=%d APP_CHK=%d "
"REF_CHK=%d\n", ((b[4] >> 6) & 0x3), ((b[4] >> 3) & 0x7),
!!(b[4] & 0x4), !!(b[4] & 0x2), !!(b[4] & 0x1));
printf(" UASK_SUP=%d GROUP_SUP=%d PRIOR_SUP=%d HEADSUP=%d ORDSUP=%d "
"SIMPSUP=%d\n", !!(b[5] & 0x20), !!(b[5] & 0x10),
!!(b[5] & 0x8), !!(b[5] & 0x4), !!(b[5] & 0x2),
!!(b[5] & 0x1));
/* CRD_SUP made obsolete in spc5r04 */
printf(" WU_SUP=%d [CRD_SUP=%d] NV_SUP=%d V_SUP=%d\n",
!!(b[6] & 0x8), !!(b[6] & 0x4),
!!(b[6] & 0x2), !!(b[6] & 0x1));
printf(" NO_PI_CHK=%d P_I_I_SUP=%d LUICLR=%d\n", !!(b[7] & 0x20),
!!(b[7] & 0x10), !!(b[7] & 0x1));
/* LU_COLL_TYPE in spc5r09, CBCS obsolete in spc5r01 */
printf(" LU_COLL_TYPE=%d R_SUP=%d HSSRELEF=%d [CBCS=%d]\n",
(b[8] >> 5) & 0x7, !!(b[8] & 0x10), !!(b[8] & 0x2),
!!(b[8] & 0x1));
printf(" Multi I_T nexus microcode download=%d\n", b[9] & 0xf);
printf(" Extended self-test completion minutes=%d\n",
sg_get_unaligned_be16(b + 10));
printf(" POA_SUP=%d HRA_SUP=%d VSA_SUP=%d DMS_VALID=%d\n",
!!(b[12] & 0x80), !!(b[12] & 0x40), !!(b[12] & 0x20),
!!(b[12] & 0x10)); /* spc5r20 */
printf(" Maximum supported sense data length=%d\n",
b[13]); /* spc4r34 */
printf(" IBS=%d IAS=%d SAC=%d NRD1=%d NRD0=%d\n", !!(b[14] & 0x80),
!!(b[14] & 0x40), !!(b[14] & 0x4), !!(b[14] & 0x2),
!!(b[14] & 0x1)); /* added in spc5r09 */
printf(" Maximum inquiry change logs=%u\n",
sg_get_unaligned_be16(b + 15)); /* spc5r17 */
printf(" Maximum mode page change logs=%u\n",
sg_get_unaligned_be16(b + 17)); /* spc5r17 */
printf(" DM_MD_4=%d DM_MD_5=%d DM_MD_6=%d DM_MD_7=%d\n",
!!(b[19] & 0x80), !!(b[19] & 0x40), !!(b[19] & 0x20),
!!(b[19] & 0x10)); /* spc5r20 */
printf(" DM_MD_D=%d DM_MD_E=%d DM_MD_F=%d\n",
!!(b[19] & 0x8), !!(b[19] & 0x4), !!(b[19] & 0x2));
}
return 0;
}
/* VPD_ATA_INFO 0x89 */
static int
decode_ata_info_vpd(uint8_t * buff, int len, int do_long, int do_hex)
{
char b[80];
int num, is_be, cc;
const char * cp;
const char * ata_transp;
if (len < 36) {
pr2serr("ATA information VPD page length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
memcpy(b, buff + 8, 8);
b[8] = '\0';
printf(" SAT Vendor identification: %s\n", b);
memcpy(b, buff + 16, 16);
b[16] = '\0';
printf(" SAT Product identification: %s\n", b);
memcpy(b, buff + 32, 4);
b[4] = '\0';
printf(" SAT Product revision level: %s\n", b);
if (len < 56)
return SG_LIB_CAT_MALFORMED;
ata_transp = (0x34 == buff[36]) ? "SATA" : "PATA";
if (do_long) {
printf(" Device signature [%s] (in hex):\n", ata_transp);
hex2stdout(buff + 36, 20, 1);
} else
printf(" Device signature indicates %s transport\n", ata_transp);
cc = buff[56]; /* 0xec for IDENTIFY DEVICE and 0xa1 for IDENTIFY
* PACKET DEVICE (obsolete) */
printf(" Command code: 0x%x\n", cc);
if (len < 60)
return SG_LIB_CAT_MALFORMED;
if (0xec == cc)
cp = "";
else if (0xa1 == cc)
cp = "PACKET ";
else
cp = NULL;
is_be = sg_is_big_endian();
if (cp) {
printf(" ATA command IDENTIFY %sDEVICE response summary:\n", cp);
num = sg_ata_get_chars((const unsigned short *)(buff + 60), 27, 20,
is_be, b);
b[num] = '\0';
printf(" model: %s\n", b);
num = sg_ata_get_chars((const unsigned short *)(buff + 60), 10, 10,
is_be, b);
b[num] = '\0';
printf(" serial number: %s\n", b);
num = sg_ata_get_chars((const unsigned short *)(buff + 60), 23, 4,
is_be, b);
b[num] = '\0';
printf(" firmware revision: %s\n", b);
if (do_long)
printf(" ATA command IDENTIFY %sDEVICE response in hex:\n", cp);
} else if (do_long)
printf(" ATA command 0x%x got following response:\n",
(unsigned int)buff[56]);
if (len < 572)
return SG_LIB_CAT_MALFORMED;
if (do_hex)
hex2stdout(buff + 60, 512, 0);
else if (do_long)
dWordHex((const unsigned short *)(buff + 60), 256, 0, is_be);
return 0;
}
/* VPD_POWER_CONDITION 0x8a */
static int
decode_power_condition(uint8_t * buff, int len)
{
if (len < 18) {
pr2serr("Power condition VPD page length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
printf(" Standby_y=%d Standby_z=%d Idle_c=%d Idle_b=%d Idle_a=%d\n",
!!(buff[4] & 0x2), !!(buff[4] & 0x1),
!!(buff[5] & 0x4), !!(buff[5] & 0x2), !!(buff[5] & 0x1));
printf(" Stopped condition recovery time (ms) %d\n",
sg_get_unaligned_be16(buff + 6));
printf(" Standby_z condition recovery time (ms) %d\n",
sg_get_unaligned_be16(buff + 8));
printf(" Standby_y condition recovery time (ms) %d\n",
sg_get_unaligned_be16(buff + 10));
printf(" Idle_a condition recovery time (ms) %d\n",
sg_get_unaligned_be16(buff + 12));
printf(" Idle_b condition recovery time (ms) %d\n",
sg_get_unaligned_be16(buff + 14));
printf(" Idle_c condition recovery time (ms) %d\n",
sg_get_unaligned_be16(buff + 16));
return 0;
}
static const char * power_unit_arr[] =
{
"Gigawatts",
"Megawatts",
"Kilowatts",
"Watts",
"Milliwatts",
"Microwatts",
"Unit reserved",
"Unit reserved",
};
/* VPD_POWER_CONSUMPTION 0x8d */
static int
decode_power_consumption_vpd(uint8_t * buff, int len)
{
int k, bump;
uint8_t * bp;
unsigned int value;
if (len < 4) {
pr2serr("Power consumption VPD page length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
len -= 4;
bp = buff + 4;
for (k = 0; k < len; k += bump, bp += bump) {
bump = 4;
if ((k + bump) > len) {
pr2serr("Power consumption VPD page, short descriptor length=%d, "
"left=%d\n", bump, (len - k));
return SG_LIB_CAT_MALFORMED;
}
value = sg_get_unaligned_be16(bp + 2);
printf(" Power consumption identifier: 0x%x", bp[0]);
if (value >= 1000 && (bp[1] & 0x7) > 0)
printf(" Maximum power consumption: %d.%03d %s\n",
value / 1000, value % 1000,
power_unit_arr[(bp[1] & 0x7) - 1]);
else
printf(" Maximum power consumption: %d %s\n",
value, power_unit_arr[bp[1] & 0x7]);
}
return 0;
}
/* VPD_BLOCK_LIMITS 0xb0 */
static int
decode_block_limits_vpd(uint8_t * buff, int len)
{
bool ugavalid;
unsigned int u;
uint64_t ull;
if (len < 16) {
pr2serr("Block limits VPD page length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
printf(" Write same non-zero (WSNZ): %d\n", !!(buff[4] & 0x1));
u = buff[5];
printf(" Maximum compare and write length: ");
if (0 == u)
printf("0 blocks [Command not implemented]\n");
else
printf("%u blocks\n", buff[5]);
u = sg_get_unaligned_be16(buff + 6);
printf(" Optimal transfer length granularity: ");
if (0 == u)
printf("0 blocks [not reported]\n");
else
printf("%u blocks\n", u);
u = sg_get_unaligned_be32(buff + 8);
printf(" Maximum transfer length: ");
if (0 == u)
printf("0 blocks [not reported]\n");
else
printf("%u blocks\n", u);
u = sg_get_unaligned_be32(buff + 12);
printf(" Optimal transfer length: ");
if (0 == u)
printf("0 blocks [not reported]\n");
else
printf("%u blocks\n", u);
if (len > 19) { /* added in sbc3r09 */
u = sg_get_unaligned_be32(buff + 16);
printf(" Maximum prefetch transfer length: ");
if (0 == u)
printf("0 blocks [ignored]\n");
else
printf("%u blocks\n", u);
}
if (len > 27) { /* added in sbc3r18 */
u = sg_get_unaligned_be32(buff + 20);
printf(" Maximum unmap LBA count: ");
if (0 == u)
printf("0 [Unmap command not implemented]\n");
else if (SG_LIB_UNBOUNDED_32BIT == u)
printf("-1 [unbounded]\n");
else
printf("%u\n", u);
u = sg_get_unaligned_be32(buff + 24);
printf(" Maximum unmap block descriptor count: ");
if (0 == u)
printf("0 [Unmap command not implemented]\n");
else if (SG_LIB_UNBOUNDED_32BIT == u)
printf("-1 [unbounded]\n");
else
printf("%u\n", u);
}
if (len > 35) { /* added in sbc3r19 */
u = sg_get_unaligned_be32(buff + 28);
printf(" Optimal unmap granularity: ");
if (0 == u)
printf("0 blocks [not reported]\n");
else
printf("%u blocks\n", u);
ugavalid = !!(buff[32] & 0x80);
printf(" Unmap granularity alignment valid: %s\n",
ugavalid ? "true" : "false");
u = 0x7fffffff & sg_get_unaligned_be32(buff + 32);
printf(" Unmap granularity alignment: %u%s\n", u,
ugavalid ? "" : " [invalid]");
}
if (len > 43) { /* added in sbc3r26 */
ull = sg_get_unaligned_be64(buff + 36);
printf(" Maximum write same length: ");
if (0 == ull)
printf("0 blocks [not reported]\n");
else
printf("0x%" PRIx64 " blocks\n", ull);
}
if (len > 44) { /* added in sbc4r02 */
u = sg_get_unaligned_be32(buff + 44);
printf(" Maximum atomic transfer length: ");
if (0 == u)
printf("0 blocks [not reported]\n");
else
printf("%u blocks\n", u);
u = sg_get_unaligned_be32(buff + 48);
printf(" Atomic alignment: ");
if (0 == u)
printf("0 [unaligned atomic writes permitted]\n");
else
printf("%u\n", u);
u = sg_get_unaligned_be32(buff + 52);
printf(" Atomic transfer length granularity: ");
if (0 == u)
printf("0 [no granularity requirement\n");
else
printf("%u\n", u);
}
if (len > 56) {
u = sg_get_unaligned_be32(buff + 56);
printf(" Maximum atomic transfer length with atomic "
"boundary: ");
if (0 == u)
printf("0 blocks [not reported]\n");
else
printf("%u blocks\n", u);
u = sg_get_unaligned_be32(buff + 60);
printf(" Maximum atomic boundary size: ");
if (0 == u)
printf("0 blocks [can only write atomic 1 block]\n");
else
printf("%u blocks\n", u);
}
return 0;
}
/* VPD_BLOCK_LIMITS_EXT 0xb7 */
static int
decode_block_limits_ext_vpd(uint8_t * buff, int len)
{
unsigned int u;
if (len < 12) {
pr2serr("Block limits extension VPD page length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
u = sg_get_unaligned_be16(buff + 6);
printf(" Maximum number of streams: ");
if (0 == u)
printf("0 [Stream control not supported]\n");
else
printf("%u\n", u);
u = sg_get_unaligned_be16(buff + 8);
printf(" Optimal stream write size: %u blocks\n", u);
u = sg_get_unaligned_be32(buff + 10);
printf(" Stream granularity size: %u\n", u);
if (len > 27) {
u = sg_get_unaligned_be32(buff + 16);
printf(" Maximum scattered LBA range transfer length: ");
if (0 == u)
printf("0 blocks [not reported]\n");
else
printf("%u blocks\n", u);
u = sg_get_unaligned_be16(buff + 22);
printf(" Maximum scattered LBA range descriptor count: ");
if (0 == u)
printf("0 [not reported]\n");
else
printf("%u\n", u);
u = sg_get_unaligned_be32(buff + 24);
printf(" Maximum scattered transfer length: ");
if (0 == u)
printf("0 blocks [not reported]\n");
else
printf("%u blocks\n", u);
}
return 0;
}
static const char * product_type_arr[] =
{
"Not specified",
"CFast",
"CompactFlash",
"MemoryStick",
"MultiMediaCard",
"Secure Digital Card (SD)",
"XQD",
"Universal Flash Storage Card (UFS)",
};
static const char * zoned_strs[] = {
"",
" [host-aware]",
" [host-managed]",
"",
};
/* VPD_BLOCK_DEV_CHARS 0xb1 */
static int
decode_block_dev_chars_vpd(uint8_t * buff, int len)
{
int zoned;
unsigned int u, k;
if (len < 64) {
pr2serr("Block device characteristics VPD page length too short=%d\n",
len);
return SG_LIB_CAT_MALFORMED;
}
u = sg_get_unaligned_be16(buff + 4);
if (0 == u)
printf(" Medium rotation rate is not reported\n");
else if (1 == u)
printf(" Non-rotating medium (e.g. solid state)\n");
else if ((u < 0x401) || (0xffff == u))
printf(" Reserved [0x%x]\n", u);
else
printf(" Nominal rotation rate: %d rpm\n", u);
u = buff[6];
printf(" Product type: ");
k = SG_ARRAY_SIZE(product_type_arr);
if (u < k)
printf("%s\n", product_type_arr[u]);
else if (u < 0xf0)
printf("Reserved [0x%x]\n", u);
else
printf("Vendor specific [0x%x]\n", u);
u = buff[7] & 0xf;
printf(" WABEREQ=%d\n", (buff[7] >> 6) & 0x3);
printf(" WACEREQ=%d\n", (buff[7] >> 4) & 0x3);
printf(" Nominal form factor");
switch (u) {
case 0:
printf(" not reported\n");
break;
case 1:
printf(": 5.25 inch\n");
break;
case 2:
printf(": 3.5 inch\n");
break;
case 3:
printf(": 2.5 inch\n");
break;
case 4:
printf(": 1.8 inch\n");
break;
case 5:
printf(": less then 1.8 inch\n");
break;
default:
printf(": reserved\n");
break;
}
zoned = (buff[8] >> 4) & 0x3; /* added sbc4r04 */
printf(" ZONED=%d%s\n", zoned, zoned_strs[zoned]);
printf(" BOCS=%d\n", !!(buff[8] & 0x4));
printf(" FUAB=%d\n", !!(buff[8] & 0x2));
printf(" VBULS=%d\n", !!(buff[8] & 0x1));
printf(" DEPOPULATION_TIME=%u (seconds)\n",
sg_get_unaligned_be32(buff + 12)); /* added sbc4r14 */
return 0;
}
/* VPD_SA_DEV_CAP 0xb0 */
static int
decode_tape_dev_caps_vpd(uint8_t * buff, int len)
{
if (len < 6) {
pr2serr("Sequential access device capabilities VPD page length too "
"short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
printf(" Worm: %d\n", !!(buff[4] & 0x1));
return 0;
}
/* VPD_MAN_ASS_SN 0xb1 */
static int
decode_tape_man_ass_sn_vpd(uint8_t * buff, int len)
{
if (len < 4) {
pr2serr("Manufacturer-assigned serial number VPD page length too "
"short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
printf(" Manufacturer-assigned serial number: %.*s\n",
len - 4, buff + 4);
return 0;
}
static const char * prov_type_arr[8] = {
"not known or fully provisioned",
"resource provisioned",
"thin provisioned",
"reserved [0x3]",
"reserved [0x4]",
"reserved [0x5]",
"reserved [0x6]",
"reserved [0x7]",
};
/* VPD_LB_PROVISIONING 0xb2 */
static int
decode_block_lb_prov_vpd(uint8_t * b, int len,
const struct sdparm_opt_coll * op)
{
int dp, pt;
unsigned int u;
if (len < 4) {
pr2serr("Logical block provisioning page too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
pt = b[6] & 0x7;
printf(" Unmap command supported (LBPU): %d\n", !!(0x80 & b[5]));
printf(" Write same (16) with unmap bit supported (LBPWS): %d\n",
!!(0x40 & b[5]));
printf(" Write same (10) with unmap bit supported (LBPWS10): %d\n",
!!(0x20 & b[5]));
printf(" Logical block provisioning read zeros (LBPRZ): %d\n",
(0x7 & (b[5] >> 2))); /* expanded from 1 to 3 bits in sbc4r07 */
printf(" Anchored LBAs supported (ANC_SUP): %d\n", !!(0x2 & b[5]));
u = b[4];
printf(" Threshold exponent: ");
if (0 == u)
printf("0 [threshold sets not supported]\n");
else
printf("%u\n", u);
dp = !!(b[5] & 0x1);
printf(" Descriptor present: %d\n", dp);
printf(" Minimum percentage: ");
u = 0x1f & (b[6] >> 3);
if (0 == u)
printf("0 [not reported]\n");
else
printf("%d\n", u);
printf(" Provisioning type: %d (%s)\n", pt, prov_type_arr[pt]);
printf(" Threshold percentage: ");
if (0 == b[7])
printf("0 [percentages not supported]\n");
else
printf("%u\n", b[7]);
if (dp) {
const uint8_t * bp;
int i_len;
bp = b + 8;
i_len = bp[3];
if (0 == i_len) {
pr2serr("Logical block provisioning page provisioning group "
"descriptor too short=%d\n", i_len);
return 0;
}
printf(" Provisioning group descriptor\n");
decode_designation_descriptor(bp, i_len, true, op);
}
return 0;
}
/* VPD_TA_SUPPORTED 0xb2 */
static int
decode_tapealert_supported_vpd(uint8_t * b, int len)
{
int k, mod, div;
if (len < 12) {
pr2serr("TapeAlert supported flags length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
for (k = 1; k < 0x41; ++k) {
mod = ((k - 1) % 8);
div = (k - 1) / 8;
if (0 == mod) {
if (div > 0)
printf("\n");
printf(" Flag%02Xh: %d", k, !! (b[4 + div] & 0x80));
} else
printf(" %02Xh: %d", k, !! (b[4 + div] & (1 << (7 - mod))));
}
printf("\n");
return 0;
}
/* VPD_REFERRALS 0xb3 */
static int
decode_referrals_vpd(uint8_t * b, int len)
{
unsigned int u;
if (len < 16) {
pr2serr("Referrals VPD page length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
u = sg_get_unaligned_be32(b + 8);
printf(" User data segment size: ");
if (0 == u)
printf("0 [per sense descriptor]\n");
else
printf("%u\n", u);
u = sg_get_unaligned_be32(b + 12);
printf(" User data segment multiplier: %u\n", u);
return 0;
}
/* VPD_SUP_BLOCK_LENS 0xb4 [added sbc4r01] */
static int
decode_sup_block_lens_vpd(uint8_t * buff, int len)
{
int k;
unsigned int u;
uint8_t * bp;
if (len < 4) {
pr2serr("Supported block lengths and protection types VPD page "
"length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
len -= 4;
bp = buff + 4;
for (k = 0; k < len; k += 8, bp += 8) {
u = sg_get_unaligned_be32(bp + 0);
printf(" Logical block length: %u\n", u);
printf(" P_I_I_SUP: %d\n", !!(bp[4] & 0x40));
printf(" NO_PI_CHK: %d\n", !!(bp[4] & 0x8)); /* sbc4r05 */
printf(" GRD_CHK: %d\n", !!(bp[4] & 0x4));
printf(" APP_CHK: %d\n", !!(bp[4] & 0x2));
printf(" REF_CHK: %d\n", !!(bp[4] & 0x1));
printf(" T3PS: %d\n", !!(bp[5] & 0x8));
printf(" T2PS: %d\n", !!(bp[5] & 0x4));
printf(" T1PS: %d\n", !!(bp[5] & 0x2));
printf(" T0PS: %d\n", !!(bp[5] & 0x1));
}
return 0;
}
/* VPD_BLOCK_DEV_C_EXTENS 0xb5 [added sbc4r02] */
static int
decode_block_dev_char_ext_vpd(uint8_t * b, int len)
{
if (len < 16) {
pr2serr("Block device characteristics extension VPD page "
"length too short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
printf(" Utilization type: ");
switch (b[5]) {
case 1:
printf("Combined writes and reads");
break;
case 2:
printf("Writes only");
break;
case 3:
printf("Separate writes and reads");
break;
default:
printf("Reserved");
break;
}
printf(" [0x%x]\n", b[5]);
printf(" Utilization units: ");
switch (b[6]) {
case 2:
printf("megabytes");
break;
case 3:
printf("gigabytes");
break;
case 4:
printf("terabytes");
break;
case 5:
printf("petabytes");
break;
case 6:
printf("exabytes");
break;
default:
printf("Reserved");
break;
}
printf(" [0x%x]\n", b[6]);
printf(" Utilization interval: ");
switch (b[7]) {
case 0xa:
printf("per day");
break;
case 0xe:
printf("per year");
break;
default:
printf("Reserved");
break;
}
printf(" [0x%x]\n", b[7]);
printf(" Utilization B: %" PRIu32 "\n", sg_get_unaligned_be32(b + 8));
printf(" Utilization A: %" PRIu32 "\n", sg_get_unaligned_be32(b + 12));
return 0;
}
/* VPD_LB_PROTECTION_ADDR 0xb5 [added ssc5r02a] */
static int
decode_lb_protection_vpd(uint8_t * buff, int len)
{
int k, bump;
uint8_t * bp;
if (len < 8) {
pr2serr("Logical block protection VPD page length too short=%d\n",
len);
return SG_LIB_CAT_MALFORMED;
}
len -= 8;
bp = buff + 8;
for (k = 0; k < len; k += bump, bp += bump) {
bump = 1 + bp[0];
printf(" method: %d, info_len: %d, LBP_W_C=%d, LBP_R_C=%d, "
"RBDP_C=%d\n", bp[1], 0x3f & bp[2], !!(0x80 & bp[3]),
!!(0x40 & bp[3]), !!(0x20 & bp[3]));
if ((k + bump) > len) {
pr2serr("Logical block protection VPD page, short descriptor "
"length=%d, left=%d\n", bump, (len - k));
return SG_LIB_CAT_MALFORMED;
}
}
return 0;
}
/* VPD_FORMAT_PRESETS 0xb8 (added sbc4r18) */
static int
decode_format_presets_vpd(uint8_t * buff, int len)
{
int k;
unsigned int sch_type;
uint8_t * bp;
len -= 4;
bp = buff + 4;
for (k = 0; k < len; k += 64, bp += 64) {
printf(" Preset identifier: 0x%x\n", sg_get_unaligned_be32(bp));
sch_type = bp[4];
printf(" schema type: %u\n", sch_type);
printf(" logical blocks per physical block exponent type: %u\n",
0xf & bp[7]);
printf(" logical block length: %u\n",
sg_get_unaligned_be32(bp + 8));
printf(" designed last LBA: 0x%" PRIx64 "\n",
sg_get_unaligned_be64(bp + 16));
printf(" FMPT_INFO: %u\n", (bp[38] >> 6) & 0x3);
printf(" protection field usage: %u\n", bp[38] & 0x7);
printf(" protection interval exponent: %u\n", bp[39] & 0xf);
if (2 == sch_type)
printf(" Defines zones for host aware device:\n");
else if (3 == sch_type)
printf(" Defines zones for host managed device:\n");
if ((2 == sch_type) || (3 == sch_type)) {
unsigned int u = bp[40 + 0];
printf(" low LBA conventional zones percentage: "
"%u.%u %%\n", u / 10, u % 10);
u = bp[40 + 1];
printf(" high LBA conventional zones percentage: "
"%u.%u %%\n", u / 10, u % 10);
printf(" logical blocks per zone: %u\n",
sg_get_unaligned_be32(bp + 40 + 12));
}
}
return 0;
}
/* VPD_CON_POS_RANGE 0xb9 (added 20-089r2) */
static int
decode_con_pos_range_vpd(uint8_t * buff, int len)
{
int k;
uint64_t u;
uint8_t * bp;
if (len < 64) {
pr2serr("Concurrent position ranges VPD page length too short=%d\n",
len);
return SG_LIB_CAT_MALFORMED;
}
len -= 64;
bp = buff + 64;
for (k = 0; k < len; k += 32, bp += 32) {
printf(" LBA range number: %u\n", bp[0]);
printf(" number of storage elements: %u\n", bp[1]);
printf(" starting LBA: 0x%" PRIx64 "\n",
sg_get_unaligned_be64(bp + 8));
u = sg_get_unaligned_be64(bp + 16);
printf(" number of LBAs: 0x%" PRIx64 " [%" PRIu64 "]\n", u, u);
}
return 0;
}
/* VPD_ZBC_DEV_CHARS sbc or zbc */
static int
decode_zbdc_vpd(uint8_t * b, int len)
{
uint32_t u;
if (len < 64) {
pr2serr("Zoned block device characteristics VPD page length too "
"short=%d\n", len);
return SG_LIB_CAT_MALFORMED;
}
printf(" Zoned block device extension: ");
switch ((b[4] >> 4) & 0xf) {
case 0:
printf("not reported\n");
break;
case 1:
printf("host aware zone block device model\n");
break;
case 2:
printf("Domains and realms zone block device model\n");
break;
default:
printf("Unknown [0x%x]\n", (b[4] >> 4) & 0xf);
break;
}
printf(" AAORB: %d\n", !!(b[4] & 0x2));
/* URSWRZ: unrestricted read in sequential write required zone */
printf(" URSWRZ type: %d\n", !!(b[4] & 0x1));
u = sg_get_unaligned_be32(b + 8);
printf(" Optimal number of open sequential write preferred zones: ");
if (SG_LIB_UNBOUNDED_32BIT == u)
printf("not reported\n");
else
printf("%" PRIu32 "\n", u);
u = sg_get_unaligned_be32(b + 12);
printf(" Optimal number of non-sequentially written sequential write "
"preferred zones: ");
if (SG_LIB_UNBOUNDED_32BIT == u)
printf("not reported\n");
else
printf("%" PRIu32 "\n", u);
u = sg_get_unaligned_be32(b + 16);
printf(" Maximum number of open sequential write required zones: ");
if (SG_LIB_UNBOUNDED_32BIT == u)
printf("no limit\n");
else
printf("%" PRIu32 "\n", u);
return 0;
}
/* Called from end of 'case VPD_SUPPORTED_VPDS:' in sdp_process_vpd_page().
* Must take care not to call that function to decode the VPD_SUPPORTED_VPDS
* page again. That will cause an infinite loop!
* Called when '--inquiry --all --all' or '-iaa' used on command line. */
static int
decode_all_vpds(uint8_t * b, int len, int sg_fd,
const struct sdparm_opt_coll * op, int req_pdt,
bool protect)
{
int k, ret;
uint8_t bb[256];
if (len > 256)
len = 256;
memcpy(bb, b, ((len < 256) ? len : 256));
for (k = 0; k < len; ++k) {
if (VPD_SUPPORTED_VPDS == bb[k])
continue; /* this avoids infinite loop */
printf("\n");
ret = sdp_process_vpd_page(sg_fd, bb[k], 0, op, req_pdt, protect,
NULL, 0, NULL, 0);
if (ret)
return ret;
}
return 0;
}
/* Assume index is less than 16 */
const char * sg_ansi_version_arr[] =
{
"no conformance claimed",
"SCSI-1", /* obsolete, ANSI X3.131-1986 */
"SCSI-2", /* obsolete, ANSI X3.131-1994 */
"SPC", /* withdrawn, ANSI INCITS 301-1997 */
"SPC-2", /* ANSI INCITS 351-2001, ISO/IEC 14776-452 */
"SPC-3", /* ANSI INCITS 408-2005, ISO/IEC 14776-453 */
"SPC-4", /* ANSI INCITS 513-2015 */
"SPC-5",
"ecma=1, [8h]",
"ecma=1, [9h]",
"ecma=1, [Ah]",
"ecma=1, [Bh]",
"reserved [Ch]",
"reserved [Dh]",
"reserved [Eh]",
"reserved [Fh]",
};
/* Hack: use vpd page=-1 to indicate want standard INQUIRY response */
static int
decode_std_inq(int sg_fd, const struct sdparm_opt_coll * op)
{
int res, verb, sz, len, pqual;
int resid = 0;
int b_sz = DEF_INQ_RESP_LEN;
uint8_t * b = NULL;
uint8_t * free_b = NULL;
verb = (op->verbose > 0) ? op->verbose - 1 : 0;
b = sg_memalign(b_sz, 0, &free_b, false);
if (NULL == b) {
pr2serr("%s: unalign to allocate ram\n", __func__);
return sg_convert_errno(ENOMEM);
}
sz = op->do_long ? b_sz : 36;
res = sg_ll_inquiry_v2(sg_fd, false, 0, b, sz, 0, &resid, false, verb);
if (res) {
pr2serr("INQUIRY fetching standard response failed\n");
goto fini;
}
if (resid > 0) {
sz -= resid;
if (sz < 5) {
pr2serr("%s: after resid (%d) response size is too short (%d)\n",
__func__, resid, sz);
res = SG_LIB_WILD_RESID;
goto fini;
}
}
pqual = (b[0] & 0xe0) >> 5;
printf("standard INQUIRY:");
if (0 == pqual)
printf("\n");
else if (1 == pqual)
printf(" [PQ indicates LU temporarily unavailable]\n");
else if (3 == pqual)
printf(" [PQ indicates LU not accessible via this port]\n");
else
printf(" [reserved or vendor specific qualifier [%d]]\n", pqual);
len = b[4] + 5;
len = (len <= sz) ? len : sz;
if (op->do_hex) {
hex2stdout(b, len, 0);
return 0;
}
printf(" PQual=%d PDT=%d RMB=%d LU_CONG=%d hot_pluggable=%d "
"version=0x%02x ", pqual, b[0] & 0x1f, !!(b[1] & 0x80),
!!(b[1] & 0x40), (b[1] >> 4) & 0x3, (unsigned int)b[2]);
printf(" [%s]\n", sg_ansi_version_arr[b[2] & 0xf]);
printf(" [AERC=%d] [TrmTsk=%d] NormACA=%d HiSUP=%d "
" Resp_data_format=%d\n SCCS=%d ",
!!(b[3] & 0x80), !!(b[3] & 0x40), !!(b[3] & 0x20),
!!(b[3] & 0x10), b[3] & 0x0f, !!(b[5] & 0x80));
printf("ACC=%d TPGS=%d 3PC=%d Protect=%d ",
!!(b[5] & 0x40), ((b[5] & 0x30) >> 4), !!(b[5] & 0x08),
!!(b[5] & 0x01));
printf(" [BQue=%d]\n EncServ=%d ", !!(b[6] & 0x80), !!(b[6] & 0x40));
if (b[6] & 0x10)
printf("MultiP=1 (VS=%d) ", !!(b[6] & 0x20));
else
printf("MultiP=0 ");
printf("[MChngr=%d] [ACKREQQ=%d] Addr16=%d\n [RelAdr=%d] ",
!!(b[6] & 0x08), !!(b[6] & 0x04), !!(b[6] & 0x01),
!!(b[7] & 0x80));
printf("WBus16=%d Sync=%d [Linked=%d] [TranDis=%d] ",
!!(b[7] & 0x20), !!(b[7] & 0x10), !!(b[7] & 0x08),
!!(b[7] & 0x04));
printf("CmdQue=%d\n", !!(b[7] & 0x02));
printf(" Vendor_identification: %.8s\n", b + 8);
printf(" Product_identification: %.16s\n", b + 16);
printf(" Product_revision_level: %.4s\n", b + 32);
res = 0;
fini:
if (free_b)
free(free_b);
return res;
}
/* If ihbp is NULL then need to send SCSI INQUIRY command to device referred
* to by sg_fd; then process the response received. If ihbp is non-NULL then
* sg_fd is ignored and the buffer pointed to by ihbp (with length no greater
* than ihb_len) is assumed to be the response to a SCSI INQUIRY command.
* Returns 0 if successful, else error. spn changes what is output, currently
* it only changes of the output of the Device Identification VPD page. */
int
sdp_process_vpd_page(int sg_fd, int pn, int spn,
const struct sdparm_opt_coll * op, int req_pdt,
bool protect, const uint8_t * ihbp, int ihb_len,
uint8_t * alt_buf, int off)
{
bool adc = false;
bool sbc = false;
bool ssc = false;
int len, k, verb, dev_pdt, pdt, sz, hex_format;
int resid = 0;
int ret = 0;
uint8_t * up;
const struct sdparm_vpd_page_t * vpp;
const char * vpd_name;
uint8_t * b = NULL;
uint8_t * free_b = NULL;
int b_sz = 2 * sg_get_page_size();
char c[80];
verb = (op->verbose > 0) ? op->verbose - 1 : 0;
if (verb > 3)
pr2serr("%s: sg_fd=%d, pn=%d, spn=%d, ihbp is %sgiven, alt_buff is "
"%sgiven, off=%d\n", __func__, sg_fd, pn, spn,
((!! ihbp) ? "" : "not "), ((!! alt_buf) ? "" : "not "), off);
hex_format = (op->do_hex > 2) ? -1 : 0;
sz = b_sz;
if (NULL == alt_buf) {
b = sg_memalign(b_sz, 0 /* page align */, &free_b, false);
if (NULL == b) {
pr2serr("Unable to allocate %d bytes on the heap\n", b_sz);
ret = sg_convert_errno(ENOMEM);
goto fini;
}
}
if (sg_fd < 0) {
if ((!! alt_buf) == (!! ihbp)) {
pr2serr("%s: logic error, if no sg_fd need either ihbp or "
"alt_buf, not both\n", __func__);
ret = sg_convert_errno(EINVAL);
goto fini;
} else if (alt_buf) {
b = alt_buf + off;
sz -= off;
pn = b[1];
} else { /* so ihbp must be non-NULL */
if (ihb_len < sz)
sz = ihb_len;
memcpy(b, ihbp, sz);
pn = b[1];
}
} else { /* so (sg_fd >= 0) , need to read from device */
if (pn < 0) {
if (VPD_NOT_STD_INQ == pn) {
ret = decode_std_inq(sg_fd, op);
goto fini;
} else if (op->do_all)
pn = VPD_SUPPORTED_VPDS; /* if '--all' list supported vpds */
else
pn = VPD_DEVICE_ID; /* default to device id page */
}
sz = (VPD_ATA_INFO == pn) ? VPD_ATA_INFO_RESP_LEN : DEF_INQ_RESP_LEN;
try_larger:
ret = sg_ll_inquiry_v2(sg_fd, true, pn, b, sz, 0, &resid, false,
verb);
if (ret) {
if (! op->examine)
pr2serr("INQUIRY fetching VPD page=0x%x failed\n", pn);
goto fini;
}
len = ((sz - resid) >= 4) ? (sg_get_unaligned_be16(b + 2) + 4) : 0;
if (len > sz) {
if (sz < VPD_LARGE_RESP_LEN) {
sz = VPD_LARGE_RESP_LEN;
goto try_larger;
}
pr2serr("%s: resid=%d implies response too short (%d)\n",
__func__, resid, len);
ret = SG_LIB_WILD_RESID;
goto fini;
}
}
dev_pdt = b[0] & 0x1f;
if ((req_pdt >= 0) && (req_pdt != (dev_pdt))) {
pr2serr("given peripheral device type [%d] differs from reported "
"[%d]\n", req_pdt, dev_pdt);
pr2serr(" start with given pdt\n");
pdt = req_pdt;
} else
pdt = dev_pdt;
switch (pn) {
case VPD_SUPPORTED_VPDS: /* 0x0 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
printf("Supported VPD pages VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
ret = 0;
goto fini;
}
if (len > 0) {
for (k = 0; k < len; ++k) {
vpp = sdp_get_vpd_detail(b[4 + k], -1, pdt);
if (vpp) {
if (op->do_long)
printf(" [0x%02x] %s [%s]\n", b[4 + k],
vpp->name, vpp->acron);
else
printf(" %s [%s]\n", vpp->name, vpp->acron);
} else
printf(" 0x%x\n", b[4 + k]);
}
/* Take care not to decode this VPD page [0x0] again! */
if ((op->do_all > 1) && (sg_fd >= 0)) {
ret = decode_all_vpds(b + 4, len, sg_fd, op, req_pdt,
protect);
if (ret)
goto fini;
}
} else
printf(" <empty>\n");
break;
case VPD_ATA_INFO: /* 0x89 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to ATA information VPD page truncated\n");
len = sz;
}
if (3 == op->do_hex) { /* output suitable for "hdparm --Istdin" */
dWordHex((const unsigned short *)(b + 60), 256, -2,
sg_is_big_endian());
goto fini;
}
if (op->do_long)
printf("ATA information [0x89] VPD page:\n");
else
printf("ATA information VPD page:\n");
if (op->do_hex && (2 != op->do_hex)) {
hex2stdout(b, len + 4, 0);
goto fini;
}
ret = decode_ata_info_vpd(b, len + 4, op->do_long, op->do_hex);
if (ret)
goto fini;
break;
case VPD_DEVICE_ID: /* 0x83 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to device identification VPD page truncated\n");
len = sz;
}
if (op->do_long)
printf("Device identification [0x83] VPD page:\n");
else if (! op->do_quiet)
printf("Device identification VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if ((0 == spn) || (VPD_DI_SEL_LU & spn))
ret = decode_dev_ids(sg_get_desig_assoc_str(VPD_ASSOC_LU), 0,
b + 4, len, VPD_ASSOC_LU, -1, -1, op);
if ((0 == spn) || (VPD_DI_SEL_TPORT & spn))
ret = decode_dev_ids(sg_get_desig_assoc_str(VPD_ASSOC_TPORT), 0,
b + 4, len, VPD_ASSOC_TPORT, -1, -1, op);
if ((0 == spn) || (VPD_DI_SEL_TARGET & spn))
ret = decode_dev_ids(sg_get_desig_assoc_str(VPD_ASSOC_TDEVICE), 0,
b + 4, len, VPD_ASSOC_TDEVICE, -1, -1, op);
if (VPD_DI_SEL_AS_IS & spn)
ret = decode_dev_ids(NULL, 0, b + 4, len, -1, -1, -1, op);
if (ret)
goto fini;
break;
case VPD_EXT_INQ: /* 0x86 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to Extended inquiry data VPD page truncated\n");
len = sz;
}
if (op->do_long)
printf("Extended inquiry data [0x86] VPD page:\n");
else if (! op->do_quiet)
printf("Extended inquiry data VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = decode_ext_inq_vpd(b, len + 4, op->do_long, protect);
if (ret)
goto fini;
break;
case VPD_MAN_NET_ADDR: /* 0x85 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to Management network addresses VPD page "
"truncated\n");
len = sz;
}
if (op->do_long)
printf("Management network addresses [0x85] VPD page:\n");
else
printf("Management network addresses VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = decode_man_net_vpd(b, len + 4);
if (ret)
goto fini;
break;
case VPD_MODE_PG_POLICY: /* 0x87 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to Mode page policy VPD page truncated\n");
len = sz;
}
if (op->do_long)
printf("Mode page policy [0x87] VPD page:\n");
else
printf("mode page policy VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = decode_mode_policy_vpd(b, len + 4);
if (ret)
goto fini;
break;
case VPD_POWER_CONDITION: /* 0x8a */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to Power condition VPD page truncated\n");
len = sz;
}
if (op->do_long)
printf("Power condition [0x8a] VPD page:\n");
else if (! op->do_quiet)
printf("Power condition VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = decode_power_condition(b, len + 4);
if (ret)
goto fini;
break;
case VPD_DEVICE_CONSTITUENTS: /* 0x8b */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2);
if (len > sz) {
pr2serr("Response to Device constituents VPD page truncated\n");
len = sz;
}
if (op->do_long)
printf("Device constituents [0x8b] VPD page:\n");
else if (! op->do_quiet)
printf("Device constituents VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = decode_dev_constit_vpd(b, len + 4, req_pdt, protect, op);
if (ret)
goto fini;
break;
case VPD_POWER_CONSUMPTION: /* 0x8d */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr( "Response to Power consumption VPD page truncated\n");
len = sz;
}
if (op->do_long)
printf("Power consumption [0x8d] VPD page:\n");
else
printf("Power consumption VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = decode_power_consumption_vpd(b, len + 4);
if (ret)
goto fini;
break;
case VPD_PROTO_LU: /* 0x90 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to Protocol-specific logical unit information "
"VPD page truncated\n");
len = sz;
}
if (op->do_long)
printf("Protocol-specific logical unit information [0x90] VPD "
"page:\n");
else
printf("Protocol-specific logical unit information VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = decode_proto_lu_vpd(b, len + 4);
if (ret)
goto fini;
break;
case VPD_PROTO_PORT: /* 0x91 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to Protocol-specific port information VPD page "
"truncated\n");
len = sz;
}
if (op->do_long)
printf("Protocol-specific port information [0x91] VPD "
"page:\n");
else
printf("Protocol-specific port information VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = decode_proto_port_vpd(b, len + 4);
if (ret)
goto fini;
break;
case VPD_SCSI_FEATURE_SETS: /* 0x92 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2);
if (len > sz) {
pr2serr("Response to SCSI Feature sets VPD page truncated\n");
len = sz;
}
if (op->do_long)
printf("SCSI Feature sets [0x92] VPD page:\n");
else
printf("SCSI Feature sets:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = decode_feature_sets_vpd(b, len + 4, op);
if (ret)
goto fini;
break;
case VPD_SCSI_PORTS: /* 0x88 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to SCSI Ports VPD page truncated\n");
len = sz;
}
if (op->do_long)
printf("SCSI Ports [0x88] VPD page:\n");
else
printf("SCSI Ports VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = decode_scsi_ports_vpd(b, len + 4, op);
if (ret)
goto fini;
break;
case VPD_SOFTW_INF_ID: /* 0x84 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to Software interface identification VPD page "
"truncated\n");
len = sz;
}
if (op->do_long)
printf("Software interface identification [0x84] VPD page:\n");
else
printf("Software interface identification VPD page:\n");
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
up = b + 4;
for ( ; len > 5; len -= 6, up += 6)
printf(" IEEE Company_id: 0x%06x, vendor specific extension "
"id: 0x%06x\n", sg_get_unaligned_be24(up + 0),
sg_get_unaligned_be24(up + 3));
break;
case VPD_UNIT_SERIAL_NUM: /* 0x80 */
if (b[1] != pn)
goto dumb_inq;
if ((0x2 == b[2]) && (0x2 == b[3])) {
/* could be a Unit Serial number VPD page with a very long
* length of 4+514 bytes; more likely standard response for
* SCSI-2, RMB=1 and a response_data_format of 0x2. */
pr2serr("very unlikely to be a Unit Serial Number VPD "
"response, so ...\n");
goto dumb_inq;
}
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (op->do_long)
printf("Unit serial number [0x80] VPD page:\n");
else
printf("Unit serial number VPD page:\n");
if (op->do_hex)
hex2stdout(b, len + 4, hex_format);
else if (len > 0) {
if (len + 4 < b_sz)
b[len + 4] = '\0';
else
b[b_sz - 1] = '\0';
printf(" %s\n", b + 4);
} else
printf(" <empty>\n");
break;
case VPD_3PARTY_COPY: /* 0x8f */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if ((NULL == ihbp) && (len > sz)) {
/* Increase response size to maximum we can handle here */
sz = VPD_XCOPY_RESP_LEN;
ret = sg_ll_inquiry_v2(sg_fd, true, pn, b, sz, 0, &resid, false,
verb);
if (ret) {
pr2serr("INQUIRY fetching VPD page=0x%x failed\n", pn);
goto fini;
}
if (resid) {
sz += resid;
if (resid < 4) {
pr2serr("%s: resid=%d implies response too short (%d)\n",
__func__, resid, sz);
ret = SG_LIB_WILD_RESID;
goto fini;
}
}
len = sg_get_unaligned_be16(b + 2);
if (len > sz) {
pr2serr("Response to Third party copy VPD page truncated\n");
len = sz;
}
}
if (op->do_long)
printf("Third party copy [0x8f] VPD page:\n");
else
printf("Third party copy VPD page:\n");
if (1 == op->do_hex) {
hex2stdout(b, len + 4, 0);
goto fini;
}
decode_3party_copy_vpd(b, len + 4, op->do_hex, pdt, op->verbose);
break;
case 0xb0: /* VPD page depends on pdt */
if (b[1] != pn)
goto dumb_inq;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
vpd_name = "Block limits (SBC)";
sbc = true;
break;
case PDT_TAPE: case PDT_MCHANGER:
vpd_name = "Sequential-access device capabilities (SSC)";
ssc = true;
break;
case PDT_OSD:
vpd_name = "OSD information (OSD)" ;
/* osd = 1; */
break;
default:
vpd_name = "unexpected pdt for B0h";
break;
}
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to %s VPD page truncated\n", vpd_name);
len = sz;
}
if (op->do_long)
printf("%s [0xb0] VPD page:\n", vpd_name);
else
printf("%s VPD page:\n", vpd_name);
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if (ssc)
ret = decode_tape_dev_caps_vpd(b, len + 4);
else if (sbc)
ret = decode_block_limits_vpd(b, len + 4);
else
hex2stdout(b, len + 4, 0);
if (ret)
goto fini;
break;
case 0xb1: /* VPD page depends on pdt */
if (b[1] != pn)
goto dumb_inq;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
vpd_name = "Block device characteristics (SBC)";
sbc = true;
break;
case PDT_TAPE: case PDT_MCHANGER:
vpd_name = "Manufactured-assigned serial number (SSC)";
ssc = true;
break;
case PDT_OSD:
vpd_name = "Security token (OSD)";
/* osd = true; */
break;
case PDT_ADC:
vpd_name = "Manufactured assigned serial number (ADC)";
adc = true;
break;
default:
vpd_name = "unexpected pdt for B1h";
break;
}
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
if (len > sz) {
pr2serr("Response to %s VPD page truncated\n", vpd_name);
len = sz;
}
if (op->do_long)
printf("%s [0xb1] VPD page:\n", vpd_name);
else
printf("%s VPD page:\n", vpd_name);
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if (ssc || adc)
ret = decode_tape_man_ass_sn_vpd(b, len + 4);
else if (sbc)
ret = decode_block_dev_chars_vpd(b, len + 4);
else
hex2stdout(b, len + 4, 0);
if (ret)
goto fini;
break;
case 0xb2: /* VPD page depends on pdt */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
vpd_name = "Logical block provisioning (SBC)";
sbc = true;
break;
case PDT_TAPE: case PDT_MCHANGER:
vpd_name = "TapeAlert supported flags (SSC)";
ssc = true;
break;
default:
vpd_name = "unexpected pdt for B2h";
break;
}
if (op->do_long)
printf("%s [0xb2] VPD page:\n", vpd_name);
else
printf("%s VPD page:\n", vpd_name);
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if (ssc)
ret = decode_tapealert_supported_vpd(b, len + 4);
else if (sbc) /* added in sbc3r20 */
ret = decode_block_lb_prov_vpd(b, len + 4, op);
else
hex2stdout(b, len + 4, 0);
if (ret)
goto fini;
break;
case 0xb3: /* VPD page depends on pdt */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
vpd_name = "Referrals (SBC)";
sbc = true;
break;
case PDT_TAPE: case PDT_MCHANGER:
vpd_name = "Automation device serial number (SSC)";
ssc = true;
break;
default:
vpd_name = "unexpected pdt for B3h";
break;
}
if (op->do_long)
printf("%s [0xb3] VPD page:\n", vpd_name);
else
printf("%s VPD page:\n", vpd_name);
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if (ssc) {
/* VPD_AUTOMATION_DEV_SN ssc */
if (len > 0) {
if (len + 4 < b_sz)
b[len + 4] = '\0';
else
b[b_sz - 1] = '\0';
printf(" serial number: %s\n", b + 4);
} else
printf(" serial number: <empty>\n");
} else if (sbc) /* added in sbc3r22 */
ret = decode_referrals_vpd(b, len + 4);
else
hex2stdout(b, len + 4, 0);
if (ret)
goto fini;
break;
case 0xb4: /* VPD page depends on pdt */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2); /* spc4r25 */
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
vpd_name = "Supported block lengths and protection types (SBC)";
sbc = true;
break;
case PDT_TAPE: case PDT_MCHANGER:
vpd_name = "Data transfer device element address (SSC)";
ssc = true;
break;
default:
vpd_name = "unexpected pdt for B4h";
break;
}
if (op->do_long)
printf("%s [0xb4] VPD page:\n", vpd_name);
else
printf("%s VPD page:\n", vpd_name);
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if (ssc) {
if (len > 0) {
printf(" 0x");
for (k = 0; k < len; ++k)
printf("%02x", (unsigned int)b[4 + k]);
printf("\n");
} else
printf(" <empty>\n");
} else if (sbc) /* added in sbc4r01 */
ret = decode_sup_block_lens_vpd(b, len + 4);
else
hex2stdout(b, len + 4, 0);
if (ret)
goto fini;
break;
case 0xb5: /* VPD page depends on pdt */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2);
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
vpd_name = "Block device characteristics extension (SBC)";
sbc = true;
break;
case PDT_TAPE: case PDT_MCHANGER:
vpd_name = "Logical block protection (SSC)";
ssc = true;
break;
default:
vpd_name = "unexpected pdt for B5h";
break;
}
if (op->do_long)
printf("%s [0xb5] VPD page:\n", vpd_name);
else
printf("%s VPD page:\n", vpd_name);
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if (sbc) /* added in sbc4r02 */
ret = decode_block_dev_char_ext_vpd(b, len + 4);
else if (ssc) /* added in ssc5r02a */
ret = decode_lb_protection_vpd(b, len + 4);
else
hex2stdout(b, len + 4, 0);
if (ret)
goto fini;
break;
case VPD_ZBC_DEV_CHARS: /* 0xb6 for both pdt=0 and pdt=0x14 */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2);
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
vpd_name = "Zoned block device characteristics";
sbc = true;
break;
default:
vpd_name = "unexpected pdt for B6h";
break;
}
if (op->do_long)
printf("%s [0xb6] VPD page:\n", vpd_name);
else
printf("%s VPD page:\n", vpd_name);
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if (sbc) /* added in zbc-r01c */
ret = decode_zbdc_vpd(b, len + 4);
else
hex2stdout(b, len + 4, 0);
if (ret)
goto fini;
break;
case 0xb7: /* VPD page depends on pdt */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2);
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
vpd_name = "Block limits extension (SBC)";
sbc = true;
break;
default:
vpd_name = "unexpected pdt for B7h";
break;
}
if (op->do_long)
printf("%s [0xb7] VPD page:\n", vpd_name);
else
printf("%s VPD page:\n", vpd_name);
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if (sbc) /* added in sbc4r07 */
ret = decode_block_limits_ext_vpd(b, len + 4);
else
hex2stdout(b, len + 4, 0);
if (ret)
goto fini;
break;
case 0xb8: /* VPD page depends on pdt */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2);
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
vpd_name = "Format presets (SBC)";
sbc = true;
break;
default:
vpd_name = "unexpected pdt for B8h";
break;
}
if (op->do_long)
printf("%s [0xb8] VPD page:\n", vpd_name);
else
printf("%s VPD page:\n", vpd_name);
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if (sbc) /* added in sbc4r18 */
ret = decode_format_presets_vpd(b, len + 4);
else
hex2stdout(b, len + 4, 0);
if (ret)
goto fini;
break;
case 0xb9: /* VPD page depends on pdt */
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2);
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
vpd_name = "Concurrent positioning ranges (SBC)";
sbc = true;
break;
default:
vpd_name = "unexpected pdt for B9h";
break;
}
if (op->do_long)
printf("%s [0xb9] VPD page:\n", vpd_name);
else
printf("%s VPD page:\n", vpd_name);
if (op->do_hex) {
hex2stdout(b, len + 4, hex_format);
goto fini;
}
ret = 0;
if (sbc)
ret = decode_con_pos_range_vpd(b, len + 4);
else
hex2stdout(b, len + 4, 0);
if (ret)
goto fini;
break;
default:
if (b[1] != pn)
goto dumb_inq;
len = sg_get_unaligned_be16(b + 2) + 4;
vpp = sdp_get_vpd_detail(pn, -1, pdt);
if (vpp)
snprintf(c, sizeof(c), "%s VPD page", vpp->name);
else
snprintf(c, sizeof(c), "VPD page 0x%x", pn);
if (op->do_hex)
printf("%s in hex:\n", c);
else
pr2serr("%s in hex:\n", c);
if (len > b_sz) {
if (op->verbose)
pr2serr("page length=%d too long, trim\n", len);
len = b_sz;
}
if (op->do_hex)
hex2stdout(b, len, hex_format);
else
hex2stderr(b, len, 0);
break;
}
ret = 0;
goto fini;
dumb_inq:
pr2serr("malformed VPD response, VPD pages probably not supported\n");
return SG_LIB_CAT_MALFORMED;
fini:
if (free_b)
free(free_b);
return ret;
}
|