public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch v2 0/2] Add IPv6 support condition check.
@ 2017-10-18  6:57 Jiaxin Wu
  2017-10-18  6:57 ` [Patch v2 1/2] NetworkPkg/HttpBootDxe: " Jiaxin Wu
  2017-10-18  6:57 ` [Patch v2 2/2] NetworkPkg/IScsiDxe: " Jiaxin Wu
  0 siblings, 2 replies; 3+ messages in thread
From: Jiaxin Wu @ 2017-10-18  6:57 UTC (permalink / raw)
  To: edk2-devel; +Cc: Karunakar P, Ye Ting, Fu Siyuan, Wu Jiaxin

Base on the request of https://bugzilla.tianocore.org/show_bug.cgi?id=710,
we provide this patch to IPv6 condition check by leveraging AIP Protocol.

Cc: Karunakar P <karunakarp@amiindia.co.in>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Karunakar P <karunakarp@amiindia.co.in>
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>

Jiaxin Wu (2):
  NetworkPkg/HttpBootDxe: Add IPv6 support condition check.
  NetworkPkg/IScsiDxe: Add IPv6 support condition check.

 NetworkPkg/HttpBootDxe/HttpBootDxe.c   | 161 +++++++++++++++++++++++++++++++--
 NetworkPkg/HttpBootDxe/HttpBootDxe.h   |   2 +
 NetworkPkg/HttpBootDxe/HttpBootDxe.inf |   4 +-
 NetworkPkg/IScsiDxe/IScsiConfig.c      |  18 ++++
 NetworkPkg/IScsiDxe/IScsiDriver.c      |   2 +-
 NetworkPkg/IScsiDxe/IScsiDriver.h      |   1 +
 NetworkPkg/IScsiDxe/IScsiDxe.inf       |   2 +
 NetworkPkg/IScsiDxe/IScsiImpl.h        |   1 +
 NetworkPkg/IScsiDxe/IScsiMisc.c        | 135 ++++++++++++++++++++++++++-
 NetworkPkg/IScsiDxe/IScsiMisc.h        |   4 +-
 10 files changed, 316 insertions(+), 14 deletions(-)

-- 
1.9.5.msysgit.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Patch v2 1/2] NetworkPkg/HttpBootDxe: Add IPv6 support condition check.
  2017-10-18  6:57 [Patch v2 0/2] Add IPv6 support condition check Jiaxin Wu
@ 2017-10-18  6:57 ` Jiaxin Wu
  2017-10-18  6:57 ` [Patch v2 2/2] NetworkPkg/IScsiDxe: " Jiaxin Wu
  1 sibling, 0 replies; 3+ messages in thread
From: Jiaxin Wu @ 2017-10-18  6:57 UTC (permalink / raw)
  To: edk2-devel; +Cc: Karunakar P, Ye Ting, Fu Siyuan, Wu Jiaxin

v2:
* Fix the ASSERT issue.

Base on the request of https://bugzilla.tianocore.org/show_bug.cgi?id=710,
we provide this patch to IPv6 condition check by leveraging AIP Protocol.

Cc: Karunakar P <karunakarp@amiindia.co.in>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Karunakar P <karunakarp@amiindia.co.in>
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/HttpBootDxe/HttpBootDxe.c   | 161 +++++++++++++++++++++++++++++++--
 NetworkPkg/HttpBootDxe/HttpBootDxe.h   |   2 +
 NetworkPkg/HttpBootDxe/HttpBootDxe.inf |   4 +-
 3 files changed, 157 insertions(+), 10 deletions(-)

diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.c b/NetworkPkg/HttpBootDxe/HttpBootDxe.c
index 642e0fe..b1f9042 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDxe.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.c
@@ -1,9 +1,9 @@
 /** @file
   Driver Binding functions implementation for UEFI HTTP boot.
 
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials are licensed and made available under 
 the terms and conditions of the BSD License that accompanies this distribution.  
 The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php.                                          
     
@@ -33,10 +33,104 @@ EFI_DRIVER_BINDING_PROTOCOL gHttpBootIp6DxeDriverBinding = {
   HTTP_BOOT_DXE_VERSION,
   NULL,
   NULL
 };
 
+
+
+/**
+  Check whether UNDI protocol supports IPv6.
+
+  @param[in]   Private           Pointer to HTTP_BOOT_PRIVATE_DATA.
+  @param[out]  Ipv6Support       TRUE if UNDI supports IPv6.
+
+  @retval EFI_SUCCESS            Get the result whether UNDI supports IPv6 by NII or AIP protocol successfully.
+  @retval EFI_NOT_FOUND          Don't know whether UNDI supports IPv6 since NII or AIP is not available.
+
+**/
+EFI_STATUS
+HttpBootCheckIpv6Support (
+  IN  HTTP_BOOT_PRIVATE_DATA       *Private,
+  OUT BOOLEAN                      *Ipv6Support
+  )
+{
+  EFI_HANDLE                       Handle;
+  EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;
+  EFI_STATUS                       Status;
+  EFI_GUID                         *InfoTypesBuffer;
+  UINTN                            InfoTypeBufferCount;
+  UINTN                            TypeIndex;
+  BOOLEAN                          Supported;
+  VOID                             *InfoBlock;
+  UINTN                            InfoBlockSize;
+
+  ASSERT (Private != NULL && Ipv6Support != NULL);
+
+  //
+  // Check whether the UNDI supports IPv6 by NII protocol.
+  //
+  if (Private->Nii != NULL) {
+    *Ipv6Support = Private->Nii->Ipv6Supported;
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Get the NIC handle by SNP protocol.
+  //  
+  Handle = NetLibGetSnpHandle (Private->Controller, NULL);
+  if (Handle == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  Aip    = NULL;
+  Status = gBS->HandleProtocol (
+                  Handle,
+                  &gEfiAdapterInformationProtocolGuid,
+                  (VOID *) &Aip
+                  );
+  if (EFI_ERROR (Status) || Aip == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  InfoTypesBuffer     = NULL;
+  InfoTypeBufferCount = 0;
+  Status = Aip->GetSupportedTypes (Aip, &InfoTypesBuffer, &InfoTypeBufferCount);
+  if (EFI_ERROR (Status) || InfoTypesBuffer == NULL) {
+    FreePool (InfoTypesBuffer);
+    return EFI_NOT_FOUND;
+  }
+
+  Supported = FALSE;
+  for (TypeIndex = 0; TypeIndex < InfoTypeBufferCount; TypeIndex++) {
+    if (CompareGuid (&InfoTypesBuffer[TypeIndex], &gEfiAdapterInfoUndiIpv6SupportGuid)) {
+      Supported = TRUE;
+      break;
+    }
+  }
+
+  FreePool (InfoTypesBuffer);
+  if (!Supported) {
+    return EFI_NOT_FOUND;
+  }
+
+  //
+  // We now have adapter information block.
+  //
+  InfoBlock     = NULL;
+  InfoBlockSize = 0;
+  Status = Aip->GetInformation (Aip, &gEfiAdapterInfoUndiIpv6SupportGuid, &InfoBlock, &InfoBlockSize);
+  if (EFI_ERROR (Status) || InfoBlock == NULL) {
+    FreePool (InfoBlock);
+    return EFI_NOT_FOUND;
+  }  
+
+  *Ipv6Support = ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT *) InfoBlock)->Ipv6Support;
+  FreePool (InfoBlock);
+  
+  return EFI_SUCCESS;
+}
+
 /**
   Destroy the HTTP child based on IPv4 stack.
 
   @param[in]  This              Pointer to the EFI_DRIVER_BINDING_PROTOCOL.
   @param[in]  Private           Pointer to HTTP_BOOT_PRIVATE_DATA.
@@ -65,11 +159,11 @@ HttpBootDestroyIp4Children (
       &gEfiDhcp4ServiceBindingProtocolGuid,
       Private->Dhcp4Child
       );
   }
 
-  if (Private->HttpCreated) {
+  if (Private->Ip6Nic == NULL && Private->HttpCreated) {
     HttpIoDestroyIo (&Private->HttpIo);
     Private->HttpCreated = FALSE;
   }
 
   if (Private->Ip4Nic != NULL) {
@@ -141,11 +235,11 @@ HttpBootDestroyIp6Children (
       &gEfiDhcp6ServiceBindingProtocolGuid,
       Private->Dhcp6Child
       );
   }
 
-  if (Private->HttpCreated) {
+  if (Private->Ip4Nic == NULL && Private->HttpCreated) {
     HttpIoDestroyIo(&Private->HttpIo);
     Private->HttpCreated = FALSE;
   }
   
   if (Private->Ip6Nic != NULL) {
@@ -308,10 +402,13 @@ HttpBootIp4DxeDriverBindingStart (
   EFI_STATUS                 Status;
   HTTP_BOOT_PRIVATE_DATA     *Private;
   EFI_DEV_PATH               *Node;
   EFI_DEVICE_PATH_PROTOCOL   *DevicePath;
   UINT32                     *Id;
+  BOOLEAN                    FirstStart;
+
+  FirstStart = FALSE;
 
   Status = gBS->OpenProtocol (
                   ControllerHandle,
                   &gEfiCallerIdGuid,
                   (VOID **) &Id,
@@ -321,10 +418,12 @@ HttpBootIp4DxeDriverBindingStart (
                   );
 
   if (!EFI_ERROR (Status)) {
     Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id);
   } else {
+    FirstStart = TRUE;
+  
     //
     // Initialize the private data structure.
     //
     Private = AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA));
     if (Private == NULL) {
@@ -394,11 +493,12 @@ HttpBootIp4DxeDriverBindingStart (
     return EFI_SUCCESS;
   }
   
   Private->Ip4Nic = AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC));
   if (Private->Ip4Nic == NULL) {
-    return EFI_OUT_OF_RESOURCES;
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ON_ERROR;
   }
   Private->Ip4Nic->Private     = Private;
   Private->Ip4Nic->ImageHandle = This->DriverBindingHandle;
   Private->Ip4Nic->Signature   = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;
   
@@ -511,17 +611,26 @@ HttpBootIp4DxeDriverBindingStart (
   if (EFI_ERROR (Status)) {
     goto ON_ERROR;
   }
   
   return EFI_SUCCESS;
-
     
 ON_ERROR:
-
+  if (FirstStart) {
+    gBS->UninstallProtocolInterface (
+           ControllerHandle,
+           &gEfiCallerIdGuid,
+           &Private->Id
+           );
+  }
+  
   HttpBootDestroyIp4Children (This, Private);
   HttpBootConfigFormUnload (Private);
-  FreePool (Private);
+
+  if (FirstStart && Private != NULL) {
+    FreePool (Private);
+  }
 
   return Status;
 }
 
 
@@ -780,10 +889,14 @@ HttpBootIp6DxeDriverBindingStart (
   EFI_STATUS                 Status;
   HTTP_BOOT_PRIVATE_DATA     *Private;
   EFI_DEV_PATH               *Node;
   EFI_DEVICE_PATH_PROTOCOL   *DevicePath;
   UINT32                     *Id;
+  BOOLEAN                    Ipv6Available;
+  BOOLEAN                    FirstStart;
+
+  FirstStart = FALSE;
   
   Status = gBS->OpenProtocol (
                   ControllerHandle,
                   &gEfiCallerIdGuid,
                   (VOID **) &Id,
@@ -793,10 +906,12 @@ HttpBootIp6DxeDriverBindingStart (
                   );
   
   if (!EFI_ERROR (Status)) {
     Private = HTTP_BOOT_PRIVATE_DATA_FROM_ID(Id);
   } else {
+    FirstStart = TRUE;
+    
     //
     // Initialize the private data structure.
     //
     Private = AllocateZeroPool (sizeof (HTTP_BOOT_PRIVATE_DATA));
     if (Private == NULL) {
@@ -856,21 +971,39 @@ HttpBootIp6DxeDriverBindingStart (
     if (EFI_ERROR (Status)) {
       goto ON_ERROR;
     }
       
   }
+
+  //
+  // Set IPv6 available flag.
+  // 
+  Status = HttpBootCheckIpv6Support (Private, &Ipv6Available);
+  if (EFI_ERROR (Status)) {
+    //
+    // Fail to get the data whether UNDI supports IPv6. 
+    // Set default value to TRUE.
+    //
+    Ipv6Available = TRUE;
+  }
+
+  if (!Ipv6Available) {
+    Status = EFI_UNSUPPORTED;
+    goto ON_ERROR;
+  }
   
   if (Private->Ip6Nic != NULL) {
     //
     // Already created before
     //
     return EFI_SUCCESS;
   }
   
   Private->Ip6Nic = AllocateZeroPool (sizeof (HTTP_BOOT_VIRTUAL_NIC));
   if (Private->Ip6Nic == NULL) {
-    return EFI_OUT_OF_RESOURCES;
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ON_ERROR;
   }
   Private->Ip6Nic->Private     = Private;
   Private->Ip6Nic->ImageHandle = This->DriverBindingHandle;
   Private->Ip6Nic->Signature   = HTTP_BOOT_VIRTUAL_NIC_SIGNATURE;
   
@@ -1009,14 +1142,24 @@ HttpBootIp6DxeDriverBindingStart (
   }
 
   return EFI_SUCCESS;
    
 ON_ERROR:
+  if (FirstStart) {
+    gBS->UninstallProtocolInterface (
+           ControllerHandle,
+           &gEfiCallerIdGuid,
+           &Private->Id
+           );
+  }
 
   HttpBootDestroyIp6Children(This, Private);
   HttpBootConfigFormUnload (Private);
-  FreePool (Private);
+
+  if (FirstStart && Private != NULL) {
+    FreePool (Private);
+  }
 
   return Status;
 }
 
 /**
diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
index 2c07cf7..166bc45 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDxe.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
@@ -56,10 +56,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/Dns6.h>
 #include <Protocol/Http.h>
 #include <Protocol/Ip4Config2.h>
 #include <Protocol/Ip6Config.h>
 #include <Protocol/RamDisk.h>
+#include <Protocol/AdapterInformation.h>
+
 //
 // Produced Protocols
 //
 #include <Protocol/LoadFile.h>
 #include <Protocol/HttpBootCallback.h>
diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.inf b/NetworkPkg/HttpBootDxe/HttpBootDxe.inf
index 4d6c5e5..6d2a772 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDxe.inf
+++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.inf
@@ -84,19 +84,21 @@
   gEfiIp6ConfigProtocolGuid                       ## TO_START
   gEfiNetworkInterfaceIdentifierProtocolGuid_31   ## SOMETIMES_CONSUMES
   gEfiRamDiskProtocolGuid                         ## SOMETIMES_CONSUMES
   gEfiHiiConfigAccessProtocolGuid                 ## BY_START
   gEfiHttpBootCallbackProtocolGuid                ## SOMETIMES_PRODUCES
-  
+  gEfiAdapterInformationProtocolGuid              ## SOMETIMES_CONSUMES
+
 [Guids]
   ## SOMETIMES_CONSUMES ## GUID # HiiIsConfigHdrMatch   mHttpBootConfigStorageName
   ## SOMETIMES_PRODUCES ## GUID # HiiConstructConfigHdr mHttpBootConfigStorageName
   ## SOMETIMES_PRODUCES ## GUID # HiiGetBrowserData     mHttpBootConfigStorageName
   ## SOMETIMES_CONSUMES ## HII
   gHttpBootConfigGuid
   gEfiVirtualCdGuid            ## SOMETIMES_CONSUMES ## GUID
   gEfiVirtualDiskGuid          ## SOMETIMES_CONSUMES ## GUID
+  gEfiAdapterInfoUndiIpv6SupportGuid             ## SOMETIMES_CONSUMES ## GUID
 
 [Pcd]
   gEfiNetworkPkgTokenSpaceGuid.PcdAllowHttpConnections       ## CONSUMES  
 
 [UserExtensions.TianoCore."ExtraFiles"]
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Patch v2 2/2] NetworkPkg/IScsiDxe: Add IPv6 support condition check.
  2017-10-18  6:57 [Patch v2 0/2] Add IPv6 support condition check Jiaxin Wu
  2017-10-18  6:57 ` [Patch v2 1/2] NetworkPkg/HttpBootDxe: " Jiaxin Wu
@ 2017-10-18  6:57 ` Jiaxin Wu
  1 sibling, 0 replies; 3+ messages in thread
From: Jiaxin Wu @ 2017-10-18  6:57 UTC (permalink / raw)
  To: edk2-devel; +Cc: Karunakar P, Ye Ting, Fu Siyuan, Wu Jiaxin

Base on the request of https://bugzilla.tianocore.org/show_bug.cgi?id=710,
we provide this patch to IPv6 condition check by leveraging AIP Protocol.

Cc: Karunakar P <karunakarp@amiindia.co.in>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Karunakar P <karunakarp@amiindia.co.in>
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/IScsiDxe/IScsiConfig.c |  18 +++++
 NetworkPkg/IScsiDxe/IScsiDriver.c |   2 +-
 NetworkPkg/IScsiDxe/IScsiDriver.h |   1 +
 NetworkPkg/IScsiDxe/IScsiDxe.inf  |   2 +
 NetworkPkg/IScsiDxe/IScsiImpl.h   |   1 +
 NetworkPkg/IScsiDxe/IScsiMisc.c   | 135 +++++++++++++++++++++++++++++++++++++-
 NetworkPkg/IScsiDxe/IScsiMisc.h   |   4 +-
 7 files changed, 159 insertions(+), 4 deletions(-)

diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c b/NetworkPkg/IScsiDxe/IScsiConfig.c
index f20f590..3ce37c5 100644
--- a/NetworkPkg/IScsiDxe/IScsiConfig.c
+++ b/NetworkPkg/IScsiDxe/IScsiConfig.c
@@ -3419,10 +3419,13 @@ IScsiFormCallback (
   EFI_IP_ADDRESS              Gateway;
   ISCSI_CONFIG_IFR_NVDATA     *IfrNvData;
   ISCSI_CONFIG_IFR_NVDATA     OldIfrNvData;
   EFI_STATUS                  Status;
   EFI_INPUT_KEY               Key;
+  ISCSI_NIC_INFO              *NicInfo;
+
+  NicInfo = NULL;
 
   if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {
     //
     // Do nothing for UEFI OPEN/CLOSE Action
     //
@@ -3589,10 +3592,25 @@ IScsiFormCallback (
       break;
 
     case KEY_IP_MODE:
       switch (Value->u8) {
       case IP_MODE_IP6:
+        NicInfo = IScsiGetNicInfoByIndex (Private->Current->NicIndex); 
+        if(!NicInfo->Ipv6Available) {			
+  	      //
+          // Current NIC doesn't Support IPv6, hence use IPv4.    
+          //    
+          IfrNvData->IpMode = IP_MODE_IP4;
+  		
+          CreatePopUp (
+            EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+            &Key,
+            L"Current NIC doesn't Support IPv6!",
+            NULL
+            );
+        }
+	  
       case IP_MODE_IP4:
         ZeroMem (IfrNvData->LocalIp, sizeof (IfrNvData->LocalIp));
         ZeroMem (IfrNvData->SubnetMask, sizeof (IfrNvData->SubnetMask));
         ZeroMem (IfrNvData->Gateway, sizeof (IfrNvData->Gateway));
         ZeroMem (IfrNvData->TargetIp, sizeof (IfrNvData->TargetIp));
diff --git a/NetworkPkg/IScsiDxe/IScsiDriver.c b/NetworkPkg/IScsiDxe/IScsiDriver.c
index 2249919..fbeef97 100644
--- a/NetworkPkg/IScsiDxe/IScsiDriver.c
+++ b/NetworkPkg/IScsiDxe/IScsiDriver.c
@@ -438,11 +438,11 @@ IScsiStart (
   }
   
   //
   // Record the incoming NIC info.
   //
-  Status = IScsiAddNic (ControllerHandle);
+  Status = IScsiAddNic (ControllerHandle, Image);
   if (EFI_ERROR (Status)) {
     return Status;
   }
 
   //
diff --git a/NetworkPkg/IScsiDxe/IScsiDriver.h b/NetworkPkg/IScsiDxe/IScsiDriver.h
index 6c6e11b..2db93c5 100644
--- a/NetworkPkg/IScsiDxe/IScsiDriver.h
+++ b/NetworkPkg/IScsiDxe/IScsiDriver.h
@@ -79,10 +79,11 @@ typedef struct {
   UINT8           NicIndex;
   UINT16          VlanId;
   UINTN           BusNumber;
   UINTN           DeviceNumber;
   UINTN           FunctionNumber;
+  BOOLEAN         Ipv6Available;
 } ISCSI_NIC_INFO;
 
 typedef struct _ISCSI_PRIVATE_PROTOCOL {
   UINT32  Reserved;
 } ISCSI_PRIVATE_PROTOCOL;
diff --git a/NetworkPkg/IScsiDxe/IScsiDxe.inf b/NetworkPkg/IScsiDxe/IScsiDxe.inf
index 01998a0..319c7fe 100644
--- a/NetworkPkg/IScsiDxe/IScsiDxe.inf
+++ b/NetworkPkg/IScsiDxe/IScsiDxe.inf
@@ -115,18 +115,20 @@
   gEfiIScsiInitiatorNameProtocolGuid
   ## PRODUCES       
   gEfiAuthenticationInfoProtocolGuid
   ## SOMETIMES_CONSUMES
   gEfiAdapterInformationProtocolGuid
+  gEfiNetworkInterfaceIdentifierProtocolGuid_31 ## SOMETIMES_CONSUMES
 
 [Guids]
   gEfiEventExitBootServicesGuid                 ## SOMETIMES_CONSUMES ## Event
   gEfiIfrTianoGuid                              ## SOMETIMES_PRODUCES ## UNDEFINED
   gEfiAcpiTableGuid                             ## SOMETIMES_CONSUMES ## SystemTable
   gEfiAcpi10TableGuid                           ## SOMETIMES_CONSUMES ## SystemTable
   gEfiAcpi20TableGuid                           ## SOMETIMES_CONSUMES ## SystemTable
   gEfiAdapterInfoNetworkBootGuid                ## SOMETIMES_CONSUMES ## UNDEFINED
+  gEfiAdapterInfoUndiIpv6SupportGuid            ## SOMETIMES_CONSUMES ## GUID
   
   ## SOMETIMES_PRODUCES ## Variable:L"AttemptOrder"
   ## SOMETIMES_CONSUMES ## Variable:L"AttemptOrder"
   ## SOMETIMES_PRODUCES ## Variable:L"InitialAttemptOrder"
   ## SOMETIMES_CONSUMES ## Variable:L"InitialAttemptOrder"
diff --git a/NetworkPkg/IScsiDxe/IScsiImpl.h b/NetworkPkg/IScsiDxe/IScsiImpl.h
index 741c497..9e36da0 100644
--- a/NetworkPkg/IScsiDxe/IScsiImpl.h
+++ b/NetworkPkg/IScsiDxe/IScsiImpl.h
@@ -37,10 +37,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 #include <Protocol/AuthenticationInfo.h>
 #include <Protocol/IScsiInitiatorName.h>
 #include <Protocol/ScsiPassThruExt.h>
 #include <Protocol/AdapterInformation.h>
+#include <Protocol/NetworkInterfaceIdentifier.h>
 
 #include <Library/HiiLib.h>
 #include <Library/UefiHiiServicesLib.h>
 #include <Library/DevicePathLib.h>
 #include <Library/DebugLib.h>
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.c b/NetworkPkg/IScsiDxe/IScsiMisc.c
index 0a0a3f5..9e4164c 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.c
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.c
@@ -464,22 +464,128 @@ IScsiGenRandom (
   }
 }
 
 
 /**
+  Check whether UNDI protocol supports IPv6.
+
+  @param[in]   ControllerHandle    Controller handle.
+  @param[in]   Image               Handle of the image.
+  @param[out]  Ipv6Support         TRUE if UNDI supports IPv6.
+
+  @retval EFI_SUCCESS            Get the result whether UNDI supports IPv6 by NII or AIP protocol successfully.
+  @retval EFI_NOT_FOUND          Don't know whether UNDI supports IPv6 since NII or AIP is not available.
+
+**/
+EFI_STATUS
+IScsiCheckIpv6Support (
+  IN  EFI_HANDLE                   ControllerHandle,
+  IN  EFI_HANDLE                   Image,
+  OUT BOOLEAN                      *Ipv6Support
+  )
+{
+  EFI_HANDLE                       Handle;
+  EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;
+  EFI_STATUS                       Status;
+  EFI_GUID                         *InfoTypesBuffer;
+  UINTN                            InfoTypeBufferCount;
+  UINTN                            TypeIndex;
+  BOOLEAN                          Supported;
+  VOID                             *InfoBlock;
+  UINTN                            InfoBlockSize;
+  
+  EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;
+
+  ASSERT (Ipv6Support != NULL);
+
+  //
+  // Check whether the UNDI supports IPv6 by NII protocol.
+  //
+  Status = gBS->OpenProtocol (
+                  ControllerHandle,
+                  &gEfiNetworkInterfaceIdentifierProtocolGuid_31,
+                  (VOID **) &Nii,
+                  Image,
+                  ControllerHandle,
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
+                  );
+  if (Status == EFI_SUCCESS) {
+    *Ipv6Support = Nii->Ipv6Supported;
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Get the NIC handle by SNP protocol.
+  //  
+  Handle = NetLibGetSnpHandle (ControllerHandle, NULL);
+  if (Handle == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  Aip    = NULL;
+  Status = gBS->HandleProtocol (
+                  Handle,
+                  &gEfiAdapterInformationProtocolGuid,
+                  (VOID *) &Aip
+                  );
+  if (EFI_ERROR (Status) || Aip == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  InfoTypesBuffer     = NULL;
+  InfoTypeBufferCount = 0;
+  Status = Aip->GetSupportedTypes (Aip, &InfoTypesBuffer, &InfoTypeBufferCount);
+  if (EFI_ERROR (Status) || InfoTypesBuffer == NULL) {
+    FreePool (InfoTypesBuffer);
+    return EFI_NOT_FOUND;
+  }
+
+  Supported = FALSE;
+  for (TypeIndex = 0; TypeIndex < InfoTypeBufferCount; TypeIndex++) {
+    if (CompareGuid (&InfoTypesBuffer[TypeIndex], &gEfiAdapterInfoUndiIpv6SupportGuid)) {
+      Supported = TRUE;
+      break;
+    }
+  }
+
+  FreePool (InfoTypesBuffer);
+  if (!Supported) {
+    return EFI_NOT_FOUND;
+  }
+
+  //
+  // We now have adapter information block.
+  //
+  InfoBlock     = NULL;
+  InfoBlockSize = 0;
+  Status = Aip->GetInformation (Aip, &gEfiAdapterInfoUndiIpv6SupportGuid, &InfoBlock, &InfoBlockSize);
+  if (EFI_ERROR (Status) || InfoBlock == NULL) {
+    FreePool (InfoBlock);
+    return EFI_NOT_FOUND;
+  }  
+
+  *Ipv6Support = ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT *) InfoBlock)->Ipv6Support;
+  FreePool (InfoBlock);
+  
+  return EFI_SUCCESS;
+}
+
+/**
   Record the NIC info in global structure.
 
   @param[in]  Controller         The handle of the controller.
+  @param[in]  Image              Handle of the image.
 
   @retval EFI_SUCCESS            The operation is completed.
   @retval EFI_OUT_OF_RESOURCES   Do not have sufficient resources to finish this
                                  operation.
 
 **/
 EFI_STATUS
 IScsiAddNic (
-  IN EFI_HANDLE  Controller
+  IN EFI_HANDLE  Controller,
+  IN EFI_HANDLE  Image
   )
 {
   EFI_STATUS                  Status;
   ISCSI_NIC_INFO              *NicInfo;
   LIST_ENTRY                  *Entry;
@@ -507,10 +613,23 @@ IScsiAddNic (
     NicInfo = NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link);
     if (NicInfo->HwAddressSize == HwAddressSize &&
         CompareMem (&NicInfo->PermanentAddress, MacAddr.Addr, HwAddressSize) == 0 &&
         NicInfo->VlanId == VlanId) {
       mPrivate->CurrentNic = NicInfo->NicIndex;
+	  
+	    //
+      // Set IPv6 available flag.
+      // 
+      Status = IScsiCheckIpv6Support (Controller, Image, &NicInfo->Ipv6Available);
+      if (EFI_ERROR (Status)) {
+        //
+        // Fail to get the data whether UNDI supports IPv6. 
+        // Set default value to TRUE.
+        //
+        NicInfo->Ipv6Available = TRUE;
+      }
+	  
       return EFI_SUCCESS;
     }
 
     if (mPrivate->MaxNic < NicInfo->NicIndex) {
       mPrivate->MaxNic = NicInfo->NicIndex;
@@ -528,11 +647,23 @@ IScsiAddNic (
   CopyMem (&NicInfo->PermanentAddress, MacAddr.Addr, HwAddressSize);
   NicInfo->HwAddressSize  = (UINT32) HwAddressSize;
   NicInfo->VlanId         = VlanId;
   NicInfo->NicIndex       = (UINT8) (mPrivate->MaxNic + 1);
   mPrivate->MaxNic        = NicInfo->NicIndex;
-
+  
+  //
+  // Set IPv6 available flag.
+  // 
+  Status = IScsiCheckIpv6Support (Controller, Image, &NicInfo->Ipv6Available);
+  if (EFI_ERROR (Status)) {
+    //
+    // Fail to get the data whether UNDI supports IPv6. 
+    // Set default value to TRUE.
+    //
+    NicInfo->Ipv6Available = TRUE;
+  }
+  
   //
   // Get the PCI location.
   //
   IScsiGetNICPciLocation (
     Controller,
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.h b/NetworkPkg/IScsiDxe/IScsiMisc.h
index caa2f94..659c026 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.h
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.h
@@ -215,19 +215,21 @@ IScsiGenRandom (
 
 /**
   Record the NIC information in a global structure.
 
   @param[in]  Controller         The handle of the controller.
+  @param[in]  Image              Handle of the image.
 
   @retval EFI_SUCCESS            The operation is completed.
   @retval EFI_OUT_OF_RESOURCES   Do not have sufficient resource to finish this
                                  operation.
 
 **/
 EFI_STATUS
 IScsiAddNic (
-  IN EFI_HANDLE  Controller
+  IN EFI_HANDLE  Controller,
+  IN EFI_HANDLE  Image
   );
 
 /**
   Delete the recorded NIC information from a global structure. Also delete corresponding
   attempts.
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-18  6:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-18  6:57 [Patch v2 0/2] Add IPv6 support condition check Jiaxin Wu
2017-10-18  6:57 ` [Patch v2 1/2] NetworkPkg/HttpBootDxe: " Jiaxin Wu
2017-10-18  6:57 ` [Patch v2 2/2] NetworkPkg/IScsiDxe: " Jiaxin Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox