1 /** @file
2   DevicePathFromText protocol as defined in the UEFI 2.0 specification.
3 
4 Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #include "UefiDevicePathLib.h"
16 
17 /**
18 
19   Duplicates a string.
20 
21   @param  Src  Source string.
22 
23   @return The duplicated string.
24 
25 **/
26 CHAR16 *
UefiDevicePathLibStrDuplicate(IN CONST CHAR16 * Src)27 UefiDevicePathLibStrDuplicate (
28   IN CONST CHAR16  *Src
29   )
30 {
31   return AllocateCopyPool (StrSize (Src), Src);
32 }
33 
34 /**
35 
36   Get parameter in a pair of parentheses follow the given node name.
37   For example, given the "Pci(0,1)" and NodeName "Pci", it returns "0,1".
38 
39   @param  Str      Device Path Text.
40   @param  NodeName Name of the node.
41 
42   @return Parameter text for the node.
43 
44 **/
45 CHAR16 *
GetParamByNodeName(IN CHAR16 * Str,IN CHAR16 * NodeName)46 GetParamByNodeName (
47   IN CHAR16 *Str,
48   IN CHAR16 *NodeName
49   )
50 {
51   CHAR16  *ParamStr;
52   CHAR16  *StrPointer;
53   UINTN   NodeNameLength;
54   UINTN   ParameterLength;
55 
56   //
57   // Check whether the node name matchs
58   //
59   NodeNameLength = StrLen (NodeName);
60   if (StrnCmp (Str, NodeName, NodeNameLength) != 0) {
61     return NULL;
62   }
63 
64   ParamStr = Str + NodeNameLength;
65   if (!IS_LEFT_PARENTH (*ParamStr)) {
66     return NULL;
67   }
68 
69   //
70   // Skip the found '(' and find first occurrence of ')'
71   //
72   ParamStr++;
73   ParameterLength = 0;
74   StrPointer = ParamStr;
75   while (!IS_NULL (*StrPointer)) {
76     if (IS_RIGHT_PARENTH (*StrPointer)) {
77       break;
78     }
79     StrPointer++;
80     ParameterLength++;
81   }
82   if (IS_NULL (*StrPointer)) {
83     //
84     // ')' not found
85     //
86     return NULL;
87   }
88 
89   ParamStr = AllocateCopyPool ((ParameterLength + 1) * sizeof (CHAR16), ParamStr);
90   if (ParamStr == NULL) {
91     return NULL;
92   }
93   //
94   // Terminate the parameter string
95   //
96   ParamStr[ParameterLength] = L'\0';
97 
98   return ParamStr;
99 }
100 
101 /**
102   Gets current sub-string from a string list, before return
103   the list header is moved to next sub-string. The sub-string is separated
104   by the specified character. For example, the separator is ',', the string
105   list is "2,0,3", it returns "2", the remain list move to "0,3"
106 
107   @param  List        A string list separated by the specified separator
108   @param  Separator   The separator character
109 
110   @return A pointer to the current sub-string
111 
112 **/
113 CHAR16 *
SplitStr(IN OUT CHAR16 ** List,IN CHAR16 Separator)114 SplitStr (
115   IN OUT CHAR16 **List,
116   IN     CHAR16 Separator
117   )
118 {
119   CHAR16  *Str;
120   CHAR16  *ReturnStr;
121 
122   Str = *List;
123   ReturnStr = Str;
124 
125   if (IS_NULL (*Str)) {
126     return ReturnStr;
127   }
128 
129   //
130   // Find first occurrence of the separator
131   //
132   while (!IS_NULL (*Str)) {
133     if (*Str == Separator) {
134       break;
135     }
136     Str++;
137   }
138 
139   if (*Str == Separator) {
140     //
141     // Find a sub-string, terminate it
142     //
143     *Str = L'\0';
144     Str++;
145   }
146 
147   //
148   // Move to next sub-string
149   //
150   *List = Str;
151 
152   return ReturnStr;
153 }
154 
155 /**
156   Gets the next parameter string from the list.
157 
158   @param List            A string list separated by the specified separator
159 
160   @return A pointer to the current sub-string
161 
162 **/
163 CHAR16 *
GetNextParamStr(IN OUT CHAR16 ** List)164 GetNextParamStr (
165   IN OUT CHAR16 **List
166   )
167 {
168   //
169   // The separator is comma
170   //
171   return SplitStr (List, L',');
172 }
173 
174 /**
175   Get one device node from entire device path text.
176 
177   @param DevicePath      On input, the current Device Path node; on output, the next device path node
178   @param IsInstanceEnd   This node is the end of a device path instance
179 
180   @return A device node text or NULL if no more device node available
181 
182 **/
183 CHAR16 *
GetNextDeviceNodeStr(IN OUT CHAR16 ** DevicePath,OUT BOOLEAN * IsInstanceEnd)184 GetNextDeviceNodeStr (
185   IN OUT CHAR16   **DevicePath,
186   OUT    BOOLEAN  *IsInstanceEnd
187   )
188 {
189   CHAR16  *Str;
190   CHAR16  *ReturnStr;
191   UINTN   ParenthesesStack;
192 
193   Str = *DevicePath;
194   if (IS_NULL (*Str)) {
195     return NULL;
196   }
197 
198   //
199   // Skip the leading '/', '(', ')' and ','
200   //
201   while (!IS_NULL (*Str)) {
202     if (!IS_SLASH (*Str) &&
203         !IS_COMMA (*Str) &&
204         !IS_LEFT_PARENTH (*Str) &&
205         !IS_RIGHT_PARENTH (*Str)) {
206       break;
207     }
208     Str++;
209   }
210 
211   ReturnStr = Str;
212 
213   //
214   // Scan for the separator of this device node, '/' or ','
215   //
216   ParenthesesStack = 0;
217   while (!IS_NULL (*Str)) {
218     if ((IS_COMMA (*Str) || IS_SLASH (*Str)) && (ParenthesesStack == 0)) {
219       break;
220     }
221 
222     if (IS_LEFT_PARENTH (*Str)) {
223       ParenthesesStack++;
224     } else if (IS_RIGHT_PARENTH (*Str)) {
225       ParenthesesStack--;
226     }
227 
228     Str++;
229   }
230 
231   if (ParenthesesStack != 0) {
232     //
233     // The '(' doesn't pair with ')', invalid device path text
234     //
235     return NULL;
236   }
237 
238   if (IS_COMMA (*Str)) {
239     *IsInstanceEnd = TRUE;
240     *Str = L'\0';
241     Str++;
242   } else {
243     *IsInstanceEnd = FALSE;
244     if (!IS_NULL (*Str)) {
245       *Str = L'\0';
246       Str++;
247     }
248   }
249 
250   *DevicePath = Str;
251 
252   return ReturnStr;
253 }
254 
255 
256 /**
257   Return whether the integer string is a hex string.
258 
259   @param Str             The integer string
260 
261   @retval TRUE   Hex string
262   @retval FALSE  Decimal string
263 
264 **/
265 BOOLEAN
IsHexStr(IN CHAR16 * Str)266 IsHexStr (
267   IN CHAR16   *Str
268   )
269 {
270   //
271   // skip preceeding white space
272   //
273   while ((*Str != 0) && *Str == L' ') {
274     Str ++;
275   }
276   //
277   // skip preceeding zeros
278   //
279   while ((*Str != 0) && *Str == L'0') {
280     Str ++;
281   }
282 
283   return (BOOLEAN) (*Str == L'x' || *Str == L'X');
284 }
285 
286 /**
287 
288   Convert integer string to uint.
289 
290   @param Str             The integer string. If leading with "0x" or "0X", it's hexadecimal.
291 
292   @return A UINTN value represented by Str
293 
294 **/
295 UINTN
Strtoi(IN CHAR16 * Str)296 Strtoi (
297   IN CHAR16  *Str
298   )
299 {
300   if (IsHexStr (Str)) {
301     return StrHexToUintn (Str);
302   } else {
303     return StrDecimalToUintn (Str);
304   }
305 }
306 
307 /**
308 
309   Convert integer string to 64 bit data.
310 
311   @param Str             The integer string. If leading with "0x" or "0X", it's hexadecimal.
312   @param Data            A pointer to the UINT64 value represented by Str
313 
314 **/
315 VOID
Strtoi64(IN CHAR16 * Str,OUT UINT64 * Data)316 Strtoi64 (
317   IN  CHAR16  *Str,
318   OUT UINT64  *Data
319   )
320 {
321   if (IsHexStr (Str)) {
322     *Data = StrHexToUint64 (Str);
323   } else {
324     *Data = StrDecimalToUint64 (Str);
325   }
326 }
327 
328 /**
329   Converts a list of string to a specified buffer.
330 
331   @param Buf             The output buffer that contains the string.
332   @param BufferLength    The length of the buffer
333   @param Str             The input string that contains the hex number
334 
335   @retval EFI_SUCCESS    The string was successfully converted to the buffer.
336 
337 **/
338 EFI_STATUS
StrToBuf(OUT UINT8 * Buf,IN UINTN BufferLength,IN CHAR16 * Str)339 StrToBuf (
340   OUT UINT8    *Buf,
341   IN  UINTN    BufferLength,
342   IN  CHAR16   *Str
343   )
344 {
345   UINTN       Index;
346   UINTN       StrLength;
347   UINT8       Digit;
348   UINT8       Byte;
349 
350   Digit = 0;
351 
352   //
353   // Two hex char make up one byte
354   //
355   StrLength = BufferLength * sizeof (CHAR16);
356 
357   for(Index = 0; Index < StrLength; Index++, Str++) {
358 
359     if ((*Str >= L'a') && (*Str <= L'f')) {
360       Digit = (UINT8) (*Str - L'a' + 0x0A);
361     } else if ((*Str >= L'A') && (*Str <= L'F')) {
362       Digit = (UINT8) (*Str - L'A' + 0x0A);
363     } else if ((*Str >= L'0') && (*Str <= L'9')) {
364       Digit = (UINT8) (*Str - L'0');
365     } else {
366       return EFI_INVALID_PARAMETER;
367     }
368 
369     //
370     // For odd characters, write the upper nibble for each buffer byte,
371     // and for even characters, the lower nibble.
372     //
373     if ((Index & 1) == 0) {
374       Byte = (UINT8) (Digit << 4);
375     } else {
376       Byte = Buf[Index / 2];
377       Byte &= 0xF0;
378       Byte = (UINT8) (Byte | Digit);
379     }
380 
381     Buf[Index / 2] = Byte;
382   }
383 
384   return EFI_SUCCESS;
385 }
386 
387 /**
388   Converts a string to GUID value.
389   Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
390 
391   @param Str              The registry format GUID string that contains the GUID value.
392   @param Guid             A pointer to the converted GUID value.
393 
394   @retval EFI_SUCCESS     The GUID string was successfully converted to the GUID value.
395   @retval EFI_UNSUPPORTED The input string is not in registry format.
396   @return others          Some error occurred when converting part of GUID value.
397 
398 **/
399 EFI_STATUS
StrToGuid(IN CHAR16 * Str,OUT EFI_GUID * Guid)400 StrToGuid (
401   IN  CHAR16   *Str,
402   OUT EFI_GUID *Guid
403   )
404 {
405   //
406   // Get the first UINT32 data
407   //
408   Guid->Data1 = (UINT32) StrHexToUint64  (Str);
409   while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {
410     Str ++;
411   }
412 
413   if (IS_HYPHEN (*Str)) {
414     Str++;
415   } else {
416     return EFI_UNSUPPORTED;
417   }
418 
419   //
420   // Get the second UINT16 data
421   //
422   Guid->Data2 = (UINT16) StrHexToUint64  (Str);
423   while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {
424     Str ++;
425   }
426 
427   if (IS_HYPHEN (*Str)) {
428     Str++;
429   } else {
430     return EFI_UNSUPPORTED;
431   }
432 
433   //
434   // Get the third UINT16 data
435   //
436   Guid->Data3 = (UINT16) StrHexToUint64  (Str);
437   while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {
438     Str ++;
439   }
440 
441   if (IS_HYPHEN (*Str)) {
442     Str++;
443   } else {
444     return EFI_UNSUPPORTED;
445   }
446 
447   //
448   // Get the following 8 bytes data
449   //
450   StrToBuf (&Guid->Data4[0], 2, Str);
451   //
452   // Skip 2 byte hex chars
453   //
454   Str += 2 * 2;
455 
456   if (IS_HYPHEN (*Str)) {
457     Str++;
458   } else {
459     return EFI_UNSUPPORTED;
460   }
461   StrToBuf (&Guid->Data4[2], 6, Str);
462 
463   return EFI_SUCCESS;
464 }
465 
466 /**
467   Converts a string to IPv4 address
468 
469   @param Str             A string representation of IPv4 address.
470   @param IPv4Addr        A pointer to the converted IPv4 address.
471 
472 **/
473 VOID
StrToIPv4Addr(IN OUT CHAR16 ** Str,OUT EFI_IPv4_ADDRESS * IPv4Addr)474 StrToIPv4Addr (
475   IN OUT CHAR16           **Str,
476   OUT    EFI_IPv4_ADDRESS *IPv4Addr
477   )
478 {
479   UINTN  Index;
480 
481   for (Index = 0; Index < 4; Index++) {
482     IPv4Addr->Addr[Index] = (UINT8) Strtoi (SplitStr (Str, L'.'));
483   }
484 }
485 
486 /**
487   Converts a string to IPv4 address
488 
489   @param Str             A string representation of IPv6 address.
490   @param IPv6Addr        A pointer to the converted IPv6 address.
491 
492 **/
493 VOID
StrToIPv6Addr(IN OUT CHAR16 ** Str,OUT EFI_IPv6_ADDRESS * IPv6Addr)494 StrToIPv6Addr (
495   IN OUT CHAR16           **Str,
496   OUT    EFI_IPv6_ADDRESS *IPv6Addr
497   )
498 {
499   UINTN  Index;
500   UINT16 Data;
501 
502   for (Index = 0; Index < 8; Index++) {
503     Data = (UINT16) StrHexToUintn (SplitStr (Str, L':'));
504     IPv6Addr->Addr[Index * 2] = (UINT8) (Data >> 8);
505     IPv6Addr->Addr[Index * 2 + 1] = (UINT8) (Data & 0xff);
506   }
507 }
508 
509 /**
510   Converts a Unicode string to ASCII string.
511 
512   @param Str             The equivalent Unicode string
513   @param AsciiStr        On input, it points to destination ASCII string buffer; on output, it points
514                          to the next ASCII string next to it
515 
516 **/
517 VOID
StrToAscii(IN CHAR16 * Str,IN OUT CHAR8 ** AsciiStr)518 StrToAscii (
519   IN     CHAR16 *Str,
520   IN OUT CHAR8  **AsciiStr
521   )
522 {
523   CHAR8 *Dest;
524 
525   Dest = *AsciiStr;
526   while (!IS_NULL (*Str)) {
527     *(Dest++) = (CHAR8) *(Str++);
528   }
529   *Dest = 0;
530 
531   //
532   // Return the string next to it
533   //
534   *AsciiStr = Dest + 1;
535 }
536 
537 /**
538   Converts a generic text device path node to device path structure.
539 
540   @param Type            The type of the device path node.
541   @param TextDeviceNode  The input text device path node.
542 
543   @return A pointer to device path structure.
544 **/
545 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextGenericPath(IN UINT8 Type,IN CHAR16 * TextDeviceNode)546 DevPathFromTextGenericPath (
547   IN UINT8  Type,
548   IN CHAR16 *TextDeviceNode
549   )
550 {
551   EFI_DEVICE_PATH_PROTOCOL *Node;
552   CHAR16                   *SubtypeStr;
553   CHAR16                   *DataStr;
554   UINTN                    DataLength;
555 
556   SubtypeStr = GetNextParamStr (&TextDeviceNode);
557   DataStr    = GetNextParamStr (&TextDeviceNode);
558 
559   if (DataStr == NULL) {
560     DataLength = 0;
561   } else {
562     DataLength = StrLen (DataStr) / 2;
563   }
564   Node = CreateDeviceNode (
565            Type,
566            (UINT8) Strtoi (SubtypeStr),
567            (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + DataLength)
568            );
569 
570   if (DataLength != 0) {
571     StrToBuf ((UINT8 *) (Node + 1), DataLength, DataStr);
572   }
573   return Node;
574 }
575 
576 /**
577   Converts a generic text device path node to device path structure.
578 
579   @param TextDeviceNode  The input Text device path node.
580 
581   @return A pointer to device path structure.
582 
583 **/
584 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextPath(IN CHAR16 * TextDeviceNode)585 DevPathFromTextPath (
586   IN CHAR16 *TextDeviceNode
587   )
588 {
589   CHAR16                   *TypeStr;
590 
591   TypeStr    = GetNextParamStr (&TextDeviceNode);
592 
593   return DevPathFromTextGenericPath ((UINT8) Strtoi (TypeStr), TextDeviceNode);
594 }
595 
596 /**
597   Converts a generic hardware text device path node to Hardware device path structure.
598 
599   @param TextDeviceNode  The input Text device path node.
600 
601   @return A pointer to Hardware device path structure.
602 
603 **/
604 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextHardwarePath(IN CHAR16 * TextDeviceNode)605 DevPathFromTextHardwarePath (
606   IN CHAR16 *TextDeviceNode
607   )
608 {
609   return DevPathFromTextGenericPath (HARDWARE_DEVICE_PATH, TextDeviceNode);
610 }
611 
612 /**
613   Converts a text device path node to Hardware PCI device path structure.
614 
615   @param TextDeviceNode  The input Text device path node.
616 
617   @return A pointer to Hardware PCI device path structure.
618 
619 **/
620 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextPci(IN CHAR16 * TextDeviceNode)621 DevPathFromTextPci (
622   IN CHAR16 *TextDeviceNode
623   )
624 {
625   CHAR16          *FunctionStr;
626   CHAR16          *DeviceStr;
627   PCI_DEVICE_PATH *Pci;
628 
629   DeviceStr   = GetNextParamStr (&TextDeviceNode);
630   FunctionStr = GetNextParamStr (&TextDeviceNode);
631   Pci         = (PCI_DEVICE_PATH *) CreateDeviceNode (
632                                       HARDWARE_DEVICE_PATH,
633                                       HW_PCI_DP,
634                                       (UINT16) sizeof (PCI_DEVICE_PATH)
635                                       );
636 
637   Pci->Function = (UINT8) Strtoi (FunctionStr);
638   Pci->Device   = (UINT8) Strtoi (DeviceStr);
639 
640   return (EFI_DEVICE_PATH_PROTOCOL *) Pci;
641 }
642 
643 /**
644   Converts a text device path node to Hardware PC card device path structure.
645 
646   @param TextDeviceNode  The input Text device path node.
647 
648   @return A pointer to Hardware PC card device path structure.
649 
650 **/
651 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextPcCard(IN CHAR16 * TextDeviceNode)652 DevPathFromTextPcCard (
653   IN CHAR16 *TextDeviceNode
654   )
655 {
656   CHAR16              *FunctionNumberStr;
657   PCCARD_DEVICE_PATH  *Pccard;
658 
659   FunctionNumberStr = GetNextParamStr (&TextDeviceNode);
660   Pccard            = (PCCARD_DEVICE_PATH *) CreateDeviceNode (
661                                                HARDWARE_DEVICE_PATH,
662                                                HW_PCCARD_DP,
663                                                (UINT16) sizeof (PCCARD_DEVICE_PATH)
664                                                );
665 
666   Pccard->FunctionNumber  = (UINT8) Strtoi (FunctionNumberStr);
667 
668   return (EFI_DEVICE_PATH_PROTOCOL *) Pccard;
669 }
670 
671 /**
672   Converts a text device path node to Hardware memory map device path structure.
673 
674   @param TextDeviceNode  The input Text device path node.
675 
676   @return A pointer to Hardware memory map device path structure.
677 
678 **/
679 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextMemoryMapped(IN CHAR16 * TextDeviceNode)680 DevPathFromTextMemoryMapped (
681   IN CHAR16 *TextDeviceNode
682   )
683 {
684   CHAR16              *MemoryTypeStr;
685   CHAR16              *StartingAddressStr;
686   CHAR16              *EndingAddressStr;
687   MEMMAP_DEVICE_PATH  *MemMap;
688 
689   MemoryTypeStr      = GetNextParamStr (&TextDeviceNode);
690   StartingAddressStr = GetNextParamStr (&TextDeviceNode);
691   EndingAddressStr   = GetNextParamStr (&TextDeviceNode);
692   MemMap             = (MEMMAP_DEVICE_PATH *) CreateDeviceNode (
693                                                HARDWARE_DEVICE_PATH,
694                                                HW_MEMMAP_DP,
695                                                (UINT16) sizeof (MEMMAP_DEVICE_PATH)
696                                                );
697 
698   MemMap->MemoryType = (UINT32) Strtoi (MemoryTypeStr);
699   Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);
700   Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);
701 
702   return (EFI_DEVICE_PATH_PROTOCOL *) MemMap;
703 }
704 
705 /**
706   Converts a text device path node to Vendor device path structure based on the input Type
707   and SubType.
708 
709   @param TextDeviceNode  The input Text device path node.
710   @param Type            The type of device path node.
711   @param SubType         The subtype of device path node.
712 
713   @return A pointer to the newly-created Vendor device path structure.
714 
715 **/
716 EFI_DEVICE_PATH_PROTOCOL *
ConvertFromTextVendor(IN CHAR16 * TextDeviceNode,IN UINT8 Type,IN UINT8 SubType)717 ConvertFromTextVendor (
718   IN CHAR16 *TextDeviceNode,
719   IN UINT8  Type,
720   IN UINT8  SubType
721   )
722 {
723   CHAR16              *GuidStr;
724   CHAR16              *DataStr;
725   UINTN               Length;
726   VENDOR_DEVICE_PATH  *Vendor;
727 
728   GuidStr = GetNextParamStr (&TextDeviceNode);
729 
730   DataStr = GetNextParamStr (&TextDeviceNode);
731   Length  = StrLen (DataStr);
732   //
733   // Two hex characters make up 1 buffer byte
734   //
735   Length  = (Length + 1) / 2;
736 
737   Vendor  = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
738                                      Type,
739                                      SubType,
740                                      (UINT16) (sizeof (VENDOR_DEVICE_PATH) + Length)
741                                      );
742 
743   StrToGuid (GuidStr, &Vendor->Guid);
744   StrToBuf (((UINT8 *) Vendor) + sizeof (VENDOR_DEVICE_PATH), Length, DataStr);
745 
746   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
747 }
748 
749 /**
750   Converts a text device path node to Vendor Hardware device path structure.
751 
752   @param TextDeviceNode  The input Text device path node.
753 
754   @return A pointer to the newly-created Vendor Hardware device path structure.
755 
756 **/
757 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextVenHw(IN CHAR16 * TextDeviceNode)758 DevPathFromTextVenHw (
759   IN CHAR16 *TextDeviceNode
760   )
761 {
762   return ConvertFromTextVendor (
763            TextDeviceNode,
764            HARDWARE_DEVICE_PATH,
765            HW_VENDOR_DP
766            );
767 }
768 
769 /**
770   Converts a text device path node to Hardware Controller device path structure.
771 
772   @param TextDeviceNode  The input Text device path node.
773 
774   @return A pointer to the newly-created Hardware Controller device path structure.
775 
776 **/
777 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextCtrl(IN CHAR16 * TextDeviceNode)778 DevPathFromTextCtrl (
779   IN CHAR16 *TextDeviceNode
780   )
781 {
782   CHAR16                  *ControllerStr;
783   CONTROLLER_DEVICE_PATH  *Controller;
784 
785   ControllerStr = GetNextParamStr (&TextDeviceNode);
786   Controller    = (CONTROLLER_DEVICE_PATH *) CreateDeviceNode (
787                                                HARDWARE_DEVICE_PATH,
788                                                HW_CONTROLLER_DP,
789                                                (UINT16) sizeof (CONTROLLER_DEVICE_PATH)
790                                                );
791   Controller->ControllerNumber = (UINT32) Strtoi (ControllerStr);
792 
793   return (EFI_DEVICE_PATH_PROTOCOL *) Controller;
794 }
795 
796 /**
797   Converts a text device path node to BMC device path structure.
798 
799   @param TextDeviceNode  The input Text device path node.
800 
801   @return A pointer to the newly-created BMC device path structure.
802 
803 **/
804 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextBmc(IN CHAR16 * TextDeviceNode)805 DevPathFromTextBmc (
806   IN CHAR16 *TextDeviceNode
807   )
808 {
809   CHAR16                *InterfaceTypeStr;
810   CHAR16                *BaseAddressStr;
811   BMC_DEVICE_PATH       *BmcDp;
812 
813   InterfaceTypeStr = GetNextParamStr (&TextDeviceNode);
814   BaseAddressStr   = GetNextParamStr (&TextDeviceNode);
815   BmcDp            = (BMC_DEVICE_PATH *) CreateDeviceNode (
816                                            HARDWARE_DEVICE_PATH,
817                                            HW_BMC_DP,
818                                            (UINT16) sizeof (BMC_DEVICE_PATH)
819                                            );
820 
821   BmcDp->InterfaceType = (UINT8) Strtoi (InterfaceTypeStr);
822   WriteUnaligned64 (
823     (UINT64 *) (&BmcDp->BaseAddress),
824     StrHexToUint64 (BaseAddressStr)
825     );
826 
827   return (EFI_DEVICE_PATH_PROTOCOL *) BmcDp;
828 }
829 
830 /**
831   Converts a generic ACPI text device path node to ACPI device path structure.
832 
833   @param TextDeviceNode  The input Text device path node.
834 
835   @return A pointer to ACPI device path structure.
836 
837 **/
838 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextAcpiPath(IN CHAR16 * TextDeviceNode)839 DevPathFromTextAcpiPath (
840   IN CHAR16 *TextDeviceNode
841   )
842 {
843   return DevPathFromTextGenericPath (ACPI_DEVICE_PATH, TextDeviceNode);
844 }
845 
846 /**
847   Converts a string to EisaId.
848 
849   @param Text   The input string.
850 
851   @return UINT32 EISA ID.
852 **/
853 UINT32
EisaIdFromText(IN CHAR16 * Text)854 EisaIdFromText (
855   IN CHAR16 *Text
856   )
857 {
858   return (((Text[0] - 'A' + 1) & 0x1f) << 10)
859        + (((Text[1] - 'A' + 1) & 0x1f) <<  5)
860        + (((Text[2] - 'A' + 1) & 0x1f) <<  0)
861        + (UINT32) (StrHexToUintn (&Text[3]) << 16)
862        ;
863 }
864 
865 /**
866   Converts a text device path node to ACPI HID device path structure.
867 
868   @param TextDeviceNode  The input Text device path node.
869 
870   @return A pointer to the newly-created ACPI HID device path structure.
871 
872 **/
873 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextAcpi(IN CHAR16 * TextDeviceNode)874 DevPathFromTextAcpi (
875   IN CHAR16 *TextDeviceNode
876   )
877 {
878   CHAR16                *HIDStr;
879   CHAR16                *UIDStr;
880   ACPI_HID_DEVICE_PATH  *Acpi;
881 
882   HIDStr = GetNextParamStr (&TextDeviceNode);
883   UIDStr = GetNextParamStr (&TextDeviceNode);
884   Acpi   = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
885                                       ACPI_DEVICE_PATH,
886                                       ACPI_DP,
887                                       (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
888                                       );
889 
890   Acpi->HID = EisaIdFromText (HIDStr);
891   Acpi->UID = (UINT32) Strtoi (UIDStr);
892 
893   return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
894 }
895 
896 /**
897   Converts a text device path node to ACPI HID device path structure.
898 
899   @param TextDeviceNode  The input Text device path node.
900   @param PnPId           The input plug and play identification.
901 
902   @return A pointer to the newly-created ACPI HID device path structure.
903 
904 **/
905 EFI_DEVICE_PATH_PROTOCOL *
ConvertFromTextAcpi(IN CHAR16 * TextDeviceNode,IN UINT32 PnPId)906 ConvertFromTextAcpi (
907   IN CHAR16 *TextDeviceNode,
908   IN UINT32  PnPId
909   )
910 {
911   CHAR16                *UIDStr;
912   ACPI_HID_DEVICE_PATH  *Acpi;
913 
914   UIDStr = GetNextParamStr (&TextDeviceNode);
915   Acpi   = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
916                                       ACPI_DEVICE_PATH,
917                                       ACPI_DP,
918                                       (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
919                                       );
920 
921   Acpi->HID = EFI_PNP_ID (PnPId);
922   Acpi->UID = (UINT32) Strtoi (UIDStr);
923 
924   return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
925 }
926 
927 /**
928   Converts a text device path node to PCI root device path structure.
929 
930   @param TextDeviceNode  The input Text device path node.
931 
932   @return A pointer to the newly-created PCI root device path structure.
933 
934 **/
935 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextPciRoot(IN CHAR16 * TextDeviceNode)936 DevPathFromTextPciRoot (
937   IN CHAR16 *TextDeviceNode
938   )
939 {
940   return ConvertFromTextAcpi (TextDeviceNode, 0x0a03);
941 }
942 
943 /**
944   Converts a text device path node to PCIE root device path structure.
945 
946   @param TextDeviceNode  The input Text device path node.
947 
948   @return A pointer to the newly-created PCIE root device path structure.
949 
950 **/
951 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextPcieRoot(IN CHAR16 * TextDeviceNode)952 DevPathFromTextPcieRoot (
953   IN CHAR16 *TextDeviceNode
954   )
955 {
956   return ConvertFromTextAcpi (TextDeviceNode, 0x0a08);
957 }
958 
959 /**
960   Converts a text device path node to Floppy device path structure.
961 
962   @param TextDeviceNode  The input Text device path node.
963 
964   @return A pointer to the newly-created Floppy device path structure.
965 
966 **/
967 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextFloppy(IN CHAR16 * TextDeviceNode)968 DevPathFromTextFloppy (
969   IN CHAR16 *TextDeviceNode
970   )
971 {
972   return ConvertFromTextAcpi (TextDeviceNode, 0x0604);
973 }
974 
975 /**
976   Converts a text device path node to Keyboard device path structure.
977 
978   @param TextDeviceNode  The input Text device path node.
979 
980   @return A pointer to the newly-created  Keyboard device path structure.
981 
982 **/
983 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextKeyboard(IN CHAR16 * TextDeviceNode)984 DevPathFromTextKeyboard (
985   IN CHAR16 *TextDeviceNode
986   )
987 {
988   return ConvertFromTextAcpi (TextDeviceNode, 0x0301);
989 }
990 
991 /**
992   Converts a text device path node to Serial device path structure.
993 
994   @param TextDeviceNode  The input Text device path node.
995 
996   @return A pointer to the newly-created Serial device path structure.
997 
998 **/
999 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextSerial(IN CHAR16 * TextDeviceNode)1000 DevPathFromTextSerial (
1001   IN CHAR16 *TextDeviceNode
1002   )
1003 {
1004   return ConvertFromTextAcpi (TextDeviceNode, 0x0501);
1005 }
1006 
1007 /**
1008   Converts a text device path node to Parallel Port device path structure.
1009 
1010   @param TextDeviceNode  The input Text device path node.
1011 
1012   @return A pointer to the newly-created Parallel Port device path structure.
1013 
1014 **/
1015 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextParallelPort(IN CHAR16 * TextDeviceNode)1016 DevPathFromTextParallelPort (
1017   IN CHAR16 *TextDeviceNode
1018   )
1019 {
1020   return ConvertFromTextAcpi (TextDeviceNode, 0x0401);
1021 }
1022 
1023 /**
1024   Converts a text device path node to ACPI extension device path structure.
1025 
1026   @param TextDeviceNode  The input Text device path node.
1027 
1028   @return A pointer to the newly-created ACPI extension device path structure.
1029 
1030 **/
1031 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextAcpiEx(IN CHAR16 * TextDeviceNode)1032 DevPathFromTextAcpiEx (
1033   IN CHAR16 *TextDeviceNode
1034   )
1035 {
1036   CHAR16                         *HIDStr;
1037   CHAR16                         *CIDStr;
1038   CHAR16                         *UIDStr;
1039   CHAR16                         *HIDSTRStr;
1040   CHAR16                         *CIDSTRStr;
1041   CHAR16                         *UIDSTRStr;
1042   CHAR8                          *AsciiStr;
1043   UINT16                         Length;
1044   ACPI_EXTENDED_HID_DEVICE_PATH  *AcpiEx;
1045 
1046   HIDStr    = GetNextParamStr (&TextDeviceNode);
1047   CIDStr    = GetNextParamStr (&TextDeviceNode);
1048   UIDStr    = GetNextParamStr (&TextDeviceNode);
1049   HIDSTRStr = GetNextParamStr (&TextDeviceNode);
1050   CIDSTRStr = GetNextParamStr (&TextDeviceNode);
1051   UIDSTRStr = GetNextParamStr (&TextDeviceNode);
1052 
1053   Length    = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (HIDSTRStr) + 1);
1054   Length    = (UINT16) (Length + StrLen (UIDSTRStr) + 1);
1055   Length    = (UINT16) (Length + StrLen (CIDSTRStr) + 1);
1056   AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (
1057                                                ACPI_DEVICE_PATH,
1058                                                ACPI_EXTENDED_DP,
1059                                                Length
1060                                                );
1061 
1062   AcpiEx->HID = EisaIdFromText (HIDStr);
1063   AcpiEx->CID = EisaIdFromText (CIDStr);
1064   AcpiEx->UID = (UINT32) Strtoi (UIDStr);
1065 
1066   AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
1067   StrToAscii (HIDSTRStr, &AsciiStr);
1068   StrToAscii (UIDSTRStr, &AsciiStr);
1069   StrToAscii (CIDSTRStr, &AsciiStr);
1070 
1071   return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;
1072 }
1073 
1074 /**
1075   Converts a text device path node to ACPI extension device path structure.
1076 
1077   @param TextDeviceNode  The input Text device path node.
1078 
1079   @return A pointer to the newly-created ACPI extension device path structure.
1080 
1081 **/
1082 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextAcpiExp(IN CHAR16 * TextDeviceNode)1083 DevPathFromTextAcpiExp (
1084   IN CHAR16 *TextDeviceNode
1085   )
1086 {
1087   CHAR16                         *HIDStr;
1088   CHAR16                         *CIDStr;
1089   CHAR16                         *UIDSTRStr;
1090   CHAR8                          *AsciiStr;
1091   UINT16                         Length;
1092   ACPI_EXTENDED_HID_DEVICE_PATH  *AcpiEx;
1093 
1094   HIDStr    = GetNextParamStr (&TextDeviceNode);
1095   CIDStr    = GetNextParamStr (&TextDeviceNode);
1096   UIDSTRStr = GetNextParamStr (&TextDeviceNode);
1097   Length    = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (UIDSTRStr) + 3);
1098   AcpiEx    = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (
1099                                                   ACPI_DEVICE_PATH,
1100                                                   ACPI_EXTENDED_DP,
1101                                                   Length
1102                                                   );
1103 
1104   AcpiEx->HID = EisaIdFromText (HIDStr);
1105   AcpiEx->CID = EisaIdFromText (CIDStr);
1106   AcpiEx->UID = 0;
1107 
1108   AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
1109   //
1110   // HID string is NULL
1111   //
1112   *AsciiStr = '\0';
1113   //
1114   // Convert UID string
1115   //
1116   AsciiStr++;
1117   StrToAscii (UIDSTRStr, &AsciiStr);
1118   //
1119   // CID string is NULL
1120   //
1121   *AsciiStr = '\0';
1122 
1123   return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;
1124 }
1125 
1126 /**
1127   Converts a text device path node to ACPI _ADR device path structure.
1128 
1129   @param TextDeviceNode  The input Text device path node.
1130 
1131   @return A pointer to the newly-created ACPI _ADR device path structure.
1132 
1133 **/
1134 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextAcpiAdr(IN CHAR16 * TextDeviceNode)1135 DevPathFromTextAcpiAdr (
1136   IN CHAR16 *TextDeviceNode
1137   )
1138 {
1139   CHAR16                *DisplayDeviceStr;
1140   ACPI_ADR_DEVICE_PATH  *AcpiAdr;
1141   UINTN                 Index;
1142   UINTN                 Length;
1143 
1144   AcpiAdr = (ACPI_ADR_DEVICE_PATH *) CreateDeviceNode (
1145                                        ACPI_DEVICE_PATH,
1146                                        ACPI_ADR_DP,
1147                                        (UINT16) sizeof (ACPI_ADR_DEVICE_PATH)
1148                                        );
1149   ASSERT (AcpiAdr != NULL);
1150 
1151   for (Index = 0; ; Index++) {
1152     DisplayDeviceStr = GetNextParamStr (&TextDeviceNode);
1153     if (IS_NULL (*DisplayDeviceStr)) {
1154       break;
1155     }
1156     if (Index > 0) {
1157       Length  = DevicePathNodeLength (AcpiAdr);
1158       AcpiAdr = ReallocatePool (
1159                   Length,
1160                   Length + sizeof (UINT32),
1161                   AcpiAdr
1162                   );
1163       ASSERT (AcpiAdr != NULL);
1164       SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32));
1165     }
1166 
1167     (&AcpiAdr->ADR)[Index] = (UINT32) Strtoi (DisplayDeviceStr);
1168   }
1169 
1170   return (EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr;
1171 }
1172 
1173 /**
1174   Converts a generic messaging text device path node to messaging device path structure.
1175 
1176   @param TextDeviceNode  The input Text device path node.
1177 
1178   @return A pointer to messaging device path structure.
1179 
1180 **/
1181 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextMsg(IN CHAR16 * TextDeviceNode)1182 DevPathFromTextMsg (
1183   IN CHAR16 *TextDeviceNode
1184   )
1185 {
1186   return DevPathFromTextGenericPath (MESSAGING_DEVICE_PATH, TextDeviceNode);
1187 }
1188 
1189 /**
1190   Converts a text device path node to Parallel Port device path structure.
1191 
1192   @param TextDeviceNode  The input Text device path node.
1193 
1194   @return A pointer to the newly-created Parallel Port device path structure.
1195 
1196 **/
1197 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextAta(IN CHAR16 * TextDeviceNode)1198 DevPathFromTextAta (
1199 IN CHAR16 *TextDeviceNode
1200 )
1201 {
1202   CHAR16            *PrimarySecondaryStr;
1203   CHAR16            *SlaveMasterStr;
1204   CHAR16            *LunStr;
1205   ATAPI_DEVICE_PATH *Atapi;
1206 
1207   Atapi = (ATAPI_DEVICE_PATH *) CreateDeviceNode (
1208     MESSAGING_DEVICE_PATH,
1209     MSG_ATAPI_DP,
1210     (UINT16) sizeof (ATAPI_DEVICE_PATH)
1211     );
1212 
1213   PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
1214   SlaveMasterStr      = GetNextParamStr (&TextDeviceNode);
1215   LunStr              = GetNextParamStr (&TextDeviceNode);
1216 
1217   if (StrCmp (PrimarySecondaryStr, L"Primary") == 0) {
1218     Atapi->PrimarySecondary = 0;
1219   } else if (StrCmp (PrimarySecondaryStr, L"Secondary") == 0) {
1220     Atapi->PrimarySecondary = 1;
1221   } else {
1222     Atapi->PrimarySecondary = (UINT8) Strtoi (PrimarySecondaryStr);
1223   }
1224   if (StrCmp (SlaveMasterStr, L"Master") == 0) {
1225     Atapi->SlaveMaster      = 0;
1226   } else if (StrCmp (SlaveMasterStr, L"Slave") == 0) {
1227     Atapi->SlaveMaster      = 1;
1228   } else {
1229     Atapi->SlaveMaster      = (UINT8) Strtoi (SlaveMasterStr);
1230   }
1231 
1232   Atapi->Lun                = (UINT16) Strtoi (LunStr);
1233 
1234   return (EFI_DEVICE_PATH_PROTOCOL *) Atapi;
1235 }
1236 
1237 /**
1238   Converts a text device path node to SCSI device path structure.
1239 
1240   @param TextDeviceNode  The input Text device path node.
1241 
1242   @return A pointer to the newly-created SCSI device path structure.
1243 
1244 **/
1245 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextScsi(IN CHAR16 * TextDeviceNode)1246 DevPathFromTextScsi (
1247   IN CHAR16 *TextDeviceNode
1248   )
1249 {
1250   CHAR16            *PunStr;
1251   CHAR16            *LunStr;
1252   SCSI_DEVICE_PATH  *Scsi;
1253 
1254   PunStr = GetNextParamStr (&TextDeviceNode);
1255   LunStr = GetNextParamStr (&TextDeviceNode);
1256   Scsi   = (SCSI_DEVICE_PATH *) CreateDeviceNode (
1257                                    MESSAGING_DEVICE_PATH,
1258                                    MSG_SCSI_DP,
1259                                    (UINT16) sizeof (SCSI_DEVICE_PATH)
1260                                    );
1261 
1262   Scsi->Pun = (UINT16) Strtoi (PunStr);
1263   Scsi->Lun = (UINT16) Strtoi (LunStr);
1264 
1265   return (EFI_DEVICE_PATH_PROTOCOL *) Scsi;
1266 }
1267 
1268 /**
1269   Converts a text device path node to Fibre device path structure.
1270 
1271   @param TextDeviceNode  The input Text device path node.
1272 
1273   @return A pointer to the newly-created Fibre device path structure.
1274 
1275 **/
1276 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextFibre(IN CHAR16 * TextDeviceNode)1277 DevPathFromTextFibre (
1278   IN CHAR16 *TextDeviceNode
1279   )
1280 {
1281   CHAR16                    *WWNStr;
1282   CHAR16                    *LunStr;
1283   FIBRECHANNEL_DEVICE_PATH  *Fibre;
1284 
1285   WWNStr = GetNextParamStr (&TextDeviceNode);
1286   LunStr = GetNextParamStr (&TextDeviceNode);
1287   Fibre  = (FIBRECHANNEL_DEVICE_PATH *) CreateDeviceNode (
1288                                           MESSAGING_DEVICE_PATH,
1289                                           MSG_FIBRECHANNEL_DP,
1290                                           (UINT16) sizeof (FIBRECHANNEL_DEVICE_PATH)
1291                                           );
1292 
1293   Fibre->Reserved = 0;
1294   Strtoi64 (WWNStr, &Fibre->WWN);
1295   Strtoi64 (LunStr, &Fibre->Lun);
1296 
1297   return (EFI_DEVICE_PATH_PROTOCOL *) Fibre;
1298 }
1299 
1300 /**
1301   Converts a text device path node to FibreEx device path structure.
1302 
1303   @param TextDeviceNode  The input Text device path node.
1304 
1305   @return A pointer to the newly-created FibreEx device path structure.
1306 
1307 **/
1308 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextFibreEx(IN CHAR16 * TextDeviceNode)1309 DevPathFromTextFibreEx (
1310   IN CHAR16 *TextDeviceNode
1311   )
1312 {
1313   CHAR16                      *WWNStr;
1314   CHAR16                      *LunStr;
1315   FIBRECHANNELEX_DEVICE_PATH  *FibreEx;
1316 
1317   WWNStr  = GetNextParamStr (&TextDeviceNode);
1318   LunStr  = GetNextParamStr (&TextDeviceNode);
1319   FibreEx = (FIBRECHANNELEX_DEVICE_PATH *) CreateDeviceNode (
1320                                              MESSAGING_DEVICE_PATH,
1321                                              MSG_FIBRECHANNELEX_DP,
1322                                              (UINT16) sizeof (FIBRECHANNELEX_DEVICE_PATH)
1323                                              );
1324 
1325   FibreEx->Reserved = 0;
1326   Strtoi64 (WWNStr, (UINT64 *) (&FibreEx->WWN));
1327   Strtoi64 (LunStr, (UINT64 *) (&FibreEx->Lun));
1328 
1329   *(UINT64 *) (&FibreEx->WWN) = SwapBytes64 (*(UINT64 *) (&FibreEx->WWN));
1330   *(UINT64 *) (&FibreEx->Lun) = SwapBytes64 (*(UINT64 *) (&FibreEx->Lun));
1331 
1332   return (EFI_DEVICE_PATH_PROTOCOL *) FibreEx;
1333 }
1334 
1335 /**
1336   Converts a text device path node to 1394 device path structure.
1337 
1338   @param TextDeviceNode  The input Text device path node.
1339 
1340   @return A pointer to the newly-created 1394 device path structure.
1341 
1342 **/
1343 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromText1394(IN CHAR16 * TextDeviceNode)1344 DevPathFromText1394 (
1345   IN CHAR16 *TextDeviceNode
1346   )
1347 {
1348   CHAR16            *GuidStr;
1349   F1394_DEVICE_PATH *F1394DevPath;
1350 
1351   GuidStr = GetNextParamStr (&TextDeviceNode);
1352   F1394DevPath  = (F1394_DEVICE_PATH *) CreateDeviceNode (
1353                                           MESSAGING_DEVICE_PATH,
1354                                           MSG_1394_DP,
1355                                           (UINT16) sizeof (F1394_DEVICE_PATH)
1356                                           );
1357 
1358   F1394DevPath->Reserved = 0;
1359   F1394DevPath->Guid     = StrHexToUint64 (GuidStr);
1360 
1361   return (EFI_DEVICE_PATH_PROTOCOL *) F1394DevPath;
1362 }
1363 
1364 /**
1365   Converts a text device path node to USB device path structure.
1366 
1367   @param TextDeviceNode  The input Text device path node.
1368 
1369   @return A pointer to the newly-created USB device path structure.
1370 
1371 **/
1372 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsb(IN CHAR16 * TextDeviceNode)1373 DevPathFromTextUsb (
1374   IN CHAR16 *TextDeviceNode
1375   )
1376 {
1377   CHAR16          *PortStr;
1378   CHAR16          *InterfaceStr;
1379   USB_DEVICE_PATH *Usb;
1380 
1381   PortStr               = GetNextParamStr (&TextDeviceNode);
1382   InterfaceStr          = GetNextParamStr (&TextDeviceNode);
1383   Usb                   = (USB_DEVICE_PATH *) CreateDeviceNode (
1384                                                 MESSAGING_DEVICE_PATH,
1385                                                 MSG_USB_DP,
1386                                                 (UINT16) sizeof (USB_DEVICE_PATH)
1387                                                 );
1388 
1389   Usb->ParentPortNumber = (UINT8) Strtoi (PortStr);
1390   Usb->InterfaceNumber  = (UINT8) Strtoi (InterfaceStr);
1391 
1392   return (EFI_DEVICE_PATH_PROTOCOL *) Usb;
1393 }
1394 
1395 /**
1396   Converts a text device path node to I20 device path structure.
1397 
1398   @param TextDeviceNode  The input Text device path node.
1399 
1400   @return A pointer to the newly-created I20 device path structure.
1401 
1402 **/
1403 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextI2O(IN CHAR16 * TextDeviceNode)1404 DevPathFromTextI2O (
1405   IN CHAR16 *TextDeviceNode
1406   )
1407 {
1408   CHAR16          *TIDStr;
1409   I2O_DEVICE_PATH *I2ODevPath;
1410 
1411   TIDStr     = GetNextParamStr (&TextDeviceNode);
1412   I2ODevPath = (I2O_DEVICE_PATH *) CreateDeviceNode (
1413                                     MESSAGING_DEVICE_PATH,
1414                                     MSG_I2O_DP,
1415                                     (UINT16) sizeof (I2O_DEVICE_PATH)
1416                                     );
1417 
1418   I2ODevPath->Tid  = (UINT32) Strtoi (TIDStr);
1419 
1420   return (EFI_DEVICE_PATH_PROTOCOL *) I2ODevPath;
1421 }
1422 
1423 /**
1424   Converts a text device path node to Infini Band device path structure.
1425 
1426   @param TextDeviceNode  The input Text device path node.
1427 
1428   @return A pointer to the newly-created Infini Band device path structure.
1429 
1430 **/
1431 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextInfiniband(IN CHAR16 * TextDeviceNode)1432 DevPathFromTextInfiniband (
1433   IN CHAR16 *TextDeviceNode
1434   )
1435 {
1436   CHAR16                  *FlagsStr;
1437   CHAR16                  *GuidStr;
1438   CHAR16                  *SidStr;
1439   CHAR16                  *TidStr;
1440   CHAR16                  *DidStr;
1441   EFI_GUID                PortGid;
1442   INFINIBAND_DEVICE_PATH  *InfiniBand;
1443 
1444   FlagsStr   = GetNextParamStr (&TextDeviceNode);
1445   GuidStr    = GetNextParamStr (&TextDeviceNode);
1446   SidStr     = GetNextParamStr (&TextDeviceNode);
1447   TidStr     = GetNextParamStr (&TextDeviceNode);
1448   DidStr     = GetNextParamStr (&TextDeviceNode);
1449   InfiniBand = (INFINIBAND_DEVICE_PATH *) CreateDeviceNode (
1450                                             MESSAGING_DEVICE_PATH,
1451                                             MSG_INFINIBAND_DP,
1452                                             (UINT16) sizeof (INFINIBAND_DEVICE_PATH)
1453                                             );
1454 
1455   InfiniBand->ResourceFlags = (UINT32) Strtoi (FlagsStr);
1456   StrToGuid (GuidStr, &PortGid);
1457   CopyMem (InfiniBand->PortGid, &PortGid, sizeof (EFI_GUID));
1458   Strtoi64 (SidStr, &InfiniBand->ServiceId);
1459   Strtoi64 (TidStr, &InfiniBand->TargetPortId);
1460   Strtoi64 (DidStr, &InfiniBand->DeviceId);
1461 
1462   return (EFI_DEVICE_PATH_PROTOCOL *) InfiniBand;
1463 }
1464 
1465 /**
1466   Converts a text device path node to Vendor-Defined Messaging device path structure.
1467 
1468   @param TextDeviceNode  The input Text device path node.
1469 
1470   @return A pointer to the newly-created Vendor-Defined Messaging device path structure.
1471 
1472 **/
1473 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextVenMsg(IN CHAR16 * TextDeviceNode)1474 DevPathFromTextVenMsg (
1475   IN CHAR16 *TextDeviceNode
1476   )
1477 {
1478   return ConvertFromTextVendor (
1479             TextDeviceNode,
1480             MESSAGING_DEVICE_PATH,
1481             MSG_VENDOR_DP
1482             );
1483 }
1484 
1485 /**
1486   Converts a text device path node to Vendor defined PC-ANSI device path structure.
1487 
1488   @param TextDeviceNode  The input Text device path node.
1489 
1490   @return A pointer to the newly-created Vendor defined PC-ANSI device path structure.
1491 
1492 **/
1493 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextVenPcAnsi(IN CHAR16 * TextDeviceNode)1494 DevPathFromTextVenPcAnsi (
1495   IN CHAR16 *TextDeviceNode
1496   )
1497 {
1498   VENDOR_DEVICE_PATH  *Vendor;
1499 
1500   Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1501                                     MESSAGING_DEVICE_PATH,
1502                                     MSG_VENDOR_DP,
1503                                     (UINT16) sizeof (VENDOR_DEVICE_PATH));
1504   CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
1505 
1506   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1507 }
1508 
1509 /**
1510   Converts a text device path node to Vendor defined VT100 device path structure.
1511 
1512   @param TextDeviceNode  The input Text device path node.
1513 
1514   @return A pointer to the newly-created Vendor defined VT100 device path structure.
1515 
1516 **/
1517 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextVenVt100(IN CHAR16 * TextDeviceNode)1518 DevPathFromTextVenVt100 (
1519   IN CHAR16 *TextDeviceNode
1520   )
1521 {
1522   VENDOR_DEVICE_PATH  *Vendor;
1523 
1524   Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1525                                     MESSAGING_DEVICE_PATH,
1526                                     MSG_VENDOR_DP,
1527                                     (UINT16) sizeof (VENDOR_DEVICE_PATH));
1528   CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
1529 
1530   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1531 }
1532 
1533 /**
1534   Converts a text device path node to Vendor defined VT100 Plus device path structure.
1535 
1536   @param TextDeviceNode  The input Text device path node.
1537 
1538   @return A pointer to the newly-created Vendor defined VT100 Plus device path structure.
1539 
1540 **/
1541 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextVenVt100Plus(IN CHAR16 * TextDeviceNode)1542 DevPathFromTextVenVt100Plus (
1543   IN CHAR16 *TextDeviceNode
1544   )
1545 {
1546   VENDOR_DEVICE_PATH  *Vendor;
1547 
1548   Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1549                                     MESSAGING_DEVICE_PATH,
1550                                     MSG_VENDOR_DP,
1551                                     (UINT16) sizeof (VENDOR_DEVICE_PATH));
1552   CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
1553 
1554   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1555 }
1556 
1557 /**
1558   Converts a text device path node to Vendor defined UTF8 device path structure.
1559 
1560   @param TextDeviceNode  The input Text device path node.
1561 
1562   @return A pointer to the newly-created Vendor defined UTF8 device path structure.
1563 
1564 **/
1565 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextVenUtf8(IN CHAR16 * TextDeviceNode)1566 DevPathFromTextVenUtf8 (
1567   IN CHAR16 *TextDeviceNode
1568   )
1569 {
1570   VENDOR_DEVICE_PATH  *Vendor;
1571 
1572   Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1573                                     MESSAGING_DEVICE_PATH,
1574                                     MSG_VENDOR_DP,
1575                                     (UINT16) sizeof (VENDOR_DEVICE_PATH));
1576   CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
1577 
1578   return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1579 }
1580 
1581 /**
1582   Converts a text device path node to UART Flow Control device path structure.
1583 
1584   @param TextDeviceNode  The input Text device path node.
1585 
1586   @return A pointer to the newly-created UART Flow Control device path structure.
1587 
1588 **/
1589 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUartFlowCtrl(IN CHAR16 * TextDeviceNode)1590 DevPathFromTextUartFlowCtrl (
1591   IN CHAR16 *TextDeviceNode
1592   )
1593 {
1594   CHAR16                        *ValueStr;
1595   UART_FLOW_CONTROL_DEVICE_PATH *UartFlowControl;
1596 
1597   ValueStr        = GetNextParamStr (&TextDeviceNode);
1598   UartFlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) CreateDeviceNode (
1599                                                         MESSAGING_DEVICE_PATH,
1600                                                         MSG_VENDOR_DP,
1601                                                         (UINT16) sizeof (UART_FLOW_CONTROL_DEVICE_PATH)
1602                                                         );
1603 
1604   CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
1605   if (StrCmp (ValueStr, L"XonXoff") == 0) {
1606     UartFlowControl->FlowControlMap = 2;
1607   } else if (StrCmp (ValueStr, L"Hardware") == 0) {
1608     UartFlowControl->FlowControlMap = 1;
1609   } else {
1610     UartFlowControl->FlowControlMap = 0;
1611   }
1612 
1613   return (EFI_DEVICE_PATH_PROTOCOL *) UartFlowControl;
1614 }
1615 
1616 /**
1617   Converts a text device path node to Serial Attached SCSI device path structure.
1618 
1619   @param TextDeviceNode  The input Text device path node.
1620 
1621   @return A pointer to the newly-created Serial Attached SCSI device path structure.
1622 
1623 **/
1624 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextSAS(IN CHAR16 * TextDeviceNode)1625 DevPathFromTextSAS (
1626   IN CHAR16 *TextDeviceNode
1627   )
1628 {
1629   CHAR16          *AddressStr;
1630   CHAR16          *LunStr;
1631   CHAR16          *RTPStr;
1632   CHAR16          *SASSATAStr;
1633   CHAR16          *LocationStr;
1634   CHAR16          *ConnectStr;
1635   CHAR16          *DriveBayStr;
1636   CHAR16          *ReservedStr;
1637   UINT16          Info;
1638   UINT16          Uint16;
1639   SAS_DEVICE_PATH *Sas;
1640 
1641   AddressStr  = GetNextParamStr (&TextDeviceNode);
1642   LunStr      = GetNextParamStr (&TextDeviceNode);
1643   RTPStr      = GetNextParamStr (&TextDeviceNode);
1644   SASSATAStr  = GetNextParamStr (&TextDeviceNode);
1645   LocationStr = GetNextParamStr (&TextDeviceNode);
1646   ConnectStr  = GetNextParamStr (&TextDeviceNode);
1647   DriveBayStr = GetNextParamStr (&TextDeviceNode);
1648   ReservedStr = GetNextParamStr (&TextDeviceNode);
1649   Sas         = (SAS_DEVICE_PATH *) CreateDeviceNode (
1650                                        MESSAGING_DEVICE_PATH,
1651                                        MSG_VENDOR_DP,
1652                                        (UINT16) sizeof (SAS_DEVICE_PATH)
1653                                        );
1654 
1655   CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid);
1656   Strtoi64 (AddressStr, &Sas->SasAddress);
1657   Strtoi64 (LunStr, &Sas->Lun);
1658   Sas->RelativeTargetPort = (UINT16) Strtoi (RTPStr);
1659 
1660   if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
1661     Info = 0x0;
1662 
1663   } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {
1664 
1665     Uint16 = (UINT16) Strtoi (DriveBayStr);
1666     if (Uint16 == 0) {
1667       Info = 0x1;
1668     } else {
1669       Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
1670     }
1671 
1672     if (StrCmp (SASSATAStr, L"SATA") == 0) {
1673       Info |= BIT4;
1674     }
1675 
1676     //
1677     // Location is an integer between 0 and 1 or else
1678     // the keyword Internal (0) or External (1).
1679     //
1680     if (StrCmp (LocationStr, L"External") == 0) {
1681       Uint16 = 1;
1682     } else if (StrCmp (LocationStr, L"Internal") == 0) {
1683       Uint16 = 0;
1684     } else {
1685       Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);
1686     }
1687     Info |= (Uint16 << 5);
1688 
1689     //
1690     // Connect is an integer between 0 and 3 or else
1691     // the keyword Direct (0) or Expanded (1).
1692     //
1693     if (StrCmp (ConnectStr, L"Expanded") == 0) {
1694       Uint16 = 1;
1695     } else if (StrCmp (ConnectStr, L"Direct") == 0) {
1696       Uint16 = 0;
1697     } else {
1698       Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));
1699     }
1700     Info |= (Uint16 << 6);
1701 
1702   } else {
1703     Info = (UINT16) Strtoi (SASSATAStr);
1704   }
1705 
1706   Sas->DeviceTopology = Info;
1707   Sas->Reserved       = (UINT32) Strtoi (ReservedStr);
1708 
1709   return (EFI_DEVICE_PATH_PROTOCOL *) Sas;
1710 }
1711 
1712 /**
1713   Converts a text device path node to Serial Attached SCSI Ex device path structure.
1714 
1715   @param TextDeviceNode  The input Text device path node.
1716 
1717   @return A pointer to the newly-created Serial Attached SCSI Ex device path structure.
1718 
1719 **/
1720 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextSasEx(IN CHAR16 * TextDeviceNode)1721 DevPathFromTextSasEx (
1722   IN CHAR16 *TextDeviceNode
1723   )
1724 {
1725   CHAR16            *AddressStr;
1726   CHAR16            *LunStr;
1727   CHAR16            *RTPStr;
1728   CHAR16            *SASSATAStr;
1729   CHAR16            *LocationStr;
1730   CHAR16            *ConnectStr;
1731   CHAR16            *DriveBayStr;
1732   UINT16            Info;
1733   UINT16            Uint16;
1734   UINT64            SasAddress;
1735   UINT64            Lun;
1736   SASEX_DEVICE_PATH *SasEx;
1737 
1738   AddressStr  = GetNextParamStr (&TextDeviceNode);
1739   LunStr      = GetNextParamStr (&TextDeviceNode);
1740   RTPStr      = GetNextParamStr (&TextDeviceNode);
1741   SASSATAStr  = GetNextParamStr (&TextDeviceNode);
1742   LocationStr = GetNextParamStr (&TextDeviceNode);
1743   ConnectStr  = GetNextParamStr (&TextDeviceNode);
1744   DriveBayStr = GetNextParamStr (&TextDeviceNode);
1745   SasEx       = (SASEX_DEVICE_PATH *) CreateDeviceNode (
1746                                         MESSAGING_DEVICE_PATH,
1747                                         MSG_SASEX_DP,
1748                                         (UINT16) sizeof (SASEX_DEVICE_PATH)
1749                                         );
1750 
1751   Strtoi64 (AddressStr, &SasAddress);
1752   Strtoi64 (LunStr,     &Lun);
1753   WriteUnaligned64 ((UINT64 *) &SasEx->SasAddress, SwapBytes64 (SasAddress));
1754   WriteUnaligned64 ((UINT64 *) &SasEx->Lun,        SwapBytes64 (Lun));
1755   SasEx->RelativeTargetPort      = (UINT16) Strtoi (RTPStr);
1756 
1757   if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
1758     Info = 0x0;
1759 
1760   } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {
1761 
1762     Uint16 = (UINT16) Strtoi (DriveBayStr);
1763     if (Uint16 == 0) {
1764       Info = 0x1;
1765     } else {
1766       Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
1767     }
1768 
1769     if (StrCmp (SASSATAStr, L"SATA") == 0) {
1770       Info |= BIT4;
1771     }
1772 
1773     //
1774     // Location is an integer between 0 and 1 or else
1775     // the keyword Internal (0) or External (1).
1776     //
1777     if (StrCmp (LocationStr, L"External") == 0) {
1778       Uint16 = 1;
1779     } else if (StrCmp (LocationStr, L"Internal") == 0) {
1780       Uint16 = 0;
1781     } else {
1782       Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);
1783     }
1784     Info |= (Uint16 << 5);
1785 
1786     //
1787     // Connect is an integer between 0 and 3 or else
1788     // the keyword Direct (0) or Expanded (1).
1789     //
1790     if (StrCmp (ConnectStr, L"Expanded") == 0) {
1791       Uint16 = 1;
1792     } else if (StrCmp (ConnectStr, L"Direct") == 0) {
1793       Uint16 = 0;
1794     } else {
1795       Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));
1796     }
1797     Info |= (Uint16 << 6);
1798 
1799   } else {
1800     Info = (UINT16) Strtoi (SASSATAStr);
1801   }
1802 
1803   SasEx->DeviceTopology = Info;
1804 
1805   return (EFI_DEVICE_PATH_PROTOCOL *) SasEx;
1806 }
1807 
1808 /**
1809   Converts a text device path node to NVM Express Namespace device path structure.
1810 
1811   @param TextDeviceNode  The input Text device path node.
1812 
1813   @return A pointer to the newly-created NVM Express Namespace device path structure.
1814 
1815 **/
1816 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextNVMe(IN CHAR16 * TextDeviceNode)1817 DevPathFromTextNVMe (
1818   IN CHAR16 *TextDeviceNode
1819   )
1820 {
1821   CHAR16                     *NamespaceIdStr;
1822   CHAR16                     *NamespaceUuidStr;
1823   NVME_NAMESPACE_DEVICE_PATH *Nvme;
1824   UINT8                      *Uuid;
1825   UINTN                      Index;
1826 
1827   NamespaceIdStr   = GetNextParamStr (&TextDeviceNode);
1828   NamespaceUuidStr = GetNextParamStr (&TextDeviceNode);
1829   Nvme = (NVME_NAMESPACE_DEVICE_PATH *) CreateDeviceNode (
1830     MESSAGING_DEVICE_PATH,
1831     MSG_NVME_NAMESPACE_DP,
1832     (UINT16) sizeof (NVME_NAMESPACE_DEVICE_PATH)
1833     );
1834 
1835   Nvme->NamespaceId = (UINT32) Strtoi (NamespaceIdStr);
1836   Uuid = (UINT8 *) &Nvme->NamespaceUuid;
1837 
1838   Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
1839   while (Index-- != 0) {
1840     Uuid[Index] = (UINT8) StrHexToUintn (SplitStr (&NamespaceUuidStr, L'-'));
1841   }
1842 
1843   return (EFI_DEVICE_PATH_PROTOCOL *) Nvme;
1844 }
1845 
1846 /**
1847   Converts a text device path node to UFS device path structure.
1848 
1849   @param TextDeviceNode  The input Text device path node.
1850 
1851   @return A pointer to the newly-created UFS device path structure.
1852 
1853 **/
1854 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUfs(IN CHAR16 * TextDeviceNode)1855 DevPathFromTextUfs (
1856   IN CHAR16 *TextDeviceNode
1857   )
1858 {
1859   CHAR16            *PunStr;
1860   CHAR16            *LunStr;
1861   UFS_DEVICE_PATH   *Ufs;
1862 
1863   PunStr = GetNextParamStr (&TextDeviceNode);
1864   LunStr = GetNextParamStr (&TextDeviceNode);
1865   Ufs    = (UFS_DEVICE_PATH *) CreateDeviceNode (
1866                                  MESSAGING_DEVICE_PATH,
1867                                  MSG_UFS_DP,
1868                                  (UINT16) sizeof (UFS_DEVICE_PATH)
1869                                  );
1870 
1871   Ufs->Pun = (UINT8) Strtoi (PunStr);
1872   Ufs->Lun = (UINT8) Strtoi (LunStr);
1873 
1874   return (EFI_DEVICE_PATH_PROTOCOL *) Ufs;
1875 }
1876 
1877 /**
1878   Converts a text device path node to SD (Secure Digital) device path structure.
1879 
1880   @param TextDeviceNode  The input Text device path node.
1881 
1882   @return A pointer to the newly-created SD device path structure.
1883 
1884 **/
1885 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextSd(IN CHAR16 * TextDeviceNode)1886 DevPathFromTextSd (
1887   IN CHAR16 *TextDeviceNode
1888   )
1889 {
1890   CHAR16            *SlotNumberStr;
1891   SD_DEVICE_PATH    *Sd;
1892 
1893   SlotNumberStr = GetNextParamStr (&TextDeviceNode);
1894   Sd            = (SD_DEVICE_PATH *) CreateDeviceNode (
1895                                        MESSAGING_DEVICE_PATH,
1896                                        MSG_SD_DP,
1897                                        (UINT16) sizeof (SD_DEVICE_PATH)
1898                                        );
1899 
1900   Sd->SlotNumber = (UINT8) Strtoi (SlotNumberStr);
1901 
1902   return (EFI_DEVICE_PATH_PROTOCOL *) Sd;
1903 }
1904 
1905 /**
1906   Converts a text device path node to EMMC (Embedded MMC) device path structure.
1907 
1908   @param TextDeviceNode  The input Text device path node.
1909 
1910   @return A pointer to the newly-created EMMC device path structure.
1911 
1912 **/
1913 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextEmmc(IN CHAR16 * TextDeviceNode)1914 DevPathFromTextEmmc (
1915   IN CHAR16 *TextDeviceNode
1916   )
1917 {
1918   CHAR16            *SlotNumberStr;
1919   EMMC_DEVICE_PATH  *Emmc;
1920 
1921   SlotNumberStr = GetNextParamStr (&TextDeviceNode);
1922   Emmc          = (EMMC_DEVICE_PATH *) CreateDeviceNode (
1923                                        MESSAGING_DEVICE_PATH,
1924                                        MSG_EMMC_DP,
1925                                        (UINT16) sizeof (EMMC_DEVICE_PATH)
1926                                        );
1927 
1928   Emmc->SlotNumber = (UINT8) Strtoi (SlotNumberStr);
1929 
1930   return (EFI_DEVICE_PATH_PROTOCOL *) Emmc;
1931 }
1932 
1933 /**
1934   Converts a text device path node to Debug Port device path structure.
1935 
1936   @param TextDeviceNode  The input Text device path node.
1937 
1938   @return A pointer to the newly-created Debug Port device path structure.
1939 
1940 **/
1941 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextDebugPort(IN CHAR16 * TextDeviceNode)1942 DevPathFromTextDebugPort (
1943   IN CHAR16 *TextDeviceNode
1944   )
1945 {
1946   VENDOR_DEFINED_MESSAGING_DEVICE_PATH  *Vend;
1947 
1948   Vend = (VENDOR_DEFINED_MESSAGING_DEVICE_PATH *) CreateDeviceNode (
1949                                                     MESSAGING_DEVICE_PATH,
1950                                                     MSG_VENDOR_DP,
1951                                                     (UINT16) sizeof (VENDOR_DEFINED_MESSAGING_DEVICE_PATH)
1952                                                     );
1953 
1954   CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
1955 
1956   return (EFI_DEVICE_PATH_PROTOCOL *) Vend;
1957 }
1958 
1959 /**
1960   Converts a text device path node to MAC device path structure.
1961 
1962   @param TextDeviceNode  The input Text device path node.
1963 
1964   @return A pointer to the newly-created MAC device path structure.
1965 
1966 **/
1967 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextMAC(IN CHAR16 * TextDeviceNode)1968 DevPathFromTextMAC (
1969   IN CHAR16 *TextDeviceNode
1970   )
1971 {
1972   CHAR16                *AddressStr;
1973   CHAR16                *IfTypeStr;
1974   UINTN                 Length;
1975   MAC_ADDR_DEVICE_PATH  *MACDevPath;
1976 
1977   AddressStr    = GetNextParamStr (&TextDeviceNode);
1978   IfTypeStr     = GetNextParamStr (&TextDeviceNode);
1979   MACDevPath    = (MAC_ADDR_DEVICE_PATH *) CreateDeviceNode (
1980                                               MESSAGING_DEVICE_PATH,
1981                                               MSG_MAC_ADDR_DP,
1982                                               (UINT16) sizeof (MAC_ADDR_DEVICE_PATH)
1983                                               );
1984 
1985   MACDevPath->IfType   = (UINT8) Strtoi (IfTypeStr);
1986 
1987   Length = sizeof (EFI_MAC_ADDRESS);
1988   StrToBuf (&MACDevPath->MacAddress.Addr[0], Length, AddressStr);
1989 
1990   return (EFI_DEVICE_PATH_PROTOCOL *) MACDevPath;
1991 }
1992 
1993 
1994 /**
1995   Converts a text format to the network protocol ID.
1996 
1997   @param Text  String of protocol field.
1998 
1999   @return Network protocol ID .
2000 
2001 **/
2002 UINTN
NetworkProtocolFromText(IN CHAR16 * Text)2003 NetworkProtocolFromText (
2004   IN CHAR16 *Text
2005   )
2006 {
2007   if (StrCmp (Text, L"UDP") == 0) {
2008     return RFC_1700_UDP_PROTOCOL;
2009   }
2010 
2011   if (StrCmp (Text, L"TCP") == 0) {
2012     return RFC_1700_TCP_PROTOCOL;
2013   }
2014 
2015   return Strtoi (Text);
2016 }
2017 
2018 
2019 /**
2020   Converts a text device path node to IPV4 device path structure.
2021 
2022   @param TextDeviceNode  The input Text device path node.
2023 
2024   @return A pointer to the newly-created IPV4 device path structure.
2025 
2026 **/
2027 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextIPv4(IN CHAR16 * TextDeviceNode)2028 DevPathFromTextIPv4 (
2029   IN CHAR16 *TextDeviceNode
2030   )
2031 {
2032   CHAR16            *RemoteIPStr;
2033   CHAR16            *ProtocolStr;
2034   CHAR16            *TypeStr;
2035   CHAR16            *LocalIPStr;
2036   CHAR16            *GatewayIPStr;
2037   CHAR16            *SubnetMaskStr;
2038   IPv4_DEVICE_PATH  *IPv4;
2039 
2040   RemoteIPStr           = GetNextParamStr (&TextDeviceNode);
2041   ProtocolStr           = GetNextParamStr (&TextDeviceNode);
2042   TypeStr               = GetNextParamStr (&TextDeviceNode);
2043   LocalIPStr            = GetNextParamStr (&TextDeviceNode);
2044   GatewayIPStr          = GetNextParamStr (&TextDeviceNode);
2045   SubnetMaskStr         = GetNextParamStr (&TextDeviceNode);
2046   IPv4                  = (IPv4_DEVICE_PATH *) CreateDeviceNode (
2047                                                  MESSAGING_DEVICE_PATH,
2048                                                  MSG_IPv4_DP,
2049                                                  (UINT16) sizeof (IPv4_DEVICE_PATH)
2050                                                  );
2051 
2052   StrToIPv4Addr (&RemoteIPStr, &IPv4->RemoteIpAddress);
2053   IPv4->Protocol = (UINT16) NetworkProtocolFromText (ProtocolStr);
2054   if (StrCmp (TypeStr, L"Static") == 0) {
2055     IPv4->StaticIpAddress = TRUE;
2056   } else {
2057     IPv4->StaticIpAddress = FALSE;
2058   }
2059 
2060   StrToIPv4Addr (&LocalIPStr, &IPv4->LocalIpAddress);
2061   if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*SubnetMaskStr)) {
2062     StrToIPv4Addr (&GatewayIPStr,  &IPv4->GatewayIpAddress);
2063     StrToIPv4Addr (&SubnetMaskStr, &IPv4->SubnetMask);
2064   } else {
2065     ZeroMem (&IPv4->GatewayIpAddress, sizeof (IPv4->GatewayIpAddress));
2066     ZeroMem (&IPv4->SubnetMask,    sizeof (IPv4->SubnetMask));
2067   }
2068 
2069   IPv4->LocalPort       = 0;
2070   IPv4->RemotePort      = 0;
2071 
2072   return (EFI_DEVICE_PATH_PROTOCOL *) IPv4;
2073 }
2074 
2075 /**
2076   Converts a text device path node to IPV6 device path structure.
2077 
2078   @param TextDeviceNode  The input Text device path node.
2079 
2080   @return A pointer to the newly-created IPV6 device path structure.
2081 
2082 **/
2083 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextIPv6(IN CHAR16 * TextDeviceNode)2084 DevPathFromTextIPv6 (
2085   IN CHAR16 *TextDeviceNode
2086   )
2087 {
2088   CHAR16            *RemoteIPStr;
2089   CHAR16            *ProtocolStr;
2090   CHAR16            *TypeStr;
2091   CHAR16            *LocalIPStr;
2092   CHAR16            *GatewayIPStr;
2093   CHAR16            *PrefixLengthStr;
2094   IPv6_DEVICE_PATH  *IPv6;
2095 
2096   RemoteIPStr           = GetNextParamStr (&TextDeviceNode);
2097   ProtocolStr           = GetNextParamStr (&TextDeviceNode);
2098   TypeStr               = GetNextParamStr (&TextDeviceNode);
2099   LocalIPStr            = GetNextParamStr (&TextDeviceNode);
2100   PrefixLengthStr       = GetNextParamStr (&TextDeviceNode);
2101   GatewayIPStr          = GetNextParamStr (&TextDeviceNode);
2102   IPv6                  = (IPv6_DEVICE_PATH *) CreateDeviceNode (
2103                                                  MESSAGING_DEVICE_PATH,
2104                                                  MSG_IPv6_DP,
2105                                                  (UINT16) sizeof (IPv6_DEVICE_PATH)
2106                                                  );
2107 
2108   StrToIPv6Addr (&RemoteIPStr, &IPv6->RemoteIpAddress);
2109   IPv6->Protocol        = (UINT16) NetworkProtocolFromText (ProtocolStr);
2110   if (StrCmp (TypeStr, L"Static") == 0) {
2111     IPv6->IpAddressOrigin = 0;
2112   } else if (StrCmp (TypeStr, L"StatelessAutoConfigure") == 0) {
2113     IPv6->IpAddressOrigin = 1;
2114   } else {
2115     IPv6->IpAddressOrigin = 2;
2116   }
2117 
2118   StrToIPv6Addr (&LocalIPStr, &IPv6->LocalIpAddress);
2119   if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*PrefixLengthStr)) {
2120     StrToIPv6Addr (&GatewayIPStr, &IPv6->GatewayIpAddress);
2121     IPv6->PrefixLength = (UINT8) Strtoi (PrefixLengthStr);
2122   } else {
2123     ZeroMem (&IPv6->GatewayIpAddress, sizeof (IPv6->GatewayIpAddress));
2124     IPv6->PrefixLength = 0;
2125   }
2126 
2127   IPv6->LocalPort       = 0;
2128   IPv6->RemotePort      = 0;
2129 
2130   return (EFI_DEVICE_PATH_PROTOCOL *) IPv6;
2131 }
2132 
2133 /**
2134   Converts a text device path node to UART device path structure.
2135 
2136   @param TextDeviceNode  The input Text device path node.
2137 
2138   @return A pointer to the newly-created UART device path structure.
2139 
2140 **/
2141 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUart(IN CHAR16 * TextDeviceNode)2142 DevPathFromTextUart (
2143   IN CHAR16 *TextDeviceNode
2144   )
2145 {
2146   CHAR16            *BaudStr;
2147   CHAR16            *DataBitsStr;
2148   CHAR16            *ParityStr;
2149   CHAR16            *StopBitsStr;
2150   UART_DEVICE_PATH  *Uart;
2151 
2152   BaudStr         = GetNextParamStr (&TextDeviceNode);
2153   DataBitsStr     = GetNextParamStr (&TextDeviceNode);
2154   ParityStr       = GetNextParamStr (&TextDeviceNode);
2155   StopBitsStr     = GetNextParamStr (&TextDeviceNode);
2156   Uart            = (UART_DEVICE_PATH *) CreateDeviceNode (
2157                                            MESSAGING_DEVICE_PATH,
2158                                            MSG_UART_DP,
2159                                            (UINT16) sizeof (UART_DEVICE_PATH)
2160                                            );
2161 
2162   if (StrCmp (BaudStr, L"DEFAULT") == 0) {
2163     Uart->BaudRate = 115200;
2164   } else {
2165     Strtoi64 (BaudStr, &Uart->BaudRate);
2166   }
2167   Uart->DataBits  = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : Strtoi (DataBitsStr));
2168   switch (*ParityStr) {
2169   case L'D':
2170     Uart->Parity = 0;
2171     break;
2172 
2173   case L'N':
2174     Uart->Parity = 1;
2175     break;
2176 
2177   case L'E':
2178     Uart->Parity = 2;
2179     break;
2180 
2181   case L'O':
2182     Uart->Parity = 3;
2183     break;
2184 
2185   case L'M':
2186     Uart->Parity = 4;
2187     break;
2188 
2189   case L'S':
2190     Uart->Parity = 5;
2191     break;
2192 
2193   default:
2194     Uart->Parity = (UINT8) Strtoi (ParityStr);
2195     break;
2196   }
2197 
2198   if (StrCmp (StopBitsStr, L"D") == 0) {
2199     Uart->StopBits = (UINT8) 0;
2200   } else if (StrCmp (StopBitsStr, L"1") == 0) {
2201     Uart->StopBits = (UINT8) 1;
2202   } else if (StrCmp (StopBitsStr, L"1.5") == 0) {
2203     Uart->StopBits = (UINT8) 2;
2204   } else if (StrCmp (StopBitsStr, L"2") == 0) {
2205     Uart->StopBits = (UINT8) 3;
2206   } else {
2207     Uart->StopBits = (UINT8) Strtoi (StopBitsStr);
2208   }
2209 
2210   return (EFI_DEVICE_PATH_PROTOCOL *) Uart;
2211 }
2212 
2213 /**
2214   Converts a text device path node to USB class device path structure.
2215 
2216   @param TextDeviceNode  The input Text device path node.
2217   @param UsbClassText    A pointer to USB_CLASS_TEXT structure to be integrated to USB Class Text.
2218 
2219   @return A pointer to the newly-created USB class device path structure.
2220 
2221 **/
2222 EFI_DEVICE_PATH_PROTOCOL *
ConvertFromTextUsbClass(IN CHAR16 * TextDeviceNode,IN USB_CLASS_TEXT * UsbClassText)2223 ConvertFromTextUsbClass (
2224   IN CHAR16         *TextDeviceNode,
2225   IN USB_CLASS_TEXT *UsbClassText
2226   )
2227 {
2228   CHAR16                *VIDStr;
2229   CHAR16                *PIDStr;
2230   CHAR16                *ClassStr;
2231   CHAR16                *SubClassStr;
2232   CHAR16                *ProtocolStr;
2233   USB_CLASS_DEVICE_PATH *UsbClass;
2234 
2235   UsbClass    = (USB_CLASS_DEVICE_PATH *) CreateDeviceNode (
2236                                             MESSAGING_DEVICE_PATH,
2237                                             MSG_USB_CLASS_DP,
2238                                             (UINT16) sizeof (USB_CLASS_DEVICE_PATH)
2239                                             );
2240 
2241   VIDStr      = GetNextParamStr (&TextDeviceNode);
2242   PIDStr      = GetNextParamStr (&TextDeviceNode);
2243   if (UsbClassText->ClassExist) {
2244     ClassStr = GetNextParamStr (&TextDeviceNode);
2245     UsbClass->DeviceClass = (UINT8) Strtoi (ClassStr);
2246   } else {
2247     UsbClass->DeviceClass = UsbClassText->Class;
2248   }
2249   if (UsbClassText->SubClassExist) {
2250     SubClassStr = GetNextParamStr (&TextDeviceNode);
2251     UsbClass->DeviceSubClass = (UINT8) Strtoi (SubClassStr);
2252   } else {
2253     UsbClass->DeviceSubClass = UsbClassText->SubClass;
2254   }
2255 
2256   ProtocolStr = GetNextParamStr (&TextDeviceNode);
2257 
2258   UsbClass->VendorId        = (UINT16) Strtoi (VIDStr);
2259   UsbClass->ProductId       = (UINT16) Strtoi (PIDStr);
2260   UsbClass->DeviceProtocol  = (UINT8) Strtoi (ProtocolStr);
2261 
2262   return (EFI_DEVICE_PATH_PROTOCOL *) UsbClass;
2263 }
2264 
2265 
2266 /**
2267   Converts a text device path node to USB class device path structure.
2268 
2269   @param TextDeviceNode  The input Text device path node.
2270 
2271   @return A pointer to the newly-created USB class device path structure.
2272 
2273 **/
2274 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbClass(IN CHAR16 * TextDeviceNode)2275 DevPathFromTextUsbClass (
2276   IN CHAR16 *TextDeviceNode
2277   )
2278 {
2279   USB_CLASS_TEXT  UsbClassText;
2280 
2281   UsbClassText.ClassExist    = TRUE;
2282   UsbClassText.SubClassExist = TRUE;
2283 
2284   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2285 }
2286 
2287 /**
2288   Converts a text device path node to USB audio device path structure.
2289 
2290   @param TextDeviceNode  The input Text device path node.
2291 
2292   @return A pointer to the newly-created USB audio device path structure.
2293 
2294 **/
2295 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbAudio(IN CHAR16 * TextDeviceNode)2296 DevPathFromTextUsbAudio (
2297   IN CHAR16 *TextDeviceNode
2298   )
2299 {
2300   USB_CLASS_TEXT  UsbClassText;
2301 
2302   UsbClassText.ClassExist    = FALSE;
2303   UsbClassText.Class         = USB_CLASS_AUDIO;
2304   UsbClassText.SubClassExist = TRUE;
2305 
2306   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2307 }
2308 
2309 /**
2310   Converts a text device path node to USB CDC Control device path structure.
2311 
2312   @param TextDeviceNode  The input Text device path node.
2313 
2314   @return A pointer to the newly-created USB CDC Control device path structure.
2315 
2316 **/
2317 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbCDCControl(IN CHAR16 * TextDeviceNode)2318 DevPathFromTextUsbCDCControl (
2319   IN CHAR16 *TextDeviceNode
2320   )
2321 {
2322   USB_CLASS_TEXT  UsbClassText;
2323 
2324   UsbClassText.ClassExist    = FALSE;
2325   UsbClassText.Class         = USB_CLASS_CDCCONTROL;
2326   UsbClassText.SubClassExist = TRUE;
2327 
2328   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2329 }
2330 
2331 /**
2332   Converts a text device path node to USB HID device path structure.
2333 
2334   @param TextDeviceNode  The input Text device path node.
2335 
2336   @return A pointer to the newly-created USB HID device path structure.
2337 
2338 **/
2339 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbHID(IN CHAR16 * TextDeviceNode)2340 DevPathFromTextUsbHID (
2341   IN CHAR16 *TextDeviceNode
2342   )
2343 {
2344   USB_CLASS_TEXT  UsbClassText;
2345 
2346   UsbClassText.ClassExist    = FALSE;
2347   UsbClassText.Class         = USB_CLASS_HID;
2348   UsbClassText.SubClassExist = TRUE;
2349 
2350   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2351 }
2352 
2353 /**
2354   Converts a text device path node to USB Image device path structure.
2355 
2356   @param TextDeviceNode  The input Text device path node.
2357 
2358   @return A pointer to the newly-created USB Image device path structure.
2359 
2360 **/
2361 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbImage(IN CHAR16 * TextDeviceNode)2362 DevPathFromTextUsbImage (
2363   IN CHAR16 *TextDeviceNode
2364   )
2365 {
2366   USB_CLASS_TEXT  UsbClassText;
2367 
2368   UsbClassText.ClassExist    = FALSE;
2369   UsbClassText.Class         = USB_CLASS_IMAGE;
2370   UsbClassText.SubClassExist = TRUE;
2371 
2372   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2373 }
2374 
2375 /**
2376   Converts a text device path node to USB Print device path structure.
2377 
2378   @param TextDeviceNode  The input Text device path node.
2379 
2380   @return A pointer to the newly-created USB Print device path structure.
2381 
2382 **/
2383 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbPrinter(IN CHAR16 * TextDeviceNode)2384 DevPathFromTextUsbPrinter (
2385   IN CHAR16 *TextDeviceNode
2386   )
2387 {
2388   USB_CLASS_TEXT  UsbClassText;
2389 
2390   UsbClassText.ClassExist    = FALSE;
2391   UsbClassText.Class         = USB_CLASS_PRINTER;
2392   UsbClassText.SubClassExist = TRUE;
2393 
2394   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2395 }
2396 
2397 /**
2398   Converts a text device path node to USB mass storage device path structure.
2399 
2400   @param TextDeviceNode  The input Text device path node.
2401 
2402   @return A pointer to the newly-created USB mass storage device path structure.
2403 
2404 **/
2405 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbMassStorage(IN CHAR16 * TextDeviceNode)2406 DevPathFromTextUsbMassStorage (
2407   IN CHAR16 *TextDeviceNode
2408   )
2409 {
2410   USB_CLASS_TEXT  UsbClassText;
2411 
2412   UsbClassText.ClassExist    = FALSE;
2413   UsbClassText.Class         = USB_CLASS_MASS_STORAGE;
2414   UsbClassText.SubClassExist = TRUE;
2415 
2416   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2417 }
2418 
2419 /**
2420   Converts a text device path node to USB HUB device path structure.
2421 
2422   @param TextDeviceNode  The input Text device path node.
2423 
2424   @return A pointer to the newly-created USB HUB device path structure.
2425 
2426 **/
2427 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbHub(IN CHAR16 * TextDeviceNode)2428 DevPathFromTextUsbHub (
2429   IN CHAR16 *TextDeviceNode
2430   )
2431 {
2432   USB_CLASS_TEXT  UsbClassText;
2433 
2434   UsbClassText.ClassExist    = FALSE;
2435   UsbClassText.Class         = USB_CLASS_HUB;
2436   UsbClassText.SubClassExist = TRUE;
2437 
2438   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2439 }
2440 
2441 /**
2442   Converts a text device path node to USB CDC data device path structure.
2443 
2444   @param TextDeviceNode  The input Text device path node.
2445 
2446   @return A pointer to the newly-created USB CDC data device path structure.
2447 
2448 **/
2449 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbCDCData(IN CHAR16 * TextDeviceNode)2450 DevPathFromTextUsbCDCData (
2451   IN CHAR16 *TextDeviceNode
2452   )
2453 {
2454   USB_CLASS_TEXT  UsbClassText;
2455 
2456   UsbClassText.ClassExist    = FALSE;
2457   UsbClassText.Class         = USB_CLASS_CDCDATA;
2458   UsbClassText.SubClassExist = TRUE;
2459 
2460   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2461 }
2462 
2463 /**
2464   Converts a text device path node to USB smart card device path structure.
2465 
2466   @param TextDeviceNode  The input Text device path node.
2467 
2468   @return A pointer to the newly-created USB smart card device path structure.
2469 
2470 **/
2471 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbSmartCard(IN CHAR16 * TextDeviceNode)2472 DevPathFromTextUsbSmartCard (
2473   IN CHAR16 *TextDeviceNode
2474   )
2475 {
2476   USB_CLASS_TEXT  UsbClassText;
2477 
2478   UsbClassText.ClassExist    = FALSE;
2479   UsbClassText.Class         = USB_CLASS_SMART_CARD;
2480   UsbClassText.SubClassExist = TRUE;
2481 
2482   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2483 }
2484 
2485 /**
2486   Converts a text device path node to USB video device path structure.
2487 
2488   @param TextDeviceNode  The input Text device path node.
2489 
2490   @return A pointer to the newly-created USB video device path structure.
2491 
2492 **/
2493 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbVideo(IN CHAR16 * TextDeviceNode)2494 DevPathFromTextUsbVideo (
2495   IN CHAR16 *TextDeviceNode
2496   )
2497 {
2498   USB_CLASS_TEXT  UsbClassText;
2499 
2500   UsbClassText.ClassExist    = FALSE;
2501   UsbClassText.Class         = USB_CLASS_VIDEO;
2502   UsbClassText.SubClassExist = TRUE;
2503 
2504   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2505 }
2506 
2507 /**
2508   Converts a text device path node to USB diagnostic device path structure.
2509 
2510   @param TextDeviceNode  The input Text device path node.
2511 
2512   @return A pointer to the newly-created USB diagnostic device path structure.
2513 
2514 **/
2515 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbDiagnostic(IN CHAR16 * TextDeviceNode)2516 DevPathFromTextUsbDiagnostic (
2517   IN CHAR16 *TextDeviceNode
2518   )
2519 {
2520   USB_CLASS_TEXT  UsbClassText;
2521 
2522   UsbClassText.ClassExist    = FALSE;
2523   UsbClassText.Class         = USB_CLASS_DIAGNOSTIC;
2524   UsbClassText.SubClassExist = TRUE;
2525 
2526   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2527 }
2528 
2529 /**
2530   Converts a text device path node to USB wireless device path structure.
2531 
2532   @param TextDeviceNode  The input Text device path node.
2533 
2534   @return A pointer to the newly-created USB wireless device path structure.
2535 
2536 **/
2537 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbWireless(IN CHAR16 * TextDeviceNode)2538 DevPathFromTextUsbWireless (
2539   IN CHAR16 *TextDeviceNode
2540   )
2541 {
2542   USB_CLASS_TEXT  UsbClassText;
2543 
2544   UsbClassText.ClassExist    = FALSE;
2545   UsbClassText.Class         = USB_CLASS_WIRELESS;
2546   UsbClassText.SubClassExist = TRUE;
2547 
2548   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2549 }
2550 
2551 /**
2552   Converts a text device path node to USB device firmware update device path structure.
2553 
2554   @param TextDeviceNode  The input Text device path node.
2555 
2556   @return A pointer to the newly-created USB device firmware update device path structure.
2557 
2558 **/
2559 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbDeviceFirmwareUpdate(IN CHAR16 * TextDeviceNode)2560 DevPathFromTextUsbDeviceFirmwareUpdate (
2561   IN CHAR16 *TextDeviceNode
2562   )
2563 {
2564   USB_CLASS_TEXT  UsbClassText;
2565 
2566   UsbClassText.ClassExist    = FALSE;
2567   UsbClassText.Class         = USB_CLASS_RESERVE;
2568   UsbClassText.SubClassExist = FALSE;
2569   UsbClassText.SubClass      = USB_SUBCLASS_FW_UPDATE;
2570 
2571   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2572 }
2573 
2574 /**
2575   Converts a text device path node to USB IRDA bridge device path structure.
2576 
2577   @param TextDeviceNode  The input Text device path node.
2578 
2579   @return A pointer to the newly-created USB IRDA bridge device path structure.
2580 
2581 **/
2582 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbIrdaBridge(IN CHAR16 * TextDeviceNode)2583 DevPathFromTextUsbIrdaBridge (
2584   IN CHAR16 *TextDeviceNode
2585   )
2586 {
2587   USB_CLASS_TEXT  UsbClassText;
2588 
2589   UsbClassText.ClassExist    = FALSE;
2590   UsbClassText.Class         = USB_CLASS_RESERVE;
2591   UsbClassText.SubClassExist = FALSE;
2592   UsbClassText.SubClass      = USB_SUBCLASS_IRDA_BRIDGE;
2593 
2594   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2595 }
2596 
2597 /**
2598   Converts a text device path node to USB text and measurement device path structure.
2599 
2600   @param TextDeviceNode  The input Text device path node.
2601 
2602   @return A pointer to the newly-created USB text and measurement device path structure.
2603 
2604 **/
2605 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbTestAndMeasurement(IN CHAR16 * TextDeviceNode)2606 DevPathFromTextUsbTestAndMeasurement (
2607   IN CHAR16 *TextDeviceNode
2608   )
2609 {
2610   USB_CLASS_TEXT  UsbClassText;
2611 
2612   UsbClassText.ClassExist    = FALSE;
2613   UsbClassText.Class         = USB_CLASS_RESERVE;
2614   UsbClassText.SubClassExist = FALSE;
2615   UsbClassText.SubClass      = USB_SUBCLASS_TEST;
2616 
2617   return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2618 }
2619 
2620 /**
2621   Converts a text device path node to USB WWID device path structure.
2622 
2623   @param TextDeviceNode  The input Text device path node.
2624 
2625   @return A pointer to the newly-created USB WWID device path structure.
2626 
2627 **/
2628 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUsbWwid(IN CHAR16 * TextDeviceNode)2629 DevPathFromTextUsbWwid (
2630   IN CHAR16 *TextDeviceNode
2631   )
2632 {
2633   CHAR16                *VIDStr;
2634   CHAR16                *PIDStr;
2635   CHAR16                *InterfaceNumStr;
2636   CHAR16                *SerialNumberStr;
2637   USB_WWID_DEVICE_PATH  *UsbWwid;
2638   UINTN                 SerialNumberStrLen;
2639 
2640   VIDStr                   = GetNextParamStr (&TextDeviceNode);
2641   PIDStr                   = GetNextParamStr (&TextDeviceNode);
2642   InterfaceNumStr          = GetNextParamStr (&TextDeviceNode);
2643   SerialNumberStr          = GetNextParamStr (&TextDeviceNode);
2644   SerialNumberStrLen       = StrLen (SerialNumberStr);
2645   if (SerialNumberStrLen >= 2 &&
2646       SerialNumberStr[0] == L'\"' &&
2647       SerialNumberStr[SerialNumberStrLen - 1] == L'\"'
2648     ) {
2649     SerialNumberStr[SerialNumberStrLen - 1] = L'\0';
2650     SerialNumberStr++;
2651     SerialNumberStrLen -= 2;
2652   }
2653   UsbWwid                  = (USB_WWID_DEVICE_PATH *) CreateDeviceNode (
2654                                                          MESSAGING_DEVICE_PATH,
2655                                                          MSG_USB_WWID_DP,
2656                                                          (UINT16) (sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16))
2657                                                          );
2658   UsbWwid->VendorId        = (UINT16) Strtoi (VIDStr);
2659   UsbWwid->ProductId       = (UINT16) Strtoi (PIDStr);
2660   UsbWwid->InterfaceNumber = (UINT16) Strtoi (InterfaceNumStr);
2661 
2662   //
2663   // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.
2664   // Therefore, the '\0' will not be copied.
2665   //
2666   CopyMem (
2667     (UINT8 *) UsbWwid + sizeof (USB_WWID_DEVICE_PATH),
2668     SerialNumberStr,
2669     SerialNumberStrLen * sizeof (CHAR16)
2670     );
2671 
2672   return (EFI_DEVICE_PATH_PROTOCOL *) UsbWwid;
2673 }
2674 
2675 /**
2676   Converts a text device path node to Logic Unit device path structure.
2677 
2678   @param TextDeviceNode  The input Text device path node.
2679 
2680   @return A pointer to the newly-created Logic Unit device path structure.
2681 
2682 **/
2683 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUnit(IN CHAR16 * TextDeviceNode)2684 DevPathFromTextUnit (
2685   IN CHAR16 *TextDeviceNode
2686   )
2687 {
2688   CHAR16                          *LunStr;
2689   DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
2690 
2691   LunStr      = GetNextParamStr (&TextDeviceNode);
2692   LogicalUnit = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) CreateDeviceNode (
2693                                                       MESSAGING_DEVICE_PATH,
2694                                                       MSG_DEVICE_LOGICAL_UNIT_DP,
2695                                                       (UINT16) sizeof (DEVICE_LOGICAL_UNIT_DEVICE_PATH)
2696                                                       );
2697 
2698   LogicalUnit->Lun  = (UINT8) Strtoi (LunStr);
2699 
2700   return (EFI_DEVICE_PATH_PROTOCOL *) LogicalUnit;
2701 }
2702 
2703 /**
2704   Converts a text device path node to iSCSI device path structure.
2705 
2706   @param TextDeviceNode  The input Text device path node.
2707 
2708   @return A pointer to the newly-created iSCSI device path structure.
2709 
2710 **/
2711 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextiSCSI(IN CHAR16 * TextDeviceNode)2712 DevPathFromTextiSCSI (
2713   IN CHAR16 *TextDeviceNode
2714   )
2715 {
2716   UINT16                      Options;
2717   CHAR16                      *NameStr;
2718   CHAR16                      *PortalGroupStr;
2719   CHAR16                      *LunStr;
2720   CHAR16                      *HeaderDigestStr;
2721   CHAR16                      *DataDigestStr;
2722   CHAR16                      *AuthenticationStr;
2723   CHAR16                      *ProtocolStr;
2724   CHAR8                       *AsciiStr;
2725   ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;
2726 
2727   NameStr           = GetNextParamStr (&TextDeviceNode);
2728   PortalGroupStr    = GetNextParamStr (&TextDeviceNode);
2729   LunStr            = GetNextParamStr (&TextDeviceNode);
2730   HeaderDigestStr   = GetNextParamStr (&TextDeviceNode);
2731   DataDigestStr     = GetNextParamStr (&TextDeviceNode);
2732   AuthenticationStr = GetNextParamStr (&TextDeviceNode);
2733   ProtocolStr       = GetNextParamStr (&TextDeviceNode);
2734   ISCSIDevPath      = (ISCSI_DEVICE_PATH_WITH_NAME *) CreateDeviceNode (
2735                                                         MESSAGING_DEVICE_PATH,
2736                                                         MSG_ISCSI_DP,
2737                                                         (UINT16) (sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + StrLen (NameStr))
2738                                                         );
2739 
2740   AsciiStr = ISCSIDevPath->TargetName;
2741   StrToAscii (NameStr, &AsciiStr);
2742 
2743   ISCSIDevPath->TargetPortalGroupTag = (UINT16) Strtoi (PortalGroupStr);
2744   Strtoi64 (LunStr, &ISCSIDevPath->Lun);
2745 
2746   Options = 0x0000;
2747   if (StrCmp (HeaderDigestStr, L"CRC32C") == 0) {
2748     Options |= 0x0002;
2749   }
2750 
2751   if (StrCmp (DataDigestStr, L"CRC32C") == 0) {
2752     Options |= 0x0008;
2753   }
2754 
2755   if (StrCmp (AuthenticationStr, L"None") == 0) {
2756     Options |= 0x0800;
2757   }
2758 
2759   if (StrCmp (AuthenticationStr, L"CHAP_UNI") == 0) {
2760     Options |= 0x1000;
2761   }
2762 
2763   ISCSIDevPath->LoginOption      = (UINT16) Options;
2764 
2765   ISCSIDevPath->NetworkProtocol  = (UINT16) StrCmp (ProtocolStr, L"TCP");
2766 
2767   return (EFI_DEVICE_PATH_PROTOCOL *) ISCSIDevPath;
2768 }
2769 
2770 /**
2771   Converts a text device path node to VLAN device path structure.
2772 
2773   @param TextDeviceNode  The input Text device path node.
2774 
2775   @return A pointer to the newly-created VLAN device path structure.
2776 
2777 **/
2778 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextVlan(IN CHAR16 * TextDeviceNode)2779 DevPathFromTextVlan (
2780   IN CHAR16 *TextDeviceNode
2781   )
2782 {
2783   CHAR16            *VlanStr;
2784   VLAN_DEVICE_PATH  *Vlan;
2785 
2786   VlanStr = GetNextParamStr (&TextDeviceNode);
2787   Vlan    = (VLAN_DEVICE_PATH *) CreateDeviceNode (
2788                                    MESSAGING_DEVICE_PATH,
2789                                    MSG_VLAN_DP,
2790                                    (UINT16) sizeof (VLAN_DEVICE_PATH)
2791                                    );
2792 
2793   Vlan->VlanId = (UINT16) Strtoi (VlanStr);
2794 
2795   return (EFI_DEVICE_PATH_PROTOCOL *) Vlan;
2796 }
2797 
2798 /**
2799   Converts a text device path node to Bluetooth device path structure.
2800 
2801   @param TextDeviceNode  The input Text device path node.
2802 
2803   @return A pointer to the newly-created Bluetooth device path structure.
2804 
2805 **/
2806 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextBluetooth(IN CHAR16 * TextDeviceNode)2807 DevPathFromTextBluetooth (
2808   IN CHAR16 *TextDeviceNode
2809   )
2810 {
2811   CHAR16                  *BluetoothStr;
2812   CHAR16                  *Walker;
2813   CHAR16                  *TempNumBuffer;
2814   UINTN                   TempBufferSize;
2815   INT32                   Index;
2816   BLUETOOTH_DEVICE_PATH   *BluetoothDp;
2817 
2818   BluetoothStr = GetNextParamStr (&TextDeviceNode);
2819   BluetoothDp = (BLUETOOTH_DEVICE_PATH *) CreateDeviceNode (
2820                                    MESSAGING_DEVICE_PATH,
2821                                    MSG_BLUETOOTH_DP,
2822                                    (UINT16) sizeof (BLUETOOTH_DEVICE_PATH)
2823                                    );
2824 
2825   Index = sizeof (BLUETOOTH_ADDRESS) - 1;
2826   Walker = BluetoothStr;
2827   while (!IS_NULL(*Walker) && Index >= 0) {
2828     TempBufferSize = 2 * sizeof(CHAR16) + StrSize(L"0x");
2829     TempNumBuffer = AllocateZeroPool (TempBufferSize);
2830     if (TempNumBuffer == NULL) {
2831       break;
2832     }
2833     StrCpyS (TempNumBuffer, TempBufferSize / sizeof (CHAR16), L"0x");
2834     StrnCatS (TempNumBuffer, TempBufferSize / sizeof (CHAR16), Walker, 2);
2835     BluetoothDp->BD_ADDR.Address[Index] = (UINT8)Strtoi (TempNumBuffer);
2836     FreePool (TempNumBuffer);
2837     Walker += 2;
2838     Index--;
2839   }
2840 
2841   return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothDp;
2842 }
2843 
2844 /**
2845   Converts a text device path node to Wi-Fi device path structure.
2846 
2847   @param TextDeviceNode  The input Text device path node.
2848 
2849   @return A pointer to the newly-created Wi-Fi device path structure.
2850 
2851 **/
2852 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextWiFi(IN CHAR16 * TextDeviceNode)2853 DevPathFromTextWiFi (
2854   IN CHAR16 *TextDeviceNode
2855   )
2856 {
2857   CHAR16                *SSIdStr;
2858   CHAR8                 AsciiStr[33];
2859   UINTN                 DataLen;
2860   WIFI_DEVICE_PATH      *WiFiDp;
2861 
2862   SSIdStr = GetNextParamStr (&TextDeviceNode);
2863   WiFiDp  = (WIFI_DEVICE_PATH *) CreateDeviceNode (
2864                                    MESSAGING_DEVICE_PATH,
2865                                    MSG_WIFI_DP,
2866                                    (UINT16) sizeof (WIFI_DEVICE_PATH)
2867                                    );
2868 
2869   if (NULL != SSIdStr) {
2870     DataLen = StrLen (SSIdStr);
2871     if (StrLen (SSIdStr) > 32) {
2872       SSIdStr[32] = L'\0';
2873       DataLen     = 32;
2874     }
2875 
2876     UnicodeStrToAsciiStrS (SSIdStr, AsciiStr, sizeof (AsciiStr));
2877     CopyMem (WiFiDp->SSId, AsciiStr, DataLen);
2878   }
2879 
2880   return (EFI_DEVICE_PATH_PROTOCOL *) WiFiDp;
2881 }
2882 
2883 /**
2884   Converts a text device path node to URI device path structure.
2885 
2886   @param TextDeviceNode  The input Text device path node.
2887 
2888   @return A pointer to the newly-created URI device path structure.
2889 
2890 **/
2891 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextUri(IN CHAR16 * TextDeviceNode)2892 DevPathFromTextUri (
2893   IN CHAR16 *TextDeviceNode
2894   )
2895 {
2896   CHAR16           *UriStr;
2897   UINTN            UriLength;
2898   URI_DEVICE_PATH  *Uri;
2899 
2900   UriStr = GetNextParamStr (&TextDeviceNode);
2901   UriLength = StrnLenS (UriStr, MAX_UINT16 - sizeof (URI_DEVICE_PATH));
2902   Uri    = (URI_DEVICE_PATH *) CreateDeviceNode (
2903                                  MESSAGING_DEVICE_PATH,
2904                                  MSG_URI_DP,
2905                                  (UINT16) (sizeof (URI_DEVICE_PATH) + UriLength)
2906                                  );
2907 
2908   while (UriLength-- != 0) {
2909     Uri->Uri[UriLength] = (CHAR8) UriStr[UriLength];
2910   }
2911 
2912   return (EFI_DEVICE_PATH_PROTOCOL *) Uri;
2913 }
2914 
2915 /**
2916   Converts a media text device path node to media device path structure.
2917 
2918   @param TextDeviceNode  The input Text device path node.
2919 
2920   @return A pointer to media device path structure.
2921 
2922 **/
2923 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextMediaPath(IN CHAR16 * TextDeviceNode)2924 DevPathFromTextMediaPath (
2925   IN CHAR16 *TextDeviceNode
2926   )
2927 {
2928   return DevPathFromTextGenericPath (MEDIA_DEVICE_PATH, TextDeviceNode);
2929 }
2930 
2931 /**
2932   Converts a text device path node to HD device path structure.
2933 
2934   @param TextDeviceNode  The input Text device path node.
2935 
2936   @return A pointer to the newly-created HD device path structure.
2937 
2938 **/
2939 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextHD(IN CHAR16 * TextDeviceNode)2940 DevPathFromTextHD (
2941   IN CHAR16 *TextDeviceNode
2942   )
2943 {
2944   CHAR16                *PartitionStr;
2945   CHAR16                *TypeStr;
2946   CHAR16                *SignatureStr;
2947   CHAR16                *StartStr;
2948   CHAR16                *SizeStr;
2949   UINT32                Signature32;
2950   EFI_GUID              SignatureGuid;
2951   HARDDRIVE_DEVICE_PATH *Hd;
2952 
2953   PartitionStr        = GetNextParamStr (&TextDeviceNode);
2954   TypeStr             = GetNextParamStr (&TextDeviceNode);
2955   SignatureStr        = GetNextParamStr (&TextDeviceNode);
2956   StartStr            = GetNextParamStr (&TextDeviceNode);
2957   SizeStr             = GetNextParamStr (&TextDeviceNode);
2958   Hd                  = (HARDDRIVE_DEVICE_PATH *) CreateDeviceNode (
2959                                                     MEDIA_DEVICE_PATH,
2960                                                     MEDIA_HARDDRIVE_DP,
2961                                                     (UINT16) sizeof (HARDDRIVE_DEVICE_PATH)
2962                                                     );
2963 
2964   Hd->PartitionNumber = (UINT32) Strtoi (PartitionStr);
2965 
2966   ZeroMem (Hd->Signature, 16);
2967   Hd->MBRType = (UINT8) 0;
2968 
2969   if (StrCmp (TypeStr, L"MBR") == 0) {
2970     Hd->SignatureType = SIGNATURE_TYPE_MBR;
2971     Hd->MBRType       = 0x01;
2972 
2973     Signature32       = (UINT32) Strtoi (SignatureStr);
2974     CopyMem (Hd->Signature, &Signature32, sizeof (UINT32));
2975   } else if (StrCmp (TypeStr, L"GPT") == 0) {
2976     Hd->SignatureType = SIGNATURE_TYPE_GUID;
2977     Hd->MBRType       = 0x02;
2978 
2979     StrToGuid (SignatureStr, &SignatureGuid);
2980     CopyMem (Hd->Signature, &SignatureGuid, sizeof (EFI_GUID));
2981   } else {
2982     Hd->SignatureType = (UINT8) Strtoi (TypeStr);
2983   }
2984 
2985   Strtoi64 (StartStr, &Hd->PartitionStart);
2986   Strtoi64 (SizeStr, &Hd->PartitionSize);
2987 
2988   return (EFI_DEVICE_PATH_PROTOCOL *) Hd;
2989 }
2990 
2991 /**
2992   Converts a text device path node to CDROM device path structure.
2993 
2994   @param TextDeviceNode  The input Text device path node.
2995 
2996   @return A pointer to the newly-created CDROM device path structure.
2997 
2998 **/
2999 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextCDROM(IN CHAR16 * TextDeviceNode)3000 DevPathFromTextCDROM (
3001   IN CHAR16 *TextDeviceNode
3002   )
3003 {
3004   CHAR16            *EntryStr;
3005   CHAR16            *StartStr;
3006   CHAR16            *SizeStr;
3007   CDROM_DEVICE_PATH *CDROMDevPath;
3008 
3009   EntryStr              = GetNextParamStr (&TextDeviceNode);
3010   StartStr              = GetNextParamStr (&TextDeviceNode);
3011   SizeStr               = GetNextParamStr (&TextDeviceNode);
3012   CDROMDevPath          = (CDROM_DEVICE_PATH *) CreateDeviceNode (
3013                                                   MEDIA_DEVICE_PATH,
3014                                                   MEDIA_CDROM_DP,
3015                                                   (UINT16) sizeof (CDROM_DEVICE_PATH)
3016                                                   );
3017 
3018   CDROMDevPath->BootEntry = (UINT32) Strtoi (EntryStr);
3019   Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
3020   Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
3021 
3022   return (EFI_DEVICE_PATH_PROTOCOL *) CDROMDevPath;
3023 }
3024 
3025 /**
3026   Converts a text device path node to Vendor-defined media device path structure.
3027 
3028   @param TextDeviceNode  The input Text device path node.
3029 
3030   @return A pointer to the newly-created Vendor-defined media device path structure.
3031 
3032 **/
3033 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextVenMedia(IN CHAR16 * TextDeviceNode)3034 DevPathFromTextVenMedia (
3035   IN CHAR16 *TextDeviceNode
3036   )
3037 {
3038   return ConvertFromTextVendor (
3039            TextDeviceNode,
3040            MEDIA_DEVICE_PATH,
3041            MEDIA_VENDOR_DP
3042            );
3043 }
3044 
3045 /**
3046   Converts a text device path node to File device path structure.
3047 
3048   @param TextDeviceNode  The input Text device path node.
3049 
3050   @return A pointer to the newly-created File device path structure.
3051 
3052 **/
3053 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextFilePath(IN CHAR16 * TextDeviceNode)3054 DevPathFromTextFilePath (
3055   IN CHAR16 *TextDeviceNode
3056   )
3057 {
3058   FILEPATH_DEVICE_PATH  *File;
3059 
3060   File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (
3061                                     MEDIA_DEVICE_PATH,
3062                                     MEDIA_FILEPATH_DP,
3063                                     (UINT16) (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2)
3064                                     );
3065 
3066   StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
3067 
3068   return (EFI_DEVICE_PATH_PROTOCOL *) File;
3069 }
3070 
3071 /**
3072   Converts a text device path node to Media protocol device path structure.
3073 
3074   @param TextDeviceNode  The input Text device path node.
3075 
3076   @return A pointer to the newly-created Media protocol device path structure.
3077 
3078 **/
3079 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextMedia(IN CHAR16 * TextDeviceNode)3080 DevPathFromTextMedia (
3081   IN CHAR16 *TextDeviceNode
3082   )
3083 {
3084   CHAR16                      *GuidStr;
3085   MEDIA_PROTOCOL_DEVICE_PATH  *Media;
3086 
3087   GuidStr = GetNextParamStr (&TextDeviceNode);
3088   Media   = (MEDIA_PROTOCOL_DEVICE_PATH *) CreateDeviceNode (
3089                                              MEDIA_DEVICE_PATH,
3090                                              MEDIA_PROTOCOL_DP,
3091                                              (UINT16) sizeof (MEDIA_PROTOCOL_DEVICE_PATH)
3092                                              );
3093 
3094   StrToGuid (GuidStr, &Media->Protocol);
3095 
3096   return (EFI_DEVICE_PATH_PROTOCOL *) Media;
3097 }
3098 
3099 /**
3100   Converts a text device path node to firmware volume device path structure.
3101 
3102   @param TextDeviceNode  The input Text device path node.
3103 
3104   @return A pointer to the newly-created firmware volume device path structure.
3105 
3106 **/
3107 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextFv(IN CHAR16 * TextDeviceNode)3108 DevPathFromTextFv (
3109   IN CHAR16 *TextDeviceNode
3110   )
3111 {
3112   CHAR16                    *GuidStr;
3113   MEDIA_FW_VOL_DEVICE_PATH  *Fv;
3114 
3115   GuidStr = GetNextParamStr (&TextDeviceNode);
3116   Fv      = (MEDIA_FW_VOL_DEVICE_PATH *) CreateDeviceNode (
3117                                            MEDIA_DEVICE_PATH,
3118                                            MEDIA_PIWG_FW_VOL_DP,
3119                                            (UINT16) sizeof (MEDIA_FW_VOL_DEVICE_PATH)
3120                                            );
3121 
3122   StrToGuid (GuidStr, &Fv->FvName);
3123 
3124   return (EFI_DEVICE_PATH_PROTOCOL *) Fv;
3125 }
3126 
3127 /**
3128   Converts a text device path node to firmware file device path structure.
3129 
3130   @param TextDeviceNode  The input Text device path node.
3131 
3132   @return A pointer to the newly-created firmware file device path structure.
3133 
3134 **/
3135 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextFvFile(IN CHAR16 * TextDeviceNode)3136 DevPathFromTextFvFile (
3137   IN CHAR16 *TextDeviceNode
3138   )
3139 {
3140   CHAR16                             *GuidStr;
3141   MEDIA_FW_VOL_FILEPATH_DEVICE_PATH  *FvFile;
3142 
3143   GuidStr = GetNextParamStr (&TextDeviceNode);
3144   FvFile  = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) CreateDeviceNode (
3145                                                     MEDIA_DEVICE_PATH,
3146                                                     MEDIA_PIWG_FW_FILE_DP,
3147                                                     (UINT16) sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)
3148                                                     );
3149 
3150   StrToGuid (GuidStr, &FvFile->FvFileName);
3151 
3152   return (EFI_DEVICE_PATH_PROTOCOL *) FvFile;
3153 }
3154 
3155 /**
3156   Converts a text device path node to text relative offset device path structure.
3157 
3158   @param TextDeviceNode  The input Text device path node.
3159 
3160   @return A pointer to the newly-created Text device path structure.
3161 
3162 **/
3163 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextRelativeOffsetRange(IN CHAR16 * TextDeviceNode)3164 DevPathFromTextRelativeOffsetRange (
3165   IN CHAR16 *TextDeviceNode
3166   )
3167 {
3168   CHAR16                                  *StartingOffsetStr;
3169   CHAR16                                  *EndingOffsetStr;
3170   MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;
3171 
3172   StartingOffsetStr = GetNextParamStr (&TextDeviceNode);
3173   EndingOffsetStr   = GetNextParamStr (&TextDeviceNode);
3174   Offset            = (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *) CreateDeviceNode (
3175                                                                     MEDIA_DEVICE_PATH,
3176                                                                     MEDIA_RELATIVE_OFFSET_RANGE_DP,
3177                                                                     (UINT16) sizeof (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH)
3178                                                                     );
3179 
3180   Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
3181   Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
3182 
3183   return (EFI_DEVICE_PATH_PROTOCOL *) Offset;
3184 }
3185 
3186 /**
3187   Converts a text device path node to text ram disk device path structure.
3188 
3189   @param TextDeviceNode  The input Text device path node.
3190 
3191   @return A pointer to the newly-created Text device path structure.
3192 
3193 **/
3194 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextRamDisk(IN CHAR16 * TextDeviceNode)3195 DevPathFromTextRamDisk (
3196   IN CHAR16 *TextDeviceNode
3197   )
3198 {
3199   CHAR16                                  *StartingAddrStr;
3200   CHAR16                                  *EndingAddrStr;
3201   CHAR16                                  *TypeGuidStr;
3202   CHAR16                                  *InstanceStr;
3203   MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;
3204   UINT64                                  StartingAddr;
3205   UINT64                                  EndingAddr;
3206 
3207   StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3208   EndingAddrStr   = GetNextParamStr (&TextDeviceNode);
3209   InstanceStr     = GetNextParamStr (&TextDeviceNode);
3210   TypeGuidStr     = GetNextParamStr (&TextDeviceNode);
3211   RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3212                                                      MEDIA_DEVICE_PATH,
3213                                                      MEDIA_RAM_DISK_DP,
3214                                                      (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3215                                                      );
3216 
3217   Strtoi64 (StartingAddrStr, &StartingAddr);
3218   WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3219   Strtoi64 (EndingAddrStr, &EndingAddr);
3220   WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3221   RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3222   StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);
3223 
3224   return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3225 }
3226 
3227 /**
3228   Converts a text device path node to text virtual disk device path structure.
3229 
3230   @param TextDeviceNode  The input Text device path node.
3231 
3232   @return A pointer to the newly-created Text device path structure.
3233 
3234 **/
3235 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextVirtualDisk(IN CHAR16 * TextDeviceNode)3236 DevPathFromTextVirtualDisk (
3237   IN CHAR16 *TextDeviceNode
3238   )
3239 {
3240   CHAR16                                  *StartingAddrStr;
3241   CHAR16                                  *EndingAddrStr;
3242   CHAR16                                  *InstanceStr;
3243   MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;
3244   UINT64                                  StartingAddr;
3245   UINT64                                  EndingAddr;
3246 
3247   StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3248   EndingAddrStr   = GetNextParamStr (&TextDeviceNode);
3249   InstanceStr     = GetNextParamStr (&TextDeviceNode);
3250 
3251   RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3252                                                      MEDIA_DEVICE_PATH,
3253                                                      MEDIA_RAM_DISK_DP,
3254                                                      (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3255                                                      );
3256 
3257   Strtoi64 (StartingAddrStr, &StartingAddr);
3258   WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3259   Strtoi64 (EndingAddrStr, &EndingAddr);
3260   WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3261   RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3262   CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);
3263 
3264   return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3265 }
3266 
3267 /**
3268   Converts a text device path node to text virtual cd device path structure.
3269 
3270   @param TextDeviceNode  The input Text device path node.
3271 
3272   @return A pointer to the newly-created Text device path structure.
3273 
3274 **/
3275 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextVirtualCd(IN CHAR16 * TextDeviceNode)3276 DevPathFromTextVirtualCd (
3277   IN CHAR16 *TextDeviceNode
3278   )
3279 {
3280   CHAR16                                  *StartingAddrStr;
3281   CHAR16                                  *EndingAddrStr;
3282   CHAR16                                  *InstanceStr;
3283   MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;
3284   UINT64                                  StartingAddr;
3285   UINT64                                  EndingAddr;
3286 
3287   StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3288   EndingAddrStr   = GetNextParamStr (&TextDeviceNode);
3289   InstanceStr     = GetNextParamStr (&TextDeviceNode);
3290 
3291   RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3292                                                      MEDIA_DEVICE_PATH,
3293                                                      MEDIA_RAM_DISK_DP,
3294                                                      (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3295                                                      );
3296 
3297   Strtoi64 (StartingAddrStr, &StartingAddr);
3298   WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3299   Strtoi64 (EndingAddrStr, &EndingAddr);
3300   WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3301   RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3302   CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);
3303 
3304   return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3305 }
3306 
3307 /**
3308   Converts a text device path node to text persistent virtual disk device path structure.
3309 
3310   @param TextDeviceNode  The input Text device path node.
3311 
3312   @return A pointer to the newly-created Text device path structure.
3313 
3314 **/
3315 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextPersistentVirtualDisk(IN CHAR16 * TextDeviceNode)3316 DevPathFromTextPersistentVirtualDisk (
3317   IN CHAR16 *TextDeviceNode
3318   )
3319 {
3320   CHAR16                                  *StartingAddrStr;
3321   CHAR16                                  *EndingAddrStr;
3322   CHAR16                                  *InstanceStr;
3323   MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;
3324   UINT64                                  StartingAddr;
3325   UINT64                                  EndingAddr;
3326 
3327   StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3328   EndingAddrStr   = GetNextParamStr (&TextDeviceNode);
3329   InstanceStr     = GetNextParamStr (&TextDeviceNode);
3330 
3331   RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3332                                                      MEDIA_DEVICE_PATH,
3333                                                      MEDIA_RAM_DISK_DP,
3334                                                      (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3335                                                      );
3336 
3337   Strtoi64 (StartingAddrStr, &StartingAddr);
3338   WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3339   Strtoi64 (EndingAddrStr, &EndingAddr);
3340   WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3341   RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3342   CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);
3343 
3344   return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3345 }
3346 
3347 /**
3348   Converts a text device path node to text persistent virtual cd device path structure.
3349 
3350   @param TextDeviceNode  The input Text device path node.
3351 
3352   @return A pointer to the newly-created Text device path structure.
3353 
3354 **/
3355 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextPersistentVirtualCd(IN CHAR16 * TextDeviceNode)3356 DevPathFromTextPersistentVirtualCd (
3357   IN CHAR16 *TextDeviceNode
3358   )
3359 {
3360   CHAR16                                  *StartingAddrStr;
3361   CHAR16                                  *EndingAddrStr;
3362   CHAR16                                  *InstanceStr;
3363   MEDIA_RAM_DISK_DEVICE_PATH              *RamDisk;
3364   UINT64                                  StartingAddr;
3365   UINT64                                  EndingAddr;
3366 
3367   StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3368   EndingAddrStr   = GetNextParamStr (&TextDeviceNode);
3369   InstanceStr     = GetNextParamStr (&TextDeviceNode);
3370 
3371   RamDisk         = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3372                                                      MEDIA_DEVICE_PATH,
3373                                                      MEDIA_RAM_DISK_DP,
3374                                                      (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3375                                                      );
3376 
3377   Strtoi64 (StartingAddrStr, &StartingAddr);
3378   WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3379   Strtoi64 (EndingAddrStr, &EndingAddr);
3380   WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3381   RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3382   CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);
3383 
3384   return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3385 }
3386 
3387 /**
3388   Converts a BBS text device path node to BBS device path structure.
3389 
3390   @param TextDeviceNode  The input Text device path node.
3391 
3392   @return A pointer to BBS device path structure.
3393 
3394 **/
3395 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextBbsPath(IN CHAR16 * TextDeviceNode)3396 DevPathFromTextBbsPath (
3397   IN CHAR16 *TextDeviceNode
3398   )
3399 {
3400   return DevPathFromTextGenericPath (BBS_DEVICE_PATH, TextDeviceNode);
3401 }
3402 
3403 /**
3404   Converts a text device path node to BIOS Boot Specification device path structure.
3405 
3406   @param TextDeviceNode  The input Text device path node.
3407 
3408   @return A pointer to the newly-created BIOS Boot Specification device path structure.
3409 
3410 **/
3411 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextBBS(IN CHAR16 * TextDeviceNode)3412 DevPathFromTextBBS (
3413   IN CHAR16 *TextDeviceNode
3414   )
3415 {
3416   CHAR16              *TypeStr;
3417   CHAR16              *IdStr;
3418   CHAR16              *FlagsStr;
3419   CHAR8               *AsciiStr;
3420   BBS_BBS_DEVICE_PATH *Bbs;
3421 
3422   TypeStr   = GetNextParamStr (&TextDeviceNode);
3423   IdStr     = GetNextParamStr (&TextDeviceNode);
3424   FlagsStr  = GetNextParamStr (&TextDeviceNode);
3425   Bbs       = (BBS_BBS_DEVICE_PATH *) CreateDeviceNode (
3426                                         BBS_DEVICE_PATH,
3427                                         BBS_BBS_DP,
3428                                         (UINT16) (sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr))
3429                                         );
3430 
3431   if (StrCmp (TypeStr, L"Floppy") == 0) {
3432     Bbs->DeviceType = BBS_TYPE_FLOPPY;
3433   } else if (StrCmp (TypeStr, L"HD") == 0) {
3434     Bbs->DeviceType = BBS_TYPE_HARDDRIVE;
3435   } else if (StrCmp (TypeStr, L"CDROM") == 0) {
3436     Bbs->DeviceType = BBS_TYPE_CDROM;
3437   } else if (StrCmp (TypeStr, L"PCMCIA") == 0) {
3438     Bbs->DeviceType = BBS_TYPE_PCMCIA;
3439   } else if (StrCmp (TypeStr, L"USB") == 0) {
3440     Bbs->DeviceType = BBS_TYPE_USB;
3441   } else if (StrCmp (TypeStr, L"Network") == 0) {
3442     Bbs->DeviceType = BBS_TYPE_EMBEDDED_NETWORK;
3443   } else {
3444     Bbs->DeviceType = (UINT16) Strtoi (TypeStr);
3445   }
3446 
3447   AsciiStr = Bbs->String;
3448   StrToAscii (IdStr, &AsciiStr);
3449 
3450   Bbs->StatusFlag = (UINT16) Strtoi (FlagsStr);
3451 
3452   return (EFI_DEVICE_PATH_PROTOCOL *) Bbs;
3453 }
3454 
3455 /**
3456   Converts a text device path node to SATA device path structure.
3457 
3458   @param TextDeviceNode  The input Text device path node.
3459 
3460   @return A pointer to the newly-created SATA device path structure.
3461 
3462 **/
3463 EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextSata(IN CHAR16 * TextDeviceNode)3464 DevPathFromTextSata (
3465   IN CHAR16 *TextDeviceNode
3466   )
3467 {
3468   SATA_DEVICE_PATH *Sata;
3469   CHAR16           *Param1;
3470   CHAR16           *Param2;
3471   CHAR16           *Param3;
3472 
3473   Param1 = GetNextParamStr (&TextDeviceNode);
3474   Param2 = GetNextParamStr (&TextDeviceNode);
3475   Param3 = GetNextParamStr (&TextDeviceNode);
3476 
3477   Sata = (SATA_DEVICE_PATH *) CreateDeviceNode (
3478                                 MESSAGING_DEVICE_PATH,
3479                                 MSG_SATA_DP,
3480                                 (UINT16) sizeof (SATA_DEVICE_PATH)
3481                                 );
3482   Sata->HBAPortNumber            = (UINT16) Strtoi (Param1);
3483   Sata->PortMultiplierPortNumber = (UINT16) Strtoi (Param2);
3484   Sata->Lun                      = (UINT16) Strtoi (Param3);
3485 
3486   return (EFI_DEVICE_PATH_PROTOCOL *) Sata;
3487 }
3488 
3489 GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
3490   {L"Path",                    DevPathFromTextPath                    },
3491 
3492   {L"HardwarePath",            DevPathFromTextHardwarePath            },
3493   {L"Pci",                     DevPathFromTextPci                     },
3494   {L"PcCard",                  DevPathFromTextPcCard                  },
3495   {L"MemoryMapped",            DevPathFromTextMemoryMapped            },
3496   {L"VenHw",                   DevPathFromTextVenHw                   },
3497   {L"Ctrl",                    DevPathFromTextCtrl                    },
3498   {L"BMC",                     DevPathFromTextBmc                     },
3499 
3500   {L"AcpiPath",                DevPathFromTextAcpiPath                },
3501   {L"Acpi",                    DevPathFromTextAcpi                    },
3502   {L"PciRoot",                 DevPathFromTextPciRoot                 },
3503   {L"PcieRoot",                DevPathFromTextPcieRoot                },
3504   {L"Floppy",                  DevPathFromTextFloppy                  },
3505   {L"Keyboard",                DevPathFromTextKeyboard                },
3506   {L"Serial",                  DevPathFromTextSerial                  },
3507   {L"ParallelPort",            DevPathFromTextParallelPort            },
3508   {L"AcpiEx",                  DevPathFromTextAcpiEx                  },
3509   {L"AcpiExp",                 DevPathFromTextAcpiExp                 },
3510   {L"AcpiAdr",                 DevPathFromTextAcpiAdr                 },
3511 
3512   {L"Msg",                     DevPathFromTextMsg                     },
3513   {L"Ata",                     DevPathFromTextAta                     },
3514   {L"Scsi",                    DevPathFromTextScsi                    },
3515   {L"Fibre",                   DevPathFromTextFibre                   },
3516   {L"FibreEx",                 DevPathFromTextFibreEx                 },
3517   {L"I1394",                   DevPathFromText1394                    },
3518   {L"USB",                     DevPathFromTextUsb                     },
3519   {L"I2O",                     DevPathFromTextI2O                     },
3520   {L"Infiniband",              DevPathFromTextInfiniband              },
3521   {L"VenMsg",                  DevPathFromTextVenMsg                  },
3522   {L"VenPcAnsi",               DevPathFromTextVenPcAnsi               },
3523   {L"VenVt100",                DevPathFromTextVenVt100                },
3524   {L"VenVt100Plus",            DevPathFromTextVenVt100Plus            },
3525   {L"VenUtf8",                 DevPathFromTextVenUtf8                 },
3526   {L"UartFlowCtrl",            DevPathFromTextUartFlowCtrl            },
3527   {L"SAS",                     DevPathFromTextSAS                     },
3528   {L"SasEx",                   DevPathFromTextSasEx                   },
3529   {L"NVMe",                    DevPathFromTextNVMe                    },
3530   {L"UFS",                     DevPathFromTextUfs                     },
3531   {L"SD",                      DevPathFromTextSd                      },
3532   {L"eMMC",                    DevPathFromTextEmmc                    },
3533   {L"DebugPort",               DevPathFromTextDebugPort               },
3534   {L"MAC",                     DevPathFromTextMAC                     },
3535   {L"IPv4",                    DevPathFromTextIPv4                    },
3536   {L"IPv6",                    DevPathFromTextIPv6                    },
3537   {L"Uart",                    DevPathFromTextUart                    },
3538   {L"UsbClass",                DevPathFromTextUsbClass                },
3539   {L"UsbAudio",                DevPathFromTextUsbAudio                },
3540   {L"UsbCDCControl",           DevPathFromTextUsbCDCControl           },
3541   {L"UsbHID",                  DevPathFromTextUsbHID                  },
3542   {L"UsbImage",                DevPathFromTextUsbImage                },
3543   {L"UsbPrinter",              DevPathFromTextUsbPrinter              },
3544   {L"UsbMassStorage",          DevPathFromTextUsbMassStorage          },
3545   {L"UsbHub",                  DevPathFromTextUsbHub                  },
3546   {L"UsbCDCData",              DevPathFromTextUsbCDCData              },
3547   {L"UsbSmartCard",            DevPathFromTextUsbSmartCard            },
3548   {L"UsbVideo",                DevPathFromTextUsbVideo                },
3549   {L"UsbDiagnostic",           DevPathFromTextUsbDiagnostic           },
3550   {L"UsbWireless",             DevPathFromTextUsbWireless             },
3551   {L"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate },
3552   {L"UsbIrdaBridge",           DevPathFromTextUsbIrdaBridge           },
3553   {L"UsbTestAndMeasurement",   DevPathFromTextUsbTestAndMeasurement   },
3554   {L"UsbWwid",                 DevPathFromTextUsbWwid                 },
3555   {L"Unit",                    DevPathFromTextUnit                    },
3556   {L"iSCSI",                   DevPathFromTextiSCSI                   },
3557   {L"Vlan",                    DevPathFromTextVlan                    },
3558   {L"Uri",                     DevPathFromTextUri                     },
3559   {L"Bluetooth",               DevPathFromTextBluetooth               },
3560   {L"Wi-Fi",                   DevPathFromTextWiFi                    },
3561   {L"MediaPath",               DevPathFromTextMediaPath               },
3562   {L"HD",                      DevPathFromTextHD                      },
3563   {L"CDROM",                   DevPathFromTextCDROM                   },
3564   {L"VenMedia",                DevPathFromTextVenMedia                },
3565   {L"Media",                   DevPathFromTextMedia                   },
3566   {L"Fv",                      DevPathFromTextFv                      },
3567   {L"FvFile",                  DevPathFromTextFvFile                  },
3568   {L"Offset",                  DevPathFromTextRelativeOffsetRange     },
3569   {L"RamDisk",                 DevPathFromTextRamDisk                 },
3570   {L"VirtualDisk",             DevPathFromTextVirtualDisk             },
3571   {L"VirtualCD",               DevPathFromTextVirtualCd               },
3572   {L"PersistentVirtualDisk",   DevPathFromTextPersistentVirtualDisk   },
3573   {L"PersistentVirtualCD",     DevPathFromTextPersistentVirtualCd     },
3574 
3575   {L"BbsPath",                 DevPathFromTextBbsPath                 },
3576   {L"BBS",                     DevPathFromTextBBS                     },
3577   {L"Sata",                    DevPathFromTextSata                    },
3578   {NULL, NULL}
3579 };
3580 
3581 /**
3582   Convert text to the binary representation of a device node.
3583 
3584   @param TextDeviceNode  TextDeviceNode points to the text representation of a device
3585                          node. Conversion starts with the first character and continues
3586                          until the first non-device node character.
3587 
3588   @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
3589           insufficient memory or text unsupported.
3590 
3591 **/
3592 EFI_DEVICE_PATH_PROTOCOL *
3593 EFIAPI
UefiDevicePathLibConvertTextToDeviceNode(IN CONST CHAR16 * TextDeviceNode)3594 UefiDevicePathLibConvertTextToDeviceNode (
3595   IN CONST CHAR16 *TextDeviceNode
3596   )
3597 {
3598   DEVICE_PATH_FROM_TEXT    FromText;
3599   CHAR16                   *ParamStr;
3600   EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
3601   CHAR16                   *DeviceNodeStr;
3602   UINTN                    Index;
3603 
3604   if ((TextDeviceNode == NULL) || (IS_NULL (*TextDeviceNode))) {
3605     return NULL;
3606   }
3607 
3608   ParamStr      = NULL;
3609   FromText      = NULL;
3610   DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
3611   ASSERT (DeviceNodeStr != NULL);
3612 
3613   for (Index = 0; mUefiDevicePathLibDevPathFromTextTable[Index].Function != NULL; Index++) {
3614     ParamStr = GetParamByNodeName (DeviceNodeStr, mUefiDevicePathLibDevPathFromTextTable[Index].DevicePathNodeText);
3615     if (ParamStr != NULL) {
3616       FromText = mUefiDevicePathLibDevPathFromTextTable[Index].Function;
3617       break;
3618     }
3619   }
3620 
3621   if (FromText == NULL) {
3622     //
3623     // A file path
3624     //
3625     FromText = DevPathFromTextFilePath;
3626     DeviceNode = FromText (DeviceNodeStr);
3627   } else {
3628     DeviceNode = FromText (ParamStr);
3629     FreePool (ParamStr);
3630   }
3631 
3632   FreePool (DeviceNodeStr);
3633 
3634   return DeviceNode;
3635 }
3636 
3637 /**
3638   Convert text to the binary representation of a device path.
3639 
3640 
3641   @param TextDevicePath  TextDevicePath points to the text representation of a device
3642                          path. Conversion starts with the first character and continues
3643                          until the first non-device node character.
3644 
3645   @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
3646           there was insufficient memory.
3647 
3648 **/
3649 EFI_DEVICE_PATH_PROTOCOL *
3650 EFIAPI
UefiDevicePathLibConvertTextToDevicePath(IN CONST CHAR16 * TextDevicePath)3651 UefiDevicePathLibConvertTextToDevicePath (
3652   IN CONST CHAR16 *TextDevicePath
3653   )
3654 {
3655   EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
3656   EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
3657   CHAR16                   *DevicePathStr;
3658   CHAR16                   *Str;
3659   CHAR16                   *DeviceNodeStr;
3660   BOOLEAN                  IsInstanceEnd;
3661   EFI_DEVICE_PATH_PROTOCOL *DevicePath;
3662 
3663   if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
3664     return NULL;
3665   }
3666 
3667   DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
3668   ASSERT (DevicePath != NULL);
3669   SetDevicePathEndNode (DevicePath);
3670 
3671   DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
3672 
3673   Str           = DevicePathStr;
3674   while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
3675     DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);
3676 
3677     NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3678     FreePool (DevicePath);
3679     FreePool (DeviceNode);
3680     DevicePath = NewDevicePath;
3681 
3682     if (IsInstanceEnd) {
3683       DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
3684       ASSERT (DeviceNode != NULL);
3685       SetDevicePathEndNode (DeviceNode);
3686 
3687       NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3688       FreePool (DevicePath);
3689       FreePool (DeviceNode);
3690       DevicePath = NewDevicePath;
3691     }
3692   }
3693 
3694   FreePool (DevicePathStr);
3695   return DevicePath;
3696 }
3697