1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
|
/** @file
Entry and initialization module for the browser.
Copyright (c) 2007 - 2011, 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 "Setup.h"
SETUP_DRIVER_PRIVATE_DATA mPrivateData = {
SETUP_DRIVER_SIGNATURE,
NULL,
{
SendForm,
BrowserCallback
}
};
EFI_HII_DATABASE_PROTOCOL *mHiiDatabase;
EFI_HII_STRING_PROTOCOL *mHiiString;
EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting;
UINTN gBrowserContextCount = 0;
LIST_ENTRY gBrowserContextList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserContextList);
BANNER_DATA *gBannerData;
EFI_HII_HANDLE gFrontPageHandle;
UINTN gClassOfVfr;
UINTN gFunctionKeySetting;
BOOLEAN gResetRequired;
EFI_HII_HANDLE gHiiHandle;
UINT16 gDirection;
EFI_SCREEN_DESCRIPTOR gScreenDimensions;
//
// Browser Global Strings
//
CHAR16 *gFunctionNineString;
CHAR16 *gFunctionTenString;
CHAR16 *gEnterString;
CHAR16 *gEnterCommitString;
CHAR16 *gEnterEscapeString;
CHAR16 *gEscapeString;
CHAR16 *gSaveFailed;
CHAR16 *gMoveHighlight;
CHAR16 *gMakeSelection;
CHAR16 *gDecNumericInput;
CHAR16 *gHexNumericInput;
CHAR16 *gToggleCheckBox;
CHAR16 *gPromptForData;
CHAR16 *gPromptForPassword;
CHAR16 *gPromptForNewPassword;
CHAR16 *gConfirmPassword;
CHAR16 *gConfirmError;
CHAR16 *gPassowordInvalid;
CHAR16 *gPressEnter;
CHAR16 *gEmptyString;
CHAR16 *gAreYouSure;
CHAR16 *gYesResponse;
CHAR16 *gNoResponse;
CHAR16 *gMiniString;
CHAR16 *gPlusString;
CHAR16 *gMinusString;
CHAR16 *gAdjustNumber;
CHAR16 *gSaveChanges;
CHAR16 *gOptionMismatch;
CHAR16 *gFormSuppress;
CHAR16 *mUnknownString = L"!";
CHAR16 gPromptBlockWidth;
CHAR16 gOptionBlockWidth;
CHAR16 gHelpBlockWidth;
EFI_GUID gZeroGuid = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
EFI_GUID gSetupBrowserGuid = {
0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}
};
FORM_BROWSER_FORMSET *gOldFormSet;
FUNCTIION_KEY_SETTING gFunctionKeySettingTable[] = {
//
// Boot Manager
//
{
{
0x847bc3fe,
0xb974,
0x446d,
{
0x94,
0x49,
0x5a,
0xd5,
0x41,
0x2e,
0x99,
0x3b
}
},
NONE_FUNCTION_KEY_SETTING
},
//
// Device Manager
//
{
{
0x3ebfa8e6,
0x511d,
0x4b5b,
{
0xa9,
0x5f,
0xfb,
0x38,
0x26,
0xf,
0x1c,
0x27
}
},
NONE_FUNCTION_KEY_SETTING
},
//
// BMM FormSet.
//
{
{
0x642237c7,
0x35d4,
0x472d,
{
0x83,
0x65,
0x12,
0xe0,
0xcc,
0xf2,
0x7a,
0x22
}
},
NONE_FUNCTION_KEY_SETTING
},
//
// BMM File Explorer FormSet.
//
{
{
0x1f2d63e1,
0xfebd,
0x4dc7,
{
0x9c,
0xc5,
0xba,
0x2b,
0x1c,
0xef,
0x9c,
0x5b
}
},
NONE_FUNCTION_KEY_SETTING
},
};
/**
This is the routine which an external caller uses to direct the browser
where to obtain it's information.
@param This The Form Browser protocol instanse.
@param Handles A pointer to an array of Handles. If HandleCount > 1 we
display a list of the formsets for the handles specified.
@param HandleCount The number of Handles specified in Handle.
@param FormSetGuid This field points to the EFI_GUID which must match the Guid
field in the EFI_IFR_FORM_SET op-code for the specified
forms-based package. If FormSetGuid is NULL, then this
function will display the first found forms package.
@param FormId This field specifies which EFI_IFR_FORM to render as the first
displayable page. If this field has a value of 0x0000, then
the forms browser will render the specified forms in their encoded order.
@param ScreenDimensions Points to recommended form dimensions, including any non-content area, in
characters.
@param ActionRequest Points to the action recommended by the form.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_NOT_FOUND No valid forms could be found to display.
**/
EFI_STATUS
EFIAPI
SendForm (
IN CONST EFI_FORM_BROWSER2_PROTOCOL *This,
IN EFI_HII_HANDLE *Handles,
IN UINTN HandleCount,
IN EFI_GUID *FormSetGuid, OPTIONAL
IN UINT16 FormId, OPTIONAL
IN CONST EFI_SCREEN_DESCRIPTOR *ScreenDimensions, OPTIONAL
OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest OPTIONAL
)
{
EFI_STATUS Status;
UI_MENU_SELECTION *Selection;
UINTN Index;
FORM_BROWSER_FORMSET *FormSet;
//
// Save globals used by SendForm()
//
SaveBrowserContext ();
Status = EFI_SUCCESS;
ZeroMem (&gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
//
// Seed the dimensions in the global
//
gST->ConOut->QueryMode (
gST->ConOut,
gST->ConOut->Mode->Mode,
&gScreenDimensions.RightColumn,
&gScreenDimensions.BottomRow
);
if (ScreenDimensions != NULL) {
//
// Check local dimension vs. global dimension.
//
if ((gScreenDimensions.RightColumn < ScreenDimensions->RightColumn) ||
(gScreenDimensions.BottomRow < ScreenDimensions->BottomRow)
) {
Status = EFI_INVALID_PARAMETER;
goto Done;
} else {
//
// Local dimension validation.
//
if ((ScreenDimensions->RightColumn > ScreenDimensions->LeftColumn) &&
(ScreenDimensions->BottomRow > ScreenDimensions->TopRow) &&
((ScreenDimensions->RightColumn - ScreenDimensions->LeftColumn) > 2) &&
(
(ScreenDimensions->BottomRow - ScreenDimensions->TopRow) > STATUS_BAR_HEIGHT +
SCROLL_ARROW_HEIGHT *
2 +
FRONT_PAGE_HEADER_HEIGHT +
FOOTER_HEIGHT +
1
)
) {
CopyMem (&gScreenDimensions, (VOID *) ScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
} else {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
}
}
gOptionBlockWidth = (CHAR16) ((gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3);
gPromptBlockWidth = (CHAR16) (gOptionBlockWidth + LEFT_SKIPPED_COLUMNS);
gHelpBlockWidth = (CHAR16) (gOptionBlockWidth - LEFT_SKIPPED_COLUMNS);
//
// Initialize the strings for the browser, upon exit of the browser, the strings will be freed
//
InitializeBrowserStrings ();
gFunctionKeySetting = DEFAULT_FUNCTION_KEY_SETTING;
//
// Ensure we are in Text mode
//
gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
for (Index = 0; Index < HandleCount; Index++) {
Selection = AllocateZeroPool (sizeof (UI_MENU_SELECTION));
ASSERT (Selection != NULL);
Selection->Handle = Handles[Index];
if (FormSetGuid != NULL) {
CopyMem (&Selection->FormSetGuid, FormSetGuid, sizeof (EFI_GUID));
Selection->FormId = FormId;
}
gOldFormSet = NULL;
do {
FormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET));
ASSERT (FormSet != NULL);
//
// Initialize internal data structures of FormSet
//
Status = InitializeFormSet (Selection->Handle, &Selection->FormSetGuid, FormSet);
if (EFI_ERROR (Status) || IsListEmpty (&FormSet->FormListHead)) {
DestroyFormSet (FormSet);
break;
}
Selection->FormSet = FormSet;
//
// Display this formset
//
gCurrentSelection = Selection;
Status = SetupBrowser (Selection);
gCurrentSelection = NULL;
if (EFI_ERROR (Status)) {
break;
}
} while (Selection->Action == UI_ACTION_REFRESH_FORMSET);
if (gOldFormSet != NULL) {
DestroyFormSet (gOldFormSet);
gOldFormSet = NULL;
}
FreePool (Selection);
}
if (ActionRequest != NULL) {
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
if (gResetRequired) {
*ActionRequest = EFI_BROWSER_ACTION_REQUEST_RESET;
}
}
FreeBrowserStrings ();
gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
gST->ConOut->ClearScreen (gST->ConOut);
Done:
//
// Restore globals used by SendForm()
//
RestoreBrowserContext ();
return Status;
}
/**
This function is called by a callback handler to retrieve uncommitted state
data from the browser.
@param This A pointer to the EFI_FORM_BROWSER2_PROTOCOL
instance.
@param ResultsDataSize A pointer to the size of the buffer associated
with ResultsData.
@param ResultsData A string returned from an IFR browser or
equivalent. The results string will have no
routing information in them.
@param RetrieveData A BOOLEAN field which allows an agent to retrieve
(if RetrieveData = TRUE) data from the uncommitted
browser state information or set (if RetrieveData
= FALSE) data in the uncommitted browser state
information.
@param VariableGuid An optional field to indicate the target variable
GUID name to use.
@param VariableName An optional field to indicate the target
human-readable variable name.
@retval EFI_SUCCESS The results have been distributed or are awaiting
distribution.
@retval EFI_BUFFER_TOO_SMALL The ResultsDataSize specified was too small to
contain the results data.
**/
EFI_STATUS
EFIAPI
BrowserCallback (
IN CONST EFI_FORM_BROWSER2_PROTOCOL *This,
IN OUT UINTN *ResultsDataSize,
IN OUT EFI_STRING ResultsData,
IN BOOLEAN RetrieveData,
IN CONST EFI_GUID *VariableGuid, OPTIONAL
IN CONST CHAR16 *VariableName OPTIONAL
)
{
EFI_STATUS Status;
LIST_ENTRY *Link;
FORMSET_STORAGE *Storage;
FORM_BROWSER_FORMSET *FormSet;
BOOLEAN Found;
CHAR16 *ConfigResp;
CHAR16 *StrPtr;
UINTN BufferSize;
UINTN TmpSize;
if (ResultsDataSize == NULL || ResultsData == NULL) {
return EFI_INVALID_PARAMETER;
}
if (gCurrentSelection == NULL) {
return EFI_NOT_READY;
}
Storage = NULL;
ConfigResp = NULL;
FormSet = gCurrentSelection->FormSet;
//
// Find target storage
//
Link = GetFirstNode (&FormSet->StorageListHead);
if (IsNull (&FormSet->StorageListHead, Link)) {
return EFI_UNSUPPORTED;
}
if (VariableGuid != NULL) {
//
// Try to find target storage
//
Found = FALSE;
while (!IsNull (&FormSet->StorageListHead, Link)) {
Storage = FORMSET_STORAGE_FROM_LINK (Link);
Link = GetNextNode (&FormSet->StorageListHead, Link);
if (CompareGuid (&Storage->Guid, (EFI_GUID *) VariableGuid)) {
if (Storage->Type == EFI_HII_VARSTORE_BUFFER) {
//
// Buffer storage require both GUID and Name
//
if (VariableName == NULL) {
return EFI_NOT_FOUND;
}
if (StrCmp (Storage->Name, (CHAR16 *) VariableName) != 0) {
continue;
}
}
Found = TRUE;
break;
}
}
if (!Found) {
return EFI_NOT_FOUND;
}
} else {
//
// GUID/Name is not specified, take the first storage in FormSet
//
Storage = FORMSET_STORAGE_FROM_LINK (Link);
}
if (RetrieveData) {
//
// Skip if there is no RequestElement
//
if (Storage->ElementCount == 0) {
return EFI_SUCCESS;
}
//
// Generate <ConfigResp>
//
Status = StorageToConfigResp (Storage, &ConfigResp, FALSE);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Skip <ConfigHdr> and '&' to point to <ConfigBody>
//
StrPtr = ConfigResp + StrLen (Storage->ConfigHdr) + 1;
BufferSize = StrSize (StrPtr);
if (*ResultsDataSize < BufferSize) {
*ResultsDataSize = BufferSize;
FreePool (ConfigResp);
return EFI_BUFFER_TOO_SMALL;
}
*ResultsDataSize = BufferSize;
CopyMem (ResultsData, StrPtr, BufferSize);
FreePool (ConfigResp);
} else {
//
// Prepare <ConfigResp>
//
TmpSize = StrLen (ResultsData);
BufferSize = (TmpSize + StrLen (Storage->ConfigHdr) + 2) * sizeof (CHAR16);
ConfigResp = AllocateZeroPool (BufferSize);
ASSERT (ConfigResp != NULL);
StrCpy (ConfigResp, Storage->ConfigHdr);
StrCat (ConfigResp, L"&");
StrCat (ConfigResp, ResultsData);
//
// Update Browser uncommited data
//
Status = ConfigRespToStorage (Storage, ConfigResp);
if (EFI_ERROR (Status)) {
return Status;
}
}
return EFI_SUCCESS;
}
/**
Initialize Setup Browser driver.
@param ImageHandle The image handle.
@param SystemTable The system table.
@retval EFI_SUCCESS The Setup Browser module is initialized correctly..
@return Other value if failed to initialize the Setup Browser module.
**/
EFI_STATUS
EFIAPI
InitializeSetup (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
//
// Locate required Hii relative protocols
//
Status = gBS->LocateProtocol (
&gEfiHiiDatabaseProtocolGuid,
NULL,
(VOID **) &mHiiDatabase
);
ASSERT_EFI_ERROR (Status);
Status = gBS->LocateProtocol (
&gEfiHiiStringProtocolGuid,
NULL,
(VOID **) &mHiiString
);
ASSERT_EFI_ERROR (Status);
Status = gBS->LocateProtocol (
&gEfiHiiConfigRoutingProtocolGuid,
NULL,
(VOID **) &mHiiConfigRouting
);
ASSERT_EFI_ERROR (Status);
//
// Publish our HII data
//
gHiiHandle = HiiAddPackages (
&gSetupBrowserGuid,
ImageHandle,
SetupBrowserStrings,
NULL
);
ASSERT (gHiiHandle != NULL);
//
// Initialize Driver private data
//
gBannerData = AllocateZeroPool (sizeof (BANNER_DATA));
ASSERT (gBannerData != NULL);
//
// Install FormBrowser2 protocol
//
mPrivateData.Handle = NULL;
Status = gBS->InstallProtocolInterface (
&mPrivateData.Handle,
&gEfiFormBrowser2ProtocolGuid,
EFI_NATIVE_INTERFACE,
&mPrivateData.FormBrowser2
);
ASSERT_EFI_ERROR (Status);
return Status;
}
/**
Create a new string in HII Package List.
@param String The String to be added
@param HiiHandle The package list in the HII database to insert the
specified string.
@return The output string.
**/
EFI_STRING_ID
NewString (
IN CHAR16 *String,
IN EFI_HII_HANDLE HiiHandle
)
{
EFI_STRING_ID StringId;
StringId = HiiSetString (HiiHandle, 0, String, NULL);
ASSERT (StringId != 0);
return StringId;
}
/**
Delete a string from HII Package List.
@param StringId Id of the string in HII database.
@param HiiHandle The HII package list handle.
@retval EFI_SUCCESS The string was deleted successfully.
**/
EFI_STATUS
DeleteString (
IN EFI_STRING_ID StringId,
IN EFI_HII_HANDLE HiiHandle
)
{
CHAR16 NullChar;
NullChar = CHAR_NULL;
HiiSetString (HiiHandle, StringId, &NullChar, NULL);
return EFI_SUCCESS;
}
/**
Get the string based on the StringId and HII Package List Handle.
@param Token The String's ID.
@param HiiHandle The package list in the HII database to search for
the specified string.
@return The output string.
**/
CHAR16 *
GetToken (
IN EFI_STRING_ID Token,
IN EFI_HII_HANDLE HiiHandle
)
{
EFI_STRING String;
if (HiiHandle == NULL) {
return NULL;
}
String = HiiGetString (HiiHandle, Token, NULL);
if (String == NULL) {
String = AllocateCopyPool (sizeof (mUnknownString), mUnknownString);
ASSERT (String != NULL);
}
return (CHAR16 *) String;
}
/**
Allocate new memory and then copy the Unicode string Source to Destination.
@param Dest Location to copy string
@param Src String to copy
**/
VOID
NewStringCpy (
IN OUT CHAR16 **Dest,
IN CHAR16 *Src
)
{
if (*Dest != NULL) {
FreePool (*Dest);
}
*Dest = AllocateCopyPool (StrSize (Src), Src);
ASSERT (*Dest != NULL);
}
/**
Allocate new memory and concatinate Source on the end of Destination.
@param Dest String to added to the end of.
@param Src String to concatinate.
**/
VOID
NewStringCat (
IN OUT CHAR16 **Dest,
IN CHAR16 *Src
)
{
CHAR16 *NewString;
UINTN TmpSize;
if (*Dest == NULL) {
NewStringCpy (Dest, Src);
return;
}
TmpSize = StrSize (*Dest);
NewString = AllocateZeroPool (TmpSize + StrSize (Src) - 1);
ASSERT (NewString != NULL);
StrCpy (NewString, *Dest);
StrCat (NewString, Src);
FreePool (*Dest);
*Dest = NewString;
}
/**
Synchronize Storage's Edit copy to Shadow copy.
@param Storage The Storage to be synchronized.
**/
VOID
SynchronizeStorage (
IN FORMSET_STORAGE *Storage
)
{
LIST_ENTRY *Link;
NAME_VALUE_NODE *Node;
switch (Storage->Type) {
case EFI_HII_VARSTORE_BUFFER:
CopyMem (Storage->Buffer, Storage->EditBuffer, Storage->Size);
break;
case EFI_HII_VARSTORE_NAME_VALUE:
Link = GetFirstNode (&Storage->NameValueListHead);
while (!IsNull (&Storage->NameValueListHead, Link)) {
Node = NAME_VALUE_NODE_FROM_LINK (Link);
NewStringCpy (&Node->Value, Node->EditValue);
Link = GetNextNode (&Storage->NameValueListHead, Link);
}
break;
case EFI_HII_VARSTORE_EFI_VARIABLE:
default:
break;
}
}
/**
Get Value for given Name from a NameValue Storage.
@param Storage The NameValue Storage.
@param Name The Name.
@param Value The retured Value.
@retval EFI_SUCCESS Value found for given Name.
@retval EFI_NOT_FOUND No such Name found in NameValue storage.
**/
EFI_STATUS
GetValueByName (
IN FORMSET_STORAGE *Storage,
IN CHAR16 *Name,
IN OUT CHAR16 **Value
)
{
LIST_ENTRY *Link;
NAME_VALUE_NODE *Node;
*Value = NULL;
Link = GetFirstNode (&Storage->NameValueListHead);
while (!IsNull (&Storage->NameValueListHead, Link)) {
Node = NAME_VALUE_NODE_FROM_LINK (Link);
if (StrCmp (Name, Node->Name) == 0) {
NewStringCpy (Value, Node->EditValue);
return EFI_SUCCESS;
}
Link = GetNextNode (&Storage->NameValueListHead, Link);
}
return EFI_NOT_FOUND;
}
/**
Set Value of given Name in a NameValue Storage.
@param Storage The NameValue Storage.
@param Name The Name.
@param Value The Value to set.
@param Edit Whether update editValue or Value.
@retval EFI_SUCCESS Value found for given Name.
@retval EFI_NOT_FOUND No such Name found in NameValue storage.
**/
EFI_STATUS
SetValueByName (
IN FORMSET_STORAGE *Storage,
IN CHAR16 *Name,
IN CHAR16 *Value,
IN BOOLEAN Edit
)
{
LIST_ENTRY *Link;
NAME_VALUE_NODE *Node;
CHAR16 *Buffer;
Link = GetFirstNode (&Storage->NameValueListHead);
while (!IsNull (&Storage->NameValueListHead, Link)) {
Node = NAME_VALUE_NODE_FROM_LINK (Link);
if (StrCmp (Name, Node->Name) == 0) {
if (Edit) {
Buffer = Node->EditValue;
} else {
Buffer = Node->Value;
}
if (Buffer != NULL) {
FreePool (Buffer);
}
Buffer = AllocateCopyPool (StrSize (Value), Value);
ASSERT (Buffer != NULL);
if (Edit) {
Node->EditValue = Buffer;
} else {
Node->Value = Buffer;
}
return EFI_SUCCESS;
}
Link = GetNextNode (&Storage->NameValueListHead, Link);
}
return EFI_NOT_FOUND;
}
/**
Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.
@param Buffer The Storage to be conveted.
@param ConfigResp The returned <ConfigResp>.
@param SingleForm Whether update data for single form or formset level.
@retval EFI_SUCCESS Convert success.
@retval EFI_INVALID_PARAMETER Incorrect storage type.
**/
EFI_STATUS
StorageToConfigResp (
IN VOID *Buffer,
IN CHAR16 **ConfigResp,
IN BOOLEAN SingleForm
)
{
EFI_STATUS Status;
EFI_STRING Progress;
LIST_ENTRY *Link;
NAME_VALUE_NODE *Node;
CHAR16 *ConfigRequest;
FORMSET_STORAGE *Storage;
FORM_BROWSER_CONFIG_REQUEST *ConfigInfo;
Status = EFI_SUCCESS;
if (SingleForm) {
ConfigInfo = (FORM_BROWSER_CONFIG_REQUEST *) Buffer;
Storage = ConfigInfo->Storage;
ConfigRequest = ConfigInfo->ConfigRequest;
} else {
Storage = (FORMSET_STORAGE *) Buffer;
ConfigRequest = Storage->ConfigRequest;
}
switch (Storage->Type) {
case EFI_HII_VARSTORE_BUFFER:
Status = mHiiConfigRouting->BlockToConfig (
mHiiConfigRouting,
ConfigRequest,
Storage->EditBuffer,
Storage->Size,
ConfigResp,
&Progress
);
break;
case EFI_HII_VARSTORE_NAME_VALUE:
*ConfigResp = NULL;
NewStringCat (ConfigResp, Storage->ConfigHdr);
Link = GetFirstNode (&Storage->NameValueListHead);
while (!IsNull (&Storage->NameValueListHead, Link)) {
Node = NAME_VALUE_NODE_FROM_LINK (Link);
if (StrStr (ConfigRequest, Node->Name) != NULL) {
NewStringCat (ConfigResp, L"&");
NewStringCat (ConfigResp, Node->Name);
NewStringCat (ConfigResp, L"=");
NewStringCat (ConfigResp, Node->EditValue);
}
Link = GetNextNode (&Storage->NameValueListHead, Link);
}
break;
case EFI_HII_VARSTORE_EFI_VARIABLE:
default:
Status = EFI_INVALID_PARAMETER;
break;
}
return Status;
}
/**
Convert <ConfigResp> to settings in Buffer Storage or NameValue Storage.
@param Storage The Storage to receive the settings.
@param ConfigResp The <ConfigResp> to be converted.
@retval EFI_SUCCESS Convert success.
@retval EFI_INVALID_PARAMETER Incorrect storage type.
**/
EFI_STATUS
ConfigRespToStorage (
IN FORMSET_STORAGE *Storage,
IN CHAR16 *ConfigResp
)
{
EFI_STATUS Status;
EFI_STRING Progress;
UINTN BufferSize;
CHAR16 *StrPtr;
CHAR16 *Name;
CHAR16 *Value;
Status = EFI_SUCCESS;
switch (Storage->Type) {
case EFI_HII_VARSTORE_BUFFER:
BufferSize = Storage->Size;
Status = mHiiConfigRouting->ConfigToBlock (
mHiiConfigRouting,
ConfigResp,
Storage->EditBuffer,
&BufferSize,
&Progress
);
break;
case EFI_HII_VARSTORE_NAME_VALUE:
StrPtr = StrStr (ConfigResp, L"PATH");
if (StrPtr == NULL) {
break;
}
StrPtr = StrStr (ConfigResp, L"&");
while (StrPtr != NULL) {
//
// Skip '&'
//
StrPtr = StrPtr + 1;
Name = StrPtr;
StrPtr = StrStr (StrPtr, L"=");
if (StrPtr == NULL) {
break;
}
*StrPtr = 0;
//
// Skip '='
//
StrPtr = StrPtr + 1;
Value = StrPtr;
StrPtr = StrStr (StrPtr, L"&");
if (StrPtr != NULL) {
*StrPtr = 0;
}
SetValueByName (Storage, Name, Value, TRUE);
}
break;
case EFI_HII_VARSTORE_EFI_VARIABLE:
default:
Status = EFI_INVALID_PARAMETER;
break;
}
return Status;
}
/**
Get Question's current Value.
@param FormSet FormSet data structure.
@param Form Form data structure.
@param Question Question to be initialized.
@param Cached TRUE: get from Edit copy FALSE: get from original
Storage
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
GetQuestionValue (
IN FORM_BROWSER_FORMSET *FormSet,
IN FORM_BROWSER_FORM *Form,
IN OUT FORM_BROWSER_STATEMENT *Question,
IN BOOLEAN Cached
)
{
EFI_STATUS Status;
BOOLEAN Enabled;
BOOLEAN Pending;
UINT8 *Dst;
UINTN StorageWidth;
EFI_TIME EfiTime;
FORMSET_STORAGE *Storage;
EFI_IFR_TYPE_VALUE *QuestionValue;
CHAR16 *ConfigRequest;
CHAR16 *Progress;
CHAR16 *Result;
CHAR16 *Value;
CHAR16 *StringPtr;
UINTN Length;
UINTN Index;
UINTN LengthStr;
BOOLEAN IsBufferStorage;
BOOLEAN IsString;
CHAR16 TemStr[5];
UINT8 DigitUint8;
Status = EFI_SUCCESS;
//
// Statement don't have storage, skip them
//
if (Question->QuestionId == 0) {
return Status;
}
//
// Question value is provided by an Expression, evaluate it
//
if (Question->ValueExpression != NULL) {
Status = EvaluateExpression (FormSet, Form, Question->ValueExpression);
if (!EFI_ERROR (Status)) {
CopyMem (&Question->HiiValue, &Question->ValueExpression->Result, sizeof (EFI_HII_VALUE));
}
return Status;
}
//
// Get question value by read expression.
//
if (Question->ReadExpression != NULL && Form->FormType == STANDARD_MAP_FORM_TYPE) {
Status = EvaluateExpression (FormSet, Form, Question->ReadExpression);
if (!EFI_ERROR (Status) && (Question->ReadExpression->Result.Type < EFI_IFR_TYPE_OTHER)) {
//
// Only update question value to the valid result.
//
CopyMem (&Question->HiiValue, &Question->ReadExpression->Result, sizeof (EFI_HII_VALUE));
return EFI_SUCCESS;
}
}
//
// Question value is provided by RTC
//
Storage = Question->Storage;
QuestionValue = &Question->HiiValue.Value;
if (Storage == NULL) {
//
// It's a Question without storage, or RTC date/time
//
if (Question->Operand == EFI_IFR_DATE_OP || Question->Operand == EFI_IFR_TIME_OP) {
//
// Date and time define the same Flags bit
//
switch (Question->Flags & EFI_QF_DATE_STORAGE) {
case QF_DATE_STORAGE_TIME:
Status = gRT->GetTime (&EfiTime, NULL);
break;
case QF_DATE_STORAGE_WAKEUP:
Status = gRT->GetWakeupTime (&Enabled, &Pending, &EfiTime);
break;
case QF_DATE_STORAGE_NORMAL:
default:
//
// For date/time without storage
//
return EFI_SUCCESS;
}
if (EFI_ERROR (Status)) {
return Status;
}
if (Question->Operand == EFI_IFR_DATE_OP) {
QuestionValue->date.Year = EfiTime.Year;
QuestionValue->date.Month = EfiTime.Month;
QuestionValue->date.Day = EfiTime.Day;
} else {
QuestionValue->time.Hour = EfiTime.Hour;
QuestionValue->time.Minute = EfiTime.Minute;
QuestionValue->time.Second = EfiTime.Second;
}
}
return EFI_SUCCESS;
}
//
// Question value is provided by EFI variable
//
StorageWidth = Question->StorageWidth;
if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
if (Question->BufferValue != NULL) {
Dst = Question->BufferValue;
} else {
Dst = (UINT8 *) QuestionValue;
}
Status = gRT->GetVariable (
Question->VariableName,
&Storage->Guid,
NULL,
&StorageWidth,
Dst
);
//
// Always return success, even this EFI variable doesn't exist
//
return EFI_SUCCESS;
}
//
// Question Value is provided by Buffer Storage or NameValue Storage
//
if (Question->BufferValue != NULL) {
//
// This Question is password or orderedlist
//
Dst = Question->BufferValue;
} else {
//
// Other type of Questions
//
Dst = (UINT8 *) &Question->HiiValue.Value;
}
IsBufferStorage = (BOOLEAN) ((Storage->Type == EFI_HII_VARSTORE_BUFFER) ? TRUE : FALSE);
IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE);
if (Cached) {
if (IsBufferStorage) {
//
// Copy from storage Edit buffer
//
CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth);
} else {
Value = NULL;
Status = GetValueByName (Storage, Question->VariableName, &Value);
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (Value != NULL);
LengthStr = StrLen (Value);
Status = EFI_SUCCESS;
if (IsString) {
//
// Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
// Add string tail char L'\0' into Length
//
Length = StorageWidth + sizeof (CHAR16);
if (Length < ((LengthStr / 4 + 1) * 2)) {
Status = EFI_BUFFER_TOO_SMALL;
} else {
StringPtr = (CHAR16 *) Dst;
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0; Index < LengthStr; Index += 4) {
StrnCpy (TemStr, Value + Index, 4);
StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);
}
//
// Add tailing L'\0' character
//
StringPtr[Index/4] = L'\0';
}
} else {
if (StorageWidth < ((LengthStr + 1) / 2)) {
Status = EFI_BUFFER_TOO_SMALL;
} else {
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0; Index < LengthStr; Index ++) {
TemStr[0] = Value[LengthStr - Index - 1];
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
if ((Index & 1) == 0) {
Dst [Index/2] = DigitUint8;
} else {
Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);
}
}
}
}
FreePool (Value);
}
} else {
//
// Request current settings from Configuration Driver
//
if (FormSet->ConfigAccess == NULL) {
return EFI_NOT_FOUND;
}
//
// <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
// <ConfigHdr> + "&" + <VariableName>
//
if (IsBufferStorage) {
Length = StrLen (Storage->ConfigHdr);
Length += StrLen (Question->BlockName);
} else {
Length = StrLen (Storage->ConfigHdr);
Length += StrLen (Question->VariableName) + 1;
}
ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));
ASSERT (ConfigRequest != NULL);
StrCpy (ConfigRequest, Storage->ConfigHdr);
if (IsBufferStorage) {
StrCat (ConfigRequest, Question->BlockName);
} else {
StrCat (ConfigRequest, L"&");
StrCat (ConfigRequest, Question->VariableName);
}
Status = FormSet->ConfigAccess->ExtractConfig (
FormSet->ConfigAccess,
ConfigRequest,
&Progress,
&Result
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Skip <ConfigRequest>
//
Value = Result + Length;
if (IsBufferStorage) {
//
// Skip "&VALUE"
//
Value = Value + 6;
}
if (*Value != '=') {
FreePool (Result);
return EFI_NOT_FOUND;
}
//
// Skip '=', point to value
//
Value = Value + 1;
//
// Suppress <AltResp> if any
//
StringPtr = Value;
while (*StringPtr != L'\0' && *StringPtr != L'&') {
StringPtr++;
}
*StringPtr = L'\0';
LengthStr = StrLen (Value);
Status = EFI_SUCCESS;
if (!IsBufferStorage && IsString) {
//
// Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
// Add string tail char L'\0' into Length
//
Length = StorageWidth + sizeof (CHAR16);
if (Length < ((LengthStr / 4 + 1) * 2)) {
Status = EFI_BUFFER_TOO_SMALL;
} else {
StringPtr = (CHAR16 *) Dst;
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0; Index < LengthStr; Index += 4) {
StrnCpy (TemStr, Value + Index, 4);
StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);
}
//
// Add tailing L'\0' character
//
StringPtr[Index/4] = L'\0';
}
} else {
if (StorageWidth < ((LengthStr + 1) / 2)) {
Status = EFI_BUFFER_TOO_SMALL;
} else {
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0; Index < LengthStr; Index ++) {
TemStr[0] = Value[LengthStr - Index - 1];
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
if ((Index & 1) == 0) {
Dst [Index/2] = DigitUint8;
} else {
Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);
}
}
}
}
if (EFI_ERROR (Status)) {
FreePool (Result);
return Status;
}
//
// Synchronize Edit Buffer
//
if (IsBufferStorage) {
CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Dst, StorageWidth);
} else {
SetValueByName (Storage, Question->VariableName, Value, TRUE);
}
FreePool (Result);
}
return Status;
}
/**
Save Question Value to edit copy(cached) or Storage(uncached).
@param FormSet FormSet data structure.
@param Form Form data structure.
@param Question Pointer to the Question.
@param Cached TRUE: set to Edit copy FALSE: set to original
Storage
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
SetQuestionValue (
IN FORM_BROWSER_FORMSET *FormSet,
IN FORM_BROWSER_FORM *Form,
IN OUT FORM_BROWSER_STATEMENT *Question,
IN BOOLEAN Cached
)
{
EFI_STATUS Status;
BOOLEAN Enabled;
BOOLEAN Pending;
UINT8 *Src;
EFI_TIME EfiTime;
UINTN BufferLen;
UINTN StorageWidth;
FORMSET_STORAGE *Storage;
EFI_IFR_TYPE_VALUE *QuestionValue;
CHAR16 *ConfigResp;
CHAR16 *Progress;
CHAR16 *Value;
UINTN Length;
BOOLEAN IsBufferStorage;
BOOLEAN IsString;
UINT8 *TemBuffer;
CHAR16 *TemName;
CHAR16 *TemString;
UINTN Index;
Status = EFI_SUCCESS;
//
// Statement don't have storage, skip them
//
if (Question->QuestionId == 0) {
return Status;
}
//
// If Question value is provided by an Expression, then it is read only
//
if (Question->ValueExpression != NULL) {
return Status;
}
//
// Before set question value, evaluate its write expression.
//
if (Question->WriteExpression != NULL && Form->FormType == STANDARD_MAP_FORM_TYPE) {
Status = EvaluateExpression (FormSet, Form, Question->WriteExpression);
if (EFI_ERROR (Status)) {
return Status;
}
}
//
// Question value is provided by RTC
//
Storage = Question->Storage;
QuestionValue = &Question->HiiValue.Value;
if (Storage == NULL) {
//
// It's a Question without storage, or RTC date/time
//
if (Question->Operand == EFI_IFR_DATE_OP || Question->Operand == EFI_IFR_TIME_OP) {
//
// Date and time define the same Flags bit
//
switch (Question->Flags & EFI_QF_DATE_STORAGE) {
case QF_DATE_STORAGE_TIME:
Status = gRT->GetTime (&EfiTime, NULL);
break;
case QF_DATE_STORAGE_WAKEUP:
Status = gRT->GetWakeupTime (&Enabled, &Pending, &EfiTime);
break;
case QF_DATE_STORAGE_NORMAL:
default:
//
// For date/time without storage
//
return EFI_SUCCESS;
}
if (EFI_ERROR (Status)) {
return Status;
}
if (Question->Operand == EFI_IFR_DATE_OP) {
EfiTime.Year = QuestionValue->date.Year;
EfiTime.Month = QuestionValue->date.Month;
EfiTime.Day = QuestionValue->date.Day;
} else {
EfiTime.Hour = QuestionValue->time.Hour;
EfiTime.Minute = QuestionValue->time.Minute;
EfiTime.Second = QuestionValue->time.Second;
}
if ((Question->Flags & EFI_QF_DATE_STORAGE) == QF_DATE_STORAGE_TIME) {
Status = gRT->SetTime (&EfiTime);
} else {
Status = gRT->SetWakeupTime (TRUE, &EfiTime);
}
}
return Status;
}
//
// Question value is provided by EFI variable
//
StorageWidth = Question->StorageWidth;
if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
if (Question->BufferValue != NULL) {
Src = Question->BufferValue;
} else {
Src = (UINT8 *) QuestionValue;
}
Status = gRT->SetVariable (
Question->VariableName,
&Storage->Guid,
Storage->Attributes,
StorageWidth,
Src
);
return Status;
}
//
// Question Value is provided by Buffer Storage or NameValue Storage
//
if (Question->BufferValue != NULL) {
Src = Question->BufferValue;
} else {
Src = (UINT8 *) &Question->HiiValue.Value;
}
IsBufferStorage = (BOOLEAN) ((Storage->Type == EFI_HII_VARSTORE_BUFFER) ? TRUE : FALSE);
IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE);
if (IsBufferStorage) {
//
// Copy to storage edit buffer
//
CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);
} else {
if (IsString) {
//
// Allocate enough string buffer.
//
Value = NULL;
BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16);
Value = AllocateZeroPool (BufferLen);
ASSERT (Value != NULL);
//
// Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
//
TemName = (CHAR16 *) Src;
TemString = Value;
for (; *TemName != L'\0'; TemName++) {
TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);
}
} else {
BufferLen = StorageWidth * 2 + 1;
Value = AllocateZeroPool (BufferLen * sizeof (CHAR16));
ASSERT (Value != NULL);
//
// Convert Buffer to Hex String
//
TemBuffer = Src + StorageWidth - 1;
TemString = Value;
for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) {
TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);
}
}
Status = SetValueByName (Storage, Question->VariableName, Value, TRUE);
FreePool (Value);
}
if (!Cached) {
//
// <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||
// <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"
//
if (IsBufferStorage) {
Length = StrLen (Question->BlockName) + 7;
} else {
Length = StrLen (Question->VariableName) + 2;
}
if (!IsBufferStorage && IsString) {
Length += (StrLen ((CHAR16 *) Src) * 4);
} else {
Length += (StorageWidth * 2);
}
ConfigResp = AllocateZeroPool ((StrLen (Storage->ConfigHdr) + Length + 1) * sizeof (CHAR16));
ASSERT (ConfigResp != NULL);
StrCpy (ConfigResp, Storage->ConfigHdr);
if (IsBufferStorage) {
StrCat (ConfigResp, Question->BlockName);
StrCat (ConfigResp, L"&VALUE=");
} else {
StrCat (ConfigResp, L"&");
StrCat (ConfigResp, Question->VariableName);
StrCat (ConfigResp, L"=");
}
Value = ConfigResp + StrLen (ConfigResp);
if (!IsBufferStorage && IsString) {
//
// Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
//
TemName = (CHAR16 *) Src;
TemString = Value;
for (; *TemName != L'\0'; TemName++) {
TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);
}
} else {
//
// Convert Buffer to Hex String
//
TemBuffer = Src + StorageWidth - 1;
TemString = Value;
for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) {
TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);
}
}
//
// Convert to lower char.
//
for (TemString = Value; *Value != L'\0'; Value++) {
if (*Value >= L'A' && *Value <= L'Z') {
*Value = (CHAR16) (*Value - L'A' + L'a');
}
}
//
// Submit Question Value to Configuration Driver
//
if (FormSet->ConfigAccess != NULL) {
Status = FormSet->ConfigAccess->RouteConfig (
FormSet->ConfigAccess,
ConfigResp,
&Progress
);
if (EFI_ERROR (Status)) {
FreePool (ConfigResp);
return Status;
}
}
FreePool (ConfigResp);
//
// Synchronize shadow Buffer
//
SynchronizeStorage (Storage);
}
return Status;
}
/**
Perform inconsistent check for a Form.
@param FormSet FormSet data structure.
@param Form Form data structure.
@param Question The Question to be validated.
@param Type Validation type: InConsistent or NoSubmit
@retval EFI_SUCCESS Form validation pass.
@retval other Form validation failed.
**/
EFI_STATUS
ValidateQuestion (
IN FORM_BROWSER_FORMSET *FormSet,
IN FORM_BROWSER_FORM *Form,
IN FORM_BROWSER_STATEMENT *Question,
IN UINTN Type
)
{
EFI_STATUS Status;
LIST_ENTRY *Link;
LIST_ENTRY *ListHead;
EFI_STRING PopUp;
EFI_INPUT_KEY Key;
FORM_EXPRESSION *Expression;
if (Type == EFI_HII_EXPRESSION_INCONSISTENT_IF) {
ListHead = &Question->InconsistentListHead;
} else if (Type == EFI_HII_EXPRESSION_NO_SUBMIT_IF) {
ListHead = &Question->NoSubmitListHead;
} else {
return EFI_UNSUPPORTED;
}
Link = GetFirstNode (ListHead);
while (!IsNull (ListHead, Link)) {
Expression = FORM_EXPRESSION_FROM_LINK (Link);
//
// Evaluate the expression
//
Status = EvaluateExpression (FormSet, Form, Expression);
if (EFI_ERROR (Status)) {
return Status;
}
if (Expression->Result.Value.b) {
//
// Condition meet, show up error message
//
if (Expression->Error != 0) {
PopUp = GetToken (Expression->Error, FormSet->HiiHandle);
do {
CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, PopUp, gPressEnter, gEmptyString);
} while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
FreePool (PopUp);
}
return EFI_NOT_READY;
}
Link = GetNextNode (ListHead, Link);
}
return EFI_SUCCESS;
}
/**
Perform NoSubmit check for each Form in FormSet.
@param FormSet FormSet data structure.
@param CurrentForm Current input form data structure.
@retval EFI_SUCCESS Form validation pass.
@retval other Form validation failed.
**/
EFI_STATUS
NoSubmitCheck (
IN FORM_BROWSER_FORMSET *FormSet,
IN FORM_BROWSER_FORM *CurrentForm
)
{
EFI_STATUS Status;
LIST_ENTRY *Link;
FORM_BROWSER_STATEMENT *Question;
FORM_BROWSER_FORM *Form;
LIST_ENTRY *LinkForm;
LinkForm = GetFirstNode (&FormSet->FormListHead);
while (!IsNull (&FormSet->FormListHead, LinkForm)) {
Form = FORM_BROWSER_FORM_FROM_LINK (LinkForm);
LinkForm = GetNextNode (&FormSet->FormListHead, LinkForm);
if (CurrentForm != NULL && CurrentForm != Form) {
continue;
}
Link = GetFirstNode (&Form->StatementListHead);
while (!IsNull (&Form->StatementListHead, Link)) {
Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
Status = ValidateQuestion (FormSet, Form, Question, EFI_HII_EXPRESSION_NO_SUBMIT_IF);
if (EFI_ERROR (Status)) {
return Status;
}
Link = GetNextNode (&Form->StatementListHead, Link);
}
}
return EFI_SUCCESS;
}
/**
Restore Storage's Edit copy to Shadow copy.
@param Storage The Storage to be synchronized.
**/
VOID
RestoreStorage (
IN FORMSET_STORAGE *Storage
)
{
LIST_ENTRY *Link;
NAME_VALUE_NODE *Node;
switch (Storage->Type) {
case EFI_HII_VARSTORE_BUFFER:
CopyMem (Storage->EditBuffer, Storage->Buffer, Storage->Size);
break;
case EFI_HII_VARSTORE_NAME_VALUE:
Link = GetFirstNode (&Storage->NameValueListHead);
while (!IsNull (&Storage->NameValueListHead, Link)) {
Node = NAME_VALUE_NODE_FROM_LINK (Link);
if (Node->EditValue != NULL) {
FreePool (Node->EditValue);
}
Node->EditValue = AllocateCopyPool (StrSize (Node->Value), Node->Value);
ASSERT (Node->EditValue != NULL);
Link = GetNextNode (&Storage->NameValueListHead, Link);
}
break;
case EFI_HII_VARSTORE_EFI_VARIABLE:
default:
break;
}
}
/**
Fill storage's edit copy with settings requested from Configuration Driver.
@param FormSet FormSet data structure.
@param ConfigInfo The config info related to this form.
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
FormRestoreStorage (
IN FORM_BROWSER_FORMSET *FormSet,
IN FORM_BROWSER_CONFIG_REQUEST *ConfigInfo
)
{
EFI_STATUS Status;
EFI_STRING Progress;
EFI_STRING Result;
UINTN BufferSize;
LIST_ENTRY *Link;
NAME_VALUE_NODE *Node;
Status = EFI_SUCCESS;
Result = NULL;
if (FormSet->ConfigAccess == NULL) {
return EFI_NOT_FOUND;
}
if (ConfigInfo->ElementCount == 0) {
//
// Skip if there is no RequestElement
//
return EFI_SUCCESS;
}
if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_BUFFER) {
BufferSize = ConfigInfo->Storage->Size;
Status = mHiiConfigRouting->BlockToConfig(
mHiiConfigRouting,
ConfigInfo->ConfigRequest,
ConfigInfo->Storage->Buffer,
BufferSize,
&Result,
&Progress
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = mHiiConfigRouting->ConfigToBlock (
mHiiConfigRouting,
Result,
ConfigInfo->Storage->EditBuffer,
&BufferSize,
&Progress
);
if (Result != NULL) {
FreePool (Result);
}
if (EFI_ERROR (Status)) {
return Status;
}
} else if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {
Link = GetFirstNode (&ConfigInfo->Storage->NameValueListHead);
while (!IsNull (&ConfigInfo->Storage->NameValueListHead, Link)) {
Node = NAME_VALUE_NODE_FROM_LINK (Link);
if (StrStr (ConfigInfo->ConfigRequest, Node->Name) != NULL) {
if (Node->EditValue != NULL) {
FreePool (Node->EditValue);
}
Node->EditValue = AllocateCopyPool (StrSize (Node->Value), Node->Value);
ASSERT (Node->EditValue != NULL);
}
Link = GetNextNode (&ConfigInfo->Storage->NameValueListHead, Link);
}
}
return Status;
}
/**
Discard data for form level or formset level.
@param FormSet FormSet data structure.
@param Form Form data structure.
@param SingleForm Only discard single form or formset.
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
DiscardForm (
IN FORM_BROWSER_FORMSET *FormSet,
IN FORM_BROWSER_FORM *Form,
IN BOOLEAN SingleForm
)
{
LIST_ENTRY *Link;
FORMSET_STORAGE *Storage;
FORM_BROWSER_CONFIG_REQUEST *ConfigInfo;
if (SingleForm) {
if (Form->NvUpdateRequired) {
ConfigInfo = NULL;
Link = GetFirstNode (&Form->ConfigRequestHead);
while (!IsNull (&Form->ConfigRequestHead, Link)) {
ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link);
Link = GetNextNode (&Form->ConfigRequestHead, Link);
if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
continue;
}
//
// Skip if there is no RequestElement
//
if (ConfigInfo->ElementCount == 0) {
continue;
}
//
// Prepare <ConfigResp>
//
FormRestoreStorage(FormSet, ConfigInfo);
}
Form->NvUpdateRequired = FALSE;
}
} else {
if (IsNvUpdateRequired(FormSet)) {
//
// Discard Buffer storage or Name/Value storage
//
Link = GetFirstNode (&FormSet->StorageListHead);
while (!IsNull (&FormSet->StorageListHead, Link)) {
Storage = FORMSET_STORAGE_FROM_LINK (Link);
Link = GetNextNode (&FormSet->StorageListHead, Link);
if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
continue;
}
//
// Skip if there is no RequestElement
//
if (Storage->ElementCount == 0) {
continue;
}
RestoreStorage(Storage);
}
UpdateNvInfoInForm(FormSet, FALSE);
}
}
return EFI_SUCCESS;
}
/**
Submit data for form level or formset level.
@param FormSet FormSet data structure.
@param Form Form data structure.
@param SingleForm whether submit for the single form or all form set.
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
SubmitForm (
IN FORM_BROWSER_FORMSET *FormSet,
IN FORM_BROWSER_FORM *Form,
IN BOOLEAN SingleForm
)
{
EFI_STATUS Status;
LIST_ENTRY *Link;
EFI_STRING ConfigResp;
EFI_STRING Progress;
FORMSET_STORAGE *Storage;
FORM_BROWSER_CONFIG_REQUEST *ConfigInfo;
//
// Validate the Form by NoSubmit check
//
if (SingleForm) {
Status = NoSubmitCheck (FormSet, Form);
} else {
Status = NoSubmitCheck (FormSet, NULL);
}
if (EFI_ERROR (Status)) {
return Status;
}
if (SingleForm) {
ConfigInfo = NULL;
Link = GetFirstNode (&Form->ConfigRequestHead);
while (!IsNull (&Form->ConfigRequestHead, Link)) {
ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link);
Link = GetNextNode (&Form->ConfigRequestHead, Link);
if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
continue;
}
//
// Skip if there is no RequestElement
//
if (ConfigInfo->ElementCount == 0) {
continue;
}
//
// Prepare <ConfigResp>
//
Status = StorageToConfigResp (ConfigInfo, &ConfigResp, TRUE);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Send <ConfigResp> to Configuration Driver
//
if (FormSet->ConfigAccess != NULL) {
Status = FormSet->ConfigAccess->RouteConfig (
FormSet->ConfigAccess,
ConfigResp,
&Progress
);
if (EFI_ERROR (Status)) {
FreePool (ConfigResp);
return Status;
}
}
FreePool (ConfigResp);
//
// Config success, update storage shadow Buffer
//
SynchronizeStorage (ConfigInfo->Storage);
}
Form->NvUpdateRequired = FALSE;
} else {
//
// Submit Buffer storage or Name/Value storage
//
Link = GetFirstNode (&FormSet->StorageListHead);
while (!IsNull (&FormSet->StorageListHead, Link)) {
Storage = FORMSET_STORAGE_FROM_LINK (Link);
Link = GetNextNode (&FormSet->StorageListHead, Link);
if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
continue;
}
//
// Skip if there is no RequestElement
//
if (Storage->ElementCount == 0) {
continue;
}
//
// Prepare <ConfigResp>
//
Status = StorageToConfigResp (Storage, &ConfigResp, FALSE);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Send <ConfigResp> to Configuration Driver
//
if (FormSet->ConfigAccess != NULL) {
Status = FormSet->ConfigAccess->RouteConfig (
FormSet->ConfigAccess,
ConfigResp,
&Progress
);
if (EFI_ERROR (Status)) {
FreePool (ConfigResp);
return Status;
}
}
FreePool (ConfigResp);
//
// Config success, update storage shadow Buffer
//
SynchronizeStorage (Storage);
}
UpdateNvInfoInForm(FormSet, FALSE);
}
return EFI_SUCCESS;
}
/**
Get Question default value from AltCfg string.
@param FormSet The form set.
@param Question The question.
@param DefaultId The default Id.
@retval EFI_SUCCESS Question is reset to default value.
**/
EFI_STATUS
GetDefaultValueFromAltCfg (
IN FORM_BROWSER_FORMSET *FormSet,
IN OUT FORM_BROWSER_STATEMENT *Question,
IN UINT16 DefaultId
)
{
BOOLEAN IsBufferStorage;
BOOLEAN IsString;
UINTN Length;
FORMSET_STORAGE *Storage;
CHAR16 *ConfigRequest;
CHAR16 *Progress;
CHAR16 *Result;
CHAR16 *ConfigResp;
CHAR16 *Value;
CHAR16 *StringPtr;
UINTN LengthStr;
UINT8 *Dst;
CHAR16 TemStr[5];
UINTN Index;
UINT8 DigitUint8;
EFI_STATUS Status;
Status = EFI_NOT_FOUND;
Length = 0;
Dst = NULL;
ConfigRequest = NULL;
Result = NULL;
ConfigResp = NULL;
Value = NULL;
Storage = Question->Storage;
if ((Storage == NULL) || (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE)) {
return Status;
}
//
// Question Value is provided by Buffer Storage or NameValue Storage
//
if (Question->BufferValue != NULL) {
//
// This Question is password or orderedlist
//
Dst = Question->BufferValue;
} else {
//
// Other type of Questions
//
Dst = (UINT8 *) &Question->HiiValue.Value;
}
IsBufferStorage = (BOOLEAN) ((Storage->Type == EFI_HII_VARSTORE_BUFFER) ? TRUE : FALSE);
IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ? TRUE : FALSE);
//
// <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||
// <ConfigHdr> + "&" + <VariableName>
//
if (IsBufferStorage) {
Length = StrLen (Storage->ConfigHdr);
Length += StrLen (Question->BlockName);
} else {
Length = StrLen (Storage->ConfigHdr);
Length += StrLen (Question->VariableName) + 1;
}
ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));
ASSERT (ConfigRequest != NULL);
StrCpy (ConfigRequest, Storage->ConfigHdr);
if (IsBufferStorage) {
StrCat (ConfigRequest, Question->BlockName);
} else {
StrCat (ConfigRequest, L"&");
StrCat (ConfigRequest, Question->VariableName);
}
Status = FormSet->ConfigAccess->ExtractConfig (
FormSet->ConfigAccess,
ConfigRequest,
&Progress,
&Result
);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Call ConfigRouting GetAltCfg(ConfigRoute, <ConfigResponse>, Guid, Name, DevicePath, AltCfgId, AltCfgResp)
// Get the default configuration string according to the default ID.
//
Status = mHiiConfigRouting->GetAltConfig (
mHiiConfigRouting,
Result,
&Storage->Guid,
Storage->Name,
NULL,
&DefaultId, // it can be NULL to get the current setting.
&ConfigResp
);
//
// The required setting can't be found. So, it is not required to be validated and set.
//
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Skip <ConfigRequest>
//
if (IsBufferStorage) {
Value = StrStr (ConfigResp, L"&VALUE");
ASSERT (Value != NULL);
//
// Skip "&VALUE"
//
Value = Value + 6;
} else {
Value = StrStr (ConfigResp, Question->VariableName);
ASSERT (Value != NULL);
Value = Value + StrLen (Question->VariableName);
}
if (*Value != '=') {
Status = EFI_NOT_FOUND;
goto Done;
}
//
// Skip '=', point to value
//
Value = Value + 1;
//
// Suppress <AltResp> if any
//
StringPtr = Value;
while (*StringPtr != L'\0' && *StringPtr != L'&') {
StringPtr++;
}
*StringPtr = L'\0';
LengthStr = StrLen (Value);
if (!IsBufferStorage && IsString) {
StringPtr = (CHAR16 *) Dst;
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0; Index < LengthStr; Index += 4) {
StrnCpy (TemStr, Value + Index, 4);
StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);
}
//
// Add tailing L'\0' character
//
StringPtr[Index/4] = L'\0';
} else {
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0; Index < LengthStr; Index ++) {
TemStr[0] = Value[LengthStr - Index - 1];
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
if ((Index & 1) == 0) {
Dst [Index/2] = DigitUint8;
} else {
Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);
}
}
}
Done:
if (ConfigRequest != NULL){
FreePool (ConfigRequest);
}
if (ConfigResp != NULL) {
FreePool (ConfigResp);
}
if (Result != NULL) {
FreePool (Result);
}
return Status;
}
/**
Get default Id value used for browser.
@param DefaultId The default id value used by hii.
@retval Browser used default value.
**/
INTN
GetDefaultIdForCallBack (
UINTN DefaultId
)
{
if (DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) {
return EFI_BROWSER_ACTION_DEFAULT_STANDARD;
} else if (DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) {
return EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING;
} else if (DefaultId == EFI_HII_DEFAULT_CLASS_SAFE) {
return EFI_BROWSER_ACTION_DEFAULT_SAFE;
} else if (DefaultId >= EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN && DefaultId < EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN + 0x1000) {
return EFI_BROWSER_ACTION_DEFAULT_PLATFORM + DefaultId - EFI_HII_DEFAULT_CLASS_PLATFORM_BEGIN;
} else if (DefaultId >= EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN && DefaultId < EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN + 0x1000) {
return EFI_BROWSER_ACTION_DEFAULT_HARDWARE + DefaultId - EFI_HII_DEFAULT_CLASS_HARDWARE_BEGIN;
} else if (DefaultId >= EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN && DefaultId < EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN + 0x1000) {
return EFI_BROWSER_ACTION_DEFAULT_FIRMWARE + DefaultId - EFI_HII_DEFAULT_CLASS_FIRMWARE_BEGIN;
} else {
return -1;
}
}
/**
Reset Question to its default value.
@param FormSet The form set.
@param Form The form.
@param Question The question.
@param DefaultId The Class of the default.
@retval EFI_SUCCESS Question is reset to default value.
**/
EFI_STATUS
GetQuestionDefault (
IN FORM_BROWSER_FORMSET *FormSet,
IN FORM_BROWSER_FORM *Form,
IN FORM_BROWSER_STATEMENT *Question,
IN UINT16 DefaultId
)
{
EFI_STATUS Status;
LIST_ENTRY *Link;
QUESTION_DEFAULT *Default;
QUESTION_OPTION *Option;
EFI_HII_VALUE *HiiValue;
UINT8 Index;
EFI_STRING StrValue;
EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
EFI_BROWSER_ACTION_REQUEST ActionRequest;
INTN Action;
Status = EFI_SUCCESS;
StrValue = NULL;
//
// Statement don't have storage, skip them
//
if (Question->QuestionId == 0) {
return Status;
}
//
// There are Five ways to specify default value for a Question:
// 1, use call back function (highest priority)
// 2, use ExtractConfig function
// 3, use nested EFI_IFR_DEFAULT
// 4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)
// 5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)
//
HiiValue = &Question->HiiValue;
//
// Get Question defaut value from call back function.
//
ConfigAccess = FormSet->ConfigAccess;
Action = GetDefaultIdForCallBack (DefaultId);
if ((Action > 0) && ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) && (ConfigAccess != NULL)) {
ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
Status = ConfigAccess->Callback (
ConfigAccess,
Action,
Question->QuestionId,
HiiValue->Type,
&HiiValue->Value,
&ActionRequest
);
if (!EFI_ERROR (Status)) {
return Status;
}
}
//
// Get default value from altcfg string.
//
if (ConfigAccess != NULL) {
Status = GetDefaultValueFromAltCfg(FormSet, Question, DefaultId);
if (!EFI_ERROR (Status)) {
return Status;
}
}
//
// EFI_IFR_DEFAULT has highest priority
//
if (!IsListEmpty (&Question->DefaultListHead)) {
Link = GetFirstNode (&Question->DefaultListHead);
while (!IsNull (&Question->DefaultListHead, Link)) {
Default = QUESTION_DEFAULT_FROM_LINK (Link);
if (Default->DefaultId == DefaultId) {
if (Default->ValueExpression != NULL) {
//
// Default is provided by an Expression, evaluate it
//
Status = EvaluateExpression (FormSet, Form, Default->ValueExpression);
if (EFI_ERROR (Status)) {
return Status;
}
CopyMem (HiiValue, &Default->ValueExpression->Result, sizeof (EFI_HII_VALUE));
} else {
//
// Default value is embedded in EFI_IFR_DEFAULT
//
CopyMem (HiiValue, &Default->Value, sizeof (EFI_HII_VALUE));
}
if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
StrValue = HiiGetString (FormSet->HiiHandle, HiiValue->Value.string, NULL);
if (StrValue == NULL) {
return EFI_NOT_FOUND;
}
Question->BufferValue = AllocateCopyPool (StrSize (StrValue), StrValue);
}
return EFI_SUCCESS;
}
Link = GetNextNode (&Question->DefaultListHead, Link);
}
}
//
// EFI_ONE_OF_OPTION
//
if ((Question->Operand == EFI_IFR_ONE_OF_OP) && !IsListEmpty (&Question->OptionListHead)) {
if (DefaultId <= EFI_HII_DEFAULT_CLASS_MANUFACTURING) {
//
// OneOfOption could only provide Standard and Manufacturing default
//
Link = GetFirstNode (&Question->OptionListHead);
while (!IsNull (&Question->OptionListHead, Link)) {
Option = QUESTION_OPTION_FROM_LINK (Link);
if (((DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) && ((Option->Flags & EFI_IFR_OPTION_DEFAULT) != 0)) ||
((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Option->Flags & EFI_IFR_OPTION_DEFAULT_MFG) != 0))
) {
CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE));
return EFI_SUCCESS;
}
Link = GetNextNode (&Question->OptionListHead, Link);
}
}
}
//
// EFI_IFR_CHECKBOX - lowest priority
//
if (Question->Operand == EFI_IFR_CHECKBOX_OP) {
if (DefaultId <= EFI_HII_DEFAULT_CLASS_MANUFACTURING) {
//
// Checkbox could only provide Standard and Manufacturing default
//
if (((DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) && ((Question->Flags & EFI_IFR_CHECKBOX_DEFAULT) != 0)) ||
((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Question->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) != 0))
) {
HiiValue->Value.b = TRUE;
} else {
HiiValue->Value.b = FALSE;
}
return EFI_SUCCESS;
}
}
//
// For Questions without default
//
switch (Question->Operand) {
case EFI_IFR_NUMERIC_OP:
//
// Take minimum value as numeric default value
//
if ((HiiValue->Value.u64 < Question->Minimum) || (HiiValue->Value.u64 > Question->Maximum)) {
HiiValue->Value.u64 = Question->Minimum;
}
break;
case EFI_IFR_ONE_OF_OP:
//
// Take first oneof option as oneof's default value
//
if (ValueToOption (Question, HiiValue) == NULL) {
Link = GetFirstNode (&Question->OptionListHead);
if (!IsNull (&Question->OptionListHead, Link)) {
Option = QUESTION_OPTION_FROM_LINK (Link);
CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE));
}
}
break;
case EFI_IFR_ORDERED_LIST_OP:
//
// Take option sequence in IFR as ordered list's default value
//
Index = 0;
Link = GetFirstNode (&Question->OptionListHead);
while (!IsNull (&Question->OptionListHead, Link)) {
Option = QUESTION_OPTION_FROM_LINK (Link);
SetArrayData (Question->BufferValue, Question->ValueType, Index, Option->Value.Value.u64);
Index++;
if (Index >= Question->MaxContainers) {
break;
}
Link = GetNextNode (&Question->OptionListHead, Link);
}
break;
default:
Status = EFI_NOT_FOUND;
break;
}
return Status;
}
/**
Reset Questions in a Formset to their default value.
@param FormSet FormSet data structure.
@param DefaultId The Class of the default.
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
ExtractFormSetDefault (
IN FORM_BROWSER_FORMSET *FormSet,
IN UINT16 DefaultId
)
{
EFI_STATUS Status;
LIST_ENTRY *FormLink;
LIST_ENTRY *StatementLink;
FORM_BROWSER_STATEMENT *Question;
FORM_BROWSER_FORM *Form;
FormLink = GetFirstNode (&FormSet->FormListHead);
while (!IsNull (&FormSet->FormListHead, FormLink)) {
Form = FORM_BROWSER_FORM_FROM_LINK (FormLink);
//
// Extract Form default
//
StatementLink = GetFirstNode (&Form->StatementListHead);
while (!IsNull (&Form->StatementListHead, StatementLink)) {
Question = FORM_BROWSER_STATEMENT_FROM_LINK (StatementLink);
StatementLink = GetNextNode (&Form->StatementListHead, StatementLink);
//
// If Question is disabled, don't reset it to default
//
if (Question->DisableExpression != NULL) {
Status = EvaluateExpression (FormSet, Form, Question->DisableExpression);
if (!EFI_ERROR (Status) && Question->DisableExpression->Result.Value.b) {
continue;
}
}
//
// Reset Question to its default value
//
Status = GetQuestionDefault (FormSet, Form, Question, DefaultId);
if (EFI_ERROR (Status)) {
continue;
}
//
// Synchronize Buffer storage's Edit buffer
//
if ((Question->Storage != NULL) &&
(Question->Storage->Type != EFI_HII_VARSTORE_EFI_VARIABLE)) {
SetQuestionValue (FormSet, Form, Question, TRUE);
}
}
FormLink = GetNextNode (&FormSet->FormListHead, FormLink);
}
return EFI_SUCCESS;
}
/**
Initialize Question's Edit copy from Storage.
@param Selection Selection contains the information about
the Selection, form and formset to be displayed.
Selection action may be updated in retrieve callback.
@param FormSet FormSet data structure.
@param Form Form data structure.
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
LoadFormConfig (
IN OUT UI_MENU_SELECTION *Selection,
IN FORM_BROWSER_FORMSET *FormSet,
IN FORM_BROWSER_FORM *Form
)
{
EFI_STATUS Status;
LIST_ENTRY *Link;
FORM_BROWSER_STATEMENT *Question;
UINT8 *BufferValue;
UINTN StorageWidth;
Link = GetFirstNode (&Form->StatementListHead);
while (!IsNull (&Form->StatementListHead, Link)) {
Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
//
// Initialize local copy of Value for each Question
//
Status = GetQuestionValue (FormSet, Form, Question, TRUE);
if (EFI_ERROR (Status)) {
return Status;
}
if ((Question->Operand == EFI_IFR_STRING_OP) || (Question->Operand == EFI_IFR_PASSWORD_OP)) {
HiiSetString (FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);
}
//
// According the spec, ref opcode try to get value from call back with "retrieve" type.
//
if ((Question->Operand == EFI_IFR_REF_OP) && (FormSet->ConfigAccess != NULL)) {
Status = ProcessCallBackFunction(Selection, Question, EFI_BROWSER_ACTION_RETRIEVE, TRUE);
if (EFI_ERROR (Status)) {
return Status;
}
}
//
// Check whether EfiVarstore with CallBack can be got.
//
if ((FormSet->ConfigAccess != NULL) &&
(Selection->Action != UI_ACTION_REFRESH_FORMSET) &&
(Question->QuestionId != 0) &&
(Question->Storage != NULL) &&
(Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) &&
((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK)) {
//
// Check QuestionValue does exist.
//
StorageWidth = Question->StorageWidth;
if (Question->BufferValue != NULL) {
BufferValue = Question->BufferValue;
} else {
BufferValue = (UINT8 *) &Question->HiiValue.Value;
}
Status = gRT->GetVariable (
Question->VariableName,
&Question->Storage->Guid,
NULL,
&StorageWidth,
BufferValue
);
if (!EFI_ERROR (Status)) {
Status = ProcessCallBackFunction(Selection, Question, EFI_BROWSER_ACTION_RETRIEVE, TRUE);
}
}
Link = GetNextNode (&Form->StatementListHead, Link);
}
return EFI_SUCCESS;
}
/**
Initialize Question's Edit copy from Storage for the whole Formset.
@param Selection Selection contains the information about
the Selection, form and formset to be displayed.
Selection action may be updated in retrieve callback.
@param FormSet FormSet data structure.
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
LoadFormSetConfig (
IN OUT UI_MENU_SELECTION *Selection,
IN FORM_BROWSER_FORMSET *FormSet
)
{
EFI_STATUS Status;
LIST_ENTRY *Link;
FORM_BROWSER_FORM *Form;
Link = GetFirstNode (&FormSet->FormListHead);
while (!IsNull (&FormSet->FormListHead, Link)) {
Form = FORM_BROWSER_FORM_FROM_LINK (Link);
//
// Initialize local copy of Value for each Form
//
Status = LoadFormConfig (Selection, FormSet, Form);
if (EFI_ERROR (Status)) {
return Status;
}
Link = GetNextNode (&FormSet->FormListHead, Link);
}
return EFI_SUCCESS;
}
/**
Fill storage's edit copy with settings requested from Configuration Driver.
@param FormSet FormSet data structure.
@param Storage Buffer Storage.
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
LoadStorage (
IN FORM_BROWSER_FORMSET *FormSet,
IN FORMSET_STORAGE *Storage
)
{
EFI_STATUS Status;
EFI_STRING Progress;
EFI_STRING Result;
CHAR16 *StrPtr;
if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
return EFI_SUCCESS;
}
if (FormSet->ConfigAccess == NULL) {
return EFI_NOT_FOUND;
}
if (Storage->ElementCount == 0) {
//
// Skip if there is no RequestElement
//
return EFI_SUCCESS;
}
//
// Request current settings from Configuration Driver
//
Status = FormSet->ConfigAccess->ExtractConfig (
FormSet->ConfigAccess,
Storage->ConfigRequest,
&Progress,
&Result
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Convert Result from <ConfigAltResp> to <ConfigResp>
//
StrPtr = StrStr (Result, L"ALTCFG");
if (StrPtr != NULL) {
*StrPtr = L'\0';
}
Status = ConfigRespToStorage (Storage, Result);
FreePool (Result);
return Status;
}
/**
Copy uncommitted data from source Storage to destination Storage.
@param Dst Target Storage for uncommitted data.
@param Src Source Storage for uncommitted data.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_INVALID_PARAMETER Source and destination Storage is not the same type.
**/
EFI_STATUS
CopyStorage (
IN OUT FORMSET_STORAGE *Dst,
IN FORMSET_STORAGE *Src
)
{
LIST_ENTRY *Link;
NAME_VALUE_NODE *Node;
if ((Dst->Type != Src->Type) || (Dst->Size != Src->Size)) {
return EFI_INVALID_PARAMETER;
}
switch (Src->Type) {
case EFI_HII_VARSTORE_BUFFER:
CopyMem (Dst->EditBuffer, Src->EditBuffer, Src->Size);
CopyMem (Dst->Buffer, Src->Buffer, Src->Size);
break;
case EFI_HII_VARSTORE_NAME_VALUE:
Link = GetFirstNode (&Src->NameValueListHead);
while (!IsNull (&Src->NameValueListHead, Link)) {
Node = NAME_VALUE_NODE_FROM_LINK (Link);
SetValueByName (Dst, Node->Name, Node->EditValue, TRUE);
SetValueByName (Dst, Node->Name, Node->Value, FALSE);
Link = GetNextNode (&Src->NameValueListHead, Link);
}
break;
case EFI_HII_VARSTORE_EFI_VARIABLE:
default:
break;
}
return EFI_SUCCESS;
}
/**
Get current setting of Questions.
@param FormSet FormSet data structure.
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
InitializeCurrentSetting (
IN OUT FORM_BROWSER_FORMSET *FormSet
)
{
LIST_ENTRY *Link;
LIST_ENTRY *Link2;
FORMSET_STORAGE *Storage;
FORMSET_STORAGE *StorageSrc;
FORMSET_STORAGE *OldStorage;
FORM_BROWSER_FORM *Form;
FORM_BROWSER_FORM *Form2;
EFI_STATUS Status;
//
// Extract default from IFR binary
//
Status = ExtractFormSetDefault (FormSet, EFI_HII_DEFAULT_CLASS_STANDARD);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Request current settings from Configuration Driver
//
Link = GetFirstNode (&FormSet->StorageListHead);
while (!IsNull (&FormSet->StorageListHead, Link)) {
Storage = FORMSET_STORAGE_FROM_LINK (Link);
OldStorage = NULL;
if (gOldFormSet != NULL) {
//
// Try to find the Storage in backup formset gOldFormSet
//
Link2 = GetFirstNode (&gOldFormSet->StorageListHead);
while (!IsNull (&gOldFormSet->StorageListHead, Link2)) {
StorageSrc = FORMSET_STORAGE_FROM_LINK (Link2);
if (StorageSrc->VarStoreId == Storage->VarStoreId) {
OldStorage = StorageSrc;
break;
}
Link2 = GetNextNode (&gOldFormSet->StorageListHead, Link2);
}
}
if (OldStorage == NULL) {
//
// Storage is not found in backup formset, request it from ConfigDriver
//
Status = LoadStorage (FormSet, Storage);
//
// Now Edit Buffer is filled with default values(lower priority) and current
// settings(higher priority), sychronize it to shadow Buffer
//
if (!EFI_ERROR (Status)) {
SynchronizeStorage (Storage);
}
} else {
//
// Storage found in backup formset, use it
//
Status = CopyStorage (Storage, OldStorage);
}
Link = GetNextNode (&FormSet->StorageListHead, Link);
}
//
// If has old formset, get the old nv update status.
//
if (gOldFormSet != NULL) {
Link = GetFirstNode (&FormSet->FormListHead);
while (!IsNull (&FormSet->FormListHead, Link)) {
Form = FORM_BROWSER_FORM_FROM_LINK (Link);
Link2 = GetFirstNode (&gOldFormSet->FormListHead);
while (!IsNull (&gOldFormSet->FormListHead, Link2)) {
Form2 = FORM_BROWSER_FORM_FROM_LINK (Link2);
if (Form->FormId == Form2->FormId) {
Form->NvUpdateRequired = Form2->NvUpdateRequired;
break;
}
Link2 = GetNextNode (&gOldFormSet->FormListHead, Link2);
}
Link = GetNextNode (&FormSet->FormListHead, Link);
}
}
return EFI_SUCCESS;
}
/**
Fetch the Ifr binary data of a FormSet.
@param Handle PackageList Handle
@param FormSetGuid On input, GUID or class GUID of a formset. If not
specified (NULL or zero GUID), take the first
FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
found in package list.
On output, GUID of the formset found(if not NULL).
@param BinaryLength The length of the FormSet IFR binary.
@param BinaryData The buffer designed to receive the FormSet.
@retval EFI_SUCCESS Buffer filled with the requested FormSet.
BufferLength was updated.
@retval EFI_INVALID_PARAMETER The handle is unknown.
@retval EFI_NOT_FOUND A form or FormSet on the requested handle cannot
be found with the requested FormId.
**/
EFI_STATUS
GetIfrBinaryData (
IN EFI_HII_HANDLE Handle,
IN OUT EFI_GUID *FormSetGuid,
OUT UINTN *BinaryLength,
OUT UINT8 **BinaryData
)
{
EFI_STATUS Status;
EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
UINTN BufferSize;
UINT8 *Package;
UINT8 *OpCodeData;
UINT32 Offset;
UINT32 Offset2;
UINT32 PackageListLength;
EFI_HII_PACKAGE_HEADER PackageHeader;
UINT8 Index;
UINT8 NumberOfClassGuid;
BOOLEAN ClassGuidMatch;
EFI_GUID *ClassGuid;
EFI_GUID *ComparingGuid;
OpCodeData = NULL;
Package = NULL;
ZeroMem (&PackageHeader, sizeof (EFI_HII_PACKAGE_HEADER));
//
// if FormSetGuid is NULL or zero GUID, return first Setup FormSet in the package list
//
if (FormSetGuid == NULL || CompareGuid (FormSetGuid, &gZeroGuid)) {
ComparingGuid = &gEfiHiiPlatformSetupFormsetGuid;
} else {
ComparingGuid = FormSetGuid;
}
//
// Get HII PackageList
//
BufferSize = 0;
HiiPackageList = NULL;
Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList);
if (Status == EFI_BUFFER_TOO_SMALL) {
HiiPackageList = AllocatePool (BufferSize);
ASSERT (HiiPackageList != NULL);
Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList);
}
if (EFI_ERROR (Status)) {
return Status;
}
ASSERT (HiiPackageList != NULL);
//
// Get Form package from this HII package List
//
Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
Offset2 = 0;
CopyMem (&PackageListLength, &HiiPackageList->PackageLength, sizeof (UINT32));
ClassGuidMatch = FALSE;
while (Offset < PackageListLength) {
Package = ((UINT8 *) HiiPackageList) + Offset;
CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));
if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) {
//
// Search FormSet in this Form Package
//
Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);
while (Offset2 < PackageHeader.Length) {
OpCodeData = Package + Offset2;
if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) {
//
// Try to compare against formset GUID
//
if (CompareGuid (ComparingGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {
break;
}
if (((EFI_IFR_OP_HEADER *) OpCodeData)->Length > OFFSET_OF (EFI_IFR_FORM_SET, Flags)) {
//
// Try to compare against formset class GUID
//
NumberOfClassGuid = (UINT8) (((EFI_IFR_FORM_SET *) OpCodeData)->Flags & 0x3);
ClassGuid = (EFI_GUID *) (OpCodeData + sizeof (EFI_IFR_FORM_SET));
for (Index = 0; Index < NumberOfClassGuid; Index++) {
if (CompareGuid (ComparingGuid, ClassGuid + Index)) {
ClassGuidMatch = TRUE;
break;
}
}
if (ClassGuidMatch) {
break;
}
} else if (ComparingGuid == &gEfiHiiPlatformSetupFormsetGuid) {
ClassGuidMatch = TRUE;
break;
}
}
Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;
}
if (Offset2 < PackageHeader.Length) {
//
// Target formset found
//
break;
}
}
Offset += PackageHeader.Length;
}
if (Offset >= PackageListLength) {
//
// Form package not found in this Package List
//
FreePool (HiiPackageList);
return EFI_NOT_FOUND;
}
if (ClassGuidMatch && (FormSetGuid != NULL)) {
//
// Return the FormSet GUID
//
CopyMem (FormSetGuid, &((EFI_IFR_FORM_SET *) OpCodeData)->Guid, sizeof (EFI_GUID));
}
//
// To determine the length of a whole FormSet IFR binary, one have to parse all the Opcodes
// in this FormSet; So, here just simply copy the data from start of a FormSet to the end
// of the Form Package.
//
*BinaryLength = PackageHeader.Length - Offset2;
*BinaryData = AllocateCopyPool (*BinaryLength, OpCodeData);
FreePool (HiiPackageList);
if (*BinaryData == NULL) {
return EFI_OUT_OF_RESOURCES;
}
return EFI_SUCCESS;
}
/**
Initialize the internal data structure of a FormSet.
@param Handle PackageList Handle
@param FormSetGuid On input, GUID or class GUID of a formset. If not
specified (NULL or zero GUID), take the first
FormSet with class GUID EFI_HII_PLATFORM_SETUP_FORMSET_GUID
found in package list.
On output, GUID of the formset found(if not NULL).
@param FormSet FormSet data structure.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_NOT_FOUND The specified FormSet could not be found.
**/
EFI_STATUS
InitializeFormSet (
IN EFI_HII_HANDLE Handle,
IN OUT EFI_GUID *FormSetGuid,
OUT FORM_BROWSER_FORMSET *FormSet
)
{
EFI_STATUS Status;
EFI_HANDLE DriverHandle;
UINT16 Index;
Status = GetIfrBinaryData (Handle, FormSetGuid, &FormSet->IfrBinaryLength, &FormSet->IfrBinaryData);
if (EFI_ERROR (Status)) {
return Status;
}
FormSet->HiiHandle = Handle;
CopyMem (&FormSet->Guid, FormSetGuid, sizeof (EFI_GUID));
//
// Retrieve ConfigAccess Protocol associated with this HiiPackageList
//
Status = mHiiDatabase->GetPackageListHandle (mHiiDatabase, Handle, &DriverHandle);
if (EFI_ERROR (Status)) {
return Status;
}
FormSet->DriverHandle = DriverHandle;
Status = gBS->HandleProtocol (
DriverHandle,
&gEfiHiiConfigAccessProtocolGuid,
(VOID **) &FormSet->ConfigAccess
);
if (EFI_ERROR (Status)) {
//
// Configuration Driver don't attach ConfigAccess protocol to its HII package
// list, then there will be no configuration action required
//
FormSet->ConfigAccess = NULL;
}
//
// Parse the IFR binary OpCodes
//
Status = ParseOpCodes (FormSet);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Set VFR type by FormSet SubClass field
//
gClassOfVfr = FORMSET_CLASS_PLATFORM_SETUP;
if (FormSet->SubClass == EFI_FRONT_PAGE_SUBCLASS) {
gClassOfVfr = FORMSET_CLASS_FRONT_PAGE;
}
//
// Set VFR type by FormSet class guid
//
for (Index = 0; Index < 3; Index ++) {
if (CompareGuid (&FormSet->ClassGuid[Index], &gEfiHiiPlatformSetupFormsetGuid)) {
gClassOfVfr |= FORMSET_CLASS_PLATFORM_SETUP;
break;
}
}
if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) == FORMSET_CLASS_FRONT_PAGE) {
gFrontPageHandle = FormSet->HiiHandle;
}
//
// Match GUID to find out the function key setting. If match fail, use the default setting.
//
for (Index = 0; Index < sizeof (gFunctionKeySettingTable) / sizeof (FUNCTIION_KEY_SETTING); Index++) {
if (CompareGuid (&FormSet->Guid, &(gFunctionKeySettingTable[Index].FormSetGuid))) {
//
// Update the function key setting.
//
gFunctionKeySetting = gFunctionKeySettingTable[Index].KeySetting;
//
// Function key prompt can not be displayed if the function key has been disabled.
//
if ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE) {
gFunctionNineString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
}
if ((gFunctionKeySetting & FUNCTION_TEN) != FUNCTION_TEN) {
gFunctionTenString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
}
}
}
return Status;
}
/**
Save globals used by previous call to SendForm(). SendForm() may be called from
HiiConfigAccess.Callback(), this will cause SendForm() be reentried.
So, save globals of previous call to SendForm() and restore them upon exit.
**/
VOID
SaveBrowserContext (
VOID
)
{
BROWSER_CONTEXT *Context;
gBrowserContextCount++;
if (gBrowserContextCount == 1) {
//
// This is not reentry of SendForm(), no context to save
//
return;
}
Context = AllocatePool (sizeof (BROWSER_CONTEXT));
ASSERT (Context != NULL);
Context->Signature = BROWSER_CONTEXT_SIGNATURE;
//
// Save FormBrowser context
//
Context->BannerData = gBannerData;
Context->ClassOfVfr = gClassOfVfr;
Context->FunctionKeySetting = gFunctionKeySetting;
Context->ResetRequired = gResetRequired;
Context->Direction = gDirection;
Context->FunctionNineString = gFunctionNineString;
Context->FunctionTenString = gFunctionTenString;
Context->EnterString = gEnterString;
Context->EnterCommitString = gEnterCommitString;
Context->EnterEscapeString = gEnterEscapeString;
Context->EscapeString = gEscapeString;
Context->SaveFailed = gSaveFailed;
Context->MoveHighlight = gMoveHighlight;
Context->MakeSelection = gMakeSelection;
Context->DecNumericInput = gDecNumericInput;
Context->HexNumericInput = gHexNumericInput;
Context->ToggleCheckBox = gToggleCheckBox;
Context->PromptForData = gPromptForData;
Context->PromptForPassword = gPromptForPassword;
Context->PromptForNewPassword = gPromptForNewPassword;
Context->ConfirmPassword = gConfirmPassword;
Context->ConfirmError = gConfirmError;
Context->PassowordInvalid = gPassowordInvalid;
Context->PressEnter = gPressEnter;
Context->EmptyString = gEmptyString;
Context->AreYouSure = gAreYouSure;
Context->YesResponse = gYesResponse;
Context->NoResponse = gNoResponse;
Context->MiniString = gMiniString;
Context->PlusString = gPlusString;
Context->MinusString = gMinusString;
Context->AdjustNumber = gAdjustNumber;
Context->SaveChanges = gSaveChanges;
Context->OptionMismatch = gOptionMismatch;
Context->FormSuppress = gFormSuppress;
Context->PromptBlockWidth = gPromptBlockWidth;
Context->OptionBlockWidth = gOptionBlockWidth;
Context->HelpBlockWidth = gHelpBlockWidth;
Context->OldFormSet = gOldFormSet;
Context->MenuRefreshHead = gMenuRefreshHead;
CopyMem (&Context->ScreenDimensions, &gScreenDimensions, sizeof (gScreenDimensions));
CopyMem (&Context->MenuOption, &gMenuOption, sizeof (gMenuOption));
//
// Insert to FormBrowser context list
//
InsertHeadList (&gBrowserContextList, &Context->Link);
}
/**
Restore globals used by previous call to SendForm().
**/
VOID
RestoreBrowserContext (
VOID
)
{
LIST_ENTRY *Link;
BROWSER_CONTEXT *Context;
ASSERT (gBrowserContextCount != 0);
gBrowserContextCount--;
if (gBrowserContextCount == 0) {
//
// This is not reentry of SendForm(), no context to restore
//
return;
}
ASSERT (!IsListEmpty (&gBrowserContextList));
Link = GetFirstNode (&gBrowserContextList);
Context = BROWSER_CONTEXT_FROM_LINK (Link);
//
// Restore FormBrowser context
//
gBannerData = Context->BannerData;
gClassOfVfr = Context->ClassOfVfr;
gFunctionKeySetting = Context->FunctionKeySetting;
gResetRequired = Context->ResetRequired;
gDirection = Context->Direction;
gFunctionNineString = Context->FunctionNineString;
gFunctionTenString = Context->FunctionTenString;
gEnterString = Context->EnterString;
gEnterCommitString = Context->EnterCommitString;
gEnterEscapeString = Context->EnterEscapeString;
gEscapeString = Context->EscapeString;
gSaveFailed = Context->SaveFailed;
gMoveHighlight = Context->MoveHighlight;
gMakeSelection = Context->MakeSelection;
gDecNumericInput = Context->DecNumericInput;
gHexNumericInput = Context->HexNumericInput;
gToggleCheckBox = Context->ToggleCheckBox;
gPromptForData = Context->PromptForData;
gPromptForPassword = Context->PromptForPassword;
gPromptForNewPassword = Context->PromptForNewPassword;
gConfirmPassword = Context->ConfirmPassword;
gConfirmError = Context->ConfirmError;
gPassowordInvalid = Context->PassowordInvalid;
gPressEnter = Context->PressEnter;
gEmptyString = Context->EmptyString;
gAreYouSure = Context->AreYouSure;
gYesResponse = Context->YesResponse;
gNoResponse = Context->NoResponse;
gMiniString = Context->MiniString;
gPlusString = Context->PlusString;
gMinusString = Context->MinusString;
gAdjustNumber = Context->AdjustNumber;
gSaveChanges = Context->SaveChanges;
gOptionMismatch = Context->OptionMismatch;
gFormSuppress = Context->FormSuppress;
gPromptBlockWidth = Context->PromptBlockWidth;
gOptionBlockWidth = Context->OptionBlockWidth;
gHelpBlockWidth = Context->HelpBlockWidth;
gOldFormSet = Context->OldFormSet;
gMenuRefreshHead = Context->MenuRefreshHead;
CopyMem (&gScreenDimensions, &Context->ScreenDimensions, sizeof (gScreenDimensions));
CopyMem (&gMenuOption, &Context->MenuOption, sizeof (gMenuOption));
//
// Remove from FormBrowser context list
//
RemoveEntryList (&Context->Link);
gBS->FreePool (Context);
}
|