1 | /** @file
|
---|
2 | This is an example of how a driver might export data to the HII protocol to be
|
---|
3 | later utilized by the Setup Protocol
|
---|
4 |
|
---|
5 | Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include "DriverSample.h"
|
---|
11 |
|
---|
12 | #define DISPLAY_ONLY_MY_ITEM 0x0002
|
---|
13 |
|
---|
14 | CHAR16 VariableName[] = L"MyIfrNVData";
|
---|
15 | CHAR16 MyEfiVar[] = L"MyEfiVar";
|
---|
16 | CHAR16 MyEfiBitVar[] = L"MyEfiBitVar";
|
---|
17 | CHAR16 MyEfiUnionVar[] = L"MyEfiUnionVar";
|
---|
18 |
|
---|
19 | EFI_HANDLE DriverHandle[2] = { NULL, NULL };
|
---|
20 | DRIVER_SAMPLE_PRIVATE_DATA *mPrivateData = NULL;
|
---|
21 | EFI_EVENT mEvent;
|
---|
22 |
|
---|
23 | HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath0 = {
|
---|
24 | {
|
---|
25 | {
|
---|
26 | HARDWARE_DEVICE_PATH,
|
---|
27 | HW_VENDOR_DP,
|
---|
28 | {
|
---|
29 | (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
|
---|
30 | (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
|
---|
31 | }
|
---|
32 | },
|
---|
33 | DRIVER_SAMPLE_FORMSET_GUID
|
---|
34 | },
|
---|
35 | {
|
---|
36 | END_DEVICE_PATH_TYPE,
|
---|
37 | END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
---|
38 | {
|
---|
39 | (UINT8)(END_DEVICE_PATH_LENGTH),
|
---|
40 | (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
|
---|
41 | }
|
---|
42 | }
|
---|
43 | };
|
---|
44 |
|
---|
45 | HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1 = {
|
---|
46 | {
|
---|
47 | {
|
---|
48 | HARDWARE_DEVICE_PATH,
|
---|
49 | HW_VENDOR_DP,
|
---|
50 | {
|
---|
51 | (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
|
---|
52 | (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
|
---|
53 | }
|
---|
54 | },
|
---|
55 | DRIVER_SAMPLE_INVENTORY_GUID
|
---|
56 | },
|
---|
57 | {
|
---|
58 | END_DEVICE_PATH_TYPE,
|
---|
59 | END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
---|
60 | {
|
---|
61 | (UINT8)(END_DEVICE_PATH_LENGTH),
|
---|
62 | (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
|
---|
63 | }
|
---|
64 | }
|
---|
65 | };
|
---|
66 |
|
---|
67 | /**
|
---|
68 | Set value of a data element in an Array by its Index.
|
---|
69 |
|
---|
70 | @param Array The data array.
|
---|
71 | @param Type Type of the data in this array.
|
---|
72 | @param Index Zero based index for data in this array.
|
---|
73 | @param Value The value to be set.
|
---|
74 |
|
---|
75 | **/
|
---|
76 | VOID
|
---|
77 | SetArrayData (
|
---|
78 | IN VOID *Array,
|
---|
79 | IN UINT8 Type,
|
---|
80 | IN UINTN Index,
|
---|
81 | IN UINT64 Value
|
---|
82 | )
|
---|
83 | {
|
---|
84 | ASSERT (Array != NULL);
|
---|
85 |
|
---|
86 | switch (Type) {
|
---|
87 | case EFI_IFR_TYPE_NUM_SIZE_8:
|
---|
88 | *(((UINT8 *)Array) + Index) = (UINT8)Value;
|
---|
89 | break;
|
---|
90 |
|
---|
91 | case EFI_IFR_TYPE_NUM_SIZE_16:
|
---|
92 | *(((UINT16 *)Array) + Index) = (UINT16)Value;
|
---|
93 | break;
|
---|
94 |
|
---|
95 | case EFI_IFR_TYPE_NUM_SIZE_32:
|
---|
96 | *(((UINT32 *)Array) + Index) = (UINT32)Value;
|
---|
97 | break;
|
---|
98 |
|
---|
99 | case EFI_IFR_TYPE_NUM_SIZE_64:
|
---|
100 | *(((UINT64 *)Array) + Index) = (UINT64)Value;
|
---|
101 | break;
|
---|
102 |
|
---|
103 | default:
|
---|
104 | break;
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | Notification function for keystrokes.
|
---|
110 |
|
---|
111 | @param[in] KeyData The key that was pressed.
|
---|
112 |
|
---|
113 | @retval EFI_SUCCESS The operation was successful.
|
---|
114 | **/
|
---|
115 | EFI_STATUS
|
---|
116 | EFIAPI
|
---|
117 | NotificationFunction (
|
---|
118 | IN EFI_KEY_DATA *KeyData
|
---|
119 | )
|
---|
120 | {
|
---|
121 | gBS->SignalEvent (mEvent);
|
---|
122 |
|
---|
123 | return EFI_SUCCESS;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /**
|
---|
127 | Function to start monitoring for CTRL-C using SimpleTextInputEx.
|
---|
128 |
|
---|
129 | @retval EFI_SUCCESS The feature is enabled.
|
---|
130 | @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
|
---|
131 | **/
|
---|
132 | EFI_STATUS
|
---|
133 | EFIAPI
|
---|
134 | InternalStartMonitor (
|
---|
135 | VOID
|
---|
136 | )
|
---|
137 | {
|
---|
138 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;
|
---|
139 | EFI_KEY_DATA KeyData;
|
---|
140 | EFI_STATUS Status;
|
---|
141 | EFI_HANDLE *Handles;
|
---|
142 | UINTN HandleCount;
|
---|
143 | UINTN HandleIndex;
|
---|
144 | VOID *NotifyHandle;
|
---|
145 |
|
---|
146 | Status = gBS->LocateHandleBuffer (
|
---|
147 | ByProtocol,
|
---|
148 | &gEfiSimpleTextInputExProtocolGuid,
|
---|
149 | NULL,
|
---|
150 | &HandleCount,
|
---|
151 | &Handles
|
---|
152 | );
|
---|
153 | for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
|
---|
154 | Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **)&SimpleEx);
|
---|
155 | ASSERT_EFI_ERROR (Status);
|
---|
156 |
|
---|
157 | KeyData.KeyState.KeyToggleState = 0;
|
---|
158 | KeyData.Key.ScanCode = 0;
|
---|
159 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
|
---|
160 | KeyData.Key.UnicodeChar = L'c';
|
---|
161 |
|
---|
162 | Status = SimpleEx->RegisterKeyNotify (
|
---|
163 | SimpleEx,
|
---|
164 | &KeyData,
|
---|
165 | NotificationFunction,
|
---|
166 | &NotifyHandle
|
---|
167 | );
|
---|
168 | if (EFI_ERROR (Status)) {
|
---|
169 | break;
|
---|
170 | }
|
---|
171 |
|
---|
172 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
|
---|
173 | Status = SimpleEx->RegisterKeyNotify (
|
---|
174 | SimpleEx,
|
---|
175 | &KeyData,
|
---|
176 | NotificationFunction,
|
---|
177 | &NotifyHandle
|
---|
178 | );
|
---|
179 | if (EFI_ERROR (Status)) {
|
---|
180 | break;
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | return EFI_SUCCESS;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /**
|
---|
188 | Function to stop monitoring for CTRL-C using SimpleTextInputEx.
|
---|
189 |
|
---|
190 | @retval EFI_SUCCESS The feature is enabled.
|
---|
191 | @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
|
---|
192 | **/
|
---|
193 | EFI_STATUS
|
---|
194 | EFIAPI
|
---|
195 | InternalStopMonitor (
|
---|
196 | VOID
|
---|
197 | )
|
---|
198 | {
|
---|
199 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;
|
---|
200 | EFI_STATUS Status;
|
---|
201 | EFI_HANDLE *Handles;
|
---|
202 | EFI_KEY_DATA KeyData;
|
---|
203 | UINTN HandleCount;
|
---|
204 | UINTN HandleIndex;
|
---|
205 | VOID *NotifyHandle;
|
---|
206 |
|
---|
207 | Status = gBS->LocateHandleBuffer (
|
---|
208 | ByProtocol,
|
---|
209 | &gEfiSimpleTextInputExProtocolGuid,
|
---|
210 | NULL,
|
---|
211 | &HandleCount,
|
---|
212 | &Handles
|
---|
213 | );
|
---|
214 | for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
|
---|
215 | Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **)&SimpleEx);
|
---|
216 | ASSERT_EFI_ERROR (Status);
|
---|
217 |
|
---|
218 | KeyData.KeyState.KeyToggleState = 0;
|
---|
219 | KeyData.Key.ScanCode = 0;
|
---|
220 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;
|
---|
221 | KeyData.Key.UnicodeChar = L'c';
|
---|
222 |
|
---|
223 | Status = SimpleEx->RegisterKeyNotify (
|
---|
224 | SimpleEx,
|
---|
225 | &KeyData,
|
---|
226 | NotificationFunction,
|
---|
227 | &NotifyHandle
|
---|
228 | );
|
---|
229 | if (!EFI_ERROR (Status)) {
|
---|
230 | Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);
|
---|
231 | }
|
---|
232 |
|
---|
233 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
|
---|
234 | Status = SimpleEx->RegisterKeyNotify (
|
---|
235 | SimpleEx,
|
---|
236 | &KeyData,
|
---|
237 | NotificationFunction,
|
---|
238 | &NotifyHandle
|
---|
239 | );
|
---|
240 | if (!EFI_ERROR (Status)) {
|
---|
241 | Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | return EFI_SUCCESS;
|
---|
246 | }
|
---|
247 |
|
---|
248 | /**
|
---|
249 | Update names of Name/Value storage to current language.
|
---|
250 |
|
---|
251 | @param PrivateData Points to the driver private data.
|
---|
252 |
|
---|
253 | @retval EFI_SUCCESS All names are successfully updated.
|
---|
254 | @retval EFI_NOT_FOUND Failed to get Name from HII database.
|
---|
255 |
|
---|
256 | **/
|
---|
257 | EFI_STATUS
|
---|
258 | LoadNameValueNames (
|
---|
259 | IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData
|
---|
260 | )
|
---|
261 | {
|
---|
262 | UINTN Index;
|
---|
263 |
|
---|
264 | //
|
---|
265 | // Get Name/Value name string of current language
|
---|
266 | //
|
---|
267 | for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
|
---|
268 | PrivateData->NameValueName[Index] = HiiGetString (
|
---|
269 | PrivateData->HiiHandle[0],
|
---|
270 | PrivateData->NameStringId[Index],
|
---|
271 | NULL
|
---|
272 | );
|
---|
273 | if (PrivateData->NameValueName[Index] == NULL) {
|
---|
274 | return EFI_NOT_FOUND;
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | return EFI_SUCCESS;
|
---|
279 | }
|
---|
280 |
|
---|
281 | /**
|
---|
282 | Get the value of <Number> in <BlockConfig> format, i.e. the value of OFFSET
|
---|
283 | or WIDTH or VALUE.
|
---|
284 | <BlockConfig> ::= 'OFFSET='<Number>&'WIDTH='<Number>&'VALUE'=<Number>
|
---|
285 |
|
---|
286 | This is a internal function.
|
---|
287 |
|
---|
288 | @param StringPtr String in <BlockConfig> format and points to the
|
---|
289 | first character of <Number>.
|
---|
290 | @param Number The output value. Caller takes the responsibility
|
---|
291 | to free memory.
|
---|
292 | @param Len Length of the <Number>, in characters.
|
---|
293 |
|
---|
294 | @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary
|
---|
295 | structures.
|
---|
296 | @retval EFI_SUCCESS Value of <Number> is outputted in Number
|
---|
297 | successfully.
|
---|
298 |
|
---|
299 | **/
|
---|
300 | EFI_STATUS
|
---|
301 | GetValueOfNumber (
|
---|
302 | IN EFI_STRING StringPtr,
|
---|
303 | OUT UINT8 **Number,
|
---|
304 | OUT UINTN *Len
|
---|
305 | )
|
---|
306 | {
|
---|
307 | EFI_STRING TmpPtr;
|
---|
308 | UINTN Length;
|
---|
309 | EFI_STRING Str;
|
---|
310 | UINT8 *Buf;
|
---|
311 | EFI_STATUS Status;
|
---|
312 | UINT8 DigitUint8;
|
---|
313 | UINTN Index;
|
---|
314 | CHAR16 TemStr[2];
|
---|
315 |
|
---|
316 | if ((StringPtr == NULL) || (*StringPtr == L'\0') || (Number == NULL) || (Len == NULL)) {
|
---|
317 | return EFI_INVALID_PARAMETER;
|
---|
318 | }
|
---|
319 |
|
---|
320 | Buf = NULL;
|
---|
321 |
|
---|
322 | TmpPtr = StringPtr;
|
---|
323 | while (*StringPtr != L'\0' && *StringPtr != L'&') {
|
---|
324 | StringPtr++;
|
---|
325 | }
|
---|
326 |
|
---|
327 | *Len = StringPtr - TmpPtr;
|
---|
328 | Length = *Len + 1;
|
---|
329 |
|
---|
330 | Str = (EFI_STRING)AllocateZeroPool (Length * sizeof (CHAR16));
|
---|
331 | if (Str == NULL) {
|
---|
332 | Status = EFI_OUT_OF_RESOURCES;
|
---|
333 | goto Exit;
|
---|
334 | }
|
---|
335 |
|
---|
336 | CopyMem (Str, TmpPtr, *Len * sizeof (CHAR16));
|
---|
337 | *(Str + *Len) = L'\0';
|
---|
338 |
|
---|
339 | Length = (Length + 1) / 2;
|
---|
340 | Buf = (UINT8 *)AllocateZeroPool (Length);
|
---|
341 | if (Buf == NULL) {
|
---|
342 | Status = EFI_OUT_OF_RESOURCES;
|
---|
343 | goto Exit;
|
---|
344 | }
|
---|
345 |
|
---|
346 | Length = *Len;
|
---|
347 | ZeroMem (TemStr, sizeof (TemStr));
|
---|
348 | for (Index = 0; Index < Length; Index++) {
|
---|
349 | TemStr[0] = Str[Length - Index - 1];
|
---|
350 | DigitUint8 = (UINT8)StrHexToUint64 (TemStr);
|
---|
351 | if ((Index & 1) == 0) {
|
---|
352 | Buf[Index/2] = DigitUint8;
|
---|
353 | } else {
|
---|
354 | Buf[Index/2] = (UINT8)((DigitUint8 << 4) + Buf[Index/2]);
|
---|
355 | }
|
---|
356 | }
|
---|
357 |
|
---|
358 | *Number = Buf;
|
---|
359 | Status = EFI_SUCCESS;
|
---|
360 |
|
---|
361 | Exit:
|
---|
362 | if (Str != NULL) {
|
---|
363 | FreePool (Str);
|
---|
364 | }
|
---|
365 |
|
---|
366 | return Status;
|
---|
367 | }
|
---|
368 |
|
---|
369 | /**
|
---|
370 | Create altcfg string.
|
---|
371 |
|
---|
372 | @param Result The request result string.
|
---|
373 | @param ConfigHdr The request head info. <ConfigHdr> format.
|
---|
374 | @param Offset The offset of the parameter int he structure.
|
---|
375 | @param Width The width of the parameter.
|
---|
376 |
|
---|
377 |
|
---|
378 | @retval The string with altcfg info append at the end.
|
---|
379 | **/
|
---|
380 | EFI_STRING
|
---|
381 | CreateAltCfgString (
|
---|
382 | IN EFI_STRING Result,
|
---|
383 | IN EFI_STRING ConfigHdr,
|
---|
384 | IN UINTN Offset,
|
---|
385 | IN UINTN Width
|
---|
386 | )
|
---|
387 | {
|
---|
388 | EFI_STRING StringPtr;
|
---|
389 | EFI_STRING TmpStr;
|
---|
390 | UINTN NewLen;
|
---|
391 |
|
---|
392 | NewLen = StrLen (Result);
|
---|
393 | //
|
---|
394 | // String Len = ConfigResp + AltConfig + AltConfig + 1("\0")
|
---|
395 | //
|
---|
396 | NewLen = (NewLen + ((1 + StrLen (ConfigHdr) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16);
|
---|
397 | StringPtr = AllocateZeroPool (NewLen);
|
---|
398 | if (StringPtr == NULL) {
|
---|
399 | return NULL;
|
---|
400 | }
|
---|
401 |
|
---|
402 | TmpStr = StringPtr;
|
---|
403 | if (Result != NULL) {
|
---|
404 | StrCpyS (StringPtr, NewLen / sizeof (CHAR16), Result);
|
---|
405 | StringPtr += StrLen (Result);
|
---|
406 | FreePool (Result);
|
---|
407 | }
|
---|
408 |
|
---|
409 | UnicodeSPrint (
|
---|
410 | StringPtr,
|
---|
411 | (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16),
|
---|
412 | L"&%s&ALTCFG=%04x",
|
---|
413 | ConfigHdr,
|
---|
414 | EFI_HII_DEFAULT_CLASS_STANDARD
|
---|
415 | );
|
---|
416 | StringPtr += StrLen (StringPtr);
|
---|
417 |
|
---|
418 | UnicodeSPrint (
|
---|
419 | StringPtr,
|
---|
420 | (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),
|
---|
421 | L"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
|
---|
422 | Offset,
|
---|
423 | Width,
|
---|
424 | DEFAULT_CLASS_STANDARD_VALUE
|
---|
425 | );
|
---|
426 | StringPtr += StrLen (StringPtr);
|
---|
427 |
|
---|
428 | UnicodeSPrint (
|
---|
429 | StringPtr,
|
---|
430 | (1 + StrLen (ConfigHdr) + 8 + 4 + 1) * sizeof (CHAR16),
|
---|
431 | L"&%s&ALTCFG=%04x",
|
---|
432 | ConfigHdr,
|
---|
433 | EFI_HII_DEFAULT_CLASS_MANUFACTURING
|
---|
434 | );
|
---|
435 | StringPtr += StrLen (StringPtr);
|
---|
436 |
|
---|
437 | UnicodeSPrint (
|
---|
438 | StringPtr,
|
---|
439 | (8 + 4 + 7 + 4 + 7 + 4 + 1) * sizeof (CHAR16),
|
---|
440 | L"&OFFSET=%04x&WIDTH=%04x&VALUE=%04x",
|
---|
441 | Offset,
|
---|
442 | Width,
|
---|
443 | DEFAULT_CLASS_MANUFACTURING_VALUE
|
---|
444 | );
|
---|
445 | StringPtr += StrLen (StringPtr);
|
---|
446 |
|
---|
447 | return TmpStr;
|
---|
448 | }
|
---|
449 |
|
---|
450 | /**
|
---|
451 | Check whether need to add the altcfg string. if need to add, add the altcfg
|
---|
452 | string.
|
---|
453 |
|
---|
454 | @param RequestResult The request result string.
|
---|
455 | @param ConfigRequestHdr The request head info. <ConfigHdr> format.
|
---|
456 |
|
---|
457 | **/
|
---|
458 | VOID
|
---|
459 | AppendAltCfgString (
|
---|
460 | IN OUT EFI_STRING *RequestResult,
|
---|
461 | IN EFI_STRING ConfigRequestHdr
|
---|
462 | )
|
---|
463 | {
|
---|
464 | EFI_STRING StringPtr;
|
---|
465 | UINTN Length;
|
---|
466 | UINT8 *TmpBuffer;
|
---|
467 | UINTN Offset;
|
---|
468 | UINTN Width;
|
---|
469 | UINTN BlockSize;
|
---|
470 | UINTN ValueOffset;
|
---|
471 | UINTN ValueWidth;
|
---|
472 | EFI_STATUS Status;
|
---|
473 |
|
---|
474 | TmpBuffer = NULL;
|
---|
475 | StringPtr = *RequestResult;
|
---|
476 | StringPtr = StrStr (StringPtr, L"OFFSET");
|
---|
477 | BlockSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
---|
478 | ValueOffset = OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, GetDefaultValueFromAccess);
|
---|
479 | ValueWidth = sizeof (((DRIVER_SAMPLE_CONFIGURATION *)0)->GetDefaultValueFromAccess);
|
---|
480 |
|
---|
481 | if (StringPtr == NULL) {
|
---|
482 | return;
|
---|
483 | }
|
---|
484 |
|
---|
485 | while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) {
|
---|
486 | StringPtr += StrLen (L"OFFSET=");
|
---|
487 | //
|
---|
488 | // Get Offset
|
---|
489 | //
|
---|
490 | Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
|
---|
491 | if (EFI_ERROR (Status)) {
|
---|
492 | return;
|
---|
493 | }
|
---|
494 |
|
---|
495 | Offset = 0;
|
---|
496 | CopyMem (
|
---|
497 | &Offset,
|
---|
498 | TmpBuffer,
|
---|
499 | (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)
|
---|
500 | );
|
---|
501 | FreePool (TmpBuffer);
|
---|
502 |
|
---|
503 | StringPtr += Length;
|
---|
504 | if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) {
|
---|
505 | return;
|
---|
506 | }
|
---|
507 |
|
---|
508 | StringPtr += StrLen (L"&WIDTH=");
|
---|
509 |
|
---|
510 | //
|
---|
511 | // Get Width
|
---|
512 | //
|
---|
513 | Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
|
---|
514 | if (EFI_ERROR (Status)) {
|
---|
515 | return;
|
---|
516 | }
|
---|
517 |
|
---|
518 | Width = 0;
|
---|
519 | CopyMem (
|
---|
520 | &Width,
|
---|
521 | TmpBuffer,
|
---|
522 | (((Length + 1) / 2) < sizeof (UINTN)) ? ((Length + 1) / 2) : sizeof (UINTN)
|
---|
523 | );
|
---|
524 | FreePool (TmpBuffer);
|
---|
525 |
|
---|
526 | StringPtr += Length;
|
---|
527 | if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) {
|
---|
528 | return;
|
---|
529 | }
|
---|
530 |
|
---|
531 | StringPtr += StrLen (L"&VALUE=");
|
---|
532 |
|
---|
533 | //
|
---|
534 | // Get Value
|
---|
535 | //
|
---|
536 | Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);
|
---|
537 | if (EFI_ERROR (Status)) {
|
---|
538 | return;
|
---|
539 | }
|
---|
540 |
|
---|
541 | StringPtr += Length;
|
---|
542 |
|
---|
543 | //
|
---|
544 | // Skip the character "&" before "OFFSET".
|
---|
545 | //
|
---|
546 | StringPtr++;
|
---|
547 |
|
---|
548 | //
|
---|
549 | // Calculate Value and convert it to hex string.
|
---|
550 | //
|
---|
551 | if (Offset + Width > BlockSize) {
|
---|
552 | return;
|
---|
553 | }
|
---|
554 |
|
---|
555 | if ((Offset <= ValueOffset) && (Offset + Width >= ValueOffset + ValueWidth)) {
|
---|
556 | *RequestResult = CreateAltCfgString (*RequestResult, ConfigRequestHdr, ValueOffset, ValueWidth);
|
---|
557 | return;
|
---|
558 | }
|
---|
559 | }
|
---|
560 | }
|
---|
561 |
|
---|
562 | /**
|
---|
563 | This function allows a caller to extract the current configuration for one
|
---|
564 | or more named elements from the target driver.
|
---|
565 |
|
---|
566 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
|
---|
567 | @param Request A null-terminated Unicode string in
|
---|
568 | <ConfigRequest> format.
|
---|
569 | @param Progress On return, points to a character in the Request
|
---|
570 | string. Points to the string's null terminator if
|
---|
571 | request was successful. Points to the most recent
|
---|
572 | '&' before the first failing name/value pair (or
|
---|
573 | the beginning of the string if the failure is in
|
---|
574 | the first name/value pair) if the request was not
|
---|
575 | successful.
|
---|
576 | @param Results A null-terminated Unicode string in
|
---|
577 | <ConfigAltResp> format which has all values filled
|
---|
578 | in for the names in the Request string. String to
|
---|
579 | be allocated by the called function.
|
---|
580 |
|
---|
581 | @retval EFI_SUCCESS The Results is filled with the requested values.
|
---|
582 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
|
---|
583 | @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
|
---|
584 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
|
---|
585 | driver.
|
---|
586 |
|
---|
587 | **/
|
---|
588 | EFI_STATUS
|
---|
589 | EFIAPI
|
---|
590 | ExtractConfig (
|
---|
591 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
|
---|
592 | IN CONST EFI_STRING Request,
|
---|
593 | OUT EFI_STRING *Progress,
|
---|
594 | OUT EFI_STRING *Results
|
---|
595 | )
|
---|
596 | {
|
---|
597 | EFI_STATUS Status;
|
---|
598 | UINTN BufferSize;
|
---|
599 | DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
|
---|
600 | EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
|
---|
601 | EFI_STRING ConfigRequest;
|
---|
602 | EFI_STRING ConfigRequestHdr;
|
---|
603 | UINTN Size;
|
---|
604 | EFI_STRING Value;
|
---|
605 | UINTN ValueStrLen;
|
---|
606 | CHAR16 BackupChar;
|
---|
607 | CHAR16 *StrPointer;
|
---|
608 | BOOLEAN AllocatedRequest;
|
---|
609 |
|
---|
610 | if ((Progress == NULL) || (Results == NULL)) {
|
---|
611 | return EFI_INVALID_PARAMETER;
|
---|
612 | }
|
---|
613 |
|
---|
614 | //
|
---|
615 | // Initialize the local variables.
|
---|
616 | //
|
---|
617 | ConfigRequestHdr = NULL;
|
---|
618 | ConfigRequest = NULL;
|
---|
619 | Size = 0;
|
---|
620 | *Progress = Request;
|
---|
621 | AllocatedRequest = FALSE;
|
---|
622 |
|
---|
623 | PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
|
---|
624 | HiiConfigRouting = PrivateData->HiiConfigRouting;
|
---|
625 |
|
---|
626 | //
|
---|
627 | // Get Buffer Storage data from EFI variable.
|
---|
628 | // Try to get the current setting from variable.
|
---|
629 | //
|
---|
630 | BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
---|
631 | Status = gRT->GetVariable (
|
---|
632 | VariableName,
|
---|
633 | &gDriverSampleFormSetGuid,
|
---|
634 | NULL,
|
---|
635 | &BufferSize,
|
---|
636 | &PrivateData->Configuration
|
---|
637 | );
|
---|
638 | if (EFI_ERROR (Status)) {
|
---|
639 | return EFI_NOT_FOUND;
|
---|
640 | }
|
---|
641 |
|
---|
642 | if (Request == NULL) {
|
---|
643 | //
|
---|
644 | // Request is set to NULL, construct full request string.
|
---|
645 | //
|
---|
646 |
|
---|
647 | //
|
---|
648 | // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
|
---|
649 | // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
|
---|
650 | //
|
---|
651 | ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);
|
---|
652 | Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
|
---|
653 | ConfigRequest = AllocateZeroPool (Size);
|
---|
654 | ASSERT (ConfigRequest != NULL);
|
---|
655 | AllocatedRequest = TRUE;
|
---|
656 | UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
|
---|
657 | FreePool (ConfigRequestHdr);
|
---|
658 | ConfigRequestHdr = NULL;
|
---|
659 | } else {
|
---|
660 | //
|
---|
661 | // Check routing data in <ConfigHdr>.
|
---|
662 | // Note: if only one Storage is used, then this checking could be skipped.
|
---|
663 | //
|
---|
664 | if (!HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, NULL)) {
|
---|
665 | return EFI_NOT_FOUND;
|
---|
666 | }
|
---|
667 |
|
---|
668 | //
|
---|
669 | // Check whether request for EFI Varstore. EFI varstore get data
|
---|
670 | // through hii database, not support in this path.
|
---|
671 | //
|
---|
672 | if (HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, MyEfiVar)) {
|
---|
673 | return EFI_UNSUPPORTED;
|
---|
674 | }
|
---|
675 |
|
---|
676 | if (HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, MyEfiBitVar)) {
|
---|
677 | return EFI_UNSUPPORTED;
|
---|
678 | }
|
---|
679 |
|
---|
680 | if (HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, MyEfiUnionVar)) {
|
---|
681 | return EFI_UNSUPPORTED;
|
---|
682 | }
|
---|
683 |
|
---|
684 | //
|
---|
685 | // Set Request to the unified request string.
|
---|
686 | //
|
---|
687 | ConfigRequest = Request;
|
---|
688 | //
|
---|
689 | // Check whether Request includes Request Element.
|
---|
690 | //
|
---|
691 | if (StrStr (Request, L"OFFSET") == NULL) {
|
---|
692 | //
|
---|
693 | // Check Request Element does exist in Reques String
|
---|
694 | //
|
---|
695 | StrPointer = StrStr (Request, L"PATH");
|
---|
696 | if (StrPointer == NULL) {
|
---|
697 | return EFI_INVALID_PARAMETER;
|
---|
698 | }
|
---|
699 |
|
---|
700 | if (StrStr (StrPointer, L"&") == NULL) {
|
---|
701 | Size = (StrLen (Request) + 32 + 1) * sizeof (CHAR16);
|
---|
702 | ConfigRequest = AllocateZeroPool (Size);
|
---|
703 | ASSERT (ConfigRequest != NULL);
|
---|
704 | AllocatedRequest = TRUE;
|
---|
705 | UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", Request, (UINT64)BufferSize);
|
---|
706 | }
|
---|
707 | }
|
---|
708 | }
|
---|
709 |
|
---|
710 | //
|
---|
711 | // Check if requesting Name/Value storage
|
---|
712 | //
|
---|
713 | if (StrStr (ConfigRequest, L"OFFSET") == NULL) {
|
---|
714 | //
|
---|
715 | // Update Name/Value storage Names
|
---|
716 | //
|
---|
717 | Status = LoadNameValueNames (PrivateData);
|
---|
718 | if (EFI_ERROR (Status)) {
|
---|
719 | return Status;
|
---|
720 | }
|
---|
721 |
|
---|
722 | //
|
---|
723 | // Allocate memory for <ConfigResp>, e.g. Name0=0x11, Name1=0x1234, Name2="ABCD"
|
---|
724 | // <Request> ::=<ConfigHdr>&Name0&Name1&Name2
|
---|
725 | // <ConfigResp>::=<ConfigHdr>&Name0=11&Name1=1234&Name2=0041004200430044
|
---|
726 | //
|
---|
727 | BufferSize = (StrLen (ConfigRequest) +
|
---|
728 | 1 + sizeof (PrivateData->Configuration.NameValueVar0) * 2 +
|
---|
729 | 1 + sizeof (PrivateData->Configuration.NameValueVar1) * 2 +
|
---|
730 | 1 + sizeof (PrivateData->Configuration.NameValueVar2) * 2 + 1) * sizeof (CHAR16);
|
---|
731 | *Results = AllocateZeroPool (BufferSize);
|
---|
732 | ASSERT (*Results != NULL);
|
---|
733 | StrCpyS (*Results, BufferSize / sizeof (CHAR16), ConfigRequest);
|
---|
734 | Value = *Results;
|
---|
735 |
|
---|
736 | //
|
---|
737 | // Append value of NameValueVar0, type is UINT8
|
---|
738 | //
|
---|
739 | if ((Value = StrStr (*Results, PrivateData->NameValueName[0])) != NULL) {
|
---|
740 | Value += StrLen (PrivateData->NameValueName[0]);
|
---|
741 | ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar0) * 2) + 1);
|
---|
742 | CopyMem (Value + ValueStrLen, Value, StrSize (Value));
|
---|
743 |
|
---|
744 | BackupChar = Value[ValueStrLen];
|
---|
745 | *Value++ = L'=';
|
---|
746 | UnicodeValueToStringS (
|
---|
747 | Value,
|
---|
748 | BufferSize - ((UINTN)Value - (UINTN)*Results),
|
---|
749 | PREFIX_ZERO | RADIX_HEX,
|
---|
750 | PrivateData->Configuration.NameValueVar0,
|
---|
751 | sizeof (PrivateData->Configuration.NameValueVar0) * 2
|
---|
752 | );
|
---|
753 | Value += StrnLenS (Value, (BufferSize - ((UINTN)Value - (UINTN)*Results)) / sizeof (CHAR16));
|
---|
754 | *Value = BackupChar;
|
---|
755 | }
|
---|
756 |
|
---|
757 | //
|
---|
758 | // Append value of NameValueVar1, type is UINT16
|
---|
759 | //
|
---|
760 | if ((Value = StrStr (*Results, PrivateData->NameValueName[1])) != NULL) {
|
---|
761 | Value += StrLen (PrivateData->NameValueName[1]);
|
---|
762 | ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar1) * 2) + 1);
|
---|
763 | CopyMem (Value + ValueStrLen, Value, StrSize (Value));
|
---|
764 |
|
---|
765 | BackupChar = Value[ValueStrLen];
|
---|
766 | *Value++ = L'=';
|
---|
767 | UnicodeValueToStringS (
|
---|
768 | Value,
|
---|
769 | BufferSize - ((UINTN)Value - (UINTN)*Results),
|
---|
770 | PREFIX_ZERO | RADIX_HEX,
|
---|
771 | PrivateData->Configuration.NameValueVar1,
|
---|
772 | sizeof (PrivateData->Configuration.NameValueVar1) * 2
|
---|
773 | );
|
---|
774 | Value += StrnLenS (Value, (BufferSize - ((UINTN)Value - (UINTN)*Results)) / sizeof (CHAR16));
|
---|
775 | *Value = BackupChar;
|
---|
776 | }
|
---|
777 |
|
---|
778 | //
|
---|
779 | // Append value of NameValueVar2, type is CHAR16 *
|
---|
780 | //
|
---|
781 | if ((Value = StrStr (*Results, PrivateData->NameValueName[2])) != NULL) {
|
---|
782 | Value += StrLen (PrivateData->NameValueName[2]);
|
---|
783 | ValueStrLen = StrLen (PrivateData->Configuration.NameValueVar2) * 4 + 1;
|
---|
784 | CopyMem (Value + ValueStrLen, Value, StrSize (Value));
|
---|
785 |
|
---|
786 | *Value++ = L'=';
|
---|
787 | //
|
---|
788 | // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
|
---|
789 | //
|
---|
790 | StrPointer = (CHAR16 *)PrivateData->Configuration.NameValueVar2;
|
---|
791 | for ( ; *StrPointer != L'\0'; StrPointer++) {
|
---|
792 | UnicodeValueToStringS (
|
---|
793 | Value,
|
---|
794 | BufferSize - ((UINTN)Value - (UINTN)*Results),
|
---|
795 | PREFIX_ZERO | RADIX_HEX,
|
---|
796 | *StrPointer,
|
---|
797 | 4
|
---|
798 | );
|
---|
799 | Value += StrnLenS (Value, (BufferSize - ((UINTN)Value - (UINTN)*Results)) / sizeof (CHAR16));
|
---|
800 | }
|
---|
801 | }
|
---|
802 |
|
---|
803 | Status = EFI_SUCCESS;
|
---|
804 | } else {
|
---|
805 | //
|
---|
806 | // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
|
---|
807 | //
|
---|
808 | Status = HiiConfigRouting->BlockToConfig (
|
---|
809 | HiiConfigRouting,
|
---|
810 | ConfigRequest,
|
---|
811 | (UINT8 *)&PrivateData->Configuration,
|
---|
812 | BufferSize,
|
---|
813 | Results,
|
---|
814 | Progress
|
---|
815 | );
|
---|
816 | if (!EFI_ERROR (Status)) {
|
---|
817 | ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);
|
---|
818 | AppendAltCfgString (Results, ConfigRequestHdr);
|
---|
819 | }
|
---|
820 | }
|
---|
821 |
|
---|
822 | //
|
---|
823 | // Free the allocated config request string.
|
---|
824 | //
|
---|
825 | if (AllocatedRequest) {
|
---|
826 | FreePool (ConfigRequest);
|
---|
827 | }
|
---|
828 |
|
---|
829 | if (ConfigRequestHdr != NULL) {
|
---|
830 | FreePool (ConfigRequestHdr);
|
---|
831 | }
|
---|
832 |
|
---|
833 | //
|
---|
834 | // Set Progress string to the original request string.
|
---|
835 | //
|
---|
836 | if (Request == NULL) {
|
---|
837 | *Progress = NULL;
|
---|
838 | } else if (StrStr (Request, L"OFFSET") == NULL) {
|
---|
839 | *Progress = Request + StrLen (Request);
|
---|
840 | }
|
---|
841 |
|
---|
842 | return Status;
|
---|
843 | }
|
---|
844 |
|
---|
845 | /**
|
---|
846 | This function processes the results of changes in configuration.
|
---|
847 |
|
---|
848 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
|
---|
849 | @param Configuration A null-terminated Unicode string in <ConfigResp>
|
---|
850 | format.
|
---|
851 | @param Progress A pointer to a string filled in with the offset of
|
---|
852 | the most recent '&' before the first failing
|
---|
853 | name/value pair (or the beginning of the string if
|
---|
854 | the failure is in the first name/value pair) or
|
---|
855 | the terminating NULL if all was successful.
|
---|
856 |
|
---|
857 | @retval EFI_SUCCESS The Results is processed successfully.
|
---|
858 | @retval EFI_INVALID_PARAMETER Configuration is NULL.
|
---|
859 | @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
|
---|
860 | driver.
|
---|
861 | @retval EFI_DEVICE_ERROR If value is 44, return error for testing.
|
---|
862 |
|
---|
863 | **/
|
---|
864 | EFI_STATUS
|
---|
865 | EFIAPI
|
---|
866 | RouteConfig (
|
---|
867 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
|
---|
868 | IN CONST EFI_STRING Configuration,
|
---|
869 | OUT EFI_STRING *Progress
|
---|
870 | )
|
---|
871 | {
|
---|
872 | EFI_STATUS Status;
|
---|
873 | UINTN BufferSize;
|
---|
874 | DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
|
---|
875 | EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
|
---|
876 | CHAR16 *Value;
|
---|
877 | CHAR16 *StrPtr;
|
---|
878 | CHAR16 TemStr[5];
|
---|
879 | UINT8 *DataBuffer;
|
---|
880 | UINT8 DigitUint8;
|
---|
881 | UINTN Index;
|
---|
882 | CHAR16 *StrBuffer;
|
---|
883 |
|
---|
884 | if ((Configuration == NULL) || (Progress == NULL)) {
|
---|
885 | return EFI_INVALID_PARAMETER;
|
---|
886 | }
|
---|
887 |
|
---|
888 | PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
|
---|
889 | HiiConfigRouting = PrivateData->HiiConfigRouting;
|
---|
890 | *Progress = Configuration;
|
---|
891 |
|
---|
892 | //
|
---|
893 | // Check routing data in <ConfigHdr>.
|
---|
894 | // Note: if only one Storage is used, then this checking could be skipped.
|
---|
895 | //
|
---|
896 | if (!HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, NULL)) {
|
---|
897 | return EFI_NOT_FOUND;
|
---|
898 | }
|
---|
899 |
|
---|
900 | //
|
---|
901 | // Check whether request for EFI Varstore. EFI varstore get data
|
---|
902 | // through hii database, not support in this path.
|
---|
903 | //
|
---|
904 | if (HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) {
|
---|
905 | return EFI_UNSUPPORTED;
|
---|
906 | }
|
---|
907 |
|
---|
908 | if (HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, MyEfiBitVar)) {
|
---|
909 | return EFI_UNSUPPORTED;
|
---|
910 | }
|
---|
911 |
|
---|
912 | if (HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, MyEfiUnionVar)) {
|
---|
913 | return EFI_UNSUPPORTED;
|
---|
914 | }
|
---|
915 |
|
---|
916 | //
|
---|
917 | // Get Buffer Storage data from EFI variable
|
---|
918 | //
|
---|
919 | BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
---|
920 | Status = gRT->GetVariable (
|
---|
921 | VariableName,
|
---|
922 | &gDriverSampleFormSetGuid,
|
---|
923 | NULL,
|
---|
924 | &BufferSize,
|
---|
925 | &PrivateData->Configuration
|
---|
926 | );
|
---|
927 | if (EFI_ERROR (Status)) {
|
---|
928 | return Status;
|
---|
929 | }
|
---|
930 |
|
---|
931 | //
|
---|
932 | // Check if configuring Name/Value storage
|
---|
933 | //
|
---|
934 | if (StrStr (Configuration, L"OFFSET") == NULL) {
|
---|
935 | //
|
---|
936 | // Update Name/Value storage Names
|
---|
937 | //
|
---|
938 | Status = LoadNameValueNames (PrivateData);
|
---|
939 | if (EFI_ERROR (Status)) {
|
---|
940 | return Status;
|
---|
941 | }
|
---|
942 |
|
---|
943 | //
|
---|
944 | // Convert value for NameValueVar0
|
---|
945 | //
|
---|
946 | if ((Value = StrStr (Configuration, PrivateData->NameValueName[0])) != NULL) {
|
---|
947 | //
|
---|
948 | // Skip "Name="
|
---|
949 | //
|
---|
950 | Value += StrLen (PrivateData->NameValueName[0]);
|
---|
951 | Value++;
|
---|
952 | //
|
---|
953 | // Get Value String
|
---|
954 | //
|
---|
955 | StrPtr = StrStr (Value, L"&");
|
---|
956 | if (StrPtr == NULL) {
|
---|
957 | StrPtr = Value + StrLen (Value);
|
---|
958 | }
|
---|
959 |
|
---|
960 | //
|
---|
961 | // Convert Value to Buffer data
|
---|
962 | //
|
---|
963 | DataBuffer = (UINT8 *)&PrivateData->Configuration.NameValueVar0;
|
---|
964 | ZeroMem (TemStr, sizeof (TemStr));
|
---|
965 | for (Index = 0, StrPtr--; StrPtr >= Value; StrPtr--, Index++) {
|
---|
966 | TemStr[0] = *StrPtr;
|
---|
967 | DigitUint8 = (UINT8)StrHexToUint64 (TemStr);
|
---|
968 | if ((Index & 1) == 0) {
|
---|
969 | DataBuffer[Index/2] = DigitUint8;
|
---|
970 | } else {
|
---|
971 | DataBuffer[Index/2] = (UINT8)((UINT8)(DigitUint8 << 4) + DataBuffer[Index/2]);
|
---|
972 | }
|
---|
973 | }
|
---|
974 | }
|
---|
975 |
|
---|
976 | //
|
---|
977 | // Convert value for NameValueVar1
|
---|
978 | //
|
---|
979 | if ((Value = StrStr (Configuration, PrivateData->NameValueName[1])) != NULL) {
|
---|
980 | //
|
---|
981 | // Skip "Name="
|
---|
982 | //
|
---|
983 | Value += StrLen (PrivateData->NameValueName[1]);
|
---|
984 | Value++;
|
---|
985 | //
|
---|
986 | // Get Value String
|
---|
987 | //
|
---|
988 | StrPtr = StrStr (Value, L"&");
|
---|
989 | if (StrPtr == NULL) {
|
---|
990 | StrPtr = Value + StrLen (Value);
|
---|
991 | }
|
---|
992 |
|
---|
993 | //
|
---|
994 | // Convert Value to Buffer data
|
---|
995 | //
|
---|
996 | DataBuffer = (UINT8 *)&PrivateData->Configuration.NameValueVar1;
|
---|
997 | ZeroMem (TemStr, sizeof (TemStr));
|
---|
998 | for (Index = 0, StrPtr--; StrPtr >= Value; StrPtr--, Index++) {
|
---|
999 | TemStr[0] = *StrPtr;
|
---|
1000 | DigitUint8 = (UINT8)StrHexToUint64 (TemStr);
|
---|
1001 | if ((Index & 1) == 0) {
|
---|
1002 | DataBuffer[Index/2] = DigitUint8;
|
---|
1003 | } else {
|
---|
1004 | DataBuffer[Index/2] = (UINT8)((UINT8)(DigitUint8 << 4) + DataBuffer[Index/2]);
|
---|
1005 | }
|
---|
1006 | }
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 | //
|
---|
1010 | // Convert value for NameValueVar2
|
---|
1011 | //
|
---|
1012 | if ((Value = StrStr (Configuration, PrivateData->NameValueName[2])) != NULL) {
|
---|
1013 | //
|
---|
1014 | // Skip "Name="
|
---|
1015 | //
|
---|
1016 | Value += StrLen (PrivateData->NameValueName[2]);
|
---|
1017 | Value++;
|
---|
1018 | //
|
---|
1019 | // Get Value String
|
---|
1020 | //
|
---|
1021 | StrPtr = StrStr (Value, L"&");
|
---|
1022 | if (StrPtr == NULL) {
|
---|
1023 | StrPtr = Value + StrLen (Value);
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | //
|
---|
1027 | // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
|
---|
1028 | //
|
---|
1029 | StrBuffer = (CHAR16 *)PrivateData->Configuration.NameValueVar2;
|
---|
1030 | ZeroMem (TemStr, sizeof (TemStr));
|
---|
1031 | while (Value < StrPtr) {
|
---|
1032 | StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), Value, 4);
|
---|
1033 | *(StrBuffer++) = (CHAR16)StrHexToUint64 (TemStr);
|
---|
1034 | Value += 4;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | *StrBuffer = L'\0';
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | //
|
---|
1041 | // Store Buffer Storage back to EFI variable
|
---|
1042 | //
|
---|
1043 | Status = gRT->SetVariable (
|
---|
1044 | VariableName,
|
---|
1045 | &gDriverSampleFormSetGuid,
|
---|
1046 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
---|
1047 | sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
---|
1048 | &PrivateData->Configuration
|
---|
1049 | );
|
---|
1050 |
|
---|
1051 | return Status;
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | //
|
---|
1055 | // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
|
---|
1056 | //
|
---|
1057 | BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
---|
1058 | Status = HiiConfigRouting->ConfigToBlock (
|
---|
1059 | HiiConfigRouting,
|
---|
1060 | Configuration,
|
---|
1061 | (UINT8 *)&PrivateData->Configuration,
|
---|
1062 | &BufferSize,
|
---|
1063 | Progress
|
---|
1064 | );
|
---|
1065 | if (EFI_ERROR (Status)) {
|
---|
1066 | return Status;
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | if (PrivateData->Configuration.QuestionApply == 44) {
|
---|
1070 | // Return error for verify the error handling of caller.
|
---|
1071 | return EFI_DEVICE_ERROR;
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 | //
|
---|
1075 | // Store Buffer Storage back to EFI variable
|
---|
1076 | //
|
---|
1077 | Status = gRT->SetVariable (
|
---|
1078 | VariableName,
|
---|
1079 | &gDriverSampleFormSetGuid,
|
---|
1080 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
---|
1081 | sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
---|
1082 | &PrivateData->Configuration
|
---|
1083 | );
|
---|
1084 |
|
---|
1085 | return Status;
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | /**
|
---|
1089 | This function processes the results of changes in configuration.
|
---|
1090 |
|
---|
1091 | @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
|
---|
1092 | @param Action Specifies the type of action taken by the browser.
|
---|
1093 | @param QuestionId A unique value which is sent to the original
|
---|
1094 | exporting driver so that it can identify the type
|
---|
1095 | of data to expect.
|
---|
1096 | @param Type The type of value for the question.
|
---|
1097 | @param Value A pointer to the data being sent to the original
|
---|
1098 | exporting driver.
|
---|
1099 | @param ActionRequest On return, points to the action requested by the
|
---|
1100 | callback function.
|
---|
1101 |
|
---|
1102 | @retval EFI_SUCCESS The callback successfully handled the action.
|
---|
1103 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
|
---|
1104 | variable and its data.
|
---|
1105 | @retval EFI_DEVICE_ERROR The variable could not be saved.
|
---|
1106 | @retval EFI_UNSUPPORTED The specified Action is not supported by the
|
---|
1107 | callback.
|
---|
1108 |
|
---|
1109 | **/
|
---|
1110 | EFI_STATUS
|
---|
1111 | EFIAPI
|
---|
1112 | DriverCallback (
|
---|
1113 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
|
---|
1114 | IN EFI_BROWSER_ACTION Action,
|
---|
1115 | IN EFI_QUESTION_ID QuestionId,
|
---|
1116 | IN UINT8 Type,
|
---|
1117 | IN EFI_IFR_TYPE_VALUE *Value,
|
---|
1118 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
|
---|
1119 | )
|
---|
1120 | {
|
---|
1121 | DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
|
---|
1122 | EFI_STATUS Status;
|
---|
1123 | VOID *StartOpCodeHandle;
|
---|
1124 | VOID *OptionsOpCodeHandle;
|
---|
1125 | EFI_IFR_GUID_LABEL *StartLabel;
|
---|
1126 | VOID *EndOpCodeHandle;
|
---|
1127 | EFI_IFR_GUID_LABEL *EndLabel;
|
---|
1128 | EFI_INPUT_KEY Key;
|
---|
1129 | DRIVER_SAMPLE_CONFIGURATION *Configuration;
|
---|
1130 | MY_EFI_VARSTORE_DATA *EfiData;
|
---|
1131 | EFI_FORM_ID FormId;
|
---|
1132 | EFI_STRING Progress;
|
---|
1133 | EFI_STRING Results;
|
---|
1134 | UINT32 ProgressErr;
|
---|
1135 | CHAR16 *TmpStr;
|
---|
1136 | UINTN Index;
|
---|
1137 | UINT64 BufferValue;
|
---|
1138 | EFI_HII_POPUP_SELECTION UserSelection;
|
---|
1139 |
|
---|
1140 | UserSelection = 0xFF;
|
---|
1141 |
|
---|
1142 | if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE)) ||
|
---|
1143 | (ActionRequest == NULL))
|
---|
1144 | {
|
---|
1145 | return EFI_INVALID_PARAMETER;
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | FormId = 0;
|
---|
1149 | ProgressErr = 0;
|
---|
1150 | Status = EFI_SUCCESS;
|
---|
1151 | BufferValue = 3;
|
---|
1152 | PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
|
---|
1153 |
|
---|
1154 | switch (Action) {
|
---|
1155 | case EFI_BROWSER_ACTION_FORM_OPEN:
|
---|
1156 | {
|
---|
1157 | if (QuestionId == 0x1234) {
|
---|
1158 | //
|
---|
1159 | // Sample CallBack for UEFI FORM_OPEN action:
|
---|
1160 | // Add Save action into Form 3 when Form 1 is opened.
|
---|
1161 | // This will be done only in FORM_OPEN CallBack of question with ID 0x1234 from Form 1.
|
---|
1162 | //
|
---|
1163 | PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
|
---|
1164 |
|
---|
1165 | //
|
---|
1166 | // Initialize the container for dynamic opcodes
|
---|
1167 | //
|
---|
1168 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();
|
---|
1169 | ASSERT (StartOpCodeHandle != NULL);
|
---|
1170 |
|
---|
1171 | //
|
---|
1172 | // Create Hii Extend Label OpCode as the start opcode
|
---|
1173 | //
|
---|
1174 | StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
|
---|
1175 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
---|
1176 | StartLabel->Number = LABEL_UPDATE2;
|
---|
1177 |
|
---|
1178 | HiiCreateActionOpCode (
|
---|
1179 | StartOpCodeHandle, // Container for dynamic created opcodes
|
---|
1180 | 0x1238, // Question ID
|
---|
1181 | STRING_TOKEN (STR_SAVE_TEXT), // Prompt text
|
---|
1182 | STRING_TOKEN (STR_SAVE_TEXT), // Help text
|
---|
1183 | EFI_IFR_FLAG_CALLBACK, // Question flag
|
---|
1184 | 0 // Action String ID
|
---|
1185 | );
|
---|
1186 |
|
---|
1187 | HiiUpdateForm (
|
---|
1188 | PrivateData->HiiHandle[0], // HII handle
|
---|
1189 | &gDriverSampleFormSetGuid, // Formset GUID
|
---|
1190 | 0x3, // Form ID
|
---|
1191 | StartOpCodeHandle, // Label for where to insert opcodes
|
---|
1192 | NULL // Insert data
|
---|
1193 | );
|
---|
1194 |
|
---|
1195 | HiiFreeOpCodeHandle (StartOpCodeHandle);
|
---|
1196 | }
|
---|
1197 |
|
---|
1198 | if (QuestionId == 0x1247) {
|
---|
1199 | Status = InternalStartMonitor ();
|
---|
1200 | ASSERT_EFI_ERROR (Status);
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | break;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | case EFI_BROWSER_ACTION_FORM_CLOSE:
|
---|
1207 | {
|
---|
1208 | if (QuestionId == 0x5678) {
|
---|
1209 | //
|
---|
1210 | // Sample CallBack for UEFI FORM_CLOSE action:
|
---|
1211 | // Show up a pop-up to specify Form 3 will be closed when exit Form 3.
|
---|
1212 | //
|
---|
1213 | do {
|
---|
1214 | CreatePopUp (
|
---|
1215 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
|
---|
1216 | &Key,
|
---|
1217 | L"",
|
---|
1218 | L"You are going to leave third Form!",
|
---|
1219 | L"Press ESC or ENTER to continue ...",
|
---|
1220 | L"",
|
---|
1221 | NULL
|
---|
1222 | );
|
---|
1223 | } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | if (QuestionId == 0x1247) {
|
---|
1227 | Status = InternalStopMonitor ();
|
---|
1228 | ASSERT_EFI_ERROR (Status);
|
---|
1229 | }
|
---|
1230 |
|
---|
1231 | break;
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | case EFI_BROWSER_ACTION_RETRIEVE:
|
---|
1235 | {
|
---|
1236 | switch (QuestionId ) {
|
---|
1237 | case 0x1248:
|
---|
1238 | if (Type != EFI_IFR_TYPE_REF) {
|
---|
1239 | return EFI_INVALID_PARAMETER;
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 | Value->ref.FormId = 0x3;
|
---|
1243 | break;
|
---|
1244 |
|
---|
1245 | case 0x5678:
|
---|
1246 | case 0x1247:
|
---|
1247 | //
|
---|
1248 | // We will reach here once the Question is refreshed
|
---|
1249 | //
|
---|
1250 |
|
---|
1251 | //
|
---|
1252 | // Initialize the container for dynamic opcodes
|
---|
1253 | //
|
---|
1254 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();
|
---|
1255 | ASSERT (StartOpCodeHandle != NULL);
|
---|
1256 |
|
---|
1257 | //
|
---|
1258 | // Create Hii Extend Label OpCode as the start opcode
|
---|
1259 | //
|
---|
1260 | StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
|
---|
1261 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
---|
1262 | if (QuestionId == 0x5678) {
|
---|
1263 | StartLabel->Number = LABEL_UPDATE2;
|
---|
1264 | FormId = 0x03;
|
---|
1265 | PrivateData->Configuration.DynamicRefresh++;
|
---|
1266 | } else if (QuestionId == 0x1247 ) {
|
---|
1267 | StartLabel->Number = LABEL_UPDATE3;
|
---|
1268 | FormId = 0x06;
|
---|
1269 | PrivateData->Configuration.RefreshGuidCount++;
|
---|
1270 | }
|
---|
1271 |
|
---|
1272 | HiiCreateActionOpCode (
|
---|
1273 | StartOpCodeHandle, // Container for dynamic created opcodes
|
---|
1274 | 0x1237, // Question ID
|
---|
1275 | STRING_TOKEN (STR_EXIT_TEXT), // Prompt text
|
---|
1276 | STRING_TOKEN (STR_EXIT_TEXT), // Help text
|
---|
1277 | EFI_IFR_FLAG_CALLBACK, // Question flag
|
---|
1278 | 0 // Action String ID
|
---|
1279 | );
|
---|
1280 |
|
---|
1281 | HiiUpdateForm (
|
---|
1282 | PrivateData->HiiHandle[0], // HII handle
|
---|
1283 | &gDriverSampleFormSetGuid, // Formset GUID
|
---|
1284 | FormId, // Form ID
|
---|
1285 | StartOpCodeHandle, // Label for where to insert opcodes
|
---|
1286 | NULL // Insert data
|
---|
1287 | );
|
---|
1288 |
|
---|
1289 | HiiFreeOpCodeHandle (StartOpCodeHandle);
|
---|
1290 |
|
---|
1291 | //
|
---|
1292 | // Refresh the Question value
|
---|
1293 | //
|
---|
1294 | Status = gRT->SetVariable (
|
---|
1295 | VariableName,
|
---|
1296 | &gDriverSampleFormSetGuid,
|
---|
1297 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
---|
1298 | sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
---|
1299 | &PrivateData->Configuration
|
---|
1300 | );
|
---|
1301 |
|
---|
1302 | if (QuestionId == 0x5678) {
|
---|
1303 | //
|
---|
1304 | // Update uncommitted data of Browser
|
---|
1305 | //
|
---|
1306 | EfiData = AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA));
|
---|
1307 | ASSERT (EfiData != NULL);
|
---|
1308 | if (HiiGetBrowserData (&gDriverSampleFormSetGuid, MyEfiVar, sizeof (MY_EFI_VARSTORE_DATA), (UINT8 *)EfiData)) {
|
---|
1309 | EfiData->Field8 = 111;
|
---|
1310 | HiiSetBrowserData (
|
---|
1311 | &gDriverSampleFormSetGuid,
|
---|
1312 | MyEfiVar,
|
---|
1313 | sizeof (MY_EFI_VARSTORE_DATA),
|
---|
1314 | (UINT8 *)EfiData,
|
---|
1315 | NULL
|
---|
1316 | );
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 | FreePool (EfiData);
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 | break;
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | break;
|
---|
1326 | }
|
---|
1327 |
|
---|
1328 | case EFI_BROWSER_ACTION_DEFAULT_STANDARD:
|
---|
1329 | {
|
---|
1330 | switch (QuestionId) {
|
---|
1331 | case 0x1240:
|
---|
1332 | Value->u8 = DEFAULT_CLASS_STANDARD_VALUE;
|
---|
1333 | break;
|
---|
1334 |
|
---|
1335 | case 0x1252:
|
---|
1336 | for (Index = 0; Index < 3; Index++) {
|
---|
1337 | SetArrayData (Value, EFI_IFR_TYPE_NUM_SIZE_8, Index, BufferValue--);
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 | break;
|
---|
1341 |
|
---|
1342 | case 0x6666:
|
---|
1343 | Value->u8 = 12;
|
---|
1344 | break;
|
---|
1345 |
|
---|
1346 | default:
|
---|
1347 | Status = EFI_UNSUPPORTED;
|
---|
1348 | break;
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | break;
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING:
|
---|
1355 | {
|
---|
1356 | switch (QuestionId) {
|
---|
1357 | case 0x1240:
|
---|
1358 | Value->u8 = DEFAULT_CLASS_MANUFACTURING_VALUE;
|
---|
1359 | break;
|
---|
1360 |
|
---|
1361 | case 0x6666:
|
---|
1362 | Value->u8 = 13;
|
---|
1363 | break;
|
---|
1364 |
|
---|
1365 | default:
|
---|
1366 | Status = EFI_UNSUPPORTED;
|
---|
1367 | break;
|
---|
1368 | }
|
---|
1369 |
|
---|
1370 | break;
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 | case EFI_BROWSER_ACTION_CHANGING:
|
---|
1374 | {
|
---|
1375 | switch (QuestionId) {
|
---|
1376 | case 0x1249:
|
---|
1377 | {
|
---|
1378 | if (Type != EFI_IFR_TYPE_REF) {
|
---|
1379 | return EFI_INVALID_PARAMETER;
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 | Value->ref.FormId = 0x1234;
|
---|
1383 | break;
|
---|
1384 | }
|
---|
1385 | case 0x1234:
|
---|
1386 | //
|
---|
1387 | // Initialize the container for dynamic opcodes
|
---|
1388 | //
|
---|
1389 | StartOpCodeHandle = HiiAllocateOpCodeHandle ();
|
---|
1390 | ASSERT (StartOpCodeHandle != NULL);
|
---|
1391 |
|
---|
1392 | EndOpCodeHandle = HiiAllocateOpCodeHandle ();
|
---|
1393 | ASSERT (EndOpCodeHandle != NULL);
|
---|
1394 |
|
---|
1395 | //
|
---|
1396 | // Create Hii Extend Label OpCode as the start opcode
|
---|
1397 | //
|
---|
1398 | StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
|
---|
1399 | StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
---|
1400 | StartLabel->Number = LABEL_UPDATE1;
|
---|
1401 |
|
---|
1402 | //
|
---|
1403 | // Create Hii Extend Label OpCode as the end opcode
|
---|
1404 | //
|
---|
1405 | EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
|
---|
1406 | EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
|
---|
1407 | EndLabel->Number = LABEL_END;
|
---|
1408 |
|
---|
1409 | HiiCreateActionOpCode (
|
---|
1410 | StartOpCodeHandle, // Container for dynamic created opcodes
|
---|
1411 | 0x1237, // Question ID
|
---|
1412 | STRING_TOKEN (STR_EXIT_TEXT), // Prompt text
|
---|
1413 | STRING_TOKEN (STR_EXIT_TEXT), // Help text
|
---|
1414 | EFI_IFR_FLAG_CALLBACK, // Question flag
|
---|
1415 | 0 // Action String ID
|
---|
1416 | );
|
---|
1417 |
|
---|
1418 | //
|
---|
1419 | // Create Option OpCode
|
---|
1420 | //
|
---|
1421 | OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
|
---|
1422 | ASSERT (OptionsOpCodeHandle != NULL);
|
---|
1423 |
|
---|
1424 | HiiCreateOneOfOptionOpCode (
|
---|
1425 | OptionsOpCodeHandle,
|
---|
1426 | STRING_TOKEN (STR_BOOT_OPTION1),
|
---|
1427 | 0,
|
---|
1428 | EFI_IFR_NUMERIC_SIZE_1,
|
---|
1429 | 1
|
---|
1430 | );
|
---|
1431 |
|
---|
1432 | HiiCreateOneOfOptionOpCode (
|
---|
1433 | OptionsOpCodeHandle,
|
---|
1434 | STRING_TOKEN (STR_BOOT_OPTION2),
|
---|
1435 | 0,
|
---|
1436 | EFI_IFR_NUMERIC_SIZE_1,
|
---|
1437 | 2
|
---|
1438 | );
|
---|
1439 |
|
---|
1440 | //
|
---|
1441 | // Prepare initial value for the dynamic created oneof Question
|
---|
1442 | //
|
---|
1443 | PrivateData->Configuration.DynamicOneof = 2;
|
---|
1444 | Status = gRT->SetVariable (
|
---|
1445 | VariableName,
|
---|
1446 | &gDriverSampleFormSetGuid,
|
---|
1447 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
---|
1448 | sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
---|
1449 | &PrivateData->Configuration
|
---|
1450 | );
|
---|
1451 |
|
---|
1452 | //
|
---|
1453 | // Set initial vlaue of dynamic created oneof Question in Form Browser
|
---|
1454 | //
|
---|
1455 | Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));
|
---|
1456 | ASSERT (Configuration != NULL);
|
---|
1457 | if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *)Configuration)) {
|
---|
1458 | Configuration->DynamicOneof = 2;
|
---|
1459 |
|
---|
1460 | //
|
---|
1461 | // Update uncommitted data of Browser
|
---|
1462 | //
|
---|
1463 | HiiSetBrowserData (
|
---|
1464 | &gDriverSampleFormSetGuid,
|
---|
1465 | VariableName,
|
---|
1466 | sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
---|
1467 | (UINT8 *)Configuration,
|
---|
1468 | NULL
|
---|
1469 | );
|
---|
1470 | }
|
---|
1471 |
|
---|
1472 | FreePool (Configuration);
|
---|
1473 |
|
---|
1474 | HiiCreateOneOfOpCode (
|
---|
1475 | StartOpCodeHandle, // Container for dynamic created opcodes
|
---|
1476 | 0x8001, // Question ID (or call it "key")
|
---|
1477 | CONFIGURATION_VARSTORE_ID, // VarStore ID
|
---|
1478 | (UINT16)DYNAMIC_ONE_OF_VAR_OFFSET, // Offset in Buffer Storage
|
---|
1479 | STRING_TOKEN (STR_ONE_OF_PROMPT), // Question prompt text
|
---|
1480 | STRING_TOKEN (STR_ONE_OF_HELP), // Question help text
|
---|
1481 | EFI_IFR_FLAG_CALLBACK, // Question flag
|
---|
1482 | EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value
|
---|
1483 | OptionsOpCodeHandle, // Option Opcode list
|
---|
1484 | NULL // Default Opcode is NULl
|
---|
1485 | );
|
---|
1486 |
|
---|
1487 | HiiCreateOrderedListOpCode (
|
---|
1488 | StartOpCodeHandle, // Container for dynamic created opcodes
|
---|
1489 | 0x8002, // Question ID
|
---|
1490 | CONFIGURATION_VARSTORE_ID, // VarStore ID
|
---|
1491 | (UINT16)DYNAMIC_ORDERED_LIST_VAR_OFFSET, // Offset in Buffer Storage
|
---|
1492 | STRING_TOKEN (STR_BOOT_OPTIONS), // Question prompt text
|
---|
1493 | STRING_TOKEN (STR_BOOT_OPTIONS), // Question help text
|
---|
1494 | EFI_IFR_FLAG_RESET_REQUIRED, // Question flag
|
---|
1495 | 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
|
---|
1496 | EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value
|
---|
1497 | 5, // Maximum container
|
---|
1498 | OptionsOpCodeHandle, // Option Opcode list
|
---|
1499 | NULL // Default Opcode is NULl
|
---|
1500 | );
|
---|
1501 |
|
---|
1502 | HiiCreateTextOpCode (
|
---|
1503 | StartOpCodeHandle,
|
---|
1504 | STRING_TOKEN (STR_TEXT_SAMPLE_HELP),
|
---|
1505 | STRING_TOKEN (STR_TEXT_SAMPLE_HELP),
|
---|
1506 | STRING_TOKEN (STR_TEXT_SAMPLE_STRING)
|
---|
1507 | );
|
---|
1508 |
|
---|
1509 | HiiCreateDateOpCode (
|
---|
1510 | StartOpCodeHandle,
|
---|
1511 | 0x8004,
|
---|
1512 | 0x0,
|
---|
1513 | 0x0,
|
---|
1514 | STRING_TOKEN (STR_DATE_SAMPLE_HELP),
|
---|
1515 | STRING_TOKEN (STR_DATE_SAMPLE_HELP),
|
---|
1516 | 0,
|
---|
1517 | QF_DATE_STORAGE_TIME,
|
---|
1518 | NULL
|
---|
1519 | );
|
---|
1520 |
|
---|
1521 | HiiCreateTimeOpCode (
|
---|
1522 | StartOpCodeHandle,
|
---|
1523 | 0x8005,
|
---|
1524 | 0x0,
|
---|
1525 | 0x0,
|
---|
1526 | STRING_TOKEN (STR_TIME_SAMPLE_HELP),
|
---|
1527 | STRING_TOKEN (STR_TIME_SAMPLE_HELP),
|
---|
1528 | 0,
|
---|
1529 | QF_TIME_STORAGE_TIME,
|
---|
1530 | NULL
|
---|
1531 | );
|
---|
1532 |
|
---|
1533 | HiiCreateGotoOpCode (
|
---|
1534 | StartOpCodeHandle, // Container for dynamic created opcodes
|
---|
1535 | 1, // Target Form ID
|
---|
1536 | STRING_TOKEN (STR_GOTO_FORM1), // Prompt text
|
---|
1537 | STRING_TOKEN (STR_GOTO_HELP), // Help text
|
---|
1538 | 0, // Question flag
|
---|
1539 | 0x8003 // Question ID
|
---|
1540 | );
|
---|
1541 |
|
---|
1542 | HiiUpdateForm (
|
---|
1543 | PrivateData->HiiHandle[0], // HII handle
|
---|
1544 | &gDriverSampleFormSetGuid, // Formset GUID
|
---|
1545 | 0x1234, // Form ID
|
---|
1546 | StartOpCodeHandle, // Label for where to insert opcodes
|
---|
1547 | EndOpCodeHandle // Replace data
|
---|
1548 | );
|
---|
1549 |
|
---|
1550 | HiiFreeOpCodeHandle (StartOpCodeHandle);
|
---|
1551 | HiiFreeOpCodeHandle (OptionsOpCodeHandle);
|
---|
1552 | HiiFreeOpCodeHandle (EndOpCodeHandle);
|
---|
1553 | break;
|
---|
1554 |
|
---|
1555 | default:
|
---|
1556 | break;
|
---|
1557 | }
|
---|
1558 |
|
---|
1559 | break;
|
---|
1560 | }
|
---|
1561 |
|
---|
1562 | case EFI_BROWSER_ACTION_CHANGED:
|
---|
1563 | switch (QuestionId) {
|
---|
1564 | case 0x1237:
|
---|
1565 | //
|
---|
1566 | // User press "Exit now", request Browser to exit
|
---|
1567 | //
|
---|
1568 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
|
---|
1569 | break;
|
---|
1570 |
|
---|
1571 | case 0x1238:
|
---|
1572 | //
|
---|
1573 | // User press "Save now", request Browser to save the uncommitted data.
|
---|
1574 | //
|
---|
1575 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
|
---|
1576 | break;
|
---|
1577 |
|
---|
1578 | case 0x1241:
|
---|
1579 | case 0x1246:
|
---|
1580 | //
|
---|
1581 | // User press "Submit current form and Exit now", request Browser to submit current form and exit
|
---|
1582 | //
|
---|
1583 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
|
---|
1584 | break;
|
---|
1585 |
|
---|
1586 | case 0x1242:
|
---|
1587 | //
|
---|
1588 | // User press "Discard current form now", request Browser to discard the uncommitted data.
|
---|
1589 | //
|
---|
1590 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD;
|
---|
1591 | break;
|
---|
1592 |
|
---|
1593 | case 0x1243:
|
---|
1594 | //
|
---|
1595 | // User press "Submit current form now", request Browser to save the uncommitted data.
|
---|
1596 | //
|
---|
1597 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
|
---|
1598 | break;
|
---|
1599 |
|
---|
1600 | case 0x1244:
|
---|
1601 | case 0x1245:
|
---|
1602 | //
|
---|
1603 | // User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit.
|
---|
1604 | //
|
---|
1605 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
|
---|
1606 | break;
|
---|
1607 |
|
---|
1608 | case 0x1253:
|
---|
1609 | //
|
---|
1610 | // User change the value of "Question apply test".
|
---|
1611 | //
|
---|
1612 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_QUESTION_APPLY;
|
---|
1613 | break;
|
---|
1614 |
|
---|
1615 | case 0x1231:
|
---|
1616 | //
|
---|
1617 | // 1. Check to see whether system support keyword.
|
---|
1618 | //
|
---|
1619 | Status = PrivateData->HiiKeywordHandler->GetData (
|
---|
1620 | PrivateData->HiiKeywordHandler,
|
---|
1621 | L"NAMESPACE=x-UEFI-ns",
|
---|
1622 | L"KEYWORD=iSCSIBootEnable",
|
---|
1623 | &Progress,
|
---|
1624 | &ProgressErr,
|
---|
1625 | &Results
|
---|
1626 | );
|
---|
1627 | if (EFI_ERROR (Status)) {
|
---|
1628 | do {
|
---|
1629 | CreatePopUp (
|
---|
1630 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
|
---|
1631 | &Key,
|
---|
1632 | L"",
|
---|
1633 | L"This system not support this keyword!",
|
---|
1634 | L"Press ENTER to continue ...",
|
---|
1635 | L"",
|
---|
1636 | NULL
|
---|
1637 | );
|
---|
1638 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
|
---|
1639 |
|
---|
1640 | Status = EFI_SUCCESS;
|
---|
1641 | break;
|
---|
1642 | }
|
---|
1643 |
|
---|
1644 | //
|
---|
1645 | // 2. If system support this keyword, just try to change value.
|
---|
1646 | //
|
---|
1647 |
|
---|
1648 | //
|
---|
1649 | // Change value from '0' to '1' or from '1' to '0'
|
---|
1650 | //
|
---|
1651 | TmpStr = StrStr (Results, L"&VALUE=");
|
---|
1652 | ASSERT (TmpStr != NULL);
|
---|
1653 | TmpStr += StrLen (L"&VALUE=");
|
---|
1654 | TmpStr++;
|
---|
1655 | if (*TmpStr == L'0') {
|
---|
1656 | *TmpStr = L'1';
|
---|
1657 | } else {
|
---|
1658 | *TmpStr = L'0';
|
---|
1659 | }
|
---|
1660 |
|
---|
1661 | //
|
---|
1662 | // 3. Call the keyword handler protocol to change the value.
|
---|
1663 | //
|
---|
1664 | Status = PrivateData->HiiKeywordHandler->SetData (
|
---|
1665 | PrivateData->HiiKeywordHandler,
|
---|
1666 | Results,
|
---|
1667 | &Progress,
|
---|
1668 | &ProgressErr
|
---|
1669 | );
|
---|
1670 | if (EFI_ERROR (Status)) {
|
---|
1671 | do {
|
---|
1672 | CreatePopUp (
|
---|
1673 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
|
---|
1674 | &Key,
|
---|
1675 | L"",
|
---|
1676 | L"Set keyword to the system failed!",
|
---|
1677 | L"Press ENTER to continue ...",
|
---|
1678 | L"",
|
---|
1679 | NULL
|
---|
1680 | );
|
---|
1681 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
|
---|
1682 |
|
---|
1683 | Status = EFI_SUCCESS;
|
---|
1684 | break;
|
---|
1685 | }
|
---|
1686 |
|
---|
1687 | break;
|
---|
1688 |
|
---|
1689 | case 0x1330:
|
---|
1690 | Status = mPrivateData->HiiPopup->CreatePopup (
|
---|
1691 | mPrivateData->HiiPopup,
|
---|
1692 | EfiHiiPopupStyleInfo,
|
---|
1693 | EfiHiiPopupTypeYesNo,
|
---|
1694 | mPrivateData->HiiHandle[0],
|
---|
1695 | STRING_TOKEN (STR_POPUP_STRING),
|
---|
1696 | &UserSelection
|
---|
1697 | );
|
---|
1698 | if (!EFI_ERROR (Status)) {
|
---|
1699 | if (UserSelection == EfiHiiPopupSelectionYes) {
|
---|
1700 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
|
---|
1701 | }
|
---|
1702 | }
|
---|
1703 |
|
---|
1704 | break;
|
---|
1705 |
|
---|
1706 | default:
|
---|
1707 | break;
|
---|
1708 | }
|
---|
1709 |
|
---|
1710 | break;
|
---|
1711 |
|
---|
1712 | case EFI_BROWSER_ACTION_SUBMITTED:
|
---|
1713 | {
|
---|
1714 | if (QuestionId == 0x1250) {
|
---|
1715 | //
|
---|
1716 | // Sample CallBack for EFI_BROWSER_ACTION_SUBMITTED action:
|
---|
1717 | // Show up a pop-up to show SUBMITTED callback has been triggered.
|
---|
1718 | //
|
---|
1719 | do {
|
---|
1720 | CreatePopUp (
|
---|
1721 | EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
|
---|
1722 | &Key,
|
---|
1723 | L"",
|
---|
1724 | L"EfiVarstore value has been submitted!",
|
---|
1725 | L"Press ESC or ENTER to continue ...",
|
---|
1726 | L"",
|
---|
1727 | NULL
|
---|
1728 | );
|
---|
1729 | } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
|
---|
1730 | }
|
---|
1731 |
|
---|
1732 | break;
|
---|
1733 | }
|
---|
1734 |
|
---|
1735 | default:
|
---|
1736 | Status = EFI_UNSUPPORTED;
|
---|
1737 | break;
|
---|
1738 | }
|
---|
1739 |
|
---|
1740 | return Status;
|
---|
1741 | }
|
---|
1742 |
|
---|
1743 | /**
|
---|
1744 | Main entry for this driver.
|
---|
1745 |
|
---|
1746 | @param ImageHandle Image handle this driver.
|
---|
1747 | @param SystemTable Pointer to SystemTable.
|
---|
1748 |
|
---|
1749 | @retval EFI_SUCESS This function always complete successfully.
|
---|
1750 |
|
---|
1751 | **/
|
---|
1752 | EFI_STATUS
|
---|
1753 | EFIAPI
|
---|
1754 | DriverSampleInit (
|
---|
1755 | IN EFI_HANDLE ImageHandle,
|
---|
1756 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
1757 | )
|
---|
1758 | {
|
---|
1759 | EFI_STATUS Status;
|
---|
1760 | EFI_HII_HANDLE HiiHandle[2];
|
---|
1761 | EFI_SCREEN_DESCRIPTOR Screen;
|
---|
1762 | EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
|
---|
1763 | EFI_HII_STRING_PROTOCOL *HiiString;
|
---|
1764 | EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2;
|
---|
1765 | EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
|
---|
1766 | EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler;
|
---|
1767 | EFI_HII_POPUP_PROTOCOL *PopupHandler;
|
---|
1768 | CHAR16 *NewString;
|
---|
1769 | UINTN BufferSize;
|
---|
1770 | DRIVER_SAMPLE_CONFIGURATION *Configuration;
|
---|
1771 | BOOLEAN ActionFlag;
|
---|
1772 | EFI_STRING ConfigRequestHdr;
|
---|
1773 | EFI_STRING NameRequestHdr;
|
---|
1774 | MY_EFI_VARSTORE_DATA *VarStoreConfig;
|
---|
1775 | MY_EFI_BITS_VARSTORE_DATA *BitsVarStoreConfig;
|
---|
1776 | MY_EFI_UNION_DATA *UnionConfig;
|
---|
1777 | EFI_INPUT_KEY HotKey;
|
---|
1778 | EDKII_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx;
|
---|
1779 |
|
---|
1780 | //
|
---|
1781 | // Initialize the local variables.
|
---|
1782 | //
|
---|
1783 | ConfigRequestHdr = NULL;
|
---|
1784 | NewString = NULL;
|
---|
1785 |
|
---|
1786 | //
|
---|
1787 | // Initialize screen dimensions for SendForm().
|
---|
1788 | // Remove 3 characters from top and bottom
|
---|
1789 | //
|
---|
1790 | ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR));
|
---|
1791 | gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow);
|
---|
1792 |
|
---|
1793 | Screen.TopRow = 3;
|
---|
1794 | Screen.BottomRow = Screen.BottomRow - 3;
|
---|
1795 |
|
---|
1796 | //
|
---|
1797 | // Initialize driver private data
|
---|
1798 | //
|
---|
1799 | mPrivateData = AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA));
|
---|
1800 | if (mPrivateData == NULL) {
|
---|
1801 | return EFI_OUT_OF_RESOURCES;
|
---|
1802 | }
|
---|
1803 |
|
---|
1804 | mPrivateData->Signature = DRIVER_SAMPLE_PRIVATE_SIGNATURE;
|
---|
1805 |
|
---|
1806 | mPrivateData->ConfigAccess.ExtractConfig = ExtractConfig;
|
---|
1807 | mPrivateData->ConfigAccess.RouteConfig = RouteConfig;
|
---|
1808 | mPrivateData->ConfigAccess.Callback = DriverCallback;
|
---|
1809 |
|
---|
1810 | //
|
---|
1811 | // Locate Hii Database protocol
|
---|
1812 | //
|
---|
1813 | Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase);
|
---|
1814 | if (EFI_ERROR (Status)) {
|
---|
1815 | return Status;
|
---|
1816 | }
|
---|
1817 |
|
---|
1818 | mPrivateData->HiiDatabase = HiiDatabase;
|
---|
1819 |
|
---|
1820 | //
|
---|
1821 | // Locate HiiString protocol
|
---|
1822 | //
|
---|
1823 | Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **)&HiiString);
|
---|
1824 | if (EFI_ERROR (Status)) {
|
---|
1825 | return Status;
|
---|
1826 | }
|
---|
1827 |
|
---|
1828 | mPrivateData->HiiString = HiiString;
|
---|
1829 |
|
---|
1830 | //
|
---|
1831 | // Locate Formbrowser2 protocol
|
---|
1832 | //
|
---|
1833 | Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **)&FormBrowser2);
|
---|
1834 | if (EFI_ERROR (Status)) {
|
---|
1835 | return Status;
|
---|
1836 | }
|
---|
1837 |
|
---|
1838 | mPrivateData->FormBrowser2 = FormBrowser2;
|
---|
1839 |
|
---|
1840 | //
|
---|
1841 | // Locate ConfigRouting protocol
|
---|
1842 | //
|
---|
1843 | Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&HiiConfigRouting);
|
---|
1844 | if (EFI_ERROR (Status)) {
|
---|
1845 | return Status;
|
---|
1846 | }
|
---|
1847 |
|
---|
1848 | mPrivateData->HiiConfigRouting = HiiConfigRouting;
|
---|
1849 |
|
---|
1850 | //
|
---|
1851 | // Locate keyword handler protocol
|
---|
1852 | //
|
---|
1853 | Status = gBS->LocateProtocol (&gEfiConfigKeywordHandlerProtocolGuid, NULL, (VOID **)&HiiKeywordHandler);
|
---|
1854 | if (EFI_ERROR (Status)) {
|
---|
1855 | return Status;
|
---|
1856 | }
|
---|
1857 |
|
---|
1858 | mPrivateData->HiiKeywordHandler = HiiKeywordHandler;
|
---|
1859 |
|
---|
1860 | //
|
---|
1861 | // Locate HiiPopup protocol
|
---|
1862 | //
|
---|
1863 | Status = gBS->LocateProtocol (&gEfiHiiPopupProtocolGuid, NULL, (VOID **)&PopupHandler);
|
---|
1864 | if (EFI_ERROR (Status)) {
|
---|
1865 | return Status;
|
---|
1866 | }
|
---|
1867 |
|
---|
1868 | mPrivateData->HiiPopup = PopupHandler;
|
---|
1869 |
|
---|
1870 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
1871 | &DriverHandle[0],
|
---|
1872 | &gEfiDevicePathProtocolGuid,
|
---|
1873 | &mHiiVendorDevicePath0,
|
---|
1874 | &gEfiHiiConfigAccessProtocolGuid,
|
---|
1875 | &mPrivateData->ConfigAccess,
|
---|
1876 | NULL
|
---|
1877 | );
|
---|
1878 | ASSERT_EFI_ERROR (Status);
|
---|
1879 |
|
---|
1880 | mPrivateData->DriverHandle[0] = DriverHandle[0];
|
---|
1881 |
|
---|
1882 | //
|
---|
1883 | // Publish our HII data
|
---|
1884 | //
|
---|
1885 | HiiHandle[0] = HiiAddPackages (
|
---|
1886 | &gDriverSampleFormSetGuid,
|
---|
1887 | DriverHandle[0],
|
---|
1888 | DriverSampleStrings,
|
---|
1889 | VfrBin,
|
---|
1890 | NULL
|
---|
1891 | );
|
---|
1892 | if (HiiHandle[0] == NULL) {
|
---|
1893 | return EFI_OUT_OF_RESOURCES;
|
---|
1894 | }
|
---|
1895 |
|
---|
1896 | mPrivateData->HiiHandle[0] = HiiHandle[0];
|
---|
1897 |
|
---|
1898 | //
|
---|
1899 | // Publish another Fromset
|
---|
1900 | //
|
---|
1901 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
1902 | &DriverHandle[1],
|
---|
1903 | &gEfiDevicePathProtocolGuid,
|
---|
1904 | &mHiiVendorDevicePath1,
|
---|
1905 | &gEfiHiiConfigAccessProtocolGuid,
|
---|
1906 | &mPrivateData->ConfigAccess,
|
---|
1907 | NULL
|
---|
1908 | );
|
---|
1909 | ASSERT_EFI_ERROR (Status);
|
---|
1910 |
|
---|
1911 | mPrivateData->DriverHandle[1] = DriverHandle[1];
|
---|
1912 |
|
---|
1913 | HiiHandle[1] = HiiAddPackages (
|
---|
1914 | &gDriverSampleInventoryGuid,
|
---|
1915 | DriverHandle[1],
|
---|
1916 | DriverSampleStrings,
|
---|
1917 | InventoryBin,
|
---|
1918 | NULL
|
---|
1919 | );
|
---|
1920 | if (HiiHandle[1] == NULL) {
|
---|
1921 | DriverSampleUnload (ImageHandle);
|
---|
1922 | return EFI_OUT_OF_RESOURCES;
|
---|
1923 | }
|
---|
1924 |
|
---|
1925 | mPrivateData->HiiHandle[1] = HiiHandle[1];
|
---|
1926 |
|
---|
1927 | //
|
---|
1928 | // Update the device path string.
|
---|
1929 | //
|
---|
1930 | NewString = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL *)&mHiiVendorDevicePath0, FALSE, FALSE);
|
---|
1931 | if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), NewString, NULL) == 0) {
|
---|
1932 | DriverSampleUnload (ImageHandle);
|
---|
1933 | return EFI_OUT_OF_RESOURCES;
|
---|
1934 | }
|
---|
1935 |
|
---|
1936 | if (NewString != NULL) {
|
---|
1937 | FreePool (NewString);
|
---|
1938 | }
|
---|
1939 |
|
---|
1940 | //
|
---|
1941 | // Very simple example of how one would update a string that is already
|
---|
1942 | // in the HII database
|
---|
1943 | //
|
---|
1944 | NewString = L"700 Mhz";
|
---|
1945 |
|
---|
1946 | if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString, NULL) == 0) {
|
---|
1947 | DriverSampleUnload (ImageHandle);
|
---|
1948 | return EFI_OUT_OF_RESOURCES;
|
---|
1949 | }
|
---|
1950 |
|
---|
1951 | HiiSetString (HiiHandle[0], 0, NewString, NULL);
|
---|
1952 |
|
---|
1953 | //
|
---|
1954 | // Initialize Name/Value name String ID
|
---|
1955 | //
|
---|
1956 | mPrivateData->NameStringId[0] = STR_NAME_VALUE_VAR_NAME0;
|
---|
1957 | mPrivateData->NameStringId[1] = STR_NAME_VALUE_VAR_NAME1;
|
---|
1958 | mPrivateData->NameStringId[2] = STR_NAME_VALUE_VAR_NAME2;
|
---|
1959 |
|
---|
1960 | //
|
---|
1961 | // Initialize configuration data
|
---|
1962 | //
|
---|
1963 | Configuration = &mPrivateData->Configuration;
|
---|
1964 | ZeroMem (Configuration, sizeof (DRIVER_SAMPLE_CONFIGURATION));
|
---|
1965 |
|
---|
1966 | //
|
---|
1967 | // Try to read NV config EFI variable first
|
---|
1968 | //
|
---|
1969 | ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, DriverHandle[0]);
|
---|
1970 | ASSERT (ConfigRequestHdr != NULL);
|
---|
1971 |
|
---|
1972 | NameRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, NULL, DriverHandle[0]);
|
---|
1973 | ASSERT (NameRequestHdr != NULL);
|
---|
1974 |
|
---|
1975 | BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
|
---|
1976 | Status = gRT->GetVariable (VariableName, &gDriverSampleFormSetGuid, NULL, &BufferSize, Configuration);
|
---|
1977 | if (EFI_ERROR (Status)) {
|
---|
1978 | //
|
---|
1979 | // Store zero data Buffer Storage to EFI variable
|
---|
1980 | //
|
---|
1981 | Status = gRT->SetVariable (
|
---|
1982 | VariableName,
|
---|
1983 | &gDriverSampleFormSetGuid,
|
---|
1984 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
---|
1985 | sizeof (DRIVER_SAMPLE_CONFIGURATION),
|
---|
1986 | Configuration
|
---|
1987 | );
|
---|
1988 | if (EFI_ERROR (Status)) {
|
---|
1989 | DriverSampleUnload (ImageHandle);
|
---|
1990 | return Status;
|
---|
1991 | }
|
---|
1992 |
|
---|
1993 | //
|
---|
1994 | // EFI variable for NV config doesn't exit, we should build this variable
|
---|
1995 | // based on default values stored in IFR
|
---|
1996 | //
|
---|
1997 | ActionFlag = HiiSetToDefaults (NameRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
|
---|
1998 | if (!ActionFlag) {
|
---|
1999 | DriverSampleUnload (ImageHandle);
|
---|
2000 | return EFI_INVALID_PARAMETER;
|
---|
2001 | }
|
---|
2002 |
|
---|
2003 | ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
|
---|
2004 | if (!ActionFlag) {
|
---|
2005 | DriverSampleUnload (ImageHandle);
|
---|
2006 | return EFI_INVALID_PARAMETER;
|
---|
2007 | }
|
---|
2008 | } else {
|
---|
2009 | //
|
---|
2010 | // EFI variable does exist and Validate Current Setting
|
---|
2011 | //
|
---|
2012 | ActionFlag = HiiValidateSettings (NameRequestHdr);
|
---|
2013 | if (!ActionFlag) {
|
---|
2014 | DriverSampleUnload (ImageHandle);
|
---|
2015 | return EFI_INVALID_PARAMETER;
|
---|
2016 | }
|
---|
2017 |
|
---|
2018 | ActionFlag = HiiValidateSettings (ConfigRequestHdr);
|
---|
2019 | if (!ActionFlag) {
|
---|
2020 | DriverSampleUnload (ImageHandle);
|
---|
2021 | return EFI_INVALID_PARAMETER;
|
---|
2022 | }
|
---|
2023 | }
|
---|
2024 |
|
---|
2025 | FreePool (ConfigRequestHdr);
|
---|
2026 |
|
---|
2027 | //
|
---|
2028 | // Initialize efi varstore configuration data
|
---|
2029 | //
|
---|
2030 | VarStoreConfig = &mPrivateData->VarStoreConfig;
|
---|
2031 | ZeroMem (VarStoreConfig, sizeof (MY_EFI_VARSTORE_DATA));
|
---|
2032 |
|
---|
2033 | ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiVar, DriverHandle[0]);
|
---|
2034 | ASSERT (ConfigRequestHdr != NULL);
|
---|
2035 |
|
---|
2036 | BufferSize = sizeof (MY_EFI_VARSTORE_DATA);
|
---|
2037 | Status = gRT->GetVariable (MyEfiVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, VarStoreConfig);
|
---|
2038 | if (EFI_ERROR (Status)) {
|
---|
2039 | //
|
---|
2040 | // Store zero data to EFI variable Storage.
|
---|
2041 | //
|
---|
2042 | Status = gRT->SetVariable (
|
---|
2043 | MyEfiVar,
|
---|
2044 | &gDriverSampleFormSetGuid,
|
---|
2045 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
---|
2046 | sizeof (MY_EFI_VARSTORE_DATA),
|
---|
2047 | VarStoreConfig
|
---|
2048 | );
|
---|
2049 | if (EFI_ERROR (Status)) {
|
---|
2050 | DriverSampleUnload (ImageHandle);
|
---|
2051 | return Status;
|
---|
2052 | }
|
---|
2053 |
|
---|
2054 | //
|
---|
2055 | // EFI variable for NV config doesn't exit, we should build this variable
|
---|
2056 | // based on default values stored in IFR
|
---|
2057 | //
|
---|
2058 | ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
|
---|
2059 | if (!ActionFlag) {
|
---|
2060 | DriverSampleUnload (ImageHandle);
|
---|
2061 | return EFI_INVALID_PARAMETER;
|
---|
2062 | }
|
---|
2063 | } else {
|
---|
2064 | //
|
---|
2065 | // EFI variable does exist and Validate Current Setting
|
---|
2066 | //
|
---|
2067 | ActionFlag = HiiValidateSettings (ConfigRequestHdr);
|
---|
2068 | if (!ActionFlag) {
|
---|
2069 | DriverSampleUnload (ImageHandle);
|
---|
2070 | return EFI_INVALID_PARAMETER;
|
---|
2071 | }
|
---|
2072 | }
|
---|
2073 |
|
---|
2074 | FreePool (ConfigRequestHdr);
|
---|
2075 |
|
---|
2076 | //
|
---|
2077 | // Initialize Bits efi varstore configuration data
|
---|
2078 | //
|
---|
2079 | BitsVarStoreConfig = &mPrivateData->BitsVarStoreConfig;
|
---|
2080 | ZeroMem (BitsVarStoreConfig, sizeof (MY_EFI_BITS_VARSTORE_DATA));
|
---|
2081 |
|
---|
2082 | ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiBitVar, DriverHandle[0]);
|
---|
2083 | ASSERT (ConfigRequestHdr != NULL);
|
---|
2084 |
|
---|
2085 | BufferSize = sizeof (MY_EFI_BITS_VARSTORE_DATA);
|
---|
2086 | Status = gRT->GetVariable (MyEfiBitVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, BitsVarStoreConfig);
|
---|
2087 | if (EFI_ERROR (Status)) {
|
---|
2088 | //
|
---|
2089 | // Store zero data to EFI variable Storage.
|
---|
2090 | //
|
---|
2091 | Status = gRT->SetVariable (
|
---|
2092 | MyEfiBitVar,
|
---|
2093 | &gDriverSampleFormSetGuid,
|
---|
2094 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
---|
2095 | sizeof (MY_EFI_BITS_VARSTORE_DATA),
|
---|
2096 | BitsVarStoreConfig
|
---|
2097 | );
|
---|
2098 | if (EFI_ERROR (Status)) {
|
---|
2099 | DriverSampleUnload (ImageHandle);
|
---|
2100 | return Status;
|
---|
2101 | }
|
---|
2102 |
|
---|
2103 | //
|
---|
2104 | // EFI variable for NV config doesn't exit, we should build this variable
|
---|
2105 | // based on default values stored in IFR
|
---|
2106 | //
|
---|
2107 | ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
|
---|
2108 | if (!ActionFlag) {
|
---|
2109 | DriverSampleUnload (ImageHandle);
|
---|
2110 | return EFI_INVALID_PARAMETER;
|
---|
2111 | }
|
---|
2112 | } else {
|
---|
2113 | //
|
---|
2114 | // EFI variable does exist and Validate Current Setting
|
---|
2115 | //
|
---|
2116 | ActionFlag = HiiValidateSettings (ConfigRequestHdr);
|
---|
2117 | if (!ActionFlag) {
|
---|
2118 | DriverSampleUnload (ImageHandle);
|
---|
2119 | return EFI_INVALID_PARAMETER;
|
---|
2120 | }
|
---|
2121 | }
|
---|
2122 |
|
---|
2123 | FreePool (ConfigRequestHdr);
|
---|
2124 |
|
---|
2125 | //
|
---|
2126 | // Initialize Union efi varstore configuration data
|
---|
2127 | //
|
---|
2128 | UnionConfig = &mPrivateData->UnionConfig;
|
---|
2129 | ZeroMem (UnionConfig, sizeof (MY_EFI_UNION_DATA));
|
---|
2130 |
|
---|
2131 | ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiUnionVar, DriverHandle[0]);
|
---|
2132 | ASSERT (ConfigRequestHdr != NULL);
|
---|
2133 |
|
---|
2134 | BufferSize = sizeof (MY_EFI_UNION_DATA);
|
---|
2135 | Status = gRT->GetVariable (MyEfiUnionVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, UnionConfig);
|
---|
2136 | if (EFI_ERROR (Status)) {
|
---|
2137 | //
|
---|
2138 | // Store zero data to EFI variable Storage.
|
---|
2139 | //
|
---|
2140 | Status = gRT->SetVariable (
|
---|
2141 | MyEfiUnionVar,
|
---|
2142 | &gDriverSampleFormSetGuid,
|
---|
2143 | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
|
---|
2144 | sizeof (MY_EFI_UNION_DATA),
|
---|
2145 | UnionConfig
|
---|
2146 | );
|
---|
2147 | if (EFI_ERROR (Status)) {
|
---|
2148 | DriverSampleUnload (ImageHandle);
|
---|
2149 | return Status;
|
---|
2150 | }
|
---|
2151 |
|
---|
2152 | //
|
---|
2153 | // EFI variable for NV config doesn't exit, we should build this variable
|
---|
2154 | // based on default values stored in IFR
|
---|
2155 | //
|
---|
2156 | ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);
|
---|
2157 | if (!ActionFlag) {
|
---|
2158 | DriverSampleUnload (ImageHandle);
|
---|
2159 | return EFI_INVALID_PARAMETER;
|
---|
2160 | }
|
---|
2161 | } else {
|
---|
2162 | //
|
---|
2163 | // EFI variable does exist and Validate Current Setting
|
---|
2164 | //
|
---|
2165 | ActionFlag = HiiValidateSettings (ConfigRequestHdr);
|
---|
2166 | if (!ActionFlag) {
|
---|
2167 | DriverSampleUnload (ImageHandle);
|
---|
2168 | return EFI_INVALID_PARAMETER;
|
---|
2169 | }
|
---|
2170 | }
|
---|
2171 |
|
---|
2172 | FreePool (ConfigRequestHdr);
|
---|
2173 |
|
---|
2174 | Status = gBS->CreateEventEx (
|
---|
2175 | EVT_NOTIFY_SIGNAL,
|
---|
2176 | TPL_NOTIFY,
|
---|
2177 | EfiEventEmptyFunction,
|
---|
2178 | NULL,
|
---|
2179 | &gEfiIfrRefreshIdOpGuid,
|
---|
2180 | &mEvent
|
---|
2181 | );
|
---|
2182 | ASSERT_EFI_ERROR (Status);
|
---|
2183 |
|
---|
2184 | //
|
---|
2185 | // Example of how to use BrowserEx protocol to register HotKey.
|
---|
2186 | //
|
---|
2187 | Status = gBS->LocateProtocol (&gEdkiiFormBrowserExProtocolGuid, NULL, (VOID **)&FormBrowserEx);
|
---|
2188 | if (!EFI_ERROR (Status)) {
|
---|
2189 | //
|
---|
2190 | // First unregister the default hot key F9 and F10.
|
---|
2191 | //
|
---|
2192 | HotKey.UnicodeChar = CHAR_NULL;
|
---|
2193 | HotKey.ScanCode = SCAN_F9;
|
---|
2194 | FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);
|
---|
2195 | HotKey.ScanCode = SCAN_F10;
|
---|
2196 | FormBrowserEx->RegisterHotKey (&HotKey, 0, 0, NULL);
|
---|
2197 |
|
---|
2198 | //
|
---|
2199 | // Register the default HotKey F9 and F10 again.
|
---|
2200 | //
|
---|
2201 | HotKey.ScanCode = SCAN_F10;
|
---|
2202 | NewString = HiiGetString (mPrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_TEN_STRING), NULL);
|
---|
2203 | ASSERT (NewString != NULL);
|
---|
2204 | FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_SUBMIT, 0, NewString);
|
---|
2205 | HotKey.ScanCode = SCAN_F9;
|
---|
2206 | NewString = HiiGetString (mPrivateData->HiiHandle[0], STRING_TOKEN (FUNCTION_NINE_STRING), NULL);
|
---|
2207 | ASSERT (NewString != NULL);
|
---|
2208 | FormBrowserEx->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString);
|
---|
2209 | }
|
---|
2210 |
|
---|
2211 | //
|
---|
2212 | // In default, this driver is built into Flash device image,
|
---|
2213 | // the following code doesn't run.
|
---|
2214 | //
|
---|
2215 |
|
---|
2216 | //
|
---|
2217 | // Example of how to display only the item we sent to HII
|
---|
2218 | // When this driver is not built into Flash device image,
|
---|
2219 | // it need to call SendForm to show front page by itself.
|
---|
2220 | //
|
---|
2221 | if (DISPLAY_ONLY_MY_ITEM <= 1) {
|
---|
2222 | //
|
---|
2223 | // Have the browser pull out our copy of the data, and only display our data
|
---|
2224 | //
|
---|
2225 | Status = FormBrowser2->SendForm (
|
---|
2226 | FormBrowser2,
|
---|
2227 | &(HiiHandle[DISPLAY_ONLY_MY_ITEM]),
|
---|
2228 | 1,
|
---|
2229 | NULL,
|
---|
2230 | 0,
|
---|
2231 | NULL,
|
---|
2232 | NULL
|
---|
2233 | );
|
---|
2234 |
|
---|
2235 | HiiRemovePackages (HiiHandle[0]);
|
---|
2236 |
|
---|
2237 | HiiRemovePackages (HiiHandle[1]);
|
---|
2238 | }
|
---|
2239 |
|
---|
2240 | return EFI_SUCCESS;
|
---|
2241 | }
|
---|
2242 |
|
---|
2243 | /**
|
---|
2244 | Unloads the application and its installed protocol.
|
---|
2245 |
|
---|
2246 | @param[in] ImageHandle Handle that identifies the image to be unloaded.
|
---|
2247 |
|
---|
2248 | @retval EFI_SUCCESS The image has been unloaded.
|
---|
2249 | **/
|
---|
2250 | EFI_STATUS
|
---|
2251 | EFIAPI
|
---|
2252 | DriverSampleUnload (
|
---|
2253 | IN EFI_HANDLE ImageHandle
|
---|
2254 | )
|
---|
2255 | {
|
---|
2256 | UINTN Index;
|
---|
2257 |
|
---|
2258 | ASSERT (mPrivateData != NULL);
|
---|
2259 |
|
---|
2260 | if (DriverHandle[0] != NULL) {
|
---|
2261 | gBS->UninstallMultipleProtocolInterfaces (
|
---|
2262 | DriverHandle[0],
|
---|
2263 | &gEfiDevicePathProtocolGuid,
|
---|
2264 | &mHiiVendorDevicePath0,
|
---|
2265 | &gEfiHiiConfigAccessProtocolGuid,
|
---|
2266 | &mPrivateData->ConfigAccess,
|
---|
2267 | NULL
|
---|
2268 | );
|
---|
2269 | DriverHandle[0] = NULL;
|
---|
2270 | }
|
---|
2271 |
|
---|
2272 | if (DriverHandle[1] != NULL) {
|
---|
2273 | gBS->UninstallMultipleProtocolInterfaces (
|
---|
2274 | DriverHandle[1],
|
---|
2275 | &gEfiDevicePathProtocolGuid,
|
---|
2276 | &mHiiVendorDevicePath1,
|
---|
2277 | &gEfiHiiConfigAccessProtocolGuid,
|
---|
2278 | &mPrivateData->ConfigAccess,
|
---|
2279 | NULL
|
---|
2280 | );
|
---|
2281 | DriverHandle[1] = NULL;
|
---|
2282 | }
|
---|
2283 |
|
---|
2284 | if (mPrivateData->HiiHandle[0] != NULL) {
|
---|
2285 | HiiRemovePackages (mPrivateData->HiiHandle[0]);
|
---|
2286 | }
|
---|
2287 |
|
---|
2288 | if (mPrivateData->HiiHandle[1] != NULL) {
|
---|
2289 | HiiRemovePackages (mPrivateData->HiiHandle[1]);
|
---|
2290 | }
|
---|
2291 |
|
---|
2292 | for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
|
---|
2293 | if (mPrivateData->NameValueName[Index] != NULL) {
|
---|
2294 | FreePool (mPrivateData->NameValueName[Index]);
|
---|
2295 | }
|
---|
2296 | }
|
---|
2297 |
|
---|
2298 | FreePool (mPrivateData);
|
---|
2299 | mPrivateData = NULL;
|
---|
2300 |
|
---|
2301 | gBS->CloseEvent (mEvent);
|
---|
2302 |
|
---|
2303 | return EFI_SUCCESS;
|
---|
2304 | }
|
---|