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