VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c@ 108794

Last change on this file since 108794 was 108794, checked in by vboxsync, 2 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette