2 Main file for support of shell consist mapping.
4 Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
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.
14 #include "UefiShellCommandLib.h"
15 #include <Library/DevicePathLib.h>
16 #include <Library/SortLib.h>
36 } DEVICE_CONSIST_MAPPING_INFO
;
46 VOID (EFIAPI
*SerialFun
) (EFI_DEVICE_PATH_PROTOCOL
*DevPath
, DEVICE_CONSIST_MAPPING_INFO
*MapInfo
);
47 INTN (EFIAPI
*CompareFun
) (EFI_DEVICE_PATH_PROTOCOL
*DevPath
, EFI_DEVICE_PATH_PROTOCOL
*DevPath2
);
48 } DEV_PATH_CONSIST_MAPPING_TABLE
;
52 Concatenates a formatted unicode string to allocated pool.
53 The caller must free the resulting buffer.
55 @param Str Tracks the allocated pool, size in use, and amount of pool allocated.
56 @param Fmt The format string
57 @param ... The data will be printed.
59 @return Allocated buffer with the formatted string printed in it.
60 The caller must free the allocated buffer.
61 The buffer allocation is not packed.
67 IN OUT POOL_PRINT
*Str
,
76 AppendStr
= AllocateZeroPool (0x1000);
77 if (AppendStr
== NULL
) {
83 UnicodeVSPrint (AppendStr
, 0x1000, Fmt
, Args
);
85 if (NULL
== Str
->Str
) {
86 StringSize
= StrSize (AppendStr
);
87 Str
->Str
= AllocateZeroPool (StringSize
);
88 ASSERT (Str
->Str
!= NULL
);
90 StringSize
= StrSize (AppendStr
);
91 StringSize
+= (StrSize (Str
->Str
) - sizeof (UINT16
));
93 Str
->Str
= ReallocatePool (
98 ASSERT (Str
->Str
!= NULL
);
101 StrnCat (Str
->Str
, AppendStr
, StringSize
/sizeof(CHAR16
) - 1 - StrLen(Str
->Str
));
102 Str
->Len
= StringSize
;
104 FreePool (AppendStr
);
108 MTD_NAME mMTDName
[] = {
132 Function to append a 64 bit number / 25 onto the string.
134 @param[in, out] Str The string so append onto.
135 @param[in] Num The number to divide and append.
137 @retval EFI_INVALID_PARAMETER A parameter was NULL.
138 @retval EFI_SUCCESS The appending was successful.
143 IN OUT POOL_PRINT
*Str
,
151 return (EFI_INVALID_PARAMETER
);
154 Result
= DivU64x32Remainder (Num
, 25, &Rem
);
156 AppendCSDNum2 (Str
, Result
);
159 CatPrint (Str
, L
"%c", Rem
+ 'a');
160 return (EFI_SUCCESS
);
164 Function to append a 64 bit number onto the mapping info.
166 @param[in, out] MappingItem The mapping info object to append onto.
167 @param[in] Num The info to append.
169 @retval EFI_INVALID_PARAMETER A parameter was NULL.
170 @retval EFI_SUCCESS The appending was successful.
175 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
179 if (MappingItem
== NULL
) {
180 return EFI_INVALID_PARAMETER
;
183 if (MappingItem
->Digital
) {
184 CatPrint (&MappingItem
->Csd
, L
"%ld", Num
);
186 AppendCSDNum2 (&MappingItem
->Csd
, Num
);
189 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
191 return (EFI_SUCCESS
);
195 Function to append string into the mapping info.
197 @param[in, out] MappingItem The mapping info object to append onto.
198 @param[in] Str The info to append.
200 @retval EFI_INVALID_PARAMETER A parameter was NULL.
201 @retval EFI_SUCCESS The appending was successful.
206 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
212 if (Str
== NULL
|| MappingItem
== NULL
) {
213 return (EFI_INVALID_PARAMETER
);
216 if (MappingItem
->Digital
) {
218 // To aVOID mult-meaning, the mapping is:
219 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
220 // 0 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15
222 for (Index
= Str
; *Index
!= 0; Index
++) {
233 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
);
237 CatPrint (&MappingItem
->Csd
, L
"16");
246 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'a' + '0');
255 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'A' + '0');
260 for (Index
= Str
; *Index
!= 0; Index
++) {
263 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
264 // a b c d e f g h i j k l m n o p
266 if (*Index
>= '0' && *Index
<= '9') {
267 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- '0' + 'a');
268 } else if (*Index
>= 'a' && *Index
<= 'f') {
269 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'a' + 'k');
270 } else if (*Index
>= 'A' && *Index
<= 'F') {
271 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'A' + 'k');
276 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
278 return (EFI_SUCCESS
);
282 Function to append a Guid to the mapping item.
284 @param[in, out] MappingItem The item to append onto.
285 @param[in] Guid The guid to append.
287 @retval EFI_SUCCESS The appending operation was successful.
288 @retval EFI_INVALID_PARAMETER A parameter was NULL.
293 DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
299 if (Guid
== NULL
|| MappingItem
== NULL
) {
300 return (EFI_INVALID_PARAMETER
);
310 AppendCSDStr (MappingItem
, Buffer
);
312 return (EFI_SUCCESS
);
316 Function to compare 2 APCI device paths.
318 @param[in] DevicePath1 The first device path to compare.
319 @param[in] DevicePath2 The second device path to compare.
321 @retval 0 The device paths represent the same device.
322 @return Non zero if the devices are different, zero otherwise.
327 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
328 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
331 ACPI_HID_DEVICE_PATH
*Acpi1
;
332 ACPI_HID_DEVICE_PATH
*Acpi2
;
334 if (DevicePath1
== NULL
|| DevicePath2
== NULL
) {
338 Acpi1
= (ACPI_HID_DEVICE_PATH
*) DevicePath1
;
339 Acpi2
= (ACPI_HID_DEVICE_PATH
*) DevicePath2
;
340 if (Acpi1
->HID
> Acpi2
->HID
|| (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
> Acpi2
->UID
)) {
344 if (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
== Acpi2
->UID
) {
352 Function to compare 2 PCI device paths.
354 @param[in] DevicePath1 The first device path to compare.
355 @param[in] DevicePath2 The second device path to compare.
357 @retval 0 The device paths represent the same device.
358 @return Non zero if the devices are different, zero otherwise.
363 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
364 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
367 PCI_DEVICE_PATH
*Pci1
;
368 PCI_DEVICE_PATH
*Pci2
;
370 ASSERT(DevicePath1
!= NULL
);
371 ASSERT(DevicePath2
!= NULL
);
373 Pci1
= (PCI_DEVICE_PATH
*) DevicePath1
;
374 Pci2
= (PCI_DEVICE_PATH
*) DevicePath2
;
375 if (Pci1
->Device
> Pci2
->Device
|| (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
> Pci2
->Function
)) {
379 if (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
== Pci2
->Function
) {
387 Do a comparison on 2 device paths.
389 @param[in] DevicePath1 The first device path.
390 @param[in] DevicePath2 The second device path.
392 @retval 0 The 2 device paths are the same.
393 @retval <0 DevicePath2 is greater than DevicePath1.
394 @retval >0 DevicePath1 is greater than DevicePath2.
398 DevPathCompareDefault (
399 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
400 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
406 ASSERT(DevicePath1
!= NULL
);
407 ASSERT(DevicePath2
!= NULL
);
409 DevPathSize1
= DevicePathNodeLength (DevicePath1
);
410 DevPathSize2
= DevicePathNodeLength (DevicePath2
);
411 if (DevPathSize1
> DevPathSize2
) {
413 } else if (DevPathSize1
< DevPathSize2
) {
416 return CompareMem (DevicePath1
, DevicePath2
, DevPathSize1
);
421 DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.
423 @param[in] DevicePathNode The node to get info on.
424 @param[in] MappingItem The info item to populate.
428 DevPathSerialHardDrive (
429 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
430 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
433 HARDDRIVE_DEVICE_PATH
*Hd
;
435 ASSERT(DevicePathNode
!= NULL
);
436 ASSERT(MappingItem
!= NULL
);
438 Hd
= (HARDDRIVE_DEVICE_PATH
*) DevicePathNode
;
439 if (MappingItem
->Mtd
== MTDTypeUnknown
) {
440 MappingItem
->Mtd
= MTDTypeHardDisk
;
443 AppendCSDNum (MappingItem
, Hd
->PartitionNumber
);
447 DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.
449 @param[in] DevicePathNode The node to get info on.
450 @param[in] MappingItem The info item to populate.
455 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
456 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
459 ATAPI_DEVICE_PATH
*Atapi
;
461 ASSERT(DevicePathNode
!= NULL
);
462 ASSERT(MappingItem
!= NULL
);
464 Atapi
= (ATAPI_DEVICE_PATH
*) DevicePathNode
;
465 AppendCSDNum (MappingItem
, (Atapi
->PrimarySecondary
* 2 + Atapi
->SlaveMaster
));
469 DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.
471 @param[in] DevicePathNode The node to get info on.
472 @param[in] MappingItem The info item to populate.
477 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
478 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
481 CDROM_DEVICE_PATH
*Cd
;
483 ASSERT(DevicePathNode
!= NULL
);
484 ASSERT(MappingItem
!= NULL
);
486 Cd
= (CDROM_DEVICE_PATH
*) DevicePathNode
;
487 MappingItem
->Mtd
= MTDTypeCDRom
;
488 AppendCSDNum (MappingItem
, Cd
->BootEntry
);
492 DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.
494 @param[in] DevicePathNode The node to get info on.
495 @param[in] MappingItem The info item to populate.
500 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
501 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
504 FIBRECHANNEL_DEVICE_PATH
*Fibre
;
506 ASSERT(DevicePathNode
!= NULL
);
507 ASSERT(MappingItem
!= NULL
);
509 Fibre
= (FIBRECHANNEL_DEVICE_PATH
*) DevicePathNode
;
510 AppendCSDNum (MappingItem
, Fibre
->WWN
);
511 AppendCSDNum (MappingItem
, Fibre
->Lun
);
515 DevicePathNode must be SerialUart type and this will populate the MappingItem.
517 @param[in] DevicePathNode The node to get info on.
518 @param[in] MappingItem The info item to populate.
523 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
524 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
527 UART_DEVICE_PATH
*Uart
;
529 ASSERT(DevicePathNode
!= NULL
);
530 ASSERT(MappingItem
!= NULL
);
532 Uart
= (UART_DEVICE_PATH
*) DevicePathNode
;
533 AppendCSDNum (MappingItem
, Uart
->BaudRate
);
534 AppendCSDNum (MappingItem
, Uart
->DataBits
);
535 AppendCSDNum (MappingItem
, Uart
->Parity
);
536 AppendCSDNum (MappingItem
, Uart
->StopBits
);
540 DevicePathNode must be SerialUSB type and this will populate the MappingItem.
542 @param[in] DevicePathNode The node to get info on.
543 @param[in] MappingItem The info item to populate.
548 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
549 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
552 USB_DEVICE_PATH
*Usb
;
554 ASSERT(DevicePathNode
!= NULL
);
555 ASSERT(MappingItem
!= NULL
);
557 Usb
= (USB_DEVICE_PATH
*) DevicePathNode
;
558 AppendCSDNum (MappingItem
, Usb
->ParentPortNumber
);
559 AppendCSDNum (MappingItem
, Usb
->InterfaceNumber
);
563 DevicePathNode must be SerialVendor type and this will populate the MappingItem.
565 @param[in] DevicePathNode The node to get info on.
566 @param[in] MappingItem The info item to populate.
571 DevPathSerialVendor (
572 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
573 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
576 VENDOR_DEVICE_PATH
*Vendor
;
577 SAS_DEVICE_PATH
*Sas
;
579 if (DevicePathNode
== NULL
|| MappingItem
== NULL
) {
583 Vendor
= (VENDOR_DEVICE_PATH
*) DevicePathNode
;
584 AppendCSDGuid (MappingItem
, &Vendor
->Guid
);
586 if (CompareGuid (&gEfiSasDevicePathGuid
, &Vendor
->Guid
)) {
587 Sas
= (SAS_DEVICE_PATH
*) Vendor
;
588 AppendCSDNum (MappingItem
, Sas
->SasAddress
);
589 AppendCSDNum (MappingItem
, Sas
->Lun
);
590 AppendCSDNum (MappingItem
, Sas
->DeviceTopology
);
591 AppendCSDNum (MappingItem
, Sas
->RelativeTargetPort
);
596 DevicePathNode must be SerialLun type and this will populate the MappingItem.
598 @param[in] DevicePathNode The node to get info on.
599 @param[in] MappingItem The info item to populate.
604 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
605 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
608 DEVICE_LOGICAL_UNIT_DEVICE_PATH
*Lun
;
610 ASSERT(DevicePathNode
!= NULL
);
611 ASSERT(MappingItem
!= NULL
);
613 Lun
= (DEVICE_LOGICAL_UNIT_DEVICE_PATH
*) DevicePathNode
;
614 AppendCSDNum (MappingItem
, Lun
->Lun
);
618 DevicePathNode must be SerialSata type and this will populate the MappingItem.
620 @param[in] DevicePathNode The node to get info on.
621 @param[in] MappingItem The info item to populate.
626 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
627 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
630 SATA_DEVICE_PATH
*Sata
;
632 ASSERT(DevicePathNode
!= NULL
);
633 ASSERT(MappingItem
!= NULL
);
635 Sata
= (SATA_DEVICE_PATH
*) DevicePathNode
;
636 AppendCSDNum (MappingItem
, Sata
->HBAPortNumber
);
637 AppendCSDNum (MappingItem
, Sata
->PortMultiplierPortNumber
);
638 AppendCSDNum (MappingItem
, Sata
->Lun
);
642 DevicePathNode must be SerialSCSI type and this will populate the MappingItem.
644 @param[in] DevicePathNode The node to get info on.
645 @param[in] MappingItem The info item to populate.
650 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
651 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
654 ///@todo make this a PCD
656 // As Csd of ISCSI node is quite long, we comment
657 // the code below to keep the consistent mapping
658 // short. Uncomment if you really need it.
661 ISCSI_DEVICE_PATH *IScsi;
662 UINT8 *IScsiTargetName;
664 UINTN TargetNameLength;
667 ASSERT(DevicePathNode != NULL);
668 ASSERT(MappingItem != NULL);
670 IScsi = (ISCSI_DEVICE_PATH *) DevicePathNode;
671 AppendCSDNum (MappingItem, IScsi->NetworkProtocol);
672 AppendCSDNum (MappingItem, IScsi->LoginOption);
673 AppendCSDNum (MappingItem, IScsi->Lun);
674 AppendCSDNum (MappingItem, IScsi->TargetPortalGroupTag);
675 TargetNameLength = DevicePathNodeLength (DevicePathNode) - sizeof (ISCSI_DEVICE_PATH);
676 if (TargetNameLength > 0) {
677 TargetName = AllocateZeroPool ((TargetNameLength + 1) * sizeof (CHAR16));
678 if (TargetName != NULL) {
679 IScsiTargetName = (UINT8 *) (IScsi + 1);
680 for (Index = 0; Index < TargetNameLength; Index++) {
681 TargetName[Index] = (CHAR16) IScsiTargetName[Index];
683 AppendCSDStr (MappingItem, TargetName);
684 FreePool (TargetName);
691 DevicePathNode must be SerialI20 type and this will populate the MappingItem.
693 @param[in] DevicePathNode The node to get info on.
694 @param[in] MappingItem The info item to populate.
699 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
700 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
703 I2O_DEVICE_PATH
*DevicePath_I20
;
705 ASSERT(DevicePathNode
!= NULL
);
706 ASSERT(MappingItem
!= NULL
);
708 DevicePath_I20
= (I2O_DEVICE_PATH
*) DevicePathNode
;
709 AppendCSDNum (MappingItem
, DevicePath_I20
->Tid
);
713 DevicePathNode must be Mac Address type and this will populate the MappingItem.
715 @param[in] DevicePathNode The node to get info on.
716 @param[in] MappingItem The info item to populate.
720 DevPathSerialMacAddr (
721 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
722 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
725 MAC_ADDR_DEVICE_PATH
*Mac
;
731 ASSERT(DevicePathNode
!= NULL
);
732 ASSERT(MappingItem
!= NULL
);
734 Mac
= (MAC_ADDR_DEVICE_PATH
*) DevicePathNode
;
736 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
737 if (Mac
->IfType
== 0x01 || Mac
->IfType
== 0x00) {
741 for (Index
= 0, PBuffer
= Buffer
; Index
< HwAddressSize
; Index
++, PBuffer
+= 2) {
742 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Mac
->MacAddress
.Addr
[Index
]);
745 AppendCSDStr (MappingItem
, Buffer
);
749 DevicePathNode must be InfiniBand type and this will populate the MappingItem.
751 @param[in] DevicePathNode The node to get info on.
752 @param[in] MappingItem The info item to populate.
756 DevPathSerialInfiniBand (
757 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
758 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
761 INFINIBAND_DEVICE_PATH
*InfiniBand
;
766 ASSERT(DevicePathNode
!= NULL
);
767 ASSERT(MappingItem
!= NULL
);
769 InfiniBand
= (INFINIBAND_DEVICE_PATH
*) DevicePathNode
;
770 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
771 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) InfiniBand
->PortGid
[Index
]);
774 AppendCSDStr (MappingItem
, Buffer
);
775 AppendCSDNum (MappingItem
, InfiniBand
->ServiceId
);
776 AppendCSDNum (MappingItem
, InfiniBand
->TargetPortId
);
777 AppendCSDNum (MappingItem
, InfiniBand
->DeviceId
);
781 DevicePathNode must be IPv4 type and this will populate the MappingItem.
783 @param[in] DevicePathNode The node to get info on.
784 @param[in] MappingItem The info item to populate.
789 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
790 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
793 IPv4_DEVICE_PATH
*Ip
;
796 ASSERT(DevicePathNode
!= NULL
);
797 ASSERT(MappingItem
!= NULL
);
799 Ip
= (IPv4_DEVICE_PATH
*) DevicePathNode
;
804 (UINTN
) Ip
->LocalIpAddress
.Addr
[0],
805 (UINTN
) Ip
->LocalIpAddress
.Addr
[1],
806 (UINTN
) Ip
->LocalIpAddress
.Addr
[2],
807 (UINTN
) Ip
->LocalIpAddress
.Addr
[3]
809 AppendCSDStr (MappingItem
, Buffer
);
810 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
815 (UINTN
) Ip
->RemoteIpAddress
.Addr
[0],
816 (UINTN
) Ip
->RemoteIpAddress
.Addr
[1],
817 (UINTN
) Ip
->RemoteIpAddress
.Addr
[2],
818 (UINTN
) Ip
->RemoteIpAddress
.Addr
[3]
820 AppendCSDStr (MappingItem
, Buffer
);
821 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
825 DevicePathNode must be IPv6 type and this will populate the MappingItem.
827 @param[in] DevicePathNode The node to get info on.
828 @param[in] MappingItem The info item to populate.
833 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
834 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
837 IPv6_DEVICE_PATH
*Ip
;
842 ASSERT(DevicePathNode
!= NULL
);
843 ASSERT(MappingItem
!= NULL
);
845 Ip
= (IPv6_DEVICE_PATH
*) DevicePathNode
;
846 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
847 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->LocalIpAddress
.Addr
[Index
]);
850 AppendCSDStr (MappingItem
, Buffer
);
851 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
852 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
853 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->RemoteIpAddress
.Addr
[Index
]);
856 AppendCSDStr (MappingItem
, Buffer
);
857 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
861 DevicePathNode must be SCSI type and this will populate the MappingItem.
863 @param[in] DevicePathNode The node to get info on.
864 @param[in] MappingItem The info item to populate.
869 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
870 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
873 SCSI_DEVICE_PATH
*Scsi
;
875 ASSERT(DevicePathNode
!= NULL
);
876 ASSERT(MappingItem
!= NULL
);
878 Scsi
= (SCSI_DEVICE_PATH
*) DevicePathNode
;
879 AppendCSDNum (MappingItem
, Scsi
->Pun
);
880 AppendCSDNum (MappingItem
, Scsi
->Lun
);
884 DevicePathNode must be 1394 type and this will populate the MappingItem.
886 @param[in] DevicePathNode The node to get info on.
887 @param[in] MappingItem The info item to populate.
892 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
893 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
896 F1394_DEVICE_PATH
*DevicePath_F1394
;
899 ASSERT(DevicePathNode
!= NULL
);
900 ASSERT(MappingItem
!= NULL
);
902 DevicePath_F1394
= (F1394_DEVICE_PATH
*) DevicePathNode
;
903 UnicodeSPrint (Buffer
, 0, L
"%lx", DevicePath_F1394
->Guid
);
904 AppendCSDStr (MappingItem
, Buffer
);
908 If the node is floppy type then populate the MappingItem.
910 @param[in] DevicePathNode The node to get info on.
911 @param[in] MappingItem The info item to populate.
916 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
917 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
920 ACPI_HID_DEVICE_PATH
*Acpi
;
922 ASSERT(DevicePathNode
!= NULL
);
923 ASSERT(MappingItem
!= NULL
);
925 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
926 if ((Acpi
->HID
& PNP_EISA_ID_MASK
) == PNP_EISA_ID_CONST
) {
927 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
928 MappingItem
->Mtd
= MTDTypeFloppy
;
929 AppendCSDNum (MappingItem
, Acpi
->UID
);
935 Empty function used for unknown devices.
937 @param[in] DevicePathNode Ignored.
938 @param[in] MappingItem Ignored.
944 DevPathSerialDefault (
945 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
946 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
952 DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable
[] = {
954 HARDWARE_DEVICE_PATH
,
956 DevPathSerialDefault
,
966 MESSAGING_DEVICE_PATH
,
969 DevPathCompareDefault
972 MESSAGING_DEVICE_PATH
,
975 DevPathCompareDefault
978 MESSAGING_DEVICE_PATH
,
981 DevPathCompareDefault
984 MESSAGING_DEVICE_PATH
,
987 DevPathCompareDefault
990 MESSAGING_DEVICE_PATH
,
993 DevPathCompareDefault
996 MESSAGING_DEVICE_PATH
,
999 DevPathCompareDefault
1002 MESSAGING_DEVICE_PATH
,
1004 DevPathSerialMacAddr
,
1005 DevPathCompareDefault
1008 MESSAGING_DEVICE_PATH
,
1011 DevPathCompareDefault
1014 MESSAGING_DEVICE_PATH
,
1017 DevPathCompareDefault
1020 MESSAGING_DEVICE_PATH
,
1022 DevPathSerialInfiniBand
,
1023 DevPathCompareDefault
1026 MESSAGING_DEVICE_PATH
,
1029 DevPathCompareDefault
1032 MESSAGING_DEVICE_PATH
,
1034 DevPathSerialVendor
,
1035 DevPathCompareDefault
1038 MESSAGING_DEVICE_PATH
,
1039 MSG_DEVICE_LOGICAL_UNIT_DP
,
1041 DevPathCompareDefault
1044 MESSAGING_DEVICE_PATH
,
1047 DevPathCompareDefault
1050 MESSAGING_DEVICE_PATH
,
1053 DevPathCompareDefault
1058 DevPathSerialHardDrive
,
1059 DevPathCompareDefault
1065 DevPathCompareDefault
1070 DevPathSerialVendor
,
1071 DevPathCompareDefault
1082 Function to determine if a device path node is Hi or not.
1084 @param[in] DevicePathNode The node to check.
1086 @retval TRUE The node is Hi.
1087 @retval FALSE The node is not Hi.
1091 IsHIDevicePathNode (
1092 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
1095 ACPI_HID_DEVICE_PATH
*Acpi
;
1097 ASSERT(DevicePathNode
!= NULL
);
1099 if (DevicePathNode
->Type
== HARDWARE_DEVICE_PATH
) {
1103 if (DevicePathNode
->Type
== ACPI_DEVICE_PATH
) {
1104 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
1105 switch (EISA_ID_TO_NUM (Acpi
->HID
)) {
1120 Function to convert a standard device path structure into a Hi version.
1122 @param[in] DevicePath The device path to convert.
1124 @return the device path portion that is Hi.
1126 EFI_DEVICE_PATH_PROTOCOL
*
1129 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1132 UINTN NonHIDevicePathNodeCount
;
1135 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1136 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1138 ASSERT(DevicePath
!= NULL
);
1140 NonHIDevicePathNodeCount
= 0;
1142 HIDevicePath
= AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1143 SetDevicePathEndNode (HIDevicePath
);
1145 Node
.DevPath
.Type
= END_DEVICE_PATH_TYPE
;
1146 Node
.DevPath
.SubType
= END_INSTANCE_DEVICE_PATH_SUBTYPE
;
1147 Node
.DevPath
.Length
[0] = (UINT8
)sizeof (EFI_DEVICE_PATH_PROTOCOL
);
1148 Node
.DevPath
.Length
[1] = 0;
1150 while (!IsDevicePathEnd (DevicePath
)) {
1151 if (IsHIDevicePathNode (DevicePath
)) {
1152 for (Index
= 0; Index
< NonHIDevicePathNodeCount
; Index
++) {
1153 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, &Node
.DevPath
);
1154 FreePool (HIDevicePath
);
1155 HIDevicePath
= TempDevicePath
;
1158 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, DevicePath
);
1159 FreePool (HIDevicePath
);
1160 HIDevicePath
= TempDevicePath
;
1162 NonHIDevicePathNodeCount
++;
1165 // Next device path node
1167 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1170 return HIDevicePath
;
1174 Function to walk the device path looking for a dumpable node.
1176 @param[in] MappingItem The Item to fill with data.
1177 @param[in] DevicePath The path of the item to get data on.
1179 @return EFI_SUCCESS Always returns success.
1183 GetDeviceConsistMappingInfo (
1184 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1185 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1188 VOID (EFIAPI
*SerialFun
) (EFI_DEVICE_PATH_PROTOCOL
*, DEVICE_CONSIST_MAPPING_INFO
*);
1192 ASSERT(DevicePath
!= NULL
);
1193 ASSERT(MappingItem
!= NULL
);
1195 SetMem (&MappingItem
->Csd
, sizeof (POOL_PRINT
), 0);
1197 while (!IsDevicePathEnd (DevicePath
)) {
1199 // Find the handler to dump this device path node
1202 for (Index
= 0; DevPathConsistMappingTable
[Index
].SerialFun
!= NULL
; Index
+= 1) {
1204 if (DevicePathType (DevicePath
) == DevPathConsistMappingTable
[Index
].Type
&&
1205 DevicePathSubType (DevicePath
) == DevPathConsistMappingTable
[Index
].SubType
1207 SerialFun
= DevPathConsistMappingTable
[Index
].SerialFun
;
1212 // If not found, use a generic function
1215 SerialFun
= DevPathSerialDefault
;
1218 SerialFun (DevicePath
, MappingItem
);
1221 // Next device path node
1223 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1230 Function to initialize the table for creating consistent map names.
1232 @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
1234 @retval EFI_SUCCESS The table was created successfully.
1238 ShellCommandConsistMappingInitialize (
1239 OUT EFI_DEVICE_PATH_PROTOCOL
***Table
1242 EFI_HANDLE
*HandleBuffer
;
1245 EFI_DEVICE_PATH_PROTOCOL
**TempTable
;
1246 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1247 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1251 HandleBuffer
= NULL
;
1253 Status
= gBS
->LocateHandleBuffer (
1260 ASSERT_EFI_ERROR(Status
);
1262 TempTable
= AllocateZeroPool ((HandleNum
+ 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
1263 if (TempTable
== NULL
) {
1264 return EFI_OUT_OF_RESOURCES
;
1267 for (HandleLoop
= 0 ; HandleLoop
< HandleNum
; HandleLoop
++) {
1268 DevicePath
= DevicePathFromHandle (HandleBuffer
[HandleLoop
]);
1269 if (DevicePath
== NULL
) {
1273 HIDevicePath
= GetHIDevicePath (DevicePath
);
1274 if (HIDevicePath
== NULL
) {
1278 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++) {
1279 if (DevicePathCompare (&TempTable
[Index
], &HIDevicePath
) == 0) {
1280 FreePool (HIDevicePath
);
1285 if (TempTable
[Index
] == NULL
) {
1286 TempTable
[Index
] = HIDevicePath
;
1290 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++);
1291 PerformQuickSort(TempTable
, Index
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1294 if (HandleBuffer
!= NULL
) {
1295 FreePool (HandleBuffer
);
1302 Function to uninitialize the table for creating consistent map names.
1304 The parameter must have been received from ShellCommandConsistMappingInitialize.
1306 @param[out] Table The pointer to pointer to DevicePathProtocol object.
1308 @retval EFI_SUCCESS The table was deleted successfully.
1312 ShellCommandConsistMappingUnInitialize (
1313 EFI_DEVICE_PATH_PROTOCOL
**Table
1318 ASSERT(Table
!= NULL
);
1320 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1321 FreePool (Table
[Index
]);
1329 Create a consistent mapped name for the device specified by DevicePath
1332 This must be called after ShellCommandConsistMappingInitialize() and
1333 before ShellCommandConsistMappingUnInitialize() is called.
1335 @param[in] DevicePath The pointer to the dev path for the device.
1336 @param[in] Table The Table of mapping information.
1338 @retval NULL A consistent mapped name could not be created.
1339 @return A pointer to a string allocated from pool with the device name.
1343 ShellCommandConsistMappingGenMappingName (
1344 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1345 IN EFI_DEVICE_PATH_PROTOCOL
**Table
1349 DEVICE_CONSIST_MAPPING_INFO MappingInfo
;
1350 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1354 ASSERT(DevicePath
!= NULL
);
1355 ASSERT(Table
!= NULL
);
1357 HIDevicePath
= GetHIDevicePath (DevicePath
);
1358 if (HIDevicePath
== NULL
) {
1362 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1363 if (DevicePathCompare (&Table
[Index
], &HIDevicePath
) == 0) {
1368 FreePool (HIDevicePath
);
1369 if (Table
[Index
] == NULL
) {
1373 MappingInfo
.Hi
= Index
;
1374 MappingInfo
.Mtd
= MTDTypeUnknown
;
1375 MappingInfo
.Digital
= FALSE
;
1377 GetDeviceConsistMappingInfo (&MappingInfo
, DevicePath
);
1379 SetMem (&Str
, sizeof (Str
), 0);
1380 for (Index
= 0; mMTDName
[Index
].MTDType
!= MTDTypeEnd
; Index
++) {
1381 if (MappingInfo
.Mtd
== mMTDName
[Index
].MTDType
) {
1386 if (mMTDName
[Index
].MTDType
!= MTDTypeEnd
) {
1387 CatPrint (&Str
, L
"%s", mMTDName
[Index
].Name
);
1390 CatPrint (&Str
, L
"%d", (UINTN
) MappingInfo
.Hi
);
1391 if (MappingInfo
.Csd
.Str
!= NULL
) {
1392 CatPrint (&Str
, L
"%s", MappingInfo
.Csd
.Str
);
1393 FreePool (MappingInfo
.Csd
.Str
);
1396 if (Str
.Str
!= NULL
) {
1397 CatPrint (&Str
, L
":");
1400 NewSize
= (Str
.Len
+ 1) * sizeof (CHAR16
);
1401 Str
.Str
= ReallocatePool (Str
.Len
, NewSize
, Str
.Str
);
1402 if (Str
.Str
== NULL
) {
1405 Str
.Str
[Str
.Len
] = CHAR_NULL
;
1410 Function to search the list of mappings for the node on the list based on the key.
1412 @param[in] MapKey String Key to search for on the map
1414 @return the node on the list.
1418 ShellCommandFindMapItem (
1419 IN CONST CHAR16
*MapKey
1422 SHELL_MAP_LIST
*MapListItem
;
1424 for ( MapListItem
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1425 ; !IsNull(&gShellMapList
.Link
, &MapListItem
->Link
)
1426 ; MapListItem
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &MapListItem
->Link
)
1428 if (gUnicodeCollation
->StriColl(gUnicodeCollation
,MapListItem
->MapName
,(CHAR16
*)MapKey
) == 0) {
1429 return (MapListItem
);