From nobody Fri Dec 27 20:51:29 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.zohomail.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 1500984781482756.9198185013593; Tue, 25 Jul 2017 05:13:01 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A79E421C91265; Tue, 25 Jul 2017 05:10:51 -0700 (PDT) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 E633321C91258 for ; Tue, 25 Jul 2017 05:10:49 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jul 2017 05:12:51 -0700 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.255.27.40]) by orsmga001.jf.intel.com with ESMTP; 25 Jul 2017 05:12:50 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,411,1496127600"; d="scan'208";a="1155145658" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Tue, 25 Jul 2017 20:12:43 +0800 Message-Id: <1500984765-8040-3-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1500984765-8040-1-git-send-email-jiaxin.wu@intel.com> References: <1500984765-8040-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 2/4] MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Fu Siyuan , Wu Jiaxin 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" Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- .../Library/UefiDevicePathLib/DevicePathFromText.c | 72 ++++++++++++++++++= ++++ .../Library/UefiDevicePathLib/DevicePathToText.c | 46 ++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c b/MdePkg= /Library/UefiDevicePathLib/DevicePathFromText.c index f50c11c..60057ec 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c @@ -2723,10 +2723,81 @@ DevPathFromTextBluetoothLE ( ); return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp; } =20 /** + Converts a text device path node to DNS device path structure. + + @param TextDeviceNode The input Text device path node. + + @return A pointer to the newly-created DNS device path structure. + +**/ +EFI_DEVICE_PATH_PROTOCOL * +DevPathFromTextDns ( + IN CHAR16 *TextDeviceNode + ) +{ + CHAR16 *DeviceNodeStr; + UINT32 DnsServerIpCount; + UINT16 DnsDeviceNodeLength; + DNS_DEVICE_PATH *DnsDeviceNode; + UINT32 DnsServerIpIndex; + CHAR16 *DnsServerIp; + + + // + // Count the DNS server address number. + // + DeviceNodeStr =3D TextDeviceNode; + DnsServerIpCount =3D 0; + while (DeviceNodeStr !=3D NULL) { + GetNextParamStr (&DeviceNodeStr); + DnsServerIpCount ++;=20 + } + + // + // Create the DNS DeviceNode. + // + DnsDeviceNodeLength =3D (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + si= zeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS)); + DnsDeviceNode =3D (DNS_DEVICE_PATH *) CreateDeviceNode ( + MESSAGING_DEVICE_PATH, + MSG_DNS_DP, + DnsDeviceNodeLength + ); + + // + // Confirm the DNS server address is IPv4 or IPv6 type. + // + DeviceNodeStr =3D TextDeviceNode; + while (!IS_NULL (*DeviceNodeStr)) { + if (*DeviceNodeStr =3D=3D L'.') { + DnsDeviceNode->IsIPv6 =3D 0x00; + break; + } + + if (*DeviceNodeStr =3D=3D L':') { + DnsDeviceNode->IsIPv6 =3D 0x01; + break; + } + + DeviceNodeStr++; + } + + for (DnsServerIpIndex =3D 0; DnsServerIpIndex < DnsServerIpCount; DnsSer= verIpIndex++) { + DnsServerIp =3D GetNextParamStr (&TextDeviceNode); + if (DnsDeviceNode->IsIPv6 =3D=3D 0x00) { + StrToIpv4Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[D= nsServerIpIndex].v4), NULL); + } else { + StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[Dn= sServerIpIndex].v6), NULL); + } + } + =20 + return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode; +} + +/** Converts a text device path node to URI device path structure. =20 @param TextDeviceNode The input Text device path node. =20 @return A pointer to the newly-created URI device path structure. @@ -3395,10 +3466,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT= _TABLE mUefiDevicePathLibDevP {L"UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement }, {L"UsbWwid", DevPathFromTextUsbWwid }, {L"Unit", DevPathFromTextUnit }, {L"iSCSI", DevPathFromTextiSCSI }, {L"Vlan", DevPathFromTextVlan }, + {L"Dns", DevPathFromTextDns }, {L"Uri", DevPathFromTextUri }, {L"Bluetooth", DevPathFromTextBluetooth }, {L"Wi-Fi", DevPathFromTextWiFi }, {L"BluetoothLE", DevPathFromTextBluetoothLE }, {L"MediaPath", DevPathFromTextMediaPath }, diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/L= ibrary/UefiDevicePathLib/DevicePathToText.c index b8d9491..63542db 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c @@ -1695,10 +1695,55 @@ DevPathToTextBluetoothLE ( BluetoothLE->Address.Type ); } =20 /** + Converts a DNS device path structure to its string representative. + + @param Str The string representative of input device. + @param DevPath The input device path structure. + @param DisplayOnly If DisplayOnly is TRUE, then the shorter text rep= resentation + of the display node is used, where applicable. If= DisplayOnly + is FALSE, then the longer text representation of = the display node + is used. + @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut form= s of text + representation for a device node can be used, whe= re applicable. + +**/ +VOID +DevPathToTextDns ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath, + IN BOOLEAN DisplayOnly, + IN BOOLEAN AllowShortcuts + ) +{ + DNS_DEVICE_PATH *DnsDevPath; + UINT32 DnsServerIpCount; + UINT32 DnsServerIpIndex; + + DnsDevPath =3D DevPath; + DnsServerIpCount =3D (UINT32) (DevicePathNodeLength(DnsDevPath) - sizeof= (EFI_DEVICE_PATH_PROTOCOL) - sizeof (DnsDevPath->IsIPv6)) / sizeof (EFI_IP= _ADDRESS); + + UefiDevicePathLibCatPrint (Str, L"Dns("); + =20 + for (DnsServerIpIndex =3D 0; DnsServerIpIndex < DnsServerIpCount; DnsSer= verIpIndex++) { + if (DnsDevPath->IsIPv6 =3D=3D 0x00) { + CatIPv4Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v4)= ); + } else { + CatIPv6Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v6)= ); + } + + if (DnsServerIpIndex < DnsServerIpCount - 1) { + UefiDevicePathLibCatPrint (Str, L","); + } + } + + UefiDevicePathLibCatPrint (Str, L")"); +} + +/** Converts a URI device path structure to its string representative. =20 @param Str The string representative of input device. @param DevPath The input device path structure. @param DisplayOnly If DisplayOnly is TRUE, then the shorter text rep= resentation @@ -2223,10 +2268,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_= TEXT_TABLE mUefiDevicePathLib {MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, DevPathToTextI= nfiniBand }, {MESSAGING_DEVICE_PATH, MSG_UART_DP, DevPathToTextU= art }, {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, DevPathToTextV= endor }, {MESSAGING_DEVICE_PATH, MSG_ISCSI_DP, DevPathToTexti= SCSI }, {MESSAGING_DEVICE_PATH, MSG_VLAN_DP, DevPathToTextV= lan }, + {MESSAGING_DEVICE_PATH, MSG_DNS_DP, DevPathToTextD= ns }, {MESSAGING_DEVICE_PATH, MSG_URI_DP, DevPathToTextU= ri }, {MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_DP, DevPathToTextB= luetooth }, {MESSAGING_DEVICE_PATH, MSG_WIFI_DP, DevPathToTextW= iFi }, {MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_LE_DP, DevPathToTextB= luetoothLE }, {MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, DevPathToTextH= ardDrive }, --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel