-/** @file\r
-The device manager reference implementation\r
-\r
-Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "DeviceManager.h"\r
-\r
-DEVICE_MANAGER_CALLBACK_DATA gDeviceManagerPrivate = {\r
- DEVICE_MANAGER_CALLBACK_DATA_SIGNATURE,\r
- NULL,\r
- NULL,\r
- {\r
- DeviceManagerExtractConfig,\r
- DeviceManagerRouteConfig,\r
- DeviceManagerCallback\r
- }\r
-};\r
-\r
-#define MAX_MAC_ADDRESS_NODE_LIST_LEN 10\r
-\r
-EFI_GUID mDeviceManagerGuid = DEVICE_MANAGER_FORMSET_GUID;\r
-\r
-//\r
-// Which Mac Address string is select\r
-// it will decide what menu need to show in the NETWORK_DEVICE_FORM_ID form.\r
-//\r
-EFI_STRING mSelectedMacAddrString;\r
-\r
-//\r
-// The Mac Address show in the NETWORK_DEVICE_LIST_FORM_ID\r
-//\r
-MAC_ADDRESS_NODE_LIST mMacDeviceList;\r
-\r
-HII_VENDOR_DEVICE_PATH mDeviceManagerHiiVendorDevicePath = {\r
- {\r
- {\r
- HARDWARE_DEVICE_PATH,\r
- HW_VENDOR_DP,\r
- {\r
- (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
- (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
- }\r
- },\r
- //\r
- // {102579A0-3686-466e-ACD8-80C087044F4A}\r
- //\r
- { 0x102579a0, 0x3686, 0x466e, { 0xac, 0xd8, 0x80, 0xc0, 0x87, 0x4, 0x4f, 0x4a } }\r
- },\r
- {\r
- END_DEVICE_PATH_TYPE,\r
- END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
- { \r
- (UINT8) (END_DEVICE_PATH_LENGTH),\r
- (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
- }\r
- }\r
-};\r
-\r
-/**\r
- Extract device path for given HII handle and class guid.\r
-\r
- @param Handle The HII handle.\r
-\r
- @retval NULL Fail to get the device path string.\r
- @return PathString Get the device path string.\r
-\r
-**/\r
-CHAR16 *\r
-DmExtractDevicePathFromHiiHandle (\r
- IN EFI_HII_HANDLE Handle\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE DriverHandle;\r
-\r
- ASSERT (Handle != NULL);\r
-\r
- if (Handle == NULL) {\r
- return NULL;\r
- }\r
-\r
- Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);\r
- if (EFI_ERROR (Status)) {\r
- return NULL;\r
- }\r
- //\r
- // Get device path string.\r
- //\r
- return ConvertDevicePathToText(DevicePathFromHandle (DriverHandle), FALSE, FALSE);\r
-}\r
-\r
-/**\r
- Get the mac address string from the device path.\r
- if the device path has the vlan, get the vanid also.\r
- \r
- @param MacAddressNode Device path begin with mac address \r
- @param PBuffer Output string buffer contain mac address.\r
-\r
-**/\r
-BOOLEAN \r
-GetMacAddressString(\r
- IN MAC_ADDR_DEVICE_PATH *MacAddressNode,\r
- OUT CHAR16 **PBuffer\r
- )\r
-{\r
- UINTN HwAddressSize;\r
- UINTN Index;\r
- UINT8 *HwAddress;\r
- EFI_DEVICE_PATH_PROTOCOL *Node;\r
- UINT16 VlanId;\r
- CHAR16 *String;\r
- UINTN BufferLen;\r
-\r
- VlanId = 0;\r
- String = NULL;\r
- ASSERT(MacAddressNode != NULL);\r
-\r
- HwAddressSize = sizeof (EFI_MAC_ADDRESS);\r
- if (MacAddressNode->IfType == 0x01 || MacAddressNode->IfType == 0x00) {\r
- HwAddressSize = 6;\r
- }\r
-\r
- //\r
- // The output format is MAC:XX:XX:XX:...\XXXX\r
- // The size is the Number size + ":" size + Vlan size(\XXXX) + End\r
- //\r
- BufferLen = (4 + 2 * HwAddressSize + (HwAddressSize - 1) + 5 + 1) * sizeof (CHAR16);\r
- String = AllocateZeroPool (BufferLen);\r
- if (String == NULL) {\r
- return FALSE;\r
- }\r
-\r
- *PBuffer = String;\r
- StrCpyS(String, BufferLen / sizeof (CHAR16), L"MAC:");\r
- String += 4;\r
- \r
- //\r
- // Convert the MAC address into a unicode string.\r
- //\r
- HwAddress = &MacAddressNode->MacAddress.Addr[0];\r
- for (Index = 0; Index < HwAddressSize; Index++) {\r
- String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(HwAddress++), 2);\r
- if (Index < HwAddressSize - 1) {\r
- *String++ = L':';\r
- }\r
- }\r
-\r
- //\r
- // If VLAN is configured, it will need extra 5 characters like "\0005".\r
- // Plus one unicode character for the null-terminator.\r
- //\r
- Node = (EFI_DEVICE_PATH_PROTOCOL *)MacAddressNode;\r
- while (!IsDevicePathEnd (Node)) {\r
- if (Node->Type == MESSAGING_DEVICE_PATH && Node->SubType == MSG_VLAN_DP) {\r
- VlanId = ((VLAN_DEVICE_PATH *) Node)->VlanId;\r
- }\r
- Node = NextDevicePathNode (Node);\r
- }\r
-\r
- if (VlanId != 0) {\r
- *String++ = L'\\';\r
- String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, VlanId, 4);\r
- }\r
-\r
- //\r
- // Null terminate the Unicode string\r
- //\r
- *String = L'\0';\r
-\r
- return TRUE;\r
-}\r
-\r
-/**\r
- Save question id and prompt id to the mac device list.\r
- If the same mac address has saved yet, no need to add more.\r
-\r
- @param MacAddrString Mac address string.\r
-\r
- @retval EFI_SUCCESS Add the item is successful.\r
- @return Other values if failed to Add the item.\r
-**/\r
-BOOLEAN \r
-AddIdToMacDeviceList (\r
- IN EFI_STRING MacAddrString\r
- )\r
-{\r
- MENU_INFO_ITEM *TempDeviceList;\r
- UINTN Index;\r
- EFI_STRING StoredString;\r
- EFI_STRING_ID PromptId;\r
- EFI_HII_HANDLE HiiHandle;\r
-\r
- HiiHandle = gDeviceManagerPrivate.HiiHandle;\r
- TempDeviceList = NULL;\r
-\r
- for (Index = 0; Index < mMacDeviceList.CurListLen; Index ++) {\r
- StoredString = HiiGetString (HiiHandle, mMacDeviceList.NodeList[Index].PromptId, NULL);\r
- if (StoredString == NULL) {\r
- return FALSE;\r
- }\r
-\r
- //\r
- // Already has save the same mac address to the list.\r
- //\r
- if (StrCmp (MacAddrString, StoredString) == 0) {\r
- return FALSE;\r
- }\r
- }\r
-\r
- PromptId = HiiSetString(HiiHandle, 0, MacAddrString, NULL);\r
- //\r
- // If not in the list, save it.\r
- //\r
- if (mMacDeviceList.MaxListLen > mMacDeviceList.CurListLen + 1) {\r
- mMacDeviceList.NodeList[mMacDeviceList.CurListLen].PromptId = PromptId;\r
- mMacDeviceList.NodeList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);\r
- } else {\r
- mMacDeviceList.MaxListLen += MAX_MAC_ADDRESS_NODE_LIST_LEN;\r
- if (mMacDeviceList.CurListLen != 0) {\r
- TempDeviceList = (MENU_INFO_ITEM *)AllocateCopyPool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen, (VOID *)mMacDeviceList.NodeList);\r
- } else {\r
- TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen);\r
- }\r
-\r
- if (TempDeviceList == NULL) {\r
- return FALSE;\r
- }\r
- TempDeviceList[mMacDeviceList.CurListLen].PromptId = PromptId; \r
- TempDeviceList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);\r
-\r
- if (mMacDeviceList.CurListLen > 0) {\r
- FreePool(mMacDeviceList.NodeList);\r
- }\r
-\r
- mMacDeviceList.NodeList = TempDeviceList;\r
- }\r
- mMacDeviceList.CurListLen ++;\r
-\r
- return TRUE;\r
-}\r
-\r
-/**\r
- Check the devcie path, try to find whether it has mac address path.\r
-\r
- In this function, first need to check whether this path has mac address path.\r
- second, when the mac address device path has find, also need to deicide whether\r
- need to add this mac address relate info to the menu.\r
-\r
- @param *Node Input device which need to be check.\r
- @param NextShowFormId FormId Which need to be show.\r
- @param *NeedAddItem Whether need to add the menu in the network device list.\r
-\r
- @retval TRUE Has mac address device path.\r
- @retval FALSE NOT Has mac address device path.\r
-\r
-**/\r
-BOOLEAN\r
-IsMacAddressDevicePath (\r
- IN VOID *Node,\r
- IN EFI_FORM_ID NextShowFormId,\r
- OUT BOOLEAN *NeedAddItem\r
- )\r
-{\r
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
- CHAR16 *Buffer;\r
- BOOLEAN ReturnVal;\r
-\r
- ASSERT (Node != NULL);\r
- *NeedAddItem = FALSE;\r
- ReturnVal = FALSE;\r
- Buffer = NULL;\r
-\r
- DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;\r
-\r
- //\r
- // find the partition device path node\r
- //\r
- while (!IsDevicePathEnd (DevicePath)) {\r
- if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&\r
- (DevicePathSubType (DevicePath) == MSG_MAC_ADDR_DP)) {\r
- ReturnVal = TRUE;\r
-\r
- if (DEVICE_MANAGER_FORM_ID == NextShowFormId) {\r
- *NeedAddItem = TRUE;\r
- break;\r
- } \r
- \r
- if (!GetMacAddressString((MAC_ADDR_DEVICE_PATH*)DevicePath, &Buffer)) {\r
- break;\r
- }\r
-\r
- if (NETWORK_DEVICE_FORM_ID == NextShowFormId) {\r
- if (StrCmp (Buffer, mSelectedMacAddrString) == 0) {\r
- *NeedAddItem = TRUE;\r
- }\r
- break;\r
- }\r
-\r
- if (NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) {\r
- //\r
- // Same handle may has two network child handle, so the questionid \r
- // has the offset of SAME_HANDLE_KEY_OFFSET.\r
- //\r
- if (AddIdToMacDeviceList (Buffer)) {\r
- *NeedAddItem = TRUE;\r
- }\r
- break;\r
- }\r
- }\r
- DevicePath = NextDevicePathNode (DevicePath);\r
- }\r
-\r
- if (Buffer != NULL) {\r
- FreePool (Buffer);\r
- }\r
-\r
- return ReturnVal;\r
-}\r
-\r
-/**\r
- Check to see if the device path is for the network device.\r
-\r
- @param Handle The HII handle which include the mac address device path.\r
- @param NextShowFormId The FormId of the form which will be show next time.\r
- @param ItemCount The new add Mac address item count.\r
-\r
- @retval TRUE Need to add new item in the menu.\r
- @return FALSE Do not need to add the menu about the network.\r
-\r
-**/\r
-BOOLEAN \r
-IsNeedAddNetworkMenu (\r
- IN EFI_HII_HANDLE Handle,\r
- IN EFI_FORM_ID NextShowFormId,\r
- OUT UINTN *ItemCount\r
- )\r
-{\r
- EFI_STATUS Status;\r
- UINTN EntryCount;\r
- UINTN Index; \r
- EFI_HII_HANDLE HiiDeviceManagerHandle;\r
- EFI_HANDLE DriverHandle;\r
- EFI_HANDLE ControllerHandle;\r
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
- EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;\r
- EFI_DEVICE_PATH_PROTOCOL *ChildDevicePath;\r
- EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
- BOOLEAN IsNeedAdd;\r
-\r
- HiiDeviceManagerHandle = gDeviceManagerPrivate.HiiHandle;\r
- IsNeedAdd = FALSE;\r
- OpenInfoBuffer = NULL;\r
- if ((Handle == NULL) || (ItemCount == NULL)) {\r
- return FALSE;\r
- }\r
- *ItemCount = 0;\r
-\r
- Status = gHiiDatabase->GetPackageListHandle (gHiiDatabase, Handle, &DriverHandle);\r
- if (EFI_ERROR (Status)) {\r
- return FALSE;\r
- }\r
- //\r
- // Get the device path by the got Driver handle .\r
- //\r
- Status = gBS->HandleProtocol (DriverHandle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath);\r
- if (EFI_ERROR (Status)) {\r
- return FALSE;\r
- }\r
- TmpDevicePath = DevicePath;\r
-\r
- // \r
- // Check whether this device path include mac address device path.\r
- // If this path has mac address path, get the value whether need \r
- // add this info to the menu and return.\r
- // Else check more about the child handle devcie path.\r
- //\r
- if (IsMacAddressDevicePath(TmpDevicePath, NextShowFormId,&IsNeedAdd)) {\r
- if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId) && IsNeedAdd) {\r
- (*ItemCount) = 1;\r
- }\r
- return IsNeedAdd;\r
- }\r
-\r
- //\r
- // Search whether this path is the controller path, not he child handle path.\r
- // And the child handle has the network devcie connected.\r
- //\r
- TmpDevicePath = DevicePath;\r
- Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid, &TmpDevicePath, &ControllerHandle);\r
- if (EFI_ERROR (Status)) {\r
- return FALSE;\r
- }\r
-\r
- if (!IsDevicePathEnd (TmpDevicePath)) {\r
- return FALSE; \r
- }\r
-\r
- //\r
- // Retrieve the list of agents that are consuming the specific protocol\r
- // on ControllerHandle.\r
- // The buffer point by OpenInfoBuffer need be free at this function.\r
- //\r
- Status = gBS->OpenProtocolInformation (\r
- ControllerHandle,\r
- &gEfiPciIoProtocolGuid,\r
- &OpenInfoBuffer,\r
- &EntryCount\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return FALSE;\r
- }\r
-\r
- //\r
- // Inspect if ChildHandle is one of the agents.\r
- //\r
- Status = EFI_UNSUPPORTED;\r
- for (Index = 0; Index < EntryCount; Index++) {\r
- //\r
- // Query all the children created by the controller handle's driver\r
- //\r
- if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
- Status = gBS->OpenProtocol (\r
- OpenInfoBuffer[Index].ControllerHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- (VOID **) &ChildDevicePath,\r
- NULL,\r
- NULL,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
- );\r
- if (EFI_ERROR (Status)) {\r
- continue;\r
- }\r
-\r
- // \r
- // Check whether this device path include mac address device path.\r
- //\r
- if (!IsMacAddressDevicePath(ChildDevicePath, NextShowFormId,&IsNeedAdd)) {\r
- //\r
- // If this path not has mac address path, check the other.\r
- //\r
- continue;\r
- } else {\r
- //\r
- // If need to update the NETWORK_DEVICE_LIST_FORM, try to get more.\r
- //\r
- if ((NETWORK_DEVICE_LIST_FORM_ID == NextShowFormId)) {\r
- if (IsNeedAdd) {\r
- (*ItemCount) += 1;\r
- }\r
- continue;\r
- } else {\r
- //\r
- // If need to update other form, return whether need to add to the menu.\r
- // \r
- goto Done;\r
- }\r
- }\r
- }\r
- }\r
-\r
-Done:\r
- if (OpenInfoBuffer != NULL) {\r
- FreePool (OpenInfoBuffer); \r
- }\r
- return IsNeedAdd; \r
-}\r
-\r
-/**\r
- Dynamic create Hii information for Device Manager.\r
-\r
- @param NextShowFormId The FormId which need to be show.\r
-\r
-**/\r
-VOID\r
-CreateDeviceManagerForm(\r
- IN EFI_FORM_ID NextShowFormId\r
-)\r
-{\r
- UINTN Index;\r
- EFI_STRING String;\r
- EFI_STRING_ID Token;\r
- EFI_STRING_ID TokenHelp;\r
- EFI_HII_HANDLE *HiiHandles;\r
- EFI_HII_HANDLE HiiHandle;\r
- EFI_GUID FormSetGuid;\r
- VOID *StartOpCodeHandle;\r
- VOID *EndOpCodeHandle;\r
- EFI_IFR_GUID_LABEL *StartLabel;\r
- EFI_IFR_GUID_LABEL *EndLabel;\r
- BOOLEAN AddNetworkMenu;\r
- UINTN AddItemCount;\r
- UINTN NewStringLen;\r
- EFI_STRING NewStringTitle;\r
- CHAR16 *DevicePathStr;\r
- EFI_STRING_ID DevicePathId;\r
- EFI_IFR_FORM_SET *Buffer; \r
- UINTN BufferSize; \r
- UINT8 ClassGuidNum; \r
- EFI_GUID *ClassGuid; \r
- UINTN TempSize;\r
- UINT8 *Ptr;\r
- EFI_STATUS Status;\r
-\r
- TempSize =0;\r
- BufferSize = 0;\r
- Buffer = NULL;\r
-\r
- HiiHandle = gDeviceManagerPrivate.HiiHandle;\r
- AddNetworkMenu = FALSE;\r
- AddItemCount = 0;\r
- //\r
- // If need show the Network device list form, clear the old save list first.\r
- //\r
- if ((NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) && (mMacDeviceList.CurListLen > 0)) {\r
- mMacDeviceList.CurListLen = 0;\r
- }\r
-\r
- //\r
- // Update the network device form titile.\r
- //\r
- if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {\r
- String = HiiGetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NULL);\r
- NewStringLen = StrLen(mSelectedMacAddrString) * 2;\r
- NewStringLen += (StrLen(String) + 2) * 2;\r
- NewStringTitle = AllocatePool (NewStringLen);\r
- UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString);\r
- HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL); \r
- FreePool (String);\r
- FreePool (NewStringTitle);\r
- }\r
-\r
- //\r
- // Allocate space for creation of UpdateData Buffer\r
- //\r
- StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
- ASSERT (StartOpCodeHandle != NULL);\r
-\r
- EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
- ASSERT (EndOpCodeHandle != NULL);\r
-\r
- //\r
- // Create Hii Extend Label OpCode as the start opcode\r
- //\r
- StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
- StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
- //\r
- // According to the next show Form id(mNextShowFormId) to decide which form need to update.\r
- //\r
- StartLabel->Number = (UINT16) (LABEL_FORM_ID_OFFSET + NextShowFormId);\r
-\r
- //\r
- // Create Hii Extend Label OpCode as the end opcode\r
- //\r
- EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
- EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
- EndLabel->Number = LABEL_END;\r
-\r
- //\r
- // Get all the Hii handles\r
- //\r
- HiiHandles = HiiGetHiiHandles (NULL);\r
- ASSERT (HiiHandles != NULL);\r
-\r
- //\r
- // Search for formset of each class type\r
- //\r
- for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r
- Status = HiiGetFormSetFromHiiHandle(HiiHandles[Index], &Buffer,&BufferSize);\r
- if (EFI_ERROR (Status)){\r
- continue;\r
- }\r
- Ptr = (UINT8 *)Buffer;\r
- while(TempSize < BufferSize) {\r
- TempSize += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r
- if (((EFI_IFR_OP_HEADER *) Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)){\r
- Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r
- continue;\r
- } \r
-\r
- ClassGuidNum = (UINT8) (((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3);\r
- ClassGuid = (EFI_GUID *) (VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET));\r
- while (ClassGuidNum-- > 0) {\r
- if (CompareGuid (&gEfiHiiPlatformSetupFormsetGuid, ClassGuid)== 0) {\r
- ClassGuid ++;\r
- continue;\r
- }\r
-\r
- String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle, NULL);\r
- if (String == NULL) {\r
- String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r
- ASSERT (String != NULL);\r
- }\r
- Token = HiiSetString (HiiHandle, 0, String, NULL);\r
- FreePool (String);\r
-\r
- String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->Help, NULL);\r
- if (String == NULL) {\r
- String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r
- ASSERT (String != NULL);\r
- }\r
- TokenHelp = HiiSetString (HiiHandle, 0, String, NULL);\r
- FreePool (String);\r
-\r
- FormSetGuid = ((EFI_IFR_FORM_SET *)Ptr)->Guid;\r
-\r
- //\r
- // Network device process\r
- // \r
- if (IsNeedAddNetworkMenu (HiiHandles[Index], NextShowFormId,&AddItemCount)) {\r
- if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {\r
- //\r
- // Only show one menu item "Network Config" in the device manger form.\r
- //\r
- if (!AddNetworkMenu) {\r
- AddNetworkMenu = TRUE;\r
- HiiCreateGotoOpCode (\r
- StartOpCodeHandle,\r
- NETWORK_DEVICE_LIST_FORM_ID,\r
- STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE),\r
- STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP),\r
- EFI_IFR_FLAG_CALLBACK,\r
- (EFI_QUESTION_ID) QUESTION_NETWORK_DEVICE_ID\r
- );\r
- }\r
- } else if (NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) {\r
- //\r
- // In network device list form, same mac address device only show one menu.\r
- //\r
- while (AddItemCount > 0) {\r
- HiiCreateGotoOpCode (\r
- StartOpCodeHandle,\r
- NETWORK_DEVICE_FORM_ID,\r
- mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].PromptId,\r
- STRING_TOKEN (STR_NETWORK_DEVICE_HELP),\r
- EFI_IFR_FLAG_CALLBACK,\r
- mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].QuestionId\r
- );\r
- AddItemCount -= 1;\r
- }\r
- } else if (NextShowFormId == NETWORK_DEVICE_FORM_ID) {\r
- //\r
- // In network device form, only the selected mac address device need to be show.\r
- //\r
- DevicePathStr = DmExtractDevicePathFromHiiHandle(HiiHandles[Index]);\r
- DevicePathId = 0;\r
- if (DevicePathStr != NULL){\r
- DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);\r
- FreePool(DevicePathStr);\r
- }\r
- HiiCreateGotoExOpCode (\r
- StartOpCodeHandle,\r
- 0,\r
- Token,\r
- TokenHelp,\r
- 0,\r
- (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),\r
- 0,\r
- &FormSetGuid, \r
- DevicePathId\r
- );\r
- }\r
- } else {\r
- //\r
- // Not network device process, only need to show at device manger form.\r
- //\r
- if (NextShowFormId == DEVICE_MANAGER_FORM_ID) {\r
- DevicePathStr = DmExtractDevicePathFromHiiHandle(HiiHandles[Index]);\r
- DevicePathId = 0;\r
- if (DevicePathStr != NULL){\r
- DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL);\r
- FreePool(DevicePathStr);\r
- }\r
- HiiCreateGotoExOpCode (\r
- StartOpCodeHandle,\r
- 0,\r
- Token,\r
- TokenHelp,\r
- 0,\r
- (EFI_QUESTION_ID) (Index + DEVICE_KEY_OFFSET),\r
- 0,\r
- &FormSetGuid,\r
- DevicePathId\r
- );\r
- }\r
- }\r
- break;\r
- }\r
-\r
- Ptr += ((EFI_IFR_OP_HEADER *) Ptr)->Length;\r
- }\r
- FreePool(Buffer);\r
- Buffer = NULL;\r
- TempSize = 0;\r
- BufferSize = 0;\r
- }\r
-\r
- HiiUpdateForm (\r
- HiiHandle,\r
- &mDeviceManagerGuid,\r
- NextShowFormId,\r
- StartOpCodeHandle,\r
- EndOpCodeHandle\r
- );\r
-\r
- HiiFreeOpCodeHandle (StartOpCodeHandle);\r
- HiiFreeOpCodeHandle (EndOpCodeHandle);\r
- FreePool (HiiHandles);\r
-}\r
-\r
-/**\r
- This function allows a caller to extract the current configuration for one\r
- or more named elements from the target driver.\r
-\r
-\r
- @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
- @param Request A null-terminated Unicode string in <ConfigRequest> format.\r
- @param Progress On return, points to a character in the Request string.\r
- Points to the string's null terminator if request was successful.\r
- Points to the most recent '&' before the first failing name/value\r
- pair (or the beginning of the string if the failure is in the\r
- first name/value pair) if the request was not successful.\r
- @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r
- has all values filled in for the names in the Request string.\r
- String to be allocated by the called function.\r
-\r
- @retval EFI_SUCCESS The Results is filled with the requested values.\r
- @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
- @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
- @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceManagerExtractConfig (\r
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
- IN CONST EFI_STRING Request,\r
- OUT EFI_STRING *Progress,\r
- OUT EFI_STRING *Results\r
- )\r
-{\r
- if (Progress == NULL || Results == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- *Progress = Request;\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-/**\r
- This function processes the results of changes in configuration.\r
-\r
- @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
- @param Configuration A null-terminated Unicode string in <ConfigResp> format.\r
- @param Progress A pointer to a string filled in with the offset of the most\r
- recent '&' before the first failing name/value pair (or the\r
- beginning of the string if the failure is in the first\r
- name/value pair) or the terminating NULL if all was successful.\r
-\r
- @retval EFI_SUCCESS The Results is processed successfully.\r
- @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
- @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceManagerRouteConfig (\r
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
- IN CONST EFI_STRING Configuration,\r
- OUT EFI_STRING *Progress\r
- )\r
-{\r
- if (Configuration == NULL || Progress == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- *Progress = Configuration;\r
-\r
- return EFI_NOT_FOUND;\r
-}\r
-\r
-/**\r
- This function is invoked if user selected a interactive opcode from Device Manager's\r
- Formset. If user set VBIOS, the new value is saved to EFI variable.\r
-\r
- @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
- @param Action Specifies the type of action taken by the browser.\r
- @param QuestionId A unique value which is sent to the original exporting driver\r
- so that it can identify the type of data to expect.\r
- @param Type The type of value for the question.\r
- @param Value A pointer to the data being sent to the original exporting driver.\r
- @param ActionRequest On return, points to the action requested by the callback function.\r
-\r
- @retval EFI_SUCCESS The callback successfully handled the action.\r
- @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceManagerCallback (\r
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
- IN EFI_BROWSER_ACTION Action,\r
- IN EFI_QUESTION_ID QuestionId,\r
- IN UINT8 Type,\r
- IN EFI_IFR_TYPE_VALUE *Value,\r
- OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
- )\r
-{\r
- UINTN CurIndex;\r
-\r
- if (Action != EFI_BROWSER_ACTION_CHANGING) {\r
- //\r
- // Do nothing for other UEFI Action. Only do call back when data is changed.\r
- //\r
- return EFI_UNSUPPORTED;\r
- }\r
- if ((Value == NULL) || (ActionRequest == NULL)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if ((QuestionId < MAX_KEY_SECTION_LEN + NETWORK_DEVICE_LIST_KEY_OFFSET) && (QuestionId >= NETWORK_DEVICE_LIST_KEY_OFFSET)) {\r
- //\r
- // If user select the mac address, need to record mac address string to support next form show.\r
- //\r
- for (CurIndex = 0; CurIndex < mMacDeviceList.CurListLen; CurIndex ++) {\r
- if (mMacDeviceList.NodeList[CurIndex].QuestionId == QuestionId) {\r
- mSelectedMacAddrString = HiiGetString (gDeviceManagerPrivate.HiiHandle, mMacDeviceList.NodeList[CurIndex].PromptId, NULL);\r
- }\r
- }\r
- CreateDeviceManagerForm(NETWORK_DEVICE_FORM_ID);\r
- } else if(QuestionId == QUESTION_NETWORK_DEVICE_ID){\r
- CreateDeviceManagerForm(NETWORK_DEVICE_LIST_FORM_ID);\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Install Boot Manager Menu driver.\r
-\r
- @param ImageHandle The image handle.\r
- @param SystemTable The system table.\r
-\r
- @retval EFI_SUCEESS Install Boot manager menu success.\r
- @retval Other Return error status.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceManagerLibConstructor (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
-)\r
-{\r
- EFI_STATUS Status;\r
-\r
- gDeviceManagerPrivate.DriverHandle = NULL;\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &gDeviceManagerPrivate.DriverHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- &mDeviceManagerHiiVendorDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- &gDeviceManagerPrivate.ConfigAccess,\r
- NULL\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // Publish our HII data.\r
- //\r
- gDeviceManagerPrivate.HiiHandle = HiiAddPackages (\r
- &mDeviceManagerGuid,\r
- gDeviceManagerPrivate.DriverHandle,\r
- DeviceManagerVfrBin,\r
- DeviceManagerLibStrings,\r
- NULL\r
- );\r
- ASSERT (gDeviceManagerPrivate.HiiHandle != NULL);\r
-\r
- //\r
- // Update boot manager page \r
- //\r
- CreateDeviceManagerForm (DEVICE_MANAGER_FORM_ID);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Unloads the application and its installed protocol.\r
-\r
- @param ImageHandle Handle that identifies the image to be unloaded.\r
- @param SystemTable The system table.\r
-\r
- @retval EFI_SUCCESS The image has been unloaded.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceManagerLibDestructor(\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
-)\r
-{\r
- EFI_STATUS Status;\r
-\r
- Status = gBS->UninstallMultipleProtocolInterfaces (\r
- gDeviceManagerPrivate.DriverHandle,\r
- &gEfiDevicePathProtocolGuid,\r
- &mDeviceManagerHiiVendorDevicePath,\r
- &gEfiHiiConfigAccessProtocolGuid,\r
- &gDeviceManagerPrivate.ConfigAccess,\r
- NULL\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- HiiRemovePackages (gDeviceManagerPrivate.HiiHandle);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r