]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
MdePkg: Add UEFI2.5 Ramdisk device path definition
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / DevicePathFromText.c
1 /** @file
2 DevicePathFromText protocol as defined in the UEFI 2.0 specification.
3
4 Copyright (c) 2013 - 2015, 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 *
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 *
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 *
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 *
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 *
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
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
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
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
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
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
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
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
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 *
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 *
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 *
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 *
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 *
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 *
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 *
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 *
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 *
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 generic ACPI text device path node to ACPI device path structure.
798
799 @param TextDeviceNode The input Text device path node.
800
801 @return A pointer to ACPI device path structure.
802
803 **/
804 EFI_DEVICE_PATH_PROTOCOL *
805 DevPathFromTextAcpiPath (
806 IN CHAR16 *TextDeviceNode
807 )
808 {
809 return DevPathFromTextGenericPath (ACPI_DEVICE_PATH, TextDeviceNode);
810 }
811
812 /**
813 Converts a string to EisaId.
814
815 @param Text The input string.
816
817 @return UINT32 EISA ID.
818 **/
819 UINT32
820 EisaIdFromText (
821 IN CHAR16 *Text
822 )
823 {
824 return (((Text[0] - 'A' + 1) & 0x1f) << 10)
825 + (((Text[1] - 'A' + 1) & 0x1f) << 5)
826 + (((Text[2] - 'A' + 1) & 0x1f) << 0)
827 + (UINT32) (StrHexToUintn (&Text[3]) << 16)
828 ;
829 }
830
831 /**
832 Converts a text device path node to ACPI HID device path structure.
833
834 @param TextDeviceNode The input Text device path node.
835
836 @return A pointer to the newly-created ACPI HID device path structure.
837
838 **/
839 EFI_DEVICE_PATH_PROTOCOL *
840 DevPathFromTextAcpi (
841 IN CHAR16 *TextDeviceNode
842 )
843 {
844 CHAR16 *HIDStr;
845 CHAR16 *UIDStr;
846 ACPI_HID_DEVICE_PATH *Acpi;
847
848 HIDStr = GetNextParamStr (&TextDeviceNode);
849 UIDStr = GetNextParamStr (&TextDeviceNode);
850 Acpi = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
851 ACPI_DEVICE_PATH,
852 ACPI_DP,
853 (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
854 );
855
856 Acpi->HID = EisaIdFromText (HIDStr);
857 Acpi->UID = (UINT32) Strtoi (UIDStr);
858
859 return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
860 }
861
862 /**
863 Converts a text device path node to ACPI HID device path structure.
864
865 @param TextDeviceNode The input Text device path node.
866 @param PnPId The input plug and play identification.
867
868 @return A pointer to the newly-created ACPI HID device path structure.
869
870 **/
871 EFI_DEVICE_PATH_PROTOCOL *
872 ConvertFromTextAcpi (
873 IN CHAR16 *TextDeviceNode,
874 IN UINT32 PnPId
875 )
876 {
877 CHAR16 *UIDStr;
878 ACPI_HID_DEVICE_PATH *Acpi;
879
880 UIDStr = GetNextParamStr (&TextDeviceNode);
881 Acpi = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
882 ACPI_DEVICE_PATH,
883 ACPI_DP,
884 (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
885 );
886
887 Acpi->HID = EFI_PNP_ID (PnPId);
888 Acpi->UID = (UINT32) Strtoi (UIDStr);
889
890 return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
891 }
892
893 /**
894 Converts a text device path node to PCI root device path structure.
895
896 @param TextDeviceNode The input Text device path node.
897
898 @return A pointer to the newly-created PCI root device path structure.
899
900 **/
901 EFI_DEVICE_PATH_PROTOCOL *
902 DevPathFromTextPciRoot (
903 IN CHAR16 *TextDeviceNode
904 )
905 {
906 return ConvertFromTextAcpi (TextDeviceNode, 0x0a03);
907 }
908
909 /**
910 Converts a text device path node to PCIE root device path structure.
911
912 @param TextDeviceNode The input Text device path node.
913
914 @return A pointer to the newly-created PCIE root device path structure.
915
916 **/
917 EFI_DEVICE_PATH_PROTOCOL *
918 DevPathFromTextPcieRoot (
919 IN CHAR16 *TextDeviceNode
920 )
921 {
922 return ConvertFromTextAcpi (TextDeviceNode, 0x0a08);
923 }
924
925 /**
926 Converts a text device path node to Floppy device path structure.
927
928 @param TextDeviceNode The input Text device path node.
929
930 @return A pointer to the newly-created Floppy device path structure.
931
932 **/
933 EFI_DEVICE_PATH_PROTOCOL *
934 DevPathFromTextFloppy (
935 IN CHAR16 *TextDeviceNode
936 )
937 {
938 return ConvertFromTextAcpi (TextDeviceNode, 0x0604);
939 }
940
941 /**
942 Converts a text device path node to Keyboard device path structure.
943
944 @param TextDeviceNode The input Text device path node.
945
946 @return A pointer to the newly-created Keyboard device path structure.
947
948 **/
949 EFI_DEVICE_PATH_PROTOCOL *
950 DevPathFromTextKeyboard (
951 IN CHAR16 *TextDeviceNode
952 )
953 {
954 return ConvertFromTextAcpi (TextDeviceNode, 0x0301);
955 }
956
957 /**
958 Converts a text device path node to Serial device path structure.
959
960 @param TextDeviceNode The input Text device path node.
961
962 @return A pointer to the newly-created Serial device path structure.
963
964 **/
965 EFI_DEVICE_PATH_PROTOCOL *
966 DevPathFromTextSerial (
967 IN CHAR16 *TextDeviceNode
968 )
969 {
970 return ConvertFromTextAcpi (TextDeviceNode, 0x0501);
971 }
972
973 /**
974 Converts a text device path node to Parallel Port device path structure.
975
976 @param TextDeviceNode The input Text device path node.
977
978 @return A pointer to the newly-created Parallel Port device path structure.
979
980 **/
981 EFI_DEVICE_PATH_PROTOCOL *
982 DevPathFromTextParallelPort (
983 IN CHAR16 *TextDeviceNode
984 )
985 {
986 return ConvertFromTextAcpi (TextDeviceNode, 0x0401);
987 }
988
989 /**
990 Converts a text device path node to ACPI extension device path structure.
991
992 @param TextDeviceNode The input Text device path node.
993
994 @return A pointer to the newly-created ACPI extension device path structure.
995
996 **/
997 EFI_DEVICE_PATH_PROTOCOL *
998 DevPathFromTextAcpiEx (
999 IN CHAR16 *TextDeviceNode
1000 )
1001 {
1002 CHAR16 *HIDStr;
1003 CHAR16 *CIDStr;
1004 CHAR16 *UIDStr;
1005 CHAR16 *HIDSTRStr;
1006 CHAR16 *CIDSTRStr;
1007 CHAR16 *UIDSTRStr;
1008 CHAR8 *AsciiStr;
1009 UINT16 Length;
1010 ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
1011
1012 HIDStr = GetNextParamStr (&TextDeviceNode);
1013 CIDStr = GetNextParamStr (&TextDeviceNode);
1014 UIDStr = GetNextParamStr (&TextDeviceNode);
1015 HIDSTRStr = GetNextParamStr (&TextDeviceNode);
1016 CIDSTRStr = GetNextParamStr (&TextDeviceNode);
1017 UIDSTRStr = GetNextParamStr (&TextDeviceNode);
1018
1019 Length = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (HIDSTRStr) + 1);
1020 Length = (UINT16) (Length + StrLen (UIDSTRStr) + 1);
1021 Length = (UINT16) (Length + StrLen (CIDSTRStr) + 1);
1022 AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (
1023 ACPI_DEVICE_PATH,
1024 ACPI_EXTENDED_DP,
1025 Length
1026 );
1027
1028 AcpiEx->HID = EisaIdFromText (HIDStr);
1029 AcpiEx->CID = EisaIdFromText (CIDStr);
1030 AcpiEx->UID = (UINT32) Strtoi (UIDStr);
1031
1032 AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
1033 StrToAscii (HIDSTRStr, &AsciiStr);
1034 StrToAscii (UIDSTRStr, &AsciiStr);
1035 StrToAscii (CIDSTRStr, &AsciiStr);
1036
1037 return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;
1038 }
1039
1040 /**
1041 Converts a text device path node to ACPI extension device path structure.
1042
1043 @param TextDeviceNode The input Text device path node.
1044
1045 @return A pointer to the newly-created ACPI extension device path structure.
1046
1047 **/
1048 EFI_DEVICE_PATH_PROTOCOL *
1049 DevPathFromTextAcpiExp (
1050 IN CHAR16 *TextDeviceNode
1051 )
1052 {
1053 CHAR16 *HIDStr;
1054 CHAR16 *CIDStr;
1055 CHAR16 *UIDSTRStr;
1056 CHAR8 *AsciiStr;
1057 UINT16 Length;
1058 ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
1059
1060 HIDStr = GetNextParamStr (&TextDeviceNode);
1061 CIDStr = GetNextParamStr (&TextDeviceNode);
1062 UIDSTRStr = GetNextParamStr (&TextDeviceNode);
1063 Length = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (UIDSTRStr) + 3);
1064 AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (
1065 ACPI_DEVICE_PATH,
1066 ACPI_EXTENDED_DP,
1067 Length
1068 );
1069
1070 AcpiEx->HID = EisaIdFromText (HIDStr);
1071 AcpiEx->CID = EisaIdFromText (CIDStr);
1072 AcpiEx->UID = 0;
1073
1074 AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
1075 //
1076 // HID string is NULL
1077 //
1078 *AsciiStr = '\0';
1079 //
1080 // Convert UID string
1081 //
1082 AsciiStr++;
1083 StrToAscii (UIDSTRStr, &AsciiStr);
1084 //
1085 // CID string is NULL
1086 //
1087 *AsciiStr = '\0';
1088
1089 return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;
1090 }
1091
1092 /**
1093 Converts a text device path node to ACPI _ADR device path structure.
1094
1095 @param TextDeviceNode The input Text device path node.
1096
1097 @return A pointer to the newly-created ACPI _ADR device path structure.
1098
1099 **/
1100 EFI_DEVICE_PATH_PROTOCOL *
1101 DevPathFromTextAcpiAdr (
1102 IN CHAR16 *TextDeviceNode
1103 )
1104 {
1105 CHAR16 *DisplayDeviceStr;
1106 ACPI_ADR_DEVICE_PATH *AcpiAdr;
1107 UINTN Index;
1108 UINTN Length;
1109
1110 AcpiAdr = (ACPI_ADR_DEVICE_PATH *) CreateDeviceNode (
1111 ACPI_DEVICE_PATH,
1112 ACPI_ADR_DP,
1113 (UINT16) sizeof (ACPI_ADR_DEVICE_PATH)
1114 );
1115 ASSERT (AcpiAdr != NULL);
1116
1117 for (Index = 0; ; Index++) {
1118 DisplayDeviceStr = GetNextParamStr (&TextDeviceNode);
1119 if (IS_NULL (*DisplayDeviceStr)) {
1120 break;
1121 }
1122 if (Index > 0) {
1123 Length = DevicePathNodeLength (AcpiAdr);
1124 AcpiAdr = ReallocatePool (
1125 Length,
1126 Length + sizeof (UINT32),
1127 AcpiAdr
1128 );
1129 ASSERT (AcpiAdr != NULL);
1130 SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32));
1131 }
1132
1133 (&AcpiAdr->ADR)[Index] = (UINT32) Strtoi (DisplayDeviceStr);
1134 }
1135
1136 return (EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr;
1137 }
1138
1139 /**
1140 Converts a generic messaging text device path node to messaging device path structure.
1141
1142 @param TextDeviceNode The input Text device path node.
1143
1144 @return A pointer to messaging device path structure.
1145
1146 **/
1147 EFI_DEVICE_PATH_PROTOCOL *
1148 DevPathFromTextMsg (
1149 IN CHAR16 *TextDeviceNode
1150 )
1151 {
1152 return DevPathFromTextGenericPath (MESSAGING_DEVICE_PATH, TextDeviceNode);
1153 }
1154
1155 /**
1156 Converts a text device path node to Parallel Port device path structure.
1157
1158 @param TextDeviceNode The input Text device path node.
1159
1160 @return A pointer to the newly-created Parallel Port device path structure.
1161
1162 **/
1163 EFI_DEVICE_PATH_PROTOCOL *
1164 DevPathFromTextAta (
1165 IN CHAR16 *TextDeviceNode
1166 )
1167 {
1168 CHAR16 *PrimarySecondaryStr;
1169 CHAR16 *SlaveMasterStr;
1170 CHAR16 *LunStr;
1171 ATAPI_DEVICE_PATH *Atapi;
1172
1173 Atapi = (ATAPI_DEVICE_PATH *) CreateDeviceNode (
1174 MESSAGING_DEVICE_PATH,
1175 MSG_ATAPI_DP,
1176 (UINT16) sizeof (ATAPI_DEVICE_PATH)
1177 );
1178
1179 PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
1180 SlaveMasterStr = GetNextParamStr (&TextDeviceNode);
1181 LunStr = GetNextParamStr (&TextDeviceNode);
1182
1183 if (StrCmp (PrimarySecondaryStr, L"Primary") == 0) {
1184 Atapi->PrimarySecondary = 0;
1185 } else if (StrCmp (PrimarySecondaryStr, L"Secondary") == 0) {
1186 Atapi->PrimarySecondary = 1;
1187 } else {
1188 Atapi->PrimarySecondary = (UINT8) Strtoi (PrimarySecondaryStr);
1189 }
1190 if (StrCmp (SlaveMasterStr, L"Master") == 0) {
1191 Atapi->SlaveMaster = 0;
1192 } else if (StrCmp (SlaveMasterStr, L"Slave") == 0) {
1193 Atapi->SlaveMaster = 1;
1194 } else {
1195 Atapi->SlaveMaster = (UINT8) Strtoi (SlaveMasterStr);
1196 }
1197
1198 Atapi->Lun = (UINT16) Strtoi (LunStr);
1199
1200 return (EFI_DEVICE_PATH_PROTOCOL *) Atapi;
1201 }
1202
1203 /**
1204 Converts a text device path node to SCSI device path structure.
1205
1206 @param TextDeviceNode The input Text device path node.
1207
1208 @return A pointer to the newly-created SCSI device path structure.
1209
1210 **/
1211 EFI_DEVICE_PATH_PROTOCOL *
1212 DevPathFromTextScsi (
1213 IN CHAR16 *TextDeviceNode
1214 )
1215 {
1216 CHAR16 *PunStr;
1217 CHAR16 *LunStr;
1218 SCSI_DEVICE_PATH *Scsi;
1219
1220 PunStr = GetNextParamStr (&TextDeviceNode);
1221 LunStr = GetNextParamStr (&TextDeviceNode);
1222 Scsi = (SCSI_DEVICE_PATH *) CreateDeviceNode (
1223 MESSAGING_DEVICE_PATH,
1224 MSG_SCSI_DP,
1225 (UINT16) sizeof (SCSI_DEVICE_PATH)
1226 );
1227
1228 Scsi->Pun = (UINT16) Strtoi (PunStr);
1229 Scsi->Lun = (UINT16) Strtoi (LunStr);
1230
1231 return (EFI_DEVICE_PATH_PROTOCOL *) Scsi;
1232 }
1233
1234 /**
1235 Converts a text device path node to Fibre device path structure.
1236
1237 @param TextDeviceNode The input Text device path node.
1238
1239 @return A pointer to the newly-created Fibre device path structure.
1240
1241 **/
1242 EFI_DEVICE_PATH_PROTOCOL *
1243 DevPathFromTextFibre (
1244 IN CHAR16 *TextDeviceNode
1245 )
1246 {
1247 CHAR16 *WWNStr;
1248 CHAR16 *LunStr;
1249 FIBRECHANNEL_DEVICE_PATH *Fibre;
1250
1251 WWNStr = GetNextParamStr (&TextDeviceNode);
1252 LunStr = GetNextParamStr (&TextDeviceNode);
1253 Fibre = (FIBRECHANNEL_DEVICE_PATH *) CreateDeviceNode (
1254 MESSAGING_DEVICE_PATH,
1255 MSG_FIBRECHANNEL_DP,
1256 (UINT16) sizeof (FIBRECHANNEL_DEVICE_PATH)
1257 );
1258
1259 Fibre->Reserved = 0;
1260 Strtoi64 (WWNStr, &Fibre->WWN);
1261 Strtoi64 (LunStr, &Fibre->Lun);
1262
1263 return (EFI_DEVICE_PATH_PROTOCOL *) Fibre;
1264 }
1265
1266 /**
1267 Converts a text device path node to FibreEx device path structure.
1268
1269 @param TextDeviceNode The input Text device path node.
1270
1271 @return A pointer to the newly-created FibreEx device path structure.
1272
1273 **/
1274 EFI_DEVICE_PATH_PROTOCOL *
1275 DevPathFromTextFibreEx (
1276 IN CHAR16 *TextDeviceNode
1277 )
1278 {
1279 CHAR16 *WWNStr;
1280 CHAR16 *LunStr;
1281 FIBRECHANNELEX_DEVICE_PATH *FibreEx;
1282
1283 WWNStr = GetNextParamStr (&TextDeviceNode);
1284 LunStr = GetNextParamStr (&TextDeviceNode);
1285 FibreEx = (FIBRECHANNELEX_DEVICE_PATH *) CreateDeviceNode (
1286 MESSAGING_DEVICE_PATH,
1287 MSG_FIBRECHANNELEX_DP,
1288 (UINT16) sizeof (FIBRECHANNELEX_DEVICE_PATH)
1289 );
1290
1291 FibreEx->Reserved = 0;
1292 Strtoi64 (WWNStr, (UINT64 *) (&FibreEx->WWN));
1293 Strtoi64 (LunStr, (UINT64 *) (&FibreEx->Lun));
1294
1295 *(UINT64 *) (&FibreEx->WWN) = SwapBytes64 (*(UINT64 *) (&FibreEx->WWN));
1296 *(UINT64 *) (&FibreEx->Lun) = SwapBytes64 (*(UINT64 *) (&FibreEx->Lun));
1297
1298 return (EFI_DEVICE_PATH_PROTOCOL *) FibreEx;
1299 }
1300
1301 /**
1302 Converts a text device path node to 1394 device path structure.
1303
1304 @param TextDeviceNode The input Text device path node.
1305
1306 @return A pointer to the newly-created 1394 device path structure.
1307
1308 **/
1309 EFI_DEVICE_PATH_PROTOCOL *
1310 DevPathFromText1394 (
1311 IN CHAR16 *TextDeviceNode
1312 )
1313 {
1314 CHAR16 *GuidStr;
1315 F1394_DEVICE_PATH *F1394DevPath;
1316
1317 GuidStr = GetNextParamStr (&TextDeviceNode);
1318 F1394DevPath = (F1394_DEVICE_PATH *) CreateDeviceNode (
1319 MESSAGING_DEVICE_PATH,
1320 MSG_1394_DP,
1321 (UINT16) sizeof (F1394_DEVICE_PATH)
1322 );
1323
1324 F1394DevPath->Reserved = 0;
1325 F1394DevPath->Guid = StrHexToUint64 (GuidStr);
1326
1327 return (EFI_DEVICE_PATH_PROTOCOL *) F1394DevPath;
1328 }
1329
1330 /**
1331 Converts a text device path node to USB device path structure.
1332
1333 @param TextDeviceNode The input Text device path node.
1334
1335 @return A pointer to the newly-created USB device path structure.
1336
1337 **/
1338 EFI_DEVICE_PATH_PROTOCOL *
1339 DevPathFromTextUsb (
1340 IN CHAR16 *TextDeviceNode
1341 )
1342 {
1343 CHAR16 *PortStr;
1344 CHAR16 *InterfaceStr;
1345 USB_DEVICE_PATH *Usb;
1346
1347 PortStr = GetNextParamStr (&TextDeviceNode);
1348 InterfaceStr = GetNextParamStr (&TextDeviceNode);
1349 Usb = (USB_DEVICE_PATH *) CreateDeviceNode (
1350 MESSAGING_DEVICE_PATH,
1351 MSG_USB_DP,
1352 (UINT16) sizeof (USB_DEVICE_PATH)
1353 );
1354
1355 Usb->ParentPortNumber = (UINT8) Strtoi (PortStr);
1356 Usb->InterfaceNumber = (UINT8) Strtoi (InterfaceStr);
1357
1358 return (EFI_DEVICE_PATH_PROTOCOL *) Usb;
1359 }
1360
1361 /**
1362 Converts a text device path node to I20 device path structure.
1363
1364 @param TextDeviceNode The input Text device path node.
1365
1366 @return A pointer to the newly-created I20 device path structure.
1367
1368 **/
1369 EFI_DEVICE_PATH_PROTOCOL *
1370 DevPathFromTextI2O (
1371 IN CHAR16 *TextDeviceNode
1372 )
1373 {
1374 CHAR16 *TIDStr;
1375 I2O_DEVICE_PATH *I2ODevPath;
1376
1377 TIDStr = GetNextParamStr (&TextDeviceNode);
1378 I2ODevPath = (I2O_DEVICE_PATH *) CreateDeviceNode (
1379 MESSAGING_DEVICE_PATH,
1380 MSG_I2O_DP,
1381 (UINT16) sizeof (I2O_DEVICE_PATH)
1382 );
1383
1384 I2ODevPath->Tid = (UINT32) Strtoi (TIDStr);
1385
1386 return (EFI_DEVICE_PATH_PROTOCOL *) I2ODevPath;
1387 }
1388
1389 /**
1390 Converts a text device path node to Infini Band device path structure.
1391
1392 @param TextDeviceNode The input Text device path node.
1393
1394 @return A pointer to the newly-created Infini Band device path structure.
1395
1396 **/
1397 EFI_DEVICE_PATH_PROTOCOL *
1398 DevPathFromTextInfiniband (
1399 IN CHAR16 *TextDeviceNode
1400 )
1401 {
1402 CHAR16 *FlagsStr;
1403 CHAR16 *GuidStr;
1404 CHAR16 *SidStr;
1405 CHAR16 *TidStr;
1406 CHAR16 *DidStr;
1407 EFI_GUID PortGid;
1408 INFINIBAND_DEVICE_PATH *InfiniBand;
1409
1410 FlagsStr = GetNextParamStr (&TextDeviceNode);
1411 GuidStr = GetNextParamStr (&TextDeviceNode);
1412 SidStr = GetNextParamStr (&TextDeviceNode);
1413 TidStr = GetNextParamStr (&TextDeviceNode);
1414 DidStr = GetNextParamStr (&TextDeviceNode);
1415 InfiniBand = (INFINIBAND_DEVICE_PATH *) CreateDeviceNode (
1416 MESSAGING_DEVICE_PATH,
1417 MSG_INFINIBAND_DP,
1418 (UINT16) sizeof (INFINIBAND_DEVICE_PATH)
1419 );
1420
1421 InfiniBand->ResourceFlags = (UINT32) Strtoi (FlagsStr);
1422 StrToGuid (GuidStr, &PortGid);
1423 CopyMem (InfiniBand->PortGid, &PortGid, sizeof (EFI_GUID));
1424 Strtoi64 (SidStr, &InfiniBand->ServiceId);
1425 Strtoi64 (TidStr, &InfiniBand->TargetPortId);
1426 Strtoi64 (DidStr, &InfiniBand->DeviceId);
1427
1428 return (EFI_DEVICE_PATH_PROTOCOL *) InfiniBand;
1429 }
1430
1431 /**
1432 Converts a text device path node to Vendor-Defined Messaging device path structure.
1433
1434 @param TextDeviceNode The input Text device path node.
1435
1436 @return A pointer to the newly-created Vendor-Defined Messaging device path structure.
1437
1438 **/
1439 EFI_DEVICE_PATH_PROTOCOL *
1440 DevPathFromTextVenMsg (
1441 IN CHAR16 *TextDeviceNode
1442 )
1443 {
1444 return ConvertFromTextVendor (
1445 TextDeviceNode,
1446 MESSAGING_DEVICE_PATH,
1447 MSG_VENDOR_DP
1448 );
1449 }
1450
1451 /**
1452 Converts a text device path node to Vendor defined PC-ANSI device path structure.
1453
1454 @param TextDeviceNode The input Text device path node.
1455
1456 @return A pointer to the newly-created Vendor defined PC-ANSI device path structure.
1457
1458 **/
1459 EFI_DEVICE_PATH_PROTOCOL *
1460 DevPathFromTextVenPcAnsi (
1461 IN CHAR16 *TextDeviceNode
1462 )
1463 {
1464 VENDOR_DEVICE_PATH *Vendor;
1465
1466 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1467 MESSAGING_DEVICE_PATH,
1468 MSG_VENDOR_DP,
1469 (UINT16) sizeof (VENDOR_DEVICE_PATH));
1470 CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
1471
1472 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1473 }
1474
1475 /**
1476 Converts a text device path node to Vendor defined VT100 device path structure.
1477
1478 @param TextDeviceNode The input Text device path node.
1479
1480 @return A pointer to the newly-created Vendor defined VT100 device path structure.
1481
1482 **/
1483 EFI_DEVICE_PATH_PROTOCOL *
1484 DevPathFromTextVenVt100 (
1485 IN CHAR16 *TextDeviceNode
1486 )
1487 {
1488 VENDOR_DEVICE_PATH *Vendor;
1489
1490 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1491 MESSAGING_DEVICE_PATH,
1492 MSG_VENDOR_DP,
1493 (UINT16) sizeof (VENDOR_DEVICE_PATH));
1494 CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
1495
1496 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1497 }
1498
1499 /**
1500 Converts a text device path node to Vendor defined VT100 Plus device path structure.
1501
1502 @param TextDeviceNode The input Text device path node.
1503
1504 @return A pointer to the newly-created Vendor defined VT100 Plus device path structure.
1505
1506 **/
1507 EFI_DEVICE_PATH_PROTOCOL *
1508 DevPathFromTextVenVt100Plus (
1509 IN CHAR16 *TextDeviceNode
1510 )
1511 {
1512 VENDOR_DEVICE_PATH *Vendor;
1513
1514 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1515 MESSAGING_DEVICE_PATH,
1516 MSG_VENDOR_DP,
1517 (UINT16) sizeof (VENDOR_DEVICE_PATH));
1518 CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
1519
1520 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1521 }
1522
1523 /**
1524 Converts a text device path node to Vendor defined UTF8 device path structure.
1525
1526 @param TextDeviceNode The input Text device path node.
1527
1528 @return A pointer to the newly-created Vendor defined UTF8 device path structure.
1529
1530 **/
1531 EFI_DEVICE_PATH_PROTOCOL *
1532 DevPathFromTextVenUtf8 (
1533 IN CHAR16 *TextDeviceNode
1534 )
1535 {
1536 VENDOR_DEVICE_PATH *Vendor;
1537
1538 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1539 MESSAGING_DEVICE_PATH,
1540 MSG_VENDOR_DP,
1541 (UINT16) sizeof (VENDOR_DEVICE_PATH));
1542 CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
1543
1544 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1545 }
1546
1547 /**
1548 Converts a text device path node to UART Flow Control device path structure.
1549
1550 @param TextDeviceNode The input Text device path node.
1551
1552 @return A pointer to the newly-created UART Flow Control device path structure.
1553
1554 **/
1555 EFI_DEVICE_PATH_PROTOCOL *
1556 DevPathFromTextUartFlowCtrl (
1557 IN CHAR16 *TextDeviceNode
1558 )
1559 {
1560 CHAR16 *ValueStr;
1561 UART_FLOW_CONTROL_DEVICE_PATH *UartFlowControl;
1562
1563 ValueStr = GetNextParamStr (&TextDeviceNode);
1564 UartFlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) CreateDeviceNode (
1565 MESSAGING_DEVICE_PATH,
1566 MSG_VENDOR_DP,
1567 (UINT16) sizeof (UART_FLOW_CONTROL_DEVICE_PATH)
1568 );
1569
1570 CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
1571 if (StrCmp (ValueStr, L"XonXoff") == 0) {
1572 UartFlowControl->FlowControlMap = 2;
1573 } else if (StrCmp (ValueStr, L"Hardware") == 0) {
1574 UartFlowControl->FlowControlMap = 1;
1575 } else {
1576 UartFlowControl->FlowControlMap = 0;
1577 }
1578
1579 return (EFI_DEVICE_PATH_PROTOCOL *) UartFlowControl;
1580 }
1581
1582 /**
1583 Converts a text device path node to Serial Attached SCSI device path structure.
1584
1585 @param TextDeviceNode The input Text device path node.
1586
1587 @return A pointer to the newly-created Serial Attached SCSI device path structure.
1588
1589 **/
1590 EFI_DEVICE_PATH_PROTOCOL *
1591 DevPathFromTextSAS (
1592 IN CHAR16 *TextDeviceNode
1593 )
1594 {
1595 CHAR16 *AddressStr;
1596 CHAR16 *LunStr;
1597 CHAR16 *RTPStr;
1598 CHAR16 *SASSATAStr;
1599 CHAR16 *LocationStr;
1600 CHAR16 *ConnectStr;
1601 CHAR16 *DriveBayStr;
1602 CHAR16 *ReservedStr;
1603 UINT16 Info;
1604 UINT16 Uint16;
1605 SAS_DEVICE_PATH *Sas;
1606
1607 AddressStr = GetNextParamStr (&TextDeviceNode);
1608 LunStr = GetNextParamStr (&TextDeviceNode);
1609 RTPStr = GetNextParamStr (&TextDeviceNode);
1610 SASSATAStr = GetNextParamStr (&TextDeviceNode);
1611 LocationStr = GetNextParamStr (&TextDeviceNode);
1612 ConnectStr = GetNextParamStr (&TextDeviceNode);
1613 DriveBayStr = GetNextParamStr (&TextDeviceNode);
1614 ReservedStr = GetNextParamStr (&TextDeviceNode);
1615 Sas = (SAS_DEVICE_PATH *) CreateDeviceNode (
1616 MESSAGING_DEVICE_PATH,
1617 MSG_VENDOR_DP,
1618 (UINT16) sizeof (SAS_DEVICE_PATH)
1619 );
1620
1621 CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid);
1622 Strtoi64 (AddressStr, &Sas->SasAddress);
1623 Strtoi64 (LunStr, &Sas->Lun);
1624 Sas->RelativeTargetPort = (UINT16) Strtoi (RTPStr);
1625
1626 if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
1627 Info = 0x0;
1628
1629 } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {
1630
1631 Uint16 = (UINT16) Strtoi (DriveBayStr);
1632 if (Uint16 == 0) {
1633 Info = 0x1;
1634 } else {
1635 Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
1636 }
1637
1638 if (StrCmp (SASSATAStr, L"SATA") == 0) {
1639 Info |= BIT4;
1640 }
1641
1642 //
1643 // Location is an integer between 0 and 1 or else
1644 // the keyword Internal (0) or External (1).
1645 //
1646 if (StrCmp (LocationStr, L"External") == 0) {
1647 Uint16 = 1;
1648 } else if (StrCmp (LocationStr, L"Internal") == 0) {
1649 Uint16 = 0;
1650 } else {
1651 Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);
1652 }
1653 Info |= (Uint16 << 5);
1654
1655 //
1656 // Connect is an integer between 0 and 3 or else
1657 // the keyword Direct (0) or Expanded (1).
1658 //
1659 if (StrCmp (ConnectStr, L"Expanded") == 0) {
1660 Uint16 = 1;
1661 } else if (StrCmp (ConnectStr, L"Direct") == 0) {
1662 Uint16 = 0;
1663 } else {
1664 Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));
1665 }
1666 Info |= (Uint16 << 6);
1667
1668 } else {
1669 Info = (UINT16) Strtoi (SASSATAStr);
1670 }
1671
1672 Sas->DeviceTopology = Info;
1673 Sas->Reserved = (UINT32) Strtoi (ReservedStr);
1674
1675 return (EFI_DEVICE_PATH_PROTOCOL *) Sas;
1676 }
1677
1678 /**
1679 Converts a text device path node to Serial Attached SCSI Ex device path structure.
1680
1681 @param TextDeviceNode The input Text device path node.
1682
1683 @return A pointer to the newly-created Serial Attached SCSI Ex device path structure.
1684
1685 **/
1686 EFI_DEVICE_PATH_PROTOCOL *
1687 DevPathFromTextSasEx (
1688 IN CHAR16 *TextDeviceNode
1689 )
1690 {
1691 CHAR16 *AddressStr;
1692 CHAR16 *LunStr;
1693 CHAR16 *RTPStr;
1694 CHAR16 *SASSATAStr;
1695 CHAR16 *LocationStr;
1696 CHAR16 *ConnectStr;
1697 CHAR16 *DriveBayStr;
1698 UINT16 Info;
1699 UINT16 Uint16;
1700 UINT64 SasAddress;
1701 UINT64 Lun;
1702 SASEX_DEVICE_PATH *SasEx;
1703
1704 AddressStr = GetNextParamStr (&TextDeviceNode);
1705 LunStr = GetNextParamStr (&TextDeviceNode);
1706 RTPStr = GetNextParamStr (&TextDeviceNode);
1707 SASSATAStr = GetNextParamStr (&TextDeviceNode);
1708 LocationStr = GetNextParamStr (&TextDeviceNode);
1709 ConnectStr = GetNextParamStr (&TextDeviceNode);
1710 DriveBayStr = GetNextParamStr (&TextDeviceNode);
1711 SasEx = (SASEX_DEVICE_PATH *) CreateDeviceNode (
1712 MESSAGING_DEVICE_PATH,
1713 MSG_SASEX_DP,
1714 (UINT16) sizeof (SASEX_DEVICE_PATH)
1715 );
1716
1717 Strtoi64 (AddressStr, &SasAddress);
1718 Strtoi64 (LunStr, &Lun);
1719 WriteUnaligned64 ((UINT64 *) &SasEx->SasAddress, SwapBytes64 (SasAddress));
1720 WriteUnaligned64 ((UINT64 *) &SasEx->Lun, SwapBytes64 (Lun));
1721 SasEx->RelativeTargetPort = (UINT16) Strtoi (RTPStr);
1722
1723 if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
1724 Info = 0x0;
1725
1726 } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {
1727
1728 Uint16 = (UINT16) Strtoi (DriveBayStr);
1729 if (Uint16 == 0) {
1730 Info = 0x1;
1731 } else {
1732 Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
1733 }
1734
1735 if (StrCmp (SASSATAStr, L"SATA") == 0) {
1736 Info |= BIT4;
1737 }
1738
1739 //
1740 // Location is an integer between 0 and 1 or else
1741 // the keyword Internal (0) or External (1).
1742 //
1743 if (StrCmp (LocationStr, L"External") == 0) {
1744 Uint16 = 1;
1745 } else if (StrCmp (LocationStr, L"Internal") == 0) {
1746 Uint16 = 0;
1747 } else {
1748 Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);
1749 }
1750 Info |= (Uint16 << 5);
1751
1752 //
1753 // Connect is an integer between 0 and 3 or else
1754 // the keyword Direct (0) or Expanded (1).
1755 //
1756 if (StrCmp (ConnectStr, L"Expanded") == 0) {
1757 Uint16 = 1;
1758 } else if (StrCmp (ConnectStr, L"Direct") == 0) {
1759 Uint16 = 0;
1760 } else {
1761 Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));
1762 }
1763 Info |= (Uint16 << 6);
1764
1765 } else {
1766 Info = (UINT16) Strtoi (SASSATAStr);
1767 }
1768
1769 SasEx->DeviceTopology = Info;
1770
1771 return (EFI_DEVICE_PATH_PROTOCOL *) SasEx;
1772 }
1773
1774 /**
1775 Converts a text device path node to NVM Express Namespace device path structure.
1776
1777 @param TextDeviceNode The input Text device path node.
1778
1779 @return A pointer to the newly-created NVM Express Namespace device path structure.
1780
1781 **/
1782 EFI_DEVICE_PATH_PROTOCOL *
1783 DevPathFromTextNVMe (
1784 IN CHAR16 *TextDeviceNode
1785 )
1786 {
1787 CHAR16 *NamespaceIdStr;
1788 CHAR16 *NamespaceUuidStr;
1789 NVME_NAMESPACE_DEVICE_PATH *Nvme;
1790 UINT8 *Uuid;
1791 UINTN Index;
1792
1793 NamespaceIdStr = GetNextParamStr (&TextDeviceNode);
1794 NamespaceUuidStr = GetNextParamStr (&TextDeviceNode);
1795 Nvme = (NVME_NAMESPACE_DEVICE_PATH *) CreateDeviceNode (
1796 MESSAGING_DEVICE_PATH,
1797 MSG_NVME_NAMESPACE_DP,
1798 (UINT16) sizeof (NVME_NAMESPACE_DEVICE_PATH)
1799 );
1800
1801 Nvme->NamespaceId = (UINT32) Strtoi (NamespaceIdStr);
1802 Uuid = (UINT8 *) &Nvme->NamespaceUuid;
1803
1804 Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
1805 while (Index-- != 0) {
1806 Uuid[Index] = (UINT8) StrHexToUintn (SplitStr (&NamespaceUuidStr, L'-'));
1807 }
1808
1809 return (EFI_DEVICE_PATH_PROTOCOL *) Nvme;
1810 }
1811
1812 /**
1813 Converts a text device path node to UFS device path structure.
1814
1815 @param TextDeviceNode The input Text device path node.
1816
1817 @return A pointer to the newly-created UFS device path structure.
1818
1819 **/
1820 EFI_DEVICE_PATH_PROTOCOL *
1821 DevPathFromTextUfs (
1822 IN CHAR16 *TextDeviceNode
1823 )
1824 {
1825 CHAR16 *PunStr;
1826 CHAR16 *LunStr;
1827 UFS_DEVICE_PATH *Ufs;
1828
1829 PunStr = GetNextParamStr (&TextDeviceNode);
1830 LunStr = GetNextParamStr (&TextDeviceNode);
1831 Ufs = (UFS_DEVICE_PATH *) CreateDeviceNode (
1832 MESSAGING_DEVICE_PATH,
1833 MSG_UFS_DP,
1834 (UINT16) sizeof (UFS_DEVICE_PATH)
1835 );
1836
1837 Ufs->Pun = (UINT8) Strtoi (PunStr);
1838 Ufs->Lun = (UINT8) Strtoi (LunStr);
1839
1840 return (EFI_DEVICE_PATH_PROTOCOL *) Ufs;
1841 }
1842
1843 /**
1844 Converts a text device path node to SD (Secure Digital) device path structure.
1845
1846 @param TextDeviceNode The input Text device path node.
1847
1848 @return A pointer to the newly-created SD device path structure.
1849
1850 **/
1851 EFI_DEVICE_PATH_PROTOCOL *
1852 DevPathFromTextSd (
1853 IN CHAR16 *TextDeviceNode
1854 )
1855 {
1856 CHAR16 *SlotNumberStr;
1857 SD_DEVICE_PATH *Sd;
1858
1859 SlotNumberStr = GetNextParamStr (&TextDeviceNode);
1860 Sd = (SD_DEVICE_PATH *) CreateDeviceNode (
1861 MESSAGING_DEVICE_PATH,
1862 MSG_SD_DP,
1863 (UINT16) sizeof (SD_DEVICE_PATH)
1864 );
1865
1866 Sd->SlotNumber = (UINT8) Strtoi (SlotNumberStr);
1867
1868 return (EFI_DEVICE_PATH_PROTOCOL *) Sd;
1869 }
1870
1871 /**
1872 Converts a text device path node to Debug Port device path structure.
1873
1874 @param TextDeviceNode The input Text device path node.
1875
1876 @return A pointer to the newly-created Debug Port device path structure.
1877
1878 **/
1879 EFI_DEVICE_PATH_PROTOCOL *
1880 DevPathFromTextDebugPort (
1881 IN CHAR16 *TextDeviceNode
1882 )
1883 {
1884 VENDOR_DEFINED_MESSAGING_DEVICE_PATH *Vend;
1885
1886 Vend = (VENDOR_DEFINED_MESSAGING_DEVICE_PATH *) CreateDeviceNode (
1887 MESSAGING_DEVICE_PATH,
1888 MSG_VENDOR_DP,
1889 (UINT16) sizeof (VENDOR_DEFINED_MESSAGING_DEVICE_PATH)
1890 );
1891
1892 CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
1893
1894 return (EFI_DEVICE_PATH_PROTOCOL *) Vend;
1895 }
1896
1897 /**
1898 Converts a text device path node to MAC device path structure.
1899
1900 @param TextDeviceNode The input Text device path node.
1901
1902 @return A pointer to the newly-created MAC device path structure.
1903
1904 **/
1905 EFI_DEVICE_PATH_PROTOCOL *
1906 DevPathFromTextMAC (
1907 IN CHAR16 *TextDeviceNode
1908 )
1909 {
1910 CHAR16 *AddressStr;
1911 CHAR16 *IfTypeStr;
1912 UINTN Length;
1913 MAC_ADDR_DEVICE_PATH *MACDevPath;
1914
1915 AddressStr = GetNextParamStr (&TextDeviceNode);
1916 IfTypeStr = GetNextParamStr (&TextDeviceNode);
1917 MACDevPath = (MAC_ADDR_DEVICE_PATH *) CreateDeviceNode (
1918 MESSAGING_DEVICE_PATH,
1919 MSG_MAC_ADDR_DP,
1920 (UINT16) sizeof (MAC_ADDR_DEVICE_PATH)
1921 );
1922
1923 MACDevPath->IfType = (UINT8) Strtoi (IfTypeStr);
1924
1925 Length = sizeof (EFI_MAC_ADDRESS);
1926 StrToBuf (&MACDevPath->MacAddress.Addr[0], Length, AddressStr);
1927
1928 return (EFI_DEVICE_PATH_PROTOCOL *) MACDevPath;
1929 }
1930
1931
1932 /**
1933 Converts a text format to the network protocol ID.
1934
1935 @param Text String of protocol field.
1936
1937 @return Network protocol ID .
1938
1939 **/
1940 UINTN
1941 NetworkProtocolFromText (
1942 IN CHAR16 *Text
1943 )
1944 {
1945 if (StrCmp (Text, L"UDP") == 0) {
1946 return RFC_1700_UDP_PROTOCOL;
1947 }
1948
1949 if (StrCmp (Text, L"TCP") == 0) {
1950 return RFC_1700_TCP_PROTOCOL;
1951 }
1952
1953 return Strtoi (Text);
1954 }
1955
1956
1957 /**
1958 Converts a text device path node to IPV4 device path structure.
1959
1960 @param TextDeviceNode The input Text device path node.
1961
1962 @return A pointer to the newly-created IPV4 device path structure.
1963
1964 **/
1965 EFI_DEVICE_PATH_PROTOCOL *
1966 DevPathFromTextIPv4 (
1967 IN CHAR16 *TextDeviceNode
1968 )
1969 {
1970 CHAR16 *RemoteIPStr;
1971 CHAR16 *ProtocolStr;
1972 CHAR16 *TypeStr;
1973 CHAR16 *LocalIPStr;
1974 CHAR16 *GatewayIPStr;
1975 CHAR16 *SubnetMaskStr;
1976 IPv4_DEVICE_PATH *IPv4;
1977
1978 RemoteIPStr = GetNextParamStr (&TextDeviceNode);
1979 ProtocolStr = GetNextParamStr (&TextDeviceNode);
1980 TypeStr = GetNextParamStr (&TextDeviceNode);
1981 LocalIPStr = GetNextParamStr (&TextDeviceNode);
1982 GatewayIPStr = GetNextParamStr (&TextDeviceNode);
1983 SubnetMaskStr = GetNextParamStr (&TextDeviceNode);
1984 IPv4 = (IPv4_DEVICE_PATH *) CreateDeviceNode (
1985 MESSAGING_DEVICE_PATH,
1986 MSG_IPv4_DP,
1987 (UINT16) sizeof (IPv4_DEVICE_PATH)
1988 );
1989
1990 StrToIPv4Addr (&RemoteIPStr, &IPv4->RemoteIpAddress);
1991 IPv4->Protocol = (UINT16) NetworkProtocolFromText (ProtocolStr);
1992 if (StrCmp (TypeStr, L"Static") == 0) {
1993 IPv4->StaticIpAddress = TRUE;
1994 } else {
1995 IPv4->StaticIpAddress = FALSE;
1996 }
1997
1998 StrToIPv4Addr (&LocalIPStr, &IPv4->LocalIpAddress);
1999 if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*SubnetMaskStr)) {
2000 StrToIPv4Addr (&GatewayIPStr, &IPv4->GatewayIpAddress);
2001 StrToIPv4Addr (&SubnetMaskStr, &IPv4->SubnetMask);
2002 } else {
2003 ZeroMem (&IPv4->GatewayIpAddress, sizeof (IPv4->GatewayIpAddress));
2004 ZeroMem (&IPv4->SubnetMask, sizeof (IPv4->SubnetMask));
2005 }
2006
2007 IPv4->LocalPort = 0;
2008 IPv4->RemotePort = 0;
2009
2010 return (EFI_DEVICE_PATH_PROTOCOL *) IPv4;
2011 }
2012
2013 /**
2014 Converts a text device path node to IPV6 device path structure.
2015
2016 @param TextDeviceNode The input Text device path node.
2017
2018 @return A pointer to the newly-created IPV6 device path structure.
2019
2020 **/
2021 EFI_DEVICE_PATH_PROTOCOL *
2022 DevPathFromTextIPv6 (
2023 IN CHAR16 *TextDeviceNode
2024 )
2025 {
2026 CHAR16 *RemoteIPStr;
2027 CHAR16 *ProtocolStr;
2028 CHAR16 *TypeStr;
2029 CHAR16 *LocalIPStr;
2030 CHAR16 *GatewayIPStr;
2031 CHAR16 *PrefixLengthStr;
2032 IPv6_DEVICE_PATH *IPv6;
2033
2034 RemoteIPStr = GetNextParamStr (&TextDeviceNode);
2035 ProtocolStr = GetNextParamStr (&TextDeviceNode);
2036 TypeStr = GetNextParamStr (&TextDeviceNode);
2037 LocalIPStr = GetNextParamStr (&TextDeviceNode);
2038 PrefixLengthStr = GetNextParamStr (&TextDeviceNode);
2039 GatewayIPStr = GetNextParamStr (&TextDeviceNode);
2040 IPv6 = (IPv6_DEVICE_PATH *) CreateDeviceNode (
2041 MESSAGING_DEVICE_PATH,
2042 MSG_IPv6_DP,
2043 (UINT16) sizeof (IPv6_DEVICE_PATH)
2044 );
2045
2046 StrToIPv6Addr (&RemoteIPStr, &IPv6->RemoteIpAddress);
2047 IPv6->Protocol = (UINT16) NetworkProtocolFromText (ProtocolStr);
2048 if (StrCmp (TypeStr, L"Static") == 0) {
2049 IPv6->IpAddressOrigin = 0;
2050 } else if (StrCmp (TypeStr, L"StatelessAutoConfigure") == 0) {
2051 IPv6->IpAddressOrigin = 1;
2052 } else {
2053 IPv6->IpAddressOrigin = 2;
2054 }
2055
2056 StrToIPv6Addr (&LocalIPStr, &IPv6->LocalIpAddress);
2057 if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*PrefixLengthStr)) {
2058 StrToIPv6Addr (&GatewayIPStr, &IPv6->GatewayIpAddress);
2059 IPv6->PrefixLength = (UINT8) Strtoi (PrefixLengthStr);
2060 } else {
2061 ZeroMem (&IPv6->GatewayIpAddress, sizeof (IPv6->GatewayIpAddress));
2062 IPv6->PrefixLength = 0;
2063 }
2064
2065 IPv6->LocalPort = 0;
2066 IPv6->RemotePort = 0;
2067
2068 return (EFI_DEVICE_PATH_PROTOCOL *) IPv6;
2069 }
2070
2071 /**
2072 Converts a text device path node to UART device path structure.
2073
2074 @param TextDeviceNode The input Text device path node.
2075
2076 @return A pointer to the newly-created UART device path structure.
2077
2078 **/
2079 EFI_DEVICE_PATH_PROTOCOL *
2080 DevPathFromTextUart (
2081 IN CHAR16 *TextDeviceNode
2082 )
2083 {
2084 CHAR16 *BaudStr;
2085 CHAR16 *DataBitsStr;
2086 CHAR16 *ParityStr;
2087 CHAR16 *StopBitsStr;
2088 UART_DEVICE_PATH *Uart;
2089
2090 BaudStr = GetNextParamStr (&TextDeviceNode);
2091 DataBitsStr = GetNextParamStr (&TextDeviceNode);
2092 ParityStr = GetNextParamStr (&TextDeviceNode);
2093 StopBitsStr = GetNextParamStr (&TextDeviceNode);
2094 Uart = (UART_DEVICE_PATH *) CreateDeviceNode (
2095 MESSAGING_DEVICE_PATH,
2096 MSG_UART_DP,
2097 (UINT16) sizeof (UART_DEVICE_PATH)
2098 );
2099
2100 if (StrCmp (BaudStr, L"DEFAULT") == 0) {
2101 Uart->BaudRate = 115200;
2102 } else {
2103 Strtoi64 (BaudStr, &Uart->BaudRate);
2104 }
2105 Uart->DataBits = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : Strtoi (DataBitsStr));
2106 switch (*ParityStr) {
2107 case L'D':
2108 Uart->Parity = 0;
2109 break;
2110
2111 case L'N':
2112 Uart->Parity = 1;
2113 break;
2114
2115 case L'E':
2116 Uart->Parity = 2;
2117 break;
2118
2119 case L'O':
2120 Uart->Parity = 3;
2121 break;
2122
2123 case L'M':
2124 Uart->Parity = 4;
2125 break;
2126
2127 case L'S':
2128 Uart->Parity = 5;
2129 break;
2130
2131 default:
2132 Uart->Parity = (UINT8) Strtoi (ParityStr);
2133 break;
2134 }
2135
2136 if (StrCmp (StopBitsStr, L"D") == 0) {
2137 Uart->StopBits = (UINT8) 0;
2138 } else if (StrCmp (StopBitsStr, L"1") == 0) {
2139 Uart->StopBits = (UINT8) 1;
2140 } else if (StrCmp (StopBitsStr, L"1.5") == 0) {
2141 Uart->StopBits = (UINT8) 2;
2142 } else if (StrCmp (StopBitsStr, L"2") == 0) {
2143 Uart->StopBits = (UINT8) 3;
2144 } else {
2145 Uart->StopBits = (UINT8) Strtoi (StopBitsStr);
2146 }
2147
2148 return (EFI_DEVICE_PATH_PROTOCOL *) Uart;
2149 }
2150
2151 /**
2152 Converts a text device path node to USB class device path structure.
2153
2154 @param TextDeviceNode The input Text device path node.
2155 @param UsbClassText A pointer to USB_CLASS_TEXT structure to be integrated to USB Class Text.
2156
2157 @return A pointer to the newly-created USB class device path structure.
2158
2159 **/
2160 EFI_DEVICE_PATH_PROTOCOL *
2161 ConvertFromTextUsbClass (
2162 IN CHAR16 *TextDeviceNode,
2163 IN USB_CLASS_TEXT *UsbClassText
2164 )
2165 {
2166 CHAR16 *VIDStr;
2167 CHAR16 *PIDStr;
2168 CHAR16 *ClassStr;
2169 CHAR16 *SubClassStr;
2170 CHAR16 *ProtocolStr;
2171 USB_CLASS_DEVICE_PATH *UsbClass;
2172
2173 UsbClass = (USB_CLASS_DEVICE_PATH *) CreateDeviceNode (
2174 MESSAGING_DEVICE_PATH,
2175 MSG_USB_CLASS_DP,
2176 (UINT16) sizeof (USB_CLASS_DEVICE_PATH)
2177 );
2178
2179 VIDStr = GetNextParamStr (&TextDeviceNode);
2180 PIDStr = GetNextParamStr (&TextDeviceNode);
2181 if (UsbClassText->ClassExist) {
2182 ClassStr = GetNextParamStr (&TextDeviceNode);
2183 UsbClass->DeviceClass = (UINT8) Strtoi (ClassStr);
2184 } else {
2185 UsbClass->DeviceClass = UsbClassText->Class;
2186 }
2187 if (UsbClassText->SubClassExist) {
2188 SubClassStr = GetNextParamStr (&TextDeviceNode);
2189 UsbClass->DeviceSubClass = (UINT8) Strtoi (SubClassStr);
2190 } else {
2191 UsbClass->DeviceSubClass = UsbClassText->SubClass;
2192 }
2193
2194 ProtocolStr = GetNextParamStr (&TextDeviceNode);
2195
2196 UsbClass->VendorId = (UINT16) Strtoi (VIDStr);
2197 UsbClass->ProductId = (UINT16) Strtoi (PIDStr);
2198 UsbClass->DeviceProtocol = (UINT8) Strtoi (ProtocolStr);
2199
2200 return (EFI_DEVICE_PATH_PROTOCOL *) UsbClass;
2201 }
2202
2203
2204 /**
2205 Converts a text device path node to USB class device path structure.
2206
2207 @param TextDeviceNode The input Text device path node.
2208
2209 @return A pointer to the newly-created USB class device path structure.
2210
2211 **/
2212 EFI_DEVICE_PATH_PROTOCOL *
2213 DevPathFromTextUsbClass (
2214 IN CHAR16 *TextDeviceNode
2215 )
2216 {
2217 USB_CLASS_TEXT UsbClassText;
2218
2219 UsbClassText.ClassExist = TRUE;
2220 UsbClassText.SubClassExist = TRUE;
2221
2222 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2223 }
2224
2225 /**
2226 Converts a text device path node to USB audio device path structure.
2227
2228 @param TextDeviceNode The input Text device path node.
2229
2230 @return A pointer to the newly-created USB audio device path structure.
2231
2232 **/
2233 EFI_DEVICE_PATH_PROTOCOL *
2234 DevPathFromTextUsbAudio (
2235 IN CHAR16 *TextDeviceNode
2236 )
2237 {
2238 USB_CLASS_TEXT UsbClassText;
2239
2240 UsbClassText.ClassExist = FALSE;
2241 UsbClassText.Class = USB_CLASS_AUDIO;
2242 UsbClassText.SubClassExist = TRUE;
2243
2244 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2245 }
2246
2247 /**
2248 Converts a text device path node to USB CDC Control device path structure.
2249
2250 @param TextDeviceNode The input Text device path node.
2251
2252 @return A pointer to the newly-created USB CDC Control device path structure.
2253
2254 **/
2255 EFI_DEVICE_PATH_PROTOCOL *
2256 DevPathFromTextUsbCDCControl (
2257 IN CHAR16 *TextDeviceNode
2258 )
2259 {
2260 USB_CLASS_TEXT UsbClassText;
2261
2262 UsbClassText.ClassExist = FALSE;
2263 UsbClassText.Class = USB_CLASS_CDCCONTROL;
2264 UsbClassText.SubClassExist = TRUE;
2265
2266 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2267 }
2268
2269 /**
2270 Converts a text device path node to USB HID device path structure.
2271
2272 @param TextDeviceNode The input Text device path node.
2273
2274 @return A pointer to the newly-created USB HID device path structure.
2275
2276 **/
2277 EFI_DEVICE_PATH_PROTOCOL *
2278 DevPathFromTextUsbHID (
2279 IN CHAR16 *TextDeviceNode
2280 )
2281 {
2282 USB_CLASS_TEXT UsbClassText;
2283
2284 UsbClassText.ClassExist = FALSE;
2285 UsbClassText.Class = USB_CLASS_HID;
2286 UsbClassText.SubClassExist = TRUE;
2287
2288 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2289 }
2290
2291 /**
2292 Converts a text device path node to USB Image device path structure.
2293
2294 @param TextDeviceNode The input Text device path node.
2295
2296 @return A pointer to the newly-created USB Image device path structure.
2297
2298 **/
2299 EFI_DEVICE_PATH_PROTOCOL *
2300 DevPathFromTextUsbImage (
2301 IN CHAR16 *TextDeviceNode
2302 )
2303 {
2304 USB_CLASS_TEXT UsbClassText;
2305
2306 UsbClassText.ClassExist = FALSE;
2307 UsbClassText.Class = USB_CLASS_IMAGE;
2308 UsbClassText.SubClassExist = TRUE;
2309
2310 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2311 }
2312
2313 /**
2314 Converts a text device path node to USB Print device path structure.
2315
2316 @param TextDeviceNode The input Text device path node.
2317
2318 @return A pointer to the newly-created USB Print device path structure.
2319
2320 **/
2321 EFI_DEVICE_PATH_PROTOCOL *
2322 DevPathFromTextUsbPrinter (
2323 IN CHAR16 *TextDeviceNode
2324 )
2325 {
2326 USB_CLASS_TEXT UsbClassText;
2327
2328 UsbClassText.ClassExist = FALSE;
2329 UsbClassText.Class = USB_CLASS_PRINTER;
2330 UsbClassText.SubClassExist = TRUE;
2331
2332 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2333 }
2334
2335 /**
2336 Converts a text device path node to USB mass storage device path structure.
2337
2338 @param TextDeviceNode The input Text device path node.
2339
2340 @return A pointer to the newly-created USB mass storage device path structure.
2341
2342 **/
2343 EFI_DEVICE_PATH_PROTOCOL *
2344 DevPathFromTextUsbMassStorage (
2345 IN CHAR16 *TextDeviceNode
2346 )
2347 {
2348 USB_CLASS_TEXT UsbClassText;
2349
2350 UsbClassText.ClassExist = FALSE;
2351 UsbClassText.Class = USB_CLASS_MASS_STORAGE;
2352 UsbClassText.SubClassExist = TRUE;
2353
2354 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2355 }
2356
2357 /**
2358 Converts a text device path node to USB HUB device path structure.
2359
2360 @param TextDeviceNode The input Text device path node.
2361
2362 @return A pointer to the newly-created USB HUB device path structure.
2363
2364 **/
2365 EFI_DEVICE_PATH_PROTOCOL *
2366 DevPathFromTextUsbHub (
2367 IN CHAR16 *TextDeviceNode
2368 )
2369 {
2370 USB_CLASS_TEXT UsbClassText;
2371
2372 UsbClassText.ClassExist = FALSE;
2373 UsbClassText.Class = USB_CLASS_HUB;
2374 UsbClassText.SubClassExist = TRUE;
2375
2376 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2377 }
2378
2379 /**
2380 Converts a text device path node to USB CDC data device path structure.
2381
2382 @param TextDeviceNode The input Text device path node.
2383
2384 @return A pointer to the newly-created USB CDC data device path structure.
2385
2386 **/
2387 EFI_DEVICE_PATH_PROTOCOL *
2388 DevPathFromTextUsbCDCData (
2389 IN CHAR16 *TextDeviceNode
2390 )
2391 {
2392 USB_CLASS_TEXT UsbClassText;
2393
2394 UsbClassText.ClassExist = FALSE;
2395 UsbClassText.Class = USB_CLASS_CDCDATA;
2396 UsbClassText.SubClassExist = TRUE;
2397
2398 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2399 }
2400
2401 /**
2402 Converts a text device path node to USB smart card device path structure.
2403
2404 @param TextDeviceNode The input Text device path node.
2405
2406 @return A pointer to the newly-created USB smart card device path structure.
2407
2408 **/
2409 EFI_DEVICE_PATH_PROTOCOL *
2410 DevPathFromTextUsbSmartCard (
2411 IN CHAR16 *TextDeviceNode
2412 )
2413 {
2414 USB_CLASS_TEXT UsbClassText;
2415
2416 UsbClassText.ClassExist = FALSE;
2417 UsbClassText.Class = USB_CLASS_SMART_CARD;
2418 UsbClassText.SubClassExist = TRUE;
2419
2420 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2421 }
2422
2423 /**
2424 Converts a text device path node to USB video device path structure.
2425
2426 @param TextDeviceNode The input Text device path node.
2427
2428 @return A pointer to the newly-created USB video device path structure.
2429
2430 **/
2431 EFI_DEVICE_PATH_PROTOCOL *
2432 DevPathFromTextUsbVideo (
2433 IN CHAR16 *TextDeviceNode
2434 )
2435 {
2436 USB_CLASS_TEXT UsbClassText;
2437
2438 UsbClassText.ClassExist = FALSE;
2439 UsbClassText.Class = USB_CLASS_VIDEO;
2440 UsbClassText.SubClassExist = TRUE;
2441
2442 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2443 }
2444
2445 /**
2446 Converts a text device path node to USB diagnostic device path structure.
2447
2448 @param TextDeviceNode The input Text device path node.
2449
2450 @return A pointer to the newly-created USB diagnostic device path structure.
2451
2452 **/
2453 EFI_DEVICE_PATH_PROTOCOL *
2454 DevPathFromTextUsbDiagnostic (
2455 IN CHAR16 *TextDeviceNode
2456 )
2457 {
2458 USB_CLASS_TEXT UsbClassText;
2459
2460 UsbClassText.ClassExist = FALSE;
2461 UsbClassText.Class = USB_CLASS_DIAGNOSTIC;
2462 UsbClassText.SubClassExist = TRUE;
2463
2464 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2465 }
2466
2467 /**
2468 Converts a text device path node to USB wireless device path structure.
2469
2470 @param TextDeviceNode The input Text device path node.
2471
2472 @return A pointer to the newly-created USB wireless device path structure.
2473
2474 **/
2475 EFI_DEVICE_PATH_PROTOCOL *
2476 DevPathFromTextUsbWireless (
2477 IN CHAR16 *TextDeviceNode
2478 )
2479 {
2480 USB_CLASS_TEXT UsbClassText;
2481
2482 UsbClassText.ClassExist = FALSE;
2483 UsbClassText.Class = USB_CLASS_WIRELESS;
2484 UsbClassText.SubClassExist = TRUE;
2485
2486 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2487 }
2488
2489 /**
2490 Converts a text device path node to USB device firmware update device path structure.
2491
2492 @param TextDeviceNode The input Text device path node.
2493
2494 @return A pointer to the newly-created USB device firmware update device path structure.
2495
2496 **/
2497 EFI_DEVICE_PATH_PROTOCOL *
2498 DevPathFromTextUsbDeviceFirmwareUpdate (
2499 IN CHAR16 *TextDeviceNode
2500 )
2501 {
2502 USB_CLASS_TEXT UsbClassText;
2503
2504 UsbClassText.ClassExist = FALSE;
2505 UsbClassText.Class = USB_CLASS_RESERVE;
2506 UsbClassText.SubClassExist = FALSE;
2507 UsbClassText.SubClass = USB_SUBCLASS_FW_UPDATE;
2508
2509 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2510 }
2511
2512 /**
2513 Converts a text device path node to USB IRDA bridge device path structure.
2514
2515 @param TextDeviceNode The input Text device path node.
2516
2517 @return A pointer to the newly-created USB IRDA bridge device path structure.
2518
2519 **/
2520 EFI_DEVICE_PATH_PROTOCOL *
2521 DevPathFromTextUsbIrdaBridge (
2522 IN CHAR16 *TextDeviceNode
2523 )
2524 {
2525 USB_CLASS_TEXT UsbClassText;
2526
2527 UsbClassText.ClassExist = FALSE;
2528 UsbClassText.Class = USB_CLASS_RESERVE;
2529 UsbClassText.SubClassExist = FALSE;
2530 UsbClassText.SubClass = USB_SUBCLASS_IRDA_BRIDGE;
2531
2532 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2533 }
2534
2535 /**
2536 Converts a text device path node to USB text and measurement device path structure.
2537
2538 @param TextDeviceNode The input Text device path node.
2539
2540 @return A pointer to the newly-created USB text and measurement device path structure.
2541
2542 **/
2543 EFI_DEVICE_PATH_PROTOCOL *
2544 DevPathFromTextUsbTestAndMeasurement (
2545 IN CHAR16 *TextDeviceNode
2546 )
2547 {
2548 USB_CLASS_TEXT UsbClassText;
2549
2550 UsbClassText.ClassExist = FALSE;
2551 UsbClassText.Class = USB_CLASS_RESERVE;
2552 UsbClassText.SubClassExist = FALSE;
2553 UsbClassText.SubClass = USB_SUBCLASS_TEST;
2554
2555 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2556 }
2557
2558 /**
2559 Converts a text device path node to USB WWID device path structure.
2560
2561 @param TextDeviceNode The input Text device path node.
2562
2563 @return A pointer to the newly-created USB WWID device path structure.
2564
2565 **/
2566 EFI_DEVICE_PATH_PROTOCOL *
2567 DevPathFromTextUsbWwid (
2568 IN CHAR16 *TextDeviceNode
2569 )
2570 {
2571 CHAR16 *VIDStr;
2572 CHAR16 *PIDStr;
2573 CHAR16 *InterfaceNumStr;
2574 CHAR16 *SerialNumberStr;
2575 USB_WWID_DEVICE_PATH *UsbWwid;
2576 UINTN SerialNumberStrLen;
2577
2578 VIDStr = GetNextParamStr (&TextDeviceNode);
2579 PIDStr = GetNextParamStr (&TextDeviceNode);
2580 InterfaceNumStr = GetNextParamStr (&TextDeviceNode);
2581 SerialNumberStr = GetNextParamStr (&TextDeviceNode);
2582 SerialNumberStrLen = StrLen (SerialNumberStr);
2583 if (SerialNumberStrLen >= 2 &&
2584 SerialNumberStr[0] == L'\"' &&
2585 SerialNumberStr[SerialNumberStrLen - 1] == L'\"'
2586 ) {
2587 SerialNumberStr[SerialNumberStrLen - 1] = L'\0';
2588 SerialNumberStr++;
2589 SerialNumberStrLen -= 2;
2590 }
2591 UsbWwid = (USB_WWID_DEVICE_PATH *) CreateDeviceNode (
2592 MESSAGING_DEVICE_PATH,
2593 MSG_USB_WWID_DP,
2594 (UINT16) (sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16))
2595 );
2596 UsbWwid->VendorId = (UINT16) Strtoi (VIDStr);
2597 UsbWwid->ProductId = (UINT16) Strtoi (PIDStr);
2598 UsbWwid->InterfaceNumber = (UINT16) Strtoi (InterfaceNumStr);
2599
2600 //
2601 // There is no memory allocated in UsbWwid for the '\0' in SerialNumberStr.
2602 // Therefore, the '\0' will not be copied.
2603 //
2604 CopyMem (
2605 (UINT8 *) UsbWwid + sizeof (USB_WWID_DEVICE_PATH),
2606 SerialNumberStr,
2607 SerialNumberStrLen * sizeof (CHAR16)
2608 );
2609
2610 return (EFI_DEVICE_PATH_PROTOCOL *) UsbWwid;
2611 }
2612
2613 /**
2614 Converts a text device path node to Logic Unit device path structure.
2615
2616 @param TextDeviceNode The input Text device path node.
2617
2618 @return A pointer to the newly-created Logic Unit device path structure.
2619
2620 **/
2621 EFI_DEVICE_PATH_PROTOCOL *
2622 DevPathFromTextUnit (
2623 IN CHAR16 *TextDeviceNode
2624 )
2625 {
2626 CHAR16 *LunStr;
2627 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
2628
2629 LunStr = GetNextParamStr (&TextDeviceNode);
2630 LogicalUnit = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) CreateDeviceNode (
2631 MESSAGING_DEVICE_PATH,
2632 MSG_DEVICE_LOGICAL_UNIT_DP,
2633 (UINT16) sizeof (DEVICE_LOGICAL_UNIT_DEVICE_PATH)
2634 );
2635
2636 LogicalUnit->Lun = (UINT8) Strtoi (LunStr);
2637
2638 return (EFI_DEVICE_PATH_PROTOCOL *) LogicalUnit;
2639 }
2640
2641 /**
2642 Converts a text device path node to iSCSI device path structure.
2643
2644 @param TextDeviceNode The input Text device path node.
2645
2646 @return A pointer to the newly-created iSCSI device path structure.
2647
2648 **/
2649 EFI_DEVICE_PATH_PROTOCOL *
2650 DevPathFromTextiSCSI (
2651 IN CHAR16 *TextDeviceNode
2652 )
2653 {
2654 UINT16 Options;
2655 CHAR16 *NameStr;
2656 CHAR16 *PortalGroupStr;
2657 CHAR16 *LunStr;
2658 CHAR16 *HeaderDigestStr;
2659 CHAR16 *DataDigestStr;
2660 CHAR16 *AuthenticationStr;
2661 CHAR16 *ProtocolStr;
2662 CHAR8 *AsciiStr;
2663 ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;
2664
2665 NameStr = GetNextParamStr (&TextDeviceNode);
2666 PortalGroupStr = GetNextParamStr (&TextDeviceNode);
2667 LunStr = GetNextParamStr (&TextDeviceNode);
2668 HeaderDigestStr = GetNextParamStr (&TextDeviceNode);
2669 DataDigestStr = GetNextParamStr (&TextDeviceNode);
2670 AuthenticationStr = GetNextParamStr (&TextDeviceNode);
2671 ProtocolStr = GetNextParamStr (&TextDeviceNode);
2672 ISCSIDevPath = (ISCSI_DEVICE_PATH_WITH_NAME *) CreateDeviceNode (
2673 MESSAGING_DEVICE_PATH,
2674 MSG_ISCSI_DP,
2675 (UINT16) (sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + StrLen (NameStr))
2676 );
2677
2678 AsciiStr = ISCSIDevPath->TargetName;
2679 StrToAscii (NameStr, &AsciiStr);
2680
2681 ISCSIDevPath->TargetPortalGroupTag = (UINT16) Strtoi (PortalGroupStr);
2682 Strtoi64 (LunStr, &ISCSIDevPath->Lun);
2683
2684 Options = 0x0000;
2685 if (StrCmp (HeaderDigestStr, L"CRC32C") == 0) {
2686 Options |= 0x0002;
2687 }
2688
2689 if (StrCmp (DataDigestStr, L"CRC32C") == 0) {
2690 Options |= 0x0008;
2691 }
2692
2693 if (StrCmp (AuthenticationStr, L"None") == 0) {
2694 Options |= 0x0800;
2695 }
2696
2697 if (StrCmp (AuthenticationStr, L"CHAP_UNI") == 0) {
2698 Options |= 0x1000;
2699 }
2700
2701 ISCSIDevPath->LoginOption = (UINT16) Options;
2702
2703 ISCSIDevPath->NetworkProtocol = (UINT16) StrCmp (ProtocolStr, L"TCP");
2704
2705 return (EFI_DEVICE_PATH_PROTOCOL *) ISCSIDevPath;
2706 }
2707
2708 /**
2709 Converts a text device path node to VLAN device path structure.
2710
2711 @param TextDeviceNode The input Text device path node.
2712
2713 @return A pointer to the newly-created VLAN device path structure.
2714
2715 **/
2716 EFI_DEVICE_PATH_PROTOCOL *
2717 DevPathFromTextVlan (
2718 IN CHAR16 *TextDeviceNode
2719 )
2720 {
2721 CHAR16 *VlanStr;
2722 VLAN_DEVICE_PATH *Vlan;
2723
2724 VlanStr = GetNextParamStr (&TextDeviceNode);
2725 Vlan = (VLAN_DEVICE_PATH *) CreateDeviceNode (
2726 MESSAGING_DEVICE_PATH,
2727 MSG_VLAN_DP,
2728 (UINT16) sizeof (VLAN_DEVICE_PATH)
2729 );
2730
2731 Vlan->VlanId = (UINT16) Strtoi (VlanStr);
2732
2733 return (EFI_DEVICE_PATH_PROTOCOL *) Vlan;
2734 }
2735
2736 /**
2737 Converts a text device path node to Bluetooth device path structure.
2738
2739 @param TextDeviceNode The input Text device path node.
2740
2741 @return A pointer to the newly-created Bluetooth device path structure.
2742
2743 **/
2744 EFI_DEVICE_PATH_PROTOCOL *
2745 DevPathFromTextBluetooth (
2746 IN CHAR16 *TextDeviceNode
2747 )
2748 {
2749 CHAR16 *BluetoothStr;
2750 CHAR16 *Walker;
2751 CHAR16 *TempNumBuffer;
2752 UINTN TempBufferSize;
2753 INT32 Index;
2754 BLUETOOTH_DEVICE_PATH *BluetoothDp;
2755
2756 BluetoothStr = GetNextParamStr (&TextDeviceNode);
2757 BluetoothDp = (BLUETOOTH_DEVICE_PATH *) CreateDeviceNode (
2758 MESSAGING_DEVICE_PATH,
2759 MSG_BLUETOOTH_DP,
2760 (UINT16) sizeof (BLUETOOTH_DEVICE_PATH)
2761 );
2762
2763 Index = sizeof (BLUETOOTH_ADDRESS) - 1;
2764 while (!IS_NULL(BluetoothStr) && Index >= 0) {
2765 Walker = SplitStr (&BluetoothStr, L':');
2766 TempBufferSize = StrSize (Walker) + StrLen (L"0x") * sizeof (CHAR16);
2767 TempNumBuffer = AllocateZeroPool (TempBufferSize);
2768 if (TempNumBuffer == NULL) {
2769 break;
2770 }
2771 StrCpyS (TempNumBuffer, TempBufferSize / sizeof (CHAR16), L"0x");
2772 StrCatS (TempNumBuffer, TempBufferSize / sizeof (CHAR16), Walker);
2773 BluetoothDp->BD_ADDR.Address[Index] = (UINT8)Strtoi (TempNumBuffer);
2774 FreePool (TempNumBuffer);
2775 Index--;
2776 }
2777
2778 return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothDp;
2779 }
2780
2781 /**
2782 Converts a text device path node to Wi-Fi device path structure.
2783
2784 @param TextDeviceNode The input Text device path node.
2785
2786 @return A pointer to the newly-created Wi-Fi device path structure.
2787
2788 **/
2789 EFI_DEVICE_PATH_PROTOCOL *
2790 DevPathFromTextWiFi (
2791 IN CHAR16 *TextDeviceNode
2792 )
2793 {
2794 CHAR16 *SSIdStr;
2795 CHAR8 *AsciiStr;
2796 WIFI_DEVICE_PATH *WiFiDp;
2797
2798 SSIdStr = GetNextParamStr (&TextDeviceNode);
2799 WiFiDp = (WIFI_DEVICE_PATH *) CreateDeviceNode (
2800 MESSAGING_DEVICE_PATH,
2801 MSG_WIFI_DP,
2802 (UINT16) sizeof (WIFI_DEVICE_PATH)
2803 );
2804
2805 AsciiStr = (CHAR8 *) WiFiDp->SSId;
2806 StrToAscii (SSIdStr, &AsciiStr);
2807
2808 return (EFI_DEVICE_PATH_PROTOCOL *) WiFiDp;
2809 }
2810
2811 /**
2812 Converts a text device path node to URI device path structure.
2813
2814 @param TextDeviceNode The input Text device path node.
2815
2816 @return A pointer to the newly-created URI device path structure.
2817
2818 **/
2819 EFI_DEVICE_PATH_PROTOCOL *
2820 DevPathFromTextUri (
2821 IN CHAR16 *TextDeviceNode
2822 )
2823 {
2824 CHAR16 *UriStr;
2825 UINTN UriLength;
2826 URI_DEVICE_PATH *Uri;
2827
2828 UriStr = GetNextParamStr (&TextDeviceNode);
2829 UriLength = StrnLenS (UriStr, MAX_UINT16 - sizeof (URI_DEVICE_PATH));
2830 Uri = (URI_DEVICE_PATH *) CreateDeviceNode (
2831 MESSAGING_DEVICE_PATH,
2832 MSG_URI_DP,
2833 (UINT16) (sizeof (URI_DEVICE_PATH) + UriLength)
2834 );
2835
2836 while (UriLength-- != 0) {
2837 Uri->Uri[UriLength] = (CHAR8) UriStr[UriLength];
2838 }
2839
2840 return (EFI_DEVICE_PATH_PROTOCOL *) Uri;
2841 }
2842
2843 /**
2844 Converts a media text device path node to media device path structure.
2845
2846 @param TextDeviceNode The input Text device path node.
2847
2848 @return A pointer to media device path structure.
2849
2850 **/
2851 EFI_DEVICE_PATH_PROTOCOL *
2852 DevPathFromTextMediaPath (
2853 IN CHAR16 *TextDeviceNode
2854 )
2855 {
2856 return DevPathFromTextGenericPath (MEDIA_DEVICE_PATH, TextDeviceNode);
2857 }
2858
2859 /**
2860 Converts a text device path node to HD device path structure.
2861
2862 @param TextDeviceNode The input Text device path node.
2863
2864 @return A pointer to the newly-created HD device path structure.
2865
2866 **/
2867 EFI_DEVICE_PATH_PROTOCOL *
2868 DevPathFromTextHD (
2869 IN CHAR16 *TextDeviceNode
2870 )
2871 {
2872 CHAR16 *PartitionStr;
2873 CHAR16 *TypeStr;
2874 CHAR16 *SignatureStr;
2875 CHAR16 *StartStr;
2876 CHAR16 *SizeStr;
2877 UINT32 Signature32;
2878 EFI_GUID SignatureGuid;
2879 HARDDRIVE_DEVICE_PATH *Hd;
2880
2881 PartitionStr = GetNextParamStr (&TextDeviceNode);
2882 TypeStr = GetNextParamStr (&TextDeviceNode);
2883 SignatureStr = GetNextParamStr (&TextDeviceNode);
2884 StartStr = GetNextParamStr (&TextDeviceNode);
2885 SizeStr = GetNextParamStr (&TextDeviceNode);
2886 Hd = (HARDDRIVE_DEVICE_PATH *) CreateDeviceNode (
2887 MEDIA_DEVICE_PATH,
2888 MEDIA_HARDDRIVE_DP,
2889 (UINT16) sizeof (HARDDRIVE_DEVICE_PATH)
2890 );
2891
2892 Hd->PartitionNumber = (UINT32) Strtoi (PartitionStr);
2893
2894 ZeroMem (Hd->Signature, 16);
2895 Hd->MBRType = (UINT8) 0;
2896
2897 if (StrCmp (TypeStr, L"MBR") == 0) {
2898 Hd->SignatureType = SIGNATURE_TYPE_MBR;
2899 Hd->MBRType = 0x01;
2900
2901 Signature32 = (UINT32) Strtoi (SignatureStr);
2902 CopyMem (Hd->Signature, &Signature32, sizeof (UINT32));
2903 } else if (StrCmp (TypeStr, L"GPT") == 0) {
2904 Hd->SignatureType = SIGNATURE_TYPE_GUID;
2905 Hd->MBRType = 0x02;
2906
2907 StrToGuid (SignatureStr, &SignatureGuid);
2908 CopyMem (Hd->Signature, &SignatureGuid, sizeof (EFI_GUID));
2909 } else {
2910 Hd->SignatureType = (UINT8) Strtoi (TypeStr);
2911 }
2912
2913 Strtoi64 (StartStr, &Hd->PartitionStart);
2914 Strtoi64 (SizeStr, &Hd->PartitionSize);
2915
2916 return (EFI_DEVICE_PATH_PROTOCOL *) Hd;
2917 }
2918
2919 /**
2920 Converts a text device path node to CDROM device path structure.
2921
2922 @param TextDeviceNode The input Text device path node.
2923
2924 @return A pointer to the newly-created CDROM device path structure.
2925
2926 **/
2927 EFI_DEVICE_PATH_PROTOCOL *
2928 DevPathFromTextCDROM (
2929 IN CHAR16 *TextDeviceNode
2930 )
2931 {
2932 CHAR16 *EntryStr;
2933 CHAR16 *StartStr;
2934 CHAR16 *SizeStr;
2935 CDROM_DEVICE_PATH *CDROMDevPath;
2936
2937 EntryStr = GetNextParamStr (&TextDeviceNode);
2938 StartStr = GetNextParamStr (&TextDeviceNode);
2939 SizeStr = GetNextParamStr (&TextDeviceNode);
2940 CDROMDevPath = (CDROM_DEVICE_PATH *) CreateDeviceNode (
2941 MEDIA_DEVICE_PATH,
2942 MEDIA_CDROM_DP,
2943 (UINT16) sizeof (CDROM_DEVICE_PATH)
2944 );
2945
2946 CDROMDevPath->BootEntry = (UINT32) Strtoi (EntryStr);
2947 Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
2948 Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
2949
2950 return (EFI_DEVICE_PATH_PROTOCOL *) CDROMDevPath;
2951 }
2952
2953 /**
2954 Converts a text device path node to Vendor-defined media device path structure.
2955
2956 @param TextDeviceNode The input Text device path node.
2957
2958 @return A pointer to the newly-created Vendor-defined media device path structure.
2959
2960 **/
2961 EFI_DEVICE_PATH_PROTOCOL *
2962 DevPathFromTextVenMedia (
2963 IN CHAR16 *TextDeviceNode
2964 )
2965 {
2966 return ConvertFromTextVendor (
2967 TextDeviceNode,
2968 MEDIA_DEVICE_PATH,
2969 MEDIA_VENDOR_DP
2970 );
2971 }
2972
2973 /**
2974 Converts a text device path node to File device path structure.
2975
2976 @param TextDeviceNode The input Text device path node.
2977
2978 @return A pointer to the newly-created File device path structure.
2979
2980 **/
2981 EFI_DEVICE_PATH_PROTOCOL *
2982 DevPathFromTextFilePath (
2983 IN CHAR16 *TextDeviceNode
2984 )
2985 {
2986 FILEPATH_DEVICE_PATH *File;
2987
2988 File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (
2989 MEDIA_DEVICE_PATH,
2990 MEDIA_FILEPATH_DP,
2991 (UINT16) (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2)
2992 );
2993
2994 StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode);
2995
2996 return (EFI_DEVICE_PATH_PROTOCOL *) File;
2997 }
2998
2999 /**
3000 Converts a text device path node to Media protocol device path structure.
3001
3002 @param TextDeviceNode The input Text device path node.
3003
3004 @return A pointer to the newly-created Media protocol device path structure.
3005
3006 **/
3007 EFI_DEVICE_PATH_PROTOCOL *
3008 DevPathFromTextMedia (
3009 IN CHAR16 *TextDeviceNode
3010 )
3011 {
3012 CHAR16 *GuidStr;
3013 MEDIA_PROTOCOL_DEVICE_PATH *Media;
3014
3015 GuidStr = GetNextParamStr (&TextDeviceNode);
3016 Media = (MEDIA_PROTOCOL_DEVICE_PATH *) CreateDeviceNode (
3017 MEDIA_DEVICE_PATH,
3018 MEDIA_PROTOCOL_DP,
3019 (UINT16) sizeof (MEDIA_PROTOCOL_DEVICE_PATH)
3020 );
3021
3022 StrToGuid (GuidStr, &Media->Protocol);
3023
3024 return (EFI_DEVICE_PATH_PROTOCOL *) Media;
3025 }
3026
3027 /**
3028 Converts a text device path node to firmware volume device path structure.
3029
3030 @param TextDeviceNode The input Text device path node.
3031
3032 @return A pointer to the newly-created firmware volume device path structure.
3033
3034 **/
3035 EFI_DEVICE_PATH_PROTOCOL *
3036 DevPathFromTextFv (
3037 IN CHAR16 *TextDeviceNode
3038 )
3039 {
3040 CHAR16 *GuidStr;
3041 MEDIA_FW_VOL_DEVICE_PATH *Fv;
3042
3043 GuidStr = GetNextParamStr (&TextDeviceNode);
3044 Fv = (MEDIA_FW_VOL_DEVICE_PATH *) CreateDeviceNode (
3045 MEDIA_DEVICE_PATH,
3046 MEDIA_PIWG_FW_VOL_DP,
3047 (UINT16) sizeof (MEDIA_FW_VOL_DEVICE_PATH)
3048 );
3049
3050 StrToGuid (GuidStr, &Fv->FvName);
3051
3052 return (EFI_DEVICE_PATH_PROTOCOL *) Fv;
3053 }
3054
3055 /**
3056 Converts a text device path node to firmware file device path structure.
3057
3058 @param TextDeviceNode The input Text device path node.
3059
3060 @return A pointer to the newly-created firmware file device path structure.
3061
3062 **/
3063 EFI_DEVICE_PATH_PROTOCOL *
3064 DevPathFromTextFvFile (
3065 IN CHAR16 *TextDeviceNode
3066 )
3067 {
3068 CHAR16 *GuidStr;
3069 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFile;
3070
3071 GuidStr = GetNextParamStr (&TextDeviceNode);
3072 FvFile = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) CreateDeviceNode (
3073 MEDIA_DEVICE_PATH,
3074 MEDIA_PIWG_FW_FILE_DP,
3075 (UINT16) sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)
3076 );
3077
3078 StrToGuid (GuidStr, &FvFile->FvFileName);
3079
3080 return (EFI_DEVICE_PATH_PROTOCOL *) FvFile;
3081 }
3082
3083 /**
3084 Converts a text device path node to text relative offset device path structure.
3085
3086 @param TextDeviceNode The input Text device path node.
3087
3088 @return A pointer to the newly-created Text device path structure.
3089
3090 **/
3091 EFI_DEVICE_PATH_PROTOCOL *
3092 DevPathFromTextRelativeOffsetRange (
3093 IN CHAR16 *TextDeviceNode
3094 )
3095 {
3096 CHAR16 *StartingOffsetStr;
3097 CHAR16 *EndingOffsetStr;
3098 MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;
3099
3100 StartingOffsetStr = GetNextParamStr (&TextDeviceNode);
3101 EndingOffsetStr = GetNextParamStr (&TextDeviceNode);
3102 Offset = (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *) CreateDeviceNode (
3103 MEDIA_DEVICE_PATH,
3104 MEDIA_RELATIVE_OFFSET_RANGE_DP,
3105 (UINT16) sizeof (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH)
3106 );
3107
3108 Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
3109 Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
3110
3111 return (EFI_DEVICE_PATH_PROTOCOL *) Offset;
3112 }
3113
3114 /**
3115 Converts a text device path node to text ram disk device path structure.
3116
3117 @param TextDeviceNode The input Text device path node.
3118
3119 @return A pointer to the newly-created Text device path structure.
3120
3121 **/
3122 EFI_DEVICE_PATH_PROTOCOL *
3123 DevPathFromTextRamDisk (
3124 IN CHAR16 *TextDeviceNode
3125 )
3126 {
3127 CHAR16 *StartingAddrStr;
3128 CHAR16 *EndingAddrStr;
3129 CHAR16 *TypeGuidStr;
3130 CHAR16 *InstanceStr;
3131 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3132 UINT64 StartingAddr;
3133 UINT64 EndingAddr;
3134
3135 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3136 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3137 InstanceStr = GetNextParamStr (&TextDeviceNode);
3138 TypeGuidStr = GetNextParamStr (&TextDeviceNode);
3139 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3140 MEDIA_DEVICE_PATH,
3141 MEDIA_RAM_DISK_DP,
3142 (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3143 );
3144
3145 Strtoi64 (StartingAddrStr, &StartingAddr);
3146 WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3147 Strtoi64 (EndingAddrStr, &EndingAddr);
3148 WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3149 RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3150 StrToGuid (TypeGuidStr, &RamDisk->TypeGuid);
3151
3152 return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3153 }
3154
3155 /**
3156 Converts a text device path node to text virtual disk 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 *
3164 DevPathFromTextVirtualDisk (
3165 IN CHAR16 *TextDeviceNode
3166 )
3167 {
3168 CHAR16 *StartingAddrStr;
3169 CHAR16 *EndingAddrStr;
3170 CHAR16 *InstanceStr;
3171 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3172 UINT64 StartingAddr;
3173 UINT64 EndingAddr;
3174
3175 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3176 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3177 InstanceStr = GetNextParamStr (&TextDeviceNode);
3178
3179 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3180 MEDIA_DEVICE_PATH,
3181 MEDIA_RAM_DISK_DP,
3182 (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3183 );
3184
3185 Strtoi64 (StartingAddrStr, &StartingAddr);
3186 WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3187 Strtoi64 (EndingAddrStr, &EndingAddr);
3188 WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3189 RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3190 CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualDiskGuid);
3191
3192 return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3193 }
3194
3195 /**
3196 Converts a text device path node to text virtual cd device path structure.
3197
3198 @param TextDeviceNode The input Text device path node.
3199
3200 @return A pointer to the newly-created Text device path structure.
3201
3202 **/
3203 EFI_DEVICE_PATH_PROTOCOL *
3204 DevPathFromTextVirtualCd (
3205 IN CHAR16 *TextDeviceNode
3206 )
3207 {
3208 CHAR16 *StartingAddrStr;
3209 CHAR16 *EndingAddrStr;
3210 CHAR16 *InstanceStr;
3211 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3212 UINT64 StartingAddr;
3213 UINT64 EndingAddr;
3214
3215 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3216 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3217 InstanceStr = GetNextParamStr (&TextDeviceNode);
3218
3219 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3220 MEDIA_DEVICE_PATH,
3221 MEDIA_RAM_DISK_DP,
3222 (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3223 );
3224
3225 Strtoi64 (StartingAddrStr, &StartingAddr);
3226 WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3227 Strtoi64 (EndingAddrStr, &EndingAddr);
3228 WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3229 RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3230 CopyGuid (&RamDisk->TypeGuid, &gEfiVirtualCdGuid);
3231
3232 return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3233 }
3234
3235 /**
3236 Converts a text device path node to text persistent virtual disk device path structure.
3237
3238 @param TextDeviceNode The input Text device path node.
3239
3240 @return A pointer to the newly-created Text device path structure.
3241
3242 **/
3243 EFI_DEVICE_PATH_PROTOCOL *
3244 DevPathFromTextPersistentVirtualDisk (
3245 IN CHAR16 *TextDeviceNode
3246 )
3247 {
3248 CHAR16 *StartingAddrStr;
3249 CHAR16 *EndingAddrStr;
3250 CHAR16 *InstanceStr;
3251 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3252 UINT64 StartingAddr;
3253 UINT64 EndingAddr;
3254
3255 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3256 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3257 InstanceStr = GetNextParamStr (&TextDeviceNode);
3258
3259 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3260 MEDIA_DEVICE_PATH,
3261 MEDIA_RAM_DISK_DP,
3262 (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3263 );
3264
3265 Strtoi64 (StartingAddrStr, &StartingAddr);
3266 WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3267 Strtoi64 (EndingAddrStr, &EndingAddr);
3268 WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3269 RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3270 CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualDiskGuid);
3271
3272 return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3273 }
3274
3275 /**
3276 Converts a text device path node to text persistent virtual cd device path structure.
3277
3278 @param TextDeviceNode The input Text device path node.
3279
3280 @return A pointer to the newly-created Text device path structure.
3281
3282 **/
3283 EFI_DEVICE_PATH_PROTOCOL *
3284 DevPathFromTextPersistentVirtualCd (
3285 IN CHAR16 *TextDeviceNode
3286 )
3287 {
3288 CHAR16 *StartingAddrStr;
3289 CHAR16 *EndingAddrStr;
3290 CHAR16 *InstanceStr;
3291 MEDIA_RAM_DISK_DEVICE_PATH *RamDisk;
3292 UINT64 StartingAddr;
3293 UINT64 EndingAddr;
3294
3295 StartingAddrStr = GetNextParamStr (&TextDeviceNode);
3296 EndingAddrStr = GetNextParamStr (&TextDeviceNode);
3297 InstanceStr = GetNextParamStr (&TextDeviceNode);
3298
3299 RamDisk = (MEDIA_RAM_DISK_DEVICE_PATH *) CreateDeviceNode (
3300 MEDIA_DEVICE_PATH,
3301 MEDIA_RAM_DISK_DP,
3302 (UINT16) sizeof (MEDIA_RAM_DISK_DEVICE_PATH)
3303 );
3304
3305 Strtoi64 (StartingAddrStr, &StartingAddr);
3306 WriteUnaligned64 ((UINT64 *) &(RamDisk->StartingAddr[0]), StartingAddr);
3307 Strtoi64 (EndingAddrStr, &EndingAddr);
3308 WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr);
3309 RamDisk->Instance = (UINT16) Strtoi (InstanceStr);
3310 CopyGuid (&RamDisk->TypeGuid, &gEfiPersistentVirtualCdGuid);
3311
3312 return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk;
3313 }
3314
3315 /**
3316 Converts a BBS text device path node to BBS device path structure.
3317
3318 @param TextDeviceNode The input Text device path node.
3319
3320 @return A pointer to BBS device path structure.
3321
3322 **/
3323 EFI_DEVICE_PATH_PROTOCOL *
3324 DevPathFromTextBbsPath (
3325 IN CHAR16 *TextDeviceNode
3326 )
3327 {
3328 return DevPathFromTextGenericPath (BBS_DEVICE_PATH, TextDeviceNode);
3329 }
3330
3331 /**
3332 Converts a text device path node to BIOS Boot Specification device path structure.
3333
3334 @param TextDeviceNode The input Text device path node.
3335
3336 @return A pointer to the newly-created BIOS Boot Specification device path structure.
3337
3338 **/
3339 EFI_DEVICE_PATH_PROTOCOL *
3340 DevPathFromTextBBS (
3341 IN CHAR16 *TextDeviceNode
3342 )
3343 {
3344 CHAR16 *TypeStr;
3345 CHAR16 *IdStr;
3346 CHAR16 *FlagsStr;
3347 CHAR8 *AsciiStr;
3348 BBS_BBS_DEVICE_PATH *Bbs;
3349
3350 TypeStr = GetNextParamStr (&TextDeviceNode);
3351 IdStr = GetNextParamStr (&TextDeviceNode);
3352 FlagsStr = GetNextParamStr (&TextDeviceNode);
3353 Bbs = (BBS_BBS_DEVICE_PATH *) CreateDeviceNode (
3354 BBS_DEVICE_PATH,
3355 BBS_BBS_DP,
3356 (UINT16) (sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr))
3357 );
3358
3359 if (StrCmp (TypeStr, L"Floppy") == 0) {
3360 Bbs->DeviceType = BBS_TYPE_FLOPPY;
3361 } else if (StrCmp (TypeStr, L"HD") == 0) {
3362 Bbs->DeviceType = BBS_TYPE_HARDDRIVE;
3363 } else if (StrCmp (TypeStr, L"CDROM") == 0) {
3364 Bbs->DeviceType = BBS_TYPE_CDROM;
3365 } else if (StrCmp (TypeStr, L"PCMCIA") == 0) {
3366 Bbs->DeviceType = BBS_TYPE_PCMCIA;
3367 } else if (StrCmp (TypeStr, L"USB") == 0) {
3368 Bbs->DeviceType = BBS_TYPE_USB;
3369 } else if (StrCmp (TypeStr, L"Network") == 0) {
3370 Bbs->DeviceType = BBS_TYPE_EMBEDDED_NETWORK;
3371 } else {
3372 Bbs->DeviceType = (UINT16) Strtoi (TypeStr);
3373 }
3374
3375 AsciiStr = Bbs->String;
3376 StrToAscii (IdStr, &AsciiStr);
3377
3378 Bbs->StatusFlag = (UINT16) Strtoi (FlagsStr);
3379
3380 return (EFI_DEVICE_PATH_PROTOCOL *) Bbs;
3381 }
3382
3383 /**
3384 Converts a text device path node to SATA device path structure.
3385
3386 @param TextDeviceNode The input Text device path node.
3387
3388 @return A pointer to the newly-created SATA device path structure.
3389
3390 **/
3391 EFI_DEVICE_PATH_PROTOCOL *
3392 DevPathFromTextSata (
3393 IN CHAR16 *TextDeviceNode
3394 )
3395 {
3396 SATA_DEVICE_PATH *Sata;
3397 CHAR16 *Param1;
3398 CHAR16 *Param2;
3399 CHAR16 *Param3;
3400
3401 Param1 = GetNextParamStr (&TextDeviceNode);
3402 Param2 = GetNextParamStr (&TextDeviceNode);
3403 Param3 = GetNextParamStr (&TextDeviceNode);
3404
3405 Sata = (SATA_DEVICE_PATH *) CreateDeviceNode (
3406 MESSAGING_DEVICE_PATH,
3407 MSG_SATA_DP,
3408 (UINT16) sizeof (SATA_DEVICE_PATH)
3409 );
3410 Sata->HBAPortNumber = (UINT16) Strtoi (Param1);
3411 Sata->PortMultiplierPortNumber = (UINT16) Strtoi (Param2);
3412 Sata->Lun = (UINT16) Strtoi (Param3);
3413
3414 return (EFI_DEVICE_PATH_PROTOCOL *) Sata;
3415 }
3416
3417 GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
3418 {L"Path", DevPathFromTextPath },
3419
3420 {L"HardwarePath", DevPathFromTextHardwarePath },
3421 {L"Pci", DevPathFromTextPci },
3422 {L"PcCard", DevPathFromTextPcCard },
3423 {L"MemoryMapped", DevPathFromTextMemoryMapped },
3424 {L"VenHw", DevPathFromTextVenHw },
3425 {L"Ctrl", DevPathFromTextCtrl },
3426
3427 {L"AcpiPath", DevPathFromTextAcpiPath },
3428 {L"Acpi", DevPathFromTextAcpi },
3429 {L"PciRoot", DevPathFromTextPciRoot },
3430 {L"PcieRoot", DevPathFromTextPcieRoot },
3431 {L"Floppy", DevPathFromTextFloppy },
3432 {L"Keyboard", DevPathFromTextKeyboard },
3433 {L"Serial", DevPathFromTextSerial },
3434 {L"ParallelPort", DevPathFromTextParallelPort },
3435 {L"AcpiEx", DevPathFromTextAcpiEx },
3436 {L"AcpiExp", DevPathFromTextAcpiExp },
3437 {L"AcpiAdr", DevPathFromTextAcpiAdr },
3438
3439 {L"Msg", DevPathFromTextMsg },
3440 {L"Ata", DevPathFromTextAta },
3441 {L"Scsi", DevPathFromTextScsi },
3442 {L"Fibre", DevPathFromTextFibre },
3443 {L"FibreEx", DevPathFromTextFibreEx },
3444 {L"I1394", DevPathFromText1394 },
3445 {L"USB", DevPathFromTextUsb },
3446 {L"I2O", DevPathFromTextI2O },
3447 {L"Infiniband", DevPathFromTextInfiniband },
3448 {L"VenMsg", DevPathFromTextVenMsg },
3449 {L"VenPcAnsi", DevPathFromTextVenPcAnsi },
3450 {L"VenVt100", DevPathFromTextVenVt100 },
3451 {L"VenVt100Plus", DevPathFromTextVenVt100Plus },
3452 {L"VenUtf8", DevPathFromTextVenUtf8 },
3453 {L"UartFlowCtrl", DevPathFromTextUartFlowCtrl },
3454 {L"SAS", DevPathFromTextSAS },
3455 {L"SasEx", DevPathFromTextSasEx },
3456 {L"NVMe", DevPathFromTextNVMe },
3457 {L"UFS", DevPathFromTextUfs },
3458 {L"SD", DevPathFromTextSd },
3459 {L"DebugPort", DevPathFromTextDebugPort },
3460 {L"MAC", DevPathFromTextMAC },
3461 {L"IPv4", DevPathFromTextIPv4 },
3462 {L"IPv6", DevPathFromTextIPv6 },
3463 {L"Uart", DevPathFromTextUart },
3464 {L"UsbClass", DevPathFromTextUsbClass },
3465 {L"UsbAudio", DevPathFromTextUsbAudio },
3466 {L"UsbCDCControl", DevPathFromTextUsbCDCControl },
3467 {L"UsbHID", DevPathFromTextUsbHID },
3468 {L"UsbImage", DevPathFromTextUsbImage },
3469 {L"UsbPrinter", DevPathFromTextUsbPrinter },
3470 {L"UsbMassStorage", DevPathFromTextUsbMassStorage },
3471 {L"UsbHub", DevPathFromTextUsbHub },
3472 {L"UsbCDCData", DevPathFromTextUsbCDCData },
3473 {L"UsbSmartCard", DevPathFromTextUsbSmartCard },
3474 {L"UsbVideo", DevPathFromTextUsbVideo },
3475 {L"UsbDiagnostic", DevPathFromTextUsbDiagnostic },
3476 {L"UsbWireless", DevPathFromTextUsbWireless },
3477 {L"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate },
3478 {L"UsbIrdaBridge", DevPathFromTextUsbIrdaBridge },
3479 {L"UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement },
3480 {L"UsbWwid", DevPathFromTextUsbWwid },
3481 {L"Unit", DevPathFromTextUnit },
3482 {L"iSCSI", DevPathFromTextiSCSI },
3483 {L"Vlan", DevPathFromTextVlan },
3484 {L"Uri", DevPathFromTextUri },
3485 {L"Bluetooth", DevPathFromTextBluetooth },
3486 {L"WiFi", DevPathFromTextWiFi },
3487 {L"MediaPath", DevPathFromTextMediaPath },
3488 {L"HD", DevPathFromTextHD },
3489 {L"CDROM", DevPathFromTextCDROM },
3490 {L"VenMedia", DevPathFromTextVenMedia },
3491 {L"Media", DevPathFromTextMedia },
3492 {L"Fv", DevPathFromTextFv },
3493 {L"FvFile", DevPathFromTextFvFile },
3494 {L"Offset", DevPathFromTextRelativeOffsetRange },
3495 {L"RamDisk", DevPathFromTextRamDisk },
3496 {L"VirtualDisk", DevPathFromTextVirtualDisk },
3497 {L"VirtualCD", DevPathFromTextVirtualCd },
3498 {L"PersistentVirtualDisk", DevPathFromTextPersistentVirtualDisk },
3499 {L"PersistentVirtualCD", DevPathFromTextPersistentVirtualCd },
3500
3501 {L"BbsPath", DevPathFromTextBbsPath },
3502 {L"BBS", DevPathFromTextBBS },
3503 {L"Sata", DevPathFromTextSata },
3504 {NULL, NULL}
3505 };
3506
3507 /**
3508 Convert text to the binary representation of a device node.
3509
3510 @param TextDeviceNode TextDeviceNode points to the text representation of a device
3511 node. Conversion starts with the first character and continues
3512 until the first non-device node character.
3513
3514 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
3515 insufficient memory or text unsupported.
3516
3517 **/
3518 EFI_DEVICE_PATH_PROTOCOL *
3519 EFIAPI
3520 UefiDevicePathLibConvertTextToDeviceNode (
3521 IN CONST CHAR16 *TextDeviceNode
3522 )
3523 {
3524 DEVICE_PATH_FROM_TEXT FromText;
3525 CHAR16 *ParamStr;
3526 EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
3527 CHAR16 *DeviceNodeStr;
3528 UINTN Index;
3529
3530 if ((TextDeviceNode == NULL) || (IS_NULL (*TextDeviceNode))) {
3531 return NULL;
3532 }
3533
3534 ParamStr = NULL;
3535 FromText = NULL;
3536 DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
3537 ASSERT (DeviceNodeStr != NULL);
3538
3539 for (Index = 0; mUefiDevicePathLibDevPathFromTextTable[Index].Function != NULL; Index++) {
3540 ParamStr = GetParamByNodeName (DeviceNodeStr, mUefiDevicePathLibDevPathFromTextTable[Index].DevicePathNodeText);
3541 if (ParamStr != NULL) {
3542 FromText = mUefiDevicePathLibDevPathFromTextTable[Index].Function;
3543 break;
3544 }
3545 }
3546
3547 if (FromText == NULL) {
3548 //
3549 // A file path
3550 //
3551 FromText = DevPathFromTextFilePath;
3552 DeviceNode = FromText (DeviceNodeStr);
3553 } else {
3554 DeviceNode = FromText (ParamStr);
3555 FreePool (ParamStr);
3556 }
3557
3558 FreePool (DeviceNodeStr);
3559
3560 return DeviceNode;
3561 }
3562
3563 /**
3564 Convert text to the binary representation of a device path.
3565
3566
3567 @param TextDevicePath TextDevicePath points to the text representation of a device
3568 path. Conversion starts with the first character and continues
3569 until the first non-device node character.
3570
3571 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
3572 there was insufficient memory.
3573
3574 **/
3575 EFI_DEVICE_PATH_PROTOCOL *
3576 EFIAPI
3577 UefiDevicePathLibConvertTextToDevicePath (
3578 IN CONST CHAR16 *TextDevicePath
3579 )
3580 {
3581 EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
3582 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
3583 CHAR16 *DevicePathStr;
3584 CHAR16 *Str;
3585 CHAR16 *DeviceNodeStr;
3586 BOOLEAN IsInstanceEnd;
3587 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
3588
3589 if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
3590 return NULL;
3591 }
3592
3593 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
3594 ASSERT (DevicePath != NULL);
3595 SetDevicePathEndNode (DevicePath);
3596
3597 DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
3598
3599 Str = DevicePathStr;
3600 while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
3601 DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);
3602
3603 NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3604 FreePool (DevicePath);
3605 FreePool (DeviceNode);
3606 DevicePath = NewDevicePath;
3607
3608 if (IsInstanceEnd) {
3609 DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
3610 ASSERT (DeviceNode != NULL);
3611 SetDevicePathEndNode (DeviceNode);
3612
3613 NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3614 FreePool (DevicePath);
3615 FreePool (DeviceNode);
3616 DevicePath = NewDevicePath;
3617 }
3618 }
3619
3620 FreePool (DevicePathStr);
3621 return DevicePath;
3622 }