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