/*-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"3536#include "efi-osdep.h"37#include "efivar-dp.h"3839#include "uefi-dplib.h"4041/*42* This is a lie, but since we have converted everything43* from wide to narrow, it's the right lie now.44*/45#define UnicodeSPrint snprintf4647/*48* Taken from MdePkg/Library/UefiDevicePathLib/DevicePathToText.c49* heavily modified:50* wide strings converted to narrow51* Low level printing code redone for narrow strings52* Routines made static53* %s -> %S in spots (where it is still UCS-2)54* %a (ascii) -> %s55* %g -> %36s hack to print guid (see above for caveat)56* some tidying up of const and deconsting. It's evil, but const57* poisoning the whole file was too much.58*/5960/** @file61DevicePathToText protocol as defined in the UEFI 2.0 specification.6263(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>64Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>65SPDX-License-Identifier: BSD-2-Clause-Patent6667**/6869// #include "UefiDevicePathLib.h"7071/**72Concatenates a formatted unicode string to allocated pool. The caller must73free the resulting buffer.7475@param Str Tracks the allocated pool, size in use, and76amount of pool allocated.77@param Fmt The format string78@param ... Variable arguments based on the format string.7980@return Allocated buffer with the formatted string printed in it.81The caller must free the allocated buffer. The buffer82allocation is not packed.8384**/85static char *86EFIAPI87UefiDevicePathLibCatPrint (88IN OUT POOL_PRINT *Str,89IN const char *Fmt,90...91)92{93UINTN Count;94VA_LIST Args;9596VA_START (Args, Fmt);97Count = vsnprintf (NULL, 0, Fmt, Args);98VA_END (Args);99100if ((Str->Count + (Count + 1)) > Str->Capacity) {101Str->Capacity = (Str->Count + (Count + 1) * 2);102Str->Str = reallocf (103Str->Str,104Str->Capacity105);106ASSERT (Str->Str != NULL);107}108109VA_START (Args, Fmt);110vsnprintf (Str->Str + Str->Count, Str->Capacity - Str->Count, Fmt, Args);111Str->Count += Count;112113VA_END (Args);114return Str->Str;115}116117/**118Converts a PCI device path structure to its string representative.119120@param Str The string representative of input device.121@param DevPath The input device path structure.122@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation123of the display node is used, where applicable. If DisplayOnly124is FALSE, then the longer text representation of the display node125is used.126@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text127representation for a device node can be used, where applicable.128129**/130static VOID131DevPathToTextPci (132IN OUT POOL_PRINT *Str,133IN VOID *DevPath,134IN BOOLEAN DisplayOnly,135IN BOOLEAN AllowShortcuts136)137{138PCI_DEVICE_PATH *Pci;139140Pci = DevPath;141UefiDevicePathLibCatPrint (Str, "Pci(0x%x,0x%x)", Pci->Device, Pci->Function);142}143144/**145Converts a PC Card device path structure to its string representative.146147@param Str The string representative of input device.148@param DevPath The input device path structure.149@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation150of the display node is used, where applicable. If DisplayOnly151is FALSE, then the longer text representation of the display node152is used.153@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text154representation for a device node can be used, where applicable.155156**/157static VOID158DevPathToTextPccard (159IN OUT POOL_PRINT *Str,160IN VOID *DevPath,161IN BOOLEAN DisplayOnly,162IN BOOLEAN AllowShortcuts163)164{165PCCARD_DEVICE_PATH *Pccard;166167Pccard = DevPath;168UefiDevicePathLibCatPrint (Str, "PcCard(0x%x)", Pccard->FunctionNumber);169}170171/**172Converts a Memory Map device path structure to its string representative.173174@param Str The string representative of input device.175@param DevPath The input device path structure.176@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation177of the display node is used, where applicable. If DisplayOnly178is FALSE, then the longer text representation of the display node179is used.180@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text181representation for a device node can be used, where applicable.182183**/184static VOID185DevPathToTextMemMap (186IN OUT POOL_PRINT *Str,187IN VOID *DevPath,188IN BOOLEAN DisplayOnly,189IN BOOLEAN AllowShortcuts190)191{192MEMMAP_DEVICE_PATH *MemMap;193194MemMap = DevPath;195UefiDevicePathLibCatPrint (196Str,197"MemoryMapped(0x%x,0x%lx,0x%lx)",198MemMap->MemoryType,199MemMap->StartingAddress,200MemMap->EndingAddress201);202}203204/**205Converts a Vendor device path structure to its string representative.206207@param Str The string representative of input device.208@param DevPath The input device path structure.209@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation210of the display node is used, where applicable. If DisplayOnly211is FALSE, then the longer text representation of the display node212is used.213@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text214representation for a device node can be used, where applicable.215216**/217static VOID218DevPathToTextVendor (219IN OUT POOL_PRINT *Str,220IN VOID *DevPath,221IN BOOLEAN DisplayOnly,222IN BOOLEAN AllowShortcuts223)224{225VENDOR_DEVICE_PATH *Vendor;226const char *Type;227UINTN Index;228UINTN DataLength;229UINT32 FlowControlMap;230UINT16 Info;231232Vendor = (VENDOR_DEVICE_PATH *)DevPath;233switch (DevicePathType (&Vendor->Header)) {234case HARDWARE_DEVICE_PATH:235Type = "Hw";236break;237238case MESSAGING_DEVICE_PATH:239Type = "Msg";240if (AllowShortcuts) {241if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {242UefiDevicePathLibCatPrint (Str, "VenPcAnsi()");243return;244} else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {245UefiDevicePathLibCatPrint (Str, "VenVt100()");246return;247} else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {248UefiDevicePathLibCatPrint (Str, "VenVt100Plus()");249return;250} else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {251UefiDevicePathLibCatPrint (Str, "VenUtf8()");252return;253} else if (CompareGuid (&Vendor->Guid, &gEfiUartDevicePathGuid)) {254FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *)Vendor)->FlowControlMap);255switch (FlowControlMap & 0x00000003) {256case 0:257UefiDevicePathLibCatPrint (Str, "UartFlowCtrl(%s)", "None");258break;259260case 1:261UefiDevicePathLibCatPrint (Str, "UartFlowCtrl(%s)", "Hardware");262break;263264case 2:265UefiDevicePathLibCatPrint (Str, "UartFlowCtrl(%s)", "XonXoff");266break;267268default:269break;270}271272return;273} else if (CompareGuid (&Vendor->Guid, &gEfiSasDevicePathGuid)) {274UefiDevicePathLibCatPrint (275Str,276"SAS(0x%lx,0x%lx,0x%x,",277((SAS_DEVICE_PATH *)Vendor)->SasAddress,278((SAS_DEVICE_PATH *)Vendor)->Lun,279((SAS_DEVICE_PATH *)Vendor)->RelativeTargetPort280);281Info = (((SAS_DEVICE_PATH *)Vendor)->DeviceTopology);282if (((Info & 0x0f) == 0) && ((Info & BIT7) == 0)) {283UefiDevicePathLibCatPrint (Str, "NoTopology,0,0,0,");284} else if (((Info & 0x0f) <= 2) && ((Info & BIT7) == 0)) {285UefiDevicePathLibCatPrint (286Str,287"%s,%s,%s,",288((Info & BIT4) != 0) ? "SATA" : "SAS",289((Info & BIT5) != 0) ? "External" : "Internal",290((Info & BIT6) != 0) ? "Expanded" : "Direct"291);292if ((Info & 0x0f) == 1) {293UefiDevicePathLibCatPrint (Str, "0,");294} else {295//296// Value 0x0 thru 0xFF -> Drive 1 thru Drive 256297//298UefiDevicePathLibCatPrint (Str, "0x%x,", ((Info >> 8) & 0xff) + 1);299}300} else {301UefiDevicePathLibCatPrint (Str, "0x%x,0,0,0,", Info);302}303304UefiDevicePathLibCatPrint (Str, "0x%x)", ((SAS_DEVICE_PATH *)Vendor)->Reserved);305return;306} else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {307UefiDevicePathLibCatPrint (Str, "DebugPort()");308return;309}310}311312break;313314case MEDIA_DEVICE_PATH:315Type = "Media";316break;317318default:319Type = "?";320break;321}322323DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);324UefiDevicePathLibCatPrint (Str, "Ven%s(%36s", Type, G(&Vendor->Guid));325if (DataLength != 0) {326UefiDevicePathLibCatPrint (Str, ",");327for (Index = 0; Index < DataLength; Index++) {328UefiDevicePathLibCatPrint (Str, "%02x", ((VENDOR_DEVICE_PATH_WITH_DATA *)Vendor)->VendorDefinedData[Index]);329}330}331332UefiDevicePathLibCatPrint (Str, ")");333}334335/**336Converts a Controller device path structure to its string representative.337338@param Str The string representative of input device.339@param DevPath The input device path structure.340@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation341of the display node is used, where applicable. If DisplayOnly342is FALSE, then the longer text representation of the display node343is used.344@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text345representation for a device node can be used, where applicable.346347**/348static VOID349DevPathToTextController (350IN OUT POOL_PRINT *Str,351IN VOID *DevPath,352IN BOOLEAN DisplayOnly,353IN BOOLEAN AllowShortcuts354)355{356CONTROLLER_DEVICE_PATH *Controller;357358Controller = DevPath;359UefiDevicePathLibCatPrint (360Str,361"Ctrl(0x%x)",362Controller->ControllerNumber363);364}365366/**367Converts a BMC device path structure to its string representative.368369@param Str The string representative of input device.370@param DevPath The input device path structure.371@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation372of the display node is used, where applicable. If DisplayOnly373is FALSE, then the longer text representation of the display node374is used.375@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text376representation for a device node can be used, where applicable.377378**/379static VOID380DevPathToTextBmc (381IN OUT POOL_PRINT *Str,382IN VOID *DevPath,383IN BOOLEAN DisplayOnly,384IN BOOLEAN AllowShortcuts385)386{387BMC_DEVICE_PATH *Bmc;388389Bmc = DevPath;390UefiDevicePathLibCatPrint (391Str,392"BMC(0x%x,0x%lx)",393Bmc->InterfaceType,394ReadUnaligned64 ((&Bmc->BaseAddress))395);396}397398/**399Converts a ACPI device path structure to its string representative.400401@param Str The string representative of input device.402@param DevPath The input device path structure.403@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation404of the display node is used, where applicable. If DisplayOnly405is FALSE, then the longer text representation of the display node406is used.407@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text408representation for a device node can be used, where applicable.409410**/411static VOID412DevPathToTextAcpi (413IN OUT POOL_PRINT *Str,414IN VOID *DevPath,415IN BOOLEAN DisplayOnly,416IN BOOLEAN AllowShortcuts417)418{419ACPI_HID_DEVICE_PATH *Acpi;420421Acpi = DevPath;422if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {423switch (EISA_ID_TO_NUM (Acpi->HID)) {424case 0x0a03:425UefiDevicePathLibCatPrint (Str, "PciRoot(0x%x)", Acpi->UID);426break;427428case 0x0a08:429UefiDevicePathLibCatPrint (Str, "PcieRoot(0x%x)", Acpi->UID);430break;431432case 0x0604:433UefiDevicePathLibCatPrint (Str, "Floppy(0x%x)", Acpi->UID);434break;435436case 0x0301:437UefiDevicePathLibCatPrint (Str, "Keyboard(0x%x)", Acpi->UID);438break;439440case 0x0501:441UefiDevicePathLibCatPrint (Str, "Serial(0x%x)", Acpi->UID);442break;443444case 0x0401:445UefiDevicePathLibCatPrint (Str, "ParallelPort(0x%x)", Acpi->UID);446break;447448default:449UefiDevicePathLibCatPrint (Str, "Acpi(PNP%04x,0x%x)", EISA_ID_TO_NUM (Acpi->HID), Acpi->UID);450break;451}452} else {453UefiDevicePathLibCatPrint (Str, "Acpi(0x%08x,0x%x)", Acpi->HID, Acpi->UID);454}455}456457/**458Converts a ACPI extended HID device path structure to its string representative.459460@param Str The string representative of input device.461@param DevPath The input device path structure.462@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation463of the display node is used, where applicable. If DisplayOnly464is FALSE, then the longer text representation of the display node465is used.466@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text467representation for a device node can be used, where applicable.468469**/470static VOID471DevPathToTextAcpiEx (472IN OUT POOL_PRINT *Str,473IN VOID *DevPath,474IN BOOLEAN DisplayOnly,475IN BOOLEAN AllowShortcuts476)477{478ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;479char HIDText[11];480char CIDText[11];481UINTN CurrentLength;482CHAR8 *CurrentPos;483UINTN NextStringOffset;484CHAR8 *Strings[3];485UINT8 HidStrIndex;486UINT8 UidStrIndex;487UINT8 CidStrIndex;488UINT8 StrIndex;489490HidStrIndex = 0;491UidStrIndex = 1;492CidStrIndex = 2;493AcpiEx = DevPath;494Strings[HidStrIndex] = NULL;495Strings[UidStrIndex] = NULL;496Strings[CidStrIndex] = NULL;497CurrentLength = sizeof (ACPI_EXTENDED_HID_DEVICE_PATH);498CurrentPos = (CHAR8 *)(((UINT8 *)AcpiEx) + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));499StrIndex = 0;500while (CurrentLength < AcpiEx->Header.Length[0] && StrIndex < ARRAY_SIZE (Strings)) {501Strings[StrIndex] = CurrentPos;502NextStringOffset = AsciiStrLen (CurrentPos) + 1;503CurrentLength += NextStringOffset;504CurrentPos += NextStringOffset;505StrIndex++;506}507508if (DisplayOnly) {509if ((EISA_ID_TO_NUM (AcpiEx->HID) == 0x0A03) ||510((EISA_ID_TO_NUM (AcpiEx->CID) == 0x0A03) && (EISA_ID_TO_NUM (AcpiEx->HID) != 0x0A08)))511{512if (Strings[UidStrIndex] != NULL) {513UefiDevicePathLibCatPrint (Str, "PciRoot(%s)", Strings[UidStrIndex]);514} else {515UefiDevicePathLibCatPrint (Str, "PciRoot(0x%x)", AcpiEx->UID);516}517518return;519}520521if ((EISA_ID_TO_NUM (AcpiEx->HID) == 0x0A08) || (EISA_ID_TO_NUM (AcpiEx->CID) == 0x0A08)) {522if (Strings[UidStrIndex] != NULL) {523UefiDevicePathLibCatPrint (Str, "PcieRoot(%s)", Strings[UidStrIndex]);524} else {525UefiDevicePathLibCatPrint (Str, "PcieRoot(0x%x)", AcpiEx->UID);526}527528return;529}530}531532//533// Converts EISA identification to string.534//535UnicodeSPrint (536HIDText,537sizeof (HIDText),538"%c%c%c%04X",539((AcpiEx->HID >> 10) & 0x1f) + 'A' - 1,540((AcpiEx->HID >> 5) & 0x1f) + 'A' - 1,541((AcpiEx->HID >> 0) & 0x1f) + 'A' - 1,542(AcpiEx->HID >> 16) & 0xFFFF543);544UnicodeSPrint (545CIDText,546sizeof (CIDText),547"%c%c%c%04X",548((AcpiEx->CID >> 10) & 0x1f) + 'A' - 1,549((AcpiEx->CID >> 5) & 0x1f) + 'A' - 1,550((AcpiEx->CID >> 0) & 0x1f) + 'A' - 1,551(AcpiEx->CID >> 16) & 0xFFFF552);553554if (((Strings[HidStrIndex] != NULL) && (*Strings[HidStrIndex] == '\0')) &&555((Strings[CidStrIndex] != NULL) && (*Strings[CidStrIndex] == '\0')) &&556((Strings[UidStrIndex] != NULL) && (*Strings[UidStrIndex] != '\0')))557{558//559// use AcpiExp()560//561if (AcpiEx->CID == 0) {562UefiDevicePathLibCatPrint (563Str,564"AcpiExp(%s,0,%s)",565HIDText,566Strings[UidStrIndex]567);568} else {569UefiDevicePathLibCatPrint (570Str,571"AcpiExp(%s,%s,%s)",572HIDText,573CIDText,574Strings[UidStrIndex]575);576}577} else {578if (DisplayOnly) {579if (Strings[HidStrIndex] != NULL) {580UefiDevicePathLibCatPrint (Str, "AcpiEx(%s,", Strings[HidStrIndex]);581} else {582UefiDevicePathLibCatPrint (Str, "AcpiEx(%s,", HIDText);583}584585if (Strings[CidStrIndex] != NULL) {586UefiDevicePathLibCatPrint (Str, "%s,", Strings[CidStrIndex]);587} else {588UefiDevicePathLibCatPrint (Str, "%s,", CIDText);589}590591if (Strings[UidStrIndex] != NULL) {592UefiDevicePathLibCatPrint (Str, "%s)", Strings[UidStrIndex]);593} else {594UefiDevicePathLibCatPrint (Str, "0x%x)", AcpiEx->UID);595}596} else {597UefiDevicePathLibCatPrint (598Str,599"AcpiEx(%s,%s,0x%x,%s,%s,%s)",600HIDText,601CIDText,602AcpiEx->UID,603Strings[HidStrIndex] != NULL ? Strings[HidStrIndex] : '\0',604Strings[CidStrIndex] != NULL ? Strings[CidStrIndex] : '\0',605Strings[UidStrIndex] != NULL ? Strings[UidStrIndex] : '\0'606);607}608}609}610611/**612Converts a ACPI address device path structure to its string representative.613614@param Str The string representative of input device.615@param DevPath The input device path structure.616@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation617of the display node is used, where applicable. If DisplayOnly618is FALSE, then the longer text representation of the display node619is used.620@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text621representation for a device node can be used, where applicable.622623**/624static VOID625DevPathToTextAcpiAdr (626IN OUT POOL_PRINT *Str,627IN VOID *DevPath,628IN BOOLEAN DisplayOnly,629IN BOOLEAN AllowShortcuts630)631{632ACPI_ADR_DEVICE_PATH *AcpiAdr;633UINT32 *Addr;634UINT16 Index;635UINT16 Length;636UINT16 AdditionalAdrCount;637638AcpiAdr = DevPath;639Length = (UINT16)DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr);640AdditionalAdrCount = (UINT16)((Length - 8) / 4);641642UefiDevicePathLibCatPrint (Str, "AcpiAdr(0x%x", AcpiAdr->ADR);643Addr = &AcpiAdr->ADR + 1;644for (Index = 0; Index < AdditionalAdrCount; Index++) {645UefiDevicePathLibCatPrint (Str, ",0x%x", Addr[Index]);646}647648UefiDevicePathLibCatPrint (Str, ")");649}650651/**652Converts a ATAPI device path structure to its string representative.653654@param Str The string representative of input device.655@param DevPath The input device path structure.656@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation657of the display node is used, where applicable. If DisplayOnly658is FALSE, then the longer text representation of the display node659is used.660@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text661representation for a device node can be used, where applicable.662663**/664static VOID665DevPathToTextAtapi (666IN OUT POOL_PRINT *Str,667IN VOID *DevPath,668IN BOOLEAN DisplayOnly,669IN BOOLEAN AllowShortcuts670)671{672ATAPI_DEVICE_PATH *Atapi;673674Atapi = DevPath;675676if (DisplayOnly) {677UefiDevicePathLibCatPrint (Str, "Ata(0x%x)", Atapi->Lun);678} else {679UefiDevicePathLibCatPrint (680Str,681"Ata(%s,%s,0x%x)",682(Atapi->PrimarySecondary == 1) ? "Secondary" : "Primary",683(Atapi->SlaveMaster == 1) ? "Slave" : "Master",684Atapi->Lun685);686}687}688689/**690Converts a SCSI device path structure to its string representative.691692@param Str The string representative of input device.693@param DevPath The input device path structure.694@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation695of the display node is used, where applicable. If DisplayOnly696is FALSE, then the longer text representation of the display node697is used.698@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text699representation for a device node can be used, where applicable.700701**/702static VOID703DevPathToTextScsi (704IN OUT POOL_PRINT *Str,705IN VOID *DevPath,706IN BOOLEAN DisplayOnly,707IN BOOLEAN AllowShortcuts708)709{710SCSI_DEVICE_PATH *Scsi;711712Scsi = DevPath;713UefiDevicePathLibCatPrint (Str, "Scsi(0x%x,0x%x)", Scsi->Pun, Scsi->Lun);714}715716/**717Converts a Fibre device path structure to its string representative.718719@param Str The string representative of input device.720@param DevPath The input device path structure.721@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation722of the display node is used, where applicable. If DisplayOnly723is FALSE, then the longer text representation of the display node724is used.725@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text726representation for a device node can be used, where applicable.727728**/729static VOID730DevPathToTextFibre (731IN OUT POOL_PRINT *Str,732IN VOID *DevPath,733IN BOOLEAN DisplayOnly,734IN BOOLEAN AllowShortcuts735)736{737FIBRECHANNEL_DEVICE_PATH *Fibre;738739Fibre = DevPath;740UefiDevicePathLibCatPrint (Str, "Fibre(0x%lx,0x%lx)", Fibre->WWN, Fibre->Lun);741}742743/**744Converts a FibreEx device path structure to its string representative.745746@param Str The string representative of input device.747@param DevPath The input device path structure.748@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation749of the display node is used, where applicable. If DisplayOnly750is FALSE, then the longer text representation of the display node751is used.752@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text753representation for a device node can be used, where applicable.754755**/756static VOID757DevPathToTextFibreEx (758IN OUT POOL_PRINT *Str,759IN VOID *DevPath,760IN BOOLEAN DisplayOnly,761IN BOOLEAN AllowShortcuts762)763{764FIBRECHANNELEX_DEVICE_PATH *FibreEx;765UINTN Index;766767FibreEx = DevPath;768UefiDevicePathLibCatPrint (Str, "FibreEx(0x");769for (Index = 0; Index < sizeof (FibreEx->WWN) / sizeof (FibreEx->WWN[0]); Index++) {770UefiDevicePathLibCatPrint (Str, "%02x", FibreEx->WWN[Index]);771}772773UefiDevicePathLibCatPrint (Str, ",0x");774for (Index = 0; Index < sizeof (FibreEx->Lun) / sizeof (FibreEx->Lun[0]); Index++) {775UefiDevicePathLibCatPrint (Str, "%02x", FibreEx->Lun[Index]);776}777778UefiDevicePathLibCatPrint (Str, ")");779}780781/**782Converts a Sas Ex device path structure to its string representative.783784@param Str The string representative of input device.785@param DevPath The input device path structure.786@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation787of the display node is used, where applicable. If DisplayOnly788is FALSE, then the longer text representation of the display node789is used.790@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text791representation for a device node can be used, where applicable.792793**/794static VOID795DevPathToTextSasEx (796IN OUT POOL_PRINT *Str,797IN VOID *DevPath,798IN BOOLEAN DisplayOnly,799IN BOOLEAN AllowShortcuts800)801{802SASEX_DEVICE_PATH *SasEx;803UINTN Index;804805SasEx = DevPath;806UefiDevicePathLibCatPrint (Str, "SasEx(0x");807808for (Index = 0; Index < sizeof (SasEx->SasAddress) / sizeof (SasEx->SasAddress[0]); Index++) {809UefiDevicePathLibCatPrint (Str, "%02x", SasEx->SasAddress[Index]);810}811812UefiDevicePathLibCatPrint (Str, ",0x");813for (Index = 0; Index < sizeof (SasEx->Lun) / sizeof (SasEx->Lun[0]); Index++) {814UefiDevicePathLibCatPrint (Str, "%02x", SasEx->Lun[Index]);815}816817UefiDevicePathLibCatPrint (Str, ",0x%x,", SasEx->RelativeTargetPort);818819if (((SasEx->DeviceTopology & 0x0f) == 0) && ((SasEx->DeviceTopology & BIT7) == 0)) {820UefiDevicePathLibCatPrint (Str, "NoTopology,0,0,0");821} else if (((SasEx->DeviceTopology & 0x0f) <= 2) && ((SasEx->DeviceTopology & BIT7) == 0)) {822UefiDevicePathLibCatPrint (823Str,824"%s,%s,%s,",825((SasEx->DeviceTopology & BIT4) != 0) ? "SATA" : "SAS",826((SasEx->DeviceTopology & BIT5) != 0) ? "External" : "Internal",827((SasEx->DeviceTopology & BIT6) != 0) ? "Expanded" : "Direct"828);829if ((SasEx->DeviceTopology & 0x0f) == 1) {830UefiDevicePathLibCatPrint (Str, "0");831} else {832//833// Value 0x0 thru 0xFF -> Drive 1 thru Drive 256834//835UefiDevicePathLibCatPrint (Str, "0x%x", ((SasEx->DeviceTopology >> 8) & 0xff) + 1);836}837} else {838UefiDevicePathLibCatPrint (Str, "0x%x,0,0,0", SasEx->DeviceTopology);839}840841UefiDevicePathLibCatPrint (Str, ")");842return;843}844845/**846Converts a NVM Express Namespace device path structure to its string representative.847848@param Str The string representative of input device.849@param DevPath The input device path structure.850@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation851of the display node is used, where applicable. If DisplayOnly852is FALSE, then the longer text representation of the display node853is used.854@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text855representation for a device node can be used, where applicable.856857**/858static VOID859DevPathToTextNVMe (860IN OUT POOL_PRINT *Str,861IN VOID *DevPath,862IN BOOLEAN DisplayOnly,863IN BOOLEAN AllowShortcuts864)865{866NVME_NAMESPACE_DEVICE_PATH *Nvme;867UINT8 *Uuid;868869Nvme = DevPath;870Uuid = (UINT8 *)&Nvme->NamespaceUuid;871UefiDevicePathLibCatPrint (872Str,873"NVMe(0x%x,%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x)",874Nvme->NamespaceId,875Uuid[7],876Uuid[6],877Uuid[5],878Uuid[4],879Uuid[3],880Uuid[2],881Uuid[1],882Uuid[0]883);884}885886/**887Converts a UFS device path structure to its string representative.888889@param Str The string representative of input device.890@param DevPath The input device path structure.891@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation892of the display node is used, where applicable. If DisplayOnly893is FALSE, then the longer text representation of the display node894is used.895@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text896representation for a device node can be used, where applicable.897898**/899static VOID900DevPathToTextUfs (901IN OUT POOL_PRINT *Str,902IN VOID *DevPath,903IN BOOLEAN DisplayOnly,904IN BOOLEAN AllowShortcuts905)906{907UFS_DEVICE_PATH *Ufs;908909Ufs = DevPath;910UefiDevicePathLibCatPrint (Str, "UFS(0x%x,0x%x)", Ufs->Pun, Ufs->Lun);911}912913/**914Converts a SD (Secure Digital) device path structure to its string representative.915916@param Str The string representative of input device.917@param DevPath The input device path structure.918@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation919of the display node is used, where applicable. If DisplayOnly920is FALSE, then the longer text representation of the display node921is used.922@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text923representation for a device node can be used, where applicable.924925**/926static VOID927DevPathToTextSd (928IN OUT POOL_PRINT *Str,929IN VOID *DevPath,930IN BOOLEAN DisplayOnly,931IN BOOLEAN AllowShortcuts932)933{934SD_DEVICE_PATH *Sd;935936Sd = DevPath;937UefiDevicePathLibCatPrint (938Str,939"SD(0x%x)",940Sd->SlotNumber941);942}943944/**945Converts a EMMC (Embedded MMC) device path structure to its string representative.946947@param Str The string representative of input device.948@param DevPath The input device path structure.949@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation950of the display node is used, where applicable. If DisplayOnly951is FALSE, then the longer text representation of the display node952is used.953@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text954representation for a device node can be used, where applicable.955956**/957static VOID958DevPathToTextEmmc (959IN OUT POOL_PRINT *Str,960IN VOID *DevPath,961IN BOOLEAN DisplayOnly,962IN BOOLEAN AllowShortcuts963)964{965EMMC_DEVICE_PATH *Emmc;966967Emmc = DevPath;968UefiDevicePathLibCatPrint (969Str,970"eMMC(0x%x)",971Emmc->SlotNumber972);973}974975/**976Converts a 1394 device path structure to its string representative.977978@param Str The string representative of input device.979@param DevPath The input device path structure.980@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation981of the display node is used, where applicable. If DisplayOnly982is FALSE, then the longer text representation of the display node983is used.984@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text985representation for a device node can be used, where applicable.986987**/988static VOID989DevPathToText1394 (990IN OUT POOL_PRINT *Str,991IN VOID *DevPath,992IN BOOLEAN DisplayOnly,993IN BOOLEAN AllowShortcuts994)995{996F1394_DEVICE_PATH *F1394DevPath;997998F1394DevPath = DevPath;999//1000// Guid has format of IEEE-EUI641001//1002UefiDevicePathLibCatPrint (Str, "I1394(%016lx)", F1394DevPath->Guid);1003}10041005/**1006Converts a USB device path structure to its string representative.10071008@param Str The string representative of input device.1009@param DevPath The input device path structure.1010@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1011of the display node is used, where applicable. If DisplayOnly1012is FALSE, then the longer text representation of the display node1013is used.1014@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1015representation for a device node can be used, where applicable.10161017**/1018static VOID1019DevPathToTextUsb (1020IN OUT POOL_PRINT *Str,1021IN VOID *DevPath,1022IN BOOLEAN DisplayOnly,1023IN BOOLEAN AllowShortcuts1024)1025{1026USB_DEVICE_PATH *Usb;10271028Usb = DevPath;1029UefiDevicePathLibCatPrint (Str, "USB(0x%x,0x%x)", Usb->ParentPortNumber, Usb->InterfaceNumber);1030}10311032/**1033Converts a USB WWID device path structure to its string representative.10341035@param Str The string representative of input device.1036@param DevPath The input device path structure.1037@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1038of the display node is used, where applicable. If DisplayOnly1039is FALSE, then the longer text representation of the display node1040is used.1041@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1042representation for a device node can be used, where applicable.10431044**/1045static VOID1046DevPathToTextUsbWWID (1047IN OUT POOL_PRINT *Str,1048IN VOID *DevPath,1049IN BOOLEAN DisplayOnly,1050IN BOOLEAN AllowShortcuts1051)1052{1053USB_WWID_DEVICE_PATH *UsbWWId;1054CHAR16 *SerialNumberStr;1055CHAR16 *NewStr;1056UINT16 Length;10571058UsbWWId = DevPath;10591060SerialNumberStr = (CHAR16 *)(&UsbWWId + 1);1061Length = (UINT16)((DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *)UsbWWId) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16));1062if ((Length >= 1) && (SerialNumberStr[Length - 1] != 0)) {1063//1064// In case no NULL terminator in SerialNumber, create a new one with NULL terminator1065//1066NewStr = AllocatePool ((Length + 1) * sizeof (CHAR16));1067ASSERT (NewStr != NULL);1068CopyMem (NewStr, SerialNumberStr, Length * sizeof (CHAR16));1069NewStr[Length] = 0;1070SerialNumberStr = NewStr;1071}10721073UefiDevicePathLibCatPrint (1074Str,1075"UsbWwid(0x%x,0x%x,0x%x,\"%S\")",1076UsbWWId->VendorId,1077UsbWWId->ProductId,1078UsbWWId->InterfaceNumber,1079SerialNumberStr1080);1081}10821083/**1084Converts a Logic Unit device path structure to its string representative.10851086@param Str The string representative of input device.1087@param DevPath The input device path structure.1088@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1089of the display node is used, where applicable. If DisplayOnly1090is FALSE, then the longer text representation of the display node1091is used.1092@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1093representation for a device node can be used, where applicable.10941095**/1096static VOID1097DevPathToTextLogicalUnit (1098IN OUT POOL_PRINT *Str,1099IN VOID *DevPath,1100IN BOOLEAN DisplayOnly,1101IN BOOLEAN AllowShortcuts1102)1103{1104DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;11051106LogicalUnit = DevPath;1107UefiDevicePathLibCatPrint (Str, "Unit(0x%x)", LogicalUnit->Lun);1108}11091110/**1111Converts a USB class device path structure to its string representative.11121113@param Str The string representative of input device.1114@param DevPath The input device path structure.1115@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1116of the display node is used, where applicable. If DisplayOnly1117is FALSE, then the longer text representation of the display node1118is used.1119@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1120representation for a device node can be used, where applicable.11211122**/1123static VOID1124DevPathToTextUsbClass (1125IN OUT POOL_PRINT *Str,1126IN VOID *DevPath,1127IN BOOLEAN DisplayOnly,1128IN BOOLEAN AllowShortcuts1129)1130{1131USB_CLASS_DEVICE_PATH *UsbClass;1132BOOLEAN IsKnownSubClass;11331134UsbClass = DevPath;11351136IsKnownSubClass = TRUE;1137switch (UsbClass->DeviceClass) {1138case USB_CLASS_AUDIO:1139UefiDevicePathLibCatPrint (Str, "UsbAudio");1140break;11411142case USB_CLASS_CDCCONTROL:1143UefiDevicePathLibCatPrint (Str, "UsbCDCControl");1144break;11451146case USB_CLASS_HID:1147UefiDevicePathLibCatPrint (Str, "UsbHID");1148break;11491150case USB_CLASS_IMAGE:1151UefiDevicePathLibCatPrint (Str, "UsbImage");1152break;11531154case USB_CLASS_PRINTER:1155UefiDevicePathLibCatPrint (Str, "UsbPrinter");1156break;11571158case USB_CLASS_MASS_STORAGE:1159UefiDevicePathLibCatPrint (Str, "UsbMassStorage");1160break;11611162case USB_CLASS_HUB:1163UefiDevicePathLibCatPrint (Str, "UsbHub");1164break;11651166case USB_CLASS_CDCDATA:1167UefiDevicePathLibCatPrint (Str, "UsbCDCData");1168break;11691170case USB_CLASS_SMART_CARD:1171UefiDevicePathLibCatPrint (Str, "UsbSmartCard");1172break;11731174case USB_CLASS_VIDEO:1175UefiDevicePathLibCatPrint (Str, "UsbVideo");1176break;11771178case USB_CLASS_DIAGNOSTIC:1179UefiDevicePathLibCatPrint (Str, "UsbDiagnostic");1180break;11811182case USB_CLASS_WIRELESS:1183UefiDevicePathLibCatPrint (Str, "UsbWireless");1184break;11851186default:1187IsKnownSubClass = FALSE;1188break;1189}11901191if (IsKnownSubClass) {1192UefiDevicePathLibCatPrint (1193Str,1194"(0x%x,0x%x,0x%x,0x%x)",1195UsbClass->VendorId,1196UsbClass->ProductId,1197UsbClass->DeviceSubClass,1198UsbClass->DeviceProtocol1199);1200return;1201}12021203if (UsbClass->DeviceClass == USB_CLASS_RESERVE) {1204if (UsbClass->DeviceSubClass == USB_SUBCLASS_FW_UPDATE) {1205UefiDevicePathLibCatPrint (1206Str,1207"UsbDeviceFirmwareUpdate(0x%x,0x%x,0x%x)",1208UsbClass->VendorId,1209UsbClass->ProductId,1210UsbClass->DeviceProtocol1211);1212return;1213} else if (UsbClass->DeviceSubClass == USB_SUBCLASS_IRDA_BRIDGE) {1214UefiDevicePathLibCatPrint (1215Str,1216"UsbIrdaBridge(0x%x,0x%x,0x%x)",1217UsbClass->VendorId,1218UsbClass->ProductId,1219UsbClass->DeviceProtocol1220);1221return;1222} else if (UsbClass->DeviceSubClass == USB_SUBCLASS_TEST) {1223UefiDevicePathLibCatPrint (1224Str,1225"UsbTestAndMeasurement(0x%x,0x%x,0x%x)",1226UsbClass->VendorId,1227UsbClass->ProductId,1228UsbClass->DeviceProtocol1229);1230return;1231}1232}12331234UefiDevicePathLibCatPrint (1235Str,1236"UsbClass(0x%x,0x%x,0x%x,0x%x,0x%x)",1237UsbClass->VendorId,1238UsbClass->ProductId,1239UsbClass->DeviceClass,1240UsbClass->DeviceSubClass,1241UsbClass->DeviceProtocol1242);1243}12441245/**1246Converts a SATA device path structure to its string representative.12471248@param Str The string representative of input device.1249@param DevPath The input device path structure.1250@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1251of the display node is used, where applicable. If DisplayOnly1252is FALSE, then the longer text representation of the display node1253is used.1254@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1255representation for a device node can be used, where applicable.12561257**/1258static VOID1259DevPathToTextSata (1260IN OUT POOL_PRINT *Str,1261IN VOID *DevPath,1262IN BOOLEAN DisplayOnly,1263IN BOOLEAN AllowShortcuts1264)1265{1266SATA_DEVICE_PATH *Sata;12671268Sata = DevPath;1269UefiDevicePathLibCatPrint (1270Str,1271"Sata(0x%x,0x%x,0x%x)",1272Sata->HBAPortNumber,1273Sata->PortMultiplierPortNumber,1274Sata->Lun1275);1276}12771278/**1279Converts a I20 device path structure to its string representative.12801281@param Str The string representative of input device.1282@param DevPath The input device path structure.1283@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1284of the display node is used, where applicable. If DisplayOnly1285is FALSE, then the longer text representation of the display node1286is used.1287@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1288representation for a device node can be used, where applicable.12891290**/1291static VOID1292DevPathToTextI2O (1293IN OUT POOL_PRINT *Str,1294IN VOID *DevPath,1295IN BOOLEAN DisplayOnly,1296IN BOOLEAN AllowShortcuts1297)1298{1299I2O_DEVICE_PATH *I2ODevPath;13001301I2ODevPath = DevPath;1302UefiDevicePathLibCatPrint (Str, "I2O(0x%x)", I2ODevPath->Tid);1303}13041305/**1306Converts a MAC address device path structure to its string representative.13071308@param Str The string representative of input device.1309@param DevPath The input device path structure.1310@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1311of the display node is used, where applicable. If DisplayOnly1312is FALSE, then the longer text representation of the display node1313is used.1314@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1315representation for a device node can be used, where applicable.13161317**/1318static VOID1319DevPathToTextMacAddr (1320IN OUT POOL_PRINT *Str,1321IN VOID *DevPath,1322IN BOOLEAN DisplayOnly,1323IN BOOLEAN AllowShortcuts1324)1325{1326MAC_ADDR_DEVICE_PATH *MacDevPath;1327UINTN HwAddressSize;1328UINTN Index;13291330MacDevPath = DevPath;13311332HwAddressSize = sizeof (EFI_MAC_ADDRESS);1333if ((MacDevPath->IfType == 0x01) || (MacDevPath->IfType == 0x00)) {1334HwAddressSize = 6;1335}13361337UefiDevicePathLibCatPrint (Str, "MAC(");13381339for (Index = 0; Index < HwAddressSize; Index++) {1340UefiDevicePathLibCatPrint (Str, "%02x", MacDevPath->MacAddress.Addr[Index]);1341}13421343UefiDevicePathLibCatPrint (Str, ",0x%x)", MacDevPath->IfType);1344}13451346/**1347Converts network protocol string to its text representation.13481349@param Str The string representative of input device.1350@param Protocol The network protocol ID.13511352**/1353static VOID1354CatNetworkProtocol (1355IN OUT POOL_PRINT *Str,1356IN UINT16 Protocol1357)1358{1359if (Protocol == RFC_1700_TCP_PROTOCOL) {1360UefiDevicePathLibCatPrint (Str, "TCP");1361} else if (Protocol == RFC_1700_UDP_PROTOCOL) {1362UefiDevicePathLibCatPrint (Str, "UDP");1363} else {1364UefiDevicePathLibCatPrint (Str, "0x%x", Protocol);1365}1366}13671368/**1369Converts IP v4 address to its text representation.13701371@param Str The string representative of input device.1372@param Address The IP v4 address.1373**/1374static VOID1375CatIPv4Address (1376IN OUT POOL_PRINT *Str,1377IN EFI_IPv4_ADDRESS *Address1378)1379{1380UefiDevicePathLibCatPrint (Str, "%d.%d.%d.%d", Address->Addr[0], Address->Addr[1], Address->Addr[2], Address->Addr[3]);1381}13821383/**1384Converts IP v6 address to its text representation.13851386@param Str The string representative of input device.1387@param Address The IP v6 address.1388**/1389static VOID1390CatIPv6Address (1391IN OUT POOL_PRINT *Str,1392IN EFI_IPv6_ADDRESS *Address1393)1394{1395UefiDevicePathLibCatPrint (1396Str,1397"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",1398Address->Addr[0],1399Address->Addr[1],1400Address->Addr[2],1401Address->Addr[3],1402Address->Addr[4],1403Address->Addr[5],1404Address->Addr[6],1405Address->Addr[7],1406Address->Addr[8],1407Address->Addr[9],1408Address->Addr[10],1409Address->Addr[11],1410Address->Addr[12],1411Address->Addr[13],1412Address->Addr[14],1413Address->Addr[15]1414);1415}14161417/**1418Converts a IPv4 device path structure to its string representative.14191420@param Str The string representative of input device.1421@param DevPath The input device path structure.1422@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1423of the display node is used, where applicable. If DisplayOnly1424is FALSE, then the longer text representation of the display node1425is used.1426@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1427representation for a device node can be used, where applicable.14281429**/1430static VOID1431DevPathToTextIPv4 (1432IN OUT POOL_PRINT *Str,1433IN VOID *DevPath,1434IN BOOLEAN DisplayOnly,1435IN BOOLEAN AllowShortcuts1436)1437{1438IPv4_DEVICE_PATH *IPDevPath;14391440IPDevPath = DevPath;1441UefiDevicePathLibCatPrint (Str, "IPv4(");1442CatIPv4Address (Str, &IPDevPath->RemoteIpAddress);14431444if (DisplayOnly) {1445UefiDevicePathLibCatPrint (Str, ")");1446return;1447}14481449UefiDevicePathLibCatPrint (Str, ",");1450CatNetworkProtocol (Str, IPDevPath->Protocol);14511452UefiDevicePathLibCatPrint (Str, ",%s,", IPDevPath->StaticIpAddress ? "Static" : "DHCP");1453CatIPv4Address (Str, &IPDevPath->LocalIpAddress);1454if (DevicePathNodeLength (IPDevPath) == sizeof (IPv4_DEVICE_PATH)) {1455UefiDevicePathLibCatPrint (Str, ",");1456CatIPv4Address (Str, &IPDevPath->GatewayIpAddress);1457UefiDevicePathLibCatPrint (Str, ",");1458CatIPv4Address (Str, &IPDevPath->SubnetMask);1459}14601461UefiDevicePathLibCatPrint (Str, ")");1462}14631464/**1465Converts a IPv6 device path structure to its string representative.14661467@param Str The string representative of input device.1468@param DevPath The input device path structure.1469@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1470of the display node is used, where applicable. If DisplayOnly1471is FALSE, then the longer text representation of the display node1472is used.1473@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1474representation for a device node can be used, where applicable.14751476**/1477static VOID1478DevPathToTextIPv6 (1479IN OUT POOL_PRINT *Str,1480IN VOID *DevPath,1481IN BOOLEAN DisplayOnly,1482IN BOOLEAN AllowShortcuts1483)1484{1485IPv6_DEVICE_PATH *IPDevPath;14861487IPDevPath = DevPath;1488UefiDevicePathLibCatPrint (Str, "IPv6(");1489CatIPv6Address (Str, &IPDevPath->RemoteIpAddress);1490if (DisplayOnly) {1491UefiDevicePathLibCatPrint (Str, ")");1492return;1493}14941495UefiDevicePathLibCatPrint (Str, ",");1496CatNetworkProtocol (Str, IPDevPath->Protocol);14971498switch (IPDevPath->IpAddressOrigin) {1499case 0:1500UefiDevicePathLibCatPrint (Str, ",Static,");1501break;1502case 1:1503UefiDevicePathLibCatPrint (Str, ",StatelessAutoConfigure,");1504break;1505default:1506UefiDevicePathLibCatPrint (Str, ",StatefulAutoConfigure,");1507break;1508}15091510CatIPv6Address (Str, &IPDevPath->LocalIpAddress);15111512if (DevicePathNodeLength (IPDevPath) == sizeof (IPv6_DEVICE_PATH)) {1513UefiDevicePathLibCatPrint (Str, ",0x%x,", IPDevPath->PrefixLength);1514CatIPv6Address (Str, &IPDevPath->GatewayIpAddress);1515}15161517UefiDevicePathLibCatPrint (Str, ")");1518}15191520/**1521Converts an Infini Band device path structure to its string representative.15221523@param Str The string representative of input device.1524@param DevPath The input device path structure.1525@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1526of the display node is used, where applicable. If DisplayOnly1527is FALSE, then the longer text representation of the display node1528is used.1529@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1530representation for a device node can be used, where applicable.15311532**/1533static VOID1534DevPathToTextInfiniBand (1535IN OUT POOL_PRINT *Str,1536IN VOID *DevPath,1537IN BOOLEAN DisplayOnly,1538IN BOOLEAN AllowShortcuts1539)1540{1541INFINIBAND_DEVICE_PATH *InfiniBand;15421543InfiniBand = DevPath;1544UefiDevicePathLibCatPrint (1545Str,1546"Infiniband(0x%x,%36s,0x%lx,0x%lx,0x%lx)",1547InfiniBand->ResourceFlags,1548G(InfiniBand->PortGid),1549InfiniBand->ServiceId,1550InfiniBand->TargetPortId,1551InfiniBand->DeviceId1552);1553}15541555/**1556Converts a UART device path structure to its string representative.15571558@param Str The string representative of input device.1559@param DevPath The input device path structure.1560@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1561of the display node is used, where applicable. If DisplayOnly1562is FALSE, then the longer text representation of the display node1563is used.1564@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1565representation for a device node can be used, where applicable.15661567**/1568static VOID1569DevPathToTextUart (1570IN OUT POOL_PRINT *Str,1571IN VOID *DevPath,1572IN BOOLEAN DisplayOnly,1573IN BOOLEAN AllowShortcuts1574)1575{1576UART_DEVICE_PATH *Uart;1577CHAR8 Parity;15781579Uart = DevPath;1580switch (Uart->Parity) {1581case 0:1582Parity = 'D';1583break;15841585case 1:1586Parity = 'N';1587break;15881589case 2:1590Parity = 'E';1591break;15921593case 3:1594Parity = 'O';1595break;15961597case 4:1598Parity = 'M';1599break;16001601case 5:1602Parity = 'S';1603break;16041605default:1606Parity = 'x';1607break;1608}16091610if (Uart->BaudRate == 0) {1611UefiDevicePathLibCatPrint (Str, "Uart(DEFAULT,");1612} else {1613UefiDevicePathLibCatPrint (Str, "Uart(%ld,", Uart->BaudRate);1614}16151616if (Uart->DataBits == 0) {1617UefiDevicePathLibCatPrint (Str, "DEFAULT,");1618} else {1619UefiDevicePathLibCatPrint (Str, "%d,", Uart->DataBits);1620}16211622UefiDevicePathLibCatPrint (Str, "%c,", Parity);16231624switch (Uart->StopBits) {1625case 0:1626UefiDevicePathLibCatPrint (Str, "D)");1627break;16281629case 1:1630UefiDevicePathLibCatPrint (Str, "1)");1631break;16321633case 2:1634UefiDevicePathLibCatPrint (Str, "1.5)");1635break;16361637case 3:1638UefiDevicePathLibCatPrint (Str, "2)");1639break;16401641default:1642UefiDevicePathLibCatPrint (Str, "x)");1643break;1644}1645}16461647/**1648Converts an iSCSI device path structure to its string representative.16491650@param Str The string representative of input device.1651@param DevPath The input device path structure.1652@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1653of the display node is used, where applicable. If DisplayOnly1654is FALSE, then the longer text representation of the display node1655is used.1656@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1657representation for a device node can be used, where applicable.16581659**/1660static VOID1661DevPathToTextiSCSI (1662IN OUT POOL_PRINT *Str,1663IN VOID *DevPath,1664IN BOOLEAN DisplayOnly,1665IN BOOLEAN AllowShortcuts1666)1667{1668ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;1669UINT16 Options;1670UINTN Index;16711672ISCSIDevPath = DevPath;1673UefiDevicePathLibCatPrint (1674Str,1675"iSCSI(%s,0x%x,0x",1676ISCSIDevPath->TargetName,1677ISCSIDevPath->TargetPortalGroupTag1678);1679for (Index = 0; Index < sizeof (ISCSIDevPath->Lun) / sizeof (UINT8); Index++) {1680UefiDevicePathLibCatPrint (Str, "%02x", ((UINT8 *)&ISCSIDevPath->Lun)[Index]);1681}16821683Options = ISCSIDevPath->LoginOption;1684UefiDevicePathLibCatPrint (Str, ",%s,", (((Options >> 1) & 0x0001) != 0) ? "CRC32C" : "None");1685UefiDevicePathLibCatPrint (Str, "%s,", (((Options >> 3) & 0x0001) != 0) ? "CRC32C" : "None");1686if (((Options >> 11) & 0x0001) != 0) {1687UefiDevicePathLibCatPrint (Str, "%s,", "None");1688} else if (((Options >> 12) & 0x0001) != 0) {1689UefiDevicePathLibCatPrint (Str, "%s,", "CHAP_UNI");1690} else {1691UefiDevicePathLibCatPrint (Str, "%s,", "CHAP_BI");1692}16931694UefiDevicePathLibCatPrint (Str, "%s)", (ISCSIDevPath->NetworkProtocol == 0) ? "TCP" : "reserved");1695}16961697/**1698Converts a VLAN device path structure to its string representative.16991700@param Str The string representative of input device.1701@param DevPath The input device path structure.1702@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1703of the display node is used, where applicable. If DisplayOnly1704is FALSE, then the longer text representation of the display node1705is used.1706@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1707representation for a device node can be used, where applicable.17081709**/1710static VOID1711DevPathToTextVlan (1712IN OUT POOL_PRINT *Str,1713IN VOID *DevPath,1714IN BOOLEAN DisplayOnly,1715IN BOOLEAN AllowShortcuts1716)1717{1718VLAN_DEVICE_PATH *Vlan;17191720Vlan = DevPath;1721UefiDevicePathLibCatPrint (Str, "Vlan(%d)", Vlan->VlanId);1722}17231724/**1725Converts a Bluetooth device path structure to its string representative.17261727@param Str The string representative of input device.1728@param DevPath The input device path structure.1729@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1730of the display node is used, where applicable. If DisplayOnly1731is FALSE, then the longer text representation of the display node1732is used.1733@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1734representation for a device node can be used, where applicable.17351736**/1737static VOID1738DevPathToTextBluetooth (1739IN OUT POOL_PRINT *Str,1740IN VOID *DevPath,1741IN BOOLEAN DisplayOnly,1742IN BOOLEAN AllowShortcuts1743)1744{1745BLUETOOTH_DEVICE_PATH *Bluetooth;17461747Bluetooth = DevPath;1748UefiDevicePathLibCatPrint (1749Str,1750"Bluetooth(%02x%02x%02x%02x%02x%02x)",1751Bluetooth->BD_ADDR.Address[0],1752Bluetooth->BD_ADDR.Address[1],1753Bluetooth->BD_ADDR.Address[2],1754Bluetooth->BD_ADDR.Address[3],1755Bluetooth->BD_ADDR.Address[4],1756Bluetooth->BD_ADDR.Address[5]1757);1758}17591760/**1761Converts a Wi-Fi device path structure to its string representative.17621763@param Str The string representative of input device.1764@param DevPath The input device path structure.1765@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1766of the display node is used, where applicable. If DisplayOnly1767is FALSE, then the longer text representation of the display node1768is used.1769@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1770representation for a device node can be used, where applicable.17711772**/1773static VOID1774DevPathToTextWiFi (1775IN OUT POOL_PRINT *Str,1776IN VOID *DevPath,1777IN BOOLEAN DisplayOnly,1778IN BOOLEAN AllowShortcuts1779)1780{1781WIFI_DEVICE_PATH *WiFi;1782UINT8 SSId[33];17831784WiFi = DevPath;17851786SSId[32] = '\0';1787CopyMem (SSId, WiFi->SSId, 32);17881789UefiDevicePathLibCatPrint (Str, "Wi-Fi(%s)", SSId);1790}17911792/**1793Converts a Bluetooth device path structure to its string representative.17941795@param Str The string representative of input device.1796@param DevPath The input device path structure.1797@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1798of the display node is used, where applicable. If DisplayOnly1799is FALSE, then the longer text representation of the display node1800is used.1801@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1802representation for a device node can be used, where applicable.18031804**/1805static VOID1806DevPathToTextBluetoothLE (1807IN OUT POOL_PRINT *Str,1808IN VOID *DevPath,1809IN BOOLEAN DisplayOnly,1810IN BOOLEAN AllowShortcuts1811)1812{1813BLUETOOTH_LE_DEVICE_PATH *BluetoothLE;18141815BluetoothLE = DevPath;1816UefiDevicePathLibCatPrint (1817Str,1818"BluetoothLE(%02x%02x%02x%02x%02x%02x,0x%02x)",1819BluetoothLE->Address.Address[0],1820BluetoothLE->Address.Address[1],1821BluetoothLE->Address.Address[2],1822BluetoothLE->Address.Address[3],1823BluetoothLE->Address.Address[4],1824BluetoothLE->Address.Address[5],1825BluetoothLE->Address.Type1826);1827}18281829/**1830Converts a DNS device path structure to its string representative.18311832@param Str The string representative of input device.1833@param DevPath The input device path structure.1834@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1835of the display node is used, where applicable. If DisplayOnly1836is FALSE, then the longer text representation of the display node1837is used.1838@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1839representation for a device node can be used, where applicable.18401841**/1842static VOID1843DevPathToTextDns (1844IN OUT POOL_PRINT *Str,1845IN VOID *DevPath,1846IN BOOLEAN DisplayOnly,1847IN BOOLEAN AllowShortcuts1848)1849{1850DNS_DEVICE_PATH *DnsDevPath;1851UINT32 DnsServerIpCount;1852UINT32 DnsServerIpIndex;18531854DnsDevPath = DevPath;1855DnsServerIpCount = (UINT32)(DevicePathNodeLength (DnsDevPath) - sizeof (EFI_DEVICE_PATH_PROTOCOL) - sizeof (DnsDevPath->IsIPv6)) / sizeof (EFI_IP_ADDRESS);18561857UefiDevicePathLibCatPrint (Str, "Dns(");18581859for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {1860if (DnsDevPath->IsIPv6 == 0x00) {1861CatIPv4Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v4));1862} else {1863CatIPv6Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v6));1864}18651866if (DnsServerIpIndex < DnsServerIpCount - 1) {1867UefiDevicePathLibCatPrint (Str, ",");1868}1869}18701871UefiDevicePathLibCatPrint (Str, ")");1872}18731874/**1875Converts a URI device path structure to its string representative.18761877@param Str The string representative of input device.1878@param DevPath The input device path structure.1879@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1880of the display node is used, where applicable. If DisplayOnly1881is FALSE, then the longer text representation of the display node1882is used.1883@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1884representation for a device node can be used, where applicable.18851886**/1887static VOID1888DevPathToTextUri (1889IN OUT POOL_PRINT *Str,1890IN VOID *DevPath,1891IN BOOLEAN DisplayOnly,1892IN BOOLEAN AllowShortcuts1893)1894{1895URI_DEVICE_PATH *Uri;1896UINTN UriLength;1897CHAR8 *UriStr;18981899//1900// Uri in the device path may not be null terminated.1901//1902Uri = DevPath;1903UriLength = DevicePathNodeLength (Uri) - sizeof (URI_DEVICE_PATH);1904UriStr = AllocatePool (UriLength + 1);19051906if (UriStr == NULL) {1907ASSERT (UriStr != NULL);1908return;1909}19101911CopyMem (UriStr, Uri->Uri, UriLength);1912UriStr[UriLength] = '\0';1913UefiDevicePathLibCatPrint (Str, "Uri(%s)", UriStr);1914FreePool (UriStr);1915}19161917/**1918Converts a Hard drive device path structure to its string representative.19191920@param Str The string representative of input device.1921@param DevPath The input device path structure.1922@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1923of the display node is used, where applicable. If DisplayOnly1924is FALSE, then the longer text representation of the display node1925is used.1926@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1927representation for a device node can be used, where applicable.19281929**/1930static VOID1931DevPathToTextHardDrive (1932IN OUT POOL_PRINT *Str,1933IN VOID *DevPath,1934IN BOOLEAN DisplayOnly,1935IN BOOLEAN AllowShortcuts1936)1937{1938HARDDRIVE_DEVICE_PATH *Hd;19391940Hd = DevPath;1941switch (Hd->SignatureType) {1942case SIGNATURE_TYPE_MBR:1943UefiDevicePathLibCatPrint (1944Str,1945"HD(%d,%s,0x%08x",1946Hd->PartitionNumber,1947"MBR",1948// *((UINT32 *)(&(Hd->Signature[0])))1949le32dec(&(Hd->Signature[0]))1950);1951break;19521953case SIGNATURE_TYPE_GUID:1954UefiDevicePathLibCatPrint (1955Str,1956"HD(%d,%s,%36s",1957Hd->PartitionNumber,1958"GPT",1959G(&(Hd->Signature[0]))1960);1961break;19621963default:1964UefiDevicePathLibCatPrint (1965Str,1966"HD(%d,%d,0",1967Hd->PartitionNumber,1968Hd->SignatureType1969);1970break;1971}19721973if (DisplayOnly) {1974UefiDevicePathLibCatPrint (Str, ")");1975} else {1976UefiDevicePathLibCatPrint (Str, ",0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize);1977}1978}19791980/**1981Converts a CDROM device path structure to its string representative.19821983@param Str The string representative of input device.1984@param DevPath The input device path structure.1985@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation1986of the display node is used, where applicable. If DisplayOnly1987is FALSE, then the longer text representation of the display node1988is used.1989@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text1990representation for a device node can be used, where applicable.19911992**/1993static VOID1994DevPathToTextCDROM (1995IN OUT POOL_PRINT *Str,1996IN VOID *DevPath,1997IN BOOLEAN DisplayOnly,1998IN BOOLEAN AllowShortcuts1999)2000{2001CDROM_DEVICE_PATH *Cd;20022003Cd = DevPath;2004if (DisplayOnly) {2005UefiDevicePathLibCatPrint (Str, "CDROM(0x%x)", Cd->BootEntry);2006return;2007}20082009UefiDevicePathLibCatPrint (Str, "CDROM(0x%x,0x%lx,0x%lx)", Cd->BootEntry, Cd->PartitionStart, Cd->PartitionSize);2010}20112012/**2013Converts a File device path structure to its string representative.20142015@param Str The string representative of input device.2016@param DevPath The input device path structure.2017@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2018of the display node is used, where applicable. If DisplayOnly2019is FALSE, then the longer text representation of the display node2020is used.2021@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2022representation for a device node can be used, where applicable.20232024**/2025static VOID2026DevPathToTextFilePath (2027IN OUT POOL_PRINT *Str,2028IN VOID *DevPath,2029IN BOOLEAN DisplayOnly,2030IN BOOLEAN AllowShortcuts2031)2032{2033FILEPATH_DEVICE_PATH *Fp;2034char *name = NULL;20352036Fp = DevPath;2037ucs2_to_utf8(Fp->PathName, &name);2038UefiDevicePathLibCatPrint (Str, "File(%s)", name);2039free(name);2040}20412042/**2043Converts a Media protocol device path structure to its string representative.20442045@param Str The string representative of input device.2046@param DevPath The input device path structure.2047@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2048of the display node is used, where applicable. If DisplayOnly2049is FALSE, then the longer text representation of the display node2050is used.2051@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2052representation for a device node can be used, where applicable.20532054**/2055static VOID2056DevPathToTextMediaProtocol (2057IN OUT POOL_PRINT *Str,2058IN VOID *DevPath,2059IN BOOLEAN DisplayOnly,2060IN BOOLEAN AllowShortcuts2061)2062{2063MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;20642065MediaProt = DevPath;2066UefiDevicePathLibCatPrint (Str, "Media(%36s)", G(&MediaProt->Protocol));2067}20682069/**2070Converts a Firmware Volume device path structure to its string representative.20712072@param Str The string representative of input device.2073@param DevPath The input device path structure.2074@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2075of the display node is used, where applicable. If DisplayOnly2076is FALSE, then the longer text representation of the display node2077is used.2078@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2079representation for a device node can be used, where applicable.20802081**/2082static VOID2083DevPathToTextFv (2084IN OUT POOL_PRINT *Str,2085IN VOID *DevPath,2086IN BOOLEAN DisplayOnly,2087IN BOOLEAN AllowShortcuts2088)2089{2090MEDIA_FW_VOL_DEVICE_PATH *Fv;20912092Fv = DevPath;2093UefiDevicePathLibCatPrint (Str, "Fv(%36s)", G(&Fv->FvName));2094}20952096/**2097Converts a Firmware Volume File device path structure to its string representative.20982099@param Str The string representative of input device.2100@param DevPath The input device path structure.2101@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2102of the display node is used, where applicable. If DisplayOnly2103is FALSE, then the longer text representation of the display node2104is used.2105@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2106representation for a device node can be used, where applicable.21072108**/2109static VOID2110DevPathToTextFvFile (2111IN OUT POOL_PRINT *Str,2112IN VOID *DevPath,2113IN BOOLEAN DisplayOnly,2114IN BOOLEAN AllowShortcuts2115)2116{2117MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFile;21182119FvFile = DevPath;2120UefiDevicePathLibCatPrint (Str, "FvFile(%36s)", G(&FvFile->FvFileName));2121}21222123/**2124Converts a Relative Offset device path structure to its string representative.21252126@param Str The string representative of input device.2127@param DevPath The input device path structure.2128@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2129of the display node is used, where applicable. If DisplayOnly2130is FALSE, then the longer text representation of the display node2131is used.2132@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2133representation for a device node can be used, where applicable.21342135**/2136static VOID2137DevPathRelativeOffsetRange (2138IN OUT POOL_PRINT *Str,2139IN VOID *DevPath,2140IN BOOLEAN DisplayOnly,2141IN BOOLEAN AllowShortcuts2142)2143{2144MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;21452146Offset = DevPath;2147UefiDevicePathLibCatPrint (2148Str,2149"Offset(0x%lx,0x%lx)",2150Offset->StartingOffset,2151Offset->EndingOffset2152);2153}21542155/**2156Converts a Ram Disk device path structure to its string representative.21572158@param Str The string representative of input device.2159@param DevPath The input device path structure.2160@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2161of the display node is used, where applicable. If DisplayOnly2162is FALSE, then the longer text representation of the display node2163is used.2164@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2165representation for a device node can be used, where applicable.21662167**/2168static VOID2169DevPathToTextRamDisk (2170IN OUT POOL_PRINT *Str,2171IN VOID *DevPath,2172IN BOOLEAN DisplayOnly,2173IN BOOLEAN AllowShortcuts2174)2175{2176MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;21772178RamDisk = DevPath;21792180if (CompareGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid)) {2181UefiDevicePathLibCatPrint (2182Str,2183"VirtualDisk(0x%lx,0x%lx,%d)",2184LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],2185LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],2186RamDisk->Instance2187);2188} else if (CompareGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid)) {2189UefiDevicePathLibCatPrint (2190Str,2191"VirtualCD(0x%lx,0x%lx,%d)",2192LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],2193LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],2194RamDisk->Instance2195);2196} else if (CompareGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid)) {2197UefiDevicePathLibCatPrint (2198Str,2199"PersistentVirtualDisk(0x%lx,0x%lx,%d)",2200LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],2201LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],2202RamDisk->Instance2203);2204} else if (CompareGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid)) {2205UefiDevicePathLibCatPrint (2206Str,2207"PersistentVirtualCD(0x%lx,0x%lx,%d)",2208LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],2209LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],2210RamDisk->Instance2211);2212} else {2213UefiDevicePathLibCatPrint (2214Str,2215"RamDisk(0x%lx,0x%lx,%d,%36s)",2216LShiftU64 ((UINT64)RamDisk->StartingAddr[1], 32) | RamDisk->StartingAddr[0],2217LShiftU64 ((UINT64)RamDisk->EndingAddr[1], 32) | RamDisk->EndingAddr[0],2218RamDisk->Instance,2219G(&RamDisk->TypeGuid)2220);2221}2222}22232224/**2225Converts a BIOS Boot Specification device path structure to its string representative.22262227@param Str The string representative of input device.2228@param DevPath The input device path structure.2229@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2230of the display node is used, where applicable. If DisplayOnly2231is FALSE, then the longer text representation of the display node2232is used.2233@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2234representation for a device node can be used, where applicable.22352236**/2237static VOID2238DevPathToTextBBS (2239IN OUT POOL_PRINT *Str,2240IN VOID *DevPath,2241IN BOOLEAN DisplayOnly,2242IN BOOLEAN AllowShortcuts2243)2244{2245BBS_BBS_DEVICE_PATH *Bbs;2246const char *Type;22472248Bbs = DevPath;2249switch (Bbs->DeviceType) {2250case BBS_TYPE_FLOPPY:2251Type = "Floppy";2252break;22532254case BBS_TYPE_HARDDRIVE:2255Type = "HD";2256break;22572258case BBS_TYPE_CDROM:2259Type = "CDROM";2260break;22612262case BBS_TYPE_PCMCIA:2263Type = "PCMCIA";2264break;22652266case BBS_TYPE_USB:2267Type = "USB";2268break;22692270case BBS_TYPE_EMBEDDED_NETWORK:2271Type = "Network";2272break;22732274default:2275Type = NULL;2276break;2277}22782279if (Type != NULL) {2280UefiDevicePathLibCatPrint (Str, "BBS(%s,%s", Type, Bbs->String);2281} else {2282UefiDevicePathLibCatPrint (Str, "BBS(0x%x,%s", Bbs->DeviceType, Bbs->String);2283}22842285if (DisplayOnly) {2286UefiDevicePathLibCatPrint (Str, ")");2287return;2288}22892290UefiDevicePathLibCatPrint (Str, ",0x%x)", Bbs->StatusFlag);2291}22922293/**2294Converts an End-of-Device-Path structure to its string representative.22952296@param Str The string representative of input device.2297@param DevPath The input device path structure.2298@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2299of the display node is used, where applicable. If DisplayOnly2300is FALSE, then the longer text representation of the display node2301is used.2302@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2303representation for a device node can be used, where applicable.23042305**/2306static VOID2307DevPathToTextEndInstance (2308IN OUT POOL_PRINT *Str,2309IN VOID *DevPath,2310IN BOOLEAN DisplayOnly,2311IN BOOLEAN AllowShortcuts2312)2313{2314UefiDevicePathLibCatPrint (Str, ",");2315}23162317GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_GENERIC_TABLE mUefiDevicePathLibToTextTableGeneric[] = {2318{ HARDWARE_DEVICE_PATH, "HardwarePath" },2319{ ACPI_DEVICE_PATH, "AcpiPath" },2320{ MESSAGING_DEVICE_PATH, "Msg" },2321{ MEDIA_DEVICE_PATH, "MediaPath" },2322{ BBS_DEVICE_PATH, "BbsPath" },2323{ 0, NULL }2324};23252326/**2327Converts an unknown device path structure to its string representative.23282329@param Str The string representative of input device.2330@param DevPath The input device path structure.2331@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2332of the display node is used, where applicable. If DisplayOnly2333is FALSE, then the longer text representation of the display node2334is used.2335@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2336representation for a device node can be used, where applicable.23372338**/2339static VOID2340DevPathToTextNodeGeneric (2341IN OUT POOL_PRINT *Str,2342IN VOID *DevPath,2343IN BOOLEAN DisplayOnly,2344IN BOOLEAN AllowShortcuts2345)2346{2347EFI_DEVICE_PATH_PROTOCOL *Node;2348UINTN Index;23492350Node = DevPath;23512352for (Index = 0; mUefiDevicePathLibToTextTableGeneric[Index].Text != NULL; Index++) {2353if (DevicePathType (Node) == mUefiDevicePathLibToTextTableGeneric[Index].Type) {2354break;2355}2356}23572358if (mUefiDevicePathLibToTextTableGeneric[Index].Text == NULL) {2359//2360// It's a node whose type cannot be recognized2361//2362UefiDevicePathLibCatPrint (Str, "Path(%d,%d", DevicePathType (Node), DevicePathSubType (Node));2363} else {2364//2365// It's a node whose type can be recognized2366//2367UefiDevicePathLibCatPrint (Str, "%s(%d", mUefiDevicePathLibToTextTableGeneric[Index].Text, DevicePathSubType (Node));2368}23692370Index = sizeof (EFI_DEVICE_PATH_PROTOCOL);2371if (Index < DevicePathNodeLength (Node)) {2372UefiDevicePathLibCatPrint (Str, ",");2373for ( ; Index < DevicePathNodeLength (Node); Index++) {2374UefiDevicePathLibCatPrint (Str, "%02x", ((UINT8 *)Node)[Index]);2375}2376}23772378UefiDevicePathLibCatPrint (Str, ")");2379}23802381static const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibToTextTable[] = {2382{ HARDWARE_DEVICE_PATH, HW_PCI_DP, DevPathToTextPci },2383{ HARDWARE_DEVICE_PATH, HW_PCCARD_DP, DevPathToTextPccard },2384{ HARDWARE_DEVICE_PATH, HW_MEMMAP_DP, DevPathToTextMemMap },2385{ HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DevPathToTextVendor },2386{ HARDWARE_DEVICE_PATH, HW_CONTROLLER_DP, DevPathToTextController },2387{ HARDWARE_DEVICE_PATH, HW_BMC_DP, DevPathToTextBmc },2388{ ACPI_DEVICE_PATH, ACPI_DP, DevPathToTextAcpi },2389{ ACPI_DEVICE_PATH, ACPI_EXTENDED_DP, DevPathToTextAcpiEx },2390{ ACPI_DEVICE_PATH, ACPI_ADR_DP, DevPathToTextAcpiAdr },2391{ MESSAGING_DEVICE_PATH, MSG_ATAPI_DP, DevPathToTextAtapi },2392{ MESSAGING_DEVICE_PATH, MSG_SCSI_DP, DevPathToTextScsi },2393{ MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP, DevPathToTextFibre },2394{ MESSAGING_DEVICE_PATH, MSG_FIBRECHANNELEX_DP, DevPathToTextFibreEx },2395{ MESSAGING_DEVICE_PATH, MSG_SASEX_DP, DevPathToTextSasEx },2396{ MESSAGING_DEVICE_PATH, MSG_NVME_NAMESPACE_DP, DevPathToTextNVMe },2397{ MESSAGING_DEVICE_PATH, MSG_UFS_DP, DevPathToTextUfs },2398{ MESSAGING_DEVICE_PATH, MSG_SD_DP, DevPathToTextSd },2399{ MESSAGING_DEVICE_PATH, MSG_EMMC_DP, DevPathToTextEmmc },2400{ MESSAGING_DEVICE_PATH, MSG_1394_DP, DevPathToText1394 },2401{ MESSAGING_DEVICE_PATH, MSG_USB_DP, DevPathToTextUsb },2402{ MESSAGING_DEVICE_PATH, MSG_USB_WWID_DP, DevPathToTextUsbWWID },2403{ MESSAGING_DEVICE_PATH, MSG_DEVICE_LOGICAL_UNIT_DP, DevPathToTextLogicalUnit },2404{ MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP, DevPathToTextUsbClass },2405{ MESSAGING_DEVICE_PATH, MSG_SATA_DP, DevPathToTextSata },2406{ MESSAGING_DEVICE_PATH, MSG_I2O_DP, DevPathToTextI2O },2407{ MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, DevPathToTextMacAddr },2408{ MESSAGING_DEVICE_PATH, MSG_IPv4_DP, DevPathToTextIPv4 },2409{ MESSAGING_DEVICE_PATH, MSG_IPv6_DP, DevPathToTextIPv6 },2410{ MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, DevPathToTextInfiniBand },2411{ MESSAGING_DEVICE_PATH, MSG_UART_DP, DevPathToTextUart },2412{ MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, DevPathToTextVendor },2413{ MESSAGING_DEVICE_PATH, MSG_ISCSI_DP, DevPathToTextiSCSI },2414{ MESSAGING_DEVICE_PATH, MSG_VLAN_DP, DevPathToTextVlan },2415{ MESSAGING_DEVICE_PATH, MSG_DNS_DP, DevPathToTextDns },2416{ MESSAGING_DEVICE_PATH, MSG_URI_DP, DevPathToTextUri },2417{ MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_DP, DevPathToTextBluetooth },2418{ MESSAGING_DEVICE_PATH, MSG_WIFI_DP, DevPathToTextWiFi },2419{ MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_LE_DP, DevPathToTextBluetoothLE },2420{ MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, DevPathToTextHardDrive },2421{ MEDIA_DEVICE_PATH, MEDIA_CDROM_DP, DevPathToTextCDROM },2422{ MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, DevPathToTextVendor },2423{ MEDIA_DEVICE_PATH, MEDIA_PROTOCOL_DP, DevPathToTextMediaProtocol },2424{ MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, DevPathToTextFilePath },2425{ MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_VOL_DP, DevPathToTextFv },2426{ MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP, DevPathToTextFvFile },2427{ MEDIA_DEVICE_PATH, MEDIA_RELATIVE_OFFSET_RANGE_DP, DevPathRelativeOffsetRange },2428{ MEDIA_DEVICE_PATH, MEDIA_RAM_DISK_DP, DevPathToTextRamDisk },2429{ BBS_DEVICE_PATH, BBS_BBS_DP, DevPathToTextBBS },2430{ END_DEVICE_PATH_TYPE, END_INSTANCE_DEVICE_PATH_SUBTYPE, DevPathToTextEndInstance },2431{ 0, 0, NULL }2432};24332434/**2435Converts a device node to its string representation.24362437@param DeviceNode A Pointer to the device node to be converted.2438@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2439of the display node is used, where applicable. If DisplayOnly2440is FALSE, then the longer text representation of the display node2441is used.2442@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2443representation for a device node can be used, where applicable.24442445@return A pointer to the allocated text representation of the device node or NULL if DeviceNode2446is NULL or there was insufficient memory.24472448**/2449static char *2450EFIAPI2451UefiDevicePathLibConvertDeviceNodeToText (2452IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,2453IN BOOLEAN DisplayOnly,2454IN BOOLEAN AllowShortcuts2455)2456{2457POOL_PRINT Str;2458UINTN Index;2459DEVICE_PATH_TO_TEXT ToText;2460EFI_DEVICE_PATH_PROTOCOL *Node;24612462if (DeviceNode == NULL) {2463return NULL;2464}24652466ZeroMem (&Str, sizeof (Str));24672468//2469// Process the device path node2470// If not found, use a generic function2471//2472Node = __DECONST(EFI_DEVICE_PATH_PROTOCOL *, DeviceNode);2473ToText = DevPathToTextNodeGeneric;2474for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index++) {2475if ((DevicePathType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].Type) &&2476(DevicePathSubType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].SubType)2477)2478{2479ToText = mUefiDevicePathLibToTextTable[Index].Function;2480break;2481}2482}24832484//2485// Print this node2486//2487ToText (&Str, (VOID *)Node, DisplayOnly, AllowShortcuts);24882489ASSERT (Str.Str != NULL);2490return Str.Str;2491}24922493/**2494Converts a device path to its text representation.24952496@param DevicePath A Pointer to the device to be converted.2497@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation2498of the display node is used, where applicable. If DisplayOnly2499is FALSE, then the longer text representation of the display node2500is used.2501@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text2502representation for a device node can be used, where applicable.25032504@return A pointer to the allocated text representation of the device path or2505NULL if DeviceNode is NULL or there was insufficient memory.25062507**/2508static char *2509EFIAPI2510UefiDevicePathLibConvertDevicePathToText (2511IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,2512IN BOOLEAN DisplayOnly,2513IN BOOLEAN AllowShortcuts2514)2515{2516POOL_PRINT Str;2517EFI_DEVICE_PATH_PROTOCOL *Node;2518EFI_DEVICE_PATH_PROTOCOL *AlignedNode;2519UINTN Index;2520DEVICE_PATH_TO_TEXT ToText;25212522if (DevicePath == NULL) {2523return NULL;2524}25252526ZeroMem (&Str, sizeof (Str));25272528//2529// Process each device path node2530//2531Node = __DECONST(EFI_DEVICE_PATH_PROTOCOL *, DevicePath);2532while (!IsDevicePathEnd (Node)) {2533//2534// Find the handler to dump this device path node2535// If not found, use a generic function2536//2537ToText = DevPathToTextNodeGeneric;2538for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index += 1) {2539if ((DevicePathType (Node) == mUefiDevicePathLibToTextTable[Index].Type) &&2540(DevicePathSubType (Node) == mUefiDevicePathLibToTextTable[Index].SubType)2541)2542{2543ToText = mUefiDevicePathLibToTextTable[Index].Function;2544break;2545}2546}25472548//2549// Put a path separator in if needed2550//2551if ((Str.Count != 0) && (ToText != DevPathToTextEndInstance)) {2552if (Str.Str[Str.Count] != ',') {2553UefiDevicePathLibCatPrint (&Str, "/");2554}2555}25562557AlignedNode = AllocateCopyPool (DevicePathNodeLength (Node), Node);2558//2559// Print this node of the device path2560//2561ToText (&Str, AlignedNode, DisplayOnly, AllowShortcuts);2562FreePool (AlignedNode);25632564//2565// Next device path node2566//2567Node = NextDevicePathNode (Node);2568}25692570if (Str.Str == NULL) {2571return AllocateZeroPool (sizeof (CHAR16));2572} else {2573return Str.Str;2574}2575}25762577ssize_t2578efidp_format_device_path(char *buf, size_t len, const_efidp dp, ssize_t max)2579{2580char *str;2581ssize_t retval;25822583/*2584* Basic sanity check on the device path.2585*/2586if (!IsDevicePathValid((CONST EFI_DEVICE_PATH_PROTOCOL *) dp, max)) {2587*buf = '\0';2588return 0;2589}25902591str = UefiDevicePathLibConvertDevicePathToText (2592__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp), FALSE, TRUE);2593if (str == NULL)2594return -1;2595strlcpy(buf, str, len);2596retval = strlen(str);2597free(str);25982599return retval;2600}26012602ssize_t2603efidp_format_device_path_node(char *buf, size_t len, const_efidp dp)2604{2605char *str;2606ssize_t retval;26072608str = UefiDevicePathLibConvertDeviceNodeToText (2609__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp), FALSE, TRUE);2610if (str == NULL)2611return -1;2612strlcpy(buf, str, len);2613retval = strlen(str);2614free(str);26152616return retval;2617}26182619size_t2620efidp_size(const_efidp dp)2621{26222623return GetDevicePathSize(__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp));2624}26252626char *2627efidp_extract_file_path(const_efidp dp)2628{2629const FILEPATH_DEVICE_PATH *fp;2630char *name = NULL;26312632fp = (const void *)dp;2633ucs2_to_utf8(fp->PathName, &name);2634return name;2635}263626372638