Re: [edk2] [Patch] ShellPkg: Enhance ping6 to select the interface automatically

2016-04-27 Thread Carsey, Jaben
Reviewed-by: Jaben Carsey <jaben.car...@intel.com>

> -Original Message-
> From: Wu, Jiaxin
> Sent: Tuesday, April 26, 2016 6:21 PM
> To: Bhupesh Sharma <bhupesh.sha...@nxp.com>; edk2-devel@lists.01.org
> Cc: Carsey, Jaben <jaben.car...@intel.com>; Ye, Ting <ting...@intel.com>;
> Fu, Siyuan <siyuan...@intel.com>
> Subject: RE: [edk2] [Patch] ShellPkg: Enhance ping6 to select the interface
> automatically
> Importance: High
> 
> Jaben and Bhupesh,
> 
> Any comments for this patch?
> 
> Thanks.
> Jiaxin
> 
> > -Original Message-
> > From: Wu, Jiaxin
> > Sent: Friday, April 22, 2016 11:01 AM
> > To: Bhupesh Sharma <bhupesh.sha...@nxp.com>; Wu, Jiaxin
> > <jiaxin...@intel.com>; edk2-devel@lists.01.org
> > Cc: Carsey, Jaben <jaben.car...@intel.com>; Ye, Ting <ting...@intel.com>;
> > Fu, Siyuan <siyuan...@intel.com>
> > Subject: RE: [edk2] [Patch] ShellPkg: Enhance ping6 to select the interface
> > automatically
> >
> > Hello Bhupesh,
> >
> > Can you also help to verify the ping6 command for the same case as ping?
> >
> > Thanks and Best Regards!
> > Jiaxin
> >
> > > -Original Message-
> > > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> > > Jiaxin Wu
> > > Sent: Friday, April 22, 2016 10:57 AM
> > > To: edk2-devel@lists.01.org
> > > Cc: Carsey, Jaben <jaben.car...@intel.com>; Ye, Ting
> > > <ting...@intel.com>; Fu, Siyuan <siyuan...@intel.com>
> > > Subject: [edk2] [Patch] ShellPkg: Enhance ping6 to select the
> > > interface automatically
> > >
> > > This patch is used to support no source IP specified case while
> > > multiple NICs existed in the platform. The command will select the
> > > first both connected and configured interface automatically.
> > >
> > > Cc: Bhupesh Sharma <bhupesh.sha...@nxp.com>
> > > Cc: Jaben Carsey <jaben.car...@intel.com>
> > > Cc: Ye Ting <ting...@intel.com>
> > > Cc: Fu Siyuan <siyuan...@intel.com>
> > > Contributed-under: TianoCore Contribution Agreement 1.0
> > > Signed-off-by: Jiaxin Wu <jiaxin...@intel.com>
> > > ---
> > >  .../Library/UefiShellNetwork2CommandsLib/Ping6.c   | 166
> > --
> > > ---
> > >  1 file changed, 95 insertions(+), 71 deletions(-)
> > >
> > > diff --git a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> > > b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> > > index af7d08f..f129612 100644
> > > --- a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> > > +++ b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> > > @@ -661,22 +661,26 @@ Ping6CreateIpInstance (  {
> > >EFI_STATUS   Status;
> > >UINTNHandleIndex;
> > >UINTNHandleNum;
> > >EFI_HANDLE   *HandleBuffer;
> > > +  BOOLEAN  UnspecifiedSrc;
> > > +  BOOLEAN  MediaPresent;
> > >EFI_SERVICE_BINDING_PROTOCOL *Ip6Sb;
> > >EFI_IP6_CONFIG_PROTOCOL  *Ip6Cfg;
> > >EFI_IP6_CONFIG_DATA  Ip6Config;
> > >EFI_IP6_CONFIG_INTERFACE_INFO*IfInfo;
> > >UINTNIfInfoSize;
> > >EFI_IPv6_ADDRESS *Addr;
> > >UINTNAddrIndex;
> > >
> > > -  HandleBuffer = NULL;
> > > -  Ip6Sb= NULL;
> > > -  IfInfo   = NULL;
> > > -  IfInfoSize   = 0;
> > > +  HandleBuffer  = NULL;
> > > +  UnspecifiedSrc= FALSE;
> > > +  MediaPresent  = TRUE;
> > > +  Ip6Sb = NULL;
> > > +  IfInfo= NULL;
> > > +  IfInfoSize= 0;
> > >
> > >//
> > >// Locate all the handles with ip6 service binding protocol.
> > >//
> > >Status = gBS->LocateHandleBuffer (
> > > @@ -687,115 +691,135 @@ Ping6CreateIpInstance (
> > >
> > >);
> > >if (EFI_ERROR (Status) || (HandleNum == 0)) {
> > >  return EFI_ABORTED;
> > >}
> > > +
> > > +  if (NetIp6IsUnspecifiedAddr (>SrcAddress)) {
> > > +//
> > > +// SrcAddress is unspecified. So, both connected and configured
> 

Re: [edk2] [Patch] ShellPkg: Enhance ping6 to select the interface automatically

2016-04-26 Thread Wu, Jiaxin
Jaben and Bhupesh,

Any comments for this patch?

Thanks.
Jiaxin

> -Original Message-
> From: Wu, Jiaxin
> Sent: Friday, April 22, 2016 11:01 AM
> To: Bhupesh Sharma <bhupesh.sha...@nxp.com>; Wu, Jiaxin
> <jiaxin...@intel.com>; edk2-devel@lists.01.org
> Cc: Carsey, Jaben <jaben.car...@intel.com>; Ye, Ting <ting...@intel.com>;
> Fu, Siyuan <siyuan...@intel.com>
> Subject: RE: [edk2] [Patch] ShellPkg: Enhance ping6 to select the interface
> automatically
> 
> Hello Bhupesh,
> 
> Can you also help to verify the ping6 command for the same case as ping?
> 
> Thanks and Best Regards!
> Jiaxin
> 
> > -Original Message-
> > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> > Jiaxin Wu
> > Sent: Friday, April 22, 2016 10:57 AM
> > To: edk2-devel@lists.01.org
> > Cc: Carsey, Jaben <jaben.car...@intel.com>; Ye, Ting
> > <ting...@intel.com>; Fu, Siyuan <siyuan...@intel.com>
> > Subject: [edk2] [Patch] ShellPkg: Enhance ping6 to select the
> > interface automatically
> >
> > This patch is used to support no source IP specified case while
> > multiple NICs existed in the platform. The command will select the
> > first both connected and configured interface automatically.
> >
> > Cc: Bhupesh Sharma <bhupesh.sha...@nxp.com>
> > Cc: Jaben Carsey <jaben.car...@intel.com>
> > Cc: Ye Ting <ting...@intel.com>
> > Cc: Fu Siyuan <siyuan...@intel.com>
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Jiaxin Wu <jiaxin...@intel.com>
> > ---
> >  .../Library/UefiShellNetwork2CommandsLib/Ping6.c   | 166
> --
> > ---
> >  1 file changed, 95 insertions(+), 71 deletions(-)
> >
> > diff --git a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> > b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> > index af7d08f..f129612 100644
> > --- a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> > +++ b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> > @@ -661,22 +661,26 @@ Ping6CreateIpInstance (  {
> >EFI_STATUS   Status;
> >UINTNHandleIndex;
> >UINTNHandleNum;
> >EFI_HANDLE   *HandleBuffer;
> > +  BOOLEAN  UnspecifiedSrc;
> > +  BOOLEAN  MediaPresent;
> >EFI_SERVICE_BINDING_PROTOCOL *Ip6Sb;
> >EFI_IP6_CONFIG_PROTOCOL  *Ip6Cfg;
> >EFI_IP6_CONFIG_DATA  Ip6Config;
> >EFI_IP6_CONFIG_INTERFACE_INFO*IfInfo;
> >UINTNIfInfoSize;
> >EFI_IPv6_ADDRESS *Addr;
> >UINTNAddrIndex;
> >
> > -  HandleBuffer = NULL;
> > -  Ip6Sb= NULL;
> > -  IfInfo   = NULL;
> > -  IfInfoSize   = 0;
> > +  HandleBuffer  = NULL;
> > +  UnspecifiedSrc= FALSE;
> > +  MediaPresent  = TRUE;
> > +  Ip6Sb = NULL;
> > +  IfInfo= NULL;
> > +  IfInfoSize= 0;
> >
> >//
> >// Locate all the handles with ip6 service binding protocol.
> >//
> >Status = gBS->LocateHandleBuffer (
> > @@ -687,115 +691,135 @@ Ping6CreateIpInstance (
> >
> >);
> >if (EFI_ERROR (Status) || (HandleNum == 0)) {
> >  return EFI_ABORTED;
> >}
> > +
> > +  if (NetIp6IsUnspecifiedAddr (>SrcAddress)) {
> > +//
> > +// SrcAddress is unspecified. So, both connected and configured
> > + interface
> > will be automatic selected.
> > +//
> > +UnspecifiedSrc = TRUE;
> > +  }
> > +
> >//
> >// Source address is required when pinging a link-local address on multi-
> >// interfaces host.
> >//
> >if (NetIp6IsLinkLocalAddr (>DstAddress) &&
> > -  NetIp6IsUnspecifiedAddr (>SrcAddress) &&
> > -  (HandleNum > 1)) {
> > +  UnspecifiedSrc && (HandleNum > 1)) {
> >  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> > (STR_PING6_INVALID_SOURCE), gShellNetwork2HiiHandle);
> >  Status = EFI_INVALID_PARAMETER;
> >  goto ON_ERROR;
> >}
> > +
> >//
> >// For each ip6 protocol, check interface addresses list.
> >//
> >for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
> >
> &g

Re: [edk2] [Patch] ShellPkg: Enhance ping6 to select the interface automatically

2016-04-21 Thread Wu, Jiaxin
Hello Bhupesh,

Can you also help to verify the ping6 command for the same case as ping?

Thanks and Best Regards!
Jiaxin

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> Jiaxin Wu
> Sent: Friday, April 22, 2016 10:57 AM
> To: edk2-devel@lists.01.org
> Cc: Carsey, Jaben <jaben.car...@intel.com>; Ye, Ting <ting...@intel.com>;
> Fu, Siyuan <siyuan...@intel.com>
> Subject: [edk2] [Patch] ShellPkg: Enhance ping6 to select the interface
> automatically
> 
> This patch is used to support no source IP specified case while multiple NICs
> existed in the platform. The command will select the first both connected
> and configured interface automatically.
> 
> Cc: Bhupesh Sharma <bhupesh.sha...@nxp.com>
> Cc: Jaben Carsey <jaben.car...@intel.com>
> Cc: Ye Ting <ting...@intel.com>
> Cc: Fu Siyuan <siyuan...@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiaxin Wu <jiaxin...@intel.com>
> ---
>  .../Library/UefiShellNetwork2CommandsLib/Ping6.c   | 166 --
> ---
>  1 file changed, 95 insertions(+), 71 deletions(-)
> 
> diff --git a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> index af7d08f..f129612 100644
> --- a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> +++ b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
> @@ -661,22 +661,26 @@ Ping6CreateIpInstance (  {
>EFI_STATUS   Status;
>UINTNHandleIndex;
>UINTNHandleNum;
>EFI_HANDLE   *HandleBuffer;
> +  BOOLEAN  UnspecifiedSrc;
> +  BOOLEAN  MediaPresent;
>EFI_SERVICE_BINDING_PROTOCOL *Ip6Sb;
>EFI_IP6_CONFIG_PROTOCOL  *Ip6Cfg;
>EFI_IP6_CONFIG_DATA  Ip6Config;
>EFI_IP6_CONFIG_INTERFACE_INFO*IfInfo;
>UINTNIfInfoSize;
>EFI_IPv6_ADDRESS *Addr;
>UINTNAddrIndex;
> 
> -  HandleBuffer = NULL;
> -  Ip6Sb= NULL;
> -  IfInfo   = NULL;
> -  IfInfoSize   = 0;
> +  HandleBuffer  = NULL;
> +  UnspecifiedSrc= FALSE;
> +  MediaPresent  = TRUE;
> +  Ip6Sb = NULL;
> +  IfInfo= NULL;
> +  IfInfoSize= 0;
> 
>//
>// Locate all the handles with ip6 service binding protocol.
>//
>Status = gBS->LocateHandleBuffer (
> @@ -687,115 +691,135 @@ Ping6CreateIpInstance (
>
>);
>if (EFI_ERROR (Status) || (HandleNum == 0)) {
>  return EFI_ABORTED;
>}
> +
> +  if (NetIp6IsUnspecifiedAddr (>SrcAddress)) {
> +//
> +// SrcAddress is unspecified. So, both connected and configured interface
> will be automatic selected.
> +//
> +UnspecifiedSrc = TRUE;
> +  }
> +
>//
>// Source address is required when pinging a link-local address on multi-
>// interfaces host.
>//
>if (NetIp6IsLinkLocalAddr (>DstAddress) &&
> -  NetIp6IsUnspecifiedAddr (>SrcAddress) &&
> -  (HandleNum > 1)) {
> +  UnspecifiedSrc && (HandleNum > 1)) {
>  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> (STR_PING6_INVALID_SOURCE), gShellNetwork2HiiHandle);
>  Status = EFI_INVALID_PARAMETER;
>  goto ON_ERROR;
>}
> +
>//
>// For each ip6 protocol, check interface addresses list.
>//
>for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
> 
>  Ip6Sb  = NULL;
>  IfInfo = NULL;
>  IfInfoSize = 0;
> 
> +if (UnspecifiedSrc) {
> +  //
> +  // Check media.
> +  //
> +  NetLibDetectMedia (HandleBuffer[HandleIndex], );
> +  if (!MediaPresent) {
> +//
> +// Skip this one.
> +//
> +continue;
> +  }
> +}
> +
>  Status = gBS->HandleProtocol (
>  HandleBuffer[HandleIndex],
>  ,
>  (VOID **) 
>  );
>  if (EFI_ERROR (Status)) {
>goto ON_ERROR;
>  }
> 
> -if (NetIp6IsUnspecifiedAddr (>SrcAddress)) {
> -  //
> -  // No need to match interface address.
> -  //
> -  break;
> -} else {
> -  //
> -  // Ip6config protocol and ip6 service binding protocol are installed
> -  // on the same handle.
> -  //
> -  Status = gBS->HandleProtocol (
> -   

[edk2] [Patch] ShellPkg: Enhance ping6 to select the interface automatically

2016-04-21 Thread Jiaxin Wu
This patch is used to support no source IP specified case while
multiple NICs existed in the platform. The command will select the
first both connected and configured interface automatically.

Cc: Bhupesh Sharma 
Cc: Jaben Carsey 
Cc: Ye Ting 
Cc: Fu Siyuan 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu 
---
 .../Library/UefiShellNetwork2CommandsLib/Ping6.c   | 166 -
 1 file changed, 95 insertions(+), 71 deletions(-)

diff --git a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c 
b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
index af7d08f..f129612 100644
--- a/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
+++ b/ShellPkg/Library/UefiShellNetwork2CommandsLib/Ping6.c
@@ -661,22 +661,26 @@ Ping6CreateIpInstance (
 {
   EFI_STATUS   Status;
   UINTNHandleIndex;
   UINTNHandleNum;
   EFI_HANDLE   *HandleBuffer;
+  BOOLEAN  UnspecifiedSrc;
+  BOOLEAN  MediaPresent;
   EFI_SERVICE_BINDING_PROTOCOL *Ip6Sb;
   EFI_IP6_CONFIG_PROTOCOL  *Ip6Cfg;
   EFI_IP6_CONFIG_DATA  Ip6Config;
   EFI_IP6_CONFIG_INTERFACE_INFO*IfInfo;
   UINTNIfInfoSize;
   EFI_IPv6_ADDRESS *Addr;
   UINTNAddrIndex;
 
-  HandleBuffer = NULL;
-  Ip6Sb= NULL;
-  IfInfo   = NULL;
-  IfInfoSize   = 0;
+  HandleBuffer  = NULL;
+  UnspecifiedSrc= FALSE;
+  MediaPresent  = TRUE;
+  Ip6Sb = NULL;
+  IfInfo= NULL;
+  IfInfoSize= 0;
 
   //
   // Locate all the handles with ip6 service binding protocol.
   //
   Status = gBS->LocateHandleBuffer (
@@ -687,115 +691,135 @@ Ping6CreateIpInstance (
   
   );
   if (EFI_ERROR (Status) || (HandleNum == 0)) {
 return EFI_ABORTED;
   }
+
+  if (NetIp6IsUnspecifiedAddr (>SrcAddress)) {
+//
+// SrcAddress is unspecified. So, both connected and configured interface 
will be automatic selected. 
+//
+UnspecifiedSrc = TRUE;
+  }
+  
   //
   // Source address is required when pinging a link-local address on multi-
   // interfaces host.
   //
   if (NetIp6IsLinkLocalAddr (>DstAddress) &&
-  NetIp6IsUnspecifiedAddr (>SrcAddress) &&
-  (HandleNum > 1)) {
+  UnspecifiedSrc && (HandleNum > 1)) {
 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PING6_INVALID_SOURCE), 
gShellNetwork2HiiHandle);
 Status = EFI_INVALID_PARAMETER;
 goto ON_ERROR;
   }
+  
   //
   // For each ip6 protocol, check interface addresses list.
   //
   for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
 
 Ip6Sb  = NULL;
 IfInfo = NULL;
 IfInfoSize = 0;
 
+if (UnspecifiedSrc) {
+  //
+  // Check media.
+  //
+  NetLibDetectMedia (HandleBuffer[HandleIndex], );
+  if (!MediaPresent) {
+//
+// Skip this one.
+//
+continue;
+  }
+}
+
 Status = gBS->HandleProtocol (
 HandleBuffer[HandleIndex],
 ,
 (VOID **) 
 );
 if (EFI_ERROR (Status)) {
   goto ON_ERROR;
 }
 
-if (NetIp6IsUnspecifiedAddr (>SrcAddress)) {
-  //
-  // No need to match interface address.
-  //
-  break;
-} else {
-  //
-  // Ip6config protocol and ip6 service binding protocol are installed
-  // on the same handle.
-  //
-  Status = gBS->HandleProtocol (
-  HandleBuffer[HandleIndex],
-  ,
-  (VOID **) 
-  );
+//
+// Ip6config protocol and ip6 service binding protocol are installed
+// on the same handle.
+//
+Status = gBS->HandleProtocol (
+HandleBuffer[HandleIndex],
+,
+(VOID **) 
+);
 
-  if (EFI_ERROR (Status)) {
-goto ON_ERROR;
-  }
-  //
-  // Get the interface information size.
-  //
-  Status = Ip6Cfg->GetData (
- Ip6Cfg,
- Ip6ConfigDataTypeInterfaceInfo,
- ,
- NULL
- );
-
-  if (Status != EFI_BUFFER_TOO_SMALL) {
-ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN 
(STR_PING6_IP6CFG_GETDATA), gShellNetwork2HiiHandle, Status);
-goto ON_ERROR;
-  }
+if (EFI_ERROR (Status)) {
+  goto ON_ERROR;
+}
+//
+// Get the interface information size.
+//
+Status = Ip6Cfg->GetData (
+   Ip6Cfg,
+   Ip6ConfigDataTypeInterfaceInfo,
+   ,
+   NULL
+