PageRenderTime 51ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/EdkCompatibilityPkg/Sample/Tools/Source/HiiPack/IfrParse.c

https://bitbucket.org/incubaid/edk2
C | 2533 lines | 1333 code | 100 blank | 1100 comment | 138 complexity | 6d6eb356b04e0a7607be43f995d28989 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*++
  2. Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
  3. This program and the accompanying materials
  4. are licensed and made available under the terms and conditions of the BSD License
  5. which accompanies this distribution. The full text of the license may be found at
  6. http://opensource.org/licenses/bsd-license.php
  7. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  9. Module Name:
  10. IfrParse.c
  11. Abstract:
  12. Routines for parsing and managing HII IFR packs.
  13. --*/
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include "Tiano.h"
  18. #include "EfiUtilityMsgs.h"
  19. #include "EfiInternalFormRepresentation.h"
  20. #include "Hii.h"
  21. #include "IfrParse.h"
  22. #include "HiiPack.h"
  23. typedef struct _VARIABLE_STORE_ENTRY {
  24. struct _VARIABLE_STORE_ENTRY *Next;
  25. CHAR8 VarName[MAX_VARIABLE_NAME];
  26. char *VarBuffer;
  27. int VarBufferSize;
  28. EFI_HII_VARIABLE_PACK *VarPack;
  29. int VarPackSize;
  30. } VARIABLE_STORE_ENTRY;
  31. typedef STATUS (*IFR_PARSE_FUNCTION) (IFR_PARSE_CONTEXT * Context);
  32. typedef struct {
  33. INT8 *Name;
  34. INT32 Size;
  35. IFR_PARSE_FUNCTION Parse;
  36. } IFR_PARSE_TABLE_ENTRY;
  37. static
  38. STATUS
  39. IfrParse01 (
  40. IFR_PARSE_CONTEXT *Context
  41. );
  42. static
  43. STATUS
  44. IfrParse02 (
  45. IFR_PARSE_CONTEXT *Context
  46. );
  47. static
  48. STATUS
  49. IfrParse03 (
  50. IFR_PARSE_CONTEXT *Context
  51. );
  52. static
  53. STATUS
  54. IfrParse05 (
  55. IFR_PARSE_CONTEXT *Context
  56. );
  57. static
  58. STATUS
  59. IfrParse06 (
  60. IFR_PARSE_CONTEXT *Context
  61. );
  62. static
  63. STATUS
  64. IfrParse07 (
  65. IFR_PARSE_CONTEXT *Context
  66. );
  67. static
  68. STATUS
  69. IfrParse08 (
  70. IFR_PARSE_CONTEXT *Context
  71. );
  72. static
  73. STATUS
  74. IfrParse09 (
  75. IFR_PARSE_CONTEXT *Context
  76. );
  77. static
  78. STATUS
  79. IfrParse0A (
  80. IFR_PARSE_CONTEXT *Context
  81. );
  82. static
  83. STATUS
  84. IfrParse0B (
  85. IFR_PARSE_CONTEXT *Context
  86. );
  87. static
  88. STATUS
  89. IfrParse0C (
  90. IFR_PARSE_CONTEXT *Context
  91. );
  92. static
  93. STATUS
  94. IfrParse0D (
  95. IFR_PARSE_CONTEXT *Context
  96. );
  97. static
  98. STATUS
  99. IfrParse0E (
  100. IFR_PARSE_CONTEXT *Context
  101. );
  102. static
  103. STATUS
  104. IfrParse0F (
  105. IFR_PARSE_CONTEXT *Context
  106. );
  107. static
  108. STATUS
  109. IfrParse10 (
  110. IFR_PARSE_CONTEXT *Context
  111. );
  112. static
  113. STATUS
  114. IfrParse11 (
  115. IFR_PARSE_CONTEXT *Context
  116. );
  117. static
  118. STATUS
  119. IfrParse12 (
  120. IFR_PARSE_CONTEXT *Context
  121. );
  122. static
  123. STATUS
  124. IfrParse13 (
  125. IFR_PARSE_CONTEXT *Context
  126. );
  127. static
  128. STATUS
  129. IfrParse14 (
  130. IFR_PARSE_CONTEXT *Context
  131. );
  132. static
  133. STATUS
  134. IfrParse15 (
  135. IFR_PARSE_CONTEXT *Context
  136. );
  137. static
  138. STATUS
  139. IfrParse16 (
  140. IFR_PARSE_CONTEXT *Context
  141. );
  142. static
  143. STATUS
  144. IfrParse17 (
  145. IFR_PARSE_CONTEXT *Context
  146. );
  147. static
  148. STATUS
  149. IfrParse18 (
  150. IFR_PARSE_CONTEXT *Context
  151. );
  152. static
  153. STATUS
  154. IfrParse19 (
  155. IFR_PARSE_CONTEXT *Context
  156. );
  157. static
  158. STATUS
  159. IfrParse1A (
  160. IFR_PARSE_CONTEXT *Context
  161. );
  162. static
  163. STATUS
  164. IfrParse1B (
  165. IFR_PARSE_CONTEXT *Context
  166. );
  167. static
  168. STATUS
  169. IfrParse1C (
  170. IFR_PARSE_CONTEXT *Context
  171. );
  172. static
  173. STATUS
  174. IfrParse1D (
  175. IFR_PARSE_CONTEXT *Context
  176. );
  177. static
  178. STATUS
  179. IfrParse1E (
  180. IFR_PARSE_CONTEXT *Context
  181. );
  182. static
  183. STATUS
  184. IfrParse1F (
  185. IFR_PARSE_CONTEXT *Context
  186. );
  187. static
  188. STATUS
  189. IfrParse20 (
  190. IFR_PARSE_CONTEXT *Context
  191. );
  192. static
  193. STATUS
  194. IfrParse21 (
  195. IFR_PARSE_CONTEXT *Context
  196. );
  197. static
  198. STATUS
  199. IfrParse22 (
  200. IFR_PARSE_CONTEXT *Context
  201. );
  202. static
  203. STATUS
  204. IfrParse23 (
  205. IFR_PARSE_CONTEXT *Context
  206. );
  207. static
  208. STATUS
  209. IfrParse24 (
  210. IFR_PARSE_CONTEXT *Context
  211. );
  212. static
  213. STATUS
  214. IfrParse25 (
  215. IFR_PARSE_CONTEXT *Context
  216. );
  217. static
  218. STATUS
  219. IfrParse26 (
  220. IFR_PARSE_CONTEXT *Context
  221. );
  222. static
  223. STATUS
  224. IfrParse27 (
  225. IFR_PARSE_CONTEXT *Context
  226. );
  227. static
  228. STATUS
  229. IfrParse28 (
  230. IFR_PARSE_CONTEXT *Context
  231. );
  232. static
  233. STATUS
  234. IfrParse29 (
  235. IFR_PARSE_CONTEXT *Context
  236. );
  237. static
  238. STATUS
  239. IfrParse2A (
  240. IFR_PARSE_CONTEXT *Context
  241. );
  242. static const IFR_PARSE_TABLE_ENTRY mIfrParseTable[] = {
  243. {
  244. 0,
  245. 0,
  246. NULL
  247. }, // invalid
  248. {
  249. "EFI_IFR_FORM",
  250. sizeof (EFI_IFR_FORM),
  251. IfrParse01
  252. },
  253. {
  254. "EFI_IFR_SUBTITLE",
  255. sizeof (EFI_IFR_SUBTITLE),
  256. IfrParse02
  257. },
  258. {
  259. "EFI_IFR_TEXT",
  260. -6,
  261. IfrParse03
  262. }, // sizeof (EFI_IFR_TEXT) },
  263. {
  264. "unused 0x04 opcode",
  265. 0,
  266. NULL
  267. }, // EFI_IFR_GRAPHIC_OP
  268. {
  269. "EFI_IFR_ONE_OF",
  270. sizeof (EFI_IFR_ONE_OF),
  271. IfrParse05
  272. },
  273. {
  274. "EFI_IFR_CHECK_BOX",
  275. sizeof (EFI_IFR_CHECK_BOX),
  276. IfrParse06
  277. },
  278. {
  279. "EFI_IFR_NUMERIC",
  280. sizeof (EFI_IFR_NUMERIC),
  281. IfrParse07
  282. },
  283. {
  284. "EFI_IFR_PASSWORD",
  285. sizeof (EFI_IFR_PASSWORD),
  286. IfrParse08
  287. },
  288. {
  289. "EFI_IFR_ONE_OF_OPTION",
  290. sizeof (EFI_IFR_ONE_OF_OPTION),
  291. IfrParse09
  292. },
  293. {
  294. "EFI_IFR_SUPPRESS",
  295. sizeof (EFI_IFR_SUPPRESS),
  296. IfrParse0A
  297. },
  298. {
  299. "EFI_IFR_END_FORM",
  300. sizeof (EFI_IFR_END_FORM),
  301. IfrParse0B
  302. },
  303. {
  304. "EFI_IFR_HIDDEN",
  305. sizeof (EFI_IFR_HIDDEN),
  306. IfrParse0C
  307. },
  308. {
  309. "EFI_IFR_END_FORM_SET",
  310. sizeof (EFI_IFR_END_FORM_SET),
  311. IfrParse0D
  312. },
  313. {
  314. "EFI_IFR_FORM_SET",
  315. sizeof (EFI_IFR_FORM_SET),
  316. IfrParse0E
  317. },
  318. {
  319. "EFI_IFR_REF",
  320. sizeof (EFI_IFR_REF),
  321. IfrParse0F
  322. },
  323. {
  324. "EFI_IFR_END_ONE_OF",
  325. sizeof (EFI_IFR_END_ONE_OF),
  326. IfrParse10
  327. },
  328. {
  329. "EFI_IFR_INCONSISTENT",
  330. sizeof (EFI_IFR_INCONSISTENT),
  331. IfrParse11
  332. },
  333. {
  334. "EFI_IFR_EQ_ID_VAL",
  335. sizeof (EFI_IFR_EQ_ID_VAL),
  336. IfrParse12
  337. },
  338. {
  339. "EFI_IFR_EQ_ID_ID",
  340. sizeof (EFI_IFR_EQ_ID_ID),
  341. IfrParse13
  342. },
  343. {
  344. "EFI_IFR_EQ_ID_LIST",
  345. -(int) (sizeof (EFI_IFR_EQ_ID_LIST)),
  346. IfrParse14
  347. },
  348. {
  349. "EFI_IFR_AND",
  350. sizeof (EFI_IFR_AND),
  351. IfrParse15
  352. },
  353. {
  354. "EFI_IFR_OR",
  355. sizeof (EFI_IFR_OR),
  356. IfrParse16
  357. },
  358. {
  359. "EFI_IFR_NOT",
  360. sizeof (EFI_IFR_NOT),
  361. IfrParse17
  362. },
  363. {
  364. "EFI_IFR_END_IF",
  365. sizeof (EFI_IFR_END_IF),
  366. IfrParse18
  367. },
  368. {
  369. "EFI_IFR_GRAYOUT",
  370. sizeof (EFI_IFR_GRAYOUT),
  371. IfrParse19
  372. },
  373. {
  374. "EFI_IFR_DATE",
  375. sizeof (EFI_IFR_DATE) / 3,
  376. IfrParse1A
  377. },
  378. {
  379. "EFI_IFR_TIME",
  380. sizeof (EFI_IFR_TIME) / 3,
  381. IfrParse1B
  382. },
  383. {
  384. "EFI_IFR_STRING",
  385. sizeof (EFI_IFR_STRING),
  386. IfrParse1C
  387. },
  388. {
  389. "EFI_IFR_LABEL",
  390. sizeof (EFI_IFR_LABEL),
  391. IfrParse1D
  392. },
  393. {
  394. "EFI_IFR_SAVE_DEFAULTS",
  395. sizeof (EFI_IFR_SAVE_DEFAULTS),
  396. IfrParse1E
  397. },
  398. {
  399. "EFI_IFR_RESTORE_DEFAULTS",
  400. sizeof (EFI_IFR_RESTORE_DEFAULTS),
  401. IfrParse1F
  402. },
  403. {
  404. "EFI_IFR_BANNER",
  405. sizeof (EFI_IFR_BANNER),
  406. IfrParse20
  407. },
  408. {
  409. "EFI_IFR_INVENTORY",
  410. sizeof (EFI_IFR_INVENTORY),
  411. IfrParse21
  412. },
  413. {
  414. "EFI_IFR_EQ_VAR_VAL_OP",
  415. sizeof (EFI_IFR_EQ_VAR_VAL),
  416. IfrParse22
  417. },
  418. {
  419. "EFI_IFR_ORDERED_LIST_OP",
  420. sizeof (EFI_IFR_ORDERED_LIST),
  421. IfrParse23
  422. },
  423. {
  424. "EFI_IFR_VARSTORE_OP",
  425. -(int) (sizeof (EFI_IFR_VARSTORE)),
  426. IfrParse24
  427. },
  428. {
  429. "EFI_IFR_VARSTORE_SELECT_OP",
  430. sizeof (EFI_IFR_VARSTORE_SELECT),
  431. IfrParse25
  432. },
  433. {
  434. "EFI_IFR_VARSTORE_SELECT_PAIR_OP",
  435. sizeof (EFI_IFR_VARSTORE_SELECT_PAIR),
  436. IfrParse26
  437. },
  438. {
  439. "EFI_IFR_TRUE",
  440. sizeof (EFI_IFR_TRUE),
  441. IfrParse27
  442. },
  443. {
  444. "EFI_IFR_FALSE",
  445. sizeof (EFI_IFR_FALSE),
  446. IfrParse28
  447. },
  448. {
  449. "EFI_IFR_GT",
  450. sizeof (EFI_IFR_GT),
  451. IfrParse29
  452. },
  453. {
  454. "EFI_IFR_GE",
  455. sizeof (EFI_IFR_GE),
  456. IfrParse2A
  457. },
  458. };
  459. #define PARSE_TABLE_ENTRIES (sizeof (mIfrParseTable) / sizeof (mIfrParseTable[0]))
  460. static
  461. STATUS
  462. GetVarStoreInfo (
  463. IFR_PARSE_CONTEXT *Context,
  464. UINT16 VarId,
  465. EFI_GUID **VarStoreGuid,
  466. char **VarStoreName
  467. );
  468. static
  469. void
  470. FreeVarStores (
  471. VOID
  472. );
  473. static
  474. STATUS
  475. CreateVarStore (
  476. EFI_GUID *VarGuid,
  477. CHAR8 *VarName,
  478. int VarStoreSize
  479. );
  480. static
  481. STATUS
  482. SetDefaults (
  483. IFR_PARSE_CONTEXT *Context,
  484. UINT32 MfgDefaults
  485. );
  486. //
  487. // Globals
  488. //
  489. static IFR_PARSE_CONTEXT *mParseContext = NULL;
  490. static VARIABLE_STORE_ENTRY *mVariableStores = NULL;
  491. static int BreakOnOpcodeTag = 0;
  492. static int OpcodeTag = 1;
  493. /*****************************************************************************/
  494. STATUS
  495. IfrParseCheck (
  496. char *Buffer,
  497. long BufferSize
  498. )
  499. /*++
  500. Routine Description:
  501. Check a buffer to ensure that is is parseable IFR
  502. Arguments:
  503. Buffer - pointer to raw IFR bytes
  504. BufferSize - size of IFR pointed to by Buffer
  505. Returns:
  506. STATUS_SUCCESS if successful
  507. STATUS_ERROR otherwise
  508. --*/
  509. {
  510. char *Start;
  511. char *End;
  512. char *Pos;
  513. EFI_IFR_OP_HEADER *OpHeader;
  514. char *FileName;
  515. FileName = "";
  516. //
  517. // Walk the list of IFR statements in the IFR pack
  518. //
  519. Start = Buffer;
  520. Pos = Buffer;
  521. End = Start + BufferSize;
  522. while ((Pos >= Start) && (Pos < End)) {
  523. OpHeader = (EFI_IFR_OP_HEADER *) Pos;
  524. //
  525. // Check range on size
  526. //
  527. if (Pos + OpHeader->Length > End) {
  528. Error (NULL, 0, 0, FileName, "invalid IFR opcode size at offset 0x%X", (int) Pos - (int) Start);
  529. return STATUS_ERROR;
  530. }
  531. if (OpHeader->Length == 0) {
  532. Error (NULL, 0, 0, FileName, "IFR opcode size=0 at offset 0x%X", (int) Pos - (int) Start);
  533. return STATUS_ERROR;
  534. }
  535. //
  536. // See if it's the END_FORMSET opcode
  537. //
  538. if (OpHeader->OpCode == EFI_IFR_END_FORM_SET_OP) {
  539. break;
  540. }
  541. //
  542. // Advance to next IFR statement/opcode
  543. //
  544. Pos += OpHeader->Length;
  545. }
  546. return STATUS_SUCCESS;
  547. }
  548. STATUS
  549. IfrParseInit (
  550. VOID
  551. )
  552. /*++
  553. Routine Description:
  554. Initialize this module for IFR pack parsing
  555. Arguments:
  556. Returns:
  557. STATUS_SUCCESS always
  558. --*/
  559. {
  560. return STATUS_SUCCESS;
  561. }
  562. STATUS
  563. IfrParseEnd (
  564. VOID
  565. )
  566. /*++
  567. Routine Description:
  568. Free up memory allocated during IFR pack parsing done by this module
  569. Arguments:
  570. None
  571. Returns:
  572. STATUS_SUCCESS always
  573. --*/
  574. {
  575. IFR_PARSE_CONTEXT *NextContext;
  576. IFR_PARSE_ENTRY *NextEntry;
  577. //
  578. // Free up the memory from our parse contexts
  579. //
  580. while (mParseContext != NULL) {
  581. while (mParseContext->Ifr != NULL) {
  582. NextEntry = mParseContext->Ifr->Next;
  583. //
  584. // We pointed directly into the user buffer, rather than make
  585. // a copy, so don't free up the bytes.
  586. //
  587. free (mParseContext->Ifr);
  588. mParseContext->Ifr = NextEntry;
  589. }
  590. NextContext = mParseContext->Next;
  591. free (mParseContext->PackHeader);
  592. free (mParseContext);
  593. mParseContext = NextContext;
  594. }
  595. return STATUS_SUCCESS;
  596. }
  597. static
  598. void
  599. FreeVarStores (
  600. VOID
  601. )
  602. /*++
  603. Routine Description:
  604. GC_TODO: Add function description
  605. Arguments:
  606. None
  607. Returns:
  608. GC_TODO: add return values
  609. --*/
  610. {
  611. VARIABLE_STORE_ENTRY *NextVarStore;
  612. //
  613. // Free up memory from our variable stores
  614. //
  615. while (mVariableStores != NULL) {
  616. if (mVariableStores->VarPack != NULL) {
  617. free (mVariableStores->VarPack);
  618. }
  619. NextVarStore = mVariableStores->Next;
  620. free (mVariableStores);
  621. mVariableStores = NextVarStore;
  622. }
  623. }
  624. /******************************************************************************
  625. FUNCTION: IfrParsePack()
  626. DESCRIPTION: Given a pointer to an IFR pack, parse it to create a linked
  627. list of opcodes and relevant data required for later dumping.
  628. *******************************************************************************/
  629. STATUS
  630. IfrParsePack (
  631. int Handle,
  632. EFI_HII_IFR_PACK *PackHeader,
  633. EFI_GUID *PackageGuid
  634. )
  635. /*++
  636. Routine Description:
  637. Given a pointer to an IFR pack, parse it to create a linked
  638. list of opcodes and relevant data required for later dumping.
  639. Arguments:
  640. Handle - the handle number associated with this IFR pack. It
  641. can be used later to retrieve more info on the particular
  642. pack
  643. PackHeader - pointer to IFR pack to parse
  644. PackageGuid - on input, it comes from the HII data table entry for this pack.
  645. On output, we'll return the IFR formset GUID.
  646. Returns:
  647. STATUS_SUCCESS always
  648. --*/
  649. {
  650. EFI_IFR_OP_HEADER *OpHeader;
  651. IFR_PARSE_CONTEXT *Context;
  652. IFR_PARSE_CONTEXT *TempContext;
  653. IFR_PARSE_ENTRY *IfrEntry;
  654. //
  655. // Initialize our context
  656. //
  657. Context = (IFR_PARSE_CONTEXT *) malloc (sizeof (IFR_PARSE_CONTEXT));
  658. if (Context == NULL) {
  659. Error (NULL, 0, 0, "memory allocation failure", NULL);
  660. return STATUS_ERROR;
  661. }
  662. memset ((void *) Context, 0, sizeof (IFR_PARSE_CONTEXT));
  663. //
  664. // Cache a copy of the input pack so the caller can free their copy
  665. //
  666. Context->PackHeader = (EFI_HII_IFR_PACK *) malloc (PackHeader->Header.Length);
  667. if (Context->PackHeader == NULL) {
  668. Error (NULL, 0, 0, "memory allocation failure", NULL);
  669. free (Context);
  670. return STATUS_ERROR;
  671. }
  672. memcpy (Context->PackHeader, PackHeader, PackHeader->Header.Length);
  673. Context->IfrBufferStart = (char *) (Context->PackHeader + 1);
  674. Context->CurrentPos = Context->IfrBufferStart;
  675. Context->IfrBufferLen = PackHeader->Header.Length - sizeof (EFI_HII_IFR_PACK);
  676. Context->Handle = Handle;
  677. Context->FormsetGuid = &Context->NullGuid;
  678. Context->PackageGuid = *PackageGuid;
  679. //
  680. // Add it to the end of our list
  681. //
  682. if (mParseContext == NULL) {
  683. mParseContext = Context;
  684. } else {
  685. TempContext = mParseContext;
  686. while (TempContext->Next != NULL) {
  687. TempContext = TempContext->Next;
  688. }
  689. TempContext->Next = Context;
  690. }
  691. //
  692. // Walk the opcodes in the pack
  693. //
  694. while
  695. (
  696. (Context->CurrentPos >= Context->IfrBufferStart) &&
  697. (Context->CurrentPos < Context->IfrBufferStart + Context->IfrBufferLen)
  698. ) {
  699. OpHeader = (EFI_IFR_OP_HEADER *) Context->CurrentPos;
  700. //
  701. // Allocate a new IFR entry to put in our linked list, then
  702. // point directly to the caller's raw data.
  703. //
  704. IfrEntry = (IFR_PARSE_ENTRY *) malloc (sizeof (IFR_PARSE_ENTRY));
  705. if (IfrEntry == NULL) {
  706. Error (NULL, 0, 0, "memory allocation failure", NULL);
  707. free (Context->PackHeader);
  708. free (Context);
  709. return STATUS_ERROR;
  710. }
  711. memset ((void *) IfrEntry, 0, sizeof (IFR_PARSE_ENTRY));
  712. IfrEntry->Tag = ++OpcodeTag;
  713. if (OpcodeTag == BreakOnOpcodeTag) {
  714. EFI_BREAKPOINT ();
  715. }
  716. IfrEntry->RawIfrHeader = (EFI_IFR_OP_HEADER *) (Context->CurrentPos);
  717. //
  718. // Add this entry to our linked list. If it's not the first, then
  719. // forward the variable store settings from the previous entry.
  720. //
  721. if (Context->LastIfr != NULL) {
  722. IfrEntry->VarStoreGuid1 = Context->LastIfr->VarStoreGuid1;
  723. IfrEntry->VarStoreName1 = Context->LastIfr->VarStoreName1;
  724. IfrEntry->VarStoreGuid2 = Context->LastIfr->VarStoreGuid2;
  725. IfrEntry->VarStoreName2 = Context->LastIfr->VarStoreName2;
  726. Context->LastIfr->Next = IfrEntry;
  727. } else {
  728. Context->Ifr = IfrEntry;
  729. }
  730. Context->LastIfr = IfrEntry;
  731. //
  732. // Switch on the opcode to parse it
  733. //
  734. if (OpHeader->OpCode < PARSE_TABLE_ENTRIES) {
  735. if (mIfrParseTable[OpHeader->OpCode].Parse != NULL) {
  736. mIfrParseTable[OpHeader->OpCode].Parse (Context);
  737. }
  738. } else {
  739. Error (
  740. NULL,
  741. 0,
  742. 0,
  743. "invalid opcode found in IFR",
  744. "offset=0x%X opcode=0x%02X",
  745. (int) OpHeader - (int) Context->PackHeader,
  746. (int) OpHeader->OpCode
  747. );
  748. free (IfrEntry);
  749. free (Context->PackHeader);
  750. free (Context);
  751. return STATUS_ERROR;
  752. }
  753. //
  754. // If it's the END_FORMSET opcode, then we're done
  755. //
  756. if (OpHeader->OpCode == EFI_IFR_END_FORM_SET_OP) {
  757. break;
  758. }
  759. //
  760. // Advance to next IFR statement/opcode
  761. //
  762. if (OpHeader->Length == 0) {
  763. Error (NULL, 0, 0, "0-length IFR opcode encountered", NULL);
  764. free (IfrEntry);
  765. free (Context->PackHeader);
  766. free (Context);
  767. return STATUS_ERROR;
  768. }
  769. Context->CurrentPos += OpHeader->Length;
  770. }
  771. //
  772. // Return the form GUID.
  773. //
  774. *PackageGuid = *Context->FormsetGuid;
  775. return STATUS_SUCCESS;
  776. }
  777. /******************************************************************************
  778. FUNCTION: GetVarStoreInfo()
  779. DESCRIPTION: IFR contains VARSTORE opcodes to specify where variable data
  780. for following opcodes is supposed to be stored. One VARSTORE statement
  781. allows you to specify the variable store GUID and a key, and another
  782. VARSTORE (select) allows you to specify the key of a VARSTORE statement.
  783. Given the key from a VARSTORE_SELECT statement, go find the corresponding
  784. VARSTORE statement with a matching key and return the varstore GUID and
  785. name. If key == 0, then the variable store is FormsetGuid."Setup"
  786. *******************************************************************************/
  787. static
  788. STATUS
  789. GetVarStoreInfo (
  790. IFR_PARSE_CONTEXT *Context,
  791. UINT16 VarId,
  792. EFI_GUID **VarStoreGuid,
  793. char **VarStoreName
  794. )
  795. /*++
  796. Routine Description:
  797. Get variable store information from an IFR pack for a given variable store ID.
  798. Arguments:
  799. Context - pointer to IFR parse context
  800. VarId - variable store ID referenced by IFR being parsed
  801. VarStoreGuid - outgoing GUID of the variable store corresponding to VarId
  802. VarStoreName - outgoing variable name of variable store corresponding to VarId
  803. Returns:
  804. STATUS_SUCCESS - variable store with matching VarId found, and outoing GUID/Name are valid
  805. STATUS_ERROR - otherwise
  806. --*/
  807. {
  808. IFR_PARSE_ENTRY *Ptr;
  809. EFI_IFR_VARSTORE *VarStore;
  810. if (Context == NULL) {
  811. return STATUS_ERROR;
  812. }
  813. //
  814. // Walk the entire IFR form and find a variable store opcode that
  815. // has a matching variable store ID.
  816. //
  817. for (Ptr = Context->Ifr; Ptr != NULL; Ptr = Ptr->Next) {
  818. if (Ptr->RawIfrHeader->OpCode == EFI_IFR_FORM_SET_OP) {
  819. if (VarId == 0) {
  820. *VarStoreGuid = &((EFI_IFR_FORM_SET *) (Ptr->RawIfrHeader))->Guid;
  821. *VarStoreName = DEFAULT_VARIABLE_NAME;
  822. return STATUS_SUCCESS;
  823. }
  824. } else if (Ptr->RawIfrHeader->OpCode == EFI_IFR_VARSTORE_OP) {
  825. //
  826. // See if it's a variable ID match
  827. //
  828. VarStore = (EFI_IFR_VARSTORE *) Ptr->RawIfrHeader;
  829. if (VarStore->VarId == VarId) {
  830. *VarStoreGuid = &VarStore->Guid;
  831. *VarStoreName = (char *) (VarStore + 1);
  832. return STATUS_SUCCESS;
  833. }
  834. }
  835. }
  836. return STATUS_ERROR;
  837. }
  838. STATUS
  839. IfrSetDefaults (
  840. int MfgDefaults
  841. )
  842. /*++
  843. Routine Description:
  844. Go through all the IFR forms we've parsed so far and create and set variable
  845. defaults.
  846. Arguments:
  847. MfgDefaults - non-zero if manufacturing defaults are desired
  848. Returns:
  849. STATUS_SUCCESS - always
  850. --*/
  851. {
  852. IFR_PARSE_CONTEXT *Context;
  853. //
  854. // First free up any variable stores we've created so far.
  855. //
  856. FreeVarStores ();
  857. for (Context = mParseContext; Context != NULL; Context = Context->Next) {
  858. //
  859. // Call our internal function to handle it
  860. //
  861. SetDefaults (Context, MfgDefaults);
  862. }
  863. return STATUS_SUCCESS;
  864. }
  865. /******************************************************************************/
  866. STATUS
  867. IfrGetIfrPack (
  868. int Handle,
  869. EFI_HII_IFR_PACK **PackHeader,
  870. EFI_GUID *FormsetGuid
  871. )
  872. /*++
  873. Routine Description:
  874. GC_TODO: Add function description
  875. Arguments:
  876. Handle - GC_TODO: add argument description
  877. PackHeader - GC_TODO: add argument description
  878. FormsetGuid - GC_TODO: add argument description
  879. Returns:
  880. GC_TODO: add return values
  881. --*/
  882. {
  883. IFR_PARSE_CONTEXT *Context;
  884. for (Context = mParseContext; Context != NULL; Context = Context->Next) {
  885. if (Context->Handle == Handle) {
  886. *PackHeader = Context->PackHeader;
  887. memcpy (FormsetGuid, Context->FormsetGuid, sizeof (EFI_GUID));
  888. return STATUS_SUCCESS;
  889. }
  890. }
  891. return STATUS_ERROR;
  892. }
  893. STATUS
  894. IfrReferencesVarPack (
  895. int IfrHandle,
  896. EFI_HII_VARIABLE_PACK *VarPack
  897. )
  898. /*++
  899. Routine Description:
  900. Given an HII handle number (which corrresponds to a handle number passed
  901. in to IfrParsePack()), see if the IFR references the specified variable
  902. pack.
  903. Arguments:
  904. IfrHandle - handle number for the IFR pack to check (passed to IfrParsePack())
  905. VarPack - variable pack to check to see if the IFR references
  906. Returns:
  907. STATUS_SUCCESS if the IFR on the given handle references the variable pack
  908. STATUS_WARNING the IFR does not reference the variable pack
  909. STATUS_ERROR invalid IFR handle
  910. --*/
  911. {
  912. IFR_PARSE_CONTEXT *Context;
  913. char VarName[MAX_VARIABLE_NAME];
  914. IFR_PARSE_ENTRY *ParseEntry;
  915. for (Context = mParseContext; Context != NULL; Context = Context->Next) {
  916. if (Context->Handle == IfrHandle) {
  917. //
  918. // Create an ASCII version of the variable name, since that's what is
  919. // referenced in IFR.
  920. //
  921. sprintf (VarName, "%S", (CHAR16 *) (VarPack + 1));
  922. //
  923. // Walk all the opcodes and see if the IFR references this variable pack
  924. //
  925. for (ParseEntry = Context->Ifr; ParseEntry != NULL; ParseEntry = ParseEntry->Next) {
  926. //
  927. // Check for Name.Guid match for primary IFR variable store
  928. //
  929. if ((strcmp (VarName, ParseEntry->VarStoreName1) == 0) &&
  930. (memcmp (&VarPack->VariableGuid, ParseEntry->VarStoreGuid1, sizeof (EFI_GUID)) == 0)
  931. ) {
  932. return STATUS_SUCCESS;
  933. }
  934. //
  935. // Check for Name.Guid match for secondary IFR variable store
  936. //
  937. if ((ParseEntry->VarStoreName2 != NULL) &&
  938. (strcmp (VarName, ParseEntry->VarStoreName2) == 0) &&
  939. (memcmp (&VarPack->VariableGuid, ParseEntry->VarStoreGuid2, sizeof (EFI_GUID)) == 0)
  940. ) {
  941. return STATUS_SUCCESS;
  942. }
  943. }
  944. return STATUS_WARNING;
  945. }
  946. }
  947. return STATUS_ERROR;
  948. }
  949. STATUS
  950. IfrGetVarPack (
  951. int VarIndex,
  952. EFI_HII_VARIABLE_PACK **VarPack
  953. )
  954. /*++
  955. Routine Description:
  956. Get the variable defaults. It is expected that the caller
  957. called IfrSetDefaults() previously to walk all the IFR forms we know about
  958. and create and initialize default values.
  959. Arguments:
  960. VarIndex - a 0-based index into all the variable stores we know about
  961. VarPack - outgoing pointer to a variable pack
  962. Returns:
  963. STATUS_ERROR - VarIndex exceeds the number of variable packs we know of
  964. STATUS_SUCCESS - otherwise
  965. --*/
  966. {
  967. VARIABLE_STORE_ENTRY *Entry;
  968. //
  969. // Initialize outgoing parameters
  970. //
  971. *VarPack = NULL;
  972. for (Entry = mVariableStores; Entry != NULL; Entry = Entry->Next) {
  973. if (VarIndex == 0) {
  974. *VarPack = Entry->VarPack;
  975. return STATUS_SUCCESS;
  976. }
  977. VarIndex--;
  978. }
  979. return STATUS_ERROR;
  980. }
  981. static
  982. STATUS
  983. SetVariableValue (
  984. EFI_GUID *VarGuid,
  985. char *VarName,
  986. int VarOffset,
  987. int VarSize,
  988. void *VarValue
  989. )
  990. /*++
  991. Routine Description:
  992. Given a variable GUID.Name, offset, size, and value, set the bytes in
  993. the variable to the provided value.
  994. Arguments:
  995. VarGuid - GUID of variable to set
  996. VarName - name of variable to set
  997. VarOffset - byte offset into the variable store
  998. VarSize - size of the value in the variable store (in bytes)
  999. VarValue - pointer to buffer containing the value to set
  1000. Returns:
  1001. --*/
  1002. {
  1003. VARIABLE_STORE_ENTRY *Entry;
  1004. char *Src;
  1005. char *Dest;
  1006. //
  1007. // Go through our list of variable stores to find the match
  1008. //
  1009. for (Entry = mVariableStores; Entry != NULL; Entry = Entry->Next) {
  1010. if (memcmp (VarGuid, &Entry->VarPack->VariableGuid, sizeof (EFI_GUID)) == 0) {
  1011. if (strcmp (VarName, Entry->VarName) == 0) {
  1012. //
  1013. // Found match -- check offset. If it's beyond the size of the variable store
  1014. // buffer, then return a warning. Note that date-time can be beyond the
  1015. // end of the varstore, which is ok.
  1016. //
  1017. if (VarOffset + VarSize <= Entry->VarBufferSize) {
  1018. //
  1019. // Stuff the data
  1020. //
  1021. Dest = Entry->VarBuffer + VarOffset;
  1022. Src = (char *) VarValue;
  1023. while (VarSize > 0) {
  1024. *Dest = *Src;
  1025. Src++;
  1026. Dest++;
  1027. VarSize--;
  1028. }
  1029. return STATUS_SUCCESS;
  1030. }
  1031. return STATUS_WARNING;
  1032. }
  1033. }
  1034. }
  1035. return STATUS_ERROR;
  1036. }
  1037. static
  1038. STATUS
  1039. SetDefaults (
  1040. IFR_PARSE_CONTEXT *Context,
  1041. UINT32 MfgDefaults
  1042. )
  1043. /*++
  1044. Routine Description:
  1045. Set variable defaults by walking a single IFR form.
  1046. Arguments:
  1047. Context - Pointer to the IFR context.
  1048. MfgDefaults - Number of Mfg defaults
  1049. Returns:
  1050. EFI_INVALID_PARAMETER - arguments to function are invalid
  1051. STATUS_SUCCESS - function executed successfully
  1052. --*/
  1053. {
  1054. int Size;
  1055. int CachedVarOffset;
  1056. int CachedVarSize;
  1057. int OrderedList;
  1058. IFR_PARSE_ENTRY *SavedParseEntry;
  1059. EFI_IFR_CHECK_BOX *IfrCheckBox;
  1060. EFI_IFR_ONE_OF_OPTION *IfrOneOfOption;
  1061. EFI_IFR_NUMERIC *IfrNumeric;
  1062. STATUS Status;
  1063. char ZeroByte;
  1064. //
  1065. // Walk the opcodes to set default values and stuff them into the variable stores
  1066. //
  1067. if (Context == NULL) {
  1068. return EFI_INVALID_PARAMETER;
  1069. }
  1070. Status = STATUS_SUCCESS;
  1071. Context->CurrentIfr = Context->Ifr;
  1072. SavedParseEntry = NULL;
  1073. OrderedList = 0;
  1074. CachedVarOffset = 0;
  1075. CachedVarSize = 0;
  1076. ZeroByte = 0;
  1077. while (Context->CurrentIfr != NULL) {
  1078. if (Context->CurrentIfr->RawIfrHeader->OpCode == EFI_IFR_FORM_SET_OP) {
  1079. //
  1080. // Formset opcode -- create a variable pack
  1081. //
  1082. Status = CreateVarStore (
  1083. &((EFI_IFR_FORM_SET *) (Context->CurrentIfr->RawIfrHeader))->Guid,
  1084. DEFAULT_VARIABLE_NAME,
  1085. ((EFI_IFR_FORM_SET *) (Context->CurrentIfr->RawIfrHeader))->NvDataSize
  1086. );
  1087. } else if (Context->CurrentIfr->RawIfrHeader->OpCode == EFI_IFR_VARSTORE_OP) {
  1088. //
  1089. // Variable store opcode -- create a variable pack
  1090. //
  1091. Status = CreateVarStore (
  1092. &((EFI_IFR_VARSTORE *) (Context->CurrentIfr->RawIfrHeader))->Guid,
  1093. (char *) Context->CurrentIfr->RawIfrHeader + sizeof (EFI_IFR_VARSTORE),
  1094. ((EFI_IFR_VARSTORE *) (Context->CurrentIfr->RawIfrHeader))->Size
  1095. );
  1096. } else if (Context->CurrentIfr->RawIfrHeader->OpCode == EFI_IFR_ONE_OF_OP) {
  1097. //
  1098. // Need this parse context later when we find the default ONE_OF_OPTION.
  1099. // Clear out the variable store first, so that we're covered if someone
  1100. // has two one-of opcode that operate on the same data.
  1101. // So "last one wins" is the behavior.
  1102. //
  1103. OrderedList = 0;
  1104. SavedParseEntry = Context->CurrentIfr;
  1105. CachedVarOffset = ((EFI_IFR_ONE_OF *) Context->CurrentIfr->RawIfrHeader)->QuestionId;
  1106. CachedVarSize = ((EFI_IFR_ONE_OF *) Context->CurrentIfr->RawIfrHeader)->Width;
  1107. } else if (Context->CurrentIfr->RawIfrHeader->OpCode == EFI_IFR_ORDERED_LIST_OP) {
  1108. //
  1109. // Need this parse context later as we parse the ONE_OF_OP's in the ordered list
  1110. //
  1111. OrderedList = 1;
  1112. SavedParseEntry = Context->CurrentIfr;
  1113. CachedVarOffset = ((EFI_IFR_ORDERED_LIST *) Context->CurrentIfr->RawIfrHeader)->QuestionId;
  1114. CachedVarSize = ((EFI_IFR_ORDERED_LIST *) Context->CurrentIfr->RawIfrHeader)->MaxEntries;
  1115. while (CachedVarSize > 0) {
  1116. Status = SetVariableValue (
  1117. SavedParseEntry->VarStoreGuid1, // GUID of variable store to write
  1118. SavedParseEntry->VarStoreName1, // name of variable store to write
  1119. CachedVarOffset, // offset into variable store
  1120. 1, // variable data size
  1121. (void *) &ZeroByte
  1122. );
  1123. //
  1124. // variable value
  1125. //
  1126. CachedVarSize--;
  1127. CachedVarOffset++;
  1128. }
  1129. CachedVarOffset = ((EFI_IFR_ORDERED_LIST *) Context->CurrentIfr->RawIfrHeader)->QuestionId;
  1130. CachedVarSize = 1;
  1131. //
  1132. // ((EFI_IFR_ORDERED_LIST *)Context->CurrentIfr->RawIfrHeader)->Width;
  1133. //
  1134. } else if (Context->CurrentIfr->RawIfrHeader->OpCode == EFI_IFR_ONE_OF_OPTION_OP) {
  1135. IfrOneOfOption = (EFI_IFR_ONE_OF_OPTION *) Context->CurrentIfr->RawIfrHeader;
  1136. //
  1137. // If we're in an ordered list, then copy the value to the data store
  1138. //
  1139. if (OrderedList) {
  1140. Status = SetVariableValue (
  1141. SavedParseEntry->VarStoreGuid1, // GUID of variable store to write
  1142. SavedParseEntry->VarStoreName1, // name of variable store to write
  1143. CachedVarOffset, // offset into variable store
  1144. 1, // variable data size
  1145. (void *) &IfrOneOfOption->Value
  1146. );
  1147. //
  1148. // variable value
  1149. //
  1150. // Advance the offset for the next ordered list item
  1151. //
  1152. CachedVarOffset += CachedVarSize;
  1153. } else {
  1154. //
  1155. // ONE-OF list. See if the default flag is set (provided we're not doing mfg defaults)
  1156. //
  1157. if (!MfgDefaults) {
  1158. if (IfrOneOfOption->Flags & EFI_IFR_FLAG_DEFAULT) {
  1159. Status = SetVariableValue (
  1160. SavedParseEntry->VarStoreGuid1, // GUID of variable store to write
  1161. SavedParseEntry->VarStoreName1, // name of variable store to write
  1162. CachedVarOffset, // offset into variable store
  1163. CachedVarSize, // variable data size
  1164. &IfrOneOfOption->Value
  1165. );
  1166. //
  1167. // variable value
  1168. //
  1169. }
  1170. } else {
  1171. if (IfrOneOfOption->Flags & EFI_IFR_FLAG_MANUFACTURING) {
  1172. Status = SetVariableValue (
  1173. SavedParseEntry->VarStoreGuid1, // GUID of variable store to write
  1174. SavedParseEntry->VarStoreName1, // name of variable store to write
  1175. CachedVarOffset, // offset into variable store
  1176. CachedVarSize, // variable data size
  1177. &IfrOneOfOption->Value
  1178. );
  1179. //
  1180. // variable value
  1181. //
  1182. }
  1183. }
  1184. }
  1185. } else if (Context->CurrentIfr->RawIfrHeader->OpCode == EFI_IFR_CHECKBOX_OP) {
  1186. //
  1187. // If we're saving defaults, and the default flag is set, or we're saving
  1188. // manufacturing defaults and the manufacturing flag is set, then save a 1.
  1189. // By default the varstore buffer is cleared, so we don't need to save a 0 ever.
  1190. //
  1191. IfrCheckBox = (EFI_IFR_CHECK_BOX *) Context->CurrentIfr->RawIfrHeader;
  1192. if (((MfgDefaults == 0) && (IfrCheckBox->Flags & EFI_IFR_FLAG_DEFAULT)) ||
  1193. ((MfgDefaults != 0) && (IfrCheckBox->Flags & EFI_IFR_FLAG_MANUFACTURING))
  1194. ) {
  1195. Size = 1;
  1196. Status = SetVariableValue (
  1197. Context->CurrentIfr->VarStoreGuid1, // GUID of variable store to write
  1198. Context->CurrentIfr->VarStoreName1, // name of variable store to write
  1199. IfrCheckBox->QuestionId, // offset into variable store
  1200. IfrCheckBox->Width, // variable data size
  1201. (void *) &Size
  1202. );
  1203. //
  1204. // variable value
  1205. //
  1206. }
  1207. } else if (Context->CurrentIfr->RawIfrHeader->OpCode == EFI_IFR_NUMERIC_OP) {
  1208. IfrNumeric = (EFI_IFR_NUMERIC *) Context->CurrentIfr->RawIfrHeader;
  1209. Status = SetVariableValue (
  1210. Context->CurrentIfr->VarStoreGuid1, // GUID of variable store to write
  1211. Context->CurrentIfr->VarStoreName1, // name of variable store to write
  1212. IfrNumeric->QuestionId, // offset into variable store
  1213. IfrNumeric->Width, // variable data size
  1214. (void *) &IfrNumeric->Default
  1215. );
  1216. //
  1217. // variable value
  1218. //
  1219. }
  1220. Context->CurrentIfr = Context->CurrentIfr->Next;
  1221. }
  1222. return STATUS_SUCCESS;
  1223. }
  1224. static
  1225. STATUS
  1226. CreateVarStore (
  1227. EFI_GUID *VarGuid,
  1228. CHAR8 *VarName,
  1229. int VarStoreSize
  1230. )
  1231. /*++
  1232. Routine Description:
  1233. Given a variable GUID.Name and the size of the variable store, allocate
  1234. storage for maintaining the variable value.
  1235. Arguments:
  1236. VarGuid - GUID for a variable
  1237. VarName - Name of the variable
  1238. VarStoreSize - size of the variable store
  1239. Returns:
  1240. STATUS_ERROR - problem with storage allocation
  1241. STATUS_SUCCESS - function executed successfully
  1242. --*/
  1243. {
  1244. VARIABLE_STORE_ENTRY *Entry;
  1245. VARIABLE_STORE_ENTRY *TempEntry;
  1246. int PackSize;
  1247. int VarNameLen;
  1248. //
  1249. // If the variable store size is zero, then do nothing. This could be valid
  1250. // if variable steering is used in the IFR such that FormsetGUID."Setup" variable
  1251. // store is never used.
  1252. //
  1253. // OPEN: What about a form that only has a time/date question? Then if some other
  1254. // function called SetDefaults(), attempting to set time/date would result in an
  1255. // error in the SetVarValue() function.
  1256. //
  1257. if (VarStoreSize == 0) {
  1258. return STATUS_SUCCESS;
  1259. }
  1260. //
  1261. // Go through our list of variable stores and see if we've already created one
  1262. // for this Guid.Name. If so, check the size and return. Otherwise create
  1263. // one and add it to the list.
  1264. //
  1265. for (Entry = mVariableStores; Entry != NULL; Entry = Entry->Next) {
  1266. if (memcmp (VarGuid, &Entry->VarPack->VariableGuid, sizeof (EFI_GUID)) == 0) {
  1267. if (strcmp (VarName, Entry->VarName) == 0) {
  1268. //
  1269. // Already have one. Check size.
  1270. //
  1271. if (Entry->VarBufferSize != VarStoreSize) {
  1272. Error (NULL, 0, 0, "mismatched variable store size between two formsets", VarName);
  1273. return STATUS_ERROR;
  1274. }
  1275. return STATUS_SUCCESS;
  1276. }
  1277. }
  1278. }
  1279. //
  1280. // Create a new one.
  1281. //
  1282. Entry = (VARIABLE_STORE_ENTRY *) malloc (sizeof (VARIABLE_STORE_ENTRY));
  1283. if (Entry == NULL) {
  1284. Error (NULL, 0, 0, "memory allocation failure", NULL);
  1285. return STATUS_ERROR;
  1286. }
  1287. memset ((void *) Entry, 0, sizeof (VARIABLE_STORE_ENTRY));
  1288. //
  1289. // Compute size of the varpack
  1290. //
  1291. VarNameLen = strlen (VarName) + 1;
  1292. PackSize = sizeof (EFI_HII_VARIABLE_PACK) + VarNameLen * sizeof (CHAR16) + VarStoreSize;
  1293. Entry->VarPack = (EFI_HII_VARIABLE_PACK *) malloc (PackSize);
  1294. if (Entry->VarPack == NULL) {
  1295. Error (NULL, 0, 0, "memory allocation failure", NULL);
  1296. free (Entry);
  1297. return STATUS_ERROR;
  1298. }
  1299. Entry->VarPack->Header.Length = PackSize;
  1300. Entry->VarPack->Header.Type = EFI_HII_VARIABLE;
  1301. Entry->VarPack->VariableNameLength = VarNameLen * sizeof (CHAR16);
  1302. Entry->VarName[MAX_VARIABLE_NAME - 1] = 0;
  1303. strncpy (Entry->VarName, VarName, MAX_VARIABLE_NAME - 1);
  1304. #ifdef USE_VC8
  1305. swprintf ((CHAR16 *) (Entry->VarPack + 1), (strlen (VarName) + 1) * sizeof (CHAR16), L"%S", VarName);
  1306. #else
  1307. swprintf ((CHAR16 *) (Entry->VarPack + 1), L"%S", VarName);
  1308. #endif
  1309. memcpy (&Entry->VarPack->VariableGuid, VarGuid, sizeof (EFI_GUID));
  1310. //
  1311. // Point VarBuffer into the allocated buffer (for convenience)
  1312. //
  1313. Entry->VarBuffer = (char *) Entry->VarPack + sizeof (EFI_HII_VARIABLE_PACK) + VarNameLen * sizeof (CHAR16);
  1314. memset ((void *) Entry->VarBuffer, 0, VarStoreSize);
  1315. Entry->VarBufferSize = VarStoreSize;
  1316. //
  1317. // Add this new varstore to our list
  1318. //
  1319. if (mVariableStores == NULL) {
  1320. mVariableStores = Entry;
  1321. } else {
  1322. for (TempEntry = mVariableStores; TempEntry->Next != NULL; TempEntry = TempEntry->Next)
  1323. ;
  1324. TempEntry->Next = Entry;
  1325. }
  1326. return STATUS_SUCCESS;
  1327. }
  1328. /******************************************************************************/
  1329. /*++
  1330. Routine Description:
  1331. The following IfrParseXX() functions are used to parse an IFR opcode numbered
  1332. XX via a dispatch table.
  1333. Arguments:
  1334. Context - IFR parsing context into which pertinent data for the
  1335. current opcode can be saved. Context->LastIfr->RawIfrHeader points to
  1336. the raw IFR bytes currently being parsed.
  1337. Returns:
  1338. STATUS_SUCCESS - always
  1339. --*/
  1340. /*******************************************************************************/
  1341. static
  1342. STATUS
  1343. IfrParse01 (
  1344. IFR_PARSE_CONTEXT *Context
  1345. )
  1346. /*++
  1347. Routine Description:
  1348. GC_TODO: Add function description
  1349. Arguments:
  1350. Context - GC_TODO: add argument description
  1351. Returns:
  1352. GC_TODO: add return values
  1353. --*/
  1354. {
  1355. return STATUS_SUCCESS;
  1356. }
  1357. static
  1358. STATUS
  1359. IfrParse02 (
  1360. IFR_PARSE_CONTEXT *Context
  1361. )
  1362. /*++
  1363. Routine Description:
  1364. GC_TODO: Add function description
  1365. Arguments:
  1366. Context - GC_TODO: add argument description
  1367. Returns:
  1368. GC_TODO: add return values
  1369. --*/
  1370. {
  1371. return STATUS_SUCCESS;
  1372. }
  1373. static
  1374. STATUS
  1375. IfrParse03 (
  1376. IFR_PARSE_CONTEXT *Context
  1377. )
  1378. /*++
  1379. Routine Description:
  1380. GC_TODO: Add function description
  1381. Arguments:
  1382. Context - GC_TODO: add argument description
  1383. Returns:
  1384. GC_TODO: add return values
  1385. --*/
  1386. {
  1387. return STATUS_SUCCESS;
  1388. }
  1389. //
  1390. // Parse the IFR EFI_IFR_ONE_OF opcode.
  1391. //
  1392. static
  1393. STATUS
  1394. IfrParse05 (
  1395. IFR_PARSE_CONTEXT *Context
  1396. )
  1397. /*++
  1398. Routine Description:
  1399. GC_TODO: Add function description
  1400. Arguments:
  1401. Context - GC_TODO: add argument description
  1402. Returns:
  1403. GC_TODO: add return values
  1404. --*/
  1405. {
  1406. return STATUS_SUCCESS;
  1407. }
  1408. static
  1409. STATUS
  1410. IfrParse06 (
  1411. IFR_PARSE_CONTEXT *Context
  1412. )
  1413. /*++
  1414. Routine Description:
  1415. GC_TODO: Add function description
  1416. Arguments:
  1417. Context - GC_TODO: add argument description
  1418. Returns:
  1419. GC_TODO: add return values
  1420. --*/
  1421. {
  1422. return STATUS_SUCCESS;
  1423. }
  1424. static
  1425. STATUS
  1426. IfrParse07 (
  1427. IFR_PARSE_CONTEXT *Context
  1428. )
  1429. /*++
  1430. Routine Description:
  1431. GC_TODO: Add function description
  1432. Arguments:
  1433. Context - GC_TODO: add argument description
  1434. Returns:
  1435. GC_TODO: add return values
  1436. --*/
  1437. {
  1438. return STATUS_SUCCESS;
  1439. }
  1440. static
  1441. STATUS
  1442. IfrParse08 (
  1443. IFR_PARSE_CONTEXT *Context
  1444. )
  1445. /*++
  1446. Routine Description:
  1447. GC_TODO: Add function description
  1448. Arguments:
  1449. Context - GC_TODO: add argument description
  1450. Returns:
  1451. GC_TODO: add return values
  1452. --*/
  1453. {
  1454. return STATUS_SUCCESS;
  1455. }
  1456. static
  1457. STATUS
  1458. IfrParse09 (
  1459. IFR_PARSE_CONTEXT *Context
  1460. )
  1461. /*++
  1462. Routine Description:
  1463. GC_TODO: Add function description
  1464. Arguments:
  1465. Context - GC_TODO: add argument description
  1466. Returns:
  1467. GC_TODO: add return values
  1468. --*/
  1469. {
  1470. return STATUS_SUCCESS;
  1471. }
  1472. static
  1473. STATUS
  1474. IfrParse0A (
  1475. IFR_PARSE_CONTEXT *Context
  1476. )
  1477. /*++
  1478. Routine Description:
  1479. GC_TODO: Add function description
  1480. Arguments:
  1481. Context - GC_TODO: add argument description
  1482. Returns:
  1483. GC_TODO: add return values
  1484. --*/
  1485. {
  1486. return STATUS_SUCCESS;
  1487. }
  1488. static
  1489. STATUS
  1490. IfrParse0B (
  1491. IFR_PARSE_CONTEXT *Context
  1492. )
  1493. /*++
  1494. Routine Description:
  1495. GC_TODO: Add function description
  1496. Arguments:
  1497. Context - GC_TODO: add argument description
  1498. Returns:
  1499. GC_TODO: add return values
  1500. --*/
  1501. {
  1502. return STATUS_SUCCESS;
  1503. }
  1504. static
  1505. STATUS
  1506. IfrParse0C (
  1507. IFR_PARSE_CONTEXT *Context
  1508. )
  1509. /*++
  1510. Routine Description:
  1511. GC_TODO: Add function description
  1512. Arguments:
  1513. Context - GC_TODO: add argument description
  1514. Returns:
  1515. GC_TODO: add return values
  1516. --*/
  1517. {
  1518. return STATUS_SUCCESS;
  1519. }
  1520. static
  1521. STATUS
  1522. IfrParse0D (
  1523. IFR_PARSE_CONTEXT *Context
  1524. )
  1525. /*++
  1526. Routine Description:
  1527. GC_TODO: Add function description
  1528. Arguments:
  1529. Context - GC_TODO: add argument description
  1530. Returns:
  1531. GC_TODO: add return values
  1532. --*/
  1533. {
  1534. return STATUS_SUCCESS;
  1535. }
  1536. static
  1537. STATUS
  1538. IfrParse0E (
  1539. IFR_PARSE_CONTEXT *Context
  1540. )
  1541. /*++
  1542. Routine Description:
  1543. GC_TODO: Add function description
  1544. Arguments:
  1545. Context - GC_TODO: add argument description
  1546. Returns:
  1547. GC_TODO: add return values
  1548. --*/
  1549. {
  1550. EFI_IFR_FORM_SET *Op;
  1551. Op = (EFI_IFR_FORM_SET *) Context->LastIfr->RawIfrHeader;
  1552. Context->LastIfr->VarStoreGuid1 = &Op->Guid;
  1553. Context->LastIfr->VarStoreName1 = "Setup";
  1554. Context->FormsetGuid = &Op->Guid;
  1555. return STATUS_SUCCESS;
  1556. }
  1557. static
  1558. STATUS
  1559. IfrParse0F (
  1560. IFR_PARSE_CONTEXT *Context
  1561. )
  1562. /*++
  1563. Routine Description:
  1564. GC_TODO: Add function description
  1565. Arguments:
  1566. Context - GC_TODO: add argument description
  1567. Returns:
  1568. GC_TODO: add return values
  1569. --*/
  1570. {
  1571. return STATUS_SUCCESS;
  1572. }
  1573. static
  1574. STATUS
  1575. IfrParse10 (
  1576. IFR_PARSE_CONTEXT *Context
  1577. )
  1578. /*++
  1579. Routine Description:
  1580. GC_TODO: Add function description
  1581. Arguments:
  1582. Context - GC_TODO: add argument description
  1583. Returns:
  1584. GC_TODO: add return values
  1585. --*/
  1586. {
  1587. return STATUS_SUCCESS;
  1588. }
  1589. static
  1590. STATUS
  1591. IfrParse11 (
  1592. IFR_PARSE_CONTEXT *Context
  1593. )
  1594. /*++
  1595. Routine Description:
  1596. GC_TODO: Add function description
  1597. Arguments:
  1598. Context - GC_TODO: add argument description
  1599. Returns:
  1600. GC_TODO: add return values
  1601. --*/
  1602. {
  1603. return STATUS_SUCCESS;
  1604. }
  1605. static
  1606. STATUS
  1607. IfrParse12 (
  1608. IFR_PARSE_CONTEXT *Context
  1609. )
  1610. /*++
  1611. Routine Description:
  1612. GC_TODO: Add function description
  1613. Arguments:
  1614. Context - GC_TODO: add argument description
  1615. Returns:
  1616. GC_TODO: add return values
  1617. --*/
  1618. {
  1619. return STATUS_SUCCESS;
  1620. }
  1621. static
  1622. STATUS
  1623. IfrParse13 (
  1624. IFR_PARSE_CONTEXT *Context
  1625. )
  1626. /*++
  1627. Routine Description:
  1628. GC_TODO: Add function description
  1629. Arguments:
  1630. Context - GC_TODO: add argument description
  1631. Returns:
  1632. GC_TODO: add return values
  1633. --*/
  1634. {
  1635. return STATUS_SUCCESS;
  1636. }
  1637. static
  1638. STATUS
  1639. IfrParse14 (
  1640. IFR_PARSE_CONTEXT *Context
  1641. )
  1642. /*++
  1643. Routine Description:
  1644. GC_TODO: Add function description
  1645. Arguments:
  1646. Context - GC_TODO: add argument description
  1647. Returns:
  1648. GC_TODO: add return values
  1649. --*/
  1650. {
  1651. return STATUS_SUCCESS;
  1652. }
  1653. static
  1654. STATUS
  1655. IfrParse15 (
  1656. IFR_PARSE_CONTEXT *Context
  1657. )
  1658. /*++
  1659. Routine Description:
  1660. GC_TODO: Add function description
  1661. Arguments:
  1662. Context - GC_TODO: add argument description
  1663. Returns:
  1664. GC_TODO: add return values
  1665. --*/
  1666. {
  1667. return STATUS_SUCCESS;
  1668. }
  1669. static
  1670. STATUS
  1671. IfrParse16 (
  1672. IFR_PARSE_CONTEXT *Context
  1673. )
  1674. /*++
  1675. Routine Description:
  1676. GC_TODO: Add function description
  1677. Arguments:
  1678. Context - GC_TODO: add argument description
  1679. Returns:
  1680. GC_TODO: add return values
  1681. --*/
  1682. {
  1683. return STATUS_SUCCESS;
  1684. }
  1685. static
  1686. STATUS
  1687. IfrParse17 (
  1688. IFR_PARSE_CONTEXT *Context
  1689. )
  1690. /*++
  1691. Routine Description:
  1692. GC_TODO: Add function description
  1693. Arguments:
  1694. Context - GC_TODO: add argument description
  1695. Returns:
  1696. GC_TODO: add return values
  1697. --*/
  1698. {
  1699. return STATUS_SUCCESS;
  1700. }
  1701. static
  1702. STATUS
  1703. IfrParse18 (
  1704. IFR_PARSE_CONTEXT *Context
  1705. )
  1706. /*++
  1707. Routine Description:
  1708. GC_TODO: Add function description
  1709. Arguments:
  1710. Context - GC_TODO: add argument description
  1711. Returns:
  1712. GC_TODO: add return values
  1713. --*/
  1714. {
  1715. return STATUS_SUCCESS;
  1716. }
  1717. static
  1718. STATUS
  1719. IfrParse19 (
  1720. IFR_PARSE_CONTEXT *Context
  1721. )
  1722. /*++
  1723. Routine Description:
  1724. GC_TODO: Add function description
  1725. Arguments:
  1726. Context - GC_TODO: add argument description
  1727. Returns:
  1728. GC_TODO: add return values
  1729. --*/
  1730. {
  1731. return STATUS_SUCCESS;
  1732. }
  1733. static
  1734. STATUS
  1735. IfrParse1A (
  1736. IFR_PARSE_CONTEXT *Context
  1737. )
  1738. /*++
  1739. Routine Description:
  1740. GC_TODO: Add function description
  1741. Arguments:
  1742. Context - GC_TODO: add argument description
  1743. Returns:
  1744. GC_TODO: add return values
  1745. --*/
  1746. {
  1747. return STATUS_SUCCESS;
  1748. }
  1749. static
  1750. STATUS
  1751. IfrParse1B (
  1752. IFR_PARSE_CONTEXT *Context
  1753. )
  1754. /*++
  1755. Routine Description:
  1756. GC_TODO: Add function description
  1757. Arguments:
  1758. Context - GC_TODO: add argument description
  1759. Returns:
  1760. GC_TODO: add return values
  1761. --*/
  1762. {
  1763. return STATUS_SUCCESS;
  1764. }
  1765. static
  1766. STATUS
  1767. IfrParse1C (
  1768. IFR_PARSE_CONTEXT *Context
  1769. )
  1770. /*++
  1771. Routine Description:
  1772. GC_TODO: Add function description
  1773. Arguments:
  1774. Context - GC_TODO: add argument description
  1775. Returns:
  1776. GC_TODO: add return values
  1777. --*/
  1778. {
  1779. return STATUS_SUCCESS;
  1780. }
  1781. static
  1782. STATUS
  1783. IfrParse1D (
  1784. IFR_PARSE_CONTEXT *Context
  1785. )
  1786. /*++
  1787. Routine Description:
  1788. GC_TODO: Add function description
  1789. Arguments:
  1790. Context - GC_TODO: add argument description
  1791. Returns:
  1792. GC_TODO: add return values
  1793. --*/
  1794. {
  1795. return STATUS_SUCCESS;
  1796. }
  1797. static
  1798. STATUS
  1799. IfrParse1E (
  1800. IFR_PARSE_CONTEXT *Context
  1801. )
  1802. /*++
  1803. Routine Description:
  1804. GC_TODO: Add function description
  1805. Arguments:
  1806. Context - GC_TODO: add argument description
  1807. Returns:
  1808. GC_TODO: add return values
  1809. --*/
  1810. {
  1811. return STATUS_SUCCESS;
  1812. }
  1813. static
  1814. STATUS
  1815. IfrParse1F (
  1816. IFR_PARSE_CONTEXT *Context
  1817. )
  1818. /*++
  1819. Routine Description:
  1820. GC_TODO: Add function description
  1821. Arguments:
  1822. Context - GC_TODO: add argument description
  1823. Returns:
  1824. GC_TODO: add return values
  1825. --*/
  1826. {
  1827. return STATUS_SUCCESS;
  1828. }
  1829. static
  1830. STATUS
  1831. IfrParse20 (
  1832. IFR_PARSE_CONTEXT *Context
  1833. )
  1834. /*++
  1835. Routine Description:
  1836. GC_TODO: Add function description
  1837. Arguments:
  1838. Context - GC_TODO: add argument description
  1839. Returns:
  1840. GC_TODO: add return values
  1841. --*/
  1842. {
  1843. return STATUS_SUCCESS;
  1844. }
  1845. static
  1846. STATUS
  1847. IfrParse21 (
  1848. IFR_PARSE_CONTEXT *Context
  1849. )
  1850. /*++
  1851. Routine Description:
  1852. GC_TODO: Add function description
  1853. Arguments:
  1854. Context - GC_TODO: add argument description
  1855. Returns:
  1856. GC_TODO: add return values
  1857. --*/
  1858. {
  1859. return STATUS_SUCCESS;
  1860. }
  1861. static
  1862. STATUS
  1863. IfrParse22 (
  1864. IFR_PARSE_CONTEXT *Context
  1865. )
  1866. /*++
  1867. Routine Description:
  1868. GC_TODO: Add function description
  1869. Arguments:
  1870. Context - GC_TODO: add argument description
  1871. Returns:
  1872. GC_TODO: add return values
  1873. --*/
  1874. {
  1875. return STATUS_SUCCESS;
  1876. }
  1877. static
  1878. STATUS
  1879. IfrParse23 (
  1880. IFR_PARSE_CONTEXT *Context
  1881. )
  1882. /*++
  1883. Routine Description:
  1884. GC_TODO: Add function description
  1885. Arguments:
  1886. Context - GC_TODO: add argument description
  1887. Returns:
  1888. GC_TODO: add return values
  1889. --*/
  1890. {
  1891. return STATUS_SUCCESS;
  1892. }
  1893. //
  1894. // EFI_IFR_VARSTORE
  1895. //
  1896. static
  1897. STATUS
  1898. IfrParse24 (
  1899. IFR_PARSE_CONTEXT *Context
  1900. )
  1901. /*++
  1902. Routine Description:
  1903. GC_TODO: Add function description
  1904. Arguments:
  1905. Context - GC_TODO: add argument description
  1906. Returns:
  1907. GC_TODO: add return values
  1908. --*/
  1909. {
  1910. EFI_IFR_VARSTORE *Op;
  1911. Op = (EFI_IFR_VARSTORE *) Context->LastIfr->RawIfrHeader;
  1912. return STATUS_SUCCESS;
  1913. }
  1914. //
  1915. // VARSTORE_SELECT
  1916. //
  1917. static
  1918. STATUS
  1919. IfrParse25 (
  1920. IFR_PARSE_CONTEXT *Context
  1921. )
  1922. /*++
  1923. Routine Description:
  1924. GC_TODO: Add function description
  1925. Arguments:
  1926. Context - GC_TODO: add argument description
  1927. Returns:
  1928. GC_TODO: add return values
  1929. --*/
  1930. {
  1931. STATUS Status;
  1932. EFI_IFR_VARSTORE_SELECT *Op;
  1933. Op = (EFI_IFR_VARSTORE_SELECT *) Context->LastIfr->RawIfrHeader;
  1934. Status = GetVarStoreInfo (Context, Op->VarId, &Context->LastIfr->VarStoreGuid1, &Context->LastIfr->VarStoreName1);
  1935. //
  1936. // VARSTORE_SELECT sets both
  1937. //
  1938. Context->LastIfr->VarStoreGuid2 = Context->LastIfr->VarStoreGuid1;
  1939. Context->LastIfr->VarStoreName2 = Context->LastIfr->VarStoreName1;
  1940. return Status;
  1941. }
  1942. //
  1943. // VARSTORE_SELECT_PAIR
  1944. //
  1945. static
  1946. STATUS
  1947. IfrParse26 (
  1948. IFR_PARSE_CONTEXT *Context
  1949. )
  1950. /*++
  1951. Routine Description:
  1952. GC_TODO: Add function description
  1953. Arguments:
  1954. Context - GC_TODO: add argument description
  1955. Returns:
  1956. GC_TODO: add return values
  1957. --*/
  1958. {
  1959. STATUS Status;
  1960. EFI_IFR_VARSTORE_SELECT_PAIR *Op;
  1961. Op = (EFI_IFR_VARSTORE_SELECT_PAIR *) Context->LastIfr->RawIfrHeader;
  1962. Status = GetVarStoreInfo (Context, Op->VarId, &Context->LastIfr->VarStoreGuid1, &Context->LastIfr->VarStoreName1);
  1963. Status = GetVarStoreInfo (
  1964. Context,
  1965. Op->SecondaryVarId,
  1966. &Context->LastIfr->VarStoreGuid2,
  1967. &Context->LastIfr->VarStoreName2
  1968. );
  1969. return Status;
  1970. }
  1971. //
  1972. // TRUE
  1973. //
  1974. static
  1975. STATUS
  1976. IfrParse27 (
  1977. IFR_PARSE_CONTEXT *Context
  1978. )
  1979. /*++
  1980. Routine Description:
  1981. GC_TODO: Add function descriptio…

Large files files are truncated, but you can click here to view the full file