]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c
MdeModulePkg DxeCore: Fix issue to print GUID value %g without pointer
[mirror_edk2.git] / MdeModulePkg / Library / DeviceManagerUiLib / DeviceManager.c
1 /** @file
2 The device manager reference implementation
3
4 Copyright (c) 2004 - 2017, 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 DeviceManagerExtractConfig,
23 DeviceManagerRouteConfig,
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 HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath = {
44 {
45 {
46 HARDWARE_DEVICE_PATH,
47 HW_VENDOR_DP,
48 {
49 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
50 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
51 }
52 },
53 //
54 // {102579A0-3686-466e-ACD8-80C087044F4A}
55 //
56 { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }
57 },
58 {
59 END_DEVICE_PATH_TYPE,
60 END_ENTIRE_DEVICE_PATH_SUBTYPE,
61 {
62 (UINT8) (END_DEVICE_PATH_LENGTH),
63 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
64 }
65 }
66 };
67
68 /**
69 Extract device path for given HII handle and class guid.
70
71 @param Handle The HII handle.
72
73 @retval NULL Fail to get the device path string.
74 @return PathString Get the device path string.
75
76 **/
77 CHAR16 *
78 DmExtractDevicePathFromHiiHandle (
79 IN EFI_HII_HANDLE Handle
80 )
81 {
82 EFI_STATUS Status;
83 EFI_HANDLE DriverHandle;
84
85 ASSERT (Handle != NULL);
86
87 if (Handle == NULL) {
88 return NULL;
89 }
90
91 Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);
92 if (EFI_ERROR (Status)) {
93 return NULL;
94 }
95 //
96 // Get device path string.
97 //
98 return ConvertDevicePathToText(DevicePathFromHandle (DriverHandle), FALSE, FALSE);
99 }
100
101 /**
102 Get the mac address string from the device path.
103 if the device path has the vlan, get the vanid also.
104
105 @param MacAddressNode Device path begin with mac address
106 @param PBuffer Output string buffer contain mac address.
107
108 **/
109 BOOLEAN
110 GetMacAddressString(
111 IN MAC_ADDR_DEVICE_PATH *MacAddressNode,
112 OUT CHAR16 **PBuffer
113 )
114 {
115 UINTN HwAddressSize;
116 UINTN Index;
117 UINT8 *HwAddress;
118 EFI_DEVICE_PATH_PROTOCOL *Node;
119 UINT16 VlanId;
120 CHAR16 *String;
121 UINTN BufferLen;
122
123 VlanId = 0;
124 String = NULL;
125 ASSERT(MacAddressNode != NULL);
126
127 HwAddressSize = sizeof (EFI_MAC_ADDRESS);
128 if (MacAddressNode->IfType == 0x01 || MacAddressNode->IfType == 0x00) {
129 HwAddressSize = 6;
130 }
131
132 //
133 // The output format is MAC:XX:XX:XX:...\XXXX
134 // The size is the Number size + ":" size + Vlan size(\XXXX) + End
135 //
136 BufferLen = (4 + 2 * HwAddressSize + (HwAddressSize - 1) + 5 + 1) * sizeof (CHAR16);
137 String = AllocateZeroPool (BufferLen);
138 if (String == NULL) {
139 return FALSE;
140 }
141
142 *PBuffer = String;
143 StrCpyS(String, BufferLen / sizeof (CHAR16), L"MAC:");
144 String += 4;
145
146 //
147 // Convert the MAC address into a unicode string.
148 //
149 HwAddress = &MacAddressNode->MacAddress.Addr[0];
150 for (Index = 0; Index < HwAddressSize; Index++) {
151 UnicodeValueToStringS (
152 String,
153 BufferLen - ((UINTN)String - (UINTN)*PBuffer),
154 PREFIX_ZERO | RADIX_HEX,
155 *(HwAddress++),
156 2
157 );
158 String += StrnLenS (String, (BufferLen - ((UINTN)String - (UINTN)*PBuffer)) / sizeof (CHAR16));
159 if (Index < HwAddressSize - 1) {
160 *String++ = L':';
161 }
162 }
163
164 //
165 // If VLAN is configured, it will need extra 5 characters like "\0005".
166 // Plus one unicode character for the null-terminator.
167 //
168 Node = (EFI_DEVICE_PATH_PROTOCOL *)MacAddressNode;
169 while (!IsDevicePathEnd (Node)) {
170 if (Node->Type == MESSAGING_DEVICE_PATH && Node->SubType == MSG_VLAN_DP) {
171 VlanId = ((VLAN_DEVICE_PATH *) Node)->VlanId;
172 }
173 Node = NextDevicePathNode (Node);
174 }
175
176 if (VlanId != 0) {
177 *String++ = L'\\';
178 UnicodeValueToStringS (
179 String,
180 BufferLen - ((UINTN)String - (UINTN)*PBuffer),
181 PREFIX_ZERO | RADIX_HEX,
182 VlanId,
183 4
184 );
185 String += StrnLenS (String, (BufferLen - ((UINTN)String - (UINTN)*PBuffer)) / sizeof (CHAR16));
186 }
187
188 //
189 // Null terminate the Unicode string
190 //
191 *String = L'\0';
192
193 return TRUE;
194 }
195
196 /**
197 Save question id and prompt id to the mac device list.
198 If the same mac address has saved yet, no need to add more.
199
200 @param MacAddrString Mac address string.
201
202 @retval EFI_SUCCESS Add the item is successful.
203 @return Other values if failed to Add the item.
204 **/
205 BOOLEAN
206 AddIdToMacDeviceList (
207 IN EFI_STRING MacAddrString
208 )
209 {
210 MENU_INFO_ITEM *TempDeviceList;
211 UINTN Index;
212 EFI_STRING StoredString;
213 EFI_STRING_ID PromptId;
214 EFI_HII_HANDLE HiiHandle;
215
216 HiiHandle = gDeviceManagerPrivate.HiiHandle;
217 TempDeviceList = NULL;
218
219 for (Index = 0; Index < mMacDeviceList.CurListLen; Index ++) {
220 StoredString = HiiGetString (HiiHandle, mMacDeviceList.NodeList[Index].PromptId, NULL);
221 if (StoredString == NULL) {
222 return FALSE;
223 }
224
225 //
226 // Already has save the same mac address to the list.
227 //
228 if (StrCmp (MacAddrString, StoredString) == 0) {
229 return FALSE;
230 }
231 }
232
233 PromptId = HiiSetString(HiiHandle, 0, MacAddrString, NULL);
234 //
235 // If not in the list, save it.
236 //
237 if (mMacDeviceList.MaxListLen > mMacDeviceList.CurListLen + 1) {
238 mMacDeviceList.NodeList[mMacDeviceList.CurListLen].PromptId = PromptId;
239 mMacDeviceList.NodeList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);
240 } else {
241 mMacDeviceList.MaxListLen += MAX_MAC_ADDRESS_NODE_LIST_LEN;
242 if (mMacDeviceList.CurListLen != 0) {
243 TempDeviceList = (MENU_INFO_ITEM *)AllocateCopyPool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen, (VOID *)mMacDeviceList.NodeList);
244 } else {
245 TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen);
246 }
247
248 if (TempDeviceList == NULL) {
249 return FALSE;
250 }
251 TempDeviceList[mMacDeviceList.CurListLen].PromptId = PromptId;
252 TempDeviceList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);
253
254 if (mMacDeviceList.CurListLen > 0) {
255 FreePool(mMacDeviceList.NodeList);
256 }
257
258 mMacDeviceList.NodeList = TempDeviceList;
259 }
260 mMacDeviceList.CurListLen ++;
261
262 return TRUE;
263 }
264
265 /**
266 Check the devcie path, try to find whether it has mac address path.
267
268 In this function, first need to check whether this path has mac address path.
269 second, when the mac address device path has find, also need to deicide whether
270 need to add this mac address relate info to the menu.
271
272 @param *Node Input device which need to be check.
273 @param NextShowFormId FormId Which need to be show.
274 @param *NeedAddItem Whether need to add the menu in the network device list.
275
276 @retval TRUE Has mac address device path.
277 @retval FALSE NOT Has mac address device path.
278
279 **/
280 BOOLEAN
281 IsMacAddressDevicePath (
282 IN VOID *Node,
283 IN EFI_FORM_ID NextShowFormId,
284 OUT BOOLEAN *NeedAddItem
285 )
286 {
287 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
288 CHAR16 *Buffer;
289 BOOLEAN ReturnVal;
290
291 ASSERT (Node != NULL);
292 *NeedAddItem = FALSE;
293 ReturnVal = FALSE;
294 Buffer = NULL;
295
296 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;
297
298 //
299 // find the partition device path node
300 //
301 while (!IsDevicePathEnd (DevicePath)) {
302 if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
303 (DevicePathSubType (DevicePath) == MSG_MAC_ADDR_DP)) {
304 ReturnVal = TRUE;
305
306 if (DEVICE_MANAGER_FORM_ID == NextShowFormId) {
307 *NeedAddItem = TRUE;
308 break;
309 }
310
311 if (!GetMacAddressString((MAC_ADDR_DEVICE_PATH*)DevicePath, &Buffer)) {
312 break;
313 }
314
315 if (NETWORK_DEVICE_FORM_ID == NextShowFormId) {
316 if (StrCmp (Buffer, mSelectedMacAddrString) == 0) {
317 *NeedAddItem = TRUE;
318 }
319 break;
320 }
321
322 if (NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) {
323 //
324 // Same handle may has two network child handle, so the questionid
325 // has the offset of SAME_HANDLE_KEY_OFFSET.
326 //
327 if (AddIdToMacDeviceList (Buffer)) {
328 *NeedAddItem = TRUE;
329 }
330 break;
331 }
332 }
333 DevicePath = NextDevicePathNode (DevicePath);
334 }
335
336 if (Buffer != NULL) {
337 FreePool (Buffer);
338 }
339
340 return ReturnVal;
341 }
342
343 /**
344 Check to see if the device path is for the network device.
345
346 @param Handle The HII handle which include the mac address device path.
347 @param NextShowFormId The FormId of the form which will be show next time.
348 @param ItemCount The new add Mac address item count.
349
350 @retval TRUE Need to add new item in the menu.
351 @return FALSE Do not need to add the menu about the network.
352
353 **/
354 BOOLEAN
355 IsNeedAddNetworkMenu (
356 IN EFI_HII_HANDLE Handle,
357 IN EFI_FORM_ID NextShowFormId,
358 OUT UINTN *ItemCount
359 )
360 {
361 EFI_STATUS Status;
362 UINTN EntryCount;
363 UINTN Index;
364 EFI_HANDLE DriverHandle;
365 EFI_HANDLE ControllerHandle;
366 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
367 EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
368 EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;
369 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
370 BOOLEAN IsNeedAdd;
371
372 IsNeedAdd = FALSE;
373 OpenInfoBuffer = NULL;
374 if ((Handle == NULL) || (ItemCount == NULL)) {
375 return FALSE;
376 }
377 *ItemCount = 0;
378
379 Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);
380 if (EFI_ERROR (Status)) {
381 return FALSE;
382 }
383 //
384 // Get the device path by the got Driver handle .
385 //
386 Status = gBS->HandleProtocol (DriverHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath);
387 if (EFI_ERROR (Status)) {
388 return FALSE;
389 }
390 TmpDevicePath = DevicePath;
391
392 //
393 // Check whether this device path include mac address device path.
394 // If this path has mac address path, get the value whether need
395 // add this info to the menu and return.
396 // Else check more about the child handle devcie path.
397 //
398 if (IsMacAddressDevicePath(TmpDevicePath, NextShowFormId,&IsNeedAdd)) {
399 if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) && IsNeedAdd) {
400 (*ItemCount) = 1;
401 }
402 return IsNeedAdd;
403 }
404
405 //
406 // Search whether this path is the controller path, not he child handle path.
407 // And the child handle has the network devcie connected.
408 //
409 TmpDevicePath = DevicePath;
410 Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid, &TmpDevicePath, &ControllerHandle);
411 if (EFI_ERROR (Status)) {
412 return FALSE;
413 }
414
415 if (!IsDevicePathEnd (TmpDevicePath)) {
416 return FALSE;
417 }
418
419 //
420 // Retrieve the list of agents that are consuming the specific protocol
421 // on ControllerHandle.
422 // The buffer point by OpenInfoBuffer need be free at this function.
423 //
424 Status = gBS->OpenProtocolInformation (
425 ControllerHandle,
426 &gEfiPciIoProtocolGuid,
427 &OpenInfoBuffer,
428 &EntryCount
429 );
430 if (EFI_ERROR (Status)) {
431 return FALSE;
432 }
433
434 //
435 // Inspect if ChildHandle is one of the agents.
436 //
437 Status = EFI_UNSUPPORTED;
438 for (Index = 0; Index < EntryCount; Index++) {
439 //
440 // Query all the children created by the controller handle's driver
441 //
442 if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
443 Status = gBS->OpenProtocol (
444 OpenInfoBuffer[Index].ControllerHandle,
445 &gEfiDevicePathProtocolGuid,
446 (VOID **) &ChildDevicePath,
447 NULL,
448 NULL,
449 EFI_OPEN_PROTOCOL_GET_PROTOCOL
450 );
451 if (EFI_ERROR (Status)) {
452 continue;
453 }
454
455 //
456 // Check whether this device path include mac address device path.
457 //
458 if (!IsMacAddressDevicePath(ChildDevicePath, NextShowFormId,&IsNeedAdd)) {
459 //
460 // If this path not has mac address path, check the other.
461 //
462 continue;
463 } else {
464 //
465 // If need to update the NETWORK_DEVICE_LIST_FORM, try to get more.
466 //
467 if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId)) {
468 if (IsNeedAdd) {
469 (*ItemCount) += 1;
470 }
471 continue;
472 } else {
473 //
474 // If need to update other form, return whether need to add to the menu.
475 //
476 goto Done;
477 }
478 }
479 }
480 }
481
482 Done:
483 if (OpenInfoBuffer != NULL) {
484 FreePool (OpenInfoBuffer);
485 }
486 return IsNeedAdd;
487 }
488
489 /**
490 Dynamic create Hii information for Device Manager.
491
492 @param NextShowFormId The FormId which need to be show.
493
494 **/
495 VOID
496 CreateDeviceManagerForm(
497 IN EFI_FORM_ID NextShowFormId
498 )
499 {
500 UINTN Index;
501 EFI_STRING String;
502 EFI_STRING_ID Token;
503 EFI_STRING_ID TokenHelp;
504 EFI_HII_HANDLE *HiiHandles;
505 EFI_HII_HANDLE HiiHandle;
506 EFI_GUID FormSetGuid;
507 VOID *StartOpCodeHandle;
508 VOID *EndOpCodeHandle;
509 EFI_IFR_GUID_LABEL *StartLabel;
510 EFI_IFR_GUID_LABEL *EndLabel;
511 BOOLEAN AddNetworkMenu;
512 UINTN AddItemCount;
513 UINTN NewStringLen;
514 EFI_STRING NewStringTitle;
515 CHAR16 *DevicePathStr;
516 EFI_STRING_ID DevicePathId;
517 EFI_IFR_FORM_SET *Buffer;
518 UINTN BufferSize;
519 UINT8 ClassGuidNum;
520 EFI_GUID *ClassGuid;
521 UINTN TempSize;
522 UINT8 *Ptr;
523 EFI_STATUS Status;
524
525 TempSize =0;
526 BufferSize = 0;
527 Buffer = NULL;
528
529 HiiHandle = gDeviceManagerPrivate.HiiHandle;
530 AddNetworkMenu = FALSE;
531 AddItemCount = 0;
532 //
533 // If need show the Network device list form, clear the old save list first.
534 //
535 if ((NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) && (mMacDeviceList.CurListLen > 0)) {
536 mMacDeviceList.CurListLen = 0;
537 }
538
539 //
540 // Update the network device form titile.
541 //
542 if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {
543 String = HiiGetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NULL);
544 NewStringLen = StrLen(mSelectedMacAddrString) * 2;
545 NewStringLen += (StrLen(String) + 2) * 2;
546 NewStringTitle = AllocatePool (NewStringLen);
547 UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString);
548 HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL);
549 FreePool (String);
550 FreePool (NewStringTitle);
551 }
552
553 //
554 // Allocate space for creation of UpdateData Buffer
555 //
556 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
557 ASSERT (StartOpCodeHandle != NULL);
558
559 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
560 ASSERT (EndOpCodeHandle != NULL);
561
562 //
563 // Create Hii Extend Label OpCode as the start opcode
564 //
565 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
566 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
567 //
568 // According to the next show Form id(mNextShowFormId) to decide which form need to update.
569 //
570 StartLabel->Number = (UINT16) (LABEL_FORM_ID_OFFSET + NextShowFormId);
571
572 //
573 // Create Hii Extend Label OpCode as the end opcode
574 //
575 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
576 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
577 EndLabel->Number = LABEL_END;
578
579 //
580 // Get all the Hii handles
581 //
582 HiiHandles = HiiGetHiiHandles (NULL);
583 ASSERT (HiiHandles != NULL);
584
585 //
586 // Search for formset of each class type
587 //
588 for (Index = 0; HiiHandles[Index] != NULL; Index++) {
589 Status = HiiGetFormSetFromHiiHandle(HiiHandles[Index], &Buffer,&BufferSize);
590 if (EFI_ERROR (Status)){
591 continue;
592 }
593 Ptr = (UINT8 *)Buffer;
594 while(TempSize < BufferSize) {
595 TempSize += ((EFI_IFR_OP_HEADER *) Ptr)->Length;
596 if (((EFI_IFR_OP_HEADER *) Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)){
597 Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;
598 continue;
599 }
600
601 ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3);
602 ClassGuid = (EFI_GUID *) (VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET));
603 while (ClassGuidNum-- > 0) {
604 if (CompareGuid (&gEfiHiiPlatformSetupFormsetGuid, ClassGuid)== 0) {
605 ClassGuid ++;
606 continue;
607 }
608
609 String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle, NULL);
610 if (String == NULL) {
611 String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);
612 ASSERT (String != NULL);
613 }
614 Token = HiiSetString (HiiHandle, 0, String, NULL);
615 FreePool (String);
616
617 String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->Help, NULL);
618 if (String == NULL) {
619 String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);
620 ASSERT (String != NULL);
621 }
622 TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);
623 FreePool (String);
624
625 FormSetGuid = ((EFI_IFR_FORM_SET *)Ptr)->Guid;
626
627 //
628 // Network device process
629 //
630 if (IsNeedAddNetworkMenu (HiiHandles[Index], NextShowFormId,&AddItemCount)) {
631 if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {
632 //
633 // Only show one menu item "Network Config" in the device manger form.
634 //
635 if (!AddNetworkMenu) {
636 AddNetworkMenu = TRUE;
637 HiiCreateGotoOpCode (
638 StartOpCodeHandle,
639 NETWORK_DEVICE_LIST_FORM_ID,
640 STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE),
641 STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP),
642 EFI_IFR_FLAG_CALLBACK,
643 (EFI_QUESTION_ID) QUESTION_NETWORK_DEVICE_ID
644 );
645 }
646 } else if (NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) {
647 //
648 // In network device list form, same mac address device only show one menu.
649 //
650 while (AddItemCount > 0) {
651 HiiCreateGotoOpCode (
652 StartOpCodeHandle,
653 NETWORK_DEVICE_FORM_ID,
654 mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].PromptId,
655 STRING_TOKEN (STR_NETWORK_DEVICE_HELP),
656 EFI_IFR_FLAG_CALLBACK,
657 mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].QuestionId
658 );
659 AddItemCount -= 1;
660 }
661 } else if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {
662 //
663 // In network device form, only the selected mac address device need to be show.
664 //
665 DevicePathStr = DmExtractDevicePathFromHiiHandle(HiiHandles[Index]);
666 DevicePathId = 0;
667 if (DevicePathStr != NULL){
668 DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);
669 FreePool(DevicePathStr);
670 }
671 HiiCreateGotoExOpCode (
672 StartOpCodeHandle,
673 0,
674 Token,
675 TokenHelp,
676 0,
677 (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),
678 0,
679 &FormSetGuid,
680 DevicePathId
681 );
682 }
683 } else {
684 //
685 // Not network device process, only need to show at device manger form.
686 //
687 if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {
688 DevicePathStr = DmExtractDevicePathFromHiiHandle(HiiHandles[Index]);
689 DevicePathId = 0;
690 if (DevicePathStr != NULL){
691 DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);
692 FreePool(DevicePathStr);
693 }
694 HiiCreateGotoExOpCode (
695 StartOpCodeHandle,
696 0,
697 Token,
698 TokenHelp,
699 0,
700 (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),
701 0,
702 &FormSetGuid,
703 DevicePathId
704 );
705 }
706 }
707 break;
708 }
709
710 Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;
711 }
712 FreePool(Buffer);
713 Buffer = NULL;
714 TempSize = 0;
715 BufferSize = 0;
716 }
717
718 HiiUpdateForm (
719 HiiHandle,
720 &mDeviceManagerGuid,
721 NextShowFormId,
722 StartOpCodeHandle,
723 EndOpCodeHandle
724 );
725
726 HiiFreeOpCodeHandle (StartOpCodeHandle);
727 HiiFreeOpCodeHandle (EndOpCodeHandle);
728 FreePool (HiiHandles);
729 }
730
731 /**
732 This function allows a caller to extract the current configuration for one
733 or more named elements from the target driver.
734
735
736 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
737 @param Request A null-terminated Unicode string in <ConfigRequest> format.
738 @param Progress On return, points to a character in the Request string.
739 Points to the string's null terminator if request was successful.
740 Points to the most recent '&' before the first failing name/value
741 pair (or the beginning of the string if the failure is in the
742 first name/value pair) if the request was not successful.
743 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
744 has all values filled in for the names in the Request string.
745 String to be allocated by the called function.
746
747 @retval EFI_SUCCESS The Results is filled with the requested values.
748 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
749 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
750 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
751
752 **/
753 EFI_STATUS
754 EFIAPI
755 DeviceManagerExtractConfig (
756 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
757 IN CONST EFI_STRING Request,
758 OUT EFI_STRING *Progress,
759 OUT EFI_STRING *Results
760 )
761 {
762 if (Progress == NULL || Results == NULL) {
763 return EFI_INVALID_PARAMETER;
764 }
765 *Progress = Request;
766 return EFI_NOT_FOUND;
767 }
768
769 /**
770 This function processes the results of changes in configuration.
771
772 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
773 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
774 @param Progress A pointer to a string filled in with the offset of the most
775 recent '&' before the first failing name/value pair (or the
776 beginning of the string if the failure is in the first
777 name/value pair) or the terminating NULL if all was successful.
778
779 @retval EFI_SUCCESS The Results is processed successfully.
780 @retval EFI_INVALID_PARAMETER Configuration is NULL.
781 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
782
783 **/
784 EFI_STATUS
785 EFIAPI
786 DeviceManagerRouteConfig (
787 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
788 IN CONST EFI_STRING Configuration,
789 OUT EFI_STRING *Progress
790 )
791 {
792 if (Configuration == NULL || Progress == NULL) {
793 return EFI_INVALID_PARAMETER;
794 }
795
796 *Progress = Configuration;
797
798 return EFI_NOT_FOUND;
799 }
800
801 /**
802 This function is invoked if user selected a interactive opcode from Device Manager's
803 Formset. If user set VBIOS, the new value is saved to EFI variable.
804
805 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
806 @param Action Specifies the type of action taken by the browser.
807 @param QuestionId A unique value which is sent to the original exporting driver
808 so that it can identify the type of data to expect.
809 @param Type The type of value for the question.
810 @param Value A pointer to the data being sent to the original exporting driver.
811 @param ActionRequest On return, points to the action requested by the callback function.
812
813 @retval EFI_SUCCESS The callback successfully handled the action.
814 @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
815
816 **/
817 EFI_STATUS
818 EFIAPI
819 DeviceManagerCallback (
820 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
821 IN EFI_BROWSER_ACTION Action,
822 IN EFI_QUESTION_ID QuestionId,
823 IN UINT8 Type,
824 IN EFI_IFR_TYPE_VALUE *Value,
825 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
826 )
827 {
828 UINTN CurIndex;
829
830 if (Action != EFI_BROWSER_ACTION_CHANGING) {
831 //
832 // Do nothing for other UEFI Action. Only do call back when data is changed.
833 //
834 return EFI_UNSUPPORTED;
835 }
836 if ((Value == NULL) || (ActionRequest == NULL)) {
837 return EFI_INVALID_PARAMETER;
838 }
839 if ((QuestionId < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET) && (QuestionId >= NETWORK_DEVICE_LIST_KEY_OFFSET)) {
840 //
841 // If user select the mac address, need to record mac address string to support next form show.
842 //
843 for (CurIndex = 0; CurIndex < mMacDeviceList.CurListLen; CurIndex ++) {
844 if (mMacDeviceList.NodeList[CurIndex].QuestionId == QuestionId) {
845 mSelectedMacAddrString = HiiGetString (gDeviceManagerPrivate.HiiHandle, mMacDeviceList.NodeList[CurIndex].PromptId, NULL);
846 }
847 }
848 CreateDeviceManagerForm(NETWORK_DEVICE_FORM_ID);
849 } else if(QuestionId == QUESTION_NETWORK_DEVICE_ID){
850 CreateDeviceManagerForm(NETWORK_DEVICE_LIST_FORM_ID);
851 }
852
853 return EFI_SUCCESS;
854 }
855
856 /**
857 Install Boot Manager Menu driver.
858
859 @param ImageHandle The image handle.
860 @param SystemTable The system table.
861
862 @retval EFI_SUCEESS Install Boot manager menu success.
863 @retval Other Return error status.
864
865 **/
866 EFI_STATUS
867 EFIAPI
868 DeviceManagerUiLibConstructor (
869 IN EFI_HANDLE ImageHandle,
870 IN EFI_SYSTEM_TABLE *SystemTable
871 )
872 {
873 EFI_STATUS Status;
874
875 gDeviceManagerPrivate.DriverHandle = NULL;
876 Status = gBS->InstallMultipleProtocolInterfaces (
877 &gDeviceManagerPrivate.DriverHandle,
878 &gEfiDevicePathProtocolGuid,
879 &mDeviceManagerHiiVendorDevicePath,
880 &gEfiHiiConfigAccessProtocolGuid,
881 &gDeviceManagerPrivate.ConfigAccess,
882 NULL
883 );
884 ASSERT_EFI_ERROR (Status);
885
886 //
887 // Publish our HII data.
888 //
889 gDeviceManagerPrivate.HiiHandle = HiiAddPackages (
890 &mDeviceManagerGuid,
891 gDeviceManagerPrivate.DriverHandle,
892 DeviceManagerVfrBin,
893 DeviceManagerUiLibStrings,
894 NULL
895 );
896 ASSERT (gDeviceManagerPrivate.HiiHandle != NULL);
897
898 //
899 // Update boot manager page
900 //
901 CreateDeviceManagerForm (DEVICE_MANAGER_FORM_ID);
902
903 return EFI_SUCCESS;
904 }
905
906 /**
907 Unloads the application and its installed protocol.
908
909 @param ImageHandle Handle that identifies the image to be unloaded.
910 @param SystemTable The system table.
911
912 @retval EFI_SUCCESS The image has been unloaded.
913 **/
914 EFI_STATUS
915 EFIAPI
916 DeviceManagerUiLibDestructor(
917 IN EFI_HANDLE ImageHandle,
918 IN EFI_SYSTEM_TABLE *SystemTable
919 )
920 {
921 EFI_STATUS Status;
922
923 Status = gBS->UninstallMultipleProtocolInterfaces (
924 gDeviceManagerPrivate.DriverHandle,
925 &gEfiDevicePathProtocolGuid,
926 &mDeviceManagerHiiVendorDevicePath,
927 &gEfiHiiConfigAccessProtocolGuid,
928 &gDeviceManagerPrivate.ConfigAccess,
929 NULL
930 );
931 ASSERT_EFI_ERROR (Status);
932
933 HiiRemovePackages (gDeviceManagerPrivate.HiiHandle);
934
935 return EFI_SUCCESS;
936 }
937