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