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