VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal/DevicePathDxe/DevicePathFromText.c@ 48674

Last change on this file since 48674 was 48674, checked in by vboxsync, 11 years ago

EFI: Export newly imported tinaocore UEFI sources to OSE.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette