From nobody Sat Nov 2 16:31:00 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1488180176063474.15827001986486; Sun, 26 Feb 2017 23:22:56 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3BC43821AD; Sun, 26 Feb 2017 23:22:49 -0800 (PST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AA0D2820D9 for ; Sun, 26 Feb 2017 23:22:47 -0800 (PST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 26 Feb 2017 23:22:47 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by fmsmga005.fm.intel.com with ESMTP; 26 Feb 2017 23:22:46 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,213,1484035200"; d="scan'208";a="69934234" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Mon, 27 Feb 2017 15:22:34 +0800 Message-Id: <20170227072239.273228-7-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170227072239.273228-1-ruiyu.ni@intel.com> References: <20170227072239.273228-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH v2 06/11] MdePkg/UefiDevicePathLib: Use BaseLib string conversion services X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Update UefiDevicePathLib to use StrToGuid/StrHexToBytes /StrToIpv4Address/StrToIpv6Address provided by BaseLib. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Liming Gao --- .../Library/UefiDevicePathLib/DevicePathFromText.c | 221 ++---------------= ---- 1 file changed, 17 insertions(+), 204 deletions(-) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c b/MdePkg= /Library/UefiDevicePathLib/DevicePathFromText.c index e2b06a2..ae38859 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c @@ -326,187 +326,6 @@ Strtoi64 ( } =20 /** - Converts a list of string to a specified buffer. - - @param Buf The output buffer that contains the string. - @param BufferLength The length of the buffer - @param Str The input string that contains the hex number - - @retval EFI_SUCCESS The string was successfully converted to the buff= er. - -**/ -EFI_STATUS -StrToBuf ( - OUT UINT8 *Buf, - IN UINTN BufferLength, - IN CHAR16 *Str - ) -{ - UINTN Index; - UINTN StrLength; - UINT8 Digit; - UINT8 Byte; - - Digit =3D 0; - - // - // Two hex char make up one byte - // - StrLength =3D BufferLength * sizeof (CHAR16); - - for(Index =3D 0; Index < StrLength; Index++, Str++) { - - if ((*Str >=3D L'a') && (*Str <=3D L'f')) { - Digit =3D (UINT8) (*Str - L'a' + 0x0A); - } else if ((*Str >=3D L'A') && (*Str <=3D L'F')) { - Digit =3D (UINT8) (*Str - L'A' + 0x0A); - } else if ((*Str >=3D L'0') && (*Str <=3D L'9')) { - Digit =3D (UINT8) (*Str - L'0'); - } else { - return EFI_INVALID_PARAMETER; - } - - // - // For odd characters, write the upper nibble for each buffer byte, - // and for even characters, the lower nibble. - // - if ((Index & 1) =3D=3D 0) { - Byte =3D (UINT8) (Digit << 4); - } else { - Byte =3D Buf[Index / 2]; - Byte &=3D 0xF0; - Byte =3D (UINT8) (Byte | Digit); - } - - Buf[Index / 2] =3D Byte; - } - - return EFI_SUCCESS; -} - -/** - Converts a string to GUID value. - Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - - @param Str The registry format GUID string that contains th= e GUID value. - @param Guid A pointer to the converted GUID value. - - @retval EFI_SUCCESS The GUID string was successfully converted to th= e GUID value. - @retval EFI_UNSUPPORTED The input string is not in registry format. - @return others Some error occurred when converting part of GUID= value. - -**/ -EFI_STATUS -DevicePathLibStrToGuid ( - IN CHAR16 *Str, - OUT EFI_GUID *Guid - ) -{ - // - // Get the first UINT32 data - // - Guid->Data1 =3D (UINT32) StrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - =20 - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - =20 - // - // Get the second UINT16 data - // - Guid->Data2 =3D (UINT16) StrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - =20 - // - // Get the third UINT16 data - // - Guid->Data3 =3D (UINT16) StrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - - // - // Get the following 8 bytes data - // =20 - StrToBuf (&Guid->Data4[0], 2, Str); - // - // Skip 2 byte hex chars - // - Str +=3D 2 * 2; - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - StrToBuf (&Guid->Data4[2], 6, Str); - - return EFI_SUCCESS; -} - -/** - Converts a string to IPv4 address - - @param Str A string representation of IPv4 address. - @param IPv4Addr A pointer to the converted IPv4 address. - -**/ -VOID -StrToIPv4Addr ( - IN OUT CHAR16 **Str, - OUT EFI_IPv4_ADDRESS *IPv4Addr - ) -{ - UINTN Index; - - for (Index =3D 0; Index < 4; Index++) { - IPv4Addr->Addr[Index] =3D (UINT8) Strtoi (SplitStr (Str, L'.')); - } -} - -/** - Converts a string to IPv4 address - - @param Str A string representation of IPv6 address. - @param IPv6Addr A pointer to the converted IPv6 address. - -**/ -VOID -StrToIPv6Addr ( - IN OUT CHAR16 **Str, - OUT EFI_IPv6_ADDRESS *IPv6Addr - ) -{ - UINTN Index; - UINT16 Data; - - for (Index =3D 0; Index < 8; Index++) { - Data =3D (UINT16) StrHexToUintn (SplitStr (Str, L':')); - IPv6Addr->Addr[Index * 2] =3D (UINT8) (Data >> 8); - IPv6Addr->Addr[Index * 2 + 1] =3D (UINT8) (Data & 0xff); - } -} - -/** Converts a Unicode string to ASCII string. =20 @param Str The equivalent Unicode string @@ -567,9 +386,7 @@ DevPathFromTextGenericPath ( (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + DataLength) ); =20 - if (DataLength !=3D 0) { - StrToBuf ((UINT8 *) (Node + 1), DataLength, DataStr); - } + StrHexToBytes (DataStr, DataLength * 2, (UINT8 *) (Node + 1), DataLength= ); return Node; } =20 @@ -740,8 +557,8 @@ ConvertFromTextVendor ( (UINT16) (sizeof (VENDOR_DEVICE_PATH)= + Length) ); =20 - DevicePathLibStrToGuid (GuidStr, &Vendor->Guid); - StrToBuf (((UINT8 *) Vendor) + sizeof (VENDOR_DEVICE_PATH), Length, Data= Str); + StrToGuid (GuidStr, &Vendor->Guid); + StrHexToBytes (DataStr, Length * 2, (UINT8 *) (Vendor + 1), Length); =20 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor; } @@ -1438,7 +1255,6 @@ DevPathFromTextInfiniband ( CHAR16 *SidStr; CHAR16 *TidStr; CHAR16 *DidStr; - EFI_GUID PortGid; INFINIBAND_DEVICE_PATH *InfiniBand; =20 FlagsStr =3D GetNextParamStr (&TextDeviceNode); @@ -1453,8 +1269,7 @@ DevPathFromTextInfiniband ( ); =20 InfiniBand->ResourceFlags =3D (UINT32) Strtoi (FlagsStr); - DevicePathLibStrToGuid (GuidStr, &PortGid); - CopyMem (InfiniBand->PortGid, &PortGid, sizeof (EFI_GUID)); + StrToGuid (GuidStr, (EFI_GUID *) InfiniBand->PortGid); Strtoi64 (SidStr, &InfiniBand->ServiceId); Strtoi64 (TidStr, &InfiniBand->TargetPortId); Strtoi64 (DidStr, &InfiniBand->DeviceId); @@ -1985,7 +1800,7 @@ DevPathFromTextMAC ( MACDevPath->IfType =3D (UINT8) Strtoi (IfTypeStr); =20 Length =3D sizeof (EFI_MAC_ADDRESS); - StrToBuf (&MACDevPath->MacAddress.Addr[0], Length, AddressStr); + StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Leng= th); =20 return (EFI_DEVICE_PATH_PROTOCOL *) MACDevPath; } @@ -2049,7 +1864,7 @@ DevPathFromTextIPv4 ( (UINT16) sizeof (IPv4_DEV= ICE_PATH) ); =20 - StrToIPv4Addr (&RemoteIPStr, &IPv4->RemoteIpAddress); + StrToIpv4Address (RemoteIPStr, NULL, &IPv4->RemoteIpAddress, NULL); IPv4->Protocol =3D (UINT16) NetworkProtocolFromText (ProtocolStr); if (StrCmp (TypeStr, L"Static") =3D=3D 0) { IPv4->StaticIpAddress =3D TRUE; @@ -2057,10 +1872,10 @@ DevPathFromTextIPv4 ( IPv4->StaticIpAddress =3D FALSE; } =20 - StrToIPv4Addr (&LocalIPStr, &IPv4->LocalIpAddress); + StrToIpv4Address (LocalIPStr, NULL, &IPv4->LocalIpAddress, NULL); if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*SubnetMaskStr)) { - StrToIPv4Addr (&GatewayIPStr, &IPv4->GatewayIpAddress); - StrToIPv4Addr (&SubnetMaskStr, &IPv4->SubnetMask); + StrToIpv4Address (GatewayIPStr, NULL, &IPv4->GatewayIpAddress, NULL); + StrToIpv4Address (SubnetMaskStr, NULL, &IPv4->SubnetMask, NULL); } else { ZeroMem (&IPv4->GatewayIpAddress, sizeof (IPv4->GatewayIpAddress)); ZeroMem (&IPv4->SubnetMask, sizeof (IPv4->SubnetMask)); @@ -2105,7 +1920,7 @@ DevPathFromTextIPv6 ( (UINT16) sizeof (IPv6_DEV= ICE_PATH) ); =20 - StrToIPv6Addr (&RemoteIPStr, &IPv6->RemoteIpAddress); + StrToIpv6Address (RemoteIPStr, NULL, &IPv6->RemoteIpAddress, NULL); IPv6->Protocol =3D (UINT16) NetworkProtocolFromText (ProtocolStr); if (StrCmp (TypeStr, L"Static") =3D=3D 0) { IPv6->IpAddressOrigin =3D 0; @@ -2115,9 +1930,9 @@ DevPathFromTextIPv6 ( IPv6->IpAddressOrigin =3D 2; } =20 - StrToIPv6Addr (&LocalIPStr, &IPv6->LocalIpAddress); + StrToIpv6Address (LocalIPStr, NULL, &IPv6->LocalIpAddress, NULL); if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*PrefixLengthStr)) { - StrToIPv6Addr (&GatewayIPStr, &IPv6->GatewayIpAddress); + StrToIpv6Address (GatewayIPStr, NULL, &IPv6->GatewayIpAddress, NULL); IPv6->PrefixLength =3D (UINT8) Strtoi (PrefixLengthStr); } else { ZeroMem (&IPv6->GatewayIpAddress, sizeof (IPv6->GatewayIpAddress)); @@ -2947,7 +2762,6 @@ DevPathFromTextHD ( CHAR16 *StartStr; CHAR16 *SizeStr; UINT32 Signature32; - EFI_GUID SignatureGuid; HARDDRIVE_DEVICE_PATH *Hd; =20 PartitionStr =3D GetNextParamStr (&TextDeviceNode); @@ -2976,8 +2790,7 @@ DevPathFromTextHD ( Hd->SignatureType =3D SIGNATURE_TYPE_GUID; Hd->MBRType =3D 0x02; =20 - DevicePathLibStrToGuid (SignatureStr, &SignatureGuid); - CopyMem (Hd->Signature, &SignatureGuid, sizeof (EFI_GUID)); + StrToGuid (SignatureStr, (EFI_GUID *) Hd->Signature); } else { Hd->SignatureType =3D (UINT8) Strtoi (TypeStr); } @@ -3091,7 +2904,7 @@ DevPathFromTextMedia ( (UINT16) sizeof (MEDIA_PROTOC= OL_DEVICE_PATH) ); =20 - DevicePathLibStrToGuid (GuidStr, &Media->Protocol); + StrToGuid (GuidStr, &Media->Protocol); =20 return (EFI_DEVICE_PATH_PROTOCOL *) Media; } @@ -3119,7 +2932,7 @@ DevPathFromTextFv ( (UINT16) sizeof (MEDIA_FW_VOL_D= EVICE_PATH) ); =20 - DevicePathLibStrToGuid (GuidStr, &Fv->FvName); + StrToGuid (GuidStr, &Fv->FvName); =20 return (EFI_DEVICE_PATH_PROTOCOL *) Fv; } @@ -3147,7 +2960,7 @@ DevPathFromTextFvFile ( (UINT16) sizeof (MEDIA= _FW_VOL_FILEPATH_DEVICE_PATH) ); =20 - DevicePathLibStrToGuid (GuidStr, &FvFile->FvFileName); + StrToGuid (GuidStr, &FvFile->FvFileName); =20 return (EFI_DEVICE_PATH_PROTOCOL *) FvFile; } @@ -3219,7 +3032,7 @@ DevPathFromTextRamDisk ( Strtoi64 (EndingAddrStr, &EndingAddr); WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr); RamDisk->Instance =3D (UINT16) Strtoi (InstanceStr); - DevicePathLibStrToGuid (TypeGuidStr, &RamDisk->TypeGuid); + StrToGuid (TypeGuidStr, &RamDisk->TypeGuid); =20 return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk; } --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel