3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
30 #include <Protocol/Print.h>
31 #include <Protocol/SimpleTextOut.h>
32 #include <Protocol/SimpleTextIn.h>
33 #include <Protocol/FormBrowser2.h>
34 #include <Protocol/DevicePath.h>
35 #include <Protocol/UnicodeCollation.h>
36 #include <Protocol/HiiConfigAccess.h>
37 #include <Protocol/HiiConfigRouting.h>
38 #include <Protocol/HiiDatabase.h>
39 #include <Protocol/HiiString.h>
41 #include <MdeModuleHii.h>
43 #include <Library/GraphicsLib.h>
44 #include <Library/PrintLib.h>
45 #include <Library/DebugLib.h>
46 #include <Library/BaseMemoryLib.h>
47 #include <Library/UefiRuntimeServicesTableLib.h>
48 #include <Library/UefiDriverEntryPoint.h>
49 #include <Library/UefiBootServicesTableLib.h>
50 #include <Library/BaseLib.h>
51 #include <Library/MemoryAllocationLib.h>
52 #include <Library/IfrSupportLib.h>
53 #include <Library/ExtendedIfrSupportLib.h>
54 #include <Library/HiiLib.h>
55 #include <Library/ExtendedHiiLib.h>
60 // This is the generated header file which includes whatever needs to be exported (strings + IFR)
63 extern UINT8 SetupBrowserStrings
[];
68 #define BANNER_HEIGHT 6
69 #define BANNER_COLUMNS 3
71 #define FRONT_PAGE_HEADER_HEIGHT 6
72 #define NONE_FRONT_PAGE_HEADER_HEIGHT 3
73 #define LEFT_SKIPPED_COLUMNS 4
74 #define FOOTER_HEIGHT 4
75 #define STATUS_BAR_HEIGHT 1
76 #define SCROLL_ARROW_HEIGHT 1
77 #define POPUP_PAD_SPACE_COUNT 5
78 #define POPUP_FRAME_WIDTH 2
81 // Definition for function key setting
83 #define NONE_FUNCTION_KEY_SETTING 0
84 #define DEFAULT_FUNCTION_KEY_SETTING (FUNCTION_ONE | FUNCTION_TWO | FUNCTION_NINE | FUNCTION_TEN)
86 #define FUNCTION_ONE (1 << 0)
87 #define FUNCTION_TWO (1 << 1)
88 #define FUNCTION_NINE (1 << 2)
89 #define FUNCTION_TEN (1 << 3)
94 } FUNCTIION_KEY_SETTING
;
97 // Character definitions
99 #define CHAR_SPACE 0x0020
100 #define UPPER_LOWER_CASE_OFFSET 0x20
105 #define ONE_SECOND 10000000
108 // Display definitions
110 #define LEFT_HYPER_DELIMITER L'<'
111 #define RIGHT_HYPER_DELIMITER L'>'
113 #define LEFT_ONEOF_DELIMITER L'<'
114 #define RIGHT_ONEOF_DELIMITER L'>'
116 #define LEFT_NUMERIC_DELIMITER L'['
117 #define RIGHT_NUMERIC_DELIMITER L']'
119 #define LEFT_CHECKBOX_DELIMITER L'['
120 #define RIGHT_CHECKBOX_DELIMITER L']'
122 #define CHECK_ON L'X'
123 #define CHECK_OFF L' '
125 #define TIME_SEPARATOR L':'
126 #define DATE_SEPARATOR L'/'
128 #define YES_ANSWER L'Y'
129 #define NO_ANSWER L'N'
132 // This is the Input Error Message
134 #define INPUT_ERROR 1
137 // This is the NV RAM update required Message
139 #define NV_UPDATE_REQUIRED 2
142 // Refresh the Status Bar with flags
144 #define REFRESH_STATUS_BAR 0xff
147 // Incremental string lenght of ConfigRequest
149 #define CONFIG_REQUEST_STRING_INCREMENTAL 1024
152 // HII value compare result
154 #define HII_VALUE_UNDEFINED 0
155 #define HII_VALUE_EQUAL 1
156 #define HII_VALUE_LESS_THAN 2
157 #define HII_VALUE_GREATER_THAN 3
160 // Incremental size of stack for expression
162 #define EXPRESSION_STACK_SIZE_INCREMENT 0x100
165 #define EFI_SPECIFICATION_ERRATA_VERSION 0
167 #define EFI_IFR_SPECIFICATION_VERSION \
168 ((((EFI_SPECIFICATION_VERSION) >> 8) & 0xff00) | \
169 (((EFI_SPECIFICATION_VERSION) & 0xf) << 4) | \
170 ((EFI_SPECIFICATION_ERRATA_VERSION) & 0xf))
172 #define SETUP_DRIVER_SIGNATURE EFI_SIGNATURE_32 ('F', 'B', 'D', 'V')
181 EFI_FORM_BROWSER2_PROTOCOL FormBrowser2
;
182 EFI_PRINT_PROTOCOL Print
;
184 } SETUP_DRIVER_PRIVATE_DATA
;
187 EFI_STRING_ID Banner
[BANNER_HEIGHT
][BANNER_COLUMNS
];
191 // IFR relative definition
193 #define EFI_HII_EXPRESSION_INCONSISTENT_IF 0
194 #define EFI_HII_EXPRESSION_NO_SUBMIT_IF 1
195 #define EFI_HII_EXPRESSION_GRAY_OUT_IF 2
196 #define EFI_HII_EXPRESSION_SUPPRESS_IF 3
197 #define EFI_HII_EXPRESSION_DISABLE_IF 4
198 #define EFI_HII_EXPRESSION_VALUE 5
199 #define EFI_HII_EXPRESSION_RULE 6
201 #define EFI_HII_VARSTORE_BUFFER 0
202 #define EFI_HII_VARSTORE_NAME_VALUE 1
203 #define EFI_HII_VARSTORE_EFI_VARIABLE 2
205 #define FORM_INCONSISTENT_VALIDATION 0
206 #define FORM_NO_SUBMIT_VALIDATION 1
210 EFI_IFR_TYPE_VALUE Value
;
213 #define NAME_VALUE_NODE_SIGNATURE EFI_SIGNATURE_32 ('N', 'V', 'S', 'T')
223 #define NAME_VALUE_NODE_FROM_LINK(a) CR (a, NAME_VALUE_NODE, Link, NAME_VALUE_NODE_SIGNATURE)
225 #define FORMSET_STORAGE_SIGNATURE EFI_SIGNATURE_32 ('F', 'S', 'T', 'G')
231 UINT8 Type
; // Storage type
236 CHAR16
*Name
; // For EFI_IFR_VARSTORE
239 UINT8
*EditBuffer
; // Edit copy for Buffer Storage
241 LIST_ENTRY NameValueListHead
; // List of NAME_VALUE_NODE
243 UINT32 Attributes
; // For EFI_IFR_VARSTORE_EFI: EFI Variable attribute
245 CHAR16
*ConfigHdr
; // <ConfigHdr>
246 CHAR16
*ConfigRequest
; // <ConfigRequest> = <ConfigHdr> + <RequestElement>
247 UINTN ElementCount
; // Number of <RequestElement> in the <ConfigRequest>
248 UINTN SpareStrLen
; // Spare length of ConfigRequest string buffer
251 #define FORMSET_STORAGE_FROM_LINK(a) CR (a, FORMSET_STORAGE, Link, FORMSET_STORAGE_SIGNATURE)
253 #define EXPRESSION_OPCODE_SIGNATURE EFI_SIGNATURE_32 ('E', 'X', 'O', 'P')
261 UINT8 Format
; // For EFI_IFR_TO_STRING, EFI_IFR_FIND
262 UINT8 Flags
; // For EFI_IFR_SPAN
263 UINT8 RuleId
; // For EFI_IFR_RULE_REF
265 EFI_HII_VALUE Value
; // For EFI_IFR_EQ_ID_VAL, EFI_IFR_UINT64, EFI_IFR_UINT32, EFI_IFR_UINT16, EFI_IFR_UINT8, EFI_IFR_STRING_REF1
267 EFI_QUESTION_ID QuestionId
; // For EFI_IFR_EQ_ID_ID, EFI_IFR_EQ_ID_LIST, EFI_IFR_QUESTION_REF1
268 EFI_QUESTION_ID QuestionId2
;
270 UINT16 ListLength
; // For EFI_IFR_EQ_ID_LIST
273 EFI_STRING_ID DevicePath
; // For EFI_IFR_QUESTION_REF3_2, EFI_IFR_QUESTION_REF3_3
277 #define EXPRESSION_OPCODE_FROM_LINK(a) CR (a, EXPRESSION_OPCODE, Link, EXPRESSION_OPCODE_SIGNATURE)
279 #define FORM_EXPRESSION_SIGNATURE EFI_SIGNATURE_32 ('F', 'E', 'X', 'P')
285 UINT8 Type
; // Type for this expression
287 UINT8 RuleId
; // For EFI_IFR_RULE only
288 EFI_STRING_ID Error
; // For EFI_IFR_NO_SUBMIT_IF, EFI_IFR_INCONSISTENT_IF only
290 EFI_HII_VALUE Result
; // Expression evaluation result
292 LIST_ENTRY OpCodeListHead
; // OpCodes consist of this expression (EXPRESSION_OPCODE)
295 #define FORM_EXPRESSION_FROM_LINK(a) CR (a, FORM_EXPRESSION, Link, FORM_EXPRESSION_SIGNATURE)
297 #define QUESTION_DEFAULT_SIGNATURE EFI_SIGNATURE_32 ('Q', 'D', 'F', 'T')
304 EFI_HII_VALUE Value
; // Default value
306 FORM_EXPRESSION
*ValueExpression
; // Not-NULL indicates default value is provided by EFI_IFR_VALUE
309 #define QUESTION_DEFAULT_FROM_LINK(a) CR (a, QUESTION_DEFAULT, Link, QUESTION_DEFAULT_SIGNATURE)
311 #define QUESTION_OPTION_SIGNATURE EFI_SIGNATURE_32 ('Q', 'O', 'P', 'T')
320 EFI_IMAGE_ID ImageId
;
322 FORM_EXPRESSION
*SuppressExpression
; // Non-NULL indicates nested inside of SuppressIf
325 #define QUESTION_OPTION_FROM_LINK(a) CR (a, QUESTION_OPTION, Link, QUESTION_OPTION_SIGNATURE)
327 #define FORM_BROWSER_STATEMENT_SIGNATURE EFI_SIGNATURE_32 ('F', 'S', 'T', 'A')
332 UINT8 Operand
; // The operand (first byte) of this Statement or Question
337 EFI_STRING_ID Prompt
;
339 EFI_STRING_ID TextTwo
; // For EFI_IFR_TEXT
344 EFI_QUESTION_ID QuestionId
; // The value of zero is reserved
345 EFI_VARSTORE_ID VarStoreId
; // A value of zero indicates no variable storage
346 FORMSET_STORAGE
*Storage
;
348 EFI_STRING_ID VarName
;
353 CHAR16
*VariableName
; // Name/Value or EFI Variable name
354 CHAR16
*BlockName
; // Buffer storage block name: "OFFSET=...WIDTH=..."
356 EFI_HII_VALUE HiiValue
; // Edit copy for checkbox, numberic, oneof
357 UINT8
*BufferValue
; // Edit copy for string, password, orderedlist
360 // OpCode specific members
362 UINT8 Flags
; // for EFI_IFR_CHECKBOX, EFI_IFR_DATE, EFI_IFR_NUMERIC, EFI_IFR_ONE_OF,
363 // EFI_IFR_ORDERED_LIST, EFI_IFR_STRING,EFI_IFR_SUBTITLE,EFI_IFR_TIME, EFI_IFR_BANNER
364 UINT8 MaxContainers
; // for EFI_IFR_ORDERED_LIST
366 UINT16 BannerLineNumber
; // for EFI_IFR_BANNER, 1-based line number
367 EFI_STRING_ID QuestionConfig
; // for EFI_IFR_ACTION, if 0 then no configuration string will be processed
369 UINT64 Minimum
; // for EFI_IFR_ONE_OF/EFI_IFR_NUMERIC, it's Min/Max value
370 UINT64 Maximum
; // for EFI_IFR_STRING/EFI_IFR_PASSWORD, it's Min/Max length
373 EFI_DEFAULT_ID DefaultId
; // for EFI_IFR_RESET_BUTTON
374 EFI_FORM_ID RefFormId
; // for EFI_IFR_REF
375 EFI_QUESTION_ID RefQuestionId
; // for EFI_IFR_REF2
376 EFI_GUID RefFormSetId
; // for EFI_IFR_REF3
377 EFI_STRING_ID RefDevicePath
; // for EFI_IFR_REF4
380 // Get from IFR parsing
382 FORM_EXPRESSION
*ValueExpression
; // nested EFI_IFR_VALUE, provide Question value and indicate Question is ReadOnly
383 LIST_ENTRY DefaultListHead
; // nested EFI_IFR_DEFAULT list (QUESTION_DEFAULT), provide default values
384 LIST_ENTRY OptionListHead
; // nested EFI_IFR_ONE_OF_OPTION list (QUESTION_OPTION)
386 EFI_IMAGE_ID ImageId
; // nested EFI_IFR_IMAGE
387 UINT8 RefreshInterval
; // nested EFI_IFR_REFRESH, refresh interval(in seconds) for Question value, 0 means no refresh
388 BOOLEAN InSubtitle
; // nesting inside of EFI_IFR_SUBTITLE
390 LIST_ENTRY InconsistentListHead
;// nested inconsistent expression list (FORM_EXPRESSION)
391 LIST_ENTRY NoSubmitListHead
; // nested nosubmit expression list (FORM_EXPRESSION)
392 FORM_EXPRESSION
*GrayOutExpression
; // nesting inside of GrayOutIf
393 FORM_EXPRESSION
*SuppressExpression
; // nesting inside of SuppressIf
395 } FORM_BROWSER_STATEMENT
;
397 #define FORM_BROWSER_STATEMENT_FROM_LINK(a) CR (a, FORM_BROWSER_STATEMENT, Link, FORM_BROWSER_STATEMENT_SIGNATURE)
399 #define FORM_BROWSER_FORM_SIGNATURE EFI_SIGNATURE_32 ('F', 'F', 'R', 'M')
406 EFI_STRING_ID FormTitle
;
408 EFI_IMAGE_ID ImageId
;
410 LIST_ENTRY ExpressionListHead
; // List of Expressions (FORM_EXPRESSION)
411 LIST_ENTRY StatementListHead
; // List of Statements and Questions (FORM_BROWSER_STATEMENT)
414 #define FORM_BROWSER_FORM_FROM_LINK(a) CR (a, FORM_BROWSER_FORM, Link, FORM_BROWSER_FORM_SIGNATURE)
416 #define FORMSET_DEFAULTSTORE_SIGNATURE EFI_SIGNATURE_32 ('F', 'D', 'F', 'S')
423 EFI_STRING_ID DefaultName
;
424 } FORMSET_DEFAULTSTORE
;
426 #define FORMSET_DEFAULTSTORE_FROM_LINK(a) CR (a, FORMSET_DEFAULTSTORE, Link, FORMSET_DEFAULTSTORE_SIGNATURE)
429 EFI_HII_HANDLE HiiHandle
;
430 EFI_HANDLE DriverHandle
;
431 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
432 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
434 UINTN IfrBinaryLength
;
435 UINT8
*IfrBinaryData
;
438 EFI_STRING_ID FormSetTitle
;
442 EFI_IMAGE_ID ImageId
;
444 FORM_BROWSER_STATEMENT
*StatementBuffer
; // Buffer for all Statements and Questions
445 EXPRESSION_OPCODE
*ExpressionBuffer
; // Buffer for all Expression OpCode
447 LIST_ENTRY StorageListHead
; // Storage list (FORMSET_STORAGE)
448 LIST_ENTRY DefaultStoreListHead
; // DefaultStore list (FORMSET_DEFAULTSTORE)
449 LIST_ENTRY FormListHead
; // Form list (FORM_BROWSER_FORM)
450 } FORM_BROWSER_FORMSET
;
453 extern EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
454 extern EFI_HII_STRING_PROTOCOL
*mHiiString
;
455 extern EFI_HII_CONFIG_ROUTING_PROTOCOL
*mHiiConfigRouting
;
457 extern BANNER_DATA
*BannerData
;
458 extern EFI_HII_HANDLE FrontPageHandle
;
459 extern UINTN gClassOfVfr
;
460 extern UINTN gFunctionKeySetting
;
461 extern BOOLEAN gResetRequired
;
462 extern BOOLEAN gNvUpdateRequired
;
463 extern EFI_HII_HANDLE gHiiHandle
;
464 extern BOOLEAN gFirstIn
;
465 extern UINT16 gDirection
;
466 extern EFI_SCREEN_DESCRIPTOR gScreenDimensions
;
467 extern BOOLEAN gUpArrow
;
468 extern BOOLEAN gDownArrow
;
471 // Browser Global Strings
473 extern CHAR16
*gFunctionOneString
;
474 extern CHAR16
*gFunctionTwoString
;
475 extern CHAR16
*gFunctionNineString
;
476 extern CHAR16
*gFunctionTenString
;
477 extern CHAR16
*gEnterString
;
478 extern CHAR16
*gEnterCommitString
;
479 extern CHAR16
*gEscapeString
;
480 extern CHAR16
*gSaveFailed
;
481 extern CHAR16
*gMoveHighlight
;
482 extern CHAR16
*gMakeSelection
;
483 extern CHAR16
*gDecNumericInput
;
484 extern CHAR16
*gHexNumericInput
;
485 extern CHAR16
*gToggleCheckBox
;
486 extern CHAR16
*gPromptForData
;
487 extern CHAR16
*gPromptForPassword
;
488 extern CHAR16
*gPromptForNewPassword
;
489 extern CHAR16
*gConfirmPassword
;
490 extern CHAR16
*gConfirmError
;
491 extern CHAR16
*gPassowordInvalid
;
492 extern CHAR16
*gPressEnter
;
493 extern CHAR16
*gEmptyString
;
494 extern CHAR16
*gAreYouSure
;
495 extern CHAR16
*gYesResponse
;
496 extern CHAR16
*gNoResponse
;
497 extern CHAR16
*gMiniString
;
498 extern CHAR16
*gPlusString
;
499 extern CHAR16
*gMinusString
;
500 extern CHAR16
*gAdjustNumber
;
502 extern CHAR16 gPromptBlockWidth
;
503 extern CHAR16 gOptionBlockWidth
;
504 extern CHAR16 gHelpBlockWidth
;
506 extern EFI_GUID gZeroGuid
;
507 extern EFI_GUID gTianoHiiIfrGuid
;
510 // Global Procedure Defines
513 InitializeBrowserStrings (
564 IN FORM_BROWSER_FORMSET
*FormSet
570 IN OUT FORM_BROWSER_FORMSET
*FormSet
583 IN EFI_HII_HANDLE HiiHandle
589 IN EFI_STRING_ID StringId
,
590 IN EFI_HII_HANDLE HiiHandle
595 IN EFI_STRING_ID Token
,
596 IN EFI_HII_HANDLE HiiHandle
602 IN UINTN RequestedWidth
,
603 IN UINTN NumberOfLines
,
604 IN CHAR16
**ArrayOfStrings
610 IN UINTN NumberOfLines
,
612 IN UINTN MaximumStringSize
,
613 OUT CHAR16
*StringBuffer
,
614 OUT EFI_INPUT_KEY
*KeyValue
,
622 IN FORM_BROWSER_FORMSET
*FormSet
,
623 IN FORM_BROWSER_FORM
*Form
,
624 IN OUT FORM_BROWSER_STATEMENT
*Question
,
631 IN FORM_BROWSER_FORMSET
*FormSet
,
632 IN FORM_BROWSER_FORM
*Form
,
633 IN OUT FORM_BROWSER_STATEMENT
*Question
,
640 IN FORM_BROWSER_FORMSET
*FormSet
,
641 IN FORM_BROWSER_FORM
*Form
,
642 IN FORM_BROWSER_STATEMENT
*Question
,
649 IN FORM_BROWSER_FORMSET
*FormSet
,
650 IN FORM_BROWSER_FORM
*Form
656 IN FORM_BROWSER_FORMSET
*FormSet
,
657 IN FORM_BROWSER_FORM
*Form
,
658 IN FORM_BROWSER_STATEMENT
*Question
,
664 InitializeCurrentSetting (
665 IN OUT FORM_BROWSER_FORMSET
*FormSet
671 IN EFI_HII_HANDLE Handle
,
672 IN OUT EFI_GUID
*FormSetGuid
,
673 OUT FORM_BROWSER_FORMSET
*FormSet
679 IN FORM_BROWSER_FORMSET
*FormSet
,
680 IN FORM_BROWSER_FORM
*Form
,
687 IN FORM_BROWSER_FORMSET
*FormSet
,
688 IN FORM_BROWSER_FORM
*Form
693 StorageToConfigResp (
694 IN FORMSET_STORAGE
*Storage
,
695 IN CHAR16
**ConfigResp
700 ConfigRespToStorage (
701 IN FORMSET_STORAGE
*Storage
,
702 IN CHAR16
*ConfigResp
708 IN FORM_BROWSER_FORMSET
*FormSet
,
709 IN FORMSET_STORAGE
*Storage
715 IN EFI_HII_HANDLE Handle
,
716 IN OUT EFI_GUID
*FormSetGuid
,
717 OUT UINTN
*BinaryLength
,
718 OUT UINT8
**BinaryData
725 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
726 IN EFI_HII_HANDLE
*Handles
,
727 IN UINTN HandleCount
,
728 IN EFI_GUID
*FormSetGuid
, OPTIONAL
729 IN UINT16 FormId
, OPTIONAL
730 IN CONST EFI_SCREEN_DESCRIPTOR
*ScreenDimensions
, OPTIONAL
731 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest OPTIONAL
738 IN CONST EFI_FORM_BROWSER2_PROTOCOL
*This
,
739 IN OUT UINTN
*ResultsDataSize
,
740 IN OUT EFI_STRING ResultsData
,
741 IN BOOLEAN RetrieveData
,
742 IN CONST EFI_GUID
*VariableGuid
, OPTIONAL
743 IN CONST CHAR16
*VariableName OPTIONAL