X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FIScsiDxe%2FIScsiMisc.c;h=1968cc9370d91f1f2bd00eff75e60222c51be29d;hb=6c8cfb0751bd64020495f065407cae0b7c3dd6ce;hp=2cf3db01b710abbc5997d7a68245dca2cd4e6219;hpb=c0d494b5a7e14f007a425c7c18f24a739d596bce;p=mirror_edk2.git diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.c b/NetworkPkg/IScsiDxe/IScsiMisc.c index 2cf3db01b7..1968cc9370 100644 --- a/NetworkPkg/IScsiDxe/IScsiMisc.c +++ b/NetworkPkg/IScsiDxe/IScsiMisc.c @@ -1,7 +1,7 @@ /** @file Miscellaneous routines for iSCSI driver. -Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -209,7 +209,7 @@ IScsiLunToUnicodeStr ( for (Index = 0; Index < 4; Index++) { if ((Lun[2 * Index] | Lun[2 * Index + 1]) == 0) { - StrCpy (TempStr, L"0-"); + StrnCpy (TempStr, L"0-", StrLen (L"0-")); } else { TempStr[0] = (CHAR16) IScsiHexString[Lun[2 * Index] >> 4]; TempStr[1] = (CHAR16) IScsiHexString[Lun[2 * Index] & 0x0F]; @@ -890,6 +890,100 @@ IScsiCleanDriverData ( FreePool (Private); } +/** + Check wheather the Controller handle is configured to use DHCP protocol. + + @param[in] Controller The handle of the controller. + @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6. + + @retval TRUE The handle of the controller need the Dhcp protocol. + @retval FALSE The handle of the controller does not need the Dhcp protocol. + +**/ +BOOLEAN +IScsiDhcpIsConfigured ( + IN EFI_HANDLE Controller, + IN UINT8 IpVersion + ) +{ + ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptTmp; + UINT8 *AttemptConfigOrder; + UINTN AttemptConfigOrderSize; + UINTN Index; + EFI_STATUS Status; + EFI_MAC_ADDRESS MacAddr; + UINTN HwAddressSize; + UINT16 VlanId; + CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN]; + CHAR16 AttemptName[ISCSI_NAME_IFR_MAX_SIZE]; + + AttemptConfigOrder = IScsiGetVariableAndSize ( + L"AttemptOrder", + &gIScsiConfigGuid, + &AttemptConfigOrderSize + ); + if (AttemptConfigOrder == NULL || AttemptConfigOrderSize == 0) { + return FALSE; + } + + // + // Get MAC address of this network device. + // + Status = NetLibGetMacAddress (Controller, &MacAddr, &HwAddressSize); + if(EFI_ERROR (Status)) { + return FALSE; + } + // + // Get VLAN ID of this network device. + // + VlanId = NetLibGetVlanId (Controller); + IScsiMacAddrToStr (&MacAddr, (UINT32) HwAddressSize, VlanId, MacString); + + for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) { + UnicodeSPrint ( + AttemptName, + (UINTN) 128, + L"%s%d", + MacString, + (UINTN) AttemptConfigOrder[Index] + ); + Status = GetVariable2 ( + AttemptName, + &gEfiIScsiInitiatorNameProtocolGuid, + (VOID**)&AttemptTmp, + NULL + ); + if(AttemptTmp == NULL || EFI_ERROR (Status)) { + continue; + } + + ASSERT (AttemptConfigOrder[Index] == AttemptTmp->AttemptConfigIndex); + + if (AttemptTmp->SessionConfigData.Enabled == ISCSI_DISABLED) { + FreePool (AttemptTmp); + continue; + } + + if (AttemptTmp->SessionConfigData.IpMode != IP_MODE_AUTOCONFIG && + AttemptTmp->SessionConfigData.IpMode != ((IpVersion == IP_VERSION_4) ? IP_MODE_IP4 : IP_MODE_IP6)) { + FreePool (AttemptTmp); + continue; + } + + if(AttemptTmp->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG || + AttemptTmp->SessionConfigData.InitiatorInfoFromDhcp == TRUE || + AttemptTmp->SessionConfigData.TargetInfoFromDhcp == TRUE) { + FreePool (AttemptTmp); + FreePool (AttemptConfigOrder); + return TRUE; + } + + FreePool (AttemptTmp); + } + + FreePool (AttemptConfigOrder); + return FALSE; +} /** Get the various configuration data. @@ -921,7 +1015,7 @@ IScsiGetConfigData ( // AttemptConfigOrder = IScsiGetVariableAndSize ( L"AttemptOrder", - &mVendorGuid, + &gIScsiConfigGuid, &AttemptConfigOrderSize ); if (AttemptConfigOrder == NULL || AttemptConfigOrderSize == 0) { @@ -1076,10 +1170,12 @@ IScsiGetConfigData ( (UINTN) AttemptConfigOrder[Index] ); - AttemptConfigData = (ISCSI_ATTEMPT_CONFIG_NVDATA *) GetVariable ( - mPrivate->PortString, - &gEfiIScsiInitiatorNameProtocolGuid - ); + GetVariable2 ( + mPrivate->PortString, + &gEfiIScsiInitiatorNameProtocolGuid, + (VOID**)&AttemptConfigData, + NULL + ); if (AttemptConfigData == NULL) { continue; @@ -1287,11 +1383,25 @@ IScsiGetTcpConnDevicePath ( if (DevicePathType (&DPathNode->DevPath) == MESSAGING_DEVICE_PATH) { if (!Conn->Ipv6Flag && DevicePathSubType (&DPathNode->DevPath) == MSG_IPv4_DP) { DPathNode->Ipv4.LocalPort = 0; - DPathNode->Ipv4.StaticIpAddress = (BOOLEAN) !Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp; + + DPathNode->Ipv4.StaticIpAddress = + (BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp); + + IP4_COPY_ADDRESS ( + &DPathNode->Ipv4.GatewayIpAddress, + &Session->ConfigData->SessionConfigData.Gateway + ); + + IP4_COPY_ADDRESS ( + &DPathNode->Ipv4.SubnetMask, + &Session->ConfigData->SessionConfigData.SubnetMask + ); break; } else if (Conn->Ipv6Flag && DevicePathSubType (&DPathNode->DevPath) == MSG_IPv6_DP) { DPathNode->Ipv6.LocalPort = 0; - DPathNode->Ipv6.StaticIpAddress = (BOOLEAN) !Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp; + DPathNode->Ipv6.IpAddressOrigin = 0; + DPathNode->Ipv6.PrefixLength = IP6_PREFIX_LENGTH; + ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS)); break; } } @@ -1326,3 +1436,70 @@ IScsiOnExitBootService ( IScsiSessionAbort (Private->Session); } } + +/** + Tests whether a controller handle is being managed by IScsi driver. + + This function tests whether the driver specified by DriverBindingHandle is + currently managing the controller specified by ControllerHandle. This test + is performed by evaluating if the the protocol specified by ProtocolGuid is + present on ControllerHandle and is was opened by DriverBindingHandle and Nic + Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. + If ProtocolGuid is NULL, then ASSERT(). + + @param ControllerHandle A handle for a controller to test. + @param DriverBindingHandle Specifies the driver binding handle for the + driver. + @param ProtocolGuid Specifies the protocol that the driver specified + by DriverBindingHandle opens in its Start() + function. + + @retval EFI_SUCCESS ControllerHandle is managed by the driver + specified by DriverBindingHandle. + @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver + specified by DriverBindingHandle. + +**/ +EFI_STATUS +EFIAPI +IScsiTestManagedDevice ( + IN EFI_HANDLE ControllerHandle, + IN EFI_HANDLE DriverBindingHandle, + IN EFI_GUID *ProtocolGuid + ) +{ + EFI_STATUS Status; + VOID *ManagedInterface; + EFI_HANDLE NicControllerHandle; + + ASSERT (ProtocolGuid != NULL); + + NicControllerHandle = NetLibGetNicHandle (ControllerHandle, ProtocolGuid); + if (NicControllerHandle == NULL) { + return EFI_UNSUPPORTED; + } + + Status = gBS->OpenProtocol ( + ControllerHandle, + (EFI_GUID *) ProtocolGuid, + &ManagedInterface, + DriverBindingHandle, + NicControllerHandle, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (!EFI_ERROR (Status)) { + gBS->CloseProtocol ( + ControllerHandle, + (EFI_GUID *) ProtocolGuid, + DriverBindingHandle, + NicControllerHandle + ); + return EFI_UNSUPPORTED; + } + + if (Status != EFI_ALREADY_STARTED) { + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +}