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
|
/*++
Copyright (c) 2005 - 2011, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
FakeHii.c
Abstract:
HII support for running under non-Tiano environment
According to the requirement that Tiano shell.efi should be able to run under EFI1.1, we should embed HII support inside
shell, because there is no native HII support in EFI1.1.
We are just to impelment a subset of the complete HII, because not all the features of HII are required in shell
Revision History
--*/
#include "FakeHii.h"
EFI_HANDLE mFakeHiiHandle = NULL;
#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)
STATIC EFI_FAKE_HII_DATA mFakeHiiData = {
EFI_FAKE_HII_DATA_SIGNATURE,
0,
{
(struct _EFI_LIST_ENTRY *) NULL,
(struct _EFI_LIST_ENTRY *) NULL
},
{
(struct _EFI_LIST_ENTRY *) NULL,
(struct _EFI_LIST_ENTRY *) NULL
},
{
FakeHiiNewString,
FakeHiiGetString,
FakeHiiSetString,
FakeHiiGetLanguages,
FakeHiiGetSecondaryLanguages
},
{
FakeHiiNewPackageList,
FakeHiiRemovePackageList,
FakeHiiUpdatePackageList,
FakeHiiListPackageLists,
FakeHiiExportPackageLists,
FakeHiiRegisterPackageNotify,
FakeHiiUnregisterPackageNotify,
FakeHiiFindKeyboardLayouts,
FakeHiiGetKeyboardLayout,
FakeHiiSetKeyboardLayout,
FakeHiiGetPackageListHandle
}
};
#endif
EFI_STATUS
FakeInitializeHiiDatabase (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Initialize fake HII database
Arguments:
ImageHandle - The image handle
SystemTable - The system table
Returns:
EFI_SUCCESS - Initialized successfully
others - failed
--*/
{
EFI_STATUS Status;
BOOLEAN HiiInstalled;
#if (EFI_SPECIFICATION_VERSION < 0x0002000A)
UINTN HandleCount;
EFI_HANDLE *HandleBuffer;
EFI_FAKE_HII_DATA *HiiData;
#endif
HiiInstalled = FALSE;
#if (EFI_SPECIFICATION_VERSION < 0x0002000A)
HiiData = NULL;
Status = LibLocateHandle (
ByProtocol,
&gEfiHiiProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer
);
if (!EFI_ERROR (Status)) {
if (NULL != HandleBuffer) {
FreePool (HandleBuffer);
HiiInstalled = TRUE;
}
}
if (!HiiInstalled)
{
HiiData = AllocateZeroPool (sizeof (EFI_FAKE_HII_DATA));
if (NULL == HiiData) {
return EFI_OUT_OF_RESOURCES;
}
HiiData->Signature = EFI_FAKE_HII_DATA_SIGNATURE;
HiiData->DatabaseHead = NULL;
HiiData->Hii.NewPack = FakeHiiNewPack;
HiiData->Hii.RemovePack = FakeHiiRemovePack;
HiiData->Hii.FindHandles = FakeHiiFindHandles;
HiiData->Hii.GetPrimaryLanguages = FakeHiiGetPrimaryLanguages;
HiiData->Hii.GetString = FakeHiiGetString;
HiiData->Hii.GetForms = FakeHiiGetForms;
HiiData->Hii.ExportDatabase = FakeHiiExportDatabase;
HiiData->Hii.GetDefaultImage = FakeHiiGetDefaultImage;
HiiData->Hii.GetGlyph = FakeHiiGetGlyph;
HiiData->Hii.GetKeyboardLayout = FakeHiiGetKeyboardLayout;
HiiData->Hii.GetLine = FakeHiiGetLine;
HiiData->Hii.GetSecondaryLanguages = FakeHiiGetSecondaryLanguages;
HiiData->Hii.GlyphToBlt = FakeHiiGlyphToBlt;
HiiData->Hii.NewString = FakeHiiNewString;
HiiData->Hii.ResetStrings = FakeHiiResetStrings;
HiiData->Hii.TestString = FakeHiiTestString;
HiiData->Hii.UpdateForm = FakeHiiUpdateForm;
Status = BS->InstallProtocolInterface (
&mFakeHiiHandle,
&gEfiHiiProtocolGuid,
EFI_NATIVE_INTERFACE,
&HiiData->Hii
);
if (EFI_ERROR (Status)) {
FreePool (HiiData);
return Status;
}
}
#else
Status = LocateHiiProtocols ();
if (!EFI_ERROR (Status)) {
HiiInstalled = TRUE;
}
if (!HiiInstalled) {
InitializeListHead (&mFakeHiiData.DatabaseList);
InitializeListHead (&mFakeHiiData.HiiHandleList);
return BS->InstallMultipleProtocolInterfaces (
&mFakeHiiHandle,
&gEfiHiiStringProtocolGuid,
&mFakeHiiData.HiiString,
&gEfiHiiDatabaseProtocolGuid,
&mFakeHiiData.HiiDatabase,
NULL
);
}
#endif
return Status;
}
EFI_STATUS
FakeUninstallHiiDatabase (
VOID
)
{
EFI_STATUS Status;
#if (EFI_SPECIFICATION_VERSION < 0x0002000A)
EFI_HII_PROTOCOL *FakeHii;
EFI_FAKE_HII_DATA *HiiData;
#endif
if (mFakeHiiHandle != NULL) {
#if (EFI_SPECIFICATION_VERSION < 0x0002000A)
Status = BS->HandleProtocol (
mFakeHiiHandle,
&gEfiHiiProtocolGuid,
(VOID**)&FakeHii
);
Status = BS->UninstallProtocolInterface (
mFakeHiiHandle,
&gEfiHiiProtocolGuid,
FakeHii
);
HiiData = EFI_FAKE_HII_DATA_FROM_THIS (FakeHii);
FreePool (HiiData);
#else
Status = LocateHiiProtocols ();
if (EFI_ERROR (Status)) {
return Status;
}
Status = BS->UninstallMultipleProtocolInterfaces (
mFakeHiiHandle,
&gEfiHiiStringProtocolGuid,
gLibHiiString,
&gEfiHiiDatabaseProtocolGuid,
gLibHiiDatabase,
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
#endif
mFakeHiiHandle = NULL;
}
return EFI_SUCCESS;
}
#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)
STATIC
VOID
GetStringTextSize (
IN UINT8 *StringSrc,
IN OUT UINTN *BufferSize
)
/*++
Routine Description:
Calculate the size of StringSrc and output it.
Arguments:
StringSrc - Points to current null-terminated string.
BufferSize - Length of the buffer.
Returns:
None.
--*/
{
UINTN StringSize;
CHAR16 Zero;
UINT8 *StringPtr;
ASSERT (StringSrc != NULL && BufferSize != NULL);
ZeroMem (&Zero, sizeof (CHAR16));
StringSize = sizeof (CHAR16);
StringPtr = StringSrc;
while (CompareMem (StringPtr, &Zero, sizeof (CHAR16)) != 0) {
StringSize += sizeof (CHAR16);
StringPtr += sizeof (CHAR16);
}
*BufferSize = StringSize;
}
STATIC
EFI_STATUS
InsertStringPackage (
IN UINT8 *PackageHdr,
IN OUT FAKE_HII_DATABASE_RECORD *PackageList
)
/*++
Routine Description:
This function insert a String package to the specified package list node.
Arguments:
PackageHdr - Pointer to a buffer stored with String package information.
PackageList - Pointer to a package list which will be inserted to.
Returns:
EFI_SUCCESS - String Package is inserted successfully.
EFI_OUT_OF_RESOURCES - Unable to allocate necessary resources for the
new String package.
EFI_INVALID_PARAMETER - PackageHdr is NULL or PackageList is NULL.
EFI_UNSUPPORTED - A string package with the same language already exists
in current package list.
--*/
{
FAKE_HII_STRING_PACKAGE *StringPackage;
UINT32 HeaderSize;
UINT32 StringInfoOffset;
UINT8 *Pointer;
CHAR8 *Language;
UINT32 LanguageSize;
EFI_LIST_ENTRY *Link;
FAKE_HII_STRING_BLOCK *Block;
UINTN StrSize;
EFI_STRING_ID CurrentStringId;
UINT16 SkipCount;
Pointer = PackageHdr + sizeof (EFI_HII_PACKAGE_HEADER);
CopyMem (&HeaderSize, Pointer, sizeof (UINT32));
Pointer += sizeof (UINT32);
CopyMem (&StringInfoOffset, Pointer, sizeof (UINT32));
//
// It is illegal to have two string packages with same language within one packagelist
// since the stringid will be duplicate if so. Check it to avoid this potential issue.
//
LanguageSize = HeaderSize - sizeof (EFI_HII_STRING_PACKAGE_HDR) + sizeof (CHAR8);
Language = (CHAR8 *) AllocateZeroPool (LanguageSize);
if (Language == NULL) {
return EFI_OUT_OF_RESOURCES;
}
strcpya (Language, (CHAR8*) ((UINT8 *) PackageHdr + HeaderSize - LanguageSize));
for (Link = PackageList->StringPkgHdr.Flink; Link != &PackageList->StringPkgHdr; Link = Link->Flink) {
StringPackage = CR (Link, FAKE_HII_STRING_PACKAGE, Entry, FAKE_HII_STRING_PACKAGE_SIGNATURE);
if (CompareLanguage (Language, StringPackage->StringPkgHdr->Language)) {
FreePool (Language);
return EFI_UNSUPPORTED;
}
}
FreePool (Language);
//
// Create a String package node
//
StringPackage = AllocateZeroPool (sizeof (FAKE_HII_STRING_PACKAGE));
if (StringPackage == NULL) {
return EFI_OUT_OF_RESOURCES;
}
StringPackage->Signature = FAKE_HII_STRING_PACKAGE_SIGNATURE;
StringPackage->StringPkgHdr = AllocateZeroPool (HeaderSize);
if (StringPackage->StringPkgHdr == NULL) {
FreePool (StringPackage);
return EFI_OUT_OF_RESOURCES;
}
InitializeListHead (&StringPackage->StringBlockHdr);
//
// Copy the String package header.
//
CopyMem (StringPackage->StringPkgHdr, PackageHdr, HeaderSize);
//
// Copy the String blocks
//
Pointer = PackageHdr + StringInfoOffset;
CurrentStringId = 1;
while (*Pointer != EFI_HII_SIBT_END) {
switch (*Pointer) {
case EFI_HII_SIBT_STRING_UCS2:
Block = AllocateZeroPool (sizeof (FAKE_HII_STRING_BLOCK));
if (Block == NULL) {
FreePool (StringPackage->StringPkgHdr);
FreePool (StringPackage);
return EFI_OUT_OF_RESOURCES;
}
Block->Signature = FAKE_HII_STRING_BLOCK_SIGNATURE;
Pointer += sizeof (EFI_HII_STRING_BLOCK);
GetStringTextSize (Pointer, &StrSize);
Block->StringBlock = AllocateZeroPool (StrSize);
if (Block->StringBlock == NULL) {
FreePool (Block);
FreePool (StringPackage->StringPkgHdr);
FreePool (StringPackage);
return EFI_OUT_OF_RESOURCES;
}
CopyMem (Block->StringBlock, Pointer, StrSize);
Block->StringId = CurrentStringId;
Block->BlockSize = StrSize;
InsertTailList (&StringPackage->StringBlockHdr, &Block->Entry);
Pointer += StrSize;
CurrentStringId++;
break;
case EFI_HII_SIBT_SKIP1:
Pointer += sizeof (EFI_HII_STRING_BLOCK);
CurrentStringId = CurrentStringId + *Pointer;
Pointer += sizeof (UINT8);
break;
case EFI_HII_SIBT_SKIP2:
Pointer += sizeof (EFI_HII_STRING_BLOCK);
CopyMem (&SkipCount, Pointer, sizeof (UINT16));
CurrentStringId = CurrentStringId + SkipCount;
Pointer += sizeof (UINT16);
break;
default:
FreePool (StringPackage->StringPkgHdr);
FreePool (StringPackage);
return EFI_UNSUPPORTED;
}
}
//
// Insert to String package array
//
InsertTailList (&PackageList->StringPkgHdr, &StringPackage->Entry);
return EFI_SUCCESS;
}
STATIC
VOID
RemoveStringPackages (
IN EFI_LIST_ENTRY *ListHead
)
/*++
Routine Description:
This function deletes all String packages from a package list node.
Arguments:
ListHead - Array header of all string packages to be removed.
Returns:
--*/
{
FAKE_HII_STRING_PACKAGE *Package;
FAKE_HII_STRING_BLOCK *Block;
while (!IsListEmpty (ListHead)) {
Package = CR (
ListHead->Flink,
FAKE_HII_STRING_PACKAGE,
Entry,
FAKE_HII_STRING_PACKAGE_SIGNATURE
);
//
// Remove all string blocks
//
while (!IsListEmpty (&Package->StringBlockHdr)) {
Block = CR (
Package->StringBlockHdr.Flink,
FAKE_HII_STRING_BLOCK,
Entry,
FAKE_HII_STRING_BLOCK_SIGNATURE
);
RemoveEntryList (&Block->Entry);
FreePool (Block->StringBlock);
FreePool (Block);
}
RemoveEntryList (&Package->Entry);
FreePool (Package->StringPkgHdr);
FreePool (Package);
}
}
EFI_STATUS
EFIAPI
FakeHiiNewPackageList (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN CONST EFI_HII_PACKAGE_LIST_HEADER *PackageList,
IN CONST EFI_HANDLE DriverHandle,
OUT EFI_HII_HANDLE *Handle
)
{
EFI_STATUS Status;
EFI_FAKE_HII_DATA *Private;
FAKE_HII_DATABASE_RECORD *DatabaseRecord;
EFI_LIST_ENTRY *Link;
EFI_GUID PackageListGuid;
FAKE_HII_HANDLE *HiiHandle;
UINT8 *PackageListPtr;
EFI_HII_PACKAGE_HEADER PackageHeader;
if (This == NULL || PackageList == NULL || Handle == NULL) {
return EFI_INVALID_PARAMETER;
}
Private = EFI_FAKE_HII_DATA_FROM_THIS (This);
CopyMem (&PackageListGuid, (VOID *) PackageList, sizeof (EFI_GUID));
//
// Check the Package list GUID to guarantee this GUID is unique in database.
//
for (Link = Private->DatabaseList.Flink; Link != &Private->DatabaseList; Link = Link->Flink) {
DatabaseRecord = CR (Link, FAKE_HII_DATABASE_RECORD, Entry, FAKE_HII_DATABASE_RECORD_SIGNATURE);
if (CompareGuid (&(DatabaseRecord->PackageListHdr.PackageListGuid), &PackageListGuid) == 0) {
return EFI_INVALID_PARAMETER;
}
}
//
// Build a PackageList node
//
DatabaseRecord = AllocateZeroPool (sizeof (FAKE_HII_DATABASE_RECORD));
if (DatabaseRecord == NULL) {
return EFI_OUT_OF_RESOURCES;
}
DatabaseRecord->Signature = FAKE_HII_DATABASE_RECORD_SIGNATURE;
InitializeListHead (&DatabaseRecord->StringPkgHdr);
CopyMem (&DatabaseRecord->PackageListHdr, (VOID *) PackageList, sizeof (EFI_HII_PACKAGE_LIST_HEADER));
//
// Insert the string packages if any.
//
PackageListPtr = (UINT8 *) PackageList + sizeof (EFI_HII_PACKAGE_LIST_HEADER);
CopyMem (&PackageHeader, PackageListPtr, sizeof (EFI_HII_PACKAGE_HEADER));
while (PackageHeader.Type != EFI_HII_PACKAGE_END) {
switch (PackageHeader.Type) {
case EFI_HII_PACKAGE_STRINGS:
Status = InsertStringPackage (PackageListPtr, DatabaseRecord);
if (EFI_ERROR (Status)) {
FreePool (DatabaseRecord);
return Status;
}
break;
default:
FreePool (DatabaseRecord);
return EFI_UNSUPPORTED;
}
PackageListPtr += PackageHeader.Length;
CopyMem (&PackageHeader, PackageListPtr, sizeof (EFI_HII_PACKAGE_HEADER));
}
//
// Create a new hii handle
//
HiiHandle = AllocateZeroPool (sizeof (FAKE_HII_HANDLE));
if (HiiHandle == NULL) {
FreePool (DatabaseRecord);
return EFI_OUT_OF_RESOURCES;
}
HiiHandle->Signature = FAKE_HII_HANDLE_SIGNATURE;
Private->HiiHandleCount++;
HiiHandle->Key = Private->HiiHandleCount;
InsertTailList (&Private->HiiHandleList, &HiiHandle->Handle);
DatabaseRecord->Handle = (EFI_HII_HANDLE) HiiHandle;
InsertTailList (&Private->DatabaseList, &DatabaseRecord->Entry);
*Handle = DatabaseRecord->Handle;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FakeHiiRemovePackageList (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_HII_HANDLE Handle
)
{
EFI_FAKE_HII_DATA *Private;
EFI_LIST_ENTRY *Link;
FAKE_HII_DATABASE_RECORD *Node;
FAKE_HII_HANDLE *HiiHandle;
BOOLEAN Matched = FALSE;
if (This == NULL || Handle == NULL) {
return EFI_INVALID_PARAMETER;
}
HiiHandle = (FAKE_HII_HANDLE *) Handle;
if (HiiHandle->Signature != FAKE_HII_HANDLE_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}
Private = EFI_FAKE_HII_DATA_FROM_THIS (This);
Node = NULL;
for (Link = Private->DatabaseList.Flink; Link != &Private->DatabaseList; Link = Link->Flink) {
Node = CR (Link, FAKE_HII_DATABASE_RECORD, Entry, FAKE_HII_DATABASE_RECORD_SIGNATURE);
if (Node->Handle == Handle) {
Matched = TRUE;
break;
}
}
if (!Matched) {
return EFI_NOT_FOUND;
}
//
// Free resources: recorded string packages and corresponding hii handle.
//
RemoveStringPackages (&Node->StringPkgHdr);
RemoveEntryList (&HiiHandle->Handle);
Private->HiiHandleCount--;
FreePool (HiiHandle);
RemoveEntryList (&Node->Entry);
FreePool (Node);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FakeHiiUpdatePackageList (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN CONST EFI_HII_PACKAGE_LIST_HEADER *PackageList
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiListPackageLists (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN UINT8 PackageType,
IN CONST EFI_GUID *PackageGuid,
IN OUT UINTN *HandleBufferLength,
OUT EFI_HII_HANDLE *Handle
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiExportPackageLists (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN OUT UINTN *BufferSize,
OUT EFI_HII_PACKAGE_LIST_HEADER *Buffer
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiRegisterPackageNotify (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN UINT8 PackageType,
IN CONST EFI_GUID *PackageGuid,
IN CONST EFI_HII_DATABASE_NOTIFY PackageNotifyFn,
IN EFI_HII_DATABASE_NOTIFY_TYPE NotifyType,
OUT EFI_HANDLE *NotifyHandle
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiUnregisterPackageNotify (
IN CONST EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_HANDLE NotificationHandle
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiFindKeyboardLayouts (
IN EFI_HII_DATABASE_PROTOCOL *This,
IN OUT UINT16 *KeyGuidBufferLength,
OUT EFI_GUID *KeyGuidBuffer
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiGetKeyboardLayout (
IN EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_GUID *KeyGuid,
IN OUT UINT16 *KeyboardLayoutLength,
OUT EFI_HII_KEYBOARD_LAYOUT *KeyboardLayout
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiSetKeyboardLayout (
IN EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_GUID *KeyGuid
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiGetPackageListHandle (
IN EFI_HII_DATABASE_PROTOCOL *This,
IN EFI_HII_HANDLE PackageListHandle,
OUT EFI_HANDLE *DriverHandle
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiNewString (
IN CONST EFI_HII_STRING_PROTOCOL *This,
IN EFI_HII_HANDLE PackageList,
OUT EFI_STRING_ID *StringId,
IN CONST CHAR8 *Language,
IN CONST CHAR16 *LanguageName, OPTIONAL
IN CONST EFI_STRING String,
IN CONST EFI_FONT_INFO *StringFontInfo OPTIONAL
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiGetString (
IN CONST EFI_HII_STRING_PROTOCOL *This,
IN CONST CHAR8 *Language,
IN EFI_HII_HANDLE PackageList,
IN EFI_STRING_ID StringId,
OUT EFI_STRING String,
IN OUT UINTN *StringSize,
OUT EFI_FONT_INFO **StringFontInfo OPTIONAL
)
{
EFI_FAKE_HII_DATA *Private;
FAKE_HII_DATABASE_RECORD *DatabaseRecord;
EFI_LIST_ENTRY *Link;
FAKE_HII_STRING_PACKAGE *StringPackage;
FAKE_HII_STRING_BLOCK *Block;
BOOLEAN Matched = FALSE;
if (This == NULL || Language == NULL || PackageList == NULL || StringSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (StringId < 1 || (String == NULL && *StringSize != 0)) {
return EFI_INVALID_PARAMETER;
}
if (((FAKE_HII_HANDLE *) PackageList)->Signature != FAKE_HII_HANDLE_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}
//
// Get the specified package list.
//
Private = EFI_STRING_FAKE_HII_DATA_FROM_THIS (This);
DatabaseRecord = NULL;
for (Link = Private->DatabaseList.Flink; Link != &Private->DatabaseList; Link = Link->Flink) {
DatabaseRecord = CR (Link, FAKE_HII_DATABASE_RECORD, Entry, FAKE_HII_DATABASE_RECORD_SIGNATURE);
if (DatabaseRecord->Handle == PackageList) {
Matched = TRUE;
break;
}
}
if (!Matched) {
return EFI_NOT_FOUND;
}
//
// Get the string package by language.
//
Matched = FALSE;
StringPackage = NULL;
for (Link = DatabaseRecord->StringPkgHdr.Flink; Link != &DatabaseRecord->StringPkgHdr; Link = Link->Flink) {
StringPackage = CR (Link, FAKE_HII_STRING_PACKAGE, Entry, FAKE_HII_STRING_PACKAGE_SIGNATURE);
if (CompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language)) {
Matched = TRUE;
break;
}
}
if (!Matched) {
return EFI_NOT_FOUND;
}
//
// Get the string block by stringid.
//
for (Link = StringPackage->StringBlockHdr.Flink; Link != &StringPackage->StringBlockHdr; Link = Link->Flink) {
Block = CR (Link, FAKE_HII_STRING_BLOCK, Entry, FAKE_HII_STRING_BLOCK_SIGNATURE);
if (Block->StringId == StringId) {
if (*StringSize < Block->BlockSize) {
*StringSize = Block->BlockSize;
return EFI_BUFFER_TOO_SMALL;
}
if (String != NULL) {
CopyMem (String, Block->StringBlock, Block->BlockSize);
}
*StringSize = Block->BlockSize;
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
EFI_STATUS
EFIAPI
FakeHiiSetString (
IN CONST EFI_HII_STRING_PROTOCOL *This,
IN EFI_HII_HANDLE PackageList,
IN EFI_STRING_ID StringId,
IN CONST CHAR8 *Language,
IN CONST EFI_STRING String,
IN CONST EFI_FONT_INFO *StringFontInfo OPTIONAL
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FakeHiiGetLanguages (
IN CONST EFI_HII_STRING_PROTOCOL *This,
IN EFI_HII_HANDLE PackageList,
IN OUT CHAR8 *Languages,
IN OUT UINTN *LanguagesSize
)
{
EFI_FAKE_HII_DATA *Private;
FAKE_HII_DATABASE_RECORD *DatabaseRecord;
EFI_LIST_ENTRY *Link;
FAKE_HII_STRING_PACKAGE *StringPackage;
BOOLEAN Matched = FALSE;
UINTN ResultSize;
if (This == NULL || PackageList == NULL || Languages == NULL || LanguagesSize == NULL) {
return EFI_INVALID_PARAMETER;
}
if (((FAKE_HII_HANDLE *) PackageList)->Signature != FAKE_HII_HANDLE_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}
//
// Get the specified package list.
//
Private = EFI_STRING_FAKE_HII_DATA_FROM_THIS (This);
DatabaseRecord = NULL;
for (Link = Private->DatabaseList.Flink; Link != &Private->DatabaseList; Link = Link->Flink) {
DatabaseRecord = CR (Link, FAKE_HII_DATABASE_RECORD, Entry, FAKE_HII_DATABASE_RECORD_SIGNATURE);
if (DatabaseRecord->Handle == PackageList) {
Matched = TRUE;
break;
}
}
if (!Matched) {
return EFI_NOT_FOUND;
}
//
// Search the languages in the specified packagelist.
//
ResultSize = 0;
for (Link = DatabaseRecord->StringPkgHdr.Flink; Link != &DatabaseRecord->StringPkgHdr; Link = Link->Flink) {
StringPackage = CR (Link, FAKE_HII_STRING_PACKAGE, Entry, FAKE_HII_STRING_PACKAGE_SIGNATURE);
ResultSize += strlena (StringPackage->StringPkgHdr->Language) + 1;
if (ResultSize <= *LanguagesSize) {
strcpya (Languages, StringPackage->StringPkgHdr->Language);
Languages += strlena (StringPackage->StringPkgHdr->Language) + 1;
*(Languages - 1) = L';';
}
}
if (ResultSize == 0) {
return EFI_NOT_FOUND;
}
if (*LanguagesSize < ResultSize) {
*LanguagesSize = ResultSize;
return EFI_BUFFER_TOO_SMALL;
}
*(Languages - 1) = 0;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FakeHiiGetSecondaryLanguages (
IN CONST EFI_HII_STRING_PROTOCOL *This,
IN EFI_HII_HANDLE PackageList,
IN CONST CHAR8 *FirstLanguage,
IN OUT CHAR8 *SecondLanguages,
IN OUT UINTN *SecondLanguagesSize
)
{
return EFI_UNSUPPORTED;
}
#else
EFI_STATUS
FakeGetPackSize (
IN VOID *Pack,
OUT UINTN *PackSize,
OUT UINT32 *NumberOfTokens
)
/*++
Routine Description:
Determines the passed in Pack's size and returns the value.
Arguments:
Pack - The package
PackSize - The package size
NumberOfTokens - The tokens number
Returns:
EFI_SUCCESS - Success
EFI_NOT_FOUND - Not found
--*/
{
EFI_HII_STRING_PACK *StringPack;
UINT16 Type;
UINT32 Length;
*PackSize = 0;
Type = EFI_HII_IFR;
if (!CompareMem (&((EFI_HII_PACK_HEADER *) Pack)->Type, &Type, sizeof (UINT16))) {
//
// The header contains the full IFR length
//
CopyMem (&Length, &((EFI_HII_PACK_HEADER *) Pack)->Length, sizeof (Length));
*PackSize = (UINTN) Length;
return EFI_SUCCESS;
}
Type = EFI_HII_STRING;
if (!CompareMem (&((EFI_HII_PACK_HEADER *) Pack)->Type, &Type, sizeof (UINT16))) {
//
// The header contains the STRING package length
// The assumption is that the strings for all languages
// are a contiguous block of data and there is a series of
// these package instances which will terminate with a NULL package
// instance.
//
StringPack = (EFI_HII_STRING_PACK *) Pack;
//
// There may be multiple instances packed together of strings
// so we must walk the self describing structures until we encounter
// the NULL structure to determine the full size.
//
CopyMem (&Length, &StringPack->Header.Length, sizeof (Length));
if (NumberOfTokens != NULL) {
CopyMem (NumberOfTokens, &StringPack->NumStringPointers, sizeof (UINT32));
}
while (Length != 0) {
*PackSize = *PackSize + Length;
StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) StringPack + Length);
CopyMem (&Length, &StringPack->Header.Length, sizeof (Length));
}
//
// Encountered a length of 0, so let's add the space for the NULL terminator
// pack's length and call it done.
//
*PackSize = *PackSize + sizeof (EFI_HII_STRING_PACK);
return EFI_SUCCESS;
}
//
// We only determine the size of the non-global Package types.
// If neither IFR or STRING data were found, return an error
//
return EFI_NOT_FOUND;
}
EFI_STATUS
FakeValidatePack (
IN EFI_HII_PROTOCOL *This,
IN EFI_FAKE_HII_PACKAGE_INSTANCE *PackageInstance,
OUT EFI_FAKE_HII_PACKAGE_INSTANCE **StringPackageInstance,
OUT UINT32 *TotalStringCount
)
/*++
Routine Description:
Verifies that the package instance is using the correct handle for string operations.
Arguments:
This - This protocol
PackageInstance - The package instance
StringPackageInstance - The string pacakge instance
TotalStringCount - The total string count
Returns:
EFI_INVALID_PARAMETER - Invalid parameter
EFI_SUCCESS - Success
--*/
{
EFI_FAKE_HII_DATA *HiiData;
EFI_FAKE_HII_HANDLE_DATABASE *HandleDatabase;
EFI_FAKE_HII_PACKAGE_INSTANCE *HandlePackageInstance;
UINT8 *RawData;
EFI_GUID Guid;
EFI_HII_IFR_PACK *FormPack;
UINTN Index;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
HiiData = EFI_FAKE_HII_DATA_FROM_THIS (This);
HandleDatabase = HiiData->DatabaseHead;
ZeroMem (&Guid, sizeof (EFI_GUID));
*StringPackageInstance = PackageInstance;
//
// Based on if there is IFR data in this package instance, determine
// what the location is of the beginning of the string data.
//
if (PackageInstance->IfrSize > 0) {
FormPack = (EFI_HII_IFR_PACK *) ((CHAR8 *) (&PackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER));
} else {
//
// If there is no IFR data assume the caller knows what they are doing.
//
return EFI_SUCCESS;
}
RawData = (UINT8 *) FormPack;
for (Index = 0; RawData[Index] != EFI_IFR_END_FORM_SET_OP;) {
if (RawData[Index] == EFI_IFR_FORM_SET_OP) {
//
// Cache the guid for this formset
//
CopyMem (&Guid, &((EFI_IFR_FORM_SET *) &RawData[Index])->Guid, sizeof (EFI_GUID));
break;
}
Index = RawData[Index + 1] + Index;
}
//
// If there is no string package, and the PackageInstance->IfrPack.Guid and PackageInstance->Guid are
// different, we should return the correct handle for the caller to use for strings.
//
if ((PackageInstance->StringSize == 0) && (CompareGuid (&Guid, &PackageInstance->Guid) != 0)) {
//
// Search the database for a handle that matches the PackageInstance->Guid
//
for (; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {
//
// Get Ifrdata and extract the Guid for it
//
HandlePackageInstance = HandleDatabase->Buffer;
ASSERT (HandlePackageInstance->IfrSize != 0);
FormPack = (EFI_HII_IFR_PACK *) ((CHAR8 *) (&HandlePackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER));
RawData = (UINT8 *) FormPack;
for (Index = 0; RawData[Index] != EFI_IFR_END_FORM_SET_OP;) {
if (RawData[Index] == EFI_IFR_FORM_SET_OP) {
//
// Cache the guid for this formset
//
CopyMem (&Guid, &((EFI_IFR_FORM_SET *) &RawData[Index])->Guid, sizeof (EFI_GUID));
break;
}
Index = RawData[Index + 1] + Index;
}
//
// If the Guid from the new handle matches the original Guid referenced in the original package data
// return the appropriate package instance data to use.
//
if (CompareGuid (&Guid, &PackageInstance->Guid) == 0) {
if (TotalStringCount != NULL) {
*TotalStringCount = HandleDatabase->NumberOfTokens;
}
*StringPackageInstance = HandlePackageInstance;
}
}
//
// end for
//
} else {
return EFI_SUCCESS;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FakeHiiNewPack (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_PACKAGES *Packages,
OUT EFI_HII_HANDLE *Handle
)
/*++
Routine Description:
Extracts the various packs from a package list.
Arguments:
This - This protocol
Packages - The padckages
Handle - The handle
Returns:
EFI_INVALID_PARAMETER - Invalid parameter
EFI_SUCCESS - Success
--*/
{
EFI_FAKE_HII_PACKAGE_INSTANCE *PackageInstance;
EFI_FAKE_HII_DATA *HiiData;
EFI_FAKE_HII_HANDLE_DATABASE *HandleDatabase;
EFI_FAKE_HII_HANDLE_DATABASE *Database;
EFI_FAKE_HII_GLOBAL_DATA *GlobalData;
EFI_HII_PACK_HEADER *PackageHeader;
EFI_HII_IFR_PACK *IfrPack;
EFI_HII_STRING_PACK *StringPack;
EFI_HII_HANDLE_PACK *Handlepack;
EFI_HII_FONT_PACK *FontPack;
EFI_HII_KEYBOARD_PACK *KeyboardPack;
EFI_STATUS Status;
UINTN IfrSize;
UINTN StringSize;
UINTN TotalStringSize;
UINTN InstanceSize;
UINTN Count;
UINTN Index;
UINT16 Member;
EFI_GUID Guid;
EFI_FORM_SET_STUB FormSetStub;
UINT8 *Location;
UINT16 Unicode;
UINT16 NumWideGlyphs;
UINT16 NumNarrowGlyphs;
UINT32 NumberOfTokens;
UINT32 TotalTokenNumber;
UINT8 *Local;
EFI_NARROW_GLYPH *NarrowGlyph;
EFI_WIDE_GLYPH *WideGlyph;
if (Packages->NumberOfPackages == 0 || This == NULL) {
return EFI_INVALID_PARAMETER;
}
HiiData = EFI_FAKE_HII_DATA_FROM_THIS (This);
GlobalData = HiiData->GlobalData;
Database = HiiData->DatabaseHead;
PackageInstance = NULL;
IfrPack = NULL;
StringPack = NULL;
InstanceSize = 0;
IfrSize = 0;
StringSize = 0;
TotalStringSize = 0;
NumberOfTokens = 0;
TotalTokenNumber = 0;
//
// Search through the passed in Packages for the IfrPack and any StringPack.
//
for (Index = 0; Index < Packages->NumberOfPackages; Index++) {
PackageHeader = *(EFI_HII_PACK_HEADER **) (((UINT8 *) Packages) + sizeof (EFI_HII_PACKAGES) + Index * sizeof (VOID *));
switch (PackageHeader->Type) {
case EFI_HII_IFR:
//
// There shoule be only one Ifr package.
//
ASSERT (IfrPack == NULL);
IfrPack = (EFI_HII_IFR_PACK *) PackageHeader;
break;
case EFI_HII_STRING:
StringPack = (EFI_HII_STRING_PACK *) PackageHeader;
//
// Sending me a String Package. Get its size.
//
Status = FakeGetPackSize ((VOID *) StringPack, &StringSize, &NumberOfTokens);
ASSERT (!EFI_ERROR (Status));
//
// The size which FakeGetPackSize() returns include the null terminator. So if multiple
// string packages are passed in, merge all these packages, and only pad one null terminator.
//
if (TotalStringSize > 0) {
TotalStringSize -= sizeof (EFI_HII_STRING_PACK);
}
TotalStringSize += StringSize;
TotalTokenNumber += NumberOfTokens;
break;
}
}
//
// If sending a StringPack without an IfrPack, you must include a GuidId
//
if ((StringPack != NULL) && (IfrPack == NULL)) {
if (Packages->GuidId == NULL) {
return EFI_INVALID_PARAMETER;
}
}
//
// If passing in an IfrPack and a GuidId is provided, ensure they are the same value.
//
if ((IfrPack != NULL) && (Packages->GuidId != NULL)) {
Location = ((UINT8 *) IfrPack);
Location = (UINT8 *) (((UINTN) Location) + sizeof (EFI_HII_PACK_HEADER));
//
// Advance to the Form Set Op-code
//
for (Count = 0; ((EFI_IFR_OP_HEADER *) &Location[Count])->OpCode != EFI_IFR_FORM_SET_OP;) {
Count = Count + ((EFI_IFR_OP_HEADER *) &Location[Count])->Length;
}
//
// Copy to local variable
//
CopyMem (&Guid, &((EFI_IFR_FORM_SET *) &Location[Count])->Guid, sizeof (EFI_GUID));
//
// Check to see if IfrPack->Guid != GuidId
//
if (CompareGuid (&Guid, Packages->GuidId) != 0) {
//
// If a string package is present, the GUIDs should have agreed. Return an error
//
if (StringPack != NULL) {
return EFI_INVALID_PARAMETER;
}
}
}
//
// If someone is passing in a string only, create a dummy IfrPack with a Guid
// to enable future searching of this data.
//
if ((IfrPack == NULL) && (StringPack != NULL)) {
ZeroMem (&FormSetStub, sizeof (FormSetStub));
FormSetStub.Header.Type = EFI_HII_IFR;
FormSetStub.Header.Length = sizeof (EFI_FORM_SET_STUB);
FormSetStub.FormSet.Header.OpCode = EFI_IFR_FORM_SET_OP;
FormSetStub.FormSet.Header.Length = (UINT8) sizeof (EFI_IFR_FORM_SET);
//
// Dummy string
//
FormSetStub.FormSet.FormSetTitle = 0x02;
CopyMem (&FormSetStub.FormSet.Guid, Packages->GuidId, sizeof (EFI_GUID));
FormSetStub.EndFormSet.Header.OpCode = EFI_IFR_END_FORM_SET_OP;
FormSetStub.EndFormSet.Header.Length = (UINT8) sizeof (EFI_IFR_END_FORM_SET);
IfrPack = (EFI_HII_IFR_PACK *) &FormSetStub;
}
if (IfrPack != NULL) {
//
// Sending me an IFR Package. Get its size.
//
Status = FakeGetPackSize ((VOID *) IfrPack, &IfrSize, NULL);
ASSERT (!EFI_ERROR (Status));
}
//
// Prepare the internal package instace buffer to store package data.
//
InstanceSize = IfrSize + TotalStringSize;
if (InstanceSize != 0) {
PackageInstance = AllocateZeroPool (InstanceSize + sizeof (EFI_FAKE_HII_PACKAGE_INSTANCE));
ASSERT (PackageInstance);
//
// If there is no DatabaseHead allocated - allocate one
//
if (HiiData->DatabaseHead == NULL) {
HiiData->DatabaseHead = AllocateZeroPool (sizeof (EFI_FAKE_HII_HANDLE_DATABASE));
ASSERT (HiiData->DatabaseHead);
}
//
// If the head is being used (Handle is non-zero), allocate next Database and
// add it to the linked-list
//
if (HiiData->DatabaseHead->Handle != 0) {
HandleDatabase = AllocateZeroPool (sizeof (EFI_FAKE_HII_HANDLE_DATABASE));
ASSERT (HandleDatabase);
for (; Database->NextHandleDatabase != NULL; Database = Database->NextHandleDatabase)
;
//
// We are sitting on the Database entry which contains the null Next pointer. Fix it.
//
Database->NextHandleDatabase = HandleDatabase;
}
Database = HiiData->DatabaseHead;
//
// Initialize this instance data
//
for (*Handle = 1; Database->NextHandleDatabase != NULL; Database = Database->NextHandleDatabase) {
//
// Since the first Database instance will have a passed back handle of 1, we will continue
// down the linked list of entries until we encounter the end of the linked list. Each time
// we go down one level deeper, increment the handle value that will be passed back.
//
if (Database->Handle >= *Handle) {
*Handle = Database->Handle + 1;
}
}
PackageInstance->Handle = *Handle;
PackageInstance->IfrSize = IfrSize;
PackageInstance->StringSize = TotalStringSize;
if (Packages->GuidId != NULL) {
CopyMem (&PackageInstance->Guid, Packages->GuidId, sizeof (EFI_GUID));
}
Database->Buffer = PackageInstance;
Database->Handle = PackageInstance->Handle;
Database->NumberOfTokens = TotalTokenNumber;
Database->NextHandleDatabase = NULL;
}
//
// Copy the Ifr package data into package instance.
//
if (IfrSize > 0) {
CopyMem (&PackageInstance->IfrData, IfrPack, IfrSize);
}
//
// Main loop to store package data into HII database.
//
StringSize = 0;
TotalStringSize = 0;
for (Index = 0; Index < Packages->NumberOfPackages; Index++) {
PackageHeader = *(EFI_HII_PACK_HEADER **) (((UINT8 *) Packages) + sizeof (EFI_HII_PACKAGES) + Index * sizeof (VOID *));
switch (PackageHeader->Type) {
case EFI_HII_STRING:
StringPack = (EFI_HII_STRING_PACK *) PackageHeader;
//
// The size which FakeGetPackSize() returns include the null terminator. So if multiple
// string packages are passed in, merge all these packages, and only pad one null terminator.
//
if (TotalStringSize > 0) {
TotalStringSize -= sizeof (EFI_HII_STRING_PACK);
}
FakeGetPackSize ((VOID *) StringPack, &StringSize, &NumberOfTokens);
CopyMem ((CHAR8 *) (&PackageInstance->IfrData) + IfrSize + TotalStringSize, StringPack, StringSize);
TotalStringSize += StringSize;
break;
case EFI_HII_HANDLES:
Handlepack = (EFI_HII_HANDLE_PACK *) PackageHeader;
CopyMem (&PackageInstance->HandlePack, Handlepack, sizeof(EFI_HII_HANDLE_PACK));
break;
case EFI_HII_FONT:
FontPack = (EFI_HII_FONT_PACK *) PackageHeader;
//
// Add whatever narrow glyphs were passed to us if undefined
//
CopyMem (&NumNarrowGlyphs, &FontPack->NumberOfNarrowGlyphs, sizeof (UINT16));
for (Count = 0; Count <= NumNarrowGlyphs; Count++) {
Local = (UINT8 *) (&FontPack->NumberOfWideGlyphs + sizeof (UINT8)) + (sizeof (EFI_NARROW_GLYPH)) * Count;
NarrowGlyph = (EFI_NARROW_GLYPH *) Local;
CopyMem (&Member, &NarrowGlyph->UnicodeWeight, sizeof (UINT16));
//
// If the glyph is already defined, do not overwrite it. It is what it is.
//
CopyMem (&Unicode, &GlobalData->NarrowGlyphs[Member].UnicodeWeight, sizeof (UINT16));
if (Unicode == 0) {
CopyMem (&GlobalData->NarrowGlyphs[Member], Local, sizeof (EFI_NARROW_GLYPH));
}
}
//
// Add whatever wide glyphs were passed to us if undefined
//
CopyMem (&NumWideGlyphs, &FontPack->NumberOfWideGlyphs, sizeof (UINT16));
for (Count = 0; Count <= NumWideGlyphs; Count++) {
Local = (UINT8 *) (&FontPack->NumberOfWideGlyphs + sizeof (UINT8)) +
(sizeof (EFI_NARROW_GLYPH)) *
NumNarrowGlyphs;
WideGlyph = (EFI_WIDE_GLYPH *) Local;
CopyMem (
&Member,
(UINTN *) (Local + sizeof (EFI_WIDE_GLYPH) * Count),
sizeof (UINT16)
);
//
// If the glyph is already defined, do not overwrite it. It is what it is.
//
CopyMem (&Unicode, &GlobalData->WideGlyphs[Member].UnicodeWeight, sizeof (UINT16));
if (Unicode == 0) {
Local = (UINT8 *) (&FontPack->NumberOfWideGlyphs + sizeof (UINT8)) +
(sizeof (EFI_NARROW_GLYPH)) *
NumNarrowGlyphs;
WideGlyph = (EFI_WIDE_GLYPH *) Local;
CopyMem (
&GlobalData->WideGlyphs[Member],
(UINTN *) (Local + sizeof (EFI_WIDE_GLYPH) * Count),
sizeof (EFI_WIDE_GLYPH)
);
}
}
break;
case EFI_HII_KEYBOARD:
KeyboardPack = (EFI_HII_KEYBOARD_PACK *) PackageHeader;
//
// Sending me a Keyboard Package
//
if (KeyboardPack->DescriptorCount > 105) {
return EFI_INVALID_PARAMETER;
}
//
// If someone updates the Descriptors with a count of 0, blow aware the overrides.
//
if (KeyboardPack->DescriptorCount == 0) {
ZeroMem (GlobalData->OverrideKeyboardLayout, sizeof (EFI_KEY_DESCRIPTOR) * 106);
}
if (KeyboardPack->DescriptorCount < 106 && KeyboardPack->DescriptorCount > 0) {
//
// If SystemKeyboard was updated already, then steer changes to the override database
//
if (GlobalData->SystemKeyboardUpdate) {
ZeroMem (GlobalData->OverrideKeyboardLayout, sizeof (EFI_KEY_DESCRIPTOR) * 106);
for (Count = 0; Count < KeyboardPack->DescriptorCount; Count++) {
CopyMem (&Member, &KeyboardPack->Descriptor[Count].Key, sizeof (UINT16));
CopyMem (
&GlobalData->OverrideKeyboardLayout[Member],
&KeyboardPack->Descriptor[Count],
sizeof (EFI_KEY_DESCRIPTOR)
);
}
} else {
//
// SystemKeyboard was never updated, so this is likely the keyboard driver setting the System database.
//
ZeroMem (GlobalData->SystemKeyboardLayout, sizeof (EFI_KEY_DESCRIPTOR) * 106);
for (Count = 0; Count < KeyboardPack->DescriptorCount; Count++) {
CopyMem (&Member, &KeyboardPack->Descriptor->Key, sizeof (UINT16));
CopyMem (
&GlobalData->SystemKeyboardLayout[Member],
&KeyboardPack->Descriptor[Count],
sizeof (EFI_KEY_DESCRIPTOR)
);
}
//
// Just updated the system keyboard database, reflect that in the global flag.
//
GlobalData->SystemKeyboardUpdate = TRUE;
}
}
break;
default:
break;
}
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FakeHiiRemovePack (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_HANDLE Handle
)
/*++
Routine Description:
Removes the various packs from a Handle
Arguments:
This - This protocol
Handle - The handle
Returns:
EFI_INVALID_PARAMETER - Invalid parameter
EFI_SUCCESS - Success
--*/
{
EFI_FAKE_HII_PACKAGE_INSTANCE *PackageInstance;
EFI_FAKE_HII_DATA *HiiData;
EFI_FAKE_HII_HANDLE_DATABASE *HandleDatabase;
EFI_FAKE_HII_HANDLE_DATABASE *PreviousHandleDatabase;
UINTN Count;
if (This == NULL || Handle == 0) {
return EFI_INVALID_PARAMETER;
}
HiiData = EFI_FAKE_HII_DATA_FROM_THIS (This);
HandleDatabase = HiiData->DatabaseHead;
PackageInstance = NULL;
//
// Initialize the Previous with the Head of the Database
//
PreviousHandleDatabase = HandleDatabase;
for (Count = 0; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {
//
// Match the numeric value with the database entry - if matched,
// free the package instance and apply fix-up to database linked list
//
if (Handle == HandleDatabase->Handle) {
PackageInstance = HandleDatabase->Buffer;
//
// Free the Package Instance
//
FreePool (PackageInstance);
//
// If this was the only Handle in the database
//
if (HiiData->DatabaseHead == HandleDatabase) {
HiiData->DatabaseHead = NULL;
}
//
// Make the parent->Next point to the current->Next
//
PreviousHandleDatabase->NextHandleDatabase = HandleDatabase->NextHandleDatabase;
FreePool (HandleDatabase);
return EFI_SUCCESS;
}
//
// If this was not the HandleDatabase entry we were looking for, cache it just in case the next one is
//
PreviousHandleDatabase = HandleDatabase;
}
//
// No handle was found - error condition
//
if (PackageInstance == NULL) {
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FakeHiiFindHandles (
IN EFI_HII_PROTOCOL *This,
IN OUT UINT16 *HandleBufferLength,
OUT EFI_HII_HANDLE *Handle
)
/*++
Routine Description:
Determines the handles that are currently active in the database.
Arguments:
This - This protocol
HandleBufferLength - Buffer length
Handle - The handle
Returns:
EFI_INVALID_PARAMETER - Invalid parameter
EFI_NOT_FOUND - Not found
EFI_SUCCESS - Success
EFI_BUFFER_TOO_SMALL - Buffer too small
--*/
{
EFI_FAKE_HII_GLOBAL_DATA *GlobalData;
EFI_FAKE_HII_HANDLE_DATABASE *Database;
EFI_FAKE_HII_DATA *HiiData;
UINTN HandleCount;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
HiiData = EFI_FAKE_HII_DATA_FROM_THIS (This);
GlobalData = HiiData->GlobalData;
Database = HiiData->DatabaseHead;
if (Database == NULL) {
*HandleBufferLength = 0;
return EFI_NOT_FOUND;
}
for (HandleCount = 0; Database != NULL; HandleCount++) {
Database = Database->NextHandleDatabase;
}
//
// Is there a sufficient buffer for the data being passed back?
//
if (*HandleBufferLength >= (sizeof (EFI_HII_HANDLE) * HandleCount)) {
Database = HiiData->DatabaseHead;
//
// Copy the Head information
//
if (Database->Handle != 0) {
CopyMem (&Handle[0], &Database->Handle, sizeof (EFI_HII_HANDLE));
Database = Database->NextHandleDatabase;
}
//
// Copy more data if appropriate
//
for (HandleCount = 1; Database != NULL; HandleCount++) {
CopyMem (&Handle[HandleCount], &Database->Handle, sizeof (EFI_HII_HANDLE));
Database = Database->NextHandleDatabase;
}
*HandleBufferLength = (UINT16) (sizeof (EFI_HII_HANDLE) * HandleCount);
return EFI_SUCCESS;
} else {
//
// Insufficient buffer length
//
*HandleBufferLength = (UINT16) (sizeof (EFI_HII_HANDLE) * HandleCount);
return EFI_BUFFER_TOO_SMALL;
}
}
EFI_STATUS
FakeCompareLanguage (
IN CHAR16 *LanguageStringLocation,
IN CHAR16 *Language
)
{
UINT8 *Local;
UINTN Index;
CHAR16 *InputString;
CHAR16 *OriginalInputString;
//
// Allocate a temporary buffer for InputString
//
InputString = AllocateZeroPool (0x100);
ASSERT (InputString);
OriginalInputString = InputString;
Local = (UINT8 *) LanguageStringLocation;
//
// Determine the size of this packed string safely (e.g. access by byte), post-increment
// to include the null-terminator
//
for (Index = 0; Local[Index] != 0; Index += 2)
;
//
// This is a packed structure that this location comes from, so let's make sure
// the value is aligned by copying it to a local variable and working on it.
//
CopyMem (InputString, LanguageStringLocation, Index);
for (Index = 0; Index < 3; Index++) {
InputString[Index] = (CHAR16) (InputString[Index] | 0x20);
Language[Index] = (CHAR16) (Language[Index] | 0x20);
}
//
// If the Language is the same return success
//
if (CompareMem (LanguageStringLocation, Language, 6) == 0) {
FreePool (InputString);
return EFI_SUCCESS;
}
//
// Skip the first three letters that comprised the primary language,
// see if what is being compared against is a secondary language
//
InputString = InputString + 3;
//
// If the Language is not the same as the Primary language, see if there are any
// secondary languages, and if there are see if we have a match. If not, return an error.
//
for (Index = 0; InputString[Index] != 0; Index = Index + 3) {
//
// Getting in here means we have a secondary language
//
if (CompareMem (&InputString[Index], Language, 6) == 0) {
FreePool (InputString);
return EFI_SUCCESS;
}
}
//
// If nothing was found, return the error
//
FreePool (OriginalInputString);
return EFI_NOT_FOUND;
}
VOID
FakeAsciiToUnicode (
IN UINT8 *Lang,
IN UINT16 *Language
)
{
UINT8 Count;
for (Count = 0; Count < 3; Count++) {
Language[Count] = (CHAR16) Lang[Count];
}
}
EFI_STATUS
EFIAPI
FakeHiiGetString (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN STRING_REF Token,
IN BOOLEAN Raw,
IN CHAR16 *LanguageString,
IN OUT UINTN *BufferLength,
OUT EFI_STRING StringBuffer
)
/*++
Routine Description:
This function extracts a string from a package already registered with the EFI HII database.
Arguments:
This - This protocol
Handle - Handle
Token - The Token
Raw - The raw data
LanguageString - The language string
BufferLength - The buffer length
StringBuffer - The string buffer
Returns:
EFI_INVALID_PARAMETER - Invalid parameter
EFI_SUCCESS - Success
EFI_BUFFER_TOO_SMALL - Buffer too small
--*/
{
INTN Count;
EFI_FAKE_HII_PACKAGE_INSTANCE *PackageInstance;
EFI_FAKE_HII_PACKAGE_INSTANCE *StringPackageInstance;
EFI_FAKE_HII_DATA *HiiData;
EFI_FAKE_HII_HANDLE_DATABASE *HandleDatabase;
EFI_HII_STRING_PACK *StringPack;
RELOFST *StringPointer;
EFI_STATUS Status;
EFI_STRING OriginalStringBuffer;
UINTN DataSize;
CHAR8 Lang[3];
CHAR16 Language[3];
UINT32 Length;
INTN Index;
RELOFST Offset;
UINT16 *Local;
UINT16 Zero;
UINT16 Narrow;
UINT16 Wide;
UINT16 NoBreak;
BOOLEAN LangFound;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
LangFound = TRUE;
DataSize = sizeof (Lang);
HiiData = EFI_FAKE_HII_DATA_FROM_THIS (This);
PackageInstance = NULL;
Zero = 0;
Narrow = NARROW_CHAR;
Wide = WIDE_CHAR;
NoBreak = NON_BREAKING_CHAR;
//
// Check numeric value against the head of the database
//
for (HandleDatabase = HiiData->DatabaseHead;
HandleDatabase != NULL;
HandleDatabase = HandleDatabase->NextHandleDatabase
) {
//
// Match the numeric value with the database entry - if matched, extract PackageInstance
//
if (Handle == HandleDatabase->Handle) {
PackageInstance = HandleDatabase->Buffer;
break;
}
}
//
// No handle was found - error condition
//
if (PackageInstance == NULL) {
return EFI_INVALID_PARAMETER;
}
Status = FakeValidatePack (This, PackageInstance, &StringPackageInstance, NULL);
//
// If there is no specified language, assume the system default language
//
if (LanguageString == NULL) {
//
// Get system default language
//
Status = RT->GetVariable (
L"Lang",
&gEfiGlobalVariableGuid,
NULL,
&DataSize,
Lang
);
if (EFI_ERROR (Status)) {
//
// If Lang doesn't exist, just use the first language you find
//
LangFound = FALSE;
goto LangNotFound;
}
//
// Convert the ASCII Lang variable to a Unicode Language variable
//
FakeAsciiToUnicode (Lang, Language);
} else {
//
// Copy input ISO value to Language variable
//
CopyMem (Language, LanguageString, 6);
}
//
// Based on if there is IFR data in this package instance, determine
// what the location is of the beginning of the string data.
//
LangNotFound:
if (StringPackageInstance->IfrSize > 0) {
StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (&StringPackageInstance->IfrData) + StringPackageInstance->IfrSize);
} else {
StringPack = (EFI_HII_STRING_PACK *) (&StringPackageInstance->IfrData);
}
//
// If Token is 0, extract entire string package
//
if (Token == 0) {
OriginalStringBuffer = StringBuffer;
CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));
//
// If trying to get the entire string package and have insufficient space. Return error
//
if (Length > *BufferLength) {
CopyMem (BufferLength, &Length, sizeof (UINT16));
return EFI_INVALID_PARAMETER;
}
for (; Length != 0;) {
CopyMem (StringBuffer, StringPack, Length);
StringBuffer = (CHAR16 *) ((CHAR8 *) (StringBuffer) + Length);
StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Length);
CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));
}
StringBuffer = OriginalStringBuffer;
return EFI_SUCCESS;
}
//
// There may be multiple instances packed together of strings
// so we must walk the self describing structures until we encounter
// what we are looking for, and then extract the string we are looking for
//
CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));
for (; Length != 0;) {
//
// If passed in Language ISO value is in this string pack's language string
// then we are dealing with the strings we want.
//
CopyMem (&Offset, &StringPack->LanguageNameString, sizeof (RELOFST));
Status = FakeCompareLanguage ((CHAR16 *) ((CHAR8 *) (StringPack) + Offset), Language);
//
// If we cannot find the lang variable, we skip this check and use the first language available
//
if (LangFound) {
if (EFI_ERROR (Status)) {
StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Length);
CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));
continue;
}
}
StringPointer = (RELOFST *) (StringPack + 1);
//
// We have the right string package - size it, and copy it to the StringBuffer
//
if (Token >= StringPack->NumStringPointers) {
return EFI_INVALID_PARAMETER;
} else {
CopyMem (&Offset, &StringPointer[Token], sizeof (RELOFST));
}
//
// Since StringPack is a packed structure, we need to determine the string's
// size safely, thus byte-wise. Post-increment the size to include the null-terminator
//
Local = (CHAR16 *) ((CHAR8 *) (StringPack) + Offset);
for (Count = 0; CompareMem (&Local[Count], &Zero, 2); Count++)
;
Count++;
Count = Count * sizeof (CHAR16);;
if (*BufferLength >= (UINTN) Count) {
//
// Copy the string to the user's buffer
//
if (Raw) {
CopyMem (StringBuffer, (VOID *) ((CHAR8 *) (StringPack) + Offset), Count);
} else {
Index = 0;
Count = -1;
do {
Count++;
for (;
CompareMem ((CHAR16 *) ((CHAR8 *) (StringPack) + Offset + Count * 2), &Narrow, 2) && CompareMem (
(CHAR16 *) ((CHAR8 *) (StringPack) + Offset + Count * 2),
&Wide,
2
) && CompareMem ((CHAR16 *) ((CHAR8 *) (StringPack) + Offset + Count * 2), &NoBreak, 2) && CompareMem (
(CHAR16 *) ((CHAR8 *) (StringPack) + Offset + Count * 2),
&Zero,
2
);
Index++, Count++
) {
CopyMem (&StringBuffer[Index], (VOID *) ((CHAR8 *) (StringPack) + Offset + Count * 2), 2);
}
} while (CompareMem ((CHAR16 *) ((CHAR8 *) (StringPack) + Offset + Count * 2), &Zero, 2));
CopyMem (&StringBuffer[Index], (VOID *) ((CHAR8 *) (StringPack) + Offset + Count * 2), 2);
for (Count = 0; StringBuffer[Count] != 0; Count++)
;
Count++;
Count = Count * 2;
}
*BufferLength = (UINTN) Count;
return EFI_SUCCESS;
} else {
*BufferLength = (UINTN) Count;
return EFI_BUFFER_TOO_SMALL;
}
}
LangFound = FALSE;
goto LangNotFound;
}
EFI_STATUS
EFIAPI
FakeHiiGetPrimaryLanguages (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
OUT EFI_STRING *LanguageString
)
/*++
Routine Description:
This function allows a program to determine what the primary languages that are supported on a given handle.
Arguments:
This - This protocol
Handle - THe handle
LanguageString - The language string
Returns:
EFI_INVALID_PARAMETER - The invalid parameter
EFI_SUCCESS - Success
--*/
{
UINTN Count;
EFI_FAKE_HII_PACKAGE_INSTANCE *PackageInstance;
EFI_FAKE_HII_PACKAGE_INSTANCE *StringPackageInstance;
EFI_FAKE_HII_DATA *HiiData;
EFI_FAKE_HII_HANDLE_DATABASE *HandleDatabase;
EFI_HII_STRING_PACK *StringPack;
EFI_HII_STRING_PACK *Location;
UINT32 Length;
RELOFST Token;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
HiiData = EFI_FAKE_HII_DATA_FROM_THIS (This);
PackageInstance = NULL;
//
// Find matching handle in the handle database. Then get the package instance.
//
for (HandleDatabase = HiiData->DatabaseHead;
HandleDatabase != NULL;
HandleDatabase = HandleDatabase->NextHandleDatabase
) {
if (Handle == HandleDatabase->Handle) {
PackageInstance = HandleDatabase->Buffer;
}
}
//
// No handle was found - error condition
//
if (PackageInstance == NULL) {
return EFI_INVALID_PARAMETER;
}
FakeValidatePack (This, PackageInstance, &StringPackageInstance, NULL);
//
// Based on if there is IFR data in this package instance, determine
// what the location is of the beginning of the string data.
//
if (StringPackageInstance->IfrSize > 0) {
StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (&StringPackageInstance->IfrData) + StringPackageInstance->IfrSize);
} else {
StringPack = (EFI_HII_STRING_PACK *) (&StringPackageInstance->IfrData);
}
Location = StringPack;
//
// Remember that the string packages are formed into contiguous blocks of language data.
//
CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));
for (Count = 0; Length != 0; Count = Count + 3) {
StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Length);
CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));
}
*LanguageString = AllocateZeroPool (2 * (Count + 1));
ASSERT (*LanguageString);
StringPack = (EFI_HII_STRING_PACK *) Location;
//
// Copy the 6 bytes to LanguageString - keep concatenating it. Shouldn't we just store uint8's since the ISO
// standard defines the lettering as all US English characters anyway? Save a few bytes.
//
CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));
for (Count = 0; Length != 0; Count = Count + 3) {
CopyMem (&Token, &StringPack->LanguageNameString, sizeof (RELOFST));
CopyMem (*LanguageString + Count, (VOID *) ((CHAR8 *) (StringPack) + Token), 6);
StringPack = (EFI_HII_STRING_PACK *) ((CHAR8 *) (StringPack) + Length);
CopyMem (&Length, &StringPack->Header.Length, sizeof (UINT32));
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FakeHiiGetForms (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN EFI_FORM_ID FormId,
IN OUT UINTN *BufferLength,
OUT UINT8 *Buffer
)
/*++
Routine Description:
This function allows a program to extract a form or form package that has
previously been registered with the EFI HII database.
Arguments:
This - This protocol
Handle - The handle
FormId - The formId
BufferLength - The Buffer length
Buffer - The Buffer
Returns:
EFI_INVALID_PARAMETER - The Invalid parameter
EFI_NOT_FOUND - Not found
EFI_SUCCESS - Success
EFI_BUFFER_TOO_SMALL - Buffer too small
--*/
{
EFI_FAKE_HII_PACKAGE_INSTANCE *PackageInstance;
EFI_FAKE_HII_DATA *HiiData;
EFI_FAKE_HII_HANDLE_DATABASE *HandleDatabase;
EFI_HII_IFR_PACK *FormPack;
EFI_IFR_FORM *Form;
EFI_IFR_OP_HEADER *Location;
if (This == NULL) {
return EFI_INVALID_PARAMETER;
}
HiiData = EFI_FAKE_HII_DATA_FROM_THIS (This);
HandleDatabase = HiiData->DatabaseHead;
PackageInstance = NULL;
//
// Check numeric value against the head of the database
//
for (; HandleDatabase != NULL; HandleDatabase = HandleDatabase->NextHandleDatabase) {
//
// Match the numeric value with the database entry - if matched, extract PackageInstance
//
if (Handle == HandleDatabase->Handle) {
PackageInstance = HandleDatabase->Buffer;
break;
}
}
//
// No handle was found - error condition
//
if (PackageInstance == NULL) {
return EFI_NOT_FOUND;
}
//
// Based on if there is IFR data in this package instance, determine
// what the location is of the beginning of the string data.
//
if (PackageInstance->IfrSize > 0) {
FormPack = (EFI_HII_IFR_PACK *) (&PackageInstance->IfrData);
} else {
//
// If there is no IFR data return an error
//
return EFI_NOT_FOUND;
}
//
// If requesting the entire Form Package
//
if (FormId == 0) {
//
// Return an error if buffer is too small
//
if (PackageInstance->IfrSize > *BufferLength) {
*BufferLength = (UINT16) PackageInstance->IfrSize;
return EFI_BUFFER_TOO_SMALL;
}
CopyMem (Buffer, FormPack, PackageInstance->IfrSize);
return EFI_SUCCESS;
} else {
FormPack = (EFI_HII_IFR_PACK *) ((CHAR8 *) (&PackageInstance->IfrData) + sizeof (EFI_HII_PACK_HEADER));
Location = (EFI_IFR_OP_HEADER *) FormPack;
//
// Look for the FormId requested
//
for (; Location->OpCode != EFI_IFR_END_FORM_SET_OP;) {
switch (Location->OpCode) {
case EFI_IFR_FORM_OP:
Form = (EFI_IFR_FORM *) Location;
//
// If we found a Form Op-code and it is of the correct Id, copy it and return
//
if (Form->FormId == FormId) {
if (Location->Length > *BufferLength) {
*BufferLength = Location->Length;
return EFI_BUFFER_TOO_SMALL;
} else {
for (; Location->OpCode != EFI_IFR_END_FORM_OP;) {
CopyMem (Buffer, Location, Location->Length);
Buffer = Buffer + Location->Length;
Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);
}
CopyMem (Buffer, Location, Location->Length);
return EFI_SUCCESS;
}
}
default:
break;
}
//
// Go to the next Op-Code
//
Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);
}
}
return EFI_SUCCESS;
}
EFI_STATUS
FakeHiiExportDatabase (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN OUT UINTN *BufferSize,
OUT VOID *Buffer
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
FakeHiiGetDefaultImage (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN UINTN DefaultMask,
OUT EFI_HII_VARIABLE_PACK_LIST **VariablePackList
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
FakeHiiGetGlyph (
IN EFI_HII_PROTOCOL *This,
IN CHAR16 *Source,
IN OUT UINT16 *Index,
OUT UINT8 **GlyphBuffer,
OUT UINT16 *BitWidth,
IN OUT UINT32 *InternalStatus
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
FakeHiiGetKeyboardLayout (
IN EFI_HII_PROTOCOL * This,
OUT UINT16 *DescriptorCount,
OUT EFI_KEY_DESCRIPTOR * Descriptor
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
FakeHiiGetLine (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN STRING_REF Token,
IN OUT UINT16 *Index,
IN UINT16 LineWidth,
IN CHAR16 *LanguageString,
IN OUT UINT16 *BufferLength,
OUT EFI_STRING StringBuffer
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
FakeHiiGetSecondaryLanguages (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN CHAR16 *PrimaryLanguage,
OUT EFI_STRING *LanguageString
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
FakeHiiGlyphToBlt (
IN EFI_HII_PROTOCOL *This,
IN UINT8 *GlyphBuffer,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
IN UINTN Count,
IN UINTN Width,
IN UINTN Height,
IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
FakeHiiNewString (
IN EFI_HII_PROTOCOL *This,
IN CHAR16 *Language,
IN EFI_HII_HANDLE Handle,
IN OUT STRING_REF *Reference,
IN CHAR16 *NewString
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
FakeHiiResetStrings (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_HANDLE Handle
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
FakeHiiTestString (
IN EFI_HII_PROTOCOL *This,
IN CHAR16 *StringToTest,
IN OUT UINT32 *FirstMissing,
OUT UINT32 *GlyphBufferSize
)
{
return EFI_UNSUPPORTED;
}
EFI_STATUS
FakeHiiUpdateForm (
IN EFI_HII_PROTOCOL *This,
IN EFI_HII_HANDLE Handle,
IN EFI_FORM_LABEL Label,
IN BOOLEAN AddData,
IN EFI_HII_UPDATE_DATA *Data
)
{
return EFI_UNSUPPORTED;
}
#endif
|