]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c
Add VLAN support.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiConfig.c
index 59840f7f060309e98712aad6f1af159684549524..35214f2ce95b19c09d7f7b0ee286b22584c51516 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Helper functions for configuring or getting the parameters relating to iSCSI.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2004 - 2009, Intel Corporation.<BR>\r
 All rights reserved. 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
@@ -67,7 +67,7 @@ IScsiIpToStr (
 \r
 /**\r
   Update the list of iSCSI devices the iSCSI driver is controlling.\r
-  \r
+\r
   @retval EFI_SUCCESS            The callback successfully handled the action.\r
   @retval Others                 Other errors as indicated.   \r
 **/\r
@@ -84,19 +84,20 @@ IScsiUpdateDeviceList (
   UINTN                       HandleIndex;\r
   UINTN                       Index;\r
   UINTN                       LastDeviceIndex;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
-  EFI_SIMPLE_NETWORK_MODE     *Mode;\r
+  EFI_MAC_ADDRESS             MacAddress;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
   ISCSI_MAC_INFO              *CurMacInfo;\r
   ISCSI_MAC_INFO              TempMacInfo;\r
-  CHAR16                      MacString[65];\r
+  CHAR16                      MacString[70];\r
   UINTN                       DeviceListSize;\r
 \r
   //\r
-  // Dump all the handles the Simple Network Protocol is installed on.\r
+  // Dump all the handles the Managed Network Service Binding Protocol is installed on.\r
   //\r
   Status = gBS->LocateHandleBuffer (\r
                   ByProtocol,\r
-                  &gEfiSimpleNetworkProtocolGuid,\r
+                  &gEfiManagedNetworkServiceBindingProtocolGuid,\r
                   NULL,\r
                   &NumHandles,\r
                   &Handles\r
@@ -127,14 +128,15 @@ IScsiUpdateDeviceList (
     LastDeviceIndex = 0;\r
 \r
     for (HandleIndex = 0; HandleIndex < NumHandles; HandleIndex++) {\r
-      gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
-\r
-      Mode = Snp->Mode;\r
+      Status = NetLibGetMacAddress (Handles[HandleIndex], &MacAddress, &HwAddressSize);\r
+      ASSERT (Status == EFI_SUCCESS);\r
+      VlanId = NetLibGetVlanId (Handles[HandleIndex]);\r
 \r
       for (Index = LastDeviceIndex; Index < DeviceList->NumDevice; Index++) {\r
         CurMacInfo = &DeviceList->MacInfo[Index];\r
-        if ((CurMacInfo->Len == Mode->HwAddressSize) &&\r
-            (NET_MAC_EQUAL (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize))\r
+        if ((CurMacInfo->Len == HwAddressSize) &&\r
+            (CurMacInfo->VlanId == VlanId) &&\r
+            (NET_MAC_EQUAL (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize))\r
             ) {\r
           //\r
           // The previous configured NIC is still here.\r
@@ -163,14 +165,14 @@ IScsiUpdateDeviceList (
       // delete the variables\r
       //\r
       CurMacInfo = &DeviceList->MacInfo[Index];\r
-      IScsiMacAddrToStr (&CurMacInfo->Mac, CurMacInfo->Len, MacString);\r
+      IScsiMacAddrToStr (&CurMacInfo->Mac, CurMacInfo->Len, CurMacInfo->VlanId, MacString);\r
       gRT->SetVariable (MacString, &gEfiIScsiInitiatorNameProtocolGuid, 0, 0, NULL);\r
       gRT->SetVariable (MacString, &mIScsiCHAPAuthInfoGuid, 0, 0, NULL);\r
     }\r
 \r
-    gBS->FreePool (DeviceList);\r
+    FreePool (DeviceList);\r
   } else if (Status != EFI_NOT_FOUND) {\r
-    gBS->FreePool (Handles);\r
+    FreePool (Handles);\r
     return Status;\r
   }\r
   //\r
@@ -181,12 +183,12 @@ IScsiUpdateDeviceList (
   DeviceList->NumDevice = (UINT8) NumHandles;\r
 \r
   for (Index = 0; Index < NumHandles; Index++) {\r
-    gBS->HandleProtocol (Handles[Index], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
-    Mode        = Snp->Mode;\r
+    NetLibGetMacAddress (Handles[Index], &MacAddress, &HwAddressSize);\r
 \r
     CurMacInfo  = &DeviceList->MacInfo[Index];\r
-    CopyMem (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize);\r
-    CurMacInfo->Len = (UINT8) Mode->HwAddressSize;\r
+    CopyMem (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize);\r
+    CurMacInfo->Len = (UINT8) HwAddressSize;\r
+    CurMacInfo->VlanId = NetLibGetVlanId (Handles[Index]);\r
   }\r
 \r
   gRT->SetVariable (\r
@@ -197,8 +199,8 @@ IScsiUpdateDeviceList (
         DeviceList\r
         );\r
 \r
-  gBS->FreePool (DeviceList);\r
-  gBS->FreePool (Handles);\r
+  FreePool (DeviceList);\r
+  FreePool (Handles);\r
 \r
   return Status;\r
 }\r
@@ -400,7 +402,7 @@ IScsiFormExtractConfig (
                                Results,\r
                                Progress\r
                                );\r
-  gBS->FreePool (IfrNvData);\r
+  FreePool (IfrNvData);\r
   return Status;\r
 }\r
 \r
@@ -544,7 +546,7 @@ IScsiFormCallback (
   case KEY_LOCAL_IP:\r
     IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String);\r
     Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
-    if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+    if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
       CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
       Status = EFI_INVALID_PARAMETER;\r
     } else {\r
@@ -568,7 +570,7 @@ IScsiFormCallback (
   case KEY_GATE_WAY:\r
     IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String);\r
     Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4);\r
-    if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
+    if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
       CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
       Status = EFI_INVALID_PARAMETER;\r
     } else {\r
@@ -580,7 +582,7 @@ IScsiFormCallback (
   case KEY_TARGET_IP:\r
     IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String);\r
     Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
-    if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+    if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
       CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
       Status = EFI_INVALID_PARAMETER;\r
     } else {\r
@@ -678,7 +680,7 @@ IScsiFormCallback (
       //\r
       if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) {\r
         CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4));\r
-        if (!Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+        if (!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
           CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Target IP is invalid!", NULL);\r
           Status = EFI_INVALID_PARAMETER;\r
           break;\r
@@ -776,7 +778,9 @@ IScsiConfigUpdateForm (
   ISCSI_CONFIG_FORM_ENTRY     *ConfigFormEntry;\r
   BOOLEAN                     EntryExisted;\r
   EFI_STATUS                  Status;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
+  EFI_MAC_ADDRESS             MacAddress;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
   CHAR16                      PortString[128];\r
   UINT16                      FormIndex;\r
   UINTN                       BufferSize;\r
@@ -813,17 +817,13 @@ IScsiConfigUpdateForm (
       ConfigFormEntry->Controller = Controller;\r
 \r
       //\r
-      // Get the simple network protocol and convert the MAC address into\r
-      // the formatted string.\r
+      // Get the MAC address and convert it into the formatted string.\r
       //\r
-      Status = gBS->HandleProtocol (\r
-                      Controller,\r
-                      &gEfiSimpleNetworkProtocolGuid,\r
-                      (VOID **)&Snp\r
-                      );\r
+      Status = NetLibGetMacAddress (Controller, &MacAddress, &HwAddressSize);\r
       ASSERT (Status == EFI_SUCCESS);\r
+      VlanId = NetLibGetVlanId (Controller);\r
 \r
-      IScsiMacAddrToStr (&Snp->Mode->PermanentAddress, Snp->Mode->HwAddressSize, ConfigFormEntry->MacString);\r
+      IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, ConfigFormEntry->MacString);\r
 \r
       //\r
       // Get the normal session configuration data.\r
@@ -873,7 +873,7 @@ IScsiConfigUpdateForm (
 \r
     mNumberOfIScsiDevices--;\r
     RemoveEntryList (&ConfigFormEntry->Link);\r
-    gBS->FreePool (ConfigFormEntry);\r
+    FreePool (ConfigFormEntry);\r
   }\r
   //\r
   // Allocate space for creation of Buffer\r
@@ -1055,7 +1055,7 @@ IScsiConfigFormUnload (
          &mCallbackInfo->ConfigAccess,\r
          NULL\r
          );\r
-  gBS->FreePool (mCallbackInfo);\r
+  FreePool (mCallbackInfo);\r
 \r
   return EFI_SUCCESS;\r
 }\r