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