2 * Copyright (c) 2017 Netflix, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * Routines to format EFI_DEVICE_PATHs from the UEFI standard. Much of
28 * this file is taken from EDK2 and rototilled.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
42 #include "efi-osdep.h"
43 #include "efivar-dp.h"
45 #include "uefi-dplib.h"
47 /* XXX STUBS -- this stuff doesn't work yet */
48 #define StrToIpv4Address(str, unk, ipv4ptr, unk2)
49 #define StrToIpv6Address(str, unk, ipv6ptr, unk2)
52 * OK. Now this is evil. Can't typedef it again. Sure beats changing them all.
53 * Since we're doing it all as narrow characters since wchar_t can't be used on
54 * FreeBSD and CHAR16 strings generally aren't a good fit. Since this parsing
55 * doesn't need Unicode for anything, this works out well.
60 * Taken from MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
64 DevicePathFromText protocol as defined in the UEFI 2.0 specification.
66 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
67 SPDX-License-Identifier: BSD-2-Clause-Patent
71 // #include "UefiDevicePathLib.h"
77 @param Src Source string.
79 @return The duplicated string.
84 UefiDevicePathLibStrDuplicate (
88 return AllocateCopyPool (StrSize (Src), Src);
93 Get parameter in a pair of parentheses follow the given node name.
94 For example, given the "Pci(0,1)" and NodeName "Pci", it returns "0,1".
96 @param Str Device Path Text.
97 @param NodeName Name of the node.
99 @return Parameter text for the node.
106 IN const CHAR16 *NodeName
111 UINTN NodeNameLength;
112 UINTN ParameterLength;
115 // Check whether the node name matchs
117 NodeNameLength = StrLen (NodeName);
118 if (StrnCmp (Str, NodeName, NodeNameLength) != 0) {
122 ParamStr = Str + NodeNameLength;
123 if (!IS_LEFT_PARENTH (*ParamStr)) {
128 // Skip the found '(' and find first occurrence of ')'
132 StrPointer = ParamStr;
133 while (!IS_NULL (*StrPointer)) {
134 if (IS_RIGHT_PARENTH (*StrPointer)) {
142 if (IS_NULL (*StrPointer)) {
149 ParamStr = AllocateCopyPool ((ParameterLength + 1) * sizeof (CHAR16), ParamStr);
150 if (ParamStr == NULL) {
155 // Terminate the parameter string
157 ParamStr[ParameterLength] = '\0';
163 Gets current sub-string from a string list, before return
164 the list header is moved to next sub-string. The sub-string is separated
165 by the specified character. For example, the separator is ',', the string
166 list is "2,0,3", it returns "2", the remain list move to "0,3"
168 @param List A string list separated by the specified separator
169 @param Separator The separator character
171 @return A pointer to the current sub-string
177 IN OUT CHAR16 **List,
187 if (IS_NULL (*Str)) {
192 // Find first occurrence of the separator
194 while (!IS_NULL (*Str)) {
195 if (*Str == Separator) {
202 if (*Str == Separator) {
204 // Find a sub-string, terminate it
211 // Move to next sub-string
219 Gets the next parameter string from the list.
221 @param List A string list separated by the specified separator
223 @return A pointer to the current sub-string
233 // The separator is comma
235 return SplitStr (List, ',');
239 Get one device node from entire device path text.
241 @param DevicePath On input, the current Device Path node; on output, the next device path node
242 @param IsInstanceEnd This node is the end of a device path instance
244 @return A device node text or NULL if no more device node available
249 GetNextDeviceNodeStr (
250 IN OUT CHAR16 **DevicePath,
251 OUT BOOLEAN *IsInstanceEnd
256 UINTN ParenthesesStack;
259 if (IS_NULL (*Str)) {
264 // Skip the leading '/', '(', ')' and ','
266 while (!IS_NULL (*Str)) {
267 if (!IS_SLASH (*Str) &&
269 !IS_LEFT_PARENTH (*Str) &&
270 !IS_RIGHT_PARENTH (*Str))
281 // Scan for the separator of this device node, '/' or ','
283 ParenthesesStack = 0;
284 while (!IS_NULL (*Str)) {
285 if ((IS_COMMA (*Str) || IS_SLASH (*Str)) && (ParenthesesStack == 0)) {
289 if (IS_LEFT_PARENTH (*Str)) {
291 } else if (IS_RIGHT_PARENTH (*Str)) {
298 if (ParenthesesStack != 0) {
300 // The '(' doesn't pair with ')', invalid device path text
305 if (IS_COMMA (*Str)) {
306 *IsInstanceEnd = TRUE;
310 *IsInstanceEnd = FALSE;
311 if (!IS_NULL (*Str)) {
325 Return whether the integer string is a hex string.
327 @param Str The integer string
329 @retval TRUE Hex string
330 @retval FALSE Decimal string
340 // skip preceeding white space
342 while ((*Str != 0) && *Str == ' ') {
347 // skip preceeding zeros
349 while ((*Str != 0) && *Str == '0') {
353 return (BOOLEAN)(*Str == 'x' || *Str == 'X');
358 Convert integer string to uint.
360 @param Str The integer string. If leading with "0x" or "0X", it's hexadecimal.
362 @return A UINTN value represented by Str
371 if (IsHexStr (Str)) {
372 return StrHexToUintn (Str);
374 return StrDecimalToUintn (Str);
380 Convert integer string to 64 bit data.
382 @param Str The integer string. If leading with "0x" or "0X", it's hexadecimal.
383 @param Data A pointer to the UINT64 value represented by Str
393 if (IsHexStr (Str)) {
394 *Data = StrHexToUint64 (Str);
396 *Data = StrDecimalToUint64 (Str);
402 Converts a Unicode string to ASCII string.
404 @param Str The equivalent Unicode string
405 @param AsciiStr On input, it points to destination ASCII string buffer; on output, it points
406 to the next ASCII string next to it
413 IN OUT CHAR8 **AsciiStr
419 while (!IS_NULL (*Str)) {
420 *(Dest++) = (CHAR8)*(Str++);
426 // Return the string next to it
428 *AsciiStr = Dest + 1;
432 Converts a generic text device path node to device path structure.
434 @param Type The type of the device path node.
435 @param TextDeviceNode The input text device path node.
437 @return A pointer to device path structure.
440 EFI_DEVICE_PATH_PROTOCOL *
441 DevPathFromTextGenericPath (
443 IN CHAR16 *TextDeviceNode
446 EFI_DEVICE_PATH_PROTOCOL *Node;
451 SubtypeStr = GetNextParamStr (&TextDeviceNode);
452 DataStr = GetNextParamStr (&TextDeviceNode);
454 if (DataStr == NULL) {
457 DataLength = StrLen (DataStr) / 2;
460 Node = CreateDeviceNode (
462 (UINT8)Strtoi (SubtypeStr),
463 (UINT16)(sizeof (EFI_DEVICE_PATH_PROTOCOL) + DataLength)
466 StrHexToBytes (DataStr, DataLength * 2, (UINT8 *)(Node + 1), DataLength);
471 Converts a generic text device path node to device path structure.
473 @param TextDeviceNode The input Text device path node.
475 @return A pointer to device path structure.
479 EFI_DEVICE_PATH_PROTOCOL *
480 DevPathFromTextPath (
481 IN CHAR16 *TextDeviceNode
486 TypeStr = GetNextParamStr (&TextDeviceNode);
488 return DevPathFromTextGenericPath ((UINT8)Strtoi (TypeStr), TextDeviceNode);
492 Converts a generic hardware text device path node to Hardware device path structure.
494 @param TextDeviceNode The input Text device path node.
496 @return A pointer to Hardware device path structure.
500 EFI_DEVICE_PATH_PROTOCOL *
501 DevPathFromTextHardwarePath (
502 IN CHAR16 *TextDeviceNode
505 return DevPathFromTextGenericPath (HARDWARE_DEVICE_PATH, TextDeviceNode);
509 Converts a text device path node to Hardware PCI device path structure.
511 @param TextDeviceNode The input Text device path node.
513 @return A pointer to Hardware PCI device path structure.
517 EFI_DEVICE_PATH_PROTOCOL *
519 IN CHAR16 *TextDeviceNode
524 PCI_DEVICE_PATH *Pci;
526 DeviceStr = GetNextParamStr (&TextDeviceNode);
527 FunctionStr = GetNextParamStr (&TextDeviceNode);
528 Pci = (PCI_DEVICE_PATH *)CreateDeviceNode (
529 HARDWARE_DEVICE_PATH,
531 (UINT16)sizeof (PCI_DEVICE_PATH)
534 Pci->Function = (UINT8)Strtoi (FunctionStr);
535 Pci->Device = (UINT8)Strtoi (DeviceStr);
537 return (EFI_DEVICE_PATH_PROTOCOL *)Pci;
541 Converts a text device path node to Hardware PC card device path structure.
543 @param TextDeviceNode The input Text device path node.
545 @return A pointer to Hardware PC card device path structure.
549 EFI_DEVICE_PATH_PROTOCOL *
550 DevPathFromTextPcCard (
551 IN CHAR16 *TextDeviceNode
554 CHAR16 *FunctionNumberStr;
555 PCCARD_DEVICE_PATH *Pccard;
557 FunctionNumberStr = GetNextParamStr (&TextDeviceNode);
558 Pccard = (PCCARD_DEVICE_PATH *)CreateDeviceNode (
559 HARDWARE_DEVICE_PATH,
561 (UINT16)sizeof (PCCARD_DEVICE_PATH)
564 Pccard->FunctionNumber = (UINT8)Strtoi (FunctionNumberStr);
566 return (EFI_DEVICE_PATH_PROTOCOL *)Pccard;
570 Converts a text device path node to Hardware memory map device path structure.
572 @param TextDeviceNode The input Text device path node.
574 @return A pointer to Hardware memory map device path structure.
578 EFI_DEVICE_PATH_PROTOCOL *
579 DevPathFromTextMemoryMapped (
580 IN CHAR16 *TextDeviceNode
583 CHAR16 *MemoryTypeStr;
584 CHAR16 *StartingAddressStr;
585 CHAR16 *EndingAddressStr;
586 MEMMAP_DEVICE_PATH *MemMap;
588 MemoryTypeStr = GetNextParamStr (&TextDeviceNode);
589 StartingAddressStr = GetNextParamStr (&TextDeviceNode);
590 EndingAddressStr = GetNextParamStr (&TextDeviceNode);
591 MemMap = (MEMMAP_DEVICE_PATH *)CreateDeviceNode (
592 HARDWARE_DEVICE_PATH,
594 (UINT16)sizeof (MEMMAP_DEVICE_PATH)
597 MemMap->MemoryType = (UINT32)Strtoi (MemoryTypeStr);
598 Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);
599 Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);
601 return (EFI_DEVICE_PATH_PROTOCOL *)MemMap;
605 Converts a text device path node to Vendor device path structure based on the input Type
608 @param TextDeviceNode The input Text device path node.
609 @param Type The type of device path node.
610 @param SubType The subtype of device path node.
612 @return A pointer to the newly-created Vendor device path structure.
616 EFI_DEVICE_PATH_PROTOCOL *
617 ConvertFromTextVendor (
618 IN CHAR16 *TextDeviceNode,
626 VENDOR_DEVICE_PATH *Vendor;
628 GuidStr = GetNextParamStr (&TextDeviceNode);
630 DataStr = GetNextParamStr (&TextDeviceNode);
631 Length = StrLen (DataStr);
633 // Two hex characters make up 1 buffer byte
635 Length = (Length + 1) / 2;
637 Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
640 (UINT16)(sizeof (VENDOR_DEVICE_PATH) + Length)
643 StrToGuid (GuidStr, &Vendor->Guid);
644 StrHexToBytes (DataStr, Length * 2, (UINT8 *)(Vendor + 1), Length);
646 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
650 Converts a text device path node to Vendor Hardware device path structure.
652 @param TextDeviceNode The input Text device path node.
654 @return A pointer to the newly-created Vendor Hardware device path structure.
658 EFI_DEVICE_PATH_PROTOCOL *
659 DevPathFromTextVenHw (
660 IN CHAR16 *TextDeviceNode
663 return ConvertFromTextVendor (
665 HARDWARE_DEVICE_PATH,
671 Converts a text device path node to Hardware Controller device path structure.
673 @param TextDeviceNode The input Text device path node.
675 @return A pointer to the newly-created Hardware Controller device path structure.
679 EFI_DEVICE_PATH_PROTOCOL *
680 DevPathFromTextCtrl (
681 IN CHAR16 *TextDeviceNode
684 CHAR16 *ControllerStr;
685 CONTROLLER_DEVICE_PATH *Controller;
687 ControllerStr = GetNextParamStr (&TextDeviceNode);
688 Controller = (CONTROLLER_DEVICE_PATH *)CreateDeviceNode (
689 HARDWARE_DEVICE_PATH,
691 (UINT16)sizeof (CONTROLLER_DEVICE_PATH)
693 Controller->ControllerNumber = (UINT32)Strtoi (ControllerStr);
695 return (EFI_DEVICE_PATH_PROTOCOL *)Controller;
699 Converts a text device path node to BMC device path structure.
701 @param TextDeviceNode The input Text device path node.
703 @return A pointer to the newly-created BMC device path structure.
707 EFI_DEVICE_PATH_PROTOCOL *
709 IN CHAR16 *TextDeviceNode
712 CHAR16 *InterfaceTypeStr;
713 CHAR16 *BaseAddressStr;
714 BMC_DEVICE_PATH *BmcDp;
716 InterfaceTypeStr = GetNextParamStr (&TextDeviceNode);
717 BaseAddressStr = GetNextParamStr (&TextDeviceNode);
718 BmcDp = (BMC_DEVICE_PATH *)CreateDeviceNode (
719 HARDWARE_DEVICE_PATH,
721 (UINT16)sizeof (BMC_DEVICE_PATH)
724 BmcDp->InterfaceType = (UINT8)Strtoi (InterfaceTypeStr);
726 (UINT64 *)(&BmcDp->BaseAddress),
727 StrHexToUint64 (BaseAddressStr)
730 return (EFI_DEVICE_PATH_PROTOCOL *)BmcDp;
734 Converts a generic ACPI text device path node to ACPI device path structure.
736 @param TextDeviceNode The input Text device path node.
738 @return A pointer to ACPI device path structure.
742 EFI_DEVICE_PATH_PROTOCOL *
743 DevPathFromTextAcpiPath (
744 IN CHAR16 *TextDeviceNode
747 return DevPathFromTextGenericPath (ACPI_DEVICE_PATH, TextDeviceNode);
751 Converts a string to EisaId.
753 @param Text The input string.
755 @return UINT32 EISA ID.
763 return (((Text[0] - 'A' + 1) & 0x1f) << 10)
764 + (((Text[1] - 'A' + 1) & 0x1f) << 5)
765 + (((Text[2] - 'A' + 1) & 0x1f) << 0)
766 + (UINT32)(StrHexToUintn (&Text[3]) << 16)
771 Converts a text device path node to ACPI HID device path structure.
773 @param TextDeviceNode The input Text device path node.
775 @return A pointer to the newly-created ACPI HID device path structure.
779 EFI_DEVICE_PATH_PROTOCOL *
780 DevPathFromTextAcpi (
781 IN CHAR16 *TextDeviceNode
786 ACPI_HID_DEVICE_PATH *Acpi;
788 HIDStr = GetNextParamStr (&TextDeviceNode);
789 UIDStr = GetNextParamStr (&TextDeviceNode);
790 Acpi = (ACPI_HID_DEVICE_PATH *)CreateDeviceNode (
793 (UINT16)sizeof (ACPI_HID_DEVICE_PATH)
796 Acpi->HID = EisaIdFromText (HIDStr);
797 Acpi->UID = (UINT32)Strtoi (UIDStr);
799 return (EFI_DEVICE_PATH_PROTOCOL *)Acpi;
803 Converts a text device path node to ACPI HID device path structure.
805 @param TextDeviceNode The input Text device path node.
806 @param PnPId The input plug and play identification.
808 @return A pointer to the newly-created ACPI HID device path structure.
812 EFI_DEVICE_PATH_PROTOCOL *
813 ConvertFromTextAcpi (
814 IN CHAR16 *TextDeviceNode,
819 ACPI_HID_DEVICE_PATH *Acpi;
821 UIDStr = GetNextParamStr (&TextDeviceNode);
822 Acpi = (ACPI_HID_DEVICE_PATH *)CreateDeviceNode (
825 (UINT16)sizeof (ACPI_HID_DEVICE_PATH)
828 Acpi->HID = EFI_PNP_ID (PnPId);
829 Acpi->UID = (UINT32)Strtoi (UIDStr);
831 return (EFI_DEVICE_PATH_PROTOCOL *)Acpi;
835 Converts a text device path node to PCI root device path structure.
837 @param TextDeviceNode The input Text device path node.
839 @return A pointer to the newly-created PCI root device path structure.
843 EFI_DEVICE_PATH_PROTOCOL *
844 DevPathFromTextPciRoot (
845 IN CHAR16 *TextDeviceNode
848 return ConvertFromTextAcpi (TextDeviceNode, 0x0a03);
852 Converts a text device path node to PCIE root device path structure.
854 @param TextDeviceNode The input Text device path node.
856 @return A pointer to the newly-created PCIE root device path structure.
860 EFI_DEVICE_PATH_PROTOCOL *
861 DevPathFromTextPcieRoot (
862 IN CHAR16 *TextDeviceNode
865 return ConvertFromTextAcpi (TextDeviceNode, 0x0a08);
869 Converts a text device path node to Floppy device path structure.
871 @param TextDeviceNode The input Text device path node.
873 @return A pointer to the newly-created Floppy device path structure.
877 EFI_DEVICE_PATH_PROTOCOL *
878 DevPathFromTextFloppy (
879 IN CHAR16 *TextDeviceNode
882 return ConvertFromTextAcpi (TextDeviceNode, 0x0604);
886 Converts a text device path node to Keyboard device path structure.
888 @param TextDeviceNode The input Text device path node.
890 @return A pointer to the newly-created Keyboard device path structure.
894 EFI_DEVICE_PATH_PROTOCOL *
895 DevPathFromTextKeyboard (
896 IN CHAR16 *TextDeviceNode
899 return ConvertFromTextAcpi (TextDeviceNode, 0x0301);
903 Converts a text device path node to Serial device path structure.
905 @param TextDeviceNode The input Text device path node.
907 @return A pointer to the newly-created Serial device path structure.
911 EFI_DEVICE_PATH_PROTOCOL *
912 DevPathFromTextSerial (
913 IN CHAR16 *TextDeviceNode
916 return ConvertFromTextAcpi (TextDeviceNode, 0x0501);
920 Converts a text device path node to Parallel Port device path structure.
922 @param TextDeviceNode The input Text device path node.
924 @return A pointer to the newly-created Parallel Port device path structure.
928 EFI_DEVICE_PATH_PROTOCOL *
929 DevPathFromTextParallelPort (
930 IN CHAR16 *TextDeviceNode
933 return ConvertFromTextAcpi (TextDeviceNode, 0x0401);
937 Converts a text device path node to ACPI extension device path structure.
939 @param TextDeviceNode The input Text device path node.
941 @return A pointer to the newly-created ACPI extension device path structure.
945 EFI_DEVICE_PATH_PROTOCOL *
946 DevPathFromTextAcpiEx (
947 IN CHAR16 *TextDeviceNode
958 ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
960 HIDStr = GetNextParamStr (&TextDeviceNode);
961 CIDStr = GetNextParamStr (&TextDeviceNode);
962 UIDStr = GetNextParamStr (&TextDeviceNode);
963 HIDSTRStr = GetNextParamStr (&TextDeviceNode);
964 CIDSTRStr = GetNextParamStr (&TextDeviceNode);
965 UIDSTRStr = GetNextParamStr (&TextDeviceNode);
967 Length = (UINT16)(sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (HIDSTRStr) + 1);
968 Length = (UINT16)(Length + StrLen (UIDSTRStr) + 1);
969 Length = (UINT16)(Length + StrLen (CIDSTRStr) + 1);
970 AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *)CreateDeviceNode (
976 AcpiEx->HID = EisaIdFromText (HIDStr);
977 AcpiEx->CID = EisaIdFromText (CIDStr);
978 AcpiEx->UID = (UINT32)Strtoi (UIDStr);
980 AsciiStr = (CHAR8 *)((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
981 StrToAscii (HIDSTRStr, &AsciiStr);
982 StrToAscii (UIDSTRStr, &AsciiStr);
983 StrToAscii (CIDSTRStr, &AsciiStr);
985 return (EFI_DEVICE_PATH_PROTOCOL *)AcpiEx;
989 Converts a text device path node to ACPI extension device path structure.
991 @param TextDeviceNode The input Text device path node.
993 @return A pointer to the newly-created ACPI extension device path structure.
997 EFI_DEVICE_PATH_PROTOCOL *
998 DevPathFromTextAcpiExp (
999 IN CHAR16 *TextDeviceNode
1007 ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
1009 HIDStr = GetNextParamStr (&TextDeviceNode);
1010 CIDStr = GetNextParamStr (&TextDeviceNode);
1011 UIDSTRStr = GetNextParamStr (&TextDeviceNode);
1012 Length = (UINT16)(sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (UIDSTRStr) + 3);
1013 AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *)CreateDeviceNode (
1019 AcpiEx->HID = EisaIdFromText (HIDStr);
1021 // According to UEFI spec, the CID parameter is optional and has a default value of 0.
1022 // So when the CID parameter is not specified or specified as 0 in the text device node.
1023 // Set the CID to 0 in the ACPI extension device path structure.
1025 if ((*CIDStr == '\0') || (*CIDStr == '0')) {
1028 AcpiEx->CID = EisaIdFromText (CIDStr);
1033 AsciiStr = (CHAR8 *)((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
1035 // HID string is NULL
1039 // Convert UID string
1042 StrToAscii (UIDSTRStr, &AsciiStr);
1044 // CID string is NULL
1048 return (EFI_DEVICE_PATH_PROTOCOL *)AcpiEx;
1052 Converts a text device path node to ACPI _ADR device path structure.
1054 @param TextDeviceNode The input Text device path node.
1056 @return A pointer to the newly-created ACPI _ADR device path structure.
1060 EFI_DEVICE_PATH_PROTOCOL *
1061 DevPathFromTextAcpiAdr (
1062 IN CHAR16 *TextDeviceNode
1065 CHAR16 *DisplayDeviceStr;
1066 ACPI_ADR_DEVICE_PATH *AcpiAdr;
1070 AcpiAdr = (ACPI_ADR_DEVICE_PATH *)CreateDeviceNode (
1073 (UINT16)sizeof (ACPI_ADR_DEVICE_PATH)
1075 ASSERT (AcpiAdr != NULL);
1077 for (Index = 0; ; Index++) {
1078 DisplayDeviceStr = GetNextParamStr (&TextDeviceNode);
1079 if (IS_NULL (*DisplayDeviceStr)) {
1084 Length = DevicePathNodeLength (AcpiAdr);
1085 AcpiAdr = ReallocatePool (
1087 Length + sizeof (UINT32),
1090 ASSERT (AcpiAdr != NULL);
1091 SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32));
1094 (&AcpiAdr->ADR)[Index] = (UINT32)Strtoi (DisplayDeviceStr);
1097 return (EFI_DEVICE_PATH_PROTOCOL *)AcpiAdr;
1101 Converts a generic messaging text device path node to messaging device path structure.
1103 @param TextDeviceNode The input Text device path node.
1105 @return A pointer to messaging device path structure.
1109 EFI_DEVICE_PATH_PROTOCOL *
1110 DevPathFromTextMsg (
1111 IN CHAR16 *TextDeviceNode
1114 return DevPathFromTextGenericPath (MESSAGING_DEVICE_PATH, TextDeviceNode);
1118 Converts a text device path node to Parallel Port device path structure.
1120 @param TextDeviceNode The input Text device path node.
1122 @return A pointer to the newly-created Parallel Port device path structure.
1126 EFI_DEVICE_PATH_PROTOCOL *
1127 DevPathFromTextAta (
1128 IN CHAR16 *TextDeviceNode
1131 CHAR16 *PrimarySecondaryStr;
1132 CHAR16 *SlaveMasterStr;
1134 ATAPI_DEVICE_PATH *Atapi;
1136 Atapi = (ATAPI_DEVICE_PATH *)CreateDeviceNode (
1137 MESSAGING_DEVICE_PATH,
1139 (UINT16)sizeof (ATAPI_DEVICE_PATH)
1142 PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
1143 SlaveMasterStr = GetNextParamStr (&TextDeviceNode);
1144 LunStr = GetNextParamStr (&TextDeviceNode);
1146 if (StrCmp (PrimarySecondaryStr, "Primary") == 0) {
1147 Atapi->PrimarySecondary = 0;
1148 } else if (StrCmp (PrimarySecondaryStr, "Secondary") == 0) {
1149 Atapi->PrimarySecondary = 1;
1151 Atapi->PrimarySecondary = (UINT8)Strtoi (PrimarySecondaryStr);
1154 if (StrCmp (SlaveMasterStr, "Master") == 0) {
1155 Atapi->SlaveMaster = 0;
1156 } else if (StrCmp (SlaveMasterStr, "Slave") == 0) {
1157 Atapi->SlaveMaster = 1;
1159 Atapi->SlaveMaster = (UINT8)Strtoi (SlaveMasterStr);
1162 Atapi->Lun = (UINT16)Strtoi (LunStr);
1164 return (EFI_DEVICE_PATH_PROTOCOL *)Atapi;
1168 Converts a text device path node to SCSI device path structure.
1170 @param TextDeviceNode The input Text device path node.
1172 @return A pointer to the newly-created SCSI device path structure.
1176 EFI_DEVICE_PATH_PROTOCOL *
1177 DevPathFromTextScsi (
1178 IN CHAR16 *TextDeviceNode
1183 SCSI_DEVICE_PATH *Scsi;
1185 PunStr = GetNextParamStr (&TextDeviceNode);
1186 LunStr = GetNextParamStr (&TextDeviceNode);
1187 Scsi = (SCSI_DEVICE_PATH *)CreateDeviceNode (
1188 MESSAGING_DEVICE_PATH,
1190 (UINT16)sizeof (SCSI_DEVICE_PATH)
1193 Scsi->Pun = (UINT16)Strtoi (PunStr);
1194 Scsi->Lun = (UINT16)Strtoi (LunStr);
1196 return (EFI_DEVICE_PATH_PROTOCOL *)Scsi;
1200 Converts a text device path node to Fibre device path structure.
1202 @param TextDeviceNode The input Text device path node.
1204 @return A pointer to the newly-created Fibre device path structure.
1208 EFI_DEVICE_PATH_PROTOCOL *
1209 DevPathFromTextFibre (
1210 IN CHAR16 *TextDeviceNode
1215 FIBRECHANNEL_DEVICE_PATH *Fibre;
1217 WWNStr = GetNextParamStr (&TextDeviceNode);
1218 LunStr = GetNextParamStr (&TextDeviceNode);
1219 Fibre = (FIBRECHANNEL_DEVICE_PATH *)CreateDeviceNode (
1220 MESSAGING_DEVICE_PATH,
1221 MSG_FIBRECHANNEL_DP,
1222 (UINT16)sizeof (FIBRECHANNEL_DEVICE_PATH)
1225 Fibre->Reserved = 0;
1226 Strtoi64 (WWNStr, &Fibre->WWN);
1227 Strtoi64 (LunStr, &Fibre->Lun);
1229 return (EFI_DEVICE_PATH_PROTOCOL *)Fibre;
1233 Converts a text device path node to FibreEx device path structure.
1235 @param TextDeviceNode The input Text device path node.
1237 @return A pointer to the newly-created FibreEx device path structure.
1241 EFI_DEVICE_PATH_PROTOCOL *
1242 DevPathFromTextFibreEx (
1243 IN CHAR16 *TextDeviceNode
1248 FIBRECHANNELEX_DEVICE_PATH *FibreEx;
1250 WWNStr = GetNextParamStr (&TextDeviceNode);
1251 LunStr = GetNextParamStr (&TextDeviceNode);
1252 FibreEx = (FIBRECHANNELEX_DEVICE_PATH *)CreateDeviceNode (
1253 MESSAGING_DEVICE_PATH,
1254 MSG_FIBRECHANNELEX_DP,
1255 (UINT16)sizeof (FIBRECHANNELEX_DEVICE_PATH)
1258 FibreEx->Reserved = 0;
1259 Strtoi64 (WWNStr, (UINT64 *)(&FibreEx->WWN));
1260 Strtoi64 (LunStr, (UINT64 *)(&FibreEx->Lun));
1262 *(UINT64 *)(&FibreEx->WWN) = SwapBytes64 (*(UINT64 *)(&FibreEx->WWN));
1263 *(UINT64 *)(&FibreEx->Lun) = SwapBytes64 (*(UINT64 *)(&FibreEx->Lun));
1265 return (EFI_DEVICE_PATH_PROTOCOL *)FibreEx;
1269 Converts a text device path node to 1394 device path structure.
1271 @param TextDeviceNode The input Text device path node.
1273 @return A pointer to the newly-created 1394 device path structure.
1277 EFI_DEVICE_PATH_PROTOCOL *
1278 DevPathFromText1394 (
1279 IN CHAR16 *TextDeviceNode
1283 F1394_DEVICE_PATH *F1394DevPath;
1285 GuidStr = GetNextParamStr (&TextDeviceNode);
1286 F1394DevPath = (F1394_DEVICE_PATH *)CreateDeviceNode (
1287 MESSAGING_DEVICE_PATH,
1289 (UINT16)sizeof (F1394_DEVICE_PATH)
1292 F1394DevPath->Reserved = 0;
1293 F1394DevPath->Guid = StrHexToUint64 (GuidStr);
1295 return (EFI_DEVICE_PATH_PROTOCOL *)F1394DevPath;
1299 Converts a text device path node to USB device path structure.
1301 @param TextDeviceNode The input Text device path node.
1303 @return A pointer to the newly-created USB device path structure.
1307 EFI_DEVICE_PATH_PROTOCOL *
1308 DevPathFromTextUsb (
1309 IN CHAR16 *TextDeviceNode
1313 CHAR16 *InterfaceStr;
1314 USB_DEVICE_PATH *Usb;
1316 PortStr = GetNextParamStr (&TextDeviceNode);
1317 InterfaceStr = GetNextParamStr (&TextDeviceNode);
1318 Usb = (USB_DEVICE_PATH *)CreateDeviceNode (
1319 MESSAGING_DEVICE_PATH,
1321 (UINT16)sizeof (USB_DEVICE_PATH)
1324 Usb->ParentPortNumber = (UINT8)Strtoi (PortStr);
1325 Usb->InterfaceNumber = (UINT8)Strtoi (InterfaceStr);
1327 return (EFI_DEVICE_PATH_PROTOCOL *)Usb;
1331 Converts a text device path node to I20 device path structure.
1333 @param TextDeviceNode The input Text device path node.
1335 @return A pointer to the newly-created I20 device path structure.
1339 EFI_DEVICE_PATH_PROTOCOL *
1340 DevPathFromTextI2O (
1341 IN CHAR16 *TextDeviceNode
1345 I2O_DEVICE_PATH *I2ODevPath;
1347 TIDStr = GetNextParamStr (&TextDeviceNode);
1348 I2ODevPath = (I2O_DEVICE_PATH *)CreateDeviceNode (
1349 MESSAGING_DEVICE_PATH,
1351 (UINT16)sizeof (I2O_DEVICE_PATH)
1354 I2ODevPath->Tid = (UINT32)Strtoi (TIDStr);
1356 return (EFI_DEVICE_PATH_PROTOCOL *)I2ODevPath;
1360 Converts a text device path node to Infini Band device path structure.
1362 @param TextDeviceNode The input Text device path node.
1364 @return A pointer to the newly-created Infini Band device path structure.
1368 EFI_DEVICE_PATH_PROTOCOL *
1369 DevPathFromTextInfiniband (
1370 IN CHAR16 *TextDeviceNode
1378 INFINIBAND_DEVICE_PATH *InfiniBand;
1380 FlagsStr = GetNextParamStr (&TextDeviceNode);
1381 GuidStr = GetNextParamStr (&TextDeviceNode);
1382 SidStr = GetNextParamStr (&TextDeviceNode);
1383 TidStr = GetNextParamStr (&TextDeviceNode);
1384 DidStr = GetNextParamStr (&TextDeviceNode);
1385 InfiniBand = (INFINIBAND_DEVICE_PATH *)CreateDeviceNode (
1386 MESSAGING_DEVICE_PATH,
1388 (UINT16)sizeof (INFINIBAND_DEVICE_PATH)
1391 InfiniBand->ResourceFlags = (UINT32)Strtoi (FlagsStr);
1392 StrToGuid (GuidStr, (EFI_GUID *)InfiniBand->PortGid);
1393 Strtoi64 (SidStr, &InfiniBand->ServiceId);
1394 Strtoi64 (TidStr, &InfiniBand->TargetPortId);
1395 Strtoi64 (DidStr, &InfiniBand->DeviceId);
1397 return (EFI_DEVICE_PATH_PROTOCOL *)InfiniBand;
1401 Converts a text device path node to Vendor-Defined Messaging device path structure.
1403 @param TextDeviceNode The input Text device path node.
1405 @return A pointer to the newly-created Vendor-Defined Messaging device path structure.
1409 EFI_DEVICE_PATH_PROTOCOL *
1410 DevPathFromTextVenMsg (
1411 IN CHAR16 *TextDeviceNode
1414 return ConvertFromTextVendor (
1416 MESSAGING_DEVICE_PATH,
1422 Converts a text device path node to Vendor defined PC-ANSI device path structure.
1424 @param TextDeviceNode The input Text device path node.
1426 @return A pointer to the newly-created Vendor defined PC-ANSI device path structure.
1430 EFI_DEVICE_PATH_PROTOCOL *
1431 DevPathFromTextVenPcAnsi (
1432 IN CHAR16 *TextDeviceNode
1435 VENDOR_DEVICE_PATH *Vendor;
1437 Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
1438 MESSAGING_DEVICE_PATH,
1440 (UINT16)sizeof (VENDOR_DEVICE_PATH)
1442 CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
1444 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
1448 Converts a text device path node to Vendor defined VT100 device path structure.
1450 @param TextDeviceNode The input Text device path node.
1452 @return A pointer to the newly-created Vendor defined VT100 device path structure.
1456 EFI_DEVICE_PATH_PROTOCOL *
1457 DevPathFromTextVenVt100 (
1458 IN CHAR16 *TextDeviceNode
1461 VENDOR_DEVICE_PATH *Vendor;
1463 Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
1464 MESSAGING_DEVICE_PATH,
1466 (UINT16)sizeof (VENDOR_DEVICE_PATH)
1468 CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
1470 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
1474 Converts a text device path node to Vendor defined VT100 Plus device path structure.
1476 @param TextDeviceNode The input Text device path node.
1478 @return A pointer to the newly-created Vendor defined VT100 Plus device path structure.
1482 EFI_DEVICE_PATH_PROTOCOL *
1483 DevPathFromTextVenVt100Plus (
1484 IN CHAR16 *TextDeviceNode
1487 VENDOR_DEVICE_PATH *Vendor;
1489 Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
1490 MESSAGING_DEVICE_PATH,
1492 (UINT16)sizeof (VENDOR_DEVICE_PATH)
1494 CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
1496 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
1500 Converts a text device path node to Vendor defined UTF8 device path structure.
1502 @param TextDeviceNode The input Text device path node.
1504 @return A pointer to the newly-created Vendor defined UTF8 device path structure.
1508 EFI_DEVICE_PATH_PROTOCOL *
1509 DevPathFromTextVenUtf8 (
1510 IN CHAR16 *TextDeviceNode
1513 VENDOR_DEVICE_PATH *Vendor;
1515 Vendor = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
1516 MESSAGING_DEVICE_PATH,
1518 (UINT16)sizeof (VENDOR_DEVICE_PATH)
1520 CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
1522 return (EFI_DEVICE_PATH_PROTOCOL *)Vendor;
1526 Converts a text device path node to UART Flow Control device path structure.
1528 @param TextDeviceNode The input Text device path node.
1530 @return A pointer to the newly-created UART Flow Control device path structure.
1534 EFI_DEVICE_PATH_PROTOCOL *
1535 DevPathFromTextUartFlowCtrl (
1536 IN CHAR16 *TextDeviceNode
1540 UART_FLOW_CONTROL_DEVICE_PATH *UartFlowControl;
1542 ValueStr = GetNextParamStr (&TextDeviceNode);
1543 UartFlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *)CreateDeviceNode (
1544 MESSAGING_DEVICE_PATH,
1546 (UINT16)sizeof (UART_FLOW_CONTROL_DEVICE_PATH)
1549 CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
1550 if (StrCmp (ValueStr, "XonXoff") == 0) {
1551 UartFlowControl->FlowControlMap = 2;
1552 } else if (StrCmp (ValueStr, "Hardware") == 0) {
1553 UartFlowControl->FlowControlMap = 1;
1555 UartFlowControl->FlowControlMap = 0;
1558 return (EFI_DEVICE_PATH_PROTOCOL *)UartFlowControl;
1562 Converts a text device path node to Serial Attached SCSI device path structure.
1564 @param TextDeviceNode The input Text device path node.
1566 @return A pointer to the newly-created Serial Attached SCSI device path structure.
1570 EFI_DEVICE_PATH_PROTOCOL *
1571 DevPathFromTextSAS (
1572 IN CHAR16 *TextDeviceNode
1579 CHAR16 *LocationStr;
1581 CHAR16 *DriveBayStr;
1582 CHAR16 *ReservedStr;
1585 SAS_DEVICE_PATH *Sas;
1587 AddressStr = GetNextParamStr (&TextDeviceNode);
1588 LunStr = GetNextParamStr (&TextDeviceNode);
1589 RTPStr = GetNextParamStr (&TextDeviceNode);
1590 SASSATAStr = GetNextParamStr (&TextDeviceNode);
1591 LocationStr = GetNextParamStr (&TextDeviceNode);
1592 ConnectStr = GetNextParamStr (&TextDeviceNode);
1593 DriveBayStr = GetNextParamStr (&TextDeviceNode);
1594 ReservedStr = GetNextParamStr (&TextDeviceNode);
1595 Sas = (SAS_DEVICE_PATH *)CreateDeviceNode (
1596 MESSAGING_DEVICE_PATH,
1598 (UINT16)sizeof (SAS_DEVICE_PATH)
1601 CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid);
1602 Strtoi64 (AddressStr, &Sas->SasAddress);
1603 Strtoi64 (LunStr, &Sas->Lun);
1604 Sas->RelativeTargetPort = (UINT16)Strtoi (RTPStr);
1606 if (StrCmp (SASSATAStr, "NoTopology") == 0) {
1608 } else if ((StrCmp (SASSATAStr, "SATA") == 0) || (StrCmp (SASSATAStr, "SAS") == 0)) {
1609 Uint16 = (UINT16)Strtoi (DriveBayStr);
1613 Info = (UINT16)(0x2 | ((Uint16 - 1) << 8));
1616 if (StrCmp (SASSATAStr, "SATA") == 0) {
1621 // Location is an integer between 0 and 1 or else
1622 // the keyword Internal (0) or External (1).
1624 if (StrCmp (LocationStr, "External") == 0) {
1626 } else if (StrCmp (LocationStr, "Internal") == 0) {
1629 Uint16 = ((UINT16)Strtoi (LocationStr) & BIT0);
1632 Info |= (Uint16 << 5);
1635 // Connect is an integer between 0 and 3 or else
1636 // the keyword Direct (0) or Expanded (1).
1638 if (StrCmp (ConnectStr, "Expanded") == 0) {
1640 } else if (StrCmp (ConnectStr, "Direct") == 0) {
1643 Uint16 = ((UINT16)Strtoi (ConnectStr) & (BIT0 | BIT1));
1646 Info |= (Uint16 << 6);
1648 Info = (UINT16)Strtoi (SASSATAStr);
1651 Sas->DeviceTopology = Info;
1652 Sas->Reserved = (UINT32)Strtoi (ReservedStr);
1654 return (EFI_DEVICE_PATH_PROTOCOL *)Sas;
1658 Converts a text device path node to Serial Attached SCSI Ex device path structure.
1660 @param TextDeviceNode The input Text device path node.
1662 @return A pointer to the newly-created Serial Attached SCSI Ex device path structure.
1666 EFI_DEVICE_PATH_PROTOCOL *
1667 DevPathFromTextSasEx (
1668 IN CHAR16 *TextDeviceNode
1675 CHAR16 *LocationStr;
1677 CHAR16 *DriveBayStr;
1682 SASEX_DEVICE_PATH *SasEx;
1684 AddressStr = GetNextParamStr (&TextDeviceNode);
1685 LunStr = GetNextParamStr (&TextDeviceNode);
1686 RTPStr = GetNextParamStr (&TextDeviceNode);
1687 SASSATAStr = GetNextParamStr (&TextDeviceNode);
1688 LocationStr = GetNextParamStr (&TextDeviceNode);
1689 ConnectStr = GetNextParamStr (&TextDeviceNode);
1690 DriveBayStr = GetNextParamStr (&TextDeviceNode);
1691 SasEx = (SASEX_DEVICE_PATH *)CreateDeviceNode (
1692 MESSAGING_DEVICE_PATH,
1694 (UINT16)sizeof (SASEX_DEVICE_PATH)
1697 Strtoi64 (AddressStr, &SasAddress);
1698 Strtoi64 (LunStr, &Lun);
1699 WriteUnaligned64 ((UINT64 *)&SasEx->SasAddress, SwapBytes64 (SasAddress));
1700 WriteUnaligned64 ((UINT64 *)&SasEx->Lun, SwapBytes64 (Lun));
1701 SasEx->RelativeTargetPort = (UINT16)Strtoi (RTPStr);
1703 if (StrCmp (SASSATAStr, "NoTopology") == 0) {
1705 } else if ((StrCmp (SASSATAStr, "SATA") == 0) || (StrCmp (SASSATAStr, "SAS") == 0)) {
1706 Uint16 = (UINT16)Strtoi (DriveBayStr);
1710 Info = (UINT16)(0x2 | ((Uint16 - 1) << 8));
1713 if (StrCmp (SASSATAStr, "SATA") == 0) {
1718 // Location is an integer between 0 and 1 or else
1719 // the keyword Internal (0) or External (1).
1721 if (StrCmp (LocationStr, "External") == 0) {
1723 } else if (StrCmp (LocationStr, "Internal") == 0) {
1726 Uint16 = ((UINT16)Strtoi (LocationStr) & BIT0);
1729 Info |= (Uint16 << 5);
1732 // Connect is an integer between 0 and 3 or else
1733 // the keyword Direct (0) or Expanded (1).
1735 if (StrCmp (ConnectStr, "Expanded") == 0) {
1737 } else if (StrCmp (ConnectStr, "Direct") == 0) {
1740 Uint16 = ((UINT16)Strtoi (ConnectStr) & (BIT0 | BIT1));
1743 Info |= (Uint16 << 6);
1745 Info = (UINT16)Strtoi (SASSATAStr);
1748 SasEx->DeviceTopology = Info;
1750 return (EFI_DEVICE_PATH_PROTOCOL *)SasEx;
1754 Converts a text device path node to NVM Express Namespace device path structure.
1756 @param TextDeviceNode The input Text device path node.
1758 @return A pointer to the newly-created NVM Express Namespace device path structure.
1762 EFI_DEVICE_PATH_PROTOCOL *
1763 DevPathFromTextNVMe (
1764 IN CHAR16 *TextDeviceNode
1767 CHAR16 *NamespaceIdStr;
1768 CHAR16 *NamespaceUuidStr;
1769 NVME_NAMESPACE_DEVICE_PATH *Nvme;
1773 NamespaceIdStr = GetNextParamStr (&TextDeviceNode);
1774 NamespaceUuidStr = GetNextParamStr (&TextDeviceNode);
1775 Nvme = (NVME_NAMESPACE_DEVICE_PATH *)CreateDeviceNode (
1776 MESSAGING_DEVICE_PATH,
1777 MSG_NVME_NAMESPACE_DP,
1778 (UINT16)sizeof (NVME_NAMESPACE_DEVICE_PATH)
1781 Nvme->NamespaceId = (UINT32)Strtoi (NamespaceIdStr);
1782 Uuid = (UINT8 *)&Nvme->NamespaceUuid;
1784 Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
1785 while (Index-- != 0) {
1786 Uuid[Index] = (UINT8)StrHexToUintn (SplitStr (&NamespaceUuidStr, '-'));
1789 return (EFI_DEVICE_PATH_PROTOCOL *)Nvme;
1793 Converts a text device path node to UFS device path structure.
1795 @param TextDeviceNode The input Text device path node.
1797 @return A pointer to the newly-created UFS device path structure.
1801 EFI_DEVICE_PATH_PROTOCOL *
1802 DevPathFromTextUfs (
1803 IN CHAR16 *TextDeviceNode
1808 UFS_DEVICE_PATH *Ufs;
1810 PunStr = GetNextParamStr (&TextDeviceNode);
1811 LunStr = GetNextParamStr (&TextDeviceNode);
1812 Ufs = (UFS_DEVICE_PATH *)CreateDeviceNode (
1813 MESSAGING_DEVICE_PATH,
1815 (UINT16)sizeof (UFS_DEVICE_PATH)
1818 Ufs->Pun = (UINT8)Strtoi (PunStr);
1819 Ufs->Lun = (UINT8)Strtoi (LunStr);
1821 return (EFI_DEVICE_PATH_PROTOCOL *)Ufs;
1825 Converts a text device path node to SD (Secure Digital) device path structure.
1827 @param TextDeviceNode The input Text device path node.
1829 @return A pointer to the newly-created SD device path structure.
1833 EFI_DEVICE_PATH_PROTOCOL *
1835 IN CHAR16 *TextDeviceNode
1838 CHAR16 *SlotNumberStr;
1841 SlotNumberStr = GetNextParamStr (&TextDeviceNode);
1842 Sd = (SD_DEVICE_PATH *)CreateDeviceNode (
1843 MESSAGING_DEVICE_PATH,
1845 (UINT16)sizeof (SD_DEVICE_PATH)
1848 Sd->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
1850 return (EFI_DEVICE_PATH_PROTOCOL *)Sd;
1854 Converts a text device path node to EMMC (Embedded MMC) device path structure.
1856 @param TextDeviceNode The input Text device path node.
1858 @return A pointer to the newly-created EMMC device path structure.
1862 EFI_DEVICE_PATH_PROTOCOL *
1863 DevPathFromTextEmmc (
1864 IN CHAR16 *TextDeviceNode
1867 CHAR16 *SlotNumberStr;
1868 EMMC_DEVICE_PATH *Emmc;
1870 SlotNumberStr = GetNextParamStr (&TextDeviceNode);
1871 Emmc = (EMMC_DEVICE_PATH *)CreateDeviceNode (
1872 MESSAGING_DEVICE_PATH,
1874 (UINT16)sizeof (EMMC_DEVICE_PATH)
1877 Emmc->SlotNumber = (UINT8)Strtoi (SlotNumberStr);
1879 return (EFI_DEVICE_PATH_PROTOCOL *)Emmc;
1883 Converts a text device path node to Debug Port device path structure.
1885 @param TextDeviceNode The input Text device path node.
1887 @return A pointer to the newly-created Debug Port device path structure.
1891 EFI_DEVICE_PATH_PROTOCOL *
1892 DevPathFromTextDebugPort (
1893 IN CHAR16 *TextDeviceNode
1896 VENDOR_DEVICE_PATH *Vend;
1898 Vend = (VENDOR_DEVICE_PATH *)CreateDeviceNode (
1899 MESSAGING_DEVICE_PATH,
1901 (UINT16)sizeof (VENDOR_DEVICE_PATH)
1904 CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
1906 return (EFI_DEVICE_PATH_PROTOCOL *)Vend;
1910 Converts a text device path node to MAC device path structure.
1912 @param TextDeviceNode The input Text device path node.
1914 @return A pointer to the newly-created MAC device path structure.
1918 EFI_DEVICE_PATH_PROTOCOL *
1919 DevPathFromTextMAC (
1920 IN CHAR16 *TextDeviceNode
1926 MAC_ADDR_DEVICE_PATH *MACDevPath;
1928 AddressStr = GetNextParamStr (&TextDeviceNode);
1929 IfTypeStr = GetNextParamStr (&TextDeviceNode);
1930 MACDevPath = (MAC_ADDR_DEVICE_PATH *)CreateDeviceNode (
1931 MESSAGING_DEVICE_PATH,
1933 (UINT16)sizeof (MAC_ADDR_DEVICE_PATH)
1936 MACDevPath->IfType = (UINT8)Strtoi (IfTypeStr);
1938 Length = sizeof (EFI_MAC_ADDRESS);
1939 if ((MACDevPath->IfType == 0x01) || (MACDevPath->IfType == 0x00)) {
1943 StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Length);
1945 return (EFI_DEVICE_PATH_PROTOCOL *)MACDevPath;
1949 Converts a text format to the network protocol ID.
1951 @param Text String of protocol field.
1953 @return Network protocol ID .
1958 NetworkProtocolFromText (
1962 if (StrCmp (Text, "UDP") == 0) {
1963 return RFC_1700_UDP_PROTOCOL;
1966 if (StrCmp (Text, "TCP") == 0) {
1967 return RFC_1700_TCP_PROTOCOL;
1970 return Strtoi (Text);
1974 Converts a text device path node to IPV4 device path structure.
1976 @param TextDeviceNode The input Text device path node.
1978 @return A pointer to the newly-created IPV4 device path structure.
1982 EFI_DEVICE_PATH_PROTOCOL *
1983 DevPathFromTextIPv4 (
1984 IN CHAR16 *TextDeviceNode
1987 CHAR16 *RemoteIPStr;
1988 CHAR16 *ProtocolStr;
1991 CHAR16 *GatewayIPStr;
1992 CHAR16 *SubnetMaskStr;
1993 IPv4_DEVICE_PATH *IPv4;
1995 RemoteIPStr = GetNextParamStr (&TextDeviceNode);
1996 ProtocolStr = GetNextParamStr (&TextDeviceNode);
1997 TypeStr = GetNextParamStr (&TextDeviceNode);
1998 LocalIPStr = GetNextParamStr (&TextDeviceNode);
1999 GatewayIPStr = GetNextParamStr (&TextDeviceNode);
2000 SubnetMaskStr = GetNextParamStr (&TextDeviceNode);
2001 IPv4 = (IPv4_DEVICE_PATH *)CreateDeviceNode (
2002 MESSAGING_DEVICE_PATH,
2004 (UINT16)sizeof (IPv4_DEVICE_PATH)
2007 StrToIpv4Address (RemoteIPStr, NULL, &IPv4->RemoteIpAddress, NULL);
2008 IPv4->Protocol = (UINT16)NetworkProtocolFromText (ProtocolStr);
2009 if (StrCmp (TypeStr, "Static") == 0) {
2010 IPv4->StaticIpAddress = TRUE;
2012 IPv4->StaticIpAddress = FALSE;
2015 StrToIpv4Address (LocalIPStr, NULL, &IPv4->LocalIpAddress, NULL);
2016 if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*SubnetMaskStr)) {
2017 StrToIpv4Address (GatewayIPStr, NULL, &IPv4->GatewayIpAddress, NULL);
2018 StrToIpv4Address (SubnetMaskStr, NULL, &IPv4->SubnetMask, NULL);
2020 ZeroMem (&IPv4->GatewayIpAddress, sizeof (IPv4->GatewayIpAddress));
2021 ZeroMem (&IPv4->SubnetMask, sizeof (IPv4->SubnetMask));
2024 IPv4->LocalPort = 0;
2025 IPv4->RemotePort = 0;
2027 return (EFI_DEVICE_PATH_PROTOCOL *)IPv4;
2031 Converts a text device path node to IPV6 device path structure.
2033 @param TextDeviceNode The input Text device path node.
2035 @return A pointer to the newly-created IPV6 device path structure.
2039 EFI_DEVICE_PATH_PROTOCOL *
2040 DevPathFromTextIPv6 (
2041 IN CHAR16 *TextDeviceNode
2044 CHAR16 *RemoteIPStr;
2045 CHAR16 *ProtocolStr;
2048 CHAR16 *GatewayIPStr;
2049 CHAR16 *PrefixLengthStr;
2050 IPv6_DEVICE_PATH *IPv6;
2052 RemoteIPStr = GetNextParamStr (&TextDeviceNode);
2053 ProtocolStr = GetNextParamStr (&TextDeviceNode);
2054 TypeStr = GetNextParamStr (&TextDeviceNode);
2055 LocalIPStr = GetNextParamStr (&TextDeviceNode);
2056 PrefixLengthStr = GetNextParamStr (&TextDeviceNode);
2057 GatewayIPStr = GetNextParamStr (&TextDeviceNode);
2058 IPv6 = (IPv6_DEVICE_PATH *)CreateDeviceNode (
2059 MESSAGING_DEVICE_PATH,
2061 (UINT16)sizeof (IPv6_DEVICE_PATH)
2064 StrToIpv6Address (RemoteIPStr, NULL, &IPv6->RemoteIpAddress, NULL);
2065 IPv6->Protocol = (UINT16)NetworkProtocolFromText (ProtocolStr);
2066 if (StrCmp (TypeStr, "Static") == 0) {
2067 IPv6->IpAddressOrigin = 0;
2068 } else if (StrCmp (TypeStr, "StatelessAutoConfigure") == 0) {
2069 IPv6->IpAddressOrigin = 1;
2071 IPv6->IpAddressOrigin = 2;
2074 StrToIpv6Address (LocalIPStr, NULL, &IPv6->LocalIpAddress, NULL);
2075 if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*PrefixLengthStr)) {
2076 StrToIpv6Address (GatewayIPStr, NULL, &IPv6->GatewayIpAddress, NULL);
2077 IPv6->PrefixLength = (UINT8)Strtoi (PrefixLengthStr);
2079 ZeroMem (&IPv6->GatewayIpAddress, sizeof (IPv6->GatewayIpAddress));
2080 IPv6->PrefixLength = 0;
2083 IPv6->LocalPort = 0;
2084 IPv6->RemotePort = 0;
2086 return (EFI_DEVICE_PATH_PROTOCOL *)IPv6;
2090 Converts a text device path node to UART device path structure.
2092 @param TextDeviceNode The input Text device path node.
2094 @return A pointer to the newly-created UART device path structure.
2098 EFI_DEVICE_PATH_PROTOCOL *
2099 DevPathFromTextUart (
2100 IN CHAR16 *TextDeviceNode
2104 CHAR16 *DataBitsStr;
2106 CHAR16 *StopBitsStr;
2107 UART_DEVICE_PATH *Uart;
2109 BaudStr = GetNextParamStr (&TextDeviceNode);
2110 DataBitsStr = GetNextParamStr (&TextDeviceNode);
2111 ParityStr = GetNextParamStr (&TextDeviceNode);
2112 StopBitsStr = GetNextParamStr (&TextDeviceNode);
2113 Uart = (UART_DEVICE_PATH *)CreateDeviceNode (
2114 MESSAGING_DEVICE_PATH,
2116 (UINT16)sizeof (UART_DEVICE_PATH)
2119 if (StrCmp (BaudStr, "DEFAULT") == 0) {
2120 Uart->BaudRate = 115200;
2122 Strtoi64 (BaudStr, &Uart->BaudRate);
2125 Uart->DataBits = (UINT8)((StrCmp (DataBitsStr, "DEFAULT") == 0) ? 8 : Strtoi (DataBitsStr));
2126 switch (*ParityStr) {
2152 Uart->Parity = (UINT8)Strtoi (ParityStr);
2156 if (StrCmp (StopBitsStr, "D") == 0) {
2157 Uart->StopBits = (UINT8)0;
2158 } else if (StrCmp (StopBitsStr, "1") == 0) {
2159 Uart->StopBits = (UINT8)1;
2160 } else if (StrCmp (StopBitsStr, "1.5") == 0) {
2161 Uart->StopBits = (UINT8)2;
2162 } else if (StrCmp (StopBitsStr, "2") == 0) {
2163 Uart->StopBits = (UINT8)3;
2165 Uart->StopBits = (UINT8)Strtoi (StopBitsStr);
2168 return (EFI_DEVICE_PATH_PROTOCOL *)Uart;
2172 Converts a text device path node to USB class device path structure.
2174 @param TextDeviceNode The input Text device path node.
2175 @param UsbClassText A pointer to USB_CLASS_TEXT structure to be integrated to USB Class Text.
2177 @return A pointer to the newly-created USB class device path structure.
2181 EFI_DEVICE_PATH_PROTOCOL *
2182 ConvertFromTextUsbClass (
2183 IN CHAR16 *TextDeviceNode,
2184 IN USB_CLASS_TEXT *UsbClassText
2190 CHAR16 *SubClassStr;
2191 CHAR16 *ProtocolStr;
2192 USB_CLASS_DEVICE_PATH *UsbClass;
2194 UsbClass = (USB_CLASS_DEVICE_PATH *)CreateDeviceNode (
2195 MESSAGING_DEVICE_PATH,
2197 (UINT16)sizeof (USB_CLASS_DEVICE_PATH)
2200 VIDStr = GetNextParamStr (&TextDeviceNode);
2201 PIDStr = GetNextParamStr (&TextDeviceNode);
2202 if (UsbClassText->ClassExist) {
2203 ClassStr = GetNextParamStr (&TextDeviceNode);
2204 if (*ClassStr == '\0') {
2205 UsbClass->DeviceClass = 0xFF;
2207 UsbClass->DeviceClass = (UINT8)Strtoi (ClassStr);
2210 UsbClass->DeviceClass = UsbClassText->Class;
2213 if (UsbClassText->SubClassExist) {
2214 SubClassStr = GetNextParamStr (&TextDeviceNode);
2215 if (*SubClassStr == '\0') {
2216 UsbClass->DeviceSubClass = 0xFF;
2218 UsbClass->DeviceSubClass = (UINT8)Strtoi (SubClassStr);
2221 UsbClass->DeviceSubClass = UsbClassText->SubClass;
2224 ProtocolStr = GetNextParamStr (&TextDeviceNode);
2226 if (*VIDStr == '\0') {
2227 UsbClass->VendorId = 0xFFFF;
2229 UsbClass->VendorId = (UINT16)Strtoi (VIDStr);
2232 if (*PIDStr == '\0') {
2233 UsbClass->ProductId = 0xFFFF;
2235 UsbClass->ProductId = (UINT16)Strtoi (PIDStr);
2238 if (*ProtocolStr == '\0') {
2239 UsbClass->DeviceProtocol = 0xFF;
2241 UsbClass->DeviceProtocol = (UINT8)Strtoi (ProtocolStr);
2244 return (EFI_DEVICE_PATH_PROTOCOL *)UsbClass;
2248 Converts a text device path node to USB class device path structure.
2250 @param TextDeviceNode The input Text device path node.
2252 @return A pointer to the newly-created USB class device path structure.
2256 EFI_DEVICE_PATH_PROTOCOL *
2257 DevPathFromTextUsbClass (
2258 IN CHAR16 *TextDeviceNode
2261 USB_CLASS_TEXT UsbClassText;
2263 UsbClassText.ClassExist = TRUE;
2264 UsbClassText.SubClassExist = TRUE;
2266 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2270 Converts a text device path node to USB audio device path structure.
2272 @param TextDeviceNode The input Text device path node.
2274 @return A pointer to the newly-created USB audio device path structure.
2278 EFI_DEVICE_PATH_PROTOCOL *
2279 DevPathFromTextUsbAudio (
2280 IN CHAR16 *TextDeviceNode
2283 USB_CLASS_TEXT UsbClassText;
2285 UsbClassText.ClassExist = FALSE;
2286 UsbClassText.Class = USB_CLASS_AUDIO;
2287 UsbClassText.SubClassExist = TRUE;
2289 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2293 Converts a text device path node to USB CDC Control device path structure.
2295 @param TextDeviceNode The input Text device path node.
2297 @return A pointer to the newly-created USB CDC Control device path structure.
2301 EFI_DEVICE_PATH_PROTOCOL *
2302 DevPathFromTextUsbCDCControl (
2303 IN CHAR16 *TextDeviceNode
2306 USB_CLASS_TEXT UsbClassText;
2308 UsbClassText.ClassExist = FALSE;
2309 UsbClassText.Class = USB_CLASS_CDCCONTROL;
2310 UsbClassText.SubClassExist = TRUE;
2312 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2316 Converts a text device path node to USB HID device path structure.
2318 @param TextDeviceNode The input Text device path node.
2320 @return A pointer to the newly-created USB HID device path structure.
2324 EFI_DEVICE_PATH_PROTOCOL *
2325 DevPathFromTextUsbHID (
2326 IN CHAR16 *TextDeviceNode
2329 USB_CLASS_TEXT UsbClassText;
2331 UsbClassText.ClassExist = FALSE;
2332 UsbClassText.Class = USB_CLASS_HID;
2333 UsbClassText.SubClassExist = TRUE;
2335 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2339 Converts a text device path node to USB Image device path structure.
2341 @param TextDeviceNode The input Text device path node.
2343 @return A pointer to the newly-created USB Image device path structure.
2347 EFI_DEVICE_PATH_PROTOCOL *
2348 DevPathFromTextUsbImage (
2349 IN CHAR16 *TextDeviceNode
2352 USB_CLASS_TEXT UsbClassText;
2354 UsbClassText.ClassExist = FALSE;
2355 UsbClassText.Class = USB_CLASS_IMAGE;
2356 UsbClassText.SubClassExist = TRUE;
2358 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2362 Converts a text device path node to USB Print device path structure.
2364 @param TextDeviceNode The input Text device path node.
2366 @return A pointer to the newly-created USB Print device path structure.
2370 EFI_DEVICE_PATH_PROTOCOL *
2371 DevPathFromTextUsbPrinter (
2372 IN CHAR16 *TextDeviceNode
2375 USB_CLASS_TEXT UsbClassText;
2377 UsbClassText.ClassExist = FALSE;
2378 UsbClassText.Class = USB_CLASS_PRINTER;
2379 UsbClassText.SubClassExist = TRUE;
2381 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2385 Converts a text device path node to USB mass storage device path structure.
2387 @param TextDeviceNode The input Text device path node.
2389 @return A pointer to the newly-created USB mass storage device path structure.
2393 EFI_DEVICE_PATH_PROTOCOL *
2394 DevPathFromTextUsbMassStorage (
2395 IN CHAR16 *TextDeviceNode
2398 USB_CLASS_TEXT UsbClassText;
2400 UsbClassText.ClassExist = FALSE;
2401 UsbClassText.Class = USB_CLASS_MASS_STORAGE;
2402 UsbClassText.SubClassExist = TRUE;
2404 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2408 Converts a text device path node to USB HUB device path structure.
2410 @param TextDeviceNode The input Text device path node.
2412 @return A pointer to the newly-created USB HUB device path structure.
2416 EFI_DEVICE_PATH_PROTOCOL *
2417 DevPathFromTextUsbHub (
2418 IN CHAR16 *TextDeviceNode
2421 USB_CLASS_TEXT UsbClassText;
2423 UsbClassText.ClassExist = FALSE;
2424 UsbClassText.Class = USB_CLASS_HUB;
2425 UsbClassText.SubClassExist = TRUE;
2427 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2431 Converts a text device path node to USB CDC data device path structure.
2433 @param TextDeviceNode The input Text device path node.
2435 @return A pointer to the newly-created USB CDC data device path structure.
2439 EFI_DEVICE_PATH_PROTOCOL *
2440 DevPathFromTextUsbCDCData (
2441 IN CHAR16 *TextDeviceNode
2444 USB_CLASS_TEXT UsbClassText;
2446 UsbClassText.ClassExist = FALSE;
2447 UsbClassText.Class = USB_CLASS_CDCDATA;
2448 UsbClassText.SubClassExist = TRUE;
2450 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2454 Converts a text device path node to USB smart card device path structure.
2456 @param TextDeviceNode The input Text device path node.
2458 @return A pointer to the newly-created USB smart card device path structure.
2462 EFI_DEVICE_PATH_PROTOCOL *
2463 DevPathFromTextUsbSmartCard (
2464 IN CHAR16 *TextDeviceNode
2467 USB_CLASS_TEXT UsbClassText;
2469 UsbClassText.ClassExist = FALSE;
2470 UsbClassText.Class = USB_CLASS_SMART_CARD;
2471 UsbClassText.SubClassExist = TRUE;
2473 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2477 Converts a text device path node to USB video device path structure.
2479 @param TextDeviceNode The input Text device path node.
2481 @return A pointer to the newly-created USB video device path structure.
2485 EFI_DEVICE_PATH_PROTOCOL *
2486 DevPathFromTextUsbVideo (
2487 IN CHAR16 *TextDeviceNode
2490 USB_CLASS_TEXT UsbClassText;
2492 UsbClassText.ClassExist = FALSE;
2493 UsbClassText.Class = USB_CLASS_VIDEO;
2494 UsbClassText.SubClassExist = TRUE;
2496 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2500 Converts a text device path node to USB diagnostic device path structure.
2502 @param TextDeviceNode The input Text device path node.
2504 @return A pointer to the newly-created USB diagnostic device path structure.
2508 EFI_DEVICE_PATH_PROTOCOL *
2509 DevPathFromTextUsbDiagnostic (
2510 IN CHAR16 *TextDeviceNode
2513 USB_CLASS_TEXT UsbClassText;
2515 UsbClassText.ClassExist = FALSE;
2516 UsbClassText.Class = USB_CLASS_DIAGNOSTIC;
2517 UsbClassText.SubClassExist = TRUE;
2519 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2523 Converts a text device path node to USB wireless device path structure.
2525 @param TextDeviceNode The input Text device path node.
2527 @return A pointer to the newly-created USB wireless device path structure.
2531 EFI_DEVICE_PATH_PROTOCOL *
2532 DevPathFromTextUsbWireless (
2533 IN CHAR16 *TextDeviceNode
2536 USB_CLASS_TEXT UsbClassText;
2538 UsbClassText.ClassExist = FALSE;
2539 UsbClassText.Class = USB_CLASS_WIRELESS;
2540 UsbClassText.SubClassExist = TRUE;
2542 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2546 Converts a text device path node to USB device firmware update device path structure.
2548 @param TextDeviceNode The input Text device path node.
2550 @return A pointer to the newly-created USB device firmware update device path structure.
2554 EFI_DEVICE_PATH_PROTOCOL *
2555 DevPathFromTextUsbDeviceFirmwareUpdate (
2556 IN CHAR16 *TextDeviceNode
2559 USB_CLASS_TEXT UsbClassText;
2561 UsbClassText.ClassExist = FALSE;
2562 UsbClassText.Class = USB_CLASS_RESERVE;
2563 UsbClassText.SubClassExist = FALSE;
2564 UsbClassText.SubClass = USB_SUBCLASS_FW_UPDATE;
2566 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2570 Converts a text device path node to USB IRDA bridge device path structure.
2572 @param TextDeviceNode The input Text device path node.
2574 @return A pointer to the newly-created USB IRDA bridge device path structure.
2578 EFI_DEVICE_PATH_PROTOCOL *
2579 DevPathFromTextUsbIrdaBridge (
2580 IN CHAR16 *TextDeviceNode
2583 USB_CLASS_TEXT UsbClassText;
2585 UsbClassText.ClassExist = FALSE;
2586 UsbClassText.Class = USB_CLASS_RESERVE;
2587 UsbClassText.SubClassExist = FALSE;
2588 UsbClassText.SubClass = USB_SUBCLASS_IRDA_BRIDGE;
2590 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2594 Converts a text device path node to USB text and measurement device path structure.
2596 @param TextDeviceNode The input Text device path node.
2598 @return A pointer to the newly-created USB text and measurement device path structure.
2602 EFI_DEVICE_PATH_PROTOCOL *
2603 DevPathFromTextUsbTestAndMeasurement (
2604 IN CHAR16 *TextDeviceNode
2607 USB_CLASS_TEXT UsbClassText;
2609 UsbClassText.ClassExist = FALSE;
2610 UsbClassText.Class = USB_CLASS_RESERVE;
2611 UsbClassText.SubClassExist = FALSE;
2612 UsbClassText.SubClass = USB_SUBCLASS_TEST;
2614 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2618 Converts a text device path node to USB WWID device path structure.
2620 @param TextDeviceNode The input Text device path node.
2622 @return A pointer to the newly-created USB WWID device path structure.
2626 EFI_DEVICE_PATH_PROTOCOL *
2627 DevPathFromTextUsbWwid (
2628 IN CHAR16 *TextDeviceNode
2633 CHAR16 *InterfaceNumStr;
2634 CHAR16 *SerialNumberStr;
2635 USB_WWID_DEVICE_PATH *UsbWwid;
2636 UINTN SerialNumberStrLen;
2638 VIDStr = GetNextParamStr (&TextDeviceNode);
2639 PIDStr = GetNextParamStr (&TextDeviceNode);
2640 InterfaceNumStr = GetNextParamStr (&TextDeviceNode);
2641 SerialNumberStr = GetNextParamStr (&TextDeviceNode);
2642 SerialNumberStrLen = StrLen (SerialNumberStr);
2643 if ((SerialNumberStrLen >= 2) &&
2644 (SerialNumberStr[0] == '\"') &&
2645 (SerialNumberStr[SerialNumberStrLen - 1] == '\"')
2648 SerialNumberStr[SerialNumberStrLen - 1] = '\0';
2650 SerialNumberStrLen -= 2;
2653 UsbWwid = (USB_WWID_DEVICE_PATH *)CreateDeviceNode (
2654 MESSAGING_DEVICE_PATH,
2656 (UINT16)(sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16))
2658 UsbWwid->VendorId = (UINT16)Strtoi (VIDStr);
2659 UsbWwid->ProductId = (UINT16)Strtoi (PIDStr);
2660 UsbWwid->InterfaceNumber = (UINT16)Strtoi (InterfaceNumStr);
2663 // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.
2664 // Therefore, the '\0' will not be copied.
2667 (UINT8 *)UsbWwid + sizeof (USB_WWID_DEVICE_PATH),
2669 SerialNumberStrLen * sizeof (CHAR16)
2672 return (EFI_DEVICE_PATH_PROTOCOL *)UsbWwid;
2676 Converts a text device path node to Logic Unit device path structure.
2678 @param TextDeviceNode The input Text device path node.
2680 @return A pointer to the newly-created Logic Unit device path structure.
2684 EFI_DEVICE_PATH_PROTOCOL *
2685 DevPathFromTextUnit (
2686 IN CHAR16 *TextDeviceNode
2690 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
2692 LunStr = GetNextParamStr (&TextDeviceNode);
2693 LogicalUnit = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *)CreateDeviceNode (
2694 MESSAGING_DEVICE_PATH,
2695 MSG_DEVICE_LOGICAL_UNIT_DP,
2696 (UINT16)sizeof (DEVICE_LOGICAL_UNIT_DEVICE_PATH)
2699 LogicalUnit->Lun = (UINT8)Strtoi (LunStr);
2701 return (EFI_DEVICE_PATH_PROTOCOL *)LogicalUnit;
2705 Converts a text device path node to iSCSI device path structure.
2707 @param TextDeviceNode The input Text device path node.
2709 @return A pointer to the newly-created iSCSI device path structure.
2713 EFI_DEVICE_PATH_PROTOCOL *
2714 DevPathFromTextiSCSI (
2715 IN CHAR16 *TextDeviceNode
2720 CHAR16 *PortalGroupStr;
2722 CHAR16 *HeaderDigestStr;
2723 CHAR16 *DataDigestStr;
2724 CHAR16 *AuthenticationStr;
2725 CHAR16 *ProtocolStr;
2727 ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;
2730 NameStr = GetNextParamStr (&TextDeviceNode);
2731 PortalGroupStr = GetNextParamStr (&TextDeviceNode);
2732 LunStr = GetNextParamStr (&TextDeviceNode);
2733 HeaderDigestStr = GetNextParamStr (&TextDeviceNode);
2734 DataDigestStr = GetNextParamStr (&TextDeviceNode);
2735 AuthenticationStr = GetNextParamStr (&TextDeviceNode);
2736 ProtocolStr = GetNextParamStr (&TextDeviceNode);
2737 ISCSIDevPath = (ISCSI_DEVICE_PATH_WITH_NAME *)CreateDeviceNode (
2738 MESSAGING_DEVICE_PATH,
2740 (UINT16)(sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + StrLen (NameStr))
2743 AsciiStr = ISCSIDevPath->TargetName;
2744 StrToAscii (NameStr, &AsciiStr);
2746 ISCSIDevPath->TargetPortalGroupTag = (UINT16)Strtoi (PortalGroupStr);
2747 Strtoi64 (LunStr, &Lun);
2748 WriteUnaligned64 ((UINT64 *)&ISCSIDevPath->Lun, SwapBytes64 (Lun));
2751 if (StrCmp (HeaderDigestStr, "CRC32C") == 0) {
2755 if (StrCmp (DataDigestStr, "CRC32C") == 0) {
2759 if (StrCmp (AuthenticationStr, "None") == 0) {
2763 if (StrCmp (AuthenticationStr, "CHAP_UNI") == 0) {
2767 ISCSIDevPath->LoginOption = (UINT16)Options;
2769 if (IS_NULL (*ProtocolStr) || (StrCmp (ProtocolStr, "TCP") == 0)) {
2770 ISCSIDevPath->NetworkProtocol = 0;
2773 // Undefined and reserved.
2775 ISCSIDevPath->NetworkProtocol = 1;
2778 return (EFI_DEVICE_PATH_PROTOCOL *)ISCSIDevPath;
2782 Converts a text device path node to VLAN device path structure.
2784 @param TextDeviceNode The input Text device path node.
2786 @return A pointer to the newly-created VLAN device path structure.
2790 EFI_DEVICE_PATH_PROTOCOL *
2791 DevPathFromTextVlan (
2792 IN CHAR16 *TextDeviceNode
2796 VLAN_DEVICE_PATH *Vlan;
2798 VlanStr = GetNextParamStr (&TextDeviceNode);
2799 Vlan = (VLAN_DEVICE_PATH *)CreateDeviceNode (
2800 MESSAGING_DEVICE_PATH,
2802 (UINT16)sizeof (VLAN_DEVICE_PATH)
2805 Vlan->VlanId = (UINT16)Strtoi (VlanStr);
2807 return (EFI_DEVICE_PATH_PROTOCOL *)Vlan;
2811 Converts a text device path node to Bluetooth device path structure.
2813 @param TextDeviceNode The input Text device path node.
2815 @return A pointer to the newly-created Bluetooth device path structure.
2819 EFI_DEVICE_PATH_PROTOCOL *
2820 DevPathFromTextBluetooth (
2821 IN CHAR16 *TextDeviceNode
2824 CHAR16 *BluetoothStr;
2825 BLUETOOTH_DEVICE_PATH *BluetoothDp;
2827 BluetoothStr = GetNextParamStr (&TextDeviceNode);
2828 BluetoothDp = (BLUETOOTH_DEVICE_PATH *)CreateDeviceNode (
2829 MESSAGING_DEVICE_PATH,
2831 (UINT16)sizeof (BLUETOOTH_DEVICE_PATH)
2835 sizeof (BLUETOOTH_ADDRESS) * 2,
2836 BluetoothDp->BD_ADDR.Address,
2837 sizeof (BLUETOOTH_ADDRESS)
2839 return (EFI_DEVICE_PATH_PROTOCOL *)BluetoothDp;
2843 Converts a text device path node to Wi-Fi device path structure.
2845 @param TextDeviceNode The input Text device path node.
2847 @return A pointer to the newly-created Wi-Fi device path structure.
2851 EFI_DEVICE_PATH_PROTOCOL *
2852 DevPathFromTextWiFi (
2853 IN CHAR16 *TextDeviceNode
2859 WIFI_DEVICE_PATH *WiFiDp;
2861 SSIdStr = GetNextParamStr (&TextDeviceNode);
2862 WiFiDp = (WIFI_DEVICE_PATH *)CreateDeviceNode (
2863 MESSAGING_DEVICE_PATH,
2865 (UINT16)sizeof (WIFI_DEVICE_PATH)
2868 if (NULL != SSIdStr) {
2869 DataLen = StrLen (SSIdStr);
2870 if (StrLen (SSIdStr) > 32) {
2875 UnicodeStrToAsciiStrS (SSIdStr, AsciiStr, sizeof (AsciiStr));
2876 CopyMem (WiFiDp->SSId, AsciiStr, DataLen);
2879 return (EFI_DEVICE_PATH_PROTOCOL *)WiFiDp;
2883 Converts a text device path node to Bluetooth LE device path structure.
2885 @param TextDeviceNode The input Text device path node.
2887 @return A pointer to the newly-created Bluetooth LE device path structure.
2891 EFI_DEVICE_PATH_PROTOCOL *
2892 DevPathFromTextBluetoothLE (
2893 IN CHAR16 *TextDeviceNode
2896 CHAR16 *BluetoothLeAddrStr;
2897 CHAR16 *BluetoothLeAddrTypeStr;
2898 BLUETOOTH_LE_DEVICE_PATH *BluetoothLeDp;
2900 BluetoothLeAddrStr = GetNextParamStr (&TextDeviceNode);
2901 BluetoothLeAddrTypeStr = GetNextParamStr (&TextDeviceNode);
2902 BluetoothLeDp = (BLUETOOTH_LE_DEVICE_PATH *)CreateDeviceNode (
2903 MESSAGING_DEVICE_PATH,
2904 MSG_BLUETOOTH_LE_DP,
2905 (UINT16)sizeof (BLUETOOTH_LE_DEVICE_PATH)
2908 BluetoothLeDp->Address.Type = (UINT8)Strtoi (BluetoothLeAddrTypeStr);
2911 sizeof (BluetoothLeDp->Address.Address) * 2,
2912 BluetoothLeDp->Address.Address,
2913 sizeof (BluetoothLeDp->Address.Address)
2915 return (EFI_DEVICE_PATH_PROTOCOL *)BluetoothLeDp;
2919 Converts a text device path node to DNS device path structure.
2921 @param TextDeviceNode The input Text device path node.
2923 @return A pointer to the newly-created DNS device path structure.
2927 EFI_DEVICE_PATH_PROTOCOL *
2928 DevPathFromTextDns (
2929 IN CHAR16 *TextDeviceNode
2932 CHAR16 *DeviceNodeStr;
2933 CHAR16 *DeviceNodeStrPtr;
2934 UINT32 DnsServerIpCount;
2935 UINT16 DnsDeviceNodeLength;
2936 DNS_DEVICE_PATH *DnsDeviceNode;
2937 UINT32 DnsServerIpIndex;
2938 CHAR16 *DnsServerIp;
2941 // Count the DNS server address number.
2943 DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
2944 if (DeviceNodeStr == NULL) {
2948 DeviceNodeStrPtr = DeviceNodeStr;
2950 DnsServerIpCount = 0;
2951 while (DeviceNodeStrPtr != NULL && *DeviceNodeStrPtr != '\0') {
2952 GetNextParamStr (&DeviceNodeStrPtr);
2956 FreePool (DeviceNodeStr);
2957 DeviceNodeStr = NULL;
2960 // One or more instances of the DNS server address in EFI_IP_ADDRESS,
2961 // otherwise, NULL will be returned.
2963 if (DnsServerIpCount == 0) {
2968 // Create the DNS DeviceNode.
2970 DnsDeviceNodeLength = (UINT16)(sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));
2971 DnsDeviceNode = (DNS_DEVICE_PATH *)CreateDeviceNode (
2972 MESSAGING_DEVICE_PATH,
2976 if (DnsDeviceNode == NULL) {
2981 // Confirm the DNS server address is IPv4 or IPv6 type.
2983 DeviceNodeStrPtr = TextDeviceNode;
2984 while (!IS_NULL (*DeviceNodeStrPtr)) {
2985 if (*DeviceNodeStrPtr == '.') {
2986 DnsDeviceNode->IsIPv6 = 0x00;
2990 if (*DeviceNodeStrPtr == ':') {
2991 DnsDeviceNode->IsIPv6 = 0x01;
2998 for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) {
2999 DnsServerIp = GetNextParamStr (&TextDeviceNode);
3000 if (DnsDeviceNode->IsIPv6 == 0x00) {
3001 StrToIpv4Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL);
3003 StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL);
3007 return (EFI_DEVICE_PATH_PROTOCOL *)DnsDeviceNode;
3011 Converts a text device path node to URI device path structure.
3013 @param TextDeviceNode The input Text device path node.
3015 @return A pointer to the newly-created URI device path structure.
3019 EFI_DEVICE_PATH_PROTOCOL *
3020 DevPathFromTextUri (
3021 IN CHAR16 *TextDeviceNode
3026 URI_DEVICE_PATH *Uri;
3028 UriStr = GetNextParamStr (&TextDeviceNode);
3029 UriLength = StrnLenS (UriStr, MAX_UINT16 - sizeof (URI_DEVICE_PATH));
3030 Uri = (URI_DEVICE_PATH *)CreateDeviceNode (
3031 MESSAGING_DEVICE_PATH,
3033 (UINT16)(sizeof (URI_DEVICE_PATH) + UriLength)
3036 while (UriLength-- != 0) {
3037 Uri->Uri[UriLength] = (CHAR8)UriStr[UriLength];
3040 return (EFI_DEVICE_PATH_PROTOCOL *)Uri;
3044 Converts a media text device path node to media device path structure.
3046 @param TextDeviceNode The input Text device path node.
3048 @return A pointer to media device path structure.
3052 EFI_DEVICE_PATH_PROTOCOL *
3053 DevPathFromTextMediaPath (
3054 IN CHAR16 *TextDeviceNode
3057 return DevPathFromTextGenericPath (MEDIA_DEVICE_PATH, TextDeviceNode);
3061 Converts a text device path node to HD device path structure.
3063 @param TextDeviceNode The input Text device path node.
3065 @return A pointer to the newly-created HD device path structure.
3069 EFI_DEVICE_PATH_PROTOCOL *
3071 IN CHAR16 *TextDeviceNode
3074 CHAR16 *PartitionStr;
3076 CHAR16 *SignatureStr;
3080 HARDDRIVE_DEVICE_PATH *Hd;
3082 PartitionStr = GetNextParamStr (&TextDeviceNode);
3083 TypeStr = GetNextParamStr (&TextDeviceNode);
3084 SignatureStr = GetNextParamStr (&TextDeviceNode);
3085 StartStr = GetNextParamStr (&TextDeviceNode);
3086 SizeStr = GetNextParamStr (&TextDeviceNode);
3087 Hd = (HARDDRIVE_DEVICE_PATH *)CreateDeviceNode (
3090 (UINT16)sizeof (HARDDRIVE_DEVICE_PATH)
3093 Hd->PartitionNumber = (UINT32)Strtoi (PartitionStr);
3095 ZeroMem (Hd->Signature, 16);
3096 Hd->MBRType = (UINT8)0;
3098 if (StrCmp (TypeStr, "MBR") == 0) {
3099 Hd->SignatureType = SIGNATURE_TYPE_MBR;
3102 Signature32 = (UINT32)Strtoi (SignatureStr);
3103 CopyMem (Hd->Signature, &Signature32, sizeof (UINT32));
3104 } else if (StrCmp (TypeStr, "GPT") == 0) {
3105 Hd->SignatureType = SIGNATURE_TYPE_GUID;
3108 StrToGuid (SignatureStr, (EFI_GUID *)Hd->Signature);
3110 Hd->SignatureType = (UINT8)Strtoi (TypeStr);
3113 Strtoi64 (StartStr, &Hd->PartitionStart);
3114 Strtoi64 (SizeStr, &Hd->PartitionSize);
3116 return (EFI_DEVICE_PATH_PROTOCOL *)Hd;
3120 Converts a text device path node to CDROM device path structure.
3122 @param TextDeviceNode The input Text device path node.
3124 @return A pointer to the newly-created CDROM device path structure.
3128 EFI_DEVICE_PATH_PROTOCOL *
3129 DevPathFromTextCDROM (
3130 IN CHAR16 *TextDeviceNode
3136 CDROM_DEVICE_PATH *CDROMDevPath;
3138 EntryStr = GetNextParamStr (&TextDeviceNode);
3139 StartStr = GetNextParamStr (&TextDeviceNode);
3140 SizeStr = GetNextParamStr (&TextDeviceNode);
3141 CDROMDevPath = (CDROM_DEVICE_PATH *)CreateDeviceNode (
3144 (UINT16)sizeof (CDROM_DEVICE_PATH)
3147 CDROMDevPath->BootEntry = (UINT32)Strtoi (EntryStr);
3148 Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
3149 Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
3151 return (EFI_DEVICE_PATH_PROTOCOL *)CDROMDevPath;
3155 Converts a text device path node to Vendor-defined media device path structure.
3157 @param TextDeviceNode The input Text device path node.
3159 @return A pointer to the newly-created Vendor-defined media device path structure.
3163 EFI_DEVICE_PATH_PROTOCOL *
3164 DevPathFromTextVenMedia (
3165 IN CHAR16 *TextDeviceNode
3168 return ConvertFromTextVendor (
3176 Converts a text device path node to File device path structure.
3178 @param TextDeviceNode The input Text device path node.
3180 @return A pointer to the newly-created File device path structure.
3184 EFI_DEVICE_PATH_PROTOCOL *
3185 DevPathFromTextFilePath (
3186 IN CHAR16 *TextDeviceNode
3189 FILEPATH_DEVICE_PATH *File;
3192 File = (FILEPATH_DEVICE_PATH *)CreateDeviceNode (
3195 (UINT16)(sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2)
3198 StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
3200 size_t len = (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2);
3202 File = (FILEPATH_DEVICE_PATH *)CreateDeviceNode (
3208 utf8_to_ucs2(TextDeviceNode, &v, &len);
3211 return (EFI_DEVICE_PATH_PROTOCOL *)File;
3215 Converts a text device path node to Media protocol device path structure.
3217 @param TextDeviceNode The input Text device path node.
3219 @return A pointer to the newly-created Media protocol device path structure.
3223 EFI_DEVICE_PATH_PROTOCOL *
3224 DevPathFromTextMedia (
3225 IN CHAR16 *TextDeviceNode
3229 MEDIA_PROTOCOL_DEVICE_PATH *Media;
3231 GuidStr = GetNextParamStr (&TextDeviceNode);
3232 Media = (MEDIA_PROTOCOL_DEVICE_PATH *)CreateDeviceNode (
3235 (UINT16)sizeof (MEDIA_PROTOCOL_DEVICE_PATH)
3238 StrToGuid (GuidStr, &Media->Protocol);
3240 return (EFI_DEVICE_PATH_PROTOCOL *)Media;
3244 Converts a text device path node to firmware volume device path structure.
3246 @param TextDeviceNode The input Text device path node.
3248 @return A pointer to the newly-created firmware volume device path structure.
3252 EFI_DEVICE_PATH_PROTOCOL *
3254 IN CHAR16 *TextDeviceNode
3258 MEDIA_FW_VOL_DEVICE_PATH *Fv;
3260 GuidStr = GetNextParamStr (&TextDeviceNode);
3261 Fv = (MEDIA_FW_VOL_DEVICE_PATH *)CreateDeviceNode (
3263 MEDIA_PIWG_FW_VOL_DP,
3264 (UINT16)sizeof (MEDIA_FW_VOL_DEVICE_PATH)
3267 StrToGuid (GuidStr, &Fv->FvName);
3269 return (EFI_DEVICE_PATH_PROTOCOL *)Fv;
3273 Converts a text device path node to firmware file device path structure.
3275 @param TextDeviceNode The input Text device path node.
3277 @return A pointer to the newly-created firmware file device path structure.
3281 EFI_DEVICE_PATH_PROTOCOL *
3282 DevPathFromTextFvFile (
3283 IN CHAR16 *TextDeviceNode
3287 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFile;
3289 GuidStr = GetNextParamStr (&TextDeviceNode);
3290 FvFile = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)CreateDeviceNode (
3292 MEDIA_PIWG_FW_FILE_DP,
3293 (UINT16)sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)
3296 StrToGuid (GuidStr, &FvFile->FvFileName);
3298 return (EFI_DEVICE_PATH_PROTOCOL *)FvFile;
3302 Converts a text device path node to text relative offset device path structure.
3304 @param TextDeviceNode The input Text device path node.
3306 @return A pointer to the newly-created Text device path structure.
3310 EFI_DEVICE_PATH_PROTOCOL *
3311 DevPathFromTextRelativeOffsetRange (
3312 IN CHAR16 *TextDeviceNode
3315 CHAR16 *StartingOffsetStr;
3316 CHAR16 *EndingOffsetStr;
3317 MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;
3319 StartingOffsetStr = GetNextParamStr (&TextDeviceNode);
3320 EndingOffsetStr = GetNextParamStr (&TextDeviceNode);
3321 Offset = (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *)CreateDeviceNode (
3323 MEDIA_RELATIVE_OFFSET_RANGE_DP,
3324 (UINT16)sizeof (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH)
3327 Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
3328 Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
3330 return (EFI_DEVICE_PATH_PROTOCOL *)Offset;
3334 Converts a text device path node to text ram disk device path structure.
3336 @param TextDeviceNode The input Text device path node.
3338 @return A pointer to the newly-created Text device path structure.
3342 EFI_DEVICE_PATH_PROTOCOL *
3343 DevPathFromTextRamDisk (
3344 IN CHAR16 *TextDeviceNode
3347 CHAR16 *StartingAddrStr;
3348 CHAR16 *EndingAddrStr;
3349 CHAR16 *TypeGuidStr;
3350 CHAR16 *InstanceStr;
3351 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3352 UINT64 StartingAddr;
3355 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3356 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3357 InstanceStr = GetNextParamStr (&TextDeviceNode);
3358 TypeGuidStr = GetNextParamStr (&TextDeviceNode);
3359 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *)CreateDeviceNode (
3362 (UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3365 Strtoi64 (StartingAddrStr, &StartingAddr);
3366 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
3367 Strtoi64 (EndingAddrStr, &EndingAddr);
3368 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
3369 RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
3370 StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);
3372 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
3376 Converts a text device path node to text virtual disk device path structure.
3378 @param TextDeviceNode The input Text device path node.
3380 @return A pointer to the newly-created Text device path structure.
3384 EFI_DEVICE_PATH_PROTOCOL *
3385 DevPathFromTextVirtualDisk (
3386 IN CHAR16 *TextDeviceNode
3389 CHAR16 *StartingAddrStr;
3390 CHAR16 *EndingAddrStr;
3391 CHAR16 *InstanceStr;
3392 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3393 UINT64 StartingAddr;
3396 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3397 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3398 InstanceStr = GetNextParamStr (&TextDeviceNode);
3400 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *)CreateDeviceNode (
3403 (UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3406 Strtoi64 (StartingAddrStr, &StartingAddr);
3407 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
3408 Strtoi64 (EndingAddrStr, &EndingAddr);
3409 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
3410 RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
3411 CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);
3413 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
3417 Converts a text device path node to text virtual cd device path structure.
3419 @param TextDeviceNode The input Text device path node.
3421 @return A pointer to the newly-created Text device path structure.
3425 EFI_DEVICE_PATH_PROTOCOL *
3426 DevPathFromTextVirtualCd (
3427 IN CHAR16 *TextDeviceNode
3430 CHAR16 *StartingAddrStr;
3431 CHAR16 *EndingAddrStr;
3432 CHAR16 *InstanceStr;
3433 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3434 UINT64 StartingAddr;
3437 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3438 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3439 InstanceStr = GetNextParamStr (&TextDeviceNode);
3441 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *)CreateDeviceNode (
3444 (UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3447 Strtoi64 (StartingAddrStr, &StartingAddr);
3448 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
3449 Strtoi64 (EndingAddrStr, &EndingAddr);
3450 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
3451 RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
3452 CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);
3454 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
3458 Converts a text device path node to text persistent virtual disk device path structure.
3460 @param TextDeviceNode The input Text device path node.
3462 @return A pointer to the newly-created Text device path structure.
3466 EFI_DEVICE_PATH_PROTOCOL *
3467 DevPathFromTextPersistentVirtualDisk (
3468 IN CHAR16 *TextDeviceNode
3471 CHAR16 *StartingAddrStr;
3472 CHAR16 *EndingAddrStr;
3473 CHAR16 *InstanceStr;
3474 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3475 UINT64 StartingAddr;
3478 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3479 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3480 InstanceStr = GetNextParamStr (&TextDeviceNode);
3482 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *)CreateDeviceNode (
3485 (UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3488 Strtoi64 (StartingAddrStr, &StartingAddr);
3489 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
3490 Strtoi64 (EndingAddrStr, &EndingAddr);
3491 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
3492 RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
3493 CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);
3495 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
3499 Converts a text device path node to text persistent virtual cd device path structure.
3501 @param TextDeviceNode The input Text device path node.
3503 @return A pointer to the newly-created Text device path structure.
3507 EFI_DEVICE_PATH_PROTOCOL *
3508 DevPathFromTextPersistentVirtualCd (
3509 IN CHAR16 *TextDeviceNode
3512 CHAR16 *StartingAddrStr;
3513 CHAR16 *EndingAddrStr;
3514 CHAR16 *InstanceStr;
3515 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3516 UINT64 StartingAddr;
3519 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3520 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3521 InstanceStr = GetNextParamStr (&TextDeviceNode);
3523 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *)CreateDeviceNode (
3526 (UINT16)sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3529 Strtoi64 (StartingAddrStr, &StartingAddr);
3530 WriteUnaligned64 ((UINT64 *)&(RamDisk->StartingAddr[0]), StartingAddr);
3531 Strtoi64 (EndingAddrStr, &EndingAddr);
3532 WriteUnaligned64 ((UINT64 *)&(RamDisk->EndingAddr[0]), EndingAddr);
3533 RamDisk->Instance = (UINT16)Strtoi (InstanceStr);
3534 CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);
3536 return (EFI_DEVICE_PATH_PROTOCOL *)RamDisk;
3540 Converts a BBS text device path node to BBS device path structure.
3542 @param TextDeviceNode The input Text device path node.
3544 @return A pointer to BBS device path structure.
3548 EFI_DEVICE_PATH_PROTOCOL *
3549 DevPathFromTextBbsPath (
3550 IN CHAR16 *TextDeviceNode
3553 return DevPathFromTextGenericPath (BBS_DEVICE_PATH, TextDeviceNode);
3557 Converts a text device path node to BIOS Boot Specification device path structure.
3559 @param TextDeviceNode The input Text device path node.
3561 @return A pointer to the newly-created BIOS Boot Specification device path structure.
3565 EFI_DEVICE_PATH_PROTOCOL *
3566 DevPathFromTextBBS (
3567 IN CHAR16 *TextDeviceNode
3574 BBS_BBS_DEVICE_PATH *Bbs;
3576 TypeStr = GetNextParamStr (&TextDeviceNode);
3577 IdStr = GetNextParamStr (&TextDeviceNode);
3578 FlagsStr = GetNextParamStr (&TextDeviceNode);
3579 Bbs = (BBS_BBS_DEVICE_PATH *)CreateDeviceNode (
3582 (UINT16)(sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr))
3585 if (StrCmp (TypeStr, "Floppy") == 0) {
3586 Bbs->DeviceType = BBS_TYPE_FLOPPY;
3587 } else if (StrCmp (TypeStr, "HD") == 0) {
3588 Bbs->DeviceType = BBS_TYPE_HARDDRIVE;
3589 } else if (StrCmp (TypeStr, "CDROM") == 0) {
3590 Bbs->DeviceType = BBS_TYPE_CDROM;
3591 } else if (StrCmp (TypeStr, "PCMCIA") == 0) {
3592 Bbs->DeviceType = BBS_TYPE_PCMCIA;
3593 } else if (StrCmp (TypeStr, "USB") == 0) {
3594 Bbs->DeviceType = BBS_TYPE_USB;
3595 } else if (StrCmp (TypeStr, "Network") == 0) {
3596 Bbs->DeviceType = BBS_TYPE_EMBEDDED_NETWORK;
3598 Bbs->DeviceType = (UINT16)Strtoi (TypeStr);
3601 AsciiStr = Bbs->String;
3602 StrToAscii (IdStr, &AsciiStr);
3604 Bbs->StatusFlag = (UINT16)Strtoi (FlagsStr);
3606 return (EFI_DEVICE_PATH_PROTOCOL *)Bbs;
3610 Converts a text device path node to SATA device path structure.
3612 @param TextDeviceNode The input Text device path node.
3614 @return A pointer to the newly-created SATA device path structure.
3618 EFI_DEVICE_PATH_PROTOCOL *
3619 DevPathFromTextSata (
3620 IN CHAR16 *TextDeviceNode
3623 SATA_DEVICE_PATH *Sata;
3628 Param1 = GetNextParamStr (&TextDeviceNode);
3629 Param2 = GetNextParamStr (&TextDeviceNode);
3630 Param3 = GetNextParamStr (&TextDeviceNode);
3632 Sata = (SATA_DEVICE_PATH *)CreateDeviceNode (
3633 MESSAGING_DEVICE_PATH,
3635 (UINT16)sizeof (SATA_DEVICE_PATH)
3637 Sata->HBAPortNumber = (UINT16)Strtoi (Param1);
3640 // According to UEFI spec, if PMPN is not provided, the default is 0xFFFF
3642 if (*Param2 == '\0' ) {
3643 Sata->PortMultiplierPortNumber = 0xFFFF;
3645 Sata->PortMultiplierPortNumber = (UINT16)Strtoi (Param2);
3648 Sata->Lun = (UINT16)Strtoi (Param3);
3650 return (EFI_DEVICE_PATH_PROTOCOL *)Sata;
3653 GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
3654 { "Path", DevPathFromTextPath },
3656 { "HardwarePath", DevPathFromTextHardwarePath },
3657 { "Pci", DevPathFromTextPci },
3658 { "PcCard", DevPathFromTextPcCard },
3659 { "MemoryMapped", DevPathFromTextMemoryMapped },
3660 { "VenHw", DevPathFromTextVenHw },
3661 { "Ctrl", DevPathFromTextCtrl },
3662 { "BMC", DevPathFromTextBmc },
3664 { "AcpiPath", DevPathFromTextAcpiPath },
3665 { "Acpi", DevPathFromTextAcpi },
3666 { "PciRoot", DevPathFromTextPciRoot },
3667 { "PcieRoot", DevPathFromTextPcieRoot },
3668 { "Floppy", DevPathFromTextFloppy },
3669 { "Keyboard", DevPathFromTextKeyboard },
3670 { "Serial", DevPathFromTextSerial },
3671 { "ParallelPort", DevPathFromTextParallelPort },
3672 { "AcpiEx", DevPathFromTextAcpiEx },
3673 { "AcpiExp", DevPathFromTextAcpiExp },
3674 { "AcpiAdr", DevPathFromTextAcpiAdr },
3676 { "Msg", DevPathFromTextMsg },
3677 { "Ata", DevPathFromTextAta },
3678 { "Scsi", DevPathFromTextScsi },
3679 { "Fibre", DevPathFromTextFibre },
3680 { "FibreEx", DevPathFromTextFibreEx },
3681 { "I1394", DevPathFromText1394 },
3682 { "USB", DevPathFromTextUsb },
3683 { "I2O", DevPathFromTextI2O },
3684 { "Infiniband", DevPathFromTextInfiniband },
3685 { "VenMsg", DevPathFromTextVenMsg },
3686 { "VenPcAnsi", DevPathFromTextVenPcAnsi },
3687 { "VenVt100", DevPathFromTextVenVt100 },
3688 { "VenVt100Plus", DevPathFromTextVenVt100Plus },
3689 { "VenUtf8", DevPathFromTextVenUtf8 },
3690 { "UartFlowCtrl", DevPathFromTextUartFlowCtrl },
3691 { "SAS", DevPathFromTextSAS },
3692 { "SasEx", DevPathFromTextSasEx },
3693 { "NVMe", DevPathFromTextNVMe },
3694 { "UFS", DevPathFromTextUfs },
3695 { "SD", DevPathFromTextSd },
3696 { "eMMC", DevPathFromTextEmmc },
3697 { "DebugPort", DevPathFromTextDebugPort },
3698 { "MAC", DevPathFromTextMAC },
3699 { "IPv4", DevPathFromTextIPv4 },
3700 { "IPv6", DevPathFromTextIPv6 },
3701 { "Uart", DevPathFromTextUart },
3702 { "UsbClass", DevPathFromTextUsbClass },
3703 { "UsbAudio", DevPathFromTextUsbAudio },
3704 { "UsbCDCControl", DevPathFromTextUsbCDCControl },
3705 { "UsbHID", DevPathFromTextUsbHID },
3706 { "UsbImage", DevPathFromTextUsbImage },
3707 { "UsbPrinter", DevPathFromTextUsbPrinter },
3708 { "UsbMassStorage", DevPathFromTextUsbMassStorage },
3709 { "UsbHub", DevPathFromTextUsbHub },
3710 { "UsbCDCData", DevPathFromTextUsbCDCData },
3711 { "UsbSmartCard", DevPathFromTextUsbSmartCard },
3712 { "UsbVideo", DevPathFromTextUsbVideo },
3713 { "UsbDiagnostic", DevPathFromTextUsbDiagnostic },
3714 { "UsbWireless", DevPathFromTextUsbWireless },
3715 { "UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate },
3716 { "UsbIrdaBridge", DevPathFromTextUsbIrdaBridge },
3717 { "UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement },
3718 { "UsbWwid", DevPathFromTextUsbWwid },
3719 { "Unit", DevPathFromTextUnit },
3720 { "iSCSI", DevPathFromTextiSCSI },
3721 { "Vlan", DevPathFromTextVlan },
3722 { "Dns", DevPathFromTextDns },
3723 { "Uri", DevPathFromTextUri },
3724 { "Bluetooth", DevPathFromTextBluetooth },
3725 { "Wi-Fi", DevPathFromTextWiFi },
3726 { "BluetoothLE", DevPathFromTextBluetoothLE },
3727 { "MediaPath", DevPathFromTextMediaPath },
3728 { "HD", DevPathFromTextHD },
3729 { "CDROM", DevPathFromTextCDROM },
3730 { "VenMedia", DevPathFromTextVenMedia },
3731 { "Media", DevPathFromTextMedia },
3732 { "Fv", DevPathFromTextFv },
3733 { "FvFile", DevPathFromTextFvFile },
3734 { "File", DevPathFromTextFilePath },
3735 { "Offset", DevPathFromTextRelativeOffsetRange },
3736 { "RamDisk", DevPathFromTextRamDisk },
3737 { "VirtualDisk", DevPathFromTextVirtualDisk },
3738 { "VirtualCD", DevPathFromTextVirtualCd },
3739 { "PersistentVirtualDisk", DevPathFromTextPersistentVirtualDisk },
3740 { "PersistentVirtualCD", DevPathFromTextPersistentVirtualCd },
3742 { "BbsPath", DevPathFromTextBbsPath },
3743 { "BBS", DevPathFromTextBBS },
3744 { "Sata", DevPathFromTextSata },
3749 Convert text to the binary representation of a device node.
3751 @param TextDeviceNode TextDeviceNode points to the text representation of a device
3752 node. Conversion starts with the first character and continues
3753 until the first non-device node character.
3755 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
3756 insufficient memory or text unsupported.
3760 EFI_DEVICE_PATH_PROTOCOL *
3762 UefiDevicePathLibConvertTextToDeviceNode (
3763 IN CONST CHAR16 *TextDeviceNode
3766 DEVICE_PATH_FROM_TEXT FromText;
3768 EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
3769 CHAR16 *DeviceNodeStr;
3772 if ((TextDeviceNode == NULL) || (IS_NULL (*TextDeviceNode))) {
3778 DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
3779 ASSERT (DeviceNodeStr != NULL);
3781 for (Index = 0; mUefiDevicePathLibDevPathFromTextTable[Index].Function != NULL; Index++) {
3782 ParamStr = GetParamByNodeName (DeviceNodeStr, mUefiDevicePathLibDevPathFromTextTable[Index].DevicePathNodeText);
3783 if (ParamStr != NULL) {
3784 FromText = mUefiDevicePathLibDevPathFromTextTable[Index].Function;
3789 if (FromText == NULL) {
3793 FromText = DevPathFromTextFilePath;
3794 DeviceNode = FromText (DeviceNodeStr);
3796 DeviceNode = FromText (ParamStr);
3797 FreePool (ParamStr);
3800 FreePool (DeviceNodeStr);
3806 Convert text to the binary representation of a device path.
3809 @param TextDevicePath TextDevicePath points to the text representation of a device
3810 path. Conversion starts with the first character and continues
3811 until the first non-device node character.
3813 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
3814 there was insufficient memory.
3818 EFI_DEVICE_PATH_PROTOCOL *
3820 UefiDevicePathLibConvertTextToDevicePath (
3821 IN CONST CHAR16 *TextDevicePath
3824 EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
3825 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
3826 CHAR16 *DevicePathStr;
3828 CHAR16 *DeviceNodeStr;
3829 BOOLEAN IsInstanceEnd;
3830 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
3832 if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
3836 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (END_DEVICE_PATH_LENGTH);
3837 ASSERT (DevicePath != NULL);
3838 SetDevicePathEndNode (DevicePath);
3840 DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
3842 Str = DevicePathStr;
3843 while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
3844 DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);
3846 NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3847 FreePool (DevicePath);
3848 FreePool (DeviceNode);
3849 DevicePath = NewDevicePath;
3851 if (IsInstanceEnd) {
3852 DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *)AllocatePool (END_DEVICE_PATH_LENGTH);
3853 ASSERT (DeviceNode != NULL);
3854 SetDevicePathEndNode (DeviceNode);
3855 DeviceNode->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
3857 NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3858 FreePool (DevicePath);
3859 FreePool (DeviceNode);
3860 DevicePath = NewDevicePath;
3864 FreePool (DevicePathStr);
3869 efidp_parse_device_path(char *path, efidp out, size_t max)
3871 EFI_DEVICE_PATH_PROTOCOL *dp;
3874 dp = UefiDevicePathLibConvertTextToDevicePath (path);
3877 len = GetDevicePathSize(dp);
3882 memcpy(out, dp, len);