Re: [edk2] [PATCH v2][Patch 2/4] MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries

2017-08-02 Thread Wu, Jiaxin
You are right. Thanks Eric, will send out V3 later.



> -Original Message-
> From: Jin, Eric
> Sent: Thursday, August 3, 2017 1:10 PM
> To: Wu, Jiaxin <jiaxin...@intel.com>; edk2-devel@lists.01.org
> Cc: Ye, Ting <ting...@intel.com>; Fu, Siyuan <siyuan...@intel.com>; Wu,
> Jiaxin <jiaxin...@intel.com>; Jin, Eric <eric....@intel.com>
> Subject: RE: [edk2] [PATCH v2][Patch 2/4] MdePkg/UefiDevicePathLib: Add
> DevPathFromTextDns and DevPathToTextDns libraries
> 
> Jiaxin,
> 
> In V2, the input parameter, TextDeviceNode, in the DevPathFromTextDns()
> is parsed by GetNextParamStr() twice.
> After the first parse, the content of TextDeviceNode is modified and can
> convert to correct device path node.
> 
> Suggest to duplicate the TextDeviceNode or restore the return value of 1st
> GetNextParamStr() for usage in next step. Thanks.
> 
> Best Regards
> Eric
> 
> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> Jiaxin Wu
> Sent: Wednesday, July 26, 2017 11:41 AM
> To: edk2-devel@lists.01.org
> Cc: Ye, Ting <ting...@intel.com>; Fu, Siyuan <siyuan...@intel.com>; Wu,
> Jiaxin <jiaxin...@intel.com>
> Subject: [edk2] [PATCH v2][Patch 2/4] MdePkg/UefiDevicePathLib: Add
> DevPathFromTextDns and DevPathToTextDns libraries
> 
> V2:
> * Add no IP instance case check.
> 
> Cc: Ye Ting <ting...@intel.com>
> Cc: Fu Siyuan <siyuan...@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Wu Jiaxin <jiaxin...@intel.com>
> ---
>  .../Library/UefiDevicePathLib/DevicePathFromText.c | 80
> ++
>  .../Library/UefiDevicePathLib/DevicePathToText.c   | 46 +
>  2 files changed, 126 insertions(+)
> 
> diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
> b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
> index f50c11c..3cdc11f 100644
> --- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
> +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
> @@ -2723,10 +2723,89 @@ DevPathFromTextBluetoothLE (
>  );
>return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp;  }
> 
>  /**
> +  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;
> +  UINT32DnsServerIpCount;
> +  UINT16DnsDeviceNodeLength;
> +  DNS_DEVICE_PATH   *DnsDeviceNode;
> +  UINT32DnsServerIpIndex;
> +  CHAR16*DnsServerIp;
> +
> +
> +  //
> +  // Count the DNS server address number.
> +  //
> +  DeviceNodeStr= TextDeviceNode;
> +  DnsServerIpCount = 0;
> +  while (DeviceNodeStr != NULL && *DeviceNodeStr != L'\0') {
> +GetNextParamStr ();
> +DnsServerIpCount ++;
> +  }
> +
> +  //
> +  // One or more instances of the DNS server address in EFI_IP_ADDRESS,
> + // otherwise, NULL will be returned.
> +  //
> +  if (DnsServerIpCount == 0) {
> +return NULL;
> +  }
> +
> +  //
> +  // Create the DNS DeviceNode.
> +  //
> +  DnsDeviceNodeLength = (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL)
> + sizeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));
> +  DnsDeviceNode   = (DNS_DEVICE_PATH *) CreateDeviceNode (
> +  MESSAGING_DEVICE_PATH,
> +  MSG_DNS_DP,
> +  DnsDeviceNodeLength
> +  );
> +
> +  //
> +  // Confirm the DNS server address is IPv4 or IPv6 type.
> +  //
> +  DeviceNodeStr = TextDeviceNode;
> +  while (!IS_NULL (*DeviceNodeStr)) {
> +if (*DeviceNodeStr == L'.') {
> +  DnsDeviceNode->IsIPv6 = 0x00;
> +  break;
> +}
> +
> +if (*DeviceNodeStr == L':') {
> +  DnsDeviceNode->IsIPv6 = 0x01;
> +  break;
> +}
> +
> +DeviceNodeStr++;
> +  }
> +
> +  for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount;
> DnsServerIpIndex++) {
> +DnsServerIp = GetNextParamStr ();
> +if (DnsDeviceNode->IsIPv6 == 0x00) {
> +  StrToIpv4Address (DnsServerIp,  NULL, &(DnsDeviceNode-
> >DnsServerIp[DnsServerIpIndex].v4), NULL);
> +} else {
> +  StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode-
> >DnsServerIp[DnsServerIpIndex].v6), NULL);
&g

Re: [edk2] [PATCH v2][Patch 2/4] MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries

2017-08-02 Thread Jin, Eric
Jiaxin,

In V2, the input parameter, TextDeviceNode, in the DevPathFromTextDns() is 
parsed by GetNextParamStr() twice.
After the first parse, the content of TextDeviceNode is modified and can 
convert to correct device path node.

Suggest to duplicate the TextDeviceNode or restore the return value of 1st 
GetNextParamStr() for usage in next step. Thanks.

Best Regards
Eric

-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Jiaxin Wu
Sent: Wednesday, July 26, 2017 11:41 AM
To: edk2-devel@lists.01.org
Cc: Ye, Ting <ting...@intel.com>; Fu, Siyuan <siyuan...@intel.com>; Wu, Jiaxin 
<jiaxin...@intel.com>
Subject: [edk2] [PATCH v2][Patch 2/4] MdePkg/UefiDevicePathLib: Add 
DevPathFromTextDns and DevPathToTextDns libraries

V2:
* Add no IP instance case check.

Cc: Ye Ting <ting...@intel.com>
Cc: Fu Siyuan <siyuan...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin...@intel.com>
---
 .../Library/UefiDevicePathLib/DevicePathFromText.c | 80 ++
 .../Library/UefiDevicePathLib/DevicePathToText.c   | 46 +
 2 files changed, 126 insertions(+)

diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c 
b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
index f50c11c..3cdc11f 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
@@ -2723,10 +2723,89 @@ DevPathFromTextBluetoothLE (
 );
   return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp;  }
 
 /**
+  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;
+  UINT32DnsServerIpCount;
+  UINT16DnsDeviceNodeLength;
+  DNS_DEVICE_PATH   *DnsDeviceNode;
+  UINT32DnsServerIpIndex;
+  CHAR16*DnsServerIp;
+
+
+  //
+  // Count the DNS server address number.
+  //
+  DeviceNodeStr= TextDeviceNode;
+  DnsServerIpCount = 0;
+  while (DeviceNodeStr != NULL && *DeviceNodeStr != L'\0') {
+GetNextParamStr ();
+DnsServerIpCount ++;
+  }
+
+  //
+  // One or more instances of the DNS server address in EFI_IP_ADDRESS,  
+ // otherwise, NULL will be returned.
+  //
+  if (DnsServerIpCount == 0) {
+return NULL;
+  }
+
+  //
+  // Create the DNS DeviceNode.
+  //
+  DnsDeviceNodeLength = (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof 
(UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));
+  DnsDeviceNode   = (DNS_DEVICE_PATH *) CreateDeviceNode (
+  MESSAGING_DEVICE_PATH,
+  MSG_DNS_DP,
+  DnsDeviceNodeLength
+  );
+
+  //
+  // Confirm the DNS server address is IPv4 or IPv6 type.
+  //
+  DeviceNodeStr = TextDeviceNode;
+  while (!IS_NULL (*DeviceNodeStr)) {
+if (*DeviceNodeStr == L'.') {
+  DnsDeviceNode->IsIPv6 = 0x00;
+  break;
+}
+
+if (*DeviceNodeStr == L':') {
+  DnsDeviceNode->IsIPv6 = 0x01;
+  break;
+}
+
+DeviceNodeStr++;
+  }
+
+  for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; 
DnsServerIpIndex++) {
+DnsServerIp = GetNextParamStr ();
+if (DnsDeviceNode->IsIPv6 == 0x00) {
+  StrToIpv4Address (DnsServerIp,  NULL, 
&(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL);
+} else {
+  StrToIpv6Address (DnsServerIp, NULL, 
&(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL);
+}
+  }
+  
+  return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode; }
+
+/**
   Converts a text device path node to URI device path structure.
 
   @param TextDeviceNode  The input Text device path node.
 
   @return A pointer to the newly-created URI device path structure.
@@ -3395,10 +3474,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"Blue

Re: [edk2] [PATCH v2][Patch 2/4] MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries

2017-07-25 Thread Fu, Siyuan
Reviewed-by: Fu Siyuan 


-Original Message-
From: Wu, Jiaxin 
Sent: Wednesday, July 26, 2017 11:41 AM
To: edk2-devel@lists.01.org
Cc: Ye, Ting ; Fu, Siyuan ; Wu, Jiaxin 

Subject: [PATCH v2][Patch 2/4] MdePkg/UefiDevicePathLib: Add DevPathFromTextDns 
and DevPathToTextDns libraries

V2:
* Add no IP instance case check.

Cc: Ye Ting 
Cc: Fu Siyuan 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin 
---
 .../Library/UefiDevicePathLib/DevicePathFromText.c | 80 ++
 .../Library/UefiDevicePathLib/DevicePathToText.c   | 46 +
 2 files changed, 126 insertions(+)

diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c 
b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
index f50c11c..3cdc11f 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
@@ -2723,10 +2723,89 @@ DevPathFromTextBluetoothLE (
 );
   return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp;
 }
 
 /**
+  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;
+  UINT32DnsServerIpCount;
+  UINT16DnsDeviceNodeLength;
+  DNS_DEVICE_PATH   *DnsDeviceNode;
+  UINT32DnsServerIpIndex;
+  CHAR16*DnsServerIp;
+
+
+  //
+  // Count the DNS server address number.
+  //
+  DeviceNodeStr= TextDeviceNode;
+  DnsServerIpCount = 0;
+  while (DeviceNodeStr != NULL && *DeviceNodeStr != L'\0') {
+GetNextParamStr ();
+DnsServerIpCount ++; 
+  }
+
+  //
+  // One or more instances of the DNS server address in EFI_IP_ADDRESS, 
+  // otherwise, NULL will be returned.
+  //
+  if (DnsServerIpCount == 0) {
+return NULL;
+  }
+
+  //
+  // Create the DNS DeviceNode.
+  //
+  DnsDeviceNodeLength = (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof 
(UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));
+  DnsDeviceNode   = (DNS_DEVICE_PATH *) CreateDeviceNode (
+  MESSAGING_DEVICE_PATH,
+  MSG_DNS_DP,
+  DnsDeviceNodeLength
+  );
+
+  //
+  // Confirm the DNS server address is IPv4 or IPv6 type.
+  //
+  DeviceNodeStr = TextDeviceNode;
+  while (!IS_NULL (*DeviceNodeStr)) {
+if (*DeviceNodeStr == L'.') {
+  DnsDeviceNode->IsIPv6 = 0x00;
+  break;
+}
+
+if (*DeviceNodeStr == L':') {
+  DnsDeviceNode->IsIPv6 = 0x01;
+  break;
+}
+
+DeviceNodeStr++;
+  }
+
+  for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; 
DnsServerIpIndex++) {
+DnsServerIp = GetNextParamStr ();
+if (DnsDeviceNode->IsIPv6 == 0x00) {
+  StrToIpv4Address (DnsServerIp,  NULL, 
&(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL);
+} else {
+  StrToIpv6Address (DnsServerIp, NULL, 
&(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL);
+}
+  }
+  
+  return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode;
+}
+
+/**
   Converts a text device path node to URI device path structure.
 
   @param TextDeviceNode  The input Text device path node.
 
   @return A pointer to the newly-created URI device path structure.
@@ -3395,10 +3474,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/Library/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
 );
 }
 
 /**
+  Converts a DNS device path structure to its string 

[edk2] [PATCH v2][Patch 2/4] MdePkg/UefiDevicePathLib: Add DevPathFromTextDns and DevPathToTextDns libraries

2017-07-25 Thread Jiaxin Wu
V2:
* Add no IP instance case check.

Cc: Ye Ting 
Cc: Fu Siyuan 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin 
---
 .../Library/UefiDevicePathLib/DevicePathFromText.c | 80 ++
 .../Library/UefiDevicePathLib/DevicePathToText.c   | 46 +
 2 files changed, 126 insertions(+)

diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c 
b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
index f50c11c..3cdc11f 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
@@ -2723,10 +2723,89 @@ DevPathFromTextBluetoothLE (
 );
   return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp;
 }
 
 /**
+  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;
+  UINT32DnsServerIpCount;
+  UINT16DnsDeviceNodeLength;
+  DNS_DEVICE_PATH   *DnsDeviceNode;
+  UINT32DnsServerIpIndex;
+  CHAR16*DnsServerIp;
+
+
+  //
+  // Count the DNS server address number.
+  //
+  DeviceNodeStr= TextDeviceNode;
+  DnsServerIpCount = 0;
+  while (DeviceNodeStr != NULL && *DeviceNodeStr != L'\0') {
+GetNextParamStr ();
+DnsServerIpCount ++; 
+  }
+
+  //
+  // One or more instances of the DNS server address in EFI_IP_ADDRESS, 
+  // otherwise, NULL will be returned.
+  //
+  if (DnsServerIpCount == 0) {
+return NULL;
+  }
+
+  //
+  // Create the DNS DeviceNode.
+  //
+  DnsDeviceNodeLength = (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof 
(UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS));
+  DnsDeviceNode   = (DNS_DEVICE_PATH *) CreateDeviceNode (
+  MESSAGING_DEVICE_PATH,
+  MSG_DNS_DP,
+  DnsDeviceNodeLength
+  );
+
+  //
+  // Confirm the DNS server address is IPv4 or IPv6 type.
+  //
+  DeviceNodeStr = TextDeviceNode;
+  while (!IS_NULL (*DeviceNodeStr)) {
+if (*DeviceNodeStr == L'.') {
+  DnsDeviceNode->IsIPv6 = 0x00;
+  break;
+}
+
+if (*DeviceNodeStr == L':') {
+  DnsDeviceNode->IsIPv6 = 0x01;
+  break;
+}
+
+DeviceNodeStr++;
+  }
+
+  for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; 
DnsServerIpIndex++) {
+DnsServerIp = GetNextParamStr ();
+if (DnsDeviceNode->IsIPv6 == 0x00) {
+  StrToIpv4Address (DnsServerIp,  NULL, 
&(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL);
+} else {
+  StrToIpv6Address (DnsServerIp, NULL, 
&(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL);
+}
+  }
+  
+  return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode;
+}
+
+/**
   Converts a text device path node to URI device path structure.
 
   @param TextDeviceNode  The input Text device path node.
 
   @return A pointer to the newly-created URI device path structure.
@@ -3395,10 +3474,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/Library/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
 );
 }
 
 /**
+  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 
representation
+ of the display node is used, where applicable. If 
DisplayOnly
+ is FALSE, then the longer text