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