]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Application/UiApp/DeviceMngr/DeviceManager.c
MdeModulePkg:Create Boot Maintenance Manager Library
[mirror_edk2.git] / MdeModulePkg / Application / UiApp / DeviceMngr / DeviceManager.c
1 /** @file
2 The platform device manager reference implementation
3
4 Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "DeviceManager.h"
16
17 DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate = {
18 DEVICE_MANAGER_CALLBACK_DATA_SIGNATURE,
19 NULL,
20 NULL,
21 {
22 FakeExtractConfig,
23 FakeRouteConfig,
24 DeviceManagerCallback
25 }
26 };
27
28 #define MAX_MAC_ADDRESS_NODE_LIST_LEN 10
29
30 EFI_GUID mDeviceManagerGuid = DEVICE_MANAGER_FORMSET_GUID;
31
32 //
33 // Which Mac Address string is select
34 // it will decide what menu need to show in the NETWORK_DEVICE_FORM_ID form.
35 //
36 EFI_STRING mSelectedMacAddrString;
37
38 //
39 // The Mac Address show in the NETWORK_DEVICE_LIST_FORM_ID
40 //
41 MAC_ADDRESS_NODE_LIST mMacDeviceList;
42
43 DEVICE_MANAGER_MENU_ITEM mDeviceManagerMenuItemTable[] = {
44 { STRING_TOKEN (STR_DISK_DEVICE), EFI_DISK_DEVICE_CLASS },
45 { STRING_TOKEN (STR_VIDEO_DEVICE), EFI_VIDEO_DEVICE_CLASS },
46 { STRING_TOKEN (STR_NETWORK_DEVICE), EFI_NETWORK_DEVICE_CLASS },
47 { STRING_TOKEN (STR_INPUT_DEVICE), EFI_INPUT_DEVICE_CLASS },
48 { STRING_TOKEN (STR_ON_BOARD_DEVICE), EFI_ON_BOARD_DEVICE_CLASS },
49 { STRING_TOKEN (STR_OTHER_DEVICE), EFI_OTHER_DEVICE_CLASS }
50 };
51
52 HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath = {
53 {
54 {
55 HARDWARE_DEVICE_PATH,
56 HW_VENDOR_DP,
57 {
58 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
59 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
60 }
61 },
62 //
63 // {102579A0-3686-466e-ACD8-80C087044F4A}
64 //
65 { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }
66 },
67 {
68 END_DEVICE_PATH_TYPE,
69 END_ENTIRE_DEVICE_PATH_SUBTYPE,
70 {
71 (UINT8) (END_DEVICE_PATH_LENGTH),
72 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
73 }
74 }
75 };
76
77 /**
78 This function is invoked if user selected a interactive opcode from Device Manager's
79 Formset. If user set VBIOS, the new value is saved to EFI variable.
80
81 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
82 @param Action Specifies the type of action taken by the browser.
83 @param QuestionId A unique value which is sent to the original exporting driver
84 so that it can identify the type of data to expect.
85 @param Type The type of value for the question.
86 @param Value A pointer to the data being sent to the original exporting driver.
87 @param ActionRequest On return, points to the action requested by the callback function.
88
89 @retval EFI_SUCCESS The callback successfully handled the action.
90 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
91
92 **/
93 EFI_STATUS
94 EFIAPI
95 DeviceManagerCallback (
96 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
97 IN EFI_BROWSER_ACTION Action,
98 IN EFI_QUESTION_ID QuestionId,
99 IN UINT8 Type,
100 IN EFI_IFR_TYPE_VALUE *Value,
101 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
102 )
103 {
104 UINTN CurIndex;
105
106 if (Action != EFI_BROWSER_ACTION_CHANGING) {
107 //
108 // Do nothing for other UEFI Action. Only do call back when data is changed.
109 //
110 return EFI_UNSUPPORTED;
111 }
112
113 if ((Value == NULL) || (ActionRequest == NULL)) {
114 return EFI_INVALID_PARAMETER;
115 }
116 if ((QuestionId < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET) && (QuestionId >= NETWORK_DEVICE_LIST_KEY_OFFSET)) {
117 //
118 // If user select the mac address, need to record mac address string to support next form show.
119 //
120 for (CurIndex = 0; CurIndex < mMacDeviceList.CurListLen; CurIndex ++) {
121 if (mMacDeviceList.NodeList[CurIndex].QuestionId == QuestionId) {
122 mSelectedMacAddrString = HiiGetString (gDeviceManagerPrivate.HiiHandle, mMacDeviceList.NodeList[CurIndex].PromptId, NULL);
123 }
124 }
125 CreateDeviceManagerForm(NETWORK_DEVICE_FORM_ID);
126 } else if(QuestionId == QUESTION_NETWORK_DEVICE_ID){
127 CreateDeviceManagerForm(NETWORK_DEVICE_LIST_FORM_ID);
128 }
129
130 return EFI_SUCCESS;
131 }
132
133 /**
134 Get the mac address string from the device path.
135 if the device path has the vlan, get the vanid also.
136
137 @param MacAddressNode Device path begin with mac address
138 @param PBuffer Output string buffer contain mac address.
139
140 **/
141 BOOLEAN
142 GetMacAddressString(
143 IN MAC_ADDR_DEVICE_PATH *MacAddressNode,
144 OUT CHAR16 **PBuffer
145 )
146 {
147 UINTN HwAddressSize;
148 UINTN Index;
149 UINT8 *HwAddress;
150 EFI_DEVICE_PATH_PROTOCOL *Node;
151 UINT16 VlanId;
152 CHAR16 *String;
153 UINTN BufferLen;
154
155 VlanId = 0;
156 String = NULL;
157 ASSERT(MacAddressNode != NULL);
158
159 HwAddressSize = sizeof (EFI_MAC_ADDRESS);
160 if (MacAddressNode->IfType == 0x01 || MacAddressNode->IfType == 0x00) {
161 HwAddressSize = 6;
162 }
163
164 //
165 // The output format is MAC:XX:XX:XX:...\XXXX
166 // The size is the Number size + ":" size + Vlan size(\XXXX) + End
167 //
168 BufferLen = (4 + 2 * HwAddressSize + (HwAddressSize - 1) + 5 + 1) * sizeof (CHAR16);
169 String = AllocateZeroPool (BufferLen);
170 if (String == NULL) {
171 return FALSE;
172 }
173
174 *PBuffer = String;
175 StrCpyS(String, BufferLen / sizeof (CHAR16), L"MAC:");
176 String += 4;
177
178 //
179 // Convert the MAC address into a unicode string.
180 //
181 HwAddress = &MacAddressNode->MacAddress.Addr[0];
182 for (Index = 0; Index < HwAddressSize; Index++) {
183 String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2);
184 if (Index < HwAddressSize - 1) {
185 *String++ = L':';
186 }
187 }
188
189 //
190 // If VLAN is configured, it will need extra 5 characters like "\0005".
191 // Plus one unicode character for the null-terminator.
192 //
193 Node = (EFI_DEVICE_PATH_PROTOCOL *)MacAddressNode;
194 while (!IsDevicePathEnd (Node)) {
195 if (Node->Type == MESSAGING_DEVICE_PATH && Node->SubType == MSG_VLAN_DP) {
196 VlanId = ((VLAN_DEVICE_PATH *) Node)->VlanId;
197 }
198 Node = NextDevicePathNode (Node);
199 }
200
201 if (VlanId != 0) {
202 *String++ = L'\\';
203 String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, VlanId, 4);
204 }
205
206 //
207 // Null terminate the Unicode string
208 //
209 *String = L'\0';
210
211 return TRUE;
212 }
213
214 /**
215 Save question id and prompt id to the mac device list.
216 If the same mac address has saved yet, no need to add more.
217
218 @param MacAddrString Mac address string.
219
220 @retval EFI_SUCCESS Add the item is successful.
221 @return Other values if failed to Add the item.
222 **/
223 BOOLEAN
224 AddIdToMacDeviceList (
225 IN EFI_STRING MacAddrString
226 )
227 {
228 MENU_INFO_ITEM *TempDeviceList;
229 UINTN Index;
230 EFI_STRING StoredString;
231 EFI_STRING_ID PromptId;
232 EFI_HII_HANDLE HiiHandle;
233
234 HiiHandle = gDeviceManagerPrivate.HiiHandle;
235 TempDeviceList = NULL;
236
237 for (Index = 0; Index < mMacDeviceList.CurListLen; Index ++) {
238 StoredString = HiiGetString (HiiHandle, mMacDeviceList.NodeList[Index].PromptId, NULL);
239 if (StoredString == NULL) {
240 return FALSE;
241 }
242
243 //
244 // Already has save the same mac address to the list.
245 //
246 if (StrCmp (MacAddrString, StoredString) == 0) {
247 return FALSE;
248 }
249 }
250
251 PromptId = HiiSetString(HiiHandle, 0, MacAddrString, NULL);
252 //
253 // If not in the list, save it.
254 //
255 if (mMacDeviceList.MaxListLen > mMacDeviceList.CurListLen + 1) {
256 mMacDeviceList.NodeList[mMacDeviceList.CurListLen].PromptId = PromptId;
257 mMacDeviceList.NodeList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);
258 } else {
259 mMacDeviceList.MaxListLen += MAX_MAC_ADDRESS_NODE_LIST_LEN;
260 if (mMacDeviceList.CurListLen != 0) {
261 TempDeviceList = (MENU_INFO_ITEM *)AllocateCopyPool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen, (VOID *)mMacDeviceList.NodeList);
262 } else {
263 TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen);
264 }
265
266 if (TempDeviceList == NULL) {
267 return FALSE;
268 }
269 TempDeviceList[mMacDeviceList.CurListLen].PromptId = PromptId;
270 TempDeviceList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);
271
272 if (mMacDeviceList.CurListLen > 0) {
273 FreePool(mMacDeviceList.NodeList);
274 }
275
276 mMacDeviceList.NodeList = TempDeviceList;
277 }
278 mMacDeviceList.CurListLen ++;
279
280 return TRUE;
281 }
282
283 /**
284 Check the devcie path, try to find whether it has mac address path.
285
286 In this function, first need to check whether this path has mac address path.
287 second, when the mac address device path has find, also need to deicide whether
288 need to add this mac address relate info to the menu.
289
290 @param *Node Input device which need to be check.
291 @param NextShowFormId FormId Which need to be show.
292 @param *NeedAddItem Whether need to add the menu in the network device list.
293
294 @retval TRUE Has mac address device path.
295 @retval FALSE NOT Has mac address device path.
296
297 **/
298 BOOLEAN
299 IsMacAddressDevicePath (
300 IN VOID *Node,
301 IN EFI_FORM_ID NextShowFormId,
302 OUT BOOLEAN *NeedAddItem
303 )
304 {
305 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
306 CHAR16 *Buffer;
307 BOOLEAN ReturnVal;
308
309 ASSERT (Node != NULL);
310 *NeedAddItem = FALSE;
311 ReturnVal = FALSE;
312 Buffer = NULL;
313
314 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;
315
316 //
317 // find the partition device path node
318 //
319 while (!IsDevicePathEnd (DevicePath)) {
320 if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
321 (DevicePathSubType (DevicePath) == MSG_MAC_ADDR_DP)) {
322 ReturnVal = TRUE;
323
324 if (DEVICE_MANAGER_FORM_ID == NextShowFormId) {
325 *NeedAddItem = TRUE;
326 break;
327 }
328
329 if (!GetMacAddressString((MAC_ADDR_DEVICE_PATH*)DevicePath, &Buffer)) {
330 break;
331 }
332
333 if (NETWORK_DEVICE_FORM_ID == NextShowFormId) {
334 if (StrCmp (Buffer, mSelectedMacAddrString) == 0) {
335 *NeedAddItem = TRUE;
336 }
337 break;
338 }
339
340 if (NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) {
341 //
342 // Same handle may has two network child handle, so the questionid
343 // has the offset of SAME_HANDLE_KEY_OFFSET.
344 //
345 if (AddIdToMacDeviceList (Buffer)) {
346 *NeedAddItem = TRUE;
347 }
348 break;
349 }
350 }
351 DevicePath = NextDevicePathNode (DevicePath);
352 }
353
354 if (Buffer != NULL) {
355 FreePool (Buffer);
356 }
357
358 return ReturnVal;
359 }
360
361 /**
362 Check to see if the device path is for the network device.
363
364 @param Handle The HII handle which include the mac address device path.
365 @param NextShowFormId The FormId of the form which will be show next time.
366 @param ItemCount The new add Mac address item count.
367
368 @retval TRUE Need to add new item in the menu.
369 @return FALSE Do not need to add the menu about the network.
370
371 **/
372 BOOLEAN
373 IsNeedAddNetworkMenu (
374 IN EFI_HII_HANDLE Handle,
375 IN EFI_FORM_ID NextShowFormId,
376 OUT UINTN *ItemCount
377 )
378 {
379 EFI_STATUS Status;
380 UINTN EntryCount;
381 UINTN Index;
382 EFI_HII_HANDLE HiiDeviceManagerHandle;
383 EFI_HANDLE DriverHandle;
384 EFI_HANDLE ControllerHandle;
385 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
386 EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
387 EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;
388 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
389 BOOLEAN IsNeedAdd;
390
391 HiiDeviceManagerHandle = gDeviceManagerPrivate.HiiHandle;
392 IsNeedAdd = FALSE;
393 OpenInfoBuffer = NULL;
394 if ((Handle == NULL) || (ItemCount == NULL)) {
395 return FALSE;
396 }
397 *ItemCount = 0;
398
399 Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);
400 if (EFI_ERROR (Status)) {
401 return FALSE;
402 }
403 //
404 // Get the device path by the got Driver handle .
405 //
406 Status = gBS->HandleProtocol (DriverHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath);
407 if (EFI_ERROR (Status)) {
408 return FALSE;
409 }
410 TmpDevicePath = DevicePath;
411
412 //
413 // Check whether this device path include mac address device path.
414 // If this path has mac address path, get the value whether need
415 // add this info to the menu and return.
416 // Else check more about the child handle devcie path.
417 //
418 if (IsMacAddressDevicePath(TmpDevicePath, NextShowFormId,&IsNeedAdd)) {
419 if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) && IsNeedAdd) {
420 (*ItemCount) = 1;
421 }
422 return IsNeedAdd;
423 }
424
425 //
426 // Search whether this path is the controller path, not he child handle path.
427 // And the child handle has the network devcie connected.
428 //
429 TmpDevicePath = DevicePath;
430 Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid, &TmpDevicePath, &ControllerHandle);
431 if (EFI_ERROR (Status)) {
432 return FALSE;
433 }
434
435 if (!IsDevicePathEnd (TmpDevicePath)) {
436 return FALSE;
437 }
438
439 //
440 // Retrieve the list of agents that are consuming the specific protocol
441 // on ControllerHandle.
442 // The buffer point by OpenInfoBuffer need be free at this function.
443 //
444 Status = gBS->OpenProtocolInformation (
445 ControllerHandle,
446 &gEfiPciIoProtocolGuid,
447 &OpenInfoBuffer,
448 &EntryCount
449 );
450 if (EFI_ERROR (Status)) {
451 return FALSE;
452 }
453
454 //
455 // Inspect if ChildHandle is one of the agents.
456 //
457 Status = EFI_UNSUPPORTED;
458 for (Index = 0; Index < EntryCount; Index++) {
459 //
460 // Query all the children created by the controller handle's driver
461 //
462 if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
463 Status = gBS->OpenProtocol (
464 OpenInfoBuffer[Index].ControllerHandle,
465 &gEfiDevicePathProtocolGuid,
466 (VOID **) &ChildDevicePath,
467 NULL,
468 NULL,
469 EFI_OPEN_PROTOCOL_GET_PROTOCOL
470 );
471 if (EFI_ERROR (Status)) {
472 continue;
473 }
474
475 //
476 // Check whether this device path include mac address device path.
477 //
478 if (!IsMacAddressDevicePath(ChildDevicePath, NextShowFormId,&IsNeedAdd)) {
479 //
480 // If this path not has mac address path, check the other.
481 //
482 continue;
483 } else {
484 //
485 // If need to update the NETWORK_DEVICE_LIST_FORM, try to get more.
486 //
487 if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId)) {
488 if (IsNeedAdd) {
489 (*ItemCount) += 1;
490 }
491 continue;
492 } else {
493 //
494 // If need to update other form, return whether need to add to the menu.
495 //
496 goto Done;
497 }
498 }
499 }
500 }
501
502 Done:
503 if (OpenInfoBuffer != NULL) {
504 FreePool (OpenInfoBuffer);
505 }
506 return IsNeedAdd;
507 }
508
509 /**
510 This function registers HII packages to HII database.
511
512 **/
513 VOID
514 InitializeDeviceManager (
515 VOID
516 )
517 {
518 EFI_STATUS Status;
519
520 if (!gConnectAllHappened){
521 EfiBootManagerConnectAll();
522 gConnectAllHappened = TRUE;
523 }
524
525 gDeviceManagerPrivate.DriverHandle = NULL;
526 Status = gBS->InstallMultipleProtocolInterfaces (
527 &gDeviceManagerPrivate.DriverHandle,
528 &gEfiDevicePathProtocolGuid,
529 &mDeviceManagerHiiVendorDevicePath,
530 &gEfiHiiConfigAccessProtocolGuid,
531 &gDeviceManagerPrivate.ConfigAccess,
532 NULL
533 );
534 ASSERT_EFI_ERROR (Status);
535
536 //
537 // Publish our HII data.
538 //
539 gDeviceManagerPrivate.HiiHandle = HiiAddPackages (
540 &mDeviceManagerGuid,
541 gDeviceManagerPrivate.DriverHandle,
542 DeviceManagerVfrBin,
543 UiAppStrings,
544 NULL
545 );
546 ASSERT (gDeviceManagerPrivate.HiiHandle != NULL);
547 }
548
549 /**
550 Remove the installed packages from the HII Database.
551
552 **/
553 VOID
554 FreeDeviceManager(
555 VOID
556 )
557 {
558 EFI_STATUS Status;
559
560 Status = gBS->UninstallMultipleProtocolInterfaces (
561 gDeviceManagerPrivate.DriverHandle,
562 &gEfiDevicePathProtocolGuid,
563 &mDeviceManagerHiiVendorDevicePath,
564 &gEfiHiiConfigAccessProtocolGuid,
565 &gDeviceManagerPrivate.ConfigAccess,
566 NULL
567 );
568 ASSERT_EFI_ERROR (Status);
569
570 HiiRemovePackages (gDeviceManagerPrivate.HiiHandle);
571 }
572
573 /**
574 Dynamic create Hii information for Device Manager.
575
576 @param NextShowFormId The FormId which need to be show.
577
578 **/
579 VOID
580 CreateDeviceManagerForm(
581 IN EFI_FORM_ID NextShowFormId
582 )
583 {
584 UINTN Index;
585 EFI_STRING String;
586 EFI_STRING_ID Token;
587 EFI_STRING_ID TokenHelp;
588 EFI_HII_HANDLE *HiiHandles;
589 EFI_HII_HANDLE HiiHandle;
590 UINTN SkipCount;
591 EFI_STRING_ID FormSetTitle;
592 EFI_STRING_ID FormSetHelp;
593 EFI_GUID FormSetGuid;
594 VOID *StartOpCodeHandle;
595 VOID *EndOpCodeHandle;
596 EFI_IFR_GUID_LABEL *StartLabel;
597 EFI_IFR_GUID_LABEL *EndLabel;
598 BOOLEAN AddNetworkMenu;
599 UINTN AddItemCount;
600 UINTN NewStringLen;
601 EFI_STRING NewStringTitle;
602 CHAR16 *DevicePathStr;
603 EFI_STRING_ID DevicePathId;
604
605 HiiHandle = gDeviceManagerPrivate.HiiHandle;
606 AddNetworkMenu = FALSE;
607 AddItemCount = 0;
608
609 //
610 // If need show the Network device list form, clear the old save list first.
611 //
612 if ((NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) && (mMacDeviceList.CurListLen > 0)) {
613 mMacDeviceList.CurListLen = 0;
614 }
615
616 //
617 // Update the network device form titile.
618 //
619 if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {
620 String = HiiGetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NULL);
621 NewStringLen = StrLen(mSelectedMacAddrString) * 2;
622 NewStringLen += (StrLen(String) + 2) * 2;
623 NewStringTitle = AllocatePool (NewStringLen);
624 UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString);
625 HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL);
626 FreePool (String);
627 FreePool (NewStringTitle);
628 }
629
630 //
631 // Allocate space for creation of UpdateData Buffer
632 //
633 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
634 ASSERT (StartOpCodeHandle != NULL);
635
636 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
637 ASSERT (EndOpCodeHandle != NULL);
638
639 //
640 // Create Hii Extend Label OpCode as the start opcode
641 //
642 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
643 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
644 //
645 // According to the next show Form id(mNextShowFormId) to decide which form need to update.
646 //
647 StartLabel->Number = (UINT16) (LABEL_FORM_ID_OFFSET + NextShowFormId);
648
649 //
650 // Create Hii Extend Label OpCode as the end opcode
651 //
652 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
653 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
654 EndLabel->Number = LABEL_END;
655
656 //
657 // Get all the Hii handles
658 //
659 HiiHandles = HiiGetHiiHandles (NULL);
660 ASSERT (HiiHandles != NULL);
661
662 //
663 // Search for formset of each class type
664 //
665 SkipCount = 0;
666 for (Index = 0; HiiHandles[Index] != NULL; Index++) {
667 //
668 // The QuestionId in the form which will call the driver form has this asssumption.
669 // QuestionId = Handle Index + NETWORK_DEVICE_LIST_KEY_OFFSET;
670 // Different QuestionId at least has the section of NETWORK_DEVICE_LIST_KEY_OFFSET.
671 //
672 ASSERT(Index < MAX_KEY_SECTION_LEN);
673 if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiHiiPlatformSetupFormsetGuid, SkipCount, &FormSetTitle, &FormSetHelp, &FormSetGuid)) {
674 SkipCount = 0;
675 continue;
676 }
677
678 String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL);
679 if (String == NULL) {
680 String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);
681 ASSERT (String != NULL);
682 }
683 Token = HiiSetString (HiiHandle, 0, String, NULL);
684 FreePool (String);
685
686 String = HiiGetString (HiiHandles[Index], FormSetHelp, NULL);
687 if (String == NULL) {
688 String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);
689 ASSERT (String != NULL);
690 }
691 TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);
692 FreePool (String);
693
694 //
695 // Network device process
696 //
697 if (IsNeedAddNetworkMenu (HiiHandles[Index], NextShowFormId,&AddItemCount)) {
698 if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {
699 //
700 // Only show one menu item "Network Config" in the device manger form.
701 //
702 if (!AddNetworkMenu) {
703 AddNetworkMenu = TRUE;
704 HiiCreateGotoOpCode (
705 StartOpCodeHandle,
706 NETWORK_DEVICE_LIST_FORM_ID,
707 STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE),
708 STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP),
709 EFI_IFR_FLAG_CALLBACK,
710 (EFI_QUESTION_ID) QUESTION_NETWORK_DEVICE_ID
711 );
712 }
713 } else if (NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) {
714 //
715 // In network device list form, same mac address device only show one menu.
716 //
717 while (AddItemCount > 0) {
718 HiiCreateGotoOpCode (
719 StartOpCodeHandle,
720 NETWORK_DEVICE_FORM_ID,
721 mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].PromptId,
722 STRING_TOKEN (STR_NETWORK_DEVICE_HELP),
723 EFI_IFR_FLAG_CALLBACK,
724 mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].QuestionId
725 );
726 AddItemCount -= 1;
727 }
728 } else if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {
729 //
730 // In network device form, only the selected mac address device need to be show.
731 //
732 DevicePathStr = ExtractDevicePathFromHiiHandle(HiiHandles[Index]);
733 DevicePathId = 0;
734 if (DevicePathStr != NULL){
735 DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);
736 FreePool(DevicePathStr);
737 }
738 HiiCreateGotoExOpCode (
739 StartOpCodeHandle,
740 0,
741 Token,
742 TokenHelp,
743 0,
744 (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),
745 0,
746 &FormSetGuid,
747 DevicePathId
748 );
749 }
750 } else {
751 //
752 //
753 // Not network device process, only need to show at device manger form.
754 //
755 if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {
756 DevicePathStr = ExtractDevicePathFromHiiHandle(HiiHandles[Index]);
757 DevicePathId = 0;
758 if (DevicePathStr != NULL){
759 DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);
760 FreePool(DevicePathStr);
761 }
762 HiiCreateGotoExOpCode (
763 StartOpCodeHandle,
764 0,
765 Token,
766 TokenHelp,
767 0,
768 (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),
769 0,
770 &FormSetGuid,
771 DevicePathId
772 );
773 }
774 }
775 //
776 //One packagelist may has more than one form package,
777 //Index-- means keep current HiiHandle and still extract from the packagelist,
778 //SkipCount++ means skip the formset which was found before in the same form package.
779 //
780 SkipCount++;
781 Index--;
782 }
783
784 HiiUpdateForm (
785 HiiHandle,
786 &mDeviceManagerGuid,
787 NextShowFormId,
788 StartOpCodeHandle,
789 EndOpCodeHandle
790 );
791
792 HiiFreeOpCodeHandle (StartOpCodeHandle);
793 HiiFreeOpCodeHandle (EndOpCodeHandle);
794 FreePool (HiiHandles);
795 }
796