/*-1* Copyright (c) 2017 Netflix, Inc.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11*12* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND13* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE14* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE15* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE16* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL17* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS18* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)19* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT20* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY21* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF22* SUCH DAMAGE.23*/2425/*26* Routines to format EFI_DEVICE_PATHs from the UEFI standard. Much of27* this file is taken from EDK2 and rototilled.28*/2930#include <efivar.h>31#include <stdio.h>32#include <string.h>3334#include "efichar.h"35#include "efivar-dp.h"36#include "uefi-dplib.h"3738/*39* This is a lie, but since we have converted everything40* from wide to narrow, it's the right lie now.41*/42#define UnicodeSPrint snprintf4344/*45* Taken from MdePkg/Library/UefiDevicePathLib/DevicePathToText.c46* heavily modified:47* wide strings converted to narrow48* Low level printing code redone for narrow strings49* Routines made static50* %s -> %S in spots (where it is still UCS-2)51* %a (ascii) -> %s52* %g -> %36s hack to print guid (see above for caveat)53* some tidying up of const and deconsting. It's evil, but const54* poisoning the whole file was too much.55*/5657/** @file58DevicePathToText protocol as defined in the UEFI 2.0 specification.5960(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>61Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>62SPDX-License-Identifier: BSD-2-Clause-Patent6364**/6566// #include "UefiDevicePathLib.h"6768/**69Concatenates a formatted unicode string to allocated pool. The caller must70free the resulting buffer.7172@param Str Tracks the allocated pool, size in use, and73amount of pool allocated.74@param Fmt The format string75@param ... Variable arguments based on the format string.7677@return Allocated buffer with the formatted string printed in it.78The caller must free the allocated buffer. The buffer79allocation is not packed.8081**/82static char *83EFIAPI84UefiDevicePathLibCatPrint (85IN OUT POOL_PRINT *Str,86IN const char *Fmt,87...88)89{90UINTN Count;91VA_LIST Args;9293VA_START (Args, Fmt);94Count = vsnprintf (NULL, 0, Fmt, Args);95VA_END (Args);9697if ((Str->Count + (Count + 1)) > Str->Capacity) {98Str->Capacity = (Str->Count + (Count + 1) * 2);99Str->Str = reallocf (100Str->Str,101Str->Capacity102);103ASSERT (Str->Str != NULL);104}105106VA_START (Args, Fmt);107vsnprintf (Str->Str + Str->Count, Str->Capacity - Str->Count, Fmt, Args);108Str->Count += Count;109110VA_END (Args);111return Str->Str;112}113114/**115Converts a PCI device path structure to its string representative.116117@param Str The string representative of input device.118@param DevPath The input device path structure.119@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation120of the display node is used, where applicable. If DisplayOnly121is FALSE, then the longer text representation of the display node122is used.123@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text124representation for a device node can be used, where applicable.125126**/127static VOID128DevPathToTextPci (129IN OUT POOL_PRINT *Str,130IN VOID *DevPath,131IN BOOLEAN DisplayOnly,132IN BOOLEAN AllowShortcuts133)134{135PCI_DEVICE_PATH *Pci;136137Pci = DevPath;138UefiDevicePathLibCatPrint (Str, "Pci(0x%x,0x%x)", Pci->Device, Pci->Function);139}140141/**142Converts a PC Card device path structure to its string representative.143144@param Str The string representative of input device.145@param DevPath The input device path structure.146@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation147of the display node is used, where applicable. If DisplayOnly148is FALSE, then the longer text representation of the display node149is used.150@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text151representation for a device node can be used, where applicable.152153**/154static VOID155DevPathToTextPccard (156IN OUT POOL_PRINT *Str,157IN VOID *DevPath,158IN BOOLEAN DisplayOnly,159IN BOOLEAN AllowShortcuts160)161{162PCCARD_DEVICE_PATH *Pccard;163164Pccard = DevPath;165UefiDevicePathLibCatPrint (Str, "PcCard(0x%x)", Pccard->FunctionNumber);166}167168/**169Converts a Memory Map device path structure to its string representative.170171@param Str The string representative of input device.172@param DevPath The input device path structure.173@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation174of the display node is used, where applicable. If DisplayOnly175is FALSE, then the longer text representation of the display node176is used.177@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text178representation for a device node can be used, where applicable.179180**/181static VOID182DevPathToTextMemMap (183IN OUT POOL_PRINT *Str,184IN VOID *DevPath,185IN BOOLEAN DisplayOnly,186IN BOOLEAN AllowShortcuts187)188{189MEMMAP_DEVICE_PATH *MemMap;190191MemMap = DevPath;192UefiDevicePathLibCatPrint (193Str,194"MemoryMapped(0x%x,0x%lx,0x%lx)",195MemMap->MemoryType,196MemMap->StartingAddress,197MemMap->EndingAddress198);199}200201/**202Converts a Vendor device path structure to its string representative.203204@param Str The string representative of input device.205@param DevPath The input device path structure.206@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation207of the display node is used, where applicable. If DisplayOnly208is FALSE, then the longer text representation of the display node209is used.210@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text211representation for a device node can be used, where applicable.212213**/214static VOID215DevPathToTextVendor (216IN OUT POOL_PRINT *Str,217IN VOID *DevPath,218IN BOOLEAN DisplayOnly,219IN BOOLEAN AllowShortcuts220)221{222VENDOR_DEVICE_PATH *Vendor;223const char *Type;224UINTN Index;225UINTN DataLength;226UINT32 FlowControlMap;227UINT16 Info;228229Vendor = (VENDOR_DEVICE_PATH *)DevPath;230switch (DevicePathType (&Vendor->Header)) {231case HARDWARE_DEVICE_PATH:232Type = "Hw";233break;234235case MESSAGING_DEVICE_PATH:236Type = "Msg";237if (AllowShortcuts) {238if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {239UefiDevicePathLibCatPrint (Str, "VenPcAnsi()");240return;241} else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {242UefiDevicePathLibCatPrint (Str, "VenVt100()");243return;244} else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {245UefiDevicePathLibCatPrint (Str, "VenVt100Plus()");246return;247} else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {248UefiDevicePathLibCatPrint (Str, "VenUtf8()");249return;250} else if (CompareGuid (&Vendor->Guid, &gEfiUartDevicePathGuid)) {251FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *)Vendor)->FlowControlMap);252switch (FlowControlMap & 0x00000003) {253case 0:254UefiDevicePathLibCatPrint (Str, "UartFlowCtrl(%s)", "None");255break;256257case 1:258UefiDevicePathLibCatPrint (Str, "UartFlowCtrl(%s)", "Hardware");259break;260261case 2:262UefiDevicePathLibCatPrint (Str, "UartFlowCtrl(%s)", "XonXoff");263break;264265default:266break;267}268269return;270} else if (CompareGuid (&Vendor->Guid, &gEfiSasDevicePathGuid)) {271UefiDevicePathLibCatPrint (272Str,273"SAS(0x%lx,0x%lx,0x%x,",274((SAS_DEVICE_PATH *)Vendor)->SasAddress,275((SAS_DEVICE_PATH *)Vendor)->Lun,276((SAS_DEVICE_PATH *)Vendor)->RelativeTargetPort277);278Info = (((SAS_DEVICE_PATH *)Vendor)->DeviceTopology);279if (((Info & 0x0f) == 0) && ((Info & BIT7) == 0)) {280UefiDevicePathLibCatPrint (Str, "NoTopology,0,0,0,");281} else if (((Info & 0x0f) <= 2) && ((Info & BIT7) == 0)) {282UefiDevicePathLibCatPrint (283Str,284"%s,%s,%s,",285((Info & BIT4) != 0) ? "SATA" : "SAS",286((Info & BIT5) != 0) ? "External" : "Internal",287((Info & BIT6) != 0) ? "Expanded" : "Direct"288);289if ((Info & 0x0f) == 1) {290UefiDevicePathLibCatPrint (Str, "0,");291} else {292//293// Value 0x0 thru 0xFF -> Drive 1 thru Drive 256294//295UefiDevicePathLibCatPrint (Str, "0x%x,", ((Info >> 8) & 0xff) + 1);296}297} else {298UefiDevicePathLibCatPrint (Str, "0x%x,0,0,0,", Info);299}300301UefiDevicePathLibCatPrint (Str, "0x%x)", ((SAS_DEVICE_PATH *)Vendor)->Reserved);302return;303} else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {304UefiDevicePathLibCatPrint (Str, "DebugPort()");305return;306}307}308309break;310311case MEDIA_DEVICE_PATH:312Type = "Media";313break;314315default:316Type = "?";317break;318}319320DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);321UefiDevicePathLibCatPrint (Str, "Ven%s(%36s", Type, G(&Vendor->Guid));322if (DataLength != 0) {323UefiDevicePathLibCatPrint (Str, ",");324for (Index = 0; Index < DataLength; Index++) {325UefiDevicePathLibCatPrint (Str, "%02x", ((VENDOR_DEVICE_PATH_WITH_DATA *)Vendor)->VendorDefinedData[Index]);326}327}328329UefiDevicePathLibCatPrint (Str, ")");330}331332/**333Converts a Controller device path structure to its string representative.334335@param Str The string representative of input device.336@param DevPath The input device path structure.337@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation338of the display node is used, where applicable. If DisplayOnly339is FALSE, then the longer text representation of the display node340is used.341@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text342representation for a device node can be used, where applicable.343344**/345static VOID346DevPathToTextController (347IN OUT POOL_PRINT *Str,348IN VOID *DevPath,349IN BOOLEAN DisplayOnly,350IN BOOLEAN AllowShortcuts351)352{353CONTROLLER_DEVICE_PATH *Controller;354355Controller = DevPath;356UefiDevicePathLibCatPrint (357Str,358"Ctrl(0x%x)",359Controller->ControllerNumber360);361}362363/**364Converts a BMC device path structure to its string representative.365366@param Str The string representative of input device.367@param DevPath The input device path structure.368@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation369of the display node is used, where applicable. If DisplayOnly370is FALSE, then the longer text representation of the display node371is used.372@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text373representation for a device node can be used, where applicable.374375**/376static VOID377DevPathToTextBmc (378IN OUT POOL_PRINT *Str,379IN VOID *DevPath,380IN BOOLEAN DisplayOnly,381IN BOOLEAN AllowShortcuts382)383{384BMC_DEVICE_PATH *Bmc;385386Bmc = DevPath;387UefiDevicePathLibCatPrint (388Str,389"BMC(0x%x,0x%lx)",390Bmc->InterfaceType,391ReadUnaligned64 ((&Bmc->BaseAddress))392);393}394395/**396Converts a ACPI device path structure to its string representative.397398@param Str The string representative of input device.399@param DevPath The input device path structure.400@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation401of the display node is used, where applicable. If DisplayOnly402is FALSE, then the longer text representation of the display node403is used.404@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text405representation for a device node can be used, where applicable.406407**/408static VOID409DevPathToTextAcpi (410IN OUT POOL_PRINT *Str,411IN VOID *DevPath,412IN BOOLEAN DisplayOnly,413IN BOOLEAN AllowShortcuts414)415{416ACPI_HID_DEVICE_PATH *Acpi;417418Acpi = DevPath;419if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {420switch (EISA_ID_TO_NUM (Acpi->HID)) {421case 0x0a03:422UefiDevicePathLibCatPrint (Str, "PciRoot(0x%x)", Acpi->UID);423break;424425case 0x0a08:426UefiDevicePathLibCatPrint (Str, "PcieRoot(0x%x)", Acpi->UID);427break;428429case 0x0604:430UefiDevicePathLibCatPrint (Str, "Floppy(0x%x)", Acpi->UID);431break;432433case 0x0301:434UefiDevicePathLibCatPrint (Str, "Keyboard(0x%x)", Acpi->UID);435break;436437case 0x0501:438UefiDevicePathLibCatPrint (Str, "Serial(0x%x)", Acpi->UID);439break;440441case 0x0401:442UefiDevicePathLibCatPrint (Str, "ParallelPort(0x%x)", Acpi->UID);443break;444445default:446UefiDevicePathLibCatPrint (Str, "Acpi(PNP%04x,0x%x)", EISA_ID_TO_NUM (Acpi->HID), Acpi->UID);447break;448}449} else {450UefiDevicePathLibCatPrint (Str, "Acpi(0x%08x,0x%x)", Acpi->HID, Acpi->UID);451}452}453454/**455Converts a ACPI extended HID device path structure to its string representative.456457@param Str The string representative of input device.458@param DevPath The input device path structure.459@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation460of the display node is used, where applicable. If DisplayOnly461is FALSE, then the longer text representation of the display node462is used.463@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text464representation for a device node can be used, where applicable.465466**/467static VOID468DevPathToTextAcpiEx (469IN OUT POOL_PRINT *Str,470IN VOID *DevPath,471IN BOOLEAN DisplayOnly,472IN BOOLEAN AllowShortcuts473)474{475ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;476char HIDText[11];477char CIDText[11];478UINTN CurrentLength;479CHAR8 *CurrentPos;480UINTN NextStringOffset;481CHAR8 *Strings[3];482UINT8 HidStrIndex;483UINT8 UidStrIndex;484UINT8 CidStrIndex;485UINT8 StrIndex;486487HidStrIndex = 0;488UidStrIndex = 1;489CidStrIndex = 2;490AcpiEx = DevPath;491Strings[HidStrIndex] = NULL;492Strings[UidStrIndex] = NULL;493Strings[CidStrIndex] = NULL;494CurrentLength = sizeof (ACPI_EXTENDED_HID_DEVICE_PATH);495CurrentPos = (CHAR8 *)(((UINT8 *)AcpiEx) + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));496StrIndex = 0;497while (CurrentLength < AcpiEx->Header.Length[0] && StrIndex < ARRAY_SIZE (Strings)) {498Strings[StrIndex] = CurrentPos;499NextStringOffset = AsciiStrLen (CurrentPos) + 1;500CurrentLength += NextStringOffset;501CurrentPos += NextStringOffset;502StrIndex++;503}504505if (DisplayOnly) {506if ((EISA_ID_TO_NUM (AcpiEx->HID) == 0x0A03) ||507((EISA_ID_TO_NUM (AcpiEx->CID) == 0x0A03) && (EISA_ID_TO_NUM (AcpiEx->HID) != 0x0A08)))508{509if (Strings[UidStrIndex] != NULL) {510UefiDevicePathLibCatPrint (Str, "PciRoot(%s)", Strings[UidStrIndex]);511} else {512UefiDevicePathLibCatPrint (Str, "PciRoot(0x%x)", AcpiEx->UID);513}514515return;516}517518if ((EISA_ID_TO_NUM (AcpiEx->HID) == 0x0A08) || (EISA_ID_TO_NUM (AcpiEx->CID) == 0x0A08)) {519if (Strings[UidStrIndex] != NULL) {520UefiDevicePathLibCatPrint (Str, "PcieRoot(%s)", Strings[UidStrIndex]);521} else {522UefiDevicePathLibCatPrint (Str, "PcieRoot(0x%x)", AcpiEx->UID);523}524525return;526}527}528529//530// Converts EISA identification to string.531//532UnicodeSPrint (533HIDText,534sizeof (HIDText),535"%c%c%c%04X",536((AcpiEx->HID >> 10) & 0x1f) + 'A' - 1,537((AcpiEx->HID >> 5) & 0x1f) + 'A' - 1,538((AcpiEx->HID >> 0) & 0x1f) + 'A' - 1,539(AcpiEx->HID >> 16) & 0xFFFF540);541UnicodeSPrint (542CIDText,543sizeof (CIDText),544"%c%c%c%04X",545((AcpiEx->CID >> 10) & 0x1f) + 'A' - 1,546((AcpiEx->CID >> 5) & 0x1f) + 'A' - 1,547((AcpiEx->CID >> 0) & 0x1f) + 'A' - 1,548(AcpiEx->CID >> 16) & 0xFFFF549);550551if (((Strings[HidStrIndex] != NULL) && (*Strings[HidStrIndex] == '\0')) &&552((Strings[CidStrIndex] != NULL) && (*Strings[CidStrIndex] == '\0')) &&553((Strings[UidStrIndex] != NULL) && (*Strings[UidStrIndex] != '\0')))554{555//556// use AcpiExp()557//558if (AcpiEx->CID == 0) {559UefiDevicePathLibCatPrint (560Str,561"AcpiExp(%s,0,%s)",562HIDText,563Strings[UidStrIndex]564);565} else {566UefiDevicePathLibCatPrint (567Str,568"AcpiExp(%s,%s,%s)",569HIDText,570CIDText,571Strings[UidStrIndex]572);573}574} else {575if (DisplayOnly) {576if (Strings[HidStrIndex] != NULL) {577UefiDevicePathLibCatPrint (Str, "AcpiEx(%s,", Strings[HidStrIndex]);578} else {579UefiDevicePathLibCatPrint (Str, "AcpiEx(%s,", HIDText);580}581582if (Strings[CidStrIndex] != NULL) {583UefiDevicePathLibCatPrint (Str, "%s,", Strings[CidStrIndex]);584} else {585UefiDevicePathLibCatPrint (Str, "%s,", CIDText);586}587588if (Strings[UidStrIndex] != NULL) {589UefiDevicePathLibCatPrint (Str, "%s)", Strings[UidStrIndex]);590} else {591UefiDevicePathLibCatPrint (Str, "0x%x)", AcpiEx->UID);592}593} else {594UefiDevicePathLibCatPrint (595Str,596"AcpiEx(%s,%s,0x%x,%s,%s,%s)",597HIDText,598CIDText,599AcpiEx->UID,600Strings[HidStrIndex] != NULL ? Strings[HidStrIndex] : '\0',601Strings[CidStrIndex] != NULL ? Strings[CidStrIndex] : '\0',602Strings[UidStrIndex] != NULL ? Strings[UidStrIndex] : '\0'603);604}605}606}607608/**609Converts a ACPI address device path structure to its string representative.610611@param Str The string representative of input device.612@param DevPath The input device path structure.613@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation614of the display node is used, where applicable. If DisplayOnly615is FALSE, then the longer text representation of the display node616is used.617@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text618representation for a device node can be used, where applicable.619620**/621static VOID622DevPathToTextAcpiAdr (623IN OUT POOL_PRINT *Str,624IN VOID *DevPath,625IN BOOLEAN DisplayOnly,626IN BOOLEAN AllowShortcuts627)628{629ACPI_ADR_DEVICE_PATH *AcpiAdr;630UINT32 *Addr;631UINT16 Index;632UINT16 Length;633UINT16 AdditionalAdrCount;634635AcpiAdr = DevPath;636Length = (UINT16)DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr);637AdditionalAdrCount = (UINT16)((Length - 8) / 4);638639UefiDevicePathLibCatPrint (Str, "AcpiAdr(0x%x", AcpiAdr->ADR);640Addr = &AcpiAdr->ADR + 1;641for (Index = 0; Index < AdditionalAdrCount; Index++) {642UefiDevicePathLibCatPrint (Str, ",0x%x", Addr[Index]);643}644645UefiDevicePathLibCatPrint (Str, ")");646}647648/**649Converts a ATAPI device path structure to its string representative.650651@param Str The string representative of input device.652@param DevPath The input device path structure.653@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation654of the display node is used, where applicable. If DisplayOnly655is FALSE, then the longer text representation of the display node656is used.657@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text658representation for a device node can be used, where applicable.659660**/661static VOID662DevPathToTextAtapi (663IN OUT POOL_PRINT *Str,664IN VOID *DevPath,665IN BOOLEAN DisplayOnly,666IN BOOLEAN AllowShortcuts667)668{669ATAPI_DEVICE_PATH *Atapi;670671Atapi = DevPath;672673if (DisplayOnly) {674UefiDevicePathLibCatPrint (Str, "Ata(0x%x)", Atapi->Lun);675} else {676UefiDevicePathLibCatPrint (677Str,678"Ata(%s,%s,0x%x)",679(Atapi->PrimarySecondary == 1) ? "Secondary" : "Primary",680(Atapi->SlaveMaster == 1) ? "Slave" : "Master",681Atapi->Lun682);683}684}685686/**687Converts a SCSI device path structure to its string representative.688689@param Str The string representative of input device.690@param DevPath The input device path structure.691@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation692of the display node is used, where applicable. If DisplayOnly693is FALSE, then the longer text representation of the display node694is used.695@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text696representation for a device node can be used, where applicable.697698**/699static VOID700DevPathToTextScsi (701IN OUT POOL_PRINT *Str,702IN VOID *DevPath,703IN BOOLEAN DisplayOnly,704IN BOOLEAN AllowShortcuts705)706{707SCSI_DEVICE_PATH *Scsi;708709Scsi = DevPath;710UefiDevicePathLibCatPrint (Str, "Scsi(0x%x,0x%x)", Scsi->Pun, Scsi->Lun);711}712713/**714Converts a Fibre device path structure to its string representative.715716@param Str The string representative of input device.717@param DevPath The input device path structure.718@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation719of the display node is used, where applicable. If DisplayOnly720is FALSE, then the longer text representation of the display node721is used.722@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text723representation for a device node can be used, where applicable.724725**/726static VOID727DevPathToTextFibre (728IN OUT POOL_PRINT *Str,729IN VOID *DevPath,730IN BOOLEAN DisplayOnly,731IN BOOLEAN AllowShortcuts732)733{734FIBRECHANNEL_DEVICE_PATH *Fibre;735736Fibre = DevPath;737UefiDevicePathLibCatPrint (Str, "Fibre(0x%lx,0x%lx)", Fibre->WWN, Fibre->Lun);738}739740/**741Converts a FibreEx device path structure to its string representative.742743@param Str The string representative of input device.744@param DevPath The input device path structure.745@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation746of the display node is used, where applicable. If DisplayOnly747is FALSE, then the longer text representation of the display node748is used.749@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text750representation for a device node can be used, where applicable.751752**/753static VOID754DevPathToTextFibreEx (755IN OUT POOL_PRINT *Str,756IN VOID *DevPath,757IN BOOLEAN DisplayOnly,758IN BOOLEAN AllowShortcuts759)760{761FIBRECHANNELEX_DEVICE_PATH *FibreEx;762UINTN Index;763764FibreEx = DevPath;765UefiDevicePathLibCatPrint (Str, "FibreEx(0x");766for (Index = 0; Index < sizeof (FibreEx->WWN) / sizeof (FibreEx->WWN[0]); Index++) {767UefiDevicePathLibCatPrint (Str, "%02x", FibreEx->WWN[Index]);768}769770UefiDevicePathLibCatPrint (Str, ",0x");771for (Index = 0; Index < sizeof (FibreEx->Lun) / sizeof (FibreEx->Lun[0]); Index++) {772UefiDevicePathLibCatPrint (Str, "%02x", FibreEx->Lun[Index]);773}774775UefiDevicePathLibCatPrint (Str, ")");776}777778/**779Converts a Sas Ex device path structure to its string representative.780781@param Str The string representative of input device.782@param DevPath The input device path structure.783@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation784of the display node is used, where applicable. If DisplayOnly785is FALSE, then the longer text representation of the display node786is used.787@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text788representation for a device node can be used, where applicable.789790**/791static VOID792DevPathToTextSasEx (793IN OUT POOL_PRINT *Str,794IN VOID *DevPath,795IN BOOLEAN DisplayOnly,796IN BOOLEAN AllowShortcuts797)798{799SASEX_DEVICE_PATH *SasEx;800UINTN Index;801802SasEx = DevPath;803UefiDevicePathLibCatPrint (Str, "SasEx(0x");804805for (Index = 0; Index < sizeof (SasEx->SasAddress) / sizeof (SasEx->SasAddress[0]); Index++) {806UefiDevicePathLibCatPrint (Str, "%02x", SasEx->SasAddress[Index]);807}808809UefiDevicePathLibCatPrint (Str, ",0x");810for (Index = 0; Index < sizeof (SasEx->Lun) / sizeof (SasEx->Lun[0]); Index++) {811UefiDevicePathLibCatPrint (Str, "%02x", SasEx->Lun[Index]);812}813814UefiDevicePathLibCatPrint (Str, ",0x%x,", SasEx->RelativeTargetPort);815816if (((SasEx->DeviceTopology & 0x0f) == 0) && ((SasEx->DeviceTopology & BIT7) == 0)) {817UefiDevicePathLibCatPrint (Str, "NoTopology,0,0,0");818} else if (((SasEx->DeviceTopology & 0x0f) <= 2) && ((SasEx->DeviceTopology & BIT7) == 0)) {819UefiDevicePathLibCatPrint (820Str,821"%s,%s,%s,",822((SasEx->DeviceTopology & BIT4) != 0) ? "SATA" : "SAS",823((SasEx->DeviceTopology & BIT5) != 0) ? "External" : "Internal",824((SasEx->DeviceTopology & BIT6) != 0) ? "Expanded" : "Direct"825);826if ((SasEx->DeviceTopology & 0x0f) == 1) {827UefiDevicePathLibCatPrint (Str, "0");828} else {829//830// Value 0x0 thru 0xFF -> Drive 1 thru Drive 256831//832UefiDevicePathLibCatPrint (Str, "0x%x", ((SasEx->DeviceTopology >> 8) & 0xff) + 1);833}834} else {835UefiDevicePathLibCatPrint (Str, "0x%x,0,0,0", SasEx->DeviceTopology);836}837838UefiDevicePathLibCatPrint (Str, ")");839return;840}841842/**843Converts a NVM Express Namespace device path structure to its string representative.844845@param Str The string representative of input device.846@param DevPath The input device path structure.847@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation848of the display node is used, where applicable. If DisplayOnly849is FALSE, then the longer text representation of the display node850is used.851@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text852representation for a device node can be used, where applicable.853854**/855static VOID856DevPathToTextNVMe (857IN OUT POOL_PRINT *Str,858IN VOID *DevPath,859IN BOOLEAN DisplayOnly,860IN BOOLEAN AllowShortcuts861)862{863NVME_NAMESPACE_DEVICE_PATH *Nvme;864UINT8 *Uuid;865866Nvme = DevPath;867Uuid = (UINT8 *)&Nvme->NamespaceUuid;868UefiDevicePathLibCatPrint (869Str,870"NVMe(0x%x,%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x)",871Nvme->NamespaceId,872Uuid[7],873Uuid[6],874Uuid[5],875Uuid[4],876Uuid[3],877Uuid[2],878Uuid[1],879Uuid[0]880);881}882883/**884Converts a UFS device path structure to its string representative.885886@param Str The string representative of input device.887@param DevPath The input device path structure.888@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation889of the display node is used, where applicable. If DisplayOnly890is FALSE, then the longer text representation of the display node891is used.892@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text893representation for a device node can be used, where applicable.894895**/896static VOID897DevPathToTextUfs (898IN OUT POOL_PRINT *Str,899IN VOID *DevPath,900IN BOOLEAN DisplayOnly,901IN BOOLEAN AllowShortcuts902)903{904UFS_DEVICE_PATH *Ufs;905906Ufs = DevPath;907UefiDevicePathLibCatPrint (Str, "UFS(0x%x,0x%x)", Ufs->Pun, Ufs->Lun);908}909910/**911Converts a SD (Secure Digital) device path structure to its string representative.912913@param Str The string representative of input device.914@param DevPath The input device path structure.915@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation916of the display node is used, where applicable. If DisplayOnly917is FALSE, then the longer text representation of the display node918is used.919@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text920representation for a device node can be used, where applicable.921922**/923static VOID924DevPathToTextSd (925IN OUT POOL_PRINT *Str,926IN VOID *DevPath,927IN BOOLEAN DisplayOnly,928IN BOOLEAN AllowShortcuts929)930{931SD_DEVICE_PATH *Sd;932933Sd = DevPath;934UefiDevicePathLibCatPrint (935Str,936"SD(0x%x)",937Sd->SlotNumber938);939}940941/**942Converts a EMMC (Embedded MMC) device path structure to its string representative.943944@param Str The string representative of input device.945@param DevPath The input device path structure.946@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation947of the display node is used, where applicable. If DisplayOnly948is FALSE, then the longer text representation of the display node949is used.950@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text951representation for a device node can be used, where applicable.952953**/954static VOID955DevPathToTextEmmc (956IN OUT POOL_PRINT *Str,957IN VOID *DevPath,958IN BOOLEAN DisplayOnly,959IN BOOLEAN AllowShortcuts960)961{962EMMC_DEVICE_PATH *Emmc;963964Emmc = DevPath;965UefiDevicePathLibCatPrint (966Str,967"eMMC(0x%x)",968Emmc->SlotNumber969);970}971972/**973Converts a 1394 device path structure to its string representative.974975@param Str The string representative of input device.976@param DevPath The input device path structure.977@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation978of the display node is used, where applicable. If DisplayOnly979is FALSE, then the longer text representation of the display node980is used.981@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text982representation for a device node can be used, where applicable.983984**/985static VOID986DevPathToText1394 (987IN OUT POOL_PRINT *Str,988IN VOID *DevPath,989IN BOOLEAN DisplayOnly,990IN BOOLEAN AllowShortcuts991)992{993F1394_DEVICE_PATH *F1394DevPath;994995F1394DevPath = DevPath;996//997// Guid has format of IEEE-EUI64998//999UefiDevicePathLibCatPrint (Str, "I1394(%016lx)", F1394DevPath->Guid);1000}10011002/**1003Converts a USB device path structure to its string representative.10041005@param Str The string representative of input device.1006@param DevPath The input device path structure.1007@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1008of the display node is used, where applicable. If DisplayOnly1009is FALSE, then the longer text representation of the display node1010is used.1011@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1012representation for a device node can be used, where applicable.10131014**/1015static VOID1016DevPathToTextUsb (1017IN OUT POOL_PRINT *Str,1018IN VOID *DevPath,1019IN BOOLEAN DisplayOnly,1020IN BOOLEAN AllowShortcuts1021)1022{1023USB_DEVICE_PATH *Usb;10241025Usb = DevPath;1026UefiDevicePathLibCatPrint (Str, "USB(0x%x,0x%x)", Usb->ParentPortNumber, Usb->InterfaceNumber);1027}10281029/**1030Converts a USB WWID device path structure to its string representative.10311032@param Str The string representative of input device.1033@param DevPath The input device path structure.1034@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1035of the display node is used, where applicable. If DisplayOnly1036is FALSE, then the longer text representation of the display node1037is used.1038@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1039representation for a device node can be used, where applicable.10401041**/1042static VOID1043DevPathToTextUsbWWID (1044IN OUT POOL_PRINT *Str,1045IN VOID *DevPath,1046IN BOOLEAN DisplayOnly,1047IN BOOLEAN AllowShortcuts1048)1049{1050USB_WWID_DEVICE_PATH *UsbWWId;1051CHAR16 *SerialNumberStr;1052CHAR16 *NewStr;1053UINT16 Length;10541055UsbWWId = DevPath;10561057SerialNumberStr = (CHAR16 *)(&UsbWWId + 1);1058Length = (UINT16)((DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *)UsbWWId) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16));1059if ((Length >= 1) && (SerialNumberStr[Length - 1] != 0)) {1060//1061// In case no NULL terminator in SerialNumber, create a new one with NULL terminator1062//1063NewStr = AllocatePool ((Length + 1) * sizeof (CHAR16));1064ASSERT (NewStr != NULL);1065CopyMem (NewStr, SerialNumberStr, Length * sizeof (CHAR16));1066NewStr[Length] = 0;1067SerialNumberStr = NewStr;1068}10691070UefiDevicePathLibCatPrint (1071Str,1072"UsbWwid(0x%x,0x%x,0x%x,\"%S\")",1073UsbWWId->VendorId,1074UsbWWId->ProductId,1075UsbWWId->InterfaceNumber,1076SerialNumberStr1077);1078}10791080/**1081Converts a Logic Unit device path structure to its string representative.10821083@param Str The string representative of input device.1084@param DevPath The input device path structure.1085@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1086of the display node is used, where applicable. If DisplayOnly1087is FALSE, then the longer text representation of the display node1088is used.1089@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1090representation for a device node can be used, where applicable.10911092**/1093static VOID1094DevPathToTextLogicalUnit (1095IN OUT POOL_PRINT *Str,1096IN VOID *DevPath,1097IN BOOLEAN DisplayOnly,1098IN BOOLEAN AllowShortcuts1099)1100{1101DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;11021103LogicalUnit = DevPath;1104UefiDevicePathLibCatPrint (Str, "Unit(0x%x)", LogicalUnit->Lun);1105}11061107/**1108Converts a USB class device path structure to its string representative.11091110@param Str The string representative of input device.1111@param DevPath The input device path structure.1112@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1113of the display node is used, where applicable. If DisplayOnly1114is FALSE, then the longer text representation of the display node1115is used.1116@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1117representation for a device node can be used, where applicable.11181119**/1120static VOID1121DevPathToTextUsbClass (1122IN OUT POOL_PRINT *Str,1123IN VOID *DevPath,1124IN BOOLEAN DisplayOnly,1125IN BOOLEAN AllowShortcuts1126)1127{1128USB_CLASS_DEVICE_PATH *UsbClass;1129BOOLEAN IsKnownSubClass;11301131UsbClass = DevPath;11321133IsKnownSubClass = TRUE;1134switch (UsbClass->DeviceClass) {1135case USB_CLASS_AUDIO:1136UefiDevicePathLibCatPrint (Str, "UsbAudio");1137break;11381139case USB_CLASS_CDCCONTROL:1140UefiDevicePathLibCatPrint (Str, "UsbCDCControl");1141break;11421143case USB_CLASS_HID:1144UefiDevicePathLibCatPrint (Str, "UsbHID");1145break;11461147case USB_CLASS_IMAGE:1148UefiDevicePathLibCatPrint (Str, "UsbImage");1149break;11501151case USB_CLASS_PRINTER:1152UefiDevicePathLibCatPrint (Str, "UsbPrinter");1153break;11541155case USB_CLASS_MASS_STORAGE:1156UefiDevicePathLibCatPrint (Str, "UsbMassStorage");1157break;11581159case USB_CLASS_HUB:1160UefiDevicePathLibCatPrint (Str, "UsbHub");1161break;11621163case USB_CLASS_CDCDATA:1164UefiDevicePathLibCatPrint (Str, "UsbCDCData");1165break;11661167case USB_CLASS_SMART_CARD:1168UefiDevicePathLibCatPrint (Str, "UsbSmartCard");1169break;11701171case USB_CLASS_VIDEO:1172UefiDevicePathLibCatPrint (Str, "UsbVideo");1173break;11741175case USB_CLASS_DIAGNOSTIC:1176UefiDevicePathLibCatPrint (Str, "UsbDiagnostic");1177break;11781179case USB_CLASS_WIRELESS:1180UefiDevicePathLibCatPrint (Str, "UsbWireless");1181break;11821183default:1184IsKnownSubClass = FALSE;1185break;1186}11871188if (IsKnownSubClass) {1189UefiDevicePathLibCatPrint (1190Str,1191"(0x%x,0x%x,0x%x,0x%x)",1192UsbClass->VendorId,1193UsbClass->ProductId,1194UsbClass->DeviceSubClass,1195UsbClass->DeviceProtocol1196);1197return;1198}11991200if (UsbClass->DeviceClass == USB_CLASS_RESERVE) {1201if (UsbClass->DeviceSubClass == USB_SUBCLASS_FW_UPDATE) {1202UefiDevicePathLibCatPrint (1203Str,1204"UsbDeviceFirmwareUpdate(0x%x,0x%x,0x%x)",1205UsbClass->VendorId,1206UsbClass->ProductId,1207UsbClass->DeviceProtocol1208);1209return;1210} else if (UsbClass->DeviceSubClass == USB_SUBCLASS_IRDA_BRIDGE) {1211UefiDevicePathLibCatPrint (1212Str,1213"UsbIrdaBridge(0x%x,0x%x,0x%x)",1214UsbClass->VendorId,1215UsbClass->ProductId,1216UsbClass->DeviceProtocol1217);1218return;1219} else if (UsbClass->DeviceSubClass == USB_SUBCLASS_TEST) {1220UefiDevicePathLibCatPrint (1221Str,1222"UsbTestAndMeasurement(0x%x,0x%x,0x%x)",1223UsbClass->VendorId,1224UsbClass->ProductId,1225UsbClass->DeviceProtocol1226);1227return;1228}1229}12301231UefiDevicePathLibCatPrint (1232Str,1233"UsbClass(0x%x,0x%x,0x%x,0x%x,0x%x)",1234UsbClass->VendorId,1235UsbClass->ProductId,1236UsbClass->DeviceClass,1237UsbClass->DeviceSubClass,1238UsbClass->DeviceProtocol1239);1240}12411242/**1243Converts a SATA device path structure to its string representative.12441245@param Str The string representative of input device.1246@param DevPath The input device path structure.1247@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1248of the display node is used, where applicable. If DisplayOnly1249is FALSE, then the longer text representation of the display node1250is used.1251@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1252representation for a device node can be used, where applicable.12531254**/1255static VOID1256DevPathToTextSata (1257IN OUT POOL_PRINT *Str,1258IN VOID *DevPath,1259IN BOOLEAN DisplayOnly,1260IN BOOLEAN AllowShortcuts1261)1262{1263SATA_DEVICE_PATH *Sata;12641265Sata = DevPath;1266UefiDevicePathLibCatPrint (1267Str,1268"Sata(0x%x,0x%x,0x%x)",1269Sata->HBAPortNumber,1270Sata->PortMultiplierPortNumber,1271Sata->Lun1272);1273}12741275/**1276Converts a I20 device path structure to its string representative.12771278@param Str The string representative of input device.1279@param DevPath The input device path structure.1280@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1281of the display node is used, where applicable. If DisplayOnly1282is FALSE, then the longer text representation of the display node1283is used.1284@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1285representation for a device node can be used, where applicable.12861287**/1288static VOID1289DevPathToTextI2O (1290IN OUT POOL_PRINT *Str,1291IN VOID *DevPath,1292IN BOOLEAN DisplayOnly,1293IN BOOLEAN AllowShortcuts1294)1295{1296I2O_DEVICE_PATH *I2ODevPath;12971298I2ODevPath = DevPath;1299UefiDevicePathLibCatPrint (Str, "I2O(0x%x)", I2ODevPath->Tid);1300}13011302/**1303Converts a MAC address device path structure to its string representative.13041305@param Str The string representative of input device.1306@param DevPath The input device path structure.1307@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1308of the display node is used, where applicable. If DisplayOnly1309is FALSE, then the longer text representation of the display node1310is used.1311@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1312representation for a device node can be used, where applicable.13131314**/1315static VOID1316DevPathToTextMacAddr (1317IN OUT POOL_PRINT *Str,1318IN VOID *DevPath,1319IN BOOLEAN DisplayOnly,1320IN BOOLEAN AllowShortcuts1321)1322{1323MAC_ADDR_DEVICE_PATH *MacDevPath;1324UINTN HwAddressSize;1325UINTN Index;13261327MacDevPath = DevPath;13281329HwAddressSize = sizeof (EFI_MAC_ADDRESS);1330if ((MacDevPath->IfType == 0x01) || (MacDevPath->IfType == 0x00)) {1331HwAddressSize = 6;1332}13331334UefiDevicePathLibCatPrint (Str, "MAC(");13351336for (Index = 0; Index < HwAddressSize; Index++) {1337UefiDevicePathLibCatPrint (Str, "%02x", MacDevPath->MacAddress.Addr[Index]);1338}13391340UefiDevicePathLibCatPrint (Str, ",0x%x)", MacDevPath->IfType);1341}13421343/**1344Converts network protocol string to its text representation.13451346@param Str The string representative of input device.1347@param Protocol The network protocol ID.13481349**/1350static VOID1351CatNetworkProtocol (1352IN OUT POOL_PRINT *Str,1353IN UINT16 Protocol1354)1355{1356if (Protocol == RFC_1700_TCP_PROTOCOL) {1357UefiDevicePathLibCatPrint (Str, "TCP");1358} else if (Protocol == RFC_1700_UDP_PROTOCOL) {1359UefiDevicePathLibCatPrint (Str, "UDP");1360} else {1361UefiDevicePathLibCatPrint (Str, "0x%x", Protocol);1362}1363}13641365/**1366Converts IP v4 address to its text representation.13671368@param Str The string representative of input device.1369@param Address The IP v4 address.1370**/1371static VOID1372CatIPv4Address (1373IN OUT POOL_PRINT *Str,1374IN EFI_IPv4_ADDRESS *Address1375)1376{1377UefiDevicePathLibCatPrint (Str, "%d.%d.%d.%d", Address->Addr[0], Address->Addr[1], Address->Addr[2], Address->Addr[3]);1378}13791380/**1381Converts IP v6 address to its text representation.13821383@param Str The string representative of input device.1384@param Address The IP v6 address.1385**/1386static VOID1387CatIPv6Address (1388IN OUT POOL_PRINT *Str,1389IN EFI_IPv6_ADDRESS *Address1390)1391{1392UefiDevicePathLibCatPrint (1393Str,1394"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",1395Address->Addr[0],1396Address->Addr[1],1397Address->Addr[2],1398Address->Addr[3],1399Address->Addr[4],1400Address->Addr[5],1401Address->Addr[6],1402Address->Addr[7],1403Address->Addr[8],1404Address->Addr[9],1405Address->Addr[10],1406Address->Addr[11],1407Address->Addr[12],1408Address->Addr[13],1409Address->Addr[14],1410Address->Addr[15]1411);1412}14131414/**1415Converts a IPv4 device path structure to its string representative.14161417@param Str The string representative of input device.1418@param DevPath The input device path structure.1419@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1420of the display node is used, where applicable. If DisplayOnly1421is FALSE, then the longer text representation of the display node1422is used.1423@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1424representation for a device node can be used, where applicable.14251426**/1427static VOID1428DevPathToTextIPv4 (1429IN OUT POOL_PRINT *Str,1430IN VOID *DevPath,1431IN BOOLEAN DisplayOnly,1432IN BOOLEAN AllowShortcuts1433)1434{1435IPv4_DEVICE_PATH *IPDevPath;14361437IPDevPath = DevPath;1438UefiDevicePathLibCatPrint (Str, "IPv4(");1439CatIPv4Address (Str, &IPDevPath->RemoteIpAddress);14401441if (DisplayOnly) {1442UefiDevicePathLibCatPrint (Str, ")");1443return;1444}14451446UefiDevicePathLibCatPrint (Str, ",");1447CatNetworkProtocol (Str, IPDevPath->Protocol);14481449UefiDevicePathLibCatPrint (Str, ",%s,", IPDevPath->StaticIpAddress ? "Static" : "DHCP");1450CatIPv4Address (Str, &IPDevPath->LocalIpAddress);1451if (DevicePathNodeLength (IPDevPath) == sizeof (IPv4_DEVICE_PATH)) {1452UefiDevicePathLibCatPrint (Str, ",");1453CatIPv4Address (Str, &IPDevPath->GatewayIpAddress);1454UefiDevicePathLibCatPrint (Str, ",");1455CatIPv4Address (Str, &IPDevPath->SubnetMask);1456}14571458UefiDevicePathLibCatPrint (Str, ")");1459}14601461/**1462Converts a IPv6 device path structure to its string representative.14631464@param Str The string representative of input device.1465@param DevPath The input device path structure.1466@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1467of the display node is used, where applicable. If DisplayOnly1468is FALSE, then the longer text representation of the display node1469is used.1470@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1471representation for a device node can be used, where applicable.14721473**/1474static VOID1475DevPathToTextIPv6 (1476IN OUT POOL_PRINT *Str,1477IN VOID *DevPath,1478IN BOOLEAN DisplayOnly,1479IN BOOLEAN AllowShortcuts1480)1481{1482IPv6_DEVICE_PATH *IPDevPath;14831484IPDevPath = DevPath;1485UefiDevicePathLibCatPrint (Str, "IPv6(");1486CatIPv6Address (Str, &IPDevPath->RemoteIpAddress);1487if (DisplayOnly) {1488UefiDevicePathLibCatPrint (Str, ")");1489return;1490}14911492UefiDevicePathLibCatPrint (Str, ",");1493CatNetworkProtocol (Str, IPDevPath->Protocol);14941495switch (IPDevPath->IpAddressOrigin) {1496case 0:1497UefiDevicePathLibCatPrint (Str, ",Static,");1498break;1499case 1:1500UefiDevicePathLibCatPrint (Str, ",StatelessAutoConfigure,");1501break;1502default:1503UefiDevicePathLibCatPrint (Str, ",StatefulAutoConfigure,");1504break;1505}15061507CatIPv6Address (Str, &IPDevPath->LocalIpAddress);15081509if (DevicePathNodeLength (IPDevPath) == sizeof (IPv6_DEVICE_PATH)) {1510UefiDevicePathLibCatPrint (Str, ",0x%x,", IPDevPath->PrefixLength);1511CatIPv6Address (Str, &IPDevPath->GatewayIpAddress);1512}15131514UefiDevicePathLibCatPrint (Str, ")");1515}15161517/**1518Converts an Infini Band device path structure to its string representative.15191520@param Str The string representative of input device.1521@param DevPath The input device path structure.1522@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1523of the display node is used, where applicable. If DisplayOnly1524is FALSE, then the longer text representation of the display node1525is used.1526@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1527representation for a device node can be used, where applicable.15281529**/1530static VOID1531DevPathToTextInfiniBand (1532IN OUT POOL_PRINT *Str,1533IN VOID *DevPath,1534IN BOOLEAN DisplayOnly,1535IN BOOLEAN AllowShortcuts1536)1537{1538INFINIBAND_DEVICE_PATH *InfiniBand;15391540InfiniBand = DevPath;1541UefiDevicePathLibCatPrint (1542Str,1543"Infiniband(0x%x,%36s,0x%lx,0x%lx,0x%lx)",1544InfiniBand->ResourceFlags,1545G(InfiniBand->PortGid),1546InfiniBand->ServiceId,1547InfiniBand->TargetPortId,1548InfiniBand->DeviceId1549);1550}15511552/**1553Converts a UART device path structure to its string representative.15541555@param Str The string representative of input device.1556@param DevPath The input device path structure.1557@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1558of the display node is used, where applicable. If DisplayOnly1559is FALSE, then the longer text representation of the display node1560is used.1561@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1562representation for a device node can be used, where applicable.15631564**/1565static VOID1566DevPathToTextUart (1567IN OUT POOL_PRINT *Str,1568IN VOID *DevPath,1569IN BOOLEAN DisplayOnly,1570IN BOOLEAN AllowShortcuts1571)1572{1573UART_DEVICE_PATH *Uart;1574CHAR8 Parity;15751576Uart = DevPath;1577switch (Uart->Parity) {1578case 0:1579Parity = 'D';1580break;15811582case 1:1583Parity = 'N';1584break;15851586case 2:1587Parity = 'E';1588break;15891590case 3:1591Parity = 'O';1592break;15931594case 4:1595Parity = 'M';1596break;15971598case 5:1599Parity = 'S';1600break;16011602default:1603Parity = 'x';1604break;1605}16061607if (Uart->BaudRate == 0) {1608UefiDevicePathLibCatPrint (Str, "Uart(DEFAULT,");1609} else {1610UefiDevicePathLibCatPrint (Str, "Uart(%ld,", Uart->BaudRate);1611}16121613if (Uart->DataBits == 0) {1614UefiDevicePathLibCatPrint (Str, "DEFAULT,");1615} else {1616UefiDevicePathLibCatPrint (Str, "%d,", Uart->DataBits);1617}16181619UefiDevicePathLibCatPrint (Str, "%c,", Parity);16201621switch (Uart->StopBits) {1622case 0:1623UefiDevicePathLibCatPrint (Str, "D)");1624break;16251626case 1:1627UefiDevicePathLibCatPrint (Str, "1)");1628break;16291630case 2:1631UefiDevicePathLibCatPrint (Str, "1.5)");1632break;16331634case 3:1635UefiDevicePathLibCatPrint (Str, "2)");1636break;16371638default:1639UefiDevicePathLibCatPrint (Str, "x)");1640break;1641}1642}16431644/**1645Converts an iSCSI device path structure to its string representative.16461647@param Str The string representative of input device.1648@param DevPath The input device path structure.1649@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1650of the display node is used, where applicable. If DisplayOnly1651is FALSE, then the longer text representation of the display node1652is used.1653@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1654representation for a device node can be used, where applicable.16551656**/1657static VOID1658DevPathToTextiSCSI (1659IN OUT POOL_PRINT *Str,1660IN VOID *DevPath,1661IN BOOLEAN DisplayOnly,1662IN BOOLEAN AllowShortcuts1663)1664{1665ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;1666UINT16 Options;1667UINTN Index;16681669ISCSIDevPath = DevPath;1670UefiDevicePathLibCatPrint (1671Str,1672"iSCSI(%s,0x%x,0x",1673ISCSIDevPath->TargetName,1674ISCSIDevPath->TargetPortalGroupTag1675);1676for (Index = 0; Index < sizeof (ISCSIDevPath->Lun) / sizeof (UINT8); Index++) {1677UefiDevicePathLibCatPrint (Str, "%02x", ((UINT8 *)&ISCSIDevPath->Lun)[Index]);1678}16791680Options = ISCSIDevPath->LoginOption;1681UefiDevicePathLibCatPrint (Str, ",%s,", (((Options >> 1) & 0x0001) != 0) ? "CRC32C" : "None");1682UefiDevicePathLibCatPrint (Str, "%s,", (((Options >> 3) & 0x0001) != 0) ? "CRC32C" : "None");1683if (((Options >> 11) & 0x0001) != 0) {1684UefiDevicePathLibCatPrint (Str, "%s,", "None");1685} else if (((Options >> 12) & 0x0001) != 0) {1686UefiDevicePathLibCatPrint (Str, "%s,", "CHAP_UNI");1687} else {1688UefiDevicePathLibCatPrint (Str, "%s,", "CHAP_BI");1689}16901691UefiDevicePathLibCatPrint (Str, "%s)", (ISCSIDevPath->NetworkProtocol == 0) ? "TCP" : "reserved");1692}16931694/**1695Converts a VLAN device path structure to its string representative.16961697@param Str The string representative of input device.1698@param DevPath The input device path structure.1699@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1700of the display node is used, where applicable. If DisplayOnly1701is FALSE, then the longer text representation of the display node1702is used.1703@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1704representation for a device node can be used, where applicable.17051706**/1707static VOID1708DevPathToTextVlan (1709IN OUT POOL_PRINT *Str,1710IN VOID *DevPath,1711IN BOOLEAN DisplayOnly,1712IN BOOLEAN AllowShortcuts1713)1714{1715VLAN_DEVICE_PATH *Vlan;17161717Vlan = DevPath;1718UefiDevicePathLibCatPrint (Str, "Vlan(%d)", Vlan->VlanId);1719}17201721/**1722Converts a Bluetooth device path structure to its string representative.17231724@param Str The string representative of input device.1725@param DevPath The input device path structure.1726@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1727of the display node is used, where applicable. If DisplayOnly1728is FALSE, then the longer text representation of the display node1729is used.1730@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1731representation for a device node can be used, where applicable.17321733**/1734static VOID1735DevPathToTextBluetooth (1736IN OUT POOL_PRINT *Str,1737IN VOID *DevPath,1738IN BOOLEAN DisplayOnly,1739IN BOOLEAN AllowShortcuts1740)1741{1742BLUETOOTH_DEVICE_PATH *Bluetooth;17431744Bluetooth = DevPath;1745UefiDevicePathLibCatPrint (1746Str,1747"Bluetooth(%02x%02x%02x%02x%02x%02x)",1748Bluetooth->BD_ADDR.Address[0],1749Bluetooth->BD_ADDR.Address[1],1750Bluetooth->BD_ADDR.Address[2],1751Bluetooth->BD_ADDR.Address[3],1752Bluetooth->BD_ADDR.Address[4],1753Bluetooth->BD_ADDR.Address[5]1754);1755}17561757/**1758Converts a Wi-Fi device path structure to its string representative.17591760@param Str The string representative of input device.1761@param DevPath The input device path structure.1762@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1763of the display node is used, where applicable. If DisplayOnly1764is FALSE, then the longer text representation of the display node1765is used.1766@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1767representation for a device node can be used, where applicable.17681769**/1770static VOID1771DevPathToTextWiFi (1772IN OUT POOL_PRINT *Str,1773IN VOID *DevPath,1774IN BOOLEAN DisplayOnly,1775IN BOOLEAN AllowShortcuts1776)1777{1778WIFI_DEVICE_PATH *WiFi;1779UINT8 SSId[33];17801781WiFi = DevPath;17821783SSId[32] = '\0';1784CopyMem (SSId, WiFi->SSId, 32);17851786UefiDevicePathLibCatPrint (Str, "Wi-Fi(%s)", SSId);1787}17881789/**1790Converts a Bluetooth device path structure to its string representative.17911792@param Str The string representative of input device.1793@param DevPath The input device path structure.1794@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1795of the display node is used, where applicable. If DisplayOnly1796is FALSE, then the longer text representation of the display node1797is used.1798@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1799representation for a device node can be used, where applicable.18001801**/1802static VOID1803DevPathToTextBluetoothLE (1804IN OUT POOL_PRINT *Str,1805IN VOID *DevPath,1806IN BOOLEAN DisplayOnly,1807IN BOOLEAN AllowShortcuts1808)1809{1810BLUETOOTH_LE_DEVICE_PATH *BluetoothLE;18111812BluetoothLE = DevPath;1813UefiDevicePathLibCatPrint (1814Str,1815"BluetoothLE(%02x%02x%02x%02x%02x%02x,0x%02x)",1816BluetoothLE->Address.Address[0],1817BluetoothLE->Address.Address[1],1818BluetoothLE->Address.Address[2],1819BluetoothLE->Address.Address[3],1820BluetoothLE->Address.Address[4],1821BluetoothLE->Address.Address[5],1822BluetoothLE->Address.Type1823);1824}18251826/**1827Converts a DNS device path structure to its string representative.18281829@param Str The string representative of input device.1830@param DevPath The input device path structure.1831@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1832of the display node is used, where applicable. If DisplayOnly1833is FALSE, then the longer text representation of the display node1834is used.1835@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1836representation for a device node can be used, where applicable.18371838**/1839static VOID1840DevPathToTextDns (1841IN OUT POOL_PRINT *Str,1842IN VOID *DevPath,1843IN BOOLEAN DisplayOnly,1844IN BOOLEAN AllowShortcuts1845)1846{1847DNS_DEVICE_PATH *DnsDevPath;1848UINT32 DnsServerIpCount;1849UINT32 DnsServerIpIndex;18501851DnsDevPath = DevPath;1852DnsServerIpCount = (UINT32)(DevicePathNodeLength (DnsDevPath) - sizeof (EFI_DEVICE_PATH_PROTOCOL) - sizeof (DnsDevPath->IsIPv6)) / sizeof (EFI_IP_ADDRESS);18531854UefiDevicePathLibCatPrint (Str, "Dns(");18551856for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {1857if (DnsDevPath->IsIPv6 == 0x00) {1858CatIPv4Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v4));1859} else {1860CatIPv6Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v6));1861}18621863if (DnsServerIpIndex < DnsServerIpCount - 1) {1864UefiDevicePathLibCatPrint (Str, ",");1865}1866}18671868UefiDevicePathLibCatPrint (Str, ")");1869}18701871/**1872Converts a URI device path structure to its string representative.18731874@param Str The string representative of input device.1875@param DevPath The input device path structure.1876@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1877of the display node is used, where applicable. If DisplayOnly1878is FALSE, then the longer text representation of the display node1879is used.1880@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1881representation for a device node can be used, where applicable.18821883**/1884static VOID1885DevPathToTextUri (1886IN OUT POOL_PRINT *Str,1887IN VOID *DevPath,1888IN BOOLEAN DisplayOnly,1889IN BOOLEAN AllowShortcuts1890)1891{1892URI_DEVICE_PATH *Uri;1893UINTN UriLength;1894CHAR8 *UriStr;18951896//1897// Uri in the device path may not be null terminated.1898//1899Uri = DevPath;1900UriLength = DevicePathNodeLength (Uri) - sizeof (URI_DEVICE_PATH);1901UriStr = AllocatePool (UriLength + 1);19021903if (UriStr == NULL) {1904ASSERT (UriStr != NULL);1905return;1906}19071908CopyMem (UriStr, Uri->Uri, UriLength);1909UriStr[UriLength] = '\0';1910UefiDevicePathLibCatPrint (Str, "Uri(%s)", UriStr);1911FreePool (UriStr);1912}19131914/**1915Converts a Hard drive device path structure to its string representative.19161917@param Str The string representative of input device.1918@param DevPath The input device path structure.1919@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1920of the display node is used, where applicable. If DisplayOnly1921is FALSE, then the longer text representation of the display node1922is used.1923@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1924representation for a device node can be used, where applicable.19251926**/1927static VOID1928DevPathToTextHardDrive (1929IN OUT POOL_PRINT *Str,1930IN VOID *DevPath,1931IN BOOLEAN DisplayOnly,1932IN BOOLEAN AllowShortcuts1933)1934{1935HARDDRIVE_DEVICE_PATH *Hd;19361937Hd = DevPath;1938switch (Hd->SignatureType) {1939case SIGNATURE_TYPE_MBR:1940UefiDevicePathLibCatPrint (1941Str,1942"HD(%d,%s,0x%08x",1943Hd->PartitionNumber,1944"MBR",1945// *((UINT32 *)(&(Hd->Signature[0])))1946le32dec(&(Hd->Signature[0]))1947);1948break;19491950case SIGNATURE_TYPE_GUID:1951UefiDevicePathLibCatPrint (1952Str,1953"HD(%d,%s,%36s",1954Hd->PartitionNumber,1955"GPT",1956G(&(Hd->Signature[0]))1957);1958break;19591960default:1961UefiDevicePathLibCatPrint (1962Str,1963"HD(%d,%d,0",1964Hd->PartitionNumber,1965Hd->SignatureType1966);1967break;1968}19691970if (DisplayOnly) {1971UefiDevicePathLibCatPrint (Str, ")");1972} else {1973UefiDevicePathLibCatPrint (Str, ",0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize);1974}1975}19761977/**1978Converts a CDROM device path structure to its string representative.19791980@param Str The string representative of input device.1981@param DevPath The input device path structure.1982@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1983of the display node is used, where applicable. If DisplayOnly1984is FALSE, then the longer text representation of the display node1985is used.1986@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1987representation for a device node can be used, where applicable.19881989**/1990static VOID1991DevPathToTextCDROM (1992IN OUT POOL_PRINT *Str,1993IN VOID *DevPath,1994IN BOOLEAN DisplayOnly,1995IN BOOLEAN AllowShortcuts1996)1997{1998CDROM_DEVICE_PATH *Cd;19992000Cd = DevPath;2001if (DisplayOnly) {2002UefiDevicePathLibCatPrint (Str, "CDROM(0x%x)", Cd->BootEntry);2003return;2004}20052006UefiDevicePathLibCatPrint (Str, "CDROM(0x%x,0x%lx,0x%lx)", Cd->BootEntry, Cd->PartitionStart, Cd->PartitionSize);2007}20082009/**2010Converts a File device path structure to its string representative.20112012@param Str The string representative of input device.2013@param DevPath The input device path structure.2014@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2015of the display node is used, where applicable. If DisplayOnly2016is FALSE, then the longer text representation of the display node2017is used.2018@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2019representation for a device node can be used, where applicable.20202021**/2022static VOID2023DevPathToTextFilePath (2024IN OUT POOL_PRINT *Str,2025IN VOID *DevPath,2026IN BOOLEAN DisplayOnly,2027IN BOOLEAN AllowShortcuts2028)2029{2030FILEPATH_DEVICE_PATH *Fp;2031char *name = NULL;20322033Fp = DevPath;2034ucs2_to_utf8(Fp->PathName, &name);2035UefiDevicePathLibCatPrint (Str, "File(%s)", name);2036free(name);2037}20382039/**2040Converts a Media protocol device path structure to its string representative.20412042@param Str The string representative of input device.2043@param DevPath The input device path structure.2044@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2045of the display node is used, where applicable. If DisplayOnly2046is FALSE, then the longer text representation of the display node2047is used.2048@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2049representation for a device node can be used, where applicable.20502051**/2052static VOID2053DevPathToTextMediaProtocol (2054IN OUT POOL_PRINT *Str,2055IN VOID *DevPath,2056IN BOOLEAN DisplayOnly,2057IN BOOLEAN AllowShortcuts2058)2059{2060MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;20612062MediaProt = DevPath;2063UefiDevicePathLibCatPrint (Str, "Media(%36s)", G(&MediaProt->Protocol));2064}20652066/**2067Converts a Firmware Volume device path structure to its string representative.20682069@param Str The string representative of input device.2070@param DevPath The input device path structure.2071@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2072of the display node is used, where applicable. If DisplayOnly2073is FALSE, then the longer text representation of the display node2074is used.2075@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2076representation for a device node can be used, where applicable.20772078**/2079static VOID2080DevPathToTextFv (2081IN OUT POOL_PRINT *Str,2082IN VOID *DevPath,2083IN BOOLEAN DisplayOnly,2084IN BOOLEAN AllowShortcuts2085)2086{2087MEDIA_FW_VOL_DEVICE_PATH *Fv;20882089Fv = DevPath;2090UefiDevicePathLibCatPrint (Str, "Fv(%36s)", G(&Fv->FvName));2091}20922093/**2094Converts a Firmware Volume File device path structure to its string representative.20952096@param Str The string representative of input device.2097@param DevPath The input device path structure.2098@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2099of the display node is used, where applicable. If DisplayOnly2100is FALSE, then the longer text representation of the display node2101is used.2102@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2103representation for a device node can be used, where applicable.21042105**/2106static VOID2107DevPathToTextFvFile (2108IN OUT POOL_PRINT *Str,2109IN VOID *DevPath,2110IN BOOLEAN DisplayOnly,2111IN BOOLEAN AllowShortcuts2112)2113{2114MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFile;21152116FvFile = DevPath;2117UefiDevicePathLibCatPrint (Str, "FvFile(%36s)", G(&FvFile->FvFileName));2118}21192120/**2121Converts a Relative Offset device path structure to its string representative.21222123@param Str The string representative of input device.2124@param DevPath The input device path structure.2125@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2126of the display node is used, where applicable. If DisplayOnly2127is FALSE, then the longer text representation of the display node2128is used.2129@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2130representation for a device node can be used, where applicable.21312132**/2133static VOID2134DevPathRelativeOffsetRange (2135IN OUT POOL_PRINT *Str,2136IN VOID *DevPath,2137IN BOOLEAN DisplayOnly,2138IN BOOLEAN AllowShortcuts2139)2140{2141MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;21422143Offset = DevPath;2144UefiDevicePathLibCatPrint (2145Str,2146"Offset(0x%lx,0x%lx)",2147Offset->StartingOffset,2148Offset->EndingOffset2149);2150}21512152/**2153Converts a Ram Disk device path structure to its string representative.21542155@param Str The string representative of input device.2156@param DevPath The input device path structure.2157@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2158of the display node is used, where applicable. If DisplayOnly2159is FALSE, then the longer text representation of the display node2160is used.2161@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2162representation for a device node can be used, where applicable.21632164**/2165static VOID2166DevPathToTextRamDisk (2167IN OUT POOL_PRINT *Str,2168IN VOID *DevPath,2169IN BOOLEAN DisplayOnly,2170IN BOOLEAN AllowShortcuts2171)2172{2173MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;21742175RamDisk = DevPath;21762177if (CompareGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid)) {2178UefiDevicePathLibCatPrint (2179Str,2180"VirtualDisk(0x%lx,0x%lx,%d)",2181LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],2182LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],2183RamDisk->Instance2184);2185} else if (CompareGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid)) {2186UefiDevicePathLibCatPrint (2187Str,2188"VirtualCD(0x%lx,0x%lx,%d)",2189LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],2190LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],2191RamDisk->Instance2192);2193} else if (CompareGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid)) {2194UefiDevicePathLibCatPrint (2195Str,2196"PersistentVirtualDisk(0x%lx,0x%lx,%d)",2197LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],2198LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],2199RamDisk->Instance2200);2201} else if (CompareGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid)) {2202UefiDevicePathLibCatPrint (2203Str,2204"PersistentVirtualCD(0x%lx,0x%lx,%d)",2205LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],2206LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],2207RamDisk->Instance2208);2209} else {2210UefiDevicePathLibCatPrint (2211Str,2212"RamDisk(0x%lx,0x%lx,%d,%36s)",2213LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],2214LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],2215RamDisk->Instance,2216G(&RamDisk->TypeGuid)2217);2218}2219}22202221/**2222Converts a BIOS Boot Specification device path structure to its string representative.22232224@param Str The string representative of input device.2225@param DevPath The input device path structure.2226@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2227of the display node is used, where applicable. If DisplayOnly2228is FALSE, then the longer text representation of the display node2229is used.2230@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2231representation for a device node can be used, where applicable.22322233**/2234static VOID2235DevPathToTextBBS (2236IN OUT POOL_PRINT *Str,2237IN VOID *DevPath,2238IN BOOLEAN DisplayOnly,2239IN BOOLEAN AllowShortcuts2240)2241{2242BBS_BBS_DEVICE_PATH *Bbs;2243const char *Type;22442245Bbs = DevPath;2246switch (Bbs->DeviceType) {2247case BBS_TYPE_FLOPPY:2248Type = "Floppy";2249break;22502251case BBS_TYPE_HARDDRIVE:2252Type = "HD";2253break;22542255case BBS_TYPE_CDROM:2256Type = "CDROM";2257break;22582259case BBS_TYPE_PCMCIA:2260Type = "PCMCIA";2261break;22622263case BBS_TYPE_USB:2264Type = "USB";2265break;22662267case BBS_TYPE_EMBEDDED_NETWORK:2268Type = "Network";2269break;22702271default:2272Type = NULL;2273break;2274}22752276if (Type != NULL) {2277UefiDevicePathLibCatPrint (Str, "BBS(%s,%s", Type, Bbs->String);2278} else {2279UefiDevicePathLibCatPrint (Str, "BBS(0x%x,%s", Bbs->DeviceType, Bbs->String);2280}22812282if (DisplayOnly) {2283UefiDevicePathLibCatPrint (Str, ")");2284return;2285}22862287UefiDevicePathLibCatPrint (Str, ",0x%x)", Bbs->StatusFlag);2288}22892290/**2291Converts an End-of-Device-Path structure to its string representative.22922293@param Str The string representative of input device.2294@param DevPath The input device path structure.2295@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2296of the display node is used, where applicable. If DisplayOnly2297is FALSE, then the longer text representation of the display node2298is used.2299@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2300representation for a device node can be used, where applicable.23012302**/2303static VOID2304DevPathToTextEndInstance (2305IN OUT POOL_PRINT *Str,2306IN VOID *DevPath,2307IN BOOLEAN DisplayOnly,2308IN BOOLEAN AllowShortcuts2309)2310{2311UefiDevicePathLibCatPrint (Str, ",");2312}23132314GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_GENERIC_TABLE mUefiDevicePathLibToTextTableGeneric[] = {2315{ HARDWARE_DEVICE_PATH, "HardwarePath" },2316{ ACPI_DEVICE_PATH, "AcpiPath" },2317{ MESSAGING_DEVICE_PATH, "Msg" },2318{ MEDIA_DEVICE_PATH, "MediaPath" },2319{ BBS_DEVICE_PATH, "BbsPath" },2320{ 0, NULL }2321};23222323/**2324Converts an unknown device path structure to its string representative.23252326@param Str The string representative of input device.2327@param DevPath The input device path structure.2328@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2329of the display node is used, where applicable. If DisplayOnly2330is FALSE, then the longer text representation of the display node2331is used.2332@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2333representation for a device node can be used, where applicable.23342335**/2336static VOID2337DevPathToTextNodeGeneric (2338IN OUT POOL_PRINT *Str,2339IN VOID *DevPath,2340IN BOOLEAN DisplayOnly,2341IN BOOLEAN AllowShortcuts2342)2343{2344EFI_DEVICE_PATH_PROTOCOL *Node;2345UINTN Index;23462347Node = DevPath;23482349for (Index = 0; mUefiDevicePathLibToTextTableGeneric[Index].Text != NULL; Index++) {2350if (DevicePathType (Node) == mUefiDevicePathLibToTextTableGeneric[Index].Type) {2351break;2352}2353}23542355if (mUefiDevicePathLibToTextTableGeneric[Index].Text == NULL) {2356//2357// It's a node whose type cannot be recognized2358//2359UefiDevicePathLibCatPrint (Str, "Path(%d,%d", DevicePathType (Node), DevicePathSubType (Node));2360} else {2361//2362// It's a node whose type can be recognized2363//2364UefiDevicePathLibCatPrint (Str, "%s(%d", mUefiDevicePathLibToTextTableGeneric[Index].Text, DevicePathSubType (Node));2365}23662367Index = sizeof (EFI_DEVICE_PATH_PROTOCOL);2368if (Index < DevicePathNodeLength (Node)) {2369UefiDevicePathLibCatPrint (Str, ",");2370for ( ; Index < DevicePathNodeLength (Node); Index++) {2371UefiDevicePathLibCatPrint (Str, "%02x", ((UINT8 *)Node)[Index]);2372}2373}23742375UefiDevicePathLibCatPrint (Str, ")");2376}23772378static const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibToTextTable[] = {2379{ HARDWARE_DEVICE_PATH, HW_PCI_DP, DevPathToTextPci },2380{ HARDWARE_DEVICE_PATH, HW_PCCARD_DP, DevPathToTextPccard },2381{ HARDWARE_DEVICE_PATH, HW_MEMMAP_DP, DevPathToTextMemMap },2382{ HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DevPathToTextVendor },2383{ HARDWARE_DEVICE_PATH, HW_CONTROLLER_DP, DevPathToTextController },2384{ HARDWARE_DEVICE_PATH, HW_BMC_DP, DevPathToTextBmc },2385{ ACPI_DEVICE_PATH, ACPI_DP, DevPathToTextAcpi },2386{ ACPI_DEVICE_PATH, ACPI_EXTENDED_DP, DevPathToTextAcpiEx },2387{ ACPI_DEVICE_PATH, ACPI_ADR_DP, DevPathToTextAcpiAdr },2388{ MESSAGING_DEVICE_PATH, MSG_ATAPI_DP, DevPathToTextAtapi },2389{ MESSAGING_DEVICE_PATH, MSG_SCSI_DP, DevPathToTextScsi },2390{ MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP, DevPathToTextFibre },2391{ MESSAGING_DEVICE_PATH, MSG_FIBRECHANNELEX_DP, DevPathToTextFibreEx },2392{ MESSAGING_DEVICE_PATH, MSG_SASEX_DP, DevPathToTextSasEx },2393{ MESSAGING_DEVICE_PATH, MSG_NVME_NAMESPACE_DP, DevPathToTextNVMe },2394{ MESSAGING_DEVICE_PATH, MSG_UFS_DP, DevPathToTextUfs },2395{ MESSAGING_DEVICE_PATH, MSG_SD_DP, DevPathToTextSd },2396{ MESSAGING_DEVICE_PATH, MSG_EMMC_DP, DevPathToTextEmmc },2397{ MESSAGING_DEVICE_PATH, MSG_1394_DP, DevPathToText1394 },2398{ MESSAGING_DEVICE_PATH, MSG_USB_DP, DevPathToTextUsb },2399{ MESSAGING_DEVICE_PATH, MSG_USB_WWID_DP, DevPathToTextUsbWWID },2400{ MESSAGING_DEVICE_PATH, MSG_DEVICE_LOGICAL_UNIT_DP, DevPathToTextLogicalUnit },2401{ MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP, DevPathToTextUsbClass },2402{ MESSAGING_DEVICE_PATH, MSG_SATA_DP, DevPathToTextSata },2403{ MESSAGING_DEVICE_PATH, MSG_I2O_DP, DevPathToTextI2O },2404{ MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, DevPathToTextMacAddr },2405{ MESSAGING_DEVICE_PATH, MSG_IPv4_DP, DevPathToTextIPv4 },2406{ MESSAGING_DEVICE_PATH, MSG_IPv6_DP, DevPathToTextIPv6 },2407{ MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, DevPathToTextInfiniBand },2408{ MESSAGING_DEVICE_PATH, MSG_UART_DP, DevPathToTextUart },2409{ MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, DevPathToTextVendor },2410{ MESSAGING_DEVICE_PATH, MSG_ISCSI_DP, DevPathToTextiSCSI },2411{ MESSAGING_DEVICE_PATH, MSG_VLAN_DP, DevPathToTextVlan },2412{ MESSAGING_DEVICE_PATH, MSG_DNS_DP, DevPathToTextDns },2413{ MESSAGING_DEVICE_PATH, MSG_URI_DP, DevPathToTextUri },2414{ MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_DP, DevPathToTextBluetooth },2415{ MESSAGING_DEVICE_PATH, MSG_WIFI_DP, DevPathToTextWiFi },2416{ MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_LE_DP, DevPathToTextBluetoothLE },2417{ MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, DevPathToTextHardDrive },2418{ MEDIA_DEVICE_PATH, MEDIA_CDROM_DP, DevPathToTextCDROM },2419{ MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, DevPathToTextVendor },2420{ MEDIA_DEVICE_PATH, MEDIA_PROTOCOL_DP, DevPathToTextMediaProtocol },2421{ MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, DevPathToTextFilePath },2422{ MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_VOL_DP, DevPathToTextFv },2423{ MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP, DevPathToTextFvFile },2424{ MEDIA_DEVICE_PATH, MEDIA_RELATIVE_OFFSET_RANGE_DP, DevPathRelativeOffsetRange },2425{ MEDIA_DEVICE_PATH, MEDIA_RAM_DISK_DP, DevPathToTextRamDisk },2426{ BBS_DEVICE_PATH, BBS_BBS_DP, DevPathToTextBBS },2427{ END_DEVICE_PATH_TYPE, END_INSTANCE_DEVICE_PATH_SUBTYPE, DevPathToTextEndInstance },2428{ 0, 0, NULL }2429};24302431/**2432Converts a device node to its string representation.24332434@param DeviceNode A Pointer to the device node to be converted.2435@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2436of the display node is used, where applicable. If DisplayOnly2437is FALSE, then the longer text representation of the display node2438is used.2439@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2440representation for a device node can be used, where applicable.24412442@return A pointer to the allocated text representation of the device node or NULL if DeviceNode2443is NULL or there was insufficient memory.24442445**/2446static char *2447EFIAPI2448UefiDevicePathLibConvertDeviceNodeToText (2449IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,2450IN BOOLEAN DisplayOnly,2451IN BOOLEAN AllowShortcuts2452)2453{2454POOL_PRINT Str;2455UINTN Index;2456DEVICE_PATH_TO_TEXT ToText;2457EFI_DEVICE_PATH_PROTOCOL *Node;24582459if (DeviceNode == NULL) {2460return NULL;2461}24622463ZeroMem (&Str, sizeof (Str));24642465//2466// Process the device path node2467// If not found, use a generic function2468//2469Node = __DECONST(EFI_DEVICE_PATH_PROTOCOL *, DeviceNode);2470ToText = DevPathToTextNodeGeneric;2471for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index++) {2472if ((DevicePathType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].Type) &&2473(DevicePathSubType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].SubType)2474)2475{2476ToText = mUefiDevicePathLibToTextTable[Index].Function;2477break;2478}2479}24802481//2482// Print this node2483//2484ToText (&Str, (VOID *)Node, DisplayOnly, AllowShortcuts);24852486ASSERT (Str.Str != NULL);2487return Str.Str;2488}24892490/**2491Converts a device path to its text representation.24922493@param DevicePath A Pointer to the device to be converted.2494@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2495of the display node is used, where applicable. If DisplayOnly2496is FALSE, then the longer text representation of the display node2497is used.2498@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2499representation for a device node can be used, where applicable.25002501@return A pointer to the allocated text representation of the device path or2502NULL if DeviceNode is NULL or there was insufficient memory.25032504**/2505static char *2506EFIAPI2507UefiDevicePathLibConvertDevicePathToText (2508IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,2509IN BOOLEAN DisplayOnly,2510IN BOOLEAN AllowShortcuts2511)2512{2513POOL_PRINT Str;2514EFI_DEVICE_PATH_PROTOCOL *Node;2515EFI_DEVICE_PATH_PROTOCOL *AlignedNode;2516UINTN Index;2517DEVICE_PATH_TO_TEXT ToText;25182519if (DevicePath == NULL) {2520return NULL;2521}25222523ZeroMem (&Str, sizeof (Str));25242525//2526// Process each device path node2527//2528Node = __DECONST(EFI_DEVICE_PATH_PROTOCOL *, DevicePath);2529while (!IsDevicePathEnd (Node)) {2530//2531// Find the handler to dump this device path node2532// If not found, use a generic function2533//2534ToText = DevPathToTextNodeGeneric;2535for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index += 1) {2536if ((DevicePathType (Node) == mUefiDevicePathLibToTextTable[Index].Type) &&2537(DevicePathSubType (Node) == mUefiDevicePathLibToTextTable[Index].SubType)2538)2539{2540ToText = mUefiDevicePathLibToTextTable[Index].Function;2541break;2542}2543}25442545//2546// Put a path separator in if needed2547//2548if ((Str.Count != 0) && (ToText != DevPathToTextEndInstance)) {2549if (Str.Str[Str.Count] != ',') {2550UefiDevicePathLibCatPrint (&Str, "/");2551}2552}25532554AlignedNode = AllocateCopyPool (DevicePathNodeLength (Node), Node);2555//2556// Print this node of the device path2557//2558ToText (&Str, AlignedNode, DisplayOnly, AllowShortcuts);2559FreePool (AlignedNode);25602561//2562// Next device path node2563//2564Node = NextDevicePathNode (Node);2565}25662567if (Str.Str == NULL) {2568return AllocateZeroPool (sizeof (CHAR16));2569} else {2570return Str.Str;2571}2572}25732574ssize_t2575efidp_format_device_path(char *buf, size_t len, const_efidp dp, ssize_t max)2576{2577char *str;2578ssize_t retval;25792580/*2581* Basic sanity check on the device path.2582*/2583if (!IsDevicePathValid((CONST EFI_DEVICE_PATH_PROTOCOL *) dp, max)) {2584*buf = '\0';2585return 0;2586}25872588str = UefiDevicePathLibConvertDevicePathToText (2589__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp), FALSE, TRUE);2590if (str == NULL)2591return -1;2592strlcpy(buf, str, len);2593retval = strlen(str);2594free(str);25952596return retval;2597}25982599ssize_t2600efidp_format_device_path_node(char *buf, size_t len, const_efidp dp)2601{2602char *str;2603ssize_t retval;26042605str = UefiDevicePathLibConvertDeviceNodeToText (2606__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp), FALSE, TRUE);2607if (str == NULL)2608return -1;2609strlcpy(buf, str, len);2610retval = strlen(str);2611free(str);26122613return retval;2614}26152616size_t2617efidp_size(const_efidp dp)2618{26192620return GetDevicePathSize(__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp));2621}26222623char *2624efidp_extract_file_path(const_efidp dp)2625{2626const FILEPATH_DEVICE_PATH *fp;2627char *name = NULL;26282629fp = (const void *)dp;2630ucs2_to_utf8(fp->PathName, &name);2631return name;2632}263326342635