]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiMisc.c
index dd110dfb3055b9a6e71fee8e5041946a2242130d..d924a8b82427ef372ad3325cbcf3e0e29ce43518 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Miscellaneous routines for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -19,8 +19,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8  IScsiHexString[] = "0123456789ABCDEFa
 /**\r
   Removes (trims) specified leading and trailing characters from a string.\r
 \r
-  @param[in, out]  Str  Pointer to the null-terminated string to be trimmed. On return, \r
-                        Str will hold the trimmed string. \r
+  @param[in, out]  Str  Pointer to the null-terminated string to be trimmed. On return,\r
+                        Str will hold the trimmed string.\r
 \r
   @param[in]      CharC Character will be trimmed from str.\r
 **/\r
@@ -32,18 +32,18 @@ StrTrim (
 {\r
   CHAR16  *Pointer1;\r
   CHAR16  *Pointer2;\r
-  \r
+\r
   if (*Str == 0) {\r
     return;\r
   }\r
-  \r
+\r
   //\r
   // Trim off the leading and trailing characters c\r
   //\r
   for (Pointer1 = Str; (*Pointer1 != 0) && (*Pointer1 == CharC); Pointer1++) {\r
     ;\r
   }\r
-  \r
+\r
   Pointer2 = Str;\r
   if (Pointer2 == Pointer1) {\r
     while (*Pointer1 != 0) {\r
@@ -51,19 +51,19 @@ StrTrim (
       Pointer1++;\r
     }\r
   } else {\r
-    while (*Pointer1 != 0) {    \r
-    *Pointer2 = *Pointer1;    \r
+    while (*Pointer1 != 0) {\r
+    *Pointer2 = *Pointer1;\r
     Pointer1++;\r
     Pointer2++;\r
     }\r
     *Pointer2 = 0;\r
   }\r
-  \r
-  \r
+\r
+\r
   for (Pointer1 = Str + StrLen(Str) - 1; Pointer1 >= Str && *Pointer1 == CharC; Pointer1--) {\r
     ;\r
   }\r
-  if  (Pointer1 !=  Str + StrLen(Str) - 1) { \r
+  if  (Pointer1 !=  Str + StrLen(Str) - 1) {\r
     *(Pointer1 + 1) = 0;\r
   }\r
 }\r
@@ -109,7 +109,7 @@ IScsiGetSubnetMaskPrefixLength (
 }\r
 \r
 /**\r
-  Convert the hexadecimal encoded LUN string into the 64-bit LUN. \r
+  Convert the hexadecimal encoded LUN string into the 64-bit LUN.\r
 \r
   @param[in]   Str             The hexadecimal encoded LUN string.\r
   @param[out]  Lun             Storage to return the 64-bit LUN.\r
@@ -123,53 +123,62 @@ IScsiAsciiStrToLun (
   OUT UINT8  *Lun\r
   )\r
 {\r
-  UINT32  Index;\r
-  CHAR8   *LunUnitStr[4];\r
-  CHAR8   Digit;\r
-  UINTN   Temp;\r
+  UINTN   Index, IndexValue, IndexNum, SizeStr;\r
+  CHAR8   TemStr[2];\r
+  UINT8   TemValue;\r
+  UINT16  Value[4];\r
 \r
   ZeroMem (Lun, 8);\r
-  ZeroMem (LunUnitStr, sizeof (LunUnitStr));\r
-\r
-  Index         = 0;\r
-  LunUnitStr[0] = Str;\r
-\r
-  if (!IsHexDigit ((UINT8 *) &Digit, *Str)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  while (*Str != '\0') {\r
-    //\r
-    // Legal representations of LUN:\r
-    //   4752-3A4F-6b7e-2F99,\r
-    //   6734-9-156f-127,\r
-    //   4186-9\r
-    //\r
-    if (*Str == '-') {\r
-      *Str = '\0';\r
-      Index++;\r
-\r
-      if (*(Str + 1) != '\0') {\r
-        if (!IsHexDigit ((UINT8 *) &Digit, *(Str + 1))) {\r
-          return EFI_INVALID_PARAMETER;\r
-        }\r
-\r
-        LunUnitStr[Index] = Str + 1;\r
+  ZeroMem (TemStr, 2);\r
+  ZeroMem ((UINT8 *) Value, sizeof (Value));\r
+  SizeStr    = AsciiStrLen (Str);\r
+  IndexValue = 0;\r
+  IndexNum   = 0;\r
+\r
+  for (Index = 0; Index < SizeStr; Index ++) {\r
+    TemStr[0] = Str[Index];\r
+    TemValue = (UINT8) AsciiStrHexToUint64 (TemStr);\r
+    if (TemValue == 0 && TemStr[0] != '0') {\r
+      if ((TemStr[0] != '-') || (IndexNum == 0)) {\r
+        //\r
+        // Invalid Lun Char\r
+        //\r
+        return EFI_INVALID_PARAMETER;\r
       }\r
-    } else if (!IsHexDigit ((UINT8 *) &Digit, *Str)) {\r
-      return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    Str++;\r
-  }\r
+    if ((TemValue == 0) && (TemStr[0] == '-')) {\r
+      //\r
+      // Next Lun value\r
+      //\r
+      if (++IndexValue >= 4) {\r
+        //\r
+        // Max 4 Lun value\r
+        //\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+      //\r
+      // Restart str index for the next lun value\r
+      //\r
+      IndexNum = 0;\r
+      continue;\r
+    }\r
 \r
-  for (Index = 0; (Index < 4) && (LunUnitStr[Index] != NULL); Index++) {\r
-    if (AsciiStrLen (LunUnitStr[Index]) > 4) {\r
+    if (++IndexNum > 4) {\r
+      //\r
+      // Each Lun Str can't exceed size 4, because it will be as UINT16 value\r
+      //\r
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    Temp = AsciiStrHexToUintn (LunUnitStr[Index]);\r
-    *((UINT16 *) &Lun[Index * 2]) = HTONS (Temp);\r
+    //\r
+    // Combine UINT16 value\r
+    //\r
+    Value[IndexValue] = (UINT16) ((Value[IndexValue] << 4) + TemValue);\r
+  }\r
+\r
+  for (Index = 0; Index <= IndexValue; Index ++) {\r
+    *((UINT16 *) &Lun[Index * 2]) =  HTONS (Value[Index]);\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -195,7 +204,7 @@ IScsiLunToUnicodeStr (
   for (Index = 0; Index < 4; Index++) {\r
 \r
     if ((Lun[2 * Index] | Lun[2 * Index + 1]) == 0) {\r
-      StrCpy (TempStr, L"0-");\r
+      CopyMem(TempStr, L"0-", sizeof (L"0-"));\r
     } else {\r
       TempStr[0]  = (CHAR16) IScsiHexString[Lun[2 * Index] >> 4];\r
       TempStr[1]  = (CHAR16) IScsiHexString[Lun[2 * Index] & 0x0F];\r
@@ -210,6 +219,7 @@ IScsiLunToUnicodeStr (
     TempStr += StrLen (TempStr);\r
   }\r
 \r
+  ASSERT (StrLen(Str) >= 1);\r
   Str[StrLen (Str) - 1] = 0;\r
 \r
   for (Index = StrLen (Str) - 1; Index > 1; Index = Index - 2) {\r
@@ -344,18 +354,21 @@ IScsiAsciiStrToIp (
 /**\r
   Convert the mac address into a hexadecimal encoded "-" seperated string.\r
 \r
-  @param[in]  Mac The mac address.\r
-  @param[in]  Len  Length in bytes of the mac address.\r
-  @param[out] Str The storage to return the mac string.\r
+  @param[in]  Mac     The mac address.\r
+  @param[in]  Len     Length in bytes of the mac address.\r
+  @param[in]  VlanId  VLAN ID of the network device.\r
+  @param[out] Str     The storage to return the mac string.\r
 **/\r
 VOID\r
 IScsiMacAddrToStr (\r
   IN  EFI_MAC_ADDRESS  *Mac,\r
   IN  UINT32           Len,\r
+  IN  UINT16           VlanId,\r
   OUT CHAR16           *Str\r
   )\r
 {\r
   UINT32  Index;\r
+  CHAR16  *String;\r
 \r
   for (Index = 0; Index < Len; Index++) {\r
     Str[3 * Index]      = (CHAR16) IScsiHexString[(Mac->Addr[Index] >> 4) & 0x0F];\r
@@ -363,7 +376,12 @@ IScsiMacAddrToStr (
     Str[3 * Index + 2]  = L'-';\r
   }\r
 \r
-  Str[3 * Index - 1] = L'\0';\r
+  String = &Str[3 * Index - 1] ;\r
+  if (VlanId != 0) {\r
+    String += UnicodeSPrint (String, 6 * sizeof (CHAR16), L"\\%04x", (UINTN) VlanId);\r
+  }\r
+\r
+  *String = L'\0';\r
 }\r
 \r
 /**\r
@@ -374,7 +392,7 @@ IScsiMacAddrToStr (
   @param[in, out]  HexStr      Pointer to the string.\r
   @param[in, out]  HexLength   The length of the string.\r
 \r
-  @retval EFI_SUCCESS          The binary data is converted to the hexadecimal string \r
+  @retval EFI_SUCCESS          The binary data is converted to the hexadecimal string\r
                                and the length of the string is updated.\r
   @retval EFI_BUFFER_TOO_SMALL The string is too small.\r
   @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
@@ -434,53 +452,39 @@ IScsiHexToBin (
   )\r
 {\r
   UINTN   Index;\r
-  UINT32  HexCount;\r
-  CHAR8   *HexBuf;\r
+  UINTN   Length;\r
   UINT8   Digit;\r
-  UINT8   Byte;\r
+  CHAR8   TemStr[2];\r
 \r
-  Digit = 0;\r
+  ZeroMem (TemStr, sizeof (TemStr));\r
 \r
   //\r
   // Find out how many hex characters the string has.\r
   //\r
-  HexBuf = HexStr;\r
-  if ((HexBuf[0] == '0') && ((HexBuf[1] == 'x') || (HexBuf[1] == 'X'))) {\r
-    HexBuf += 2;\r
+  if ((HexStr[0] == '0') && ((HexStr[1] == 'x') || (HexStr[1] == 'X'))) {\r
+    HexStr += 2;\r
   }\r
 \r
-  for (Index = 0, HexCount = 0; IsHexDigit (&Digit, HexBuf[Index]); Index++, HexCount++)\r
-    ;\r
-\r
-  if (HexCount == 0) {\r
-    *BinLength = 0;\r
-    return EFI_SUCCESS;\r
-  }\r
-  //\r
-  // Test if buffer is passed enough.\r
-  //\r
-  if (((HexCount + 1) / 2) > *BinLength) {\r
-    *BinLength = (HexCount + 1) / 2;\r
-    return EFI_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  *BinLength = (HexCount + 1) / 2;\r
-\r
-  for (Index = 0; Index < HexCount; Index++) {\r
-\r
-    IsHexDigit (&Digit, HexBuf[HexCount - 1 - Index]);\r
+  Length = AsciiStrLen (HexStr);\r
 \r
+  for (Index = 0; Index < Length; Index ++) {\r
+    TemStr[0] = HexStr[Index];\r
+    Digit = (UINT8) AsciiStrHexToUint64 (TemStr);\r
+    if (Digit == 0 && TemStr[0] != '0') {\r
+      //\r
+      // Invalid Lun Char\r
+      //\r
+      break;\r
+    }\r
     if ((Index & 1) == 0) {\r
-      Byte = Digit;\r
+      BinBuffer [Index/2] = Digit;\r
     } else {\r
-      Byte = BinBuffer[*BinLength - 1 - Index / 2];\r
-      Byte &= 0x0F;\r
-      Byte = (UINT8) (Byte | (Digit << 4));\r
+      BinBuffer [Index/2] = (UINT8) ((BinBuffer [Index/2] << 4) + Digit);\r
     }\r
-\r
-    BinBuffer[*BinLength - 1 - Index / 2] = Byte;\r
   }\r
 \r
+  *BinLength = (UINT32) ((Index + 1)/2);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -545,7 +549,7 @@ IScsiCreateDriverData (
                   &Private->ExitBootServiceEvent\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (Private);\r
+    FreePool (Private);\r
     return NULL;\r
   }\r
 \r
@@ -570,7 +574,7 @@ IScsiCreateDriverData (
                   );\r
   if (EFI_ERROR (Status)) {\r
     gBS->CloseEvent (Private->ExitBootServiceEvent);\r
-    gBS->FreePool (Private);\r
+    FreePool (Private);\r
 \r
     return NULL;\r
   }\r
@@ -583,34 +587,102 @@ IScsiCreateDriverData (
 /**\r
   Clean the iSCSI driver data.\r
 \r
-  @param[in]  Private The iSCSI driver data.\r
+  @param[in]              Private The iSCSI driver data.\r
+\r
+  @retval EFI_SUCCESS     The clean operation is successful.\r
+  @retval Others          Other errors as indicated.\r
+\r
 **/\r
-VOID\r
+EFI_STATUS\r
 IScsiCleanDriverData (\r
   IN ISCSI_DRIVER_DATA  *Private\r
   )\r
 {\r
+  EFI_STATUS             Status;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
   if (Private->DevicePath != NULL) {\r
-    gBS->UninstallProtocolInterface (\r
-          Private->ExtScsiPassThruHandle,\r
-          &gEfiDevicePathProtocolGuid,\r
-          Private->DevicePath\r
-          );\r
+    Status = gBS->UninstallProtocolInterface (\r
+                    Private->ExtScsiPassThruHandle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    Private->DevicePath\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto EXIT;\r
+    }\r
 \r
-    gBS->FreePool (Private->DevicePath);\r
+    FreePool (Private->DevicePath);\r
   }\r
 \r
   if (Private->ExtScsiPassThruHandle != NULL) {\r
-    gBS->UninstallProtocolInterface (\r
-          Private->ExtScsiPassThruHandle,\r
-          &gEfiExtScsiPassThruProtocolGuid,\r
-          &Private->IScsiExtScsiPassThru\r
-          );\r
+    Status = gBS->UninstallProtocolInterface (\r
+                    Private->ExtScsiPassThruHandle,\r
+                    &gEfiExtScsiPassThruProtocolGuid,\r
+                    &Private->IScsiExtScsiPassThru\r
+                    );\r
   }\r
 \r
-  gBS->CloseEvent (Private->ExitBootServiceEvent);\r
+EXIT:\r
+  if (Private->ExitBootServiceEvent != NULL) {\r
+    gBS->CloseEvent (Private->ExitBootServiceEvent);\r
+  }\r
 \r
-  gBS->FreePool (Private);\r
+  FreePool (Private);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Check wheather the Controller is configured to use DHCP protocol.\r
+\r
+  @param[in]  Controller           The handle of the controller.\r
+\r
+  @retval TRUE                     The handle of the controller need the Dhcp protocol.\r
+  @retval FALSE                    The handle of the controller does not need the Dhcp protocol.\r
+\r
+**/\r
+BOOLEAN\r
+IScsiDhcpIsConfigured (\r
+  IN EFI_HANDLE  Controller\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_MAC_ADDRESS             MacAddress;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
+  CHAR16                      MacString[70];\r
+  ISCSI_SESSION_CONFIG_NVDATA *ConfigDataTmp;\r
+\r
+  //\r
+  // Get the mac string, it's the name of various variable\r
+  //\r
+  Status = NetLibGetMacAddress (Controller, &MacAddress, &HwAddressSize);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+  VlanId = NetLibGetVlanId (Controller);\r
+  IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, MacString);\r
+\r
+  //\r
+  // Get the normal configuration.\r
+  //\r
+  Status = GetVariable2 (\r
+             MacString,\r
+             &gEfiIScsiInitiatorNameProtocolGuid,\r
+             (VOID**)&ConfigDataTmp,\r
+             NULL\r
+             );\r
+  if (ConfigDataTmp == NULL || EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (ConfigDataTmp->Enabled && ConfigDataTmp->InitiatorInfoFromDhcp) {\r
+    FreePool (ConfigDataTmp);\r
+    return TRUE;\r
+  }\r
+\r
+  FreePool (ConfigDataTmp);\r
+  return FALSE;\r
 }\r
 \r
 /**\r
@@ -630,9 +702,10 @@ IScsiGetConfigData (
   EFI_STATUS                  Status;\r
   ISCSI_SESSION               *Session;\r
   UINTN                       BufferSize;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
-  EFI_SIMPLE_NETWORK_MODE     *Mode;\r
-  CHAR16                      MacString[65];\r
+  EFI_MAC_ADDRESS             MacAddress;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
+  CHAR16                      MacString[70];\r
 \r
   //\r
   // get the iSCSI Initiator Name\r
@@ -648,21 +721,13 @@ IScsiGetConfigData (
     return Status;\r
   }\r
 \r
-  Status = gBS->HandleProtocol (\r
-                  Private->Controller,\r
-                  &gEfiSimpleNetworkProtocolGuid,\r
-                  (VOID **)&Snp\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Mode = Snp->Mode;\r
-\r
   //\r
   // Get the mac string, it's the name of various variable\r
   //\r
-  IScsiMacAddrToStr (&Mode->PermanentAddress, Mode->HwAddressSize, MacString);\r
+  Status = NetLibGetMacAddress (Private->Controller, &MacAddress, &HwAddressSize);\r
+  ASSERT (Status == EFI_SUCCESS);\r
+  VlanId = NetLibGetVlanId (Private->Controller);\r
+  IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, MacString);\r
 \r
   //\r
   // Get the normal configuration.\r
@@ -688,7 +753,7 @@ IScsiGetConfigData (
   BufferSize = sizeof (Session->AuthData.AuthConfig);\r
   Status = gRT->GetVariable (\r
                   MacString,\r
-                  &mIScsiCHAPAuthInfoGuid,\r
+                  &gIScsiCHAPAuthInfoGuid,\r
                   NULL,\r
                   &BufferSize,\r
                   &Session->AuthData.AuthConfig\r
@@ -749,6 +814,9 @@ IScsiGetTcpConnDevicePath (
   // Duplicate it.\r
   //\r
   DevicePath  = DuplicateDevicePath (DevicePath);\r
+  if (DevicePath == NULL) {\r
+    return NULL;\r
+  }\r
 \r
   DPathNode   = (EFI_DEV_PATH *) DevicePath;\r
 \r
@@ -758,7 +826,28 @@ IScsiGetTcpConnDevicePath (
         ) {\r
 \r
       DPathNode->Ipv4.LocalPort       = 0;\r
-      DPathNode->Ipv4.StaticIpAddress = (BOOLEAN) (!Session->ConfigData.NvData.InitiatorInfoFromDhcp);\r
+      DPathNode->Ipv4.StaticIpAddress =\r
+        (BOOLEAN) (!Session->ConfigData.NvData.InitiatorInfoFromDhcp);\r
+\r
+      //\r
+      //  Add a judgement here to support previous versions of IPv4_DEVICE_PATH.\r
+      //  In previous versions of IPv4_DEVICE_PATH, GatewayIpAddress and SubnetMask\r
+      //  do not exist.\r
+      //  In new version of IPv4_DEVICE_PATH, structcure length is 27.\r
+      //\r
+      if (DevicePathNodeLength (&DPathNode->Ipv4) == IP4_NODE_LEN_NEW_VERSIONS) {\r
+\r
+        IP4_COPY_ADDRESS (\r
+          &DPathNode->Ipv4.GatewayIpAddress,\r
+          &Session->ConfigData.NvData.Gateway\r
+          );\r
+\r
+        IP4_COPY_ADDRESS (\r
+          &DPathNode->Ipv4.SubnetMask,\r
+          &Session->ConfigData.NvData.SubnetMask\r
+          );\r
+      }\r
+\r
       break;\r
     }\r
 \r
@@ -784,7 +873,76 @@ IScsiOnExitBootService (
   ISCSI_DRIVER_DATA *Private;\r
 \r
   Private = (ISCSI_DRIVER_DATA *) Context;\r
+\r
   gBS->CloseEvent (Private->ExitBootServiceEvent);\r
+  Private->ExitBootServiceEvent = NULL;\r
 \r
   IScsiSessionAbort (&Private->Session);\r
 }\r
+\r
+/**\r
+  Tests whether a controller handle is being managed by IScsi driver.\r
+\r
+  This function tests whether the driver specified by DriverBindingHandle is\r
+  currently managing the controller specified by ControllerHandle.  This test\r
+  is performed by evaluating if the the protocol specified by ProtocolGuid is\r
+  present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
+  Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.\r
+  If ProtocolGuid is NULL, then ASSERT().\r
+\r
+  @param  ControllerHandle     A handle for a controller to test.\r
+  @param  DriverBindingHandle  Specifies the driver binding handle for the\r
+                               driver.\r
+  @param  ProtocolGuid         Specifies the protocol that the driver specified\r
+                               by DriverBindingHandle opens in its Start()\r
+                               function.\r
+\r
+  @retval EFI_SUCCESS          ControllerHandle is managed by the driver\r
+                               specified by DriverBindingHandle.\r
+  @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the driver\r
+                               specified by DriverBindingHandle.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IScsiTestManagedDevice (\r
+  IN  EFI_HANDLE       ControllerHandle,\r
+  IN  EFI_HANDLE       DriverBindingHandle,\r
+  IN  EFI_GUID         *ProtocolGuid\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  VOID           *ManagedInterface;\r
+  EFI_HANDLE     NicControllerHandle;\r
+\r
+  ASSERT (ProtocolGuid != NULL);\r
+\r
+  NicControllerHandle = NetLibGetNicHandle (ControllerHandle, ProtocolGuid);\r
+  if (NicControllerHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  (EFI_GUID *) ProtocolGuid,\r
+                  &ManagedInterface,\r
+                  DriverBindingHandle,\r
+                  NicControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           (EFI_GUID *) ProtocolGuid,\r
+           DriverBindingHandle,\r
+           NicControllerHandle\r
+           );\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r