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

2016-04-28 Thread Wu, Jiaxin
Siyuan,

I'm not prefer to handle the link local src address selecting automatically to 
make things more complexity. 

Just follow the guide that src address is required when pinging a link-local 
address no matter multiple or single interface in platform. But, I will update 
the patch to add a hint info this case. Do you agree?

Thanks for the comments.

Jiaxin





> -Original Message-
> From: Fu, Siyuan
> Sent: Thursday, April 28, 2016 11:03 AM
> To: Wu, Jiaxin ; edk2-devel@lists.01.org
> Cc: David Van Arnem ; Bhupesh Sharma
> ; Carsey, Jaben ; Ye,
> Ting 
> Subject: RE: [Patch] ShellPkg: Enhance ping to select the interface
> automatically
> 
> Hi, Jiaxin
> 
> A interface with only link local address should be allowed as the src if the 
> dest
> is also an link local address, right?
> 
> And the 2 if conditions in line 1052 is better to change to a "if 
> (UnspecifiedSrc)
> else ..." so it's more readable.
> 
> If (UnspecifiedSrc && !NetIp6IsUnspecifiedAddr (Addr)
> && !NetIp6IsLinkLocalAddr (Addr)){
> }
> if (!UnspecifiedSrc && EFI_IP6_EQUAL (>SrcAddress, Addr)) {
> }
> 
> Best Regards
> Siyuan
> 
> > -Original Message-
> > From: Wu, Jiaxin
> > Sent: Tuesday, April 19, 2016 9:52 AM
> > To: edk2-devel@lists.01.org
> > Cc: David Van Arnem ; Bhupesh Sharma
> > ; Carsey, Jaben ;
> Ye,
> > Ting ; Fu, Siyuan 
> > Subject: [Patch] ShellPkg: Enhance ping 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: David Van Arnem 
> > 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/UefiShellNetwork1CommandsLib/Ping.c| 224 -
> -
> > ---
> >  1 file changed, 127 insertions(+), 97 deletions(-)
> >
> > diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > index 13bcdde..6b05884 100644
> > --- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > +++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > @@ -874,20 +874,24 @@ PingCreateIpInstance (  {
> >EFI_STATUS   Status;
> >UINTNHandleIndex;
> >UINTNHandleNum;
> >EFI_HANDLE   *HandleBuffer;
> > +  BOOLEAN  UnspecifiedSrc;
> > +  BOOLEAN  MediaPresent;
> >EFI_SERVICE_BINDING_PROTOCOL *EfiSb;
> >VOID *IpXCfg;
> >EFI_IP6_CONFIG_DATA  Ip6Config;
> >EFI_IP4_CONFIG_DATA  Ip4Config;
> >VOID *IpXInterfaceInfo;
> >UINTNIfInfoSize;
> >EFI_IPv6_ADDRESS *Addr;
> >UINTNAddrIndex;
> >
> >HandleBuffer  = NULL;
> > +  UnspecifiedSrc= FALSE;
> > +  MediaPresent  = TRUE;
> >EfiSb = NULL;
> >IpXInterfaceInfo  = NULL;
> >IfInfoSize= 0;
> >
> >//
> > @@ -923,139 +927,165 @@ PingCreateIpInstance (
> >ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> > (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ping", mSrcString);
> >Status = EFI_INVALID_PARAMETER;
> >goto ON_ERROR;
> >  }
> >}
> > +
> > +  if (Private->IpChoice == PING_IP_CHOICE_IP6 ?
> > + NetIp6IsUnspecifiedAddr
> > ((EFI_IPv6_ADDRESS*)>SrcAddress) : \
> > +  PingNetIp4IsUnspecifiedAddr ((EFI_IPv4_ADDRESS*)
> > >SrcAddress)) {
> > +//
> > +// SrcAddress is unspecified. So, both connected and configured
> > + interface
> > will be automatic selected.
> > +//
> > +UnspecifiedSrc = TRUE;
> > +  }
> > +
> >//
> >// For each ip6 protocol, check interface addresses list.
> >//
> >for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
> > -
> >  EfiSb = NULL;
> >  IpXInterfaceInfo  = NULL;
> >  IfInfoSize= 0;
> >
> > +if (UnspecifiedSrc) {
> > +  //
> > +  // Check media.
> > +  //
> > +  NetLibDetectMedia (HandleBuffer[HandleIndex], );
> > +  if (!MediaPresent) {
> > +//
> > +// Skip this one.
> > +//
> > +continue;
> > +  }
> > +}
> > +
> >  Status = gBS->HandleProtocol (
> >  HandleBuffer[HandleIndex],
> >   

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

2016-04-27 Thread Fu, Siyuan
Hi, Jiaxin

A interface with only link local address should be allowed as the src if the 
dest is also an link local address, right?

And the 2 if conditions in line 1052 is better to change to a "if 
(UnspecifiedSrc) else ..." so it's more readable.

If (UnspecifiedSrc && !NetIp6IsUnspecifiedAddr (Addr) && 
!NetIp6IsLinkLocalAddr (Addr)){
}
if (!UnspecifiedSrc && EFI_IP6_EQUAL (>SrcAddress, Addr)) {
}

Best Regards
Siyuan

> -Original Message-
> From: Wu, Jiaxin
> Sent: Tuesday, April 19, 2016 9:52 AM
> To: edk2-devel@lists.01.org
> Cc: David Van Arnem ; Bhupesh Sharma
> ; Carsey, Jaben ; Ye,
> Ting ; Fu, Siyuan 
> Subject: [Patch] ShellPkg: Enhance ping 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: David Van Arnem 
> 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/UefiShellNetwork1CommandsLib/Ping.c| 224 --
> ---
>  1 file changed, 127 insertions(+), 97 deletions(-)
> 
> diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> index 13bcdde..6b05884 100644
> --- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> +++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> @@ -874,20 +874,24 @@ PingCreateIpInstance (
>  {
>EFI_STATUS   Status;
>UINTNHandleIndex;
>UINTNHandleNum;
>EFI_HANDLE   *HandleBuffer;
> +  BOOLEAN  UnspecifiedSrc;
> +  BOOLEAN  MediaPresent;
>EFI_SERVICE_BINDING_PROTOCOL *EfiSb;
>VOID *IpXCfg;
>EFI_IP6_CONFIG_DATA  Ip6Config;
>EFI_IP4_CONFIG_DATA  Ip4Config;
>VOID *IpXInterfaceInfo;
>UINTNIfInfoSize;
>EFI_IPv6_ADDRESS *Addr;
>UINTNAddrIndex;
> 
>HandleBuffer  = NULL;
> +  UnspecifiedSrc= FALSE;
> +  MediaPresent  = TRUE;
>EfiSb = NULL;
>IpXInterfaceInfo  = NULL;
>IfInfoSize= 0;
> 
>//
> @@ -923,139 +927,165 @@ PingCreateIpInstance (
>ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),
> gShellNetwork1HiiHandle, L"ping", mSrcString);
>Status = EFI_INVALID_PARAMETER;
>goto ON_ERROR;
>  }
>}
> +
> +  if (Private->IpChoice == PING_IP_CHOICE_IP6 ? NetIp6IsUnspecifiedAddr
> ((EFI_IPv6_ADDRESS*)>SrcAddress) : \
> +  PingNetIp4IsUnspecifiedAddr ((EFI_IPv4_ADDRESS*)
> >SrcAddress)) {
> +//
> +// SrcAddress is unspecified. So, both connected and configured interface
> will be automatic selected.
> +//
> +UnspecifiedSrc = TRUE;
> +  }
> +
>//
>// For each ip6 protocol, check interface addresses list.
>//
>for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
> -
>  EfiSb = NULL;
>  IpXInterfaceInfo  = NULL;
>  IfInfoSize= 0;
> 
> +if (UnspecifiedSrc) {
> +  //
> +  // Check media.
> +  //
> +  NetLibDetectMedia (HandleBuffer[HandleIndex], );
> +  if (!MediaPresent) {
> +//
> +// Skip this one.
> +//
> +continue;
> +  }
> +}
> +
>  Status = gBS->HandleProtocol (
>  HandleBuffer[HandleIndex],
>  Private->IpChoice ==
> PING_IP_CHOICE_IP6?:
> ndingProtocolGuid,
>  (VOID **) 
>  );
>  if (EFI_ERROR (Status)) {
>goto ON_ERROR;
>  }
> 
> -if (Private->IpChoice == PING_IP_CHOICE_IP6?NetIp6IsUnspecifiedAddr
> ((EFI_IPv6_ADDRESS*)>SrcAddress):PingNetIp4IsUnspecifiedAddr
> ((EFI_IPv4_ADDRESS*)>SrcAddress)) {
> -  //
> -  // No need to match interface address.
> -  //
> -  break;
> +//
> +// Ip6config protocol and ip6 service binding protocol are installed
> +// on the same handle.
> +//
> +Status = gBS->HandleProtocol (
> +HandleBuffer[HandleIndex],
> +Private->IpChoice ==
> PING_IP_CHOICE_IP6?:
> uid,
> +(VOID **) 
> +);
> +
> +if (EFI_ERROR (Status)) {
> +  goto ON_ERROR;
> +}
> +//
> +// Get the interface information size.
> +//
> +if (Private->IpChoice == PING_IP_CHOICE_IP6) {
> +  

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

2016-04-21 Thread Bhupesh Sharma
Hello Jiaxin,

Sorry for the delay in reply - I was on holidays.

I will check this patch at my end and will soon get back with the results.

Regards,
Bhupesh

> -Original Message-
> From: Wu, Jiaxin [mailto:jiaxin...@intel.com]
> Sent: Thursday, April 21, 2016 7:35 AM
> To: Bhupesh Sharma ; Carsey, Jaben
> ; edk2-devel@lists.01.org
> Cc: David Van Arnem ; Ye, Ting
> ; Fu, Siyuan 
> Subject: RE: [Patch] ShellPkg: Enhance ping to select the interface
> automatically
> 
> Hello Bhupesh,
> 
> Any test result or feedback for this patch?
> 
> Thanks.
> Jiaxin
> 
> > -Original Message-
> > From: Carsey, Jaben
> > Sent: Wednesday, April 20, 2016 1:10 AM
> > To: Wu, Jiaxin ; edk2-devel@lists.01.org
> > Cc: David Van Arnem ; Bhupesh Sharma
> > ; Ye, Ting ; Fu, Siyuan
> > ; Carsey, Jaben 
> > Subject: RE: [Patch] ShellPkg: Enhance ping to select the interface
> > automatically
> >
> > Reviewed-by: Jaben Carsey 
> >
> >
> >
> > > -Original Message-
> > > From: Wu, Jiaxin
> > > Sent: Monday, April 18, 2016 6:52 PM
> > > To: edk2-devel@lists.01.org
> > > Cc: David Van Arnem ; Bhupesh Sharma
> > > ; Carsey, Jaben ;
> > Ye,
> > > Ting ; Fu, Siyuan 
> > > Subject: [Patch] ShellPkg: Enhance ping to select the interface
> > > automatically
> > > Importance: High
> > >
> > > 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: David Van Arnem 
> > > 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/UefiShellNetwork1CommandsLib/Ping.c| 224
> -
> > ---
> > > -
> > >  1 file changed, 127 insertions(+), 97 deletions(-)
> > >
> > > diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > > index 13bcdde..6b05884 100644
> > > --- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > > +++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > > @@ -874,20 +874,24 @@ PingCreateIpInstance (  {
> > >EFI_STATUS   Status;
> > >UINTNHandleIndex;
> > >UINTNHandleNum;
> > >EFI_HANDLE   *HandleBuffer;
> > > +  BOOLEAN  UnspecifiedSrc;
> > > +  BOOLEAN  MediaPresent;
> > >EFI_SERVICE_BINDING_PROTOCOL *EfiSb;
> > >VOID *IpXCfg;
> > >EFI_IP6_CONFIG_DATA  Ip6Config;
> > >EFI_IP4_CONFIG_DATA  Ip4Config;
> > >VOID *IpXInterfaceInfo;
> > >UINTNIfInfoSize;
> > >EFI_IPv6_ADDRESS *Addr;
> > >UINTNAddrIndex;
> > >
> > >HandleBuffer  = NULL;
> > > +  UnspecifiedSrc= FALSE;
> > > +  MediaPresent  = TRUE;
> > >EfiSb = NULL;
> > >IpXInterfaceInfo  = NULL;
> > >IfInfoSize= 0;
> > >
> > >//
> > > @@ -923,139 +927,165 @@ PingCreateIpInstance (
> > >ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> > > (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ping", mSrcString);
> > >Status = EFI_INVALID_PARAMETER;
> > >goto ON_ERROR;
> > >  }
> > >}
> > > +
> > > +  if (Private->IpChoice == PING_IP_CHOICE_IP6 ?
> > > + NetIp6IsUnspecifiedAddr
> > > ((EFI_IPv6_ADDRESS*)>SrcAddress) : \
> > > +  PingNetIp4IsUnspecifiedAddr ((EFI_IPv4_ADDRESS*)
> > > >SrcAddress)) {
> > > +//
> > > +// SrcAddress is unspecified. So, both connected and
> configured
> > > + interface
> > > will be automatic selected.
> > > +//
> > > +UnspecifiedSrc = TRUE;
> > > +  }
> > > +
> > >//
> > >// For each ip6 protocol, check interface addresses list.
> > >//
> > >for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
> > > -
> > >  EfiSb = NULL;
> > >  IpXInterfaceInfo  = NULL;
> > >  IfInfoSize= 0;
> > >
> > > +if (UnspecifiedSrc) {
> > > +  //
> > > +  // Check media.
> > > +  //
> > > +  NetLibDetectMedia (HandleBuffer[HandleIndex],
> );
> > > +  if (!MediaPresent) {
> > > +//
> > > +// Skip this one.
> > > +//
> 

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

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

Any test result or feedback for this patch? 

Thanks.
Jiaxin

> -Original Message-
> From: Carsey, Jaben
> Sent: Wednesday, April 20, 2016 1:10 AM
> To: Wu, Jiaxin ; edk2-devel@lists.01.org
> Cc: David Van Arnem ; Bhupesh Sharma
> ; Ye, Ting ; Fu, Siyuan
> ; Carsey, Jaben 
> Subject: RE: [Patch] ShellPkg: Enhance ping to select the interface
> automatically
> 
> Reviewed-by: Jaben Carsey 
> 
> 
> 
> > -Original Message-
> > From: Wu, Jiaxin
> > Sent: Monday, April 18, 2016 6:52 PM
> > To: edk2-devel@lists.01.org
> > Cc: David Van Arnem ; Bhupesh Sharma
> > ; Carsey, Jaben ;
> Ye,
> > Ting ; Fu, Siyuan 
> > Subject: [Patch] ShellPkg: Enhance ping to select the interface
> > automatically
> > Importance: High
> >
> > 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: David Van Arnem 
> > 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/UefiShellNetwork1CommandsLib/Ping.c| 224 -
> ---
> > -
> >  1 file changed, 127 insertions(+), 97 deletions(-)
> >
> > diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > index 13bcdde..6b05884 100644
> > --- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > +++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> > @@ -874,20 +874,24 @@ PingCreateIpInstance (  {
> >EFI_STATUS   Status;
> >UINTNHandleIndex;
> >UINTNHandleNum;
> >EFI_HANDLE   *HandleBuffer;
> > +  BOOLEAN  UnspecifiedSrc;
> > +  BOOLEAN  MediaPresent;
> >EFI_SERVICE_BINDING_PROTOCOL *EfiSb;
> >VOID *IpXCfg;
> >EFI_IP6_CONFIG_DATA  Ip6Config;
> >EFI_IP4_CONFIG_DATA  Ip4Config;
> >VOID *IpXInterfaceInfo;
> >UINTNIfInfoSize;
> >EFI_IPv6_ADDRESS *Addr;
> >UINTNAddrIndex;
> >
> >HandleBuffer  = NULL;
> > +  UnspecifiedSrc= FALSE;
> > +  MediaPresent  = TRUE;
> >EfiSb = NULL;
> >IpXInterfaceInfo  = NULL;
> >IfInfoSize= 0;
> >
> >//
> > @@ -923,139 +927,165 @@ PingCreateIpInstance (
> >ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN
> > (STR_GEN_PARAM_INV), gShellNetwork1HiiHandle, L"ping", mSrcString);
> >Status = EFI_INVALID_PARAMETER;
> >goto ON_ERROR;
> >  }
> >}
> > +
> > +  if (Private->IpChoice == PING_IP_CHOICE_IP6 ?
> > + NetIp6IsUnspecifiedAddr
> > ((EFI_IPv6_ADDRESS*)>SrcAddress) : \
> > +  PingNetIp4IsUnspecifiedAddr ((EFI_IPv4_ADDRESS*)
> > >SrcAddress)) {
> > +//
> > +// SrcAddress is unspecified. So, both connected and configured
> > + interface
> > will be automatic selected.
> > +//
> > +UnspecifiedSrc = TRUE;
> > +  }
> > +
> >//
> >// For each ip6 protocol, check interface addresses list.
> >//
> >for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
> > -
> >  EfiSb = NULL;
> >  IpXInterfaceInfo  = NULL;
> >  IfInfoSize= 0;
> >
> > +if (UnspecifiedSrc) {
> > +  //
> > +  // Check media.
> > +  //
> > +  NetLibDetectMedia (HandleBuffer[HandleIndex], );
> > +  if (!MediaPresent) {
> > +//
> > +// Skip this one.
> > +//
> > +continue;
> > +  }
> > +}
> > +
> >  Status = gBS->HandleProtocol (
> >  HandleBuffer[HandleIndex],
> >  Private->IpChoice ==
> >
> PING_IP_CHOICE_IP6?:
> > i
> > ndingProtocolGuid,
> >  (VOID **) 
> >  );
> >  if (EFI_ERROR (Status)) {
> >goto ON_ERROR;
> >  }
> >
> > -if (Private->IpChoice == PING_IP_CHOICE_IP6?NetIp6IsUnspecifiedAddr
> > ((EFI_IPv6_ADDRESS*)
> >SrcAddress):PingNetIp4IsUnspecifiedAddr
> > ((EFI_IPv4_ADDRESS*)>SrcAddress)) {
> > -  //
> > -  // No need to match interface address.
> > -  //
> > -  break;
> > +//
> > +// Ip6config protocol and ip6 service binding protocol are installed
> > +// on the same handle.
> > +//
> > +Status = 

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

2016-04-19 Thread Carsey, Jaben
Reviewed-by: Jaben Carsey 



> -Original Message-
> From: Wu, Jiaxin
> Sent: Monday, April 18, 2016 6:52 PM
> To: edk2-devel@lists.01.org
> Cc: David Van Arnem ; Bhupesh Sharma
> ; Carsey, Jaben ; Ye,
> Ting ; Fu, Siyuan 
> Subject: [Patch] ShellPkg: Enhance ping to select the interface automatically
> Importance: High
> 
> 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: David Van Arnem 
> 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/UefiShellNetwork1CommandsLib/Ping.c| 224 
> -
>  1 file changed, 127 insertions(+), 97 deletions(-)
> 
> diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> index 13bcdde..6b05884 100644
> --- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> +++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
> @@ -874,20 +874,24 @@ PingCreateIpInstance (
>  {
>EFI_STATUS   Status;
>UINTNHandleIndex;
>UINTNHandleNum;
>EFI_HANDLE   *HandleBuffer;
> +  BOOLEAN  UnspecifiedSrc;
> +  BOOLEAN  MediaPresent;
>EFI_SERVICE_BINDING_PROTOCOL *EfiSb;
>VOID *IpXCfg;
>EFI_IP6_CONFIG_DATA  Ip6Config;
>EFI_IP4_CONFIG_DATA  Ip4Config;
>VOID *IpXInterfaceInfo;
>UINTNIfInfoSize;
>EFI_IPv6_ADDRESS *Addr;
>UINTNAddrIndex;
> 
>HandleBuffer  = NULL;
> +  UnspecifiedSrc= FALSE;
> +  MediaPresent  = TRUE;
>EfiSb = NULL;
>IpXInterfaceInfo  = NULL;
>IfInfoSize= 0;
> 
>//
> @@ -923,139 +927,165 @@ PingCreateIpInstance (
>ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),
> gShellNetwork1HiiHandle, L"ping", mSrcString);
>Status = EFI_INVALID_PARAMETER;
>goto ON_ERROR;
>  }
>}
> +
> +  if (Private->IpChoice == PING_IP_CHOICE_IP6 ? NetIp6IsUnspecifiedAddr
> ((EFI_IPv6_ADDRESS*)>SrcAddress) : \
> +  PingNetIp4IsUnspecifiedAddr ((EFI_IPv4_ADDRESS*)
> >SrcAddress)) {
> +//
> +// SrcAddress is unspecified. So, both connected and configured interface
> will be automatic selected.
> +//
> +UnspecifiedSrc = TRUE;
> +  }
> +
>//
>// For each ip6 protocol, check interface addresses list.
>//
>for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
> -
>  EfiSb = NULL;
>  IpXInterfaceInfo  = NULL;
>  IfInfoSize= 0;
> 
> +if (UnspecifiedSrc) {
> +  //
> +  // Check media.
> +  //
> +  NetLibDetectMedia (HandleBuffer[HandleIndex], );
> +  if (!MediaPresent) {
> +//
> +// Skip this one.
> +//
> +continue;
> +  }
> +}
> +
>  Status = gBS->HandleProtocol (
>  HandleBuffer[HandleIndex],
>  Private->IpChoice ==
> PING_IP_CHOICE_IP6?:
> ndingProtocolGuid,
>  (VOID **) 
>  );
>  if (EFI_ERROR (Status)) {
>goto ON_ERROR;
>  }
> 
> -if (Private->IpChoice == PING_IP_CHOICE_IP6?NetIp6IsUnspecifiedAddr
> ((EFI_IPv6_ADDRESS*)>SrcAddress):PingNetIp4IsUnspecifiedAddr
> ((EFI_IPv4_ADDRESS*)>SrcAddress)) {
> -  //
> -  // No need to match interface address.
> -  //
> -  break;
> +//
> +// Ip6config protocol and ip6 service binding protocol are installed
> +// on the same handle.
> +//
> +Status = gBS->HandleProtocol (
> +HandleBuffer[HandleIndex],
> +Private->IpChoice ==
> PING_IP_CHOICE_IP6?:
> id,
> +(VOID **) 
> +);
> +
> +if (EFI_ERROR (Status)) {
> +  goto ON_ERROR;
> +}
> +//
> +// Get the interface information size.
> +//
> +if (Private->IpChoice == PING_IP_CHOICE_IP6) {
> +  Status = ((EFI_IP6_CONFIG_PROTOCOL*)IpXCfg)->GetData (
> + IpXCfg,
> + Ip6ConfigDataTypeInterfaceInfo,
> + ,
> + NULL
> + );
>  } else {
> -  //
> -  // Ip6config protocol and ip6 service binding protocol are installed
> -  // on the same handle.
> -

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

2016-04-18 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: David Van Arnem 
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/UefiShellNetwork1CommandsLib/Ping.c| 224 -
 1 file changed, 127 insertions(+), 97 deletions(-)

diff --git a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c 
b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
index 13bcdde..6b05884 100644
--- a/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
+++ b/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c
@@ -874,20 +874,24 @@ PingCreateIpInstance (
 {
   EFI_STATUS   Status;
   UINTNHandleIndex;
   UINTNHandleNum;
   EFI_HANDLE   *HandleBuffer;
+  BOOLEAN  UnspecifiedSrc;
+  BOOLEAN  MediaPresent;
   EFI_SERVICE_BINDING_PROTOCOL *EfiSb;
   VOID *IpXCfg;
   EFI_IP6_CONFIG_DATA  Ip6Config;
   EFI_IP4_CONFIG_DATA  Ip4Config;
   VOID *IpXInterfaceInfo;
   UINTNIfInfoSize;
   EFI_IPv6_ADDRESS *Addr;
   UINTNAddrIndex;
 
   HandleBuffer  = NULL;
+  UnspecifiedSrc= FALSE;
+  MediaPresent  = TRUE;
   EfiSb = NULL;
   IpXInterfaceInfo  = NULL;
   IfInfoSize= 0;
 
   //
@@ -923,139 +927,165 @@ PingCreateIpInstance (
   ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), 
gShellNetwork1HiiHandle, L"ping", mSrcString);  
   Status = EFI_INVALID_PARAMETER;
   goto ON_ERROR;
 }
   }
+
+  if (Private->IpChoice == PING_IP_CHOICE_IP6 ? NetIp6IsUnspecifiedAddr 
((EFI_IPv6_ADDRESS*)>SrcAddress) : \
+  PingNetIp4IsUnspecifiedAddr ((EFI_IPv4_ADDRESS*)>SrcAddress)) {
+//
+// SrcAddress is unspecified. So, both connected and configured interface 
will be automatic selected. 
+//
+UnspecifiedSrc = TRUE;
+  }
+  
   //
   // For each ip6 protocol, check interface addresses list.
   //
   for (HandleIndex = 0; HandleIndex < HandleNum; HandleIndex++) {
-
 EfiSb = NULL;
 IpXInterfaceInfo  = NULL;
 IfInfoSize= 0;
 
+if (UnspecifiedSrc) {
+  //
+  // Check media.
+  //
+  NetLibDetectMedia (HandleBuffer[HandleIndex], );
+  if (!MediaPresent) {
+//
+// Skip this one.
+//
+continue;
+  }
+}
+
 Status = gBS->HandleProtocol (
 HandleBuffer[HandleIndex],
 Private->IpChoice == 
PING_IP_CHOICE_IP6?:,
 (VOID **) 
 );
 if (EFI_ERROR (Status)) {
   goto ON_ERROR;
 }
 
-if (Private->IpChoice == PING_IP_CHOICE_IP6?NetIp6IsUnspecifiedAddr 
((EFI_IPv6_ADDRESS*)>SrcAddress):PingNetIp4IsUnspecifiedAddr 
((EFI_IPv4_ADDRESS*)>SrcAddress)) {
-  //
-  // No need to match interface address.
-  //
-  break;
+//
+// Ip6config protocol and ip6 service binding protocol are installed
+// on the same handle.
+//
+Status = gBS->HandleProtocol (
+HandleBuffer[HandleIndex],
+Private->IpChoice == 
PING_IP_CHOICE_IP6?:,
+(VOID **) 
+);
+
+if (EFI_ERROR (Status)) {
+  goto ON_ERROR;
+}
+//
+// Get the interface information size.
+//
+if (Private->IpChoice == PING_IP_CHOICE_IP6) {
+  Status = ((EFI_IP6_CONFIG_PROTOCOL*)IpXCfg)->GetData (
+ IpXCfg,
+ Ip6ConfigDataTypeInterfaceInfo,
+ ,
+ NULL
+ );
 } else {
-  //
-  // Ip6config protocol and ip6 service binding protocol are installed
-  // on the same handle.
-  //
-  Status = gBS->HandleProtocol (
-  HandleBuffer[HandleIndex],
-  Private->IpChoice == 
PING_IP_CHOICE_IP6?:,
-  (VOID **) 
-  );
+  Status = ((EFI_IP4_CONFIG2_PROTOCOL*)IpXCfg)->GetData (
+ IpXCfg,
+ Ip4Config2DataTypeInterfaceInfo,
+ ,
+ NULL
+ );
+}
+
+//
+// Skip the ones not in current use.
+//
+if (Status == EFI_NOT_STARTED) {
+  continue;
+}
 
-  if (EFI_ERROR (Status)) {
-goto ON_ERROR;
-  }
-  //
-  // Get the interface information size.
-  //
-  if