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
|
/** @file
This is an example of how a driver might export data to the HII protocol to be
later utilized by the Setup Protocol
Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
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.
**/
#include "DriverSample.h"
#define DISPLAY_ONLY_MY_ITEM 0x0002
CHAR16 VariableName[] = L"MyIfrNVData";
CHAR16 MyEfiVar[] = L"MyEfiVar";
EFI_HANDLE DriverHandle[2] = {NULL, NULL};
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData = NULL;
EFI_EVENT mEvent;
HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = {
{
{
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
(UINT8) (sizeof (VENDOR_DEVICE_PATH)),
(UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
}
},
DRIVER_SAMPLE_FORMSET_GUID
},
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{
(UINT8) (END_DEVICE_PATH_LENGTH),
(UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
}
}
};
HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = {
{
{
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
(UINT8) (sizeof (VENDOR_DEVICE_PATH)),
(UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
}
},
DRIVER_SAMPLE_INVENTORY_GUID
},
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{
(UINT8) (END_DEVICE_PATH_LENGTH),
(UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
}
}
};
/**
Add empty function for event process function.
@param Event The Event need to be process
@param Context The context of the event.
**/
VOID
EFIAPI
DriverSampleInternalEmptyFunction (
IN EFI_EVENT Event,
IN VOID *Context
)
{
}
/**
Notification function for keystrokes.
@param[in] KeyData The key that was pressed.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
EFIAPI
NotificationFunction(
IN EFI_KEY_DATA *KeyData
)
{
gBS->SignalEvent (mEvent);
return EFI_SUCCESS;
}
/**
Function to start monitoring for CTRL-C using SimpleTextInputEx.
@retval EFI_SUCCESS The feature is enabled.
@retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
**/
EFI_STATUS
EFIAPI
InternalStartMonitor(
VOID
)
{
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;
EFI_KEY_DATA KeyData;
EFI_STATUS Status;
EFI_HANDLE *Handles;
UINTN HandleCount;
UINTN HandleIndex;
EFI_HANDLE NotifyHandle;
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiSimpleTextInputExProtocolGuid,
NULL,
&HandleCount,
&Handles
);
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);
ASSERT_EFI_ERROR (Status);
KeyData.KeyState.KeyToggleState = 0;
KeyData.Key.ScanCode = 0;
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
KeyData.Key.UnicodeChar = L'c';
Status = SimpleEx->RegisterKeyNotify(
SimpleEx,
&KeyData,
NotificationFunction,
&NotifyHandle);
if (EFI_ERROR (Status)) {
break;
}
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
Status = SimpleEx->RegisterKeyNotify(
SimpleEx,
&KeyData,
NotificationFunction,
&NotifyHandle);
if (EFI_ERROR (Status)) {
break;
}
}
return EFI_SUCCESS;
}
/**
Function to stop monitoring for CTRL-C using SimpleTextInputEx.
@retval EFI_SUCCESS The feature is enabled.
@retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
**/
EFI_STATUS
EFIAPI
InternalStopMonitor(
VOID
)
{
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;
EFI_STATUS Status;
EFI_HANDLE *Handles;
EFI_KEY_DATA KeyData;
UINTN HandleCount;
UINTN HandleIndex;
EFI_HANDLE NotifyHandle;
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiSimpleTextInputExProtocolGuid,
NULL,
&HandleCount,
&Handles
);
for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);
ASSERT_EFI_ERROR (Status);
KeyData.KeyState.KeyToggleState = 0;
KeyData.Key.ScanCode = 0;
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
KeyData.Key.UnicodeChar = L'c';
Status = SimpleEx->RegisterKeyNotify(
SimpleEx,
&KeyData,
NotificationFunction,
&NotifyHandle);
if (!EFI_ERROR (Status)) {
Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);
}
KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
Status = SimpleEx->RegisterKeyNotify(
SimpleEx,
&KeyData,
NotificationFunction,
&NotifyHandle);
if (!EFI_ERROR (Status)) {
Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);
}
}
return EFI_SUCCESS;
}
/**
Encode the password using a simple algorithm.
@param Password The string to be encoded.
@param MaxSize The size of the string.
**/
VOID
EncodePassword (
IN CHAR16 *Password,
IN UINTN MaxSize
)
{
UINTN Index;
UINTN Loop;
CHAR16 *Buffer;
CHAR16 *Key;
Key = L"MAR10648567";
Buffer = AllocateZeroPool (MaxSize);
ASSERT (Buffer != NULL);
for (Index = 0; Key[Index] != 0; Index++) {
for (Loop = 0; Loop < (UINT8) (MaxSize / 2); Loop++) {
Buffer[Loop] = (CHAR16) (Password[Loop] ^ Key[Index]);
}
}
CopyMem (Password, Buffer, MaxSize);
FreePool (Buffer);
return ;
}
/**
Validate the user's password.
@param PrivateData This driver's private context data.
@param StringId The user's input.
@retval EFI_SUCCESS The user's input matches the password.
@retval EFI_NOT_READY The user's input does not match the password.
**/
EFI_STATUS
ValidatePassword (
IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData,
IN EFI_STRING_ID StringId
)
{
EFI_STATUS Status;
UINTN Index;
UINTN BufferSize;
UINTN PasswordMaxSize;
CHAR16 *Password;
CHAR16 *EncodedPassword;
BOOLEAN OldPassword;
//
// Get encoded password first
//
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
Status = gRT->GetVariable (
VariableName,
&gDriverSampleFormSetGuid,
NULL,
&BufferSize,
&PrivateData->Configuration
);
if (EFI_ERROR (Status)) {
//
// Old password not exist, prompt for new password
//
return EFI_SUCCESS;
}
OldPassword = FALSE;
PasswordMaxSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);
//
// Check whether we have any old password set
//
for (Index = 0; Index < PasswordMaxSize / sizeof (UINT16); Index++) {
if (PrivateData->Configuration.WhatIsThePassword2[Index] != 0) {
OldPassword = TRUE;
break;
}
}
if (!OldPassword) {
//
// Old password not exist, return EFI_SUCCESS to prompt for new password
//
return EFI_SUCCESS;
}
//
// Get user input password
//
Password = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL);
if (Password == NULL) {
return EFI_NOT_READY;
}
if (StrSize (Password) > PasswordMaxSize) {
FreePool (Password);
return EFI_NOT_READY;
}
//
// Validate old password
//
EncodedPassword = AllocateZeroPool (PasswordMaxSize);
ASSERT (EncodedPassword != NULL);
StrnCpy (EncodedPassword, Password, StrLen (Password));
EncodePassword (EncodedPassword, StrLen (EncodedPassword) * sizeof (CHAR16));
if (CompareMem (EncodedPassword, PrivateData->Configuration.WhatIsThePassword2, PasswordMaxSize) != 0) {
//
// Old password mismatch, return EFI_NOT_READY to prompt for error message
//
Status = EFI_NOT_READY;
} else {
Status = EFI_SUCCESS;
}
FreePool (Password);
FreePool (EncodedPassword);
return Status;
}
/**
Encode the password using a simple algorithm.
@param PrivateData This driver's private context data.
@param StringId The password from User.
@retval EFI_SUCESS The operation is successful.
@return Other value if gRT->SetVariable () fails.
**/
EFI_STATUS
SetPassword (
IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData,
IN EFI_STRING_ID StringId
)
{
EFI_STATUS Status;
CHAR16 *Password;
CHAR16 *TempPassword;
UINTN PasswordSize;
DRIVER_SAMPLE_CONFIGURATION *Configuration;
UINTN BufferSize;
//
// Get Buffer Storage data from EFI variable
//
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
Status = gRT->GetVariable (
VariableName,
&gDriverSampleFormSetGuid,
NULL,
&BufferSize,
&PrivateData->Configuration
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get user input password
//
Password = &PrivateData->Configuration.WhatIsThePassword2[0];
PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);
ZeroMem (Password, PasswordSize);
TempPassword = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL);
if (TempPassword == NULL) {
return EFI_NOT_READY;
}
if (StrSize (TempPassword) > PasswordSize) {
FreePool (TempPassword);
return EFI_NOT_READY;
}
StrnCpy (Password, TempPassword, StrLen (TempPassword));
FreePool (TempPassword);
//
// Retrive uncommitted data from Browser
//
Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));
ASSERT (Configuration != NULL);
if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {
//
// Update password's clear text in the screen
//
CopyMem (Configuration->PasswordClearText, Password, StrSize (Password));
//
// Update uncommitted data of Browser
//
HiiSetBrowserData (
&gDriverSampleFormSetGuid,
VariableName,
sizeof (DRIVER_SAMPLE_CONFIGURATION),
(UINT8 *) Configuration,
NULL
);
}
//
// Free Configuration Buffer
//
FreePool (Configuration);
//
// Set password
//
EncodePassword (Password, StrLen (Password) * 2);
Status = gRT->SetVariable(
VariableName,
&gDriverSampleFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (DRIVER_SAMPLE_CONFIGURATION),
&PrivateData->Configuration
);
return Status;
}
/**
Update names of Name/Value storage to current language.
@param PrivateData Points to the driver private data.
@retval EFI_SUCCESS All names are successfully updated.
@retval EFI_NOT_FOUND Failed to get Name from HII database.
**/
EFI_STATUS
LoadNameValueNames (
IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData
)
{
UINTN Index;
//
// Get Name/Value name string of current language
//
for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
PrivateData->NameValueName[Index] = HiiGetString (
PrivateData->HiiHandle[0],
PrivateData->NameStringId[Index],
NULL
);
if (PrivateData->NameValueName[Index] == NULL) {
return EFI_NOT_FOUND;
}
}
return EFI_SUCCESS;
}
/**
Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
or WIDTH or VALUE.
<BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
This is a internal function.
@param StringPtr String in <BlockConfig> format and points to the
first character of <Number>.
@param Number The output value. Caller takes the responsibility
to free memory.
@param Len Length of the <Number>, in characters.
@retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
structures.
@retval EFI_SUCCESS Value of <Number> is outputted in Number
successfully.
**/
EFI_STATUS
GetValueOfNumber (
IN EFI_STRING StringPtr,
OUT UINT8 **Number,
OUT UINTN *Len
)
{
EFI_STRING TmpPtr;
UINTN Length;
EFI_STRING Str;
UINT8 *Buf;
EFI_STATUS Status;
UINT8 DigitUint8;
UINTN Index;
CHAR16 TemStr[2];
if (StringPtr == NULL || *StringPtr == L'\0' || Number == NULL || Len == NULL) {
return EFI_INVALID_PARAMETER;
}
Buf = NULL;
TmpPtr = StringPtr;
while (*StringPtr != L'\0' && *StringPtr != L'&') {
StringPtr++;
}
*Len = StringPtr - TmpPtr;
Length = *Len + 1;
Str = (EFI_STRING) AllocateZeroPool (Length * sizeof (CHAR16));
if (Str == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
CopyMem (Str, TmpPtr, *Len * sizeof (CHAR16));
*(Str + *Len) = L'\0';
Length = (Length + 1) / 2;
Buf = (UINT8 *) AllocateZeroPool (Length);
if (Buf == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
Length = *Len;
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0; Index < Length; Index ++) {
TemStr[0] = Str[Length - Index - 1];
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
if ((Index & 1) == 0) {
Buf [Index/2] = DigitUint8;
} else {
Buf [Index/2] = (UINT8) ((DigitUint8 << 4) + Buf [Index/2]);
}
}
*Number = Buf;
Status = EFI_SUCCESS;
Exit:
if (Str != NULL) {
FreePool (Str);
}
return Status;
}
/**
Create altcfg string.
@param Result The request result string.
@param ConfigHdr The request head info. <ConfigHdr> format.
@param Offset The offset of the parameter int he structure.
@param Width The width of the parameter.
@retval The string with altcfg info append at the end.
**/
EFI_STRING
CreateAltCfgString (
IN EFI_STRING Result,
IN EFI_STRING ConfigHdr,
IN UINTN Offset,
IN UINTN Width
)
{
EFI_STRING StringPtr;
EFI_STRING TmpStr;
UINTN NewLen;
NewLen = StrLen (Result);
//
// String Len = ConfigResp + AltConfig + AltConfig + 1("\0")
//
NewLen = (NewLen + ((1 + StrLen (ConfigHdr) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16);
StringPtr = AllocateZeroPool (NewLen);
if (StringPtr == NULL) {
return NULL;
}
TmpStr = StringPtr;
if (Result != NULL) {
StrCpy (StringPtr, Result);
StringPtr += StrLen (Result);
FreePool (Result);
}
UnicodeSPrint (
StringPtr,
(1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16),
L"&%s&ALTCFG=%04x",
ConfigHdr,
EFI_HII_DEFAULT_CLASS_STANDARD
);
StringPtr += StrLen (StringPtr);
UnicodeSPrint (
StringPtr,
(8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),
L"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
Offset,
Width,
DEFAULT_CLASS_STANDARD_VALUE
);
StringPtr += StrLen (StringPtr);
UnicodeSPrint (
StringPtr,
(1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16),
L"&%s&ALTCFG=%04x",
ConfigHdr,
EFI_HII_DEFAULT_CLASS_MANUFACTURING
);
StringPtr += StrLen (StringPtr);
UnicodeSPrint (
StringPtr,
(8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),
L"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
Offset,
Width,
DEFAULT_CLASS_MANUFACTURING_VALUE
);
StringPtr += StrLen (StringPtr);
return TmpStr;
}
/**
Check whether need to add the altcfg string. if need to add, add the altcfg
string.
@param RequestResult The request result string.
@param ConfigRequestHdr The request head info. <ConfigHdr> format.
**/
VOID
AppendAltCfgString (
IN OUT EFI_STRING *RequestResult,
IN EFI_STRING ConfigRequestHdr
)
{
EFI_STRING StringPtr;
UINTN Length;
UINT8 *TmpBuffer;
UINTN Offset;
UINTN Width;
UINTN BlockSize;
UINTN ValueOffset;
UINTN ValueWidth;
EFI_STATUS Status;
StringPtr = *RequestResult;
StringPtr = StrStr (StringPtr, L"OFFSET");
BlockSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
ValueOffset = OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, GetDefaultValueFromAccess);
ValueWidth = sizeof (((DRIVER_SAMPLE_CONFIGURATION *)0)->GetDefaultValueFromAccess);
if (StringPtr == NULL) {
return;
}
while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) {
StringPtr += StrLen (L"OFFSET=");
//
// Get Offset
//
Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
if (EFI_ERROR (Status)) {
return;
}
Offset = 0;
CopyMem (
&Offset,
TmpBuffer,
(((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)
);
FreePool (TmpBuffer);
StringPtr += Length;
if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {
return;
}
StringPtr += StrLen (L"&WIDTH=");
//
// Get Width
//
Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
if (EFI_ERROR (Status)) {
return;
}
Width = 0;
CopyMem (
&Width,
TmpBuffer,
(((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)
);
FreePool (TmpBuffer);
StringPtr += Length;
if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {
return;
}
StringPtr += StrLen (L"&VALUE=");
//
// Get Value
//
Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
if (EFI_ERROR (Status)) {
return;
}
StringPtr += Length;
//
// Calculate Value and convert it to hex string.
//
if (Offset + Width > BlockSize) {
return;
}
if (Offset <= ValueOffset && Offset + Width >= ValueOffset + ValueWidth) {
*RequestResult = CreateAltCfgString(*RequestResult, ConfigRequestHdr, ValueOffset, ValueWidth);
return;
}
}
}
/**
This function allows a caller to extract the current configuration for one
or more named elements from the target driver.
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
@param Request A null-terminated Unicode string in
<ConfigRequest> format.
@param Progress On return, points to a character in the Request
string. Points to the string's null terminator if
request was successful. Points to the most recent
'&' before the first failing name/value pair (or
the beginning of the string if the failure is in
the first name/value pair) if the request was not
successful.
@param Results A null-terminated Unicode string in
<ConfigAltResp> format which has all values filled
in for the names in the Request string. String to
be allocated by the called function.
@retval EFI_SUCCESS The Results is filled with the requested values.
@retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
@retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
@retval EFI_NOT_FOUND Routing data doesn't match any storage in this
driver.
**/
EFI_STATUS
EFIAPI
ExtractConfig (
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
IN CONST EFI_STRING Request,
OUT EFI_STRING *Progress,
OUT EFI_STRING *Results
)
{
EFI_STATUS Status;
UINTN BufferSize;
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
EFI_STRING ConfigRequest;
EFI_STRING ConfigRequestHdr;
UINTN Size;
EFI_STRING Value;
UINTN ValueStrLen;
CHAR16 BackupChar;
CHAR16 *StrPointer;
BOOLEAN AllocatedRequest;
if (Progress == NULL || Results == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Initialize the local variables.
//
ConfigRequestHdr = NULL;
ConfigRequest = NULL;
Size = 0;
*Progress = Request;
AllocatedRequest = FALSE;
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
HiiConfigRouting = PrivateData->HiiConfigRouting;
//
// Get Buffer Storage data from EFI variable.
// Try to get the current setting from variable.
//
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
Status = gRT->GetVariable (
VariableName,
&gDriverSampleFormSetGuid,
NULL,
&BufferSize,
&PrivateData->Configuration
);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
if (Request == NULL) {
//
// Request is set to NULL, construct full request string.
//
//
// Allocate and fill a buffer large enough to hold the <ConfigHdr> template
// followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
//
ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);
Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
ConfigRequest = AllocateZeroPool (Size);
ASSERT (ConfigRequest != NULL);
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
FreePool (ConfigRequestHdr);
ConfigRequestHdr = NULL;
} else {
//
// Check routing data in <ConfigHdr>.
// Note: if only one Storage is used, then this checking could be skipped.
//
if (!HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, NULL)) {
return EFI_NOT_FOUND;
}
//
// Check whether request for EFI Varstore. EFI varstore get data
// through hii database, not support in this path.
//
if (HiiIsConfigHdrMatch(Request, &gDriverSampleFormSetGuid, MyEfiVar)) {
return EFI_UNSUPPORTED;
}
//
// Set Request to the unified request string.
//
ConfigRequest = Request;
//
// Check whether Request includes Request Element.
//
if (StrStr (Request, L"OFFSET") == NULL) {
//
// Check Request Element does exist in Reques String
//
StrPointer = StrStr (Request, L"PATH");
if (StrPointer == NULL) {
return EFI_INVALID_PARAMETER;
}
if (StrStr (StrPointer, L"&") == NULL) {
Size = (StrLen (Request) + 32 + 1) * sizeof (CHAR16);
ConfigRequest = AllocateZeroPool (Size);
ASSERT (ConfigRequest != NULL);
AllocatedRequest = TRUE;
UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", Request, (UINT64)BufferSize);
}
}
}
//
// Check if requesting Name/Value storage
//
if (StrStr (ConfigRequest, L"OFFSET") == NULL) {
//
// Update Name/Value storage Names
//
Status = LoadNameValueNames (PrivateData);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Allocate memory for <ConfigResp>, e.g. Name0=0x11, Name1=0x1234, Name2="ABCD"
// <Request> ::=<ConfigHdr>&Name0&Name1&Name2
// <ConfigResp>::=<ConfigHdr>&Name0=11&Name1=1234&Name2=0041004200430044
//
BufferSize = (StrLen (ConfigRequest) +
1 + sizeof (PrivateData->Configuration.NameValueVar0) * 2 +
1 + sizeof (PrivateData->Configuration.NameValueVar1) * 2 +
1 + sizeof (PrivateData->Configuration.NameValueVar2) * 2 + 1) * sizeof (CHAR16);
*Results = AllocateZeroPool (BufferSize);
ASSERT (*Results != NULL);
StrCpy (*Results, ConfigRequest);
Value = *Results;
//
// Append value of NameValueVar0, type is UINT8
//
if ((Value = StrStr (*Results, PrivateData->NameValueName[0])) != NULL) {
Value += StrLen (PrivateData->NameValueName[0]);
ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar0) * 2) + 1);
CopyMem (Value + ValueStrLen, Value, StrSize (Value));
BackupChar = Value[ValueStrLen];
*Value++ = L'=';
Value += UnicodeValueToString (
Value,
PREFIX_ZERO | RADIX_HEX,
PrivateData->Configuration.NameValueVar0,
sizeof (PrivateData->Configuration.NameValueVar0) * 2
);
*Value = BackupChar;
}
//
// Append value of NameValueVar1, type is UINT16
//
if ((Value = StrStr (*Results, PrivateData->NameValueName[1])) != NULL) {
Value += StrLen (PrivateData->NameValueName[1]);
ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar1) * 2) + 1);
CopyMem (Value + ValueStrLen, Value, StrSize (Value));
BackupChar = Value[ValueStrLen];
*Value++ = L'=';
Value += UnicodeValueToString (
Value,
PREFIX_ZERO | RADIX_HEX,
PrivateData->Configuration.NameValueVar1,
sizeof (PrivateData->Configuration.NameValueVar1) * 2
);
*Value = BackupChar;
}
//
// Append value of NameValueVar2, type is CHAR16 *
//
if ((Value = StrStr (*Results, PrivateData->NameValueName[2])) != NULL) {
Value += StrLen (PrivateData->NameValueName[2]);
ValueStrLen = StrLen (PrivateData->Configuration.NameValueVar2) * 4 + 1;
CopyMem (Value + ValueStrLen, Value, StrSize (Value));
*Value++ = L'=';
//
// Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
//
StrPointer = (CHAR16 *) PrivateData->Configuration.NameValueVar2;
for (; *StrPointer != L'\0'; StrPointer++) {
Value += UnicodeValueToString (Value, PREFIX_ZERO | RADIX_HEX, *StrPointer, 4);
}
}
Status = EFI_SUCCESS;
} else {
//
// Convert buffer data to <ConfigResp> by helper function BlockToConfig()
//
Status = HiiConfigRouting->BlockToConfig (
HiiConfigRouting,
ConfigRequest,
(UINT8 *) &PrivateData->Configuration,
BufferSize,
Results,
Progress
);
if (!EFI_ERROR (Status)) {
ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);
AppendAltCfgString(Results, ConfigRequestHdr);
}
}
//
// Free the allocated config request string.
//
if (AllocatedRequest) {
FreePool (ConfigRequest);
}
if (ConfigRequestHdr != NULL) {
FreePool (ConfigRequestHdr);
}
//
// Set Progress string to the original request string.
//
if (Request == NULL) {
*Progress = NULL;
} else if (StrStr (Request, L"OFFSET") == NULL) {
*Progress = Request + StrLen (Request);
}
return Status;
}
/**
This function processes the results of changes in configuration.
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
@param Configuration A null-terminated Unicode string in <ConfigResp>
format.
@param Progress A pointer to a string filled in with the offset of
the most recent '&' before the first failing
name/value pair (or the beginning of the string if
the failure is in the first name/value pair) or
the terminating NULL if all was successful.
@retval EFI_SUCCESS The Results is processed successfully.
@retval EFI_INVALID_PARAMETER Configuration is NULL.
@retval EFI_NOT_FOUND Routing data doesn't match any storage in this
driver.
**/
EFI_STATUS
EFIAPI
RouteConfig (
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
IN CONST EFI_STRING Configuration,
OUT EFI_STRING *Progress
)
{
EFI_STATUS Status;
UINTN BufferSize;
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
CHAR16 *Value;
CHAR16 *StrPtr;
CHAR16 TemStr[5];
UINT8 *DataBuffer;
UINT8 DigitUint8;
UINTN Index;
CHAR16 *StrBuffer;
if (Configuration == NULL || Progress == NULL) {
return EFI_INVALID_PARAMETER;
}
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
HiiConfigRouting = PrivateData->HiiConfigRouting;
*Progress = Configuration;
//
// Check routing data in <ConfigHdr>.
// Note: if only one Storage is used, then this checking could be skipped.
//
if (!HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, NULL)) {
return EFI_NOT_FOUND;
}
//
// Check whether request for EFI Varstore. EFI varstore get data
// through hii database, not support in this path.
//
if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) {
return EFI_UNSUPPORTED;
}
//
// Get Buffer Storage data from EFI variable
//
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
Status = gRT->GetVariable (
VariableName,
&gDriverSampleFormSetGuid,
NULL,
&BufferSize,
&PrivateData->Configuration
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Check if configuring Name/Value storage
//
if (StrStr (Configuration, L"OFFSET") == NULL) {
//
// Update Name/Value storage Names
//
Status = LoadNameValueNames (PrivateData);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Convert value for NameValueVar0
//
if ((Value = StrStr (Configuration, PrivateData->NameValueName[0])) != NULL) {
//
// Skip "Name="
//
Value += StrLen (PrivateData->NameValueName[0]);
Value++;
//
// Get Value String
//
StrPtr = StrStr (Value, L"&");
if (StrPtr == NULL) {
StrPtr = Value + StrLen (Value);
}
//
// Convert Value to Buffer data
//
DataBuffer = (UINT8 *) &PrivateData->Configuration.NameValueVar0;
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0, StrPtr --; StrPtr >= Value; StrPtr --, Index ++) {
TemStr[0] = *StrPtr;
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
if ((Index & 1) == 0) {
DataBuffer [Index/2] = DigitUint8;
} else {
DataBuffer [Index/2] = (UINT8) ((UINT8) (DigitUint8 << 4) + DataBuffer [Index/2]);
}
}
}
//
// Convert value for NameValueVar1
//
if ((Value = StrStr (Configuration, PrivateData->NameValueName[1])) != NULL) {
//
// Skip "Name="
//
Value += StrLen (PrivateData->NameValueName[1]);
Value++;
//
// Get Value String
//
StrPtr = StrStr (Value, L"&");
if (StrPtr == NULL) {
StrPtr = Value + StrLen (Value);
}
//
// Convert Value to Buffer data
//
DataBuffer = (UINT8 *) &PrivateData->Configuration.NameValueVar1;
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0, StrPtr --; StrPtr >= Value; StrPtr --, Index ++) {
TemStr[0] = *StrPtr;
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
if ((Index & 1) == 0) {
DataBuffer [Index/2] = DigitUint8;
} else {
DataBuffer [Index/2] = (UINT8) ((UINT8) (DigitUint8 << 4) + DataBuffer [Index/2]);
}
}
}
//
// Convert value for NameValueVar2
//
if ((Value = StrStr (Configuration, PrivateData->NameValueName[2])) != NULL) {
//
// Skip "Name="
//
Value += StrLen (PrivateData->NameValueName[2]);
Value++;
//
// Get Value String
//
StrPtr = StrStr (Value, L"&");
if (StrPtr == NULL) {
StrPtr = Value + StrLen (Value);
}
//
// Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
//
StrBuffer = (CHAR16 *) PrivateData->Configuration.NameValueVar2;
ZeroMem (TemStr, sizeof (TemStr));
while (Value < StrPtr) {
StrnCpy (TemStr, Value, 4);
*(StrBuffer++) = (CHAR16) StrHexToUint64 (TemStr);
Value += 4;
}
*StrBuffer = L'\0';
}
//
// Store Buffer Storage back to EFI variable
//
Status = gRT->SetVariable(
VariableName,
&gDriverSampleFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (DRIVER_SAMPLE_CONFIGURATION),
&PrivateData->Configuration
);
return Status;
}
//
// Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
//
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
Status = HiiConfigRouting->ConfigToBlock (
HiiConfigRouting,
Configuration,
(UINT8 *) &PrivateData->Configuration,
&BufferSize,
Progress
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Store Buffer Storage back to EFI variable
//
Status = gRT->SetVariable(
VariableName,
&gDriverSampleFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (DRIVER_SAMPLE_CONFIGURATION),
&PrivateData->Configuration
);
return Status;
}
/**
This function processes the results of changes in configuration.
@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
@param Action Specifies the type of action taken by the browser.
@param QuestionId A unique value which is sent to the original
exporting driver so that it can identify the type
of data to expect.
@param Type The type of value for the question.
@param Value A pointer to the data being sent to the original
exporting driver.
@param ActionRequest On return, points to the action requested by the
callback function.
@retval EFI_SUCCESS The callback successfully handled the action.
@retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
variable and its data.
@retval EFI_DEVICE_ERROR The variable could not be saved.
@retval EFI_UNSUPPORTED The specified Action is not supported by the
callback.
**/
EFI_STATUS
EFIAPI
DriverCallback (
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
IN EFI_BROWSER_ACTION Action,
IN EFI_QUESTION_ID QuestionId,
IN UINT8 Type,
IN EFI_IFR_TYPE_VALUE *Value,
OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
)
{
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
EFI_STATUS Status;
VOID *StartOpCodeHandle;
VOID *OptionsOpCodeHandle;
EFI_IFR_GUID_LABEL *StartLabel;
VOID *EndOpCodeHandle;
EFI_IFR_GUID_LABEL *EndLabel;
EFI_INPUT_KEY Key;
DRIVER_SAMPLE_CONFIGURATION *Configuration;
MY_EFI_VARSTORE_DATA *EfiData;
EFI_FORM_ID FormId;
if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))||
(ActionRequest == NULL)) {
return EFI_INVALID_PARAMETER;
}
FormId = 0;
Status = EFI_SUCCESS;
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
switch (Action) {
case EFI_BROWSER_ACTION_FORM_OPEN:
{
if (QuestionId == 0x1234) {
//
// Sample CallBack for UEFI FORM_OPEN action:
// Add Save action into Form 3 when Form 1 is opened.
// This will be done only in FORM_OPEN CallBack of question with ID 0x1234 from Form 1.
//
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
//
// Initialize the container for dynamic opcodes
//
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
ASSERT (StartOpCodeHandle != NULL);
//
// Create Hii Extend Label OpCode as the start opcode
//
StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
StartLabel->Number = LABEL_UPDATE2;
HiiCreateActionOpCode (
StartOpCodeHandle, // Container for dynamic created opcodes
0x1238, // Question ID
STRING_TOKEN(STR_SAVE_TEXT), // Prompt text
STRING_TOKEN(STR_SAVE_TEXT), // Help text
EFI_IFR_FLAG_CALLBACK, // Question flag
0 // Action String ID
);
HiiUpdateForm (
PrivateData->HiiHandle[0], // HII handle
&gDriverSampleFormSetGuid, // Formset GUID
0x3, // Form ID
StartOpCodeHandle, // Label for where to insert opcodes
NULL // Insert data
);
HiiFreeOpCodeHandle (StartOpCodeHandle);
}
if (QuestionId == 0x1247) {
Status = InternalStartMonitor ();
ASSERT_EFI_ERROR (Status);
}
}
break;
case EFI_BROWSER_ACTION_FORM_CLOSE:
{
if (QuestionId == 0x5678) {
//
// Sample CallBack for UEFI FORM_CLOSE action:
// Show up a pop-up to specify Form 3 will be closed when exit Form 3.
//
do {
CreatePopUp (
EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
&Key,
L"",
L"You are going to leave third Form!",
L"Press ESC or ENTER to continue ...",
L"",
NULL
);
} while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
}
if (QuestionId == 0x1247) {
Status = InternalStopMonitor ();
ASSERT_EFI_ERROR (Status);
}
}
break;
case EFI_BROWSER_ACTION_RETRIEVE:
{
if (QuestionId == 0x1248) {
{
if (Type != EFI_IFR_TYPE_REF) {
return EFI_INVALID_PARAMETER;
}
Value->ref.FormId = 0x3;
}
}
}
break;
case EFI_BROWSER_ACTION_DEFAULT_STANDARD:
{
switch (QuestionId) {
case 0x1240:
Value->u8 = DEFAULT_CLASS_STANDARD_VALUE;
break;
default:
Status = EFI_UNSUPPORTED;
break;
}
}
break;
case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING:
{
switch (QuestionId) {
case 0x1240:
Value->u8 = DEFAULT_CLASS_MANUFACTURING_VALUE;
break;
default:
Status = EFI_UNSUPPORTED;
break;
}
}
break;
case EFI_BROWSER_ACTION_CHANGING:
{
switch (QuestionId) {
case 0x1249:
{
if (Type != EFI_IFR_TYPE_REF) {
return EFI_INVALID_PARAMETER;
}
Value->ref.FormId = 0x1234;
}
break;
case 0x1234:
//
// Initialize the container for dynamic opcodes
//
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
ASSERT (StartOpCodeHandle != NULL);
EndOpCodeHandle = HiiAllocateOpCodeHandle ();
ASSERT (EndOpCodeHandle != NULL);
//
// Create Hii Extend Label OpCode as the start opcode
//
StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
StartLabel->Number = LABEL_UPDATE1;
//
// Create Hii Extend Label OpCode as the end opcode
//
EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
EndLabel->Number = LABEL_END;
HiiCreateActionOpCode (
StartOpCodeHandle, // Container for dynamic created opcodes
0x1237, // Question ID
STRING_TOKEN(STR_EXIT_TEXT), // Prompt text
STRING_TOKEN(STR_EXIT_TEXT), // Help text
EFI_IFR_FLAG_CALLBACK, // Question flag
0 // Action String ID
);
//
// Create Option OpCode
//
OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
ASSERT (OptionsOpCodeHandle != NULL);
HiiCreateOneOfOptionOpCode (
OptionsOpCodeHandle,
STRING_TOKEN (STR_BOOT_OPTION1),
0,
EFI_IFR_NUMERIC_SIZE_1,
1
);
HiiCreateOneOfOptionOpCode (
OptionsOpCodeHandle,
STRING_TOKEN (STR_BOOT_OPTION2),
0,
EFI_IFR_NUMERIC_SIZE_1,
2
);
//
// Prepare initial value for the dynamic created oneof Question
//
PrivateData->Configuration.DynamicOneof = 2;
Status = gRT->SetVariable(
VariableName,
&gDriverSampleFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (DRIVER_SAMPLE_CONFIGURATION),
&PrivateData->Configuration
);
//
// Set initial vlaue of dynamic created oneof Question in Form Browser
//
Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));
ASSERT (Configuration != NULL);
if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {
Configuration->DynamicOneof = 2;
//
// Update uncommitted data of Browser
//
HiiSetBrowserData (
&gDriverSampleFormSetGuid,
VariableName,
sizeof (DRIVER_SAMPLE_CONFIGURATION),
(UINT8 *) Configuration,
NULL
);
}
FreePool (Configuration);
HiiCreateOneOfOpCode (
StartOpCodeHandle, // Container for dynamic created opcodes
0x8001, // Question ID (or call it "key")
CONFIGURATION_VARSTORE_ID, // VarStore ID
(UINT16) DYNAMIC_ONE_OF_VAR_OFFSET, // Offset in Buffer Storage
STRING_TOKEN (STR_ONE_OF_PROMPT), // Question prompt text
STRING_TOKEN (STR_ONE_OF_HELP), // Question help text
EFI_IFR_FLAG_CALLBACK, // Question flag
EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value
OptionsOpCodeHandle, // Option Opcode list
NULL // Default Opcode is NULl
);
HiiCreateOrderedListOpCode (
StartOpCodeHandle, // Container for dynamic created opcodes
0x8002, // Question ID
CONFIGURATION_VARSTORE_ID, // VarStore ID
(UINT16) DYNAMIC_ORDERED_LIST_VAR_OFFSET, // Offset in Buffer Storage
STRING_TOKEN (STR_BOOT_OPTIONS), // Question prompt text
STRING_TOKEN (STR_BOOT_OPTIONS), // Question help text
EFI_IFR_FLAG_RESET_REQUIRED, // Question flag
0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value
5, // Maximum container
OptionsOpCodeHandle, // Option Opcode list
NULL // Default Opcode is NULl
);
HiiCreateTextOpCode (
StartOpCodeHandle,
STRING_TOKEN(STR_TEXT_SAMPLE_HELP),
STRING_TOKEN(STR_TEXT_SAMPLE_HELP),
STRING_TOKEN(STR_TEXT_SAMPLE_STRING)
);
HiiCreateDateOpCode (
StartOpCodeHandle,
0x8004,
0x0,
0x0,
STRING_TOKEN(STR_DATE_SAMPLE_HELP),
STRING_TOKEN(STR_DATE_SAMPLE_HELP),
0,
QF_DATE_STORAGE_TIME,
NULL
);
HiiCreateTimeOpCode (
StartOpCodeHandle,
0x8005,
0x0,
0x0,
STRING_TOKEN(STR_TIME_SAMPLE_HELP),
STRING_TOKEN(STR_TIME_SAMPLE_HELP),
0,
QF_TIME_STORAGE_TIME,
NULL
);
HiiCreateGotoOpCode (
StartOpCodeHandle, // Container for dynamic created opcodes
1, // Target Form ID
STRING_TOKEN (STR_GOTO_FORM1), // Prompt text
STRING_TOKEN (STR_GOTO_HELP), // Help text
0, // Question flag
0x8003 // Question ID
);
HiiUpdateForm (
PrivateData->HiiHandle[0], // HII handle
&gDriverSampleFormSetGuid, // Formset GUID
0x1234, // Form ID
StartOpCodeHandle, // Label for where to insert opcodes
EndOpCodeHandle // Replace data
);
HiiFreeOpCodeHandle (StartOpCodeHandle);
HiiFreeOpCodeHandle (OptionsOpCodeHandle);
HiiFreeOpCodeHandle (EndOpCodeHandle);
break;
case 0x5678:
case 0x1247:
//
// We will reach here once the Question is refreshed
//
//
// Initialize the container for dynamic opcodes
//
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
ASSERT (StartOpCodeHandle != NULL);
//
// Create Hii Extend Label OpCode as the start opcode
//
StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
if (QuestionId == 0x5678) {
StartLabel->Number = LABEL_UPDATE2;
FormId = 0x03;
PrivateData->Configuration.DynamicRefresh++;
} else if (QuestionId == 0x1247 ) {
StartLabel->Number = LABEL_UPDATE3;
FormId = 0x06;
PrivateData->Configuration.RefreshGuidCount++;
}
HiiCreateActionOpCode (
StartOpCodeHandle, // Container for dynamic created opcodes
0x1237, // Question ID
STRING_TOKEN(STR_EXIT_TEXT), // Prompt text
STRING_TOKEN(STR_EXIT_TEXT), // Help text
EFI_IFR_FLAG_CALLBACK, // Question flag
0 // Action String ID
);
HiiUpdateForm (
PrivateData->HiiHandle[0], // HII handle
&gDriverSampleFormSetGuid, // Formset GUID
FormId, // Form ID
StartOpCodeHandle, // Label for where to insert opcodes
NULL // Insert data
);
HiiFreeOpCodeHandle (StartOpCodeHandle);
//
// Refresh the Question value
//
Status = gRT->SetVariable(
VariableName,
&gDriverSampleFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (DRIVER_SAMPLE_CONFIGURATION),
&PrivateData->Configuration
);
if (QuestionId == 0x5678) {
//
// Update uncommitted data of Browser
//
EfiData = AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA));
ASSERT (EfiData != NULL);
if (HiiGetBrowserData (&gDriverSampleFormSetGuid, MyEfiVar, sizeof (MY_EFI_VARSTORE_DATA), (UINT8 *) EfiData)) {
EfiData->Field8 = 111;
HiiSetBrowserData (
&gDriverSampleFormSetGuid,
MyEfiVar,
sizeof (MY_EFI_VARSTORE_DATA),
(UINT8 *) EfiData,
NULL
);
}
FreePool (EfiData);
}
break;
case 0x2000:
//
// Only used to update the state.
//
if ((Type == EFI_IFR_TYPE_STRING) && (Value->string == 0) &&
(PrivateData->PasswordState == BROWSER_STATE_SET_PASSWORD)) {
PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
return EFI_INVALID_PARAMETER;
}
//
// When try to set a new password, user will be chanlleged with old password.
// The Callback is responsible for validating old password input by user,
// If Callback return EFI_SUCCESS, it indicates validation pass.
//
switch (PrivateData->PasswordState) {
case BROWSER_STATE_VALIDATE_PASSWORD:
Status = ValidatePassword (PrivateData, Value->string);
if (Status == EFI_SUCCESS) {
PrivateData->PasswordState = BROWSER_STATE_SET_PASSWORD;
}
break;
case BROWSER_STATE_SET_PASSWORD:
Status = SetPassword (PrivateData, Value->string);
PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
break;
default:
break;
}
break;
default:
break;
}
}
break;
case EFI_BROWSER_ACTION_CHANGED:
switch (QuestionId) {
case 0x1237:
//
// User press "Exit now", request Browser to exit
//
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
break;
case 0x1238:
//
// User press "Save now", request Browser to save the uncommitted data.
//
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
break;
case 0x1241:
case 0x1246:
//
// User press "Submit current form and Exit now", request Browser to submit current form and exit
//
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
break;
case 0x1242:
//
// User press "Discard current form now", request Browser to discard the uncommitted data.
//
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD;
break;
case 0x1243:
//
// User press "Submit current form now", request Browser to save the uncommitted data.
//
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
break;
case 0x1244:
case 0x1245:
//
// User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit.
//
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
break;
default:
break;
}
break;
default:
Status = EFI_UNSUPPORTED;
break;
}
return Status;
}
/**
Main entry for this driver.
@param ImageHandle Image handle this driver.
@param SystemTable Pointer to SystemTable.
@retval EFI_SUCESS This function always complete successfully.
**/
EFI_STATUS
EFIAPI
DriverSampleInit (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_HII_HANDLE HiiHandle[2];
EFI_SCREEN_DESCRIPTOR Screen;
EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
EFI_HII_STRING_PROTOCOL *HiiString;
EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;
EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
CHAR16 *NewString;
UINTN BufferSize;
DRIVER_SAMPLE_CONFIGURATION *Configuration;
BOOLEAN ActionFlag;
EFI_STRING ConfigRequestHdr;
MY_EFI_VARSTORE_DATA *VarStoreConfig;
EFI_INPUT_KEY HotKey;
EFI_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx;
EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *pToText;
//
// Initialize the local variables.
//
ConfigRequestHdr = NULL;
NewString = NULL;
pToText = NULL;
//
// Initialize screen dimensions for SendForm().
// Remove 3 characters from top and bottom
//
ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR));
gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow);
Screen.TopRow = 3;
Screen.BottomRow = Screen.BottomRow - 3;
//
// Initialize driver private data
//
PrivateData = AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA));
if (PrivateData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
PrivateData->Signature = DRIVER_SAMPLE_PRIVATE_SIGNATURE;
PrivateData->ConfigAccess.ExtractConfig = ExtractConfig;
PrivateData->ConfigAccess.RouteConfig = RouteConfig;
PrivateData->ConfigAccess.Callback = DriverCallback;
PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
//
// Locate Hii Database protocol
//
Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &HiiDatabase);
if (EFI_ERROR (Status)) {
return Status;
}
PrivateData->HiiDatabase = HiiDatabase;
//
// Locate HiiString protocol
//
Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &HiiString);
if (EFI_ERROR (Status)) {
return Status;
}
PrivateData->HiiString = HiiString;
//
// Locate Formbrowser2 protocol
//
Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2);
if (EFI_ERROR (Status)) {
return Status;
}
PrivateData->FormBrowser2 = FormBrowser2;
//
// Locate ConfigRouting protocol
//
Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting);
if (EFI_ERROR (Status)) {
return Status;
}
PrivateData->HiiConfigRouting = HiiConfigRouting;
Status = gBS->InstallMultipleProtocolInterfaces (
&DriverHandle[0],
&gEfiDevicePathProtocolGuid,
&mHiiVendorDevicePath0,
&gEfiHiiConfigAccessProtocolGuid,
&PrivateData->ConfigAccess,
NULL
);
ASSERT_EFI_ERROR (Status);
PrivateData->DriverHandle[0] = DriverHandle[0];
//
// Publish our HII data
//
HiiHandle[0] = HiiAddPackages (
&gDriverSampleFormSetGuid,
DriverHandle[0],
DriverSampleStrings,
VfrBin,
NULL
);
if (HiiHandle[0] == NULL) {
return EFI_OUT_OF_RESOURCES;
}
PrivateData->HiiHandle[0] = HiiHandle[0];
//
// Publish another Fromset
//
Status = gBS->InstallMultipleProtocolInterfaces (
&DriverHandle[1],
&gEfiDevicePathProtocolGuid,
&mHiiVendorDevicePath1,
NULL
);
ASSERT_EFI_ERROR (Status);
PrivateData->DriverHandle[1] = DriverHandle[1];
HiiHandle[1] = HiiAddPackages (
&gDriverSampleInventoryGuid,
DriverHandle[1],
DriverSampleStrings,
InventoryBin,
NULL
);
if (HiiHandle[1] == NULL) {
DriverSampleUnload (ImageHandle);
return EFI_OUT_OF_RESOURCES;
}
PrivateData->HiiHandle[1] = HiiHandle[1];
Status = gBS->LocateProtocol (
&gEfiDevicePathToTextProtocolGuid,
NULL,
(VOID **) &pToText
);
ASSERT_EFI_ERROR (Status);
//
// Update the device path string.
//
NewString = pToText->ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)&mHiiVendorDevicePath0, FALSE, FALSE);
if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), NewString, NULL) == 0) {
DriverSampleUnload (ImageHandle);
return EFI_OUT_OF_RESOURCES;
}
if (NewString != NULL) {
FreePool (NewString);
}
//
// Very simple example of how one would update a string that is already
// in the HII database
//
NewString = L"700 Mhz";
if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString, NULL) == 0) {
DriverSampleUnload (ImageHandle);
return EFI_OUT_OF_RESOURCES;
}
HiiSetString (HiiHandle[0], 0, NewString, NULL);
//
// Initialize Name/Value name String ID
//
PrivateData->NameStringId[0] = STR_NAME_VALUE_VAR_NAME0;
PrivateData->NameStringId[1] = STR_NAME_VALUE_VAR_NAME1;
PrivateData->NameStringId[2] = STR_NAME_VALUE_VAR_NAME2;
//
// Initialize configuration data
//
Configuration = &PrivateData->Configuration;
ZeroMem (Configuration, sizeof (DRIVER_SAMPLE_CONFIGURATION));
//
// Try to read NV config EFI variable first
//
ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, DriverHandle[0]);
ASSERT (ConfigRequestHdr != NULL);
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
Status = gRT->GetVariable (VariableName, &gDriverSampleFormSetGuid, NULL, &BufferSize, Configuration);
if (EFI_ERROR (Status)) {
//
// Store zero data Buffer Storage to EFI variable
//
Status = gRT->SetVariable(
VariableName,
&gDriverSampleFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (DRIVER_SAMPLE_CONFIGURATION),
Configuration
);
ASSERT (Status == EFI_SUCCESS);
//
// EFI variable for NV config doesn't exit, we should build this variable
// based on default values stored in IFR
//
ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
ASSERT (ActionFlag);
} else {
//
// EFI variable does exist and Validate Current Setting
//
ActionFlag = HiiValidateSettings (ConfigRequestHdr);
ASSERT (ActionFlag);
}
FreePool (ConfigRequestHdr);
//
// Initialize efi varstore configuration data
//
VarStoreConfig = &PrivateData->VarStoreConfig;
ZeroMem (VarStoreConfig, sizeof (MY_EFI_VARSTORE_DATA));
ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiVar, DriverHandle[0]);
ASSERT (ConfigRequestHdr != NULL);
BufferSize = sizeof (MY_EFI_VARSTORE_DATA);
Status = gRT->GetVariable (MyEfiVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, VarStoreConfig);
if (EFI_ERROR (Status)) {
//
// Store zero data to EFI variable Storage.
//
Status = gRT->SetVariable(
MyEfiVar,
&gDriverSampleFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (MY_EFI_VARSTORE_DATA),
VarStoreConfig
);
ASSERT (Status == EFI_SUCCESS);
//
// EFI variable for NV config doesn't exit, we should build this variable
// based on default values stored in IFR
//
ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
ASSERT (ActionFlag);
} else {
//
// EFI variable does exist and Validate Current Setting
//
ActionFlag = HiiValidateSettings (ConfigRequestHdr);
ASSERT (ActionFlag);
}
FreePool (ConfigRequestHdr);
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
DriverSampleInternalEmptyFunction,
NULL,
&gEfiIfrRefreshIdOpGuid,
&mEvent
);
ASSERT_EFI_ERROR (Status);
//
// Example of how to use BrowserEx protocol to register HotKey.
//
Status = gBS->LocateProtocol (&gEfiFormBrowserExProtocolGuid, NULL, (VOID **) &FormBrowserEx);
if (!EFI_ERROR (Status)) {
//
// First unregister the default hot key F9 and F10.
//
HotKey.UnicodeChar = CHAR_NULL;
HotKey.ScanCode = SCAN_F9;
FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);
HotKey.ScanCode = SCAN_F10;
FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);
//
// Register the default HotKey F9 and F10 again.
//
HotKey.ScanCode = SCAN_F10;
NewString = HiiGetString (PrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_TEN_STRING), NULL);
ASSERT (NewString != NULL);
FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_SUBMIT, 0, NewString);
HotKey.ScanCode = SCAN_F9;
NewString = HiiGetString (PrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_NINE_STRING), NULL);
ASSERT (NewString != NULL);
FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString);
}
//
// In default, this driver is built into Flash device image,
// the following code doesn't run.
//
//
// Example of how to display only the item we sent to HII
// When this driver is not built into Flash device image,
// it need to call SendForm to show front page by itself.
//
if (DISPLAY_ONLY_MY_ITEM <= 1) {
//
// Have the browser pull out our copy of the data, and only display our data
//
Status = FormBrowser2->SendForm (
FormBrowser2,
&(HiiHandle[DISPLAY_ONLY_MY_ITEM]),
1,
NULL,
0,
NULL,
NULL
);
HiiRemovePackages (HiiHandle[0]);
HiiRemovePackages (HiiHandle[1]);
}
return EFI_SUCCESS;
}
/**
Unloads the application and its installed protocol.
@param[in] ImageHandle Handle that identifies the image to be unloaded.
@retval EFI_SUCCESS The image has been unloaded.
**/
EFI_STATUS
EFIAPI
DriverSampleUnload (
IN EFI_HANDLE ImageHandle
)
{
UINTN Index;
ASSERT (PrivateData != NULL);
if (DriverHandle[0] != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
DriverHandle[0],
&gEfiDevicePathProtocolGuid,
&mHiiVendorDevicePath0,
&gEfiHiiConfigAccessProtocolGuid,
&PrivateData->ConfigAccess,
NULL
);
DriverHandle[0] = NULL;
}
if (DriverHandle[1] != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
DriverHandle[1],
&gEfiDevicePathProtocolGuid,
&mHiiVendorDevicePath1,
NULL
);
DriverHandle[1] = NULL;
}
if (PrivateData->HiiHandle[0] != NULL) {
HiiRemovePackages (PrivateData->HiiHandle[0]);
}
if (PrivateData->HiiHandle[1] != NULL) {
HiiRemovePackages (PrivateData->HiiHandle[1]);
}
for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
if (PrivateData->NameValueName[Index] != NULL) {
FreePool (PrivateData->NameValueName[Index]);
}
}
FreePool (PrivateData);
PrivateData = NULL;
gBS->CloseEvent (mEvent);
return EFI_SUCCESS;
}
|