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