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