summaryrefslogtreecommitdiff
path: root/IntelUndiPkg/GigUndiDxe/Hii.c
blob: a5d8ae207819aef073749be3d5c499e97849c777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
/**************************************************************************

Copyright (c) 2016, Intel Corporation

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of Intel Corporation nor the names of its contributors
      may be used to endorse or promote products derived from this software
      without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

***************************************************************************/
#include <Uefi.h>
#include <Library/PrintLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/HiiLib.h>
#include <Guid/MdeModuleHii.h>
#include <Protocol/HiiConfigRouting.h>
#include <Protocol/FormBrowser2.h>
#include <Protocol/HiiConfigAccess.h>
#include <Protocol/HiiDatabase.h>
#include <Protocol/HiiString.h>
#include "NVDataStruc.h"
#include "wol.h"



// This is the auto-generated header file that includes definitions of string IDs for HII
#include "GigUndiDxeStrDefs.h"

#include "EepromConfig.h"





#include "ComponentName.h"
#include "HiiInternalLib.h"
#include "Hii.h"

/* Global and module variables */

/* Protocol structure tentative definition */
EFI_HII_CONFIG_ACCESS_PROTOCOL gUndiHiiConfigAccess;

EFI_GUID mHiiFormGuid    = E1000_HII_FORM_GUID;
EFI_GUID mHiiDataGuid    = E1000_HII_DATA_GUID;


CHAR16 mVariableName[]    = L"UndiNVData";

STATIC BOOLEAN mBlinkLedsCalled = FALSE;

UINT32 gGuidInstance = 0;






/** This function allows a caller to extract the current configuration for one
   or more named elements from the target driver.

   @param[in]   This       Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
   @param[in]   Request    A null-terminated Unicode string in <ConfigRequest> format.
   @param[out]  Progress   On return, points to a character in the Request string.
                           Points to the string's null terminator if request was successful.
                           Points to the most recent '&' before the first failing name/value
                           pair (or the beginning of the string if the failure is in the
                           first name/value pair) if the request was not successful.
   @param[out]   Results   A null-terminated Unicode string in <ConfigAltResp> format which
                           has all values filled in for the names in the Request string.
                           String to be allocated by the called function.

   @retval   EFI_SUCCESS            The Results is filled with the requested values.
   @retval   EFI_OUT_OF_RESOURCES   Not enough memory to store the results.
   @retval   EFI_INVALID_PARAMETER  Progress is NULL
   @retval   EFI_INVALID_PARAMETER  Results is NULL
   @retval   EFI_INVALID_PARAMETER  Request is NULL, illegal syntax, or unknown name.
   @retval   EFI_DEVICE_ERROR       Failed to construct <ConfigHdr> template.
   @retval   EFI_NOT_FOUND          Routing data doesn't match any storage in this driver.
   @retval   EFI_DEVICE_ERROR       Failed to extract iSCSI configuration
   @retval   EFI_DEVICE_ERROR       Failed to extract FCoE configuration
**/
EFI_STATUS
EFIAPI
ExtractConfig (
  IN  CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  IN  CONST EFI_STRING                      Request,
  OUT EFI_STRING *                          Progress,
  OUT EFI_STRING *                          Results
  )
{
  EFI_STATUS         Status;
  UNDI_PRIVATE_DATA *UndiPrivateData;
  UINT8              AltMac[6];
  EFI_STRING         TmpString;
  UINTN              ElementOffset;
  UINTN              ElementWidth;
  UINTN              LastElementWidth;
  EFI_STRING         ConfigRequestHdr;
  EFI_STRING         ConfigRequest;
  BOOLEAN            AllocatedRequest;
  UINTN              Size;
  UINTN              BufferSize;

  if (Progress == NULL 
    || Results == NULL)
  {
    return EFI_INVALID_PARAMETER;
  }

  Status           = EFI_INVALID_PARAMETER;
  ConfigRequestHdr = NULL;
  ConfigRequest    = NULL;
  AllocatedRequest = FALSE;
  Size             = 0;

  DEBUGPRINT (HII, ("Request %s\n", Request));


  *Progress = Request;
  if ((Request != NULL) 
    && !HiiIsConfigHdrMatch (Request, &mHiiDataGuid, mVariableName))
  {
    DEBUGPRINT (HII, ("HiiIsConfigHdrMatch failed\n"));
    DEBUGWAIT (HII);
    return EFI_NOT_FOUND;
  }

  UndiPrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);


  ConfigRequest = Request;
  BufferSize = sizeof (UNDI_DRIVER_CONFIGURATION);
  if ((Request == NULL)
    || (StrStr (Request, L"OFFSET") == NULL))
  {
    
    // Request has no request element, construct full request string.
    // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
    // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator.
    ConfigRequestHdr = HiiConstructConfigHdr (&mHiiDataGuid, mVariableName, UndiPrivateData->HiiInstallHandle);
    if (ConfigRequestHdr == NULL) {
      DEBUGPRINT(HII, ("Failed to construct <ConfigHdr> template\n"));
      return EFI_DEVICE_ERROR;
    }
    Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
    ConfigRequest = AllocateZeroPool (Size);
    AllocatedRequest = TRUE;
    UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64) BufferSize);
    FreePool (ConfigRequestHdr);
  }

  // We already know the Request has a correct header. Jump over the header and
  // start parsing requested parameters
  TmpString = SkipConfigHeader (ConfigRequest);

  LastElementWidth = 0;
  ElementOffset = 0;
  ElementWidth = 0;

  // Don't read all parameters from NVM, only those included in the Request string.
  // On TM UEFI calls ExtractConfig for each individual parameter, so it would
  // cost a lot of time to read all parameters during each ExtractConfig execution.
  // Each element consists of a OFFSET, WIDTH pair.
  for (; ; ) {
    if (ElementWidth > LastElementWidth) {
      ElementWidth -= LastElementWidth;
      ElementOffset += LastElementWidth;
    } else {
      TmpString = GetNextRequestElement (TmpString, &ElementOffset, &ElementWidth);
      if (TmpString == NULL) {
        
        // No more elements in the Request string
        // If Request string is empty (contains only header) then
        // we exit the loop with error status
        break;
      }
    }

    // Assume success
    Status = EFI_SUCCESS;
    // DEBUGPRINT(HII, ("ElementOffset=%d, ElementWidth=%d\n", ElementOffset, ElementWidth));

    if (ElementOffset == UNDI_CONFIG_OFFSET (LinkSpeed)) {
      UndiPrivateData->Configuration.LinkSpeed = (UINT8) EepromGetLanSpeedStatus (UndiPrivateData);
      DEBUGPRINT (HII, ("GetLinkSpeed %d\n", UndiPrivateData->Configuration.LinkSpeed));
      LastElementWidth = UNDI_CONFIG_WIDTH (LinkSpeed);
      continue;
    }
    if (ElementOffset == UNDI_CONFIG_OFFSET (DefaultWolEnable)) {
      if (WolIsWakeOnLanSupported (UndiPrivateData)) {
        UndiPrivateData->Configuration.DefaultWolEnable = WOL_ENABLE;
      } else {
        UndiPrivateData->Configuration.DefaultWolEnable = WOL_NA;
      }
      LastElementWidth = UNDI_CONFIG_WIDTH (DefaultWolEnable);
      continue;
    }
    if (ElementOffset == UNDI_CONFIG_OFFSET (WolEnable)) {
      UndiPrivateData->Configuration.WolEnable = WolGetWakeOnLanStatusEx (UndiPrivateData);
      LastElementWidth = UNDI_CONFIG_WIDTH (WolEnable);
      continue;
    }

    if (ElementOffset == UNDI_CONFIG_OFFSET (AltMacAddr)) {
      if (UndiPrivateData->AltMacAddrSupported) {
        UINT8 MacAddr[6];
        
        // Copy Alternate MAC Address
        EepromMacAddressGet (UndiPrivateData, (UINT16 *) &MacAddr[0], (UINT16 *) &AltMac[0]);

        if ((AltMac[0] == MacAddr[0]) &&
          (AltMac[1] == MacAddr[1]) &&
          (AltMac[2] == MacAddr[2]) &&
          (AltMac[3] == MacAddr[3]) &&
          (AltMac[4] == MacAddr[4]) &&
          (AltMac[5] == MacAddr[5]))
        {
          SetMem (AltMac, sizeof (AltMac), 0);
        }
        
        // Convert it to a MAC string
        UnicodeSPrint (
          UndiPrivateData->Configuration.AltMacAddr,
          sizeof (UndiPrivateData->Configuration.AltMacAddr),
          L"%02x:%02x:%02x:%02x:%02x:%02x",
          AltMac[0],
          AltMac[1],
          AltMac[2],
          AltMac[3],
          AltMac[4],
          AltMac[5]
        );
      }
      LastElementWidth = UNDI_CONFIG_WIDTH (AltMacAddr);
      continue;
    }
    if (ElementOffset == UNDI_CONFIG_OFFSET (LinkStatus)) {
      if (IsLinkUp (&UndiPrivateData->NicInfo)) {
        UndiPrivateData->Configuration.LinkStatus = LINK_CONNECTED;
      } else {
        UndiPrivateData->Configuration.LinkStatus = LINK_DISCONNECTED;
      }
      LastElementWidth = UNDI_CONFIG_WIDTH (LinkStatus);
      continue;
    }
    if (ElementOffset == UNDI_CONFIG_OFFSET (BlinkLed)) {
    
      // Set LED blinking time to default value of 0 (don't blink)
      UndiPrivateData->Configuration.BlinkLed = 0;
      LastElementWidth = UNDI_CONFIG_WIDTH (BlinkLed);
      continue;
    }
    if (ElementOffset == UNDI_CONFIG_OFFSET (AltMacAddrSupport)) {
      UndiPrivateData->Configuration.AltMacAddrSupport = UndiPrivateData->AltMacAddrSupported;
      LastElementWidth = UNDI_CONFIG_WIDTH (AltMacAddrSupport);
      continue;
    }

    if (ElementOffset == UNDI_CONFIG_OFFSET (LinkSpeedSettingsSupported)) {
      UndiPrivateData->Configuration.LinkSpeedSettingsSupported = UndiPrivateData->LinkSpeedSettingsSupported;
      LastElementWidth = UNDI_CONFIG_WIDTH (LinkSpeedSettingsSupported);
      continue;
    }
    if (ElementOffset == UNDI_CONFIG_OFFSET (WolSettingsSupported)) {
      if (WolIsWakeOnLanSupported (UndiPrivateData)) {
        UndiPrivateData->Configuration.WolSettingsSupported = WOL_SETTINGS_SUPPORTED;
      } else {
        UndiPrivateData->Configuration.WolSettingsSupported = WOL_SETTINGS_NOT_SUPPORTED;
      }
      LastElementWidth = UNDI_CONFIG_WIDTH (WolSettingsSupported);
      continue;
    }
    
    // If we got there that means the element's offset is not on the list.
    // Assume the width is one and search again
    LastElementWidth = 1;
    continue;
  }

  if (EFI_ERROR (Status)) {
  
    // Error ocurred while reading NVM settings.
    DEBUGPRINT (CRITICAL, ("Error ocurred while reading NVM settings %r\n", Status));
    DEBUGWAIT (CRITICAL);
    goto ExitExtractError;
  }
  
  // Parameters have been correctly read from NVM. Create Result strings using
  // helper function from BIOS and exit.
  Status = UndiPrivateData->HiiConfigRouting->BlockToConfig (
                                                UndiPrivateData->HiiConfigRouting,
                                                ConfigRequest,
                                                (UINT8 *) &UndiPrivateData->Configuration,
                                                sizeof (UNDI_DRIVER_CONFIGURATION),
                                                Results,
                                                Progress
                                              );
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("BlockToConfig failed with %r\n", Status));
    DEBUGWAIT (CRITICAL);
  }

  // Set Progress string to the original request string.
  if (Request == NULL) {
    *Progress = NULL;
  } else if (StrStr (Request, L"OFFSET") == NULL) {
    *Progress = Request + StrLen (Request);
  }

ExitExtractError:

  // Free the allocated config request string.
  if (AllocatedRequest) {
    FreePool (ConfigRequest);
    ConfigRequest = NULL;
  }

  return Status;
}

/** This function processes the results of changes in configuration.

   @param[in]   This           Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
   @param[in]   Configuration  A null-terminated Unicode string in <ConfigResp> format.
   @param[out]  Progress       A pointer to a string filled in with the offset of the most
                               recent '&' before the first failing name/value pair (or the
                               beginning of the string if the failure is in the first
                               name/value pair) or the terminating NULL if all was successful.

   @retval   EFI_SUCCESS            The Results is processed successfully.
   @retval   EFI_INVALID_PARAMETER  Configuration is NULL.
   @retval   EFI_INVALID_PARAMETER  Progress is NULL.
   @retval   EFI_NOT_FOUND          Routing data doesn't match any storage in this driver.
**/
EFI_STATUS
EFIAPI
RouteConfig (
  IN  CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  IN  CONST EFI_STRING                      Configuration,
  OUT EFI_STRING *                          Progress
  )
{
  EFI_STATUS                       Status;
  UINTN                            BufferSize;
  UNDI_PRIVATE_DATA                *UndiPrivateData;

  if ((Configuration == NULL)
    || (Progress == NULL))
  {
    return EFI_INVALID_PARAMETER;
  }

  DEBUGPRINT (HII, ("Configuration %s\n", Configuration));

  if (!HiiIsConfigHdrMatch (Configuration, &mHiiDataGuid, mVariableName)) {
    *Progress = Configuration;
    return EFI_NOT_FOUND;
  }

  UndiPrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);



  // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
  BufferSize = sizeof (UNDI_DRIVER_CONFIGURATION);
  Status = UndiPrivateData->HiiConfigRouting->ConfigToBlock (
                                                UndiPrivateData->HiiConfigRouting,
                                                Configuration,
                                                (UINT8 *) &UndiPrivateData->Configuration,
                                                &BufferSize,
                                                Progress
                                              );
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("ConfigToBlock returns %r\n", Status));
    DEBUGWAIT (CRITICAL);
    goto ExitRouteError;
  }
  DEBUGPRINT (HII, ("Set WakeOnLan %d\n", UndiPrivateData->Configuration.WolEnable));

  // General Parameters
  UndiPrivateData->Configuration.WolEnable = WolEnableWakeOnLanEx (
                                               UndiPrivateData,
                                               UndiPrivateData->Configuration.WolEnable
                                             );

  DEBUGPRINT (HII, ("Set Link Speed %d\n", UndiPrivateData->Configuration.LinkSpeed));
  EepromSetLanSpeed (
    UndiPrivateData,
    UndiPrivateData->Configuration.LinkSpeed
  );

  if (UndiPrivateData->Configuration.BlinkLed > 15) {
  
    //  Report invalid parametrer value
    SetProgressString (
      Configuration,
      STRUCT_OFFSET (UNDI_DRIVER_CONFIGURATION, BlinkLed),
      Progress
    );
    goto ExitRouteError;
  } else if (UndiPrivateData->Configuration.BlinkLed > 0) {
    BlinkLeds (&UndiPrivateData->NicInfo, UndiPrivateData->Configuration.BlinkLed);
  }




ExitRouteError:
  EepromUpdateChecksum (UndiPrivateData);

  DEBUGPRINT (HII, ("RouteConfig finishes with status %r\n", Status));

  return Status;
}

/** Locates HII protocols (Database, String, FormBrowser2 and ConfigRouting)

   @param[in]   UndiPrivateData   Driver private data structure

   @retval   EFI_SUCCESS     All protocols located successfully
   @retval   EFI_NOT_FOUND   No instances of one of above protocols were found
**/
EFI_STATUS
HiiOpenProtocol (
  UNDI_PRIVATE_DATA *UndiPrivateData
  )
{
  EFI_STATUS                      Status;

  // Initialize the Hii Database handle to NULL so we can check later
  // to see whether it was installed.
  UndiPrivateData->HiiDatabase = NULL;
  UndiPrivateData->HiiString = NULL;
  UndiPrivateData->FormBrowser2 = NULL;
  UndiPrivateData->HiiConfigRouting = NULL;

  DEBUGPRINT (HII, ("Locate HII Protocol\n"));
  
  // Locate Hii Database protocol
  Status = gBS->LocateProtocol (
                  &gEfiHiiDatabaseProtocolGuid,
                  NULL,
                  (VOID **)&UndiPrivateData->HiiDatabase
                );
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("Error finding HII protocol: %r\n", Status));
    DEBUGWAIT (CRITICAL);
    return Status;
  }

  // Locate HiiString protocol
  DEBUGPRINT (HII, ("Locate HII String Protocol\n"));
  Status = gBS->LocateProtocol (
                  &gEfiHiiStringProtocolGuid,
                  NULL,
                  (VOID **)&UndiPrivateData->HiiString
                );
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("Error finding HII String protocol: %r\n", Status));
    DEBUGWAIT (CRITICAL);
    return Status;
  }

  // Locate Formbrowser2 protocol
  DEBUGPRINT (HII, ("Locate HII Form Browser Protocol\n"));
  Status = gBS->LocateProtocol (
                  &gEfiFormBrowser2ProtocolGuid,
                  NULL,
                  (VOID **)&UndiPrivateData->FormBrowser2
                );
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("Error finding HII form browser protocol: %r\n", Status));
    DEBUGWAIT (CRITICAL);
    return Status;
  }

  // Locate ConfigRouting protocol
  DEBUGPRINT (HII, ("Locate HII ConfigRouting Protocol\n"));
  Status = gBS->LocateProtocol (
                  &gEfiHiiConfigRoutingProtocolGuid,
                  NULL,
                  (VOID **)&UndiPrivateData->HiiConfigRouting
                );
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("Error finding HII ConfigRouting protocol: %r\n", Status));
    DEBUGWAIT (CRITICAL);
    return Status;
  }

  return Status;
}

/** Sets MAC ID string according to MAC type

   @param[in]   UndiPrivateData   Driver private data structure
   @param[out]  String            Pointer to string buffer for resulting MAC ID 

   @return   Matching MAC ID string written to String buffer, or "unknown"
**/
VOID
HiiSetMacIdString (
  IN  UNDI_PRIVATE_DATA *UndiPrivateData,
  OUT CHAR16 *           String
  )
{
  switch (UndiPrivateData->NicInfo.Hw.mac.type) {

#ifndef NO_82571_SUPPORT
  case e1000_82571:
    UnicodeSPrint (String, 80, L"Intel 82571");
    break;
  case e1000_82572:
    UnicodeSPrint (String, 80, L"Intel 82572");
    break;
  case e1000_82573:
    UnicodeSPrint (String, 80, L"Intel 82573");
    break;
#ifndef NO_82574_SUPPORT
  case e1000_82574:
    UnicodeSPrint (String, 80, L"Intel 82574");
    break;
  case e1000_82583:
    UnicodeSPrint (String, 80, L"Intel 82583V");
    break;
#endif /* NO_82574_SUPPORT */
#endif /* NO_82571_SUPPORT */
#ifndef NO_80003ES2LAN_SUPPORT
  case e1000_80003es2lan:
    UnicodeSPrint (String, 80, L"Intel 80003ES2LAN");
    break;
#endif /* NO_80003ES2LAN_SUPPORT */
#ifndef NO_82575_SUPPORT
  case e1000_82575:
    UnicodeSPrint (String, 80, L"Intel 82575");
    break;
  case e1000_82576:
    UnicodeSPrint (String, 80, L"Intel 82576");
    break;
#endif /* NO_82575_SUPPORT */
#ifndef NO_82580_SUPPORT
  case e1000_82580:
    UnicodeSPrint (String, 80, L"Intel 82580");
    break;
#endif /* NO_82580_SUPPORT */
  case e1000_i350:
    UnicodeSPrint (String, 80, L"Intel i350");
    break;
  case e1000_i354:
    UnicodeSPrint (String, 80, L"Intel i354");
    break;
  case e1000_i210:
    UnicodeSPrint (String, 80, L"Intel i210");
    break;
  case e1000_i211:
    UnicodeSPrint (String, 80, L"Intel i211");
    break;
  default:
    UnicodeSPrint (String, 80, L"unknown");
    break;
  }
}


/** This function performs required initialization of strings in String Package

   @param[in]   UndiPrivateData   Driver private data structure
   @param[in]   Lang              Language of the strings to retrieve and set

   @retval EFI_SUCCESS            All tasks have finished succesfully
   @retval EFI_DEVICE_ERROR       Processing error ocurred
**/
EFI_STATUS
HiiSetMenuStrings (
  UNDI_PRIVATE_DATA *UndiPrivateData,
  CHAR8 *            Lang
  )
{
  EFI_STATUS    Status = EFI_SUCCESS;
  CHAR16        *BrandString;
  CHAR16        String[HII_STRING_LEN];
  CHAR16        SubString[HII_STRING_LEN];
  UINT8         MacAddr[6];
  UINT8         AltMacAddr[6];
  EFI_STRING    SubStringTmp;
  EFI_STRING_ID StringId;

  // Do not modify x-UEFI langugage strings
  if (Lang[0] != 'x') {

    // Take the branding string of this device
    // Branding strings are not localized, use the default English branding
    // string.
    BrandString = UndiPrivateData->Brand;

    UnicodeSPrint (
      SubString,
      HII_STRING_LEN,
      L"%s",
      BrandString
    );

    UnicodeSPrint (
      SubString,
      HII_STRING_LEN,
      L"%s - %02x:%02x:%02x:%02x:%02x:%02x",
      BrandString,
      UndiPrivateData->NicInfo.Hw.mac.addr[0],
      UndiPrivateData->NicInfo.Hw.mac.addr[1],
      UndiPrivateData->NicInfo.Hw.mac.addr[2],
      UndiPrivateData->NicInfo.Hw.mac.addr[3],
      UndiPrivateData->NicInfo.Hw.mac.addr[4],
      UndiPrivateData->NicInfo.Hw.mac.addr[5]
    );
    StringId = HiiSetString (
               UndiPrivateData->HiiHandle,
               STRING_TOKEN (STR_INV_FORM_SET_TITLE),
               SubString,
               Lang
             );
    if (StringId == 0) {
      DEBUGPRINT (CRITICAL, ("IfrLibSetString error: %r\n", Status));
      DEBUGWAIT (CRITICAL);
      return EFI_DEVICE_ERROR;
    }

    // Set Factory Default MAC address
    DEBUGPRINT (HII, ("Setting MAC address\n"));

    EepromMacAddressGet (
      UndiPrivateData,
      (UINT16 *) &MacAddr[0],
      (UINT16 *) &AltMacAddr[0]
    );

    SubStringTmp = HiiGetString (
                     UndiPrivateData->HiiHandle,
                     STRING_TOKEN (STR_MAC_ADDR_TEXT),
                     Lang
                   );

    if (SubStringTmp == NULL) {
      DEBUGPRINT (CRITICAL, ("HiiGetString error\n"));
      DEBUGWAIT (CRITICAL);
      return Status;
    }

    // Fill with MAC address data
    UnicodeSPrint (
      String,
      HII_STRING_LEN,
      SubStringTmp,
      MacAddr[0],
      MacAddr[1],
      MacAddr[2],
      MacAddr[3],
      MacAddr[4],
      MacAddr[5]
    );

    // Need to free memory previously allocated by HiiGetString
    FreePool (SubStringTmp);

    StringId = HiiSetString (
                 UndiPrivateData->HiiHandle,
                 STRING_TOKEN (STR_MAC_ADDR_TEXT),
                 String,
                 Lang
               );
    if (StringId == 0) {
      DEBUGPRINT (CRITICAL, ("1:SetString error: %r\n", Status));
      DEBUGWAIT (CRITICAL);
      return EFI_DEVICE_ERROR;
    }

    // Set PCI Address
    {
      UnicodeSPrint (
        String,
        HII_STRING_LEN,
        L"%02x:%02x:%02x",
        UndiPrivateData->NicInfo.Bus,
        UndiPrivateData->NicInfo.Device,
        UndiPrivateData->NicInfo.Function
      );
    }
    StringId = HiiSetString (
                 UndiPrivateData->HiiHandle,
                 STRING_TOKEN (STR_PCI_BUS_DEV_FUNC_TEXT),
                 String,
                 Lang
               );

    if (StringId == 0) {
      DEBUGPRINT (CRITICAL, ("HiiSetString error\n"));
      DEBUGWAIT (CRITICAL);
      return EFI_DEVICE_ERROR;
    }

    // Set UEFI Driver Branding String
    ComponentNameGetDriverName (NULL, "eng", &BrandString);

    SubStringTmp = HiiGetString (
                     UndiPrivateData->HiiHandle,
                     STRING_TOKEN (STR_EFI_DRIVER_VER_TEXT),
                     Lang
                   );

    if (SubStringTmp == NULL) {
      DEBUGPRINT (CRITICAL, ("HiiGetString error\n"));
      DEBUGWAIT (CRITICAL);
      return Status;
    }

    UnicodeSPrint (String, HII_STRING_LEN, SubStringTmp, BrandString);

    FreePool (SubStringTmp);

    StringId = HiiSetString (
                 UndiPrivateData->HiiHandle,
                 STRING_TOKEN (STR_EFI_DRIVER_VER_TEXT),
                 String,
                 Lang
               );

    if (StringId == 0) {
      DEBUGPRINT (CRITICAL, ("HiiSetString error\n"));
      DEBUGWAIT (CRITICAL);
      return EFI_DEVICE_ERROR;
    }

    // Set Device Name String
    UnicodeSPrint (
      String,
      HII_STRING_LEN,
      L"%s",
      UndiPrivateData->Brand
    );

    StringId = HiiSetString (
                 UndiPrivateData->HiiHandle,
                 STRING_TOKEN (STR_DEVICE_NAME_TEXT),
                 String,
                 Lang
               );
    if (StringId == 0) {
      DEBUGPRINT (CRITICAL, ("HiiSetString error\n"));
      DEBUGWAIT (CRITICAL);
      return EFI_DEVICE_ERROR;
    }

    // Set PCI Device ID
    SubStringTmp = HiiGetString (
                     UndiPrivateData->HiiHandle,
                     STRING_TOKEN (STR_DEVICE_ID_TEXT),
                     Lang
                   );

    if (SubStringTmp == NULL) {
      DEBUGPRINT (CRITICAL, ("HiiGetString error\n"));
      DEBUGWAIT (CRITICAL);
      return Status;
    }

    UnicodeSPrint (String, HII_STRING_LEN, SubStringTmp, UndiPrivateData->NicInfo.Hw.device_id);

    FreePool (SubStringTmp);

    StringId = HiiSetString (
                 UndiPrivateData->HiiHandle,
                 STRING_TOKEN (STR_DEVICE_ID_TEXT),
                 String,
                 Lang
               );
    if (StringId == 0) {
      DEBUGPRINT (CRITICAL, ("HiiSetString error\n"));
      DEBUGWAIT (CRITICAL);
      return EFI_DEVICE_ERROR;
    }

    // Set MAC ID String, not localized, use English string.
    HiiSetMacIdString (UndiPrivateData, String);
    StringId = HiiSetString (
                 UndiPrivateData->HiiHandle,
                 STRING_TOKEN (STR_CONTROLER_ID_TEXT),
                 String,
                 Lang
               );
    if (StringId == 0) {
      DEBUGPRINT (CRITICAL, ("HiiSetString error\n"));
      DEBUGWAIT (CRITICAL);
      return EFI_DEVICE_ERROR;
    }

    // Set PBA number
    {
      CHAR8  PBAString8[MAX_PBA_STR_LENGTH];
      CHAR16 PBAString[MAX_PBA_STR_LENGTH];

      Status = ReadPbaString (
                 &UndiPrivateData->NicInfo,
                 PBAString8,
                 MAX_PBA_STR_LENGTH
               );
      if (Status == EFI_SUCCESS) {
      
        // Convert CHAR8 to CHAR16 for use with SPrint
        PBAString8[MAX_PBA_STR_LENGTH - 1] = 0;
        Status = AsciiStrToUnicodeStrWrapper (
                   PBAString8,
                   PBAString,
                   sizeof (PBAString) / sizeof (CHAR16)
                 );
        if (EFI_ERROR (Status)) {
          DEBUGPRINT (CRITICAL, ("AsciiStrToUnicodeStrWrapper error\n"));
          DEBUGWAIT (CRITICAL);
          return Status;
        }
      }
      StringId = HiiSetString (
                   UndiPrivateData->HiiHandle,
                   STRING_TOKEN (STR_ADAPTER_PBA_TEXT),
                   PBAString,
                   Lang
                 );
      if (StringId == 0) {
        DEBUGPRINT (CRITICAL, ("HiiSetString error\n"));
        DEBUGWAIT (CRITICAL);
        return EFI_DEVICE_ERROR;
      }
    }
  } 


  return Status;
}

/** Sets Link speed support and WOL settings.

   @param[in,out]   UndiPrivateData   Points to the driver instance private data.

   @retval   EFI_SUCCESS  Settings successfully applied
**/
EFI_STATUS
HiiConfigureStandardFeaturesSupport (
  IN OUT UNDI_PRIVATE_DATA *UndiPrivateData
  )
{

  // Decide about link speed options depending on link capabilities
  // of the adapter

  // Speed settings are supported for copper only
  if (UndiPrivateData->NicInfo.Hw.phy.media_type != e1000_media_type_copper) {
    UndiPrivateData->LinkSpeedSettingsSupported = FALSE;
  } else {
    UndiPrivateData->LinkSpeedSettingsSupported = TRUE;
  }
  UndiPrivateData->Configuration.WolEnable = (UINT8) WolGetWakeOnLanStatusEx (UndiPrivateData);

  return EFI_SUCCESS;
}


/** Initializes HII inventory packages

   @param[in]   UndiPrivateData   Driver private data structure

   @retval   EFI_SUCCESS            Function returned successfully
   @retval   EFI_OUT_OF_RESOURCES   Not enough resources for HII packages
   @retval   !EFI_SUCCESS           Failed to initialize HII inventory
**/
EFI_STATUS
HiiInventoryPackage (
  UNDI_PRIVATE_DATA *UndiPrivateData
  )
{
  EFI_STATUS                      Status;
  EFI_HII_PACKAGE_LIST_HEADER     *PackageList = NULL;
  CHAR8                           Lang[HII_STRING_LEN];
  CHAR8                           SubLang[HII_STRING_LEN];
  UINTN                           Size;
  UINTN                           i, j;
  UINT8                           *NGigUndiDxeStringsPtr;
  NGigUndiDxeStringsPtr = GigUndiDxeStrings;


  DEBUGPRINT (HII, ("InventoryPackage\n"));


    PackageList = HiiAddPackages (
                    &mHiiFormGuid,
                    UndiPrivateData->HiiInstallHandle,
                    NGigUndiDxeStringsPtr,
                    InventoryBin,
                    NULL
                  );
  if (PackageList == NULL) {
    DEBUGPRINT (CRITICAL, ("PreparePackageList, out of resource.\n"));
    DEBUGWAIT (CRITICAL);
    return EFI_OUT_OF_RESOURCES;
  }

  UndiPrivateData->HiiHandle = PackageList;

  Status = HiiConfigureStandardFeaturesSupport (UndiPrivateData);
  if (EFI_ERROR (Status)) {
    return Status;
  }


  // Prepare HII strings for all supported languages
  Size = HII_STRING_LEN;
  Status = UndiPrivateData->HiiString->GetLanguages (
                                         UndiPrivateData->HiiString,
                                         UndiPrivateData->HiiHandle,
                                         Lang,
                                         &Size
                                       );

  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("GetLanguages returns %r\n", Status));
    DEBUGWAIT (CRITICAL);
    return Status;
  }

  i = 0;
  while (i < Size) {
    j = 0;
    do {
      if (Lang[i] == ';') {
        SubLang[j] = '\0';
        i++;
        j++;
        break;
      } else {
        SubLang[j] = Lang[i];
        i++;
        j++;
      }

    } while (Lang[i] != '\0');

    SubLang[j] = '\0';

    // Setup strings for this language
    Status = HiiSetMenuStrings (UndiPrivateData, SubLang);

    if (EFI_ERROR (Status)) {
      DEBUGPRINT (CRITICAL, ("SetMenuStrings returns %r\n", Status));
      DEBUGWAIT (CRITICAL);
      break;
    }

    // This was the last supported language so we can exit the loop
    if (Lang[i] == '\0') {
      break;
    }
  }

  return Status;
}

/** Callback to handle request for LED blinking

   @param[in]   This        HII config access protocol current instance
   @param[in]   Action      Type of browser action
   @param[in]   QuestionId  Question ID related to specific HII content
   @param[in]   Type        Type specifying question value
   @param[in]   Value       Question value

   @retval   EFI_SUCCESS       LED blinking handled successfully
   @retval   EFI_UNSUPPORTED   Failed to get/set HII browser data
**/
EFI_STATUS
HiiBlinkLedsCallback (
  IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  IN  EFI_BROWSER_ACTION                   Action,
  IN EFI_QUESTION_ID                       QuestionId,
  IN UINT8                                 Type,
  IN EFI_IFR_TYPE_VALUE *                  Value
  )
{
  EFI_STATUS                Status;
  UNDI_PRIVATE_DATA         *UndiPrivateData;
  UNDI_DRIVER_CONFIGURATION HiiDrvConfig;

  Status = EFI_SUCCESS;

  if ((Action != EFI_BROWSER_ACTION_CHANGING) &&
    (Action != EFI_BROWSER_ACTION_CHANGED)) {
    return Status;
  }

  UndiPrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);

  ZeroMem (&HiiDrvConfig, sizeof (HiiDrvConfig));
  if (!HiiGetBrowserData (NULL, NULL, sizeof (HiiDrvConfig), (UINT8 *) &HiiDrvConfig)) {
    return EFI_UNSUPPORTED;
  }

  switch (QuestionId) {
  case QUESTION_ID_BLINK_LED:
    if (Type == EFI_IFR_TYPE_NUM_SIZE_16) {
      if ((Action == EFI_BROWSER_ACTION_CHANGING) ||
        ((Action == EFI_BROWSER_ACTION_CHANGED)
        && (!mBlinkLedsCalled)))
      {
#if defined(u16)
#undef u16
#endif /* defined(u16) */

        BlinkLeds (&UndiPrivateData->NicInfo, Value->u16);
        if (Action == EFI_BROWSER_ACTION_CHANGING) {
          mBlinkLedsCalled = TRUE;
        } else {
          mBlinkLedsCalled = FALSE;
        }
      }
      
      // After blinking the LED, always clear the Blink LEDs question back to 0.
      Value->u16 = 0;
      HiiDrvConfig.BlinkLed = 0;

      if (!HiiSetBrowserData (NULL, NULL, sizeof (HiiDrvConfig), (UINT8 *) &HiiDrvConfig, NULL)) {
        Status = EFI_UNSUPPORTED;
      }
    } else {
      Status = EFI_UNSUPPORTED;
    }
    break;
  default:
    break;
  }

  return Status;
}

/** This function processes the results of changes in configuration.

   @param[in]   This            Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
   @param[in]   Action          Specifies the type of action taken by the browser.
   @param[in]   QuestionId      A unique value which is sent to the original exporting driver
                                so that it can identify the type of data to expect.
   @param[in]   Type            The type of value for the question.
   @param[in]   Value           A pointer to the data being sent to the original exporting driver.
   @param[out]  ActionRequest   On return, points to the action requested by the callback function.

   @retval   EFI_SUCCESS           The callback successfully handled the action.
   @retval   EFI_OUT_OF_RESOURCES  Not enough storage is available to hold the variable and its data.
   @retval   EFI_DEVICE_ERROR      The variable could not be saved.
   @retval   EFI_UNSUPPORTED       The specified Action is not supported by the callback.
**/
EFI_STATUS
EFIAPI
DriverCallback (
  IN  CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  IN  EFI_BROWSER_ACTION                    Action,
  IN  EFI_QUESTION_ID                       QuestionId,
  IN  UINT8                                 Type,
  IN  EFI_IFR_TYPE_VALUE *                  Value,
  OUT EFI_BROWSER_ACTION_REQUEST *          ActionRequest
  )
{
  EFI_STATUS Status;

  DEBUGPRINT (HII, ("Action=%d, QuestionId=%d, Type=%d\n", Action, QuestionId, Type));

  if ((Value == NULL) 
    || (ActionRequest == NULL))
  {
    return EFI_INVALID_PARAMETER;
  }

  *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;

  switch (Action) {
  case EFI_BROWSER_ACTION_CHANGING:
    Status = HiiBlinkLedsCallback (This, Action, QuestionId, Type, Value);
    if (EFI_ERROR (Status)) {
      break;
    }
    break;
  case EFI_BROWSER_ACTION_CHANGED:
    Status = HiiBlinkLedsCallback (This, Action, QuestionId, Type, Value);
    if (EFI_ERROR (Status)) {
      break;
    }
    break;
  case EFI_BROWSER_ACTION_FORM_OPEN:
  case EFI_BROWSER_ACTION_FORM_CLOSE:
    Status = EFI_SUCCESS;
    break;
  default:
    Status = EFI_UNSUPPORTED;
    break;
  }

  return Status;
}

/** Installs the HII user interface screen in the UEFI device manager.

   @param[in]   UndiPrivateData   Points to the driver instance private data.

   @retval   EFI_SUCCESS     HII interface installed correctly
   @retval   !EFI_SUCCESS    Failed to install HII interface
**/
EFI_STATUS
EFIAPI
HiiInit (
  IN UNDI_PRIVATE_DATA *UndiPrivateData
  )
{
  EFI_STATUS                      Status;
  EFI_SCREEN_DESCRIPTOR           Screen;

  DEBUGPRINT (HII, ("HiiInit\n"));

  // Try to open the HII protocols first.  If they are not present in the system
  // get out.
  Status = HiiOpenProtocol (UndiPrivateData);
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("HiiOpenProtocol returns: %x\n", Status));
    DEBUGWAIT (CRITICAL);
    return Status;
  }

  // Initialize screen dimensions for SendForm().
  // Remove 3 characters from top and bottom
  ZeroMem (&Screen, sizeof (EFI_SCREEN_DESCRIPTOR));
  gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Screen.RightColumn, &Screen.BottomRow);

  Screen.TopRow     = 3;
  Screen.BottomRow  = Screen.BottomRow - 3;

  UndiPrivateData->ConfigAccess = gUndiHiiConfigAccess;

  UndiPrivateData->HiiInstallHandle = UndiPrivateData->DeviceHandle;

  Status = gBS->InstallProtocolInterface (
                  &UndiPrivateData->HiiInstallHandle,
                  &gEfiHiiConfigAccessProtocolGuid,
                  EFI_NATIVE_INTERFACE,
                  &UndiPrivateData->ConfigAccess
                );
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("InstallProtocolInterface error: %r\n", Status));
    DEBUGWAIT (CRITICAL);
  }

  Status = HiiInventoryPackage (UndiPrivateData);
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("InventoryPackage returns: %r\n", Status));
    DEBUGWAIT (CRITICAL);
    return Status;
  }

  // Initialize configuration data
  DEBUGPRINT (HII, ("initialize configuration data\n"));
  ZeroMem (&UndiPrivateData->Configuration, sizeof (UNDI_DRIVER_CONFIGURATION));

  DEBUGPRINT (HII, ("HiiInit is complete\n"));

  return EFI_SUCCESS;
}

/** HII uninstalls the HII user interface screen in the UEFI device manager.

   @param[in]   UndiPrivateData   Points to the driver instance private data.

   @retval   EFI_SUCCESS    HII interface uninstalled correctly
   @retval   !EFI_SUCCESS   Failed to uninstall HII interface
**/
EFI_STATUS
EFIAPI
HiiUnload (
  IN UNDI_PRIVATE_DATA *UndiPrivateData
  )
{
  EFI_STATUS                      Status;

  if ((UndiPrivateData->HiiDatabase == NULL) ||
    (UndiPrivateData->HiiString == NULL) ||
    (UndiPrivateData->FormBrowser2 == NULL) ||
    (UndiPrivateData->HiiConfigRouting == NULL))
  {
    DEBUGPRINT (HII, ("HII Not initialized, returning.\n"));
    return EFI_SUCCESS;
  }

  DEBUGPRINT (HII, ("Calling RemovePackageList: %X\n", UndiPrivateData->HiiDatabase));
  Status = UndiPrivateData->HiiDatabase->RemovePackageList (
                                           UndiPrivateData->HiiDatabase,
                                           UndiPrivateData->HiiHandle
                                         );
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("RemovePackageList error: %r\n", Status));
    DEBUGWAIT (CRITICAL);
    return Status;
  }

  Status = gBS->UninstallProtocolInterface (
                  UndiPrivateData->HiiInstallHandle,
                  &gEfiHiiConfigAccessProtocolGuid,
                  &UndiPrivateData->ConfigAccess
                );
  if (EFI_ERROR (Status)) {
    DEBUGPRINT (CRITICAL, ("UninstallProtocolInterface error: %r\n", Status));
    DEBUGWAIT (CRITICAL);
  }

  return Status;
}

/* Protocol structure definition and initialization */

EFI_HII_CONFIG_ACCESS_PROTOCOL gUndiHiiConfigAccess = {
  ExtractConfig,
  RouteConfig,
  DriverCallback
};