X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIScsiDxe%2FIScsiConfig.c;h=cb1eff1b690cc8494bc631e6f3e2c0497f64e992;hp=0a1f7eee37d8a2852abd2d9ce71fbd91dcf80c13;hb=d1102dba7210b95e41d06c2338a22ba6af248645;hpb=cd3d9a851ba7fac1b761c02acedb310b65fc2604 diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c index 0a1f7eee37..cb1eff1b69 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c @@ -1,7 +1,7 @@ /** @file Helper functions for configuring or getting the parameters relating to iSCSI. -Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2018, 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 @@ -14,7 +14,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "IScsiImpl.h" -EFI_GUID mVendorGuid = ISCSI_CONFIG_GUID; CHAR16 mVendorStorageName[] = L"ISCSI_CONFIG_IFR_NVDATA"; BOOLEAN mIScsiDeviceListUpdated = FALSE; UINTN mNumberOfIScsiDevices = 0; @@ -35,15 +34,12 @@ HII_VENDOR_DEVICE_PATH mIScsiHiiVendorDevicePath = { (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) } }, - // - // {49D7B73E-143D-4716-977B-C45F1CB038CC} - // - { 0x49d7b73e, 0x143d, 0x4716, { 0x97, 0x7b, 0xc4, 0x5f, 0x1c, 0xb0, 0x38, 0xcc } } + IP4_ISCSI_CONFIG_GUID }, { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, - { + { (UINT8) (END_DEVICE_PATH_LENGTH), (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) } @@ -98,7 +94,7 @@ IScsiParseIsIdFromString ( if (StrLen (IsIdStr) != 6) { UnicodeSPrint ( PortString, - (UINTN) ISCSI_NAME_IFR_MAX_SIZE, + (UINTN) sizeof (PortString), L"Error! Input is incorrect, please input 6 hex numbers!\n" ); @@ -184,7 +180,7 @@ IScsiConvertIsIdToString ( Update the list of iSCSI devices the iSCSI driver is controlling. @retval EFI_SUCCESS The callback successfully handled the action. - @retval Others Other errors as indicated. + @retval Others Other errors as indicated. **/ EFI_STATUS IScsiUpdateDeviceList ( @@ -224,17 +220,18 @@ IScsiUpdateDeviceList ( DataSize = 0; Status = gRT->GetVariable ( L"iSCSIDeviceList", - &mVendorGuid, + &gIp4IScsiConfigGuid, NULL, &DataSize, NULL ); if (Status == EFI_BUFFER_TOO_SMALL) { DeviceList = (ISCSI_DEVICE_LIST *) AllocatePool (DataSize); + ASSERT (DeviceList != NULL); gRT->GetVariable ( L"iSCSIDeviceList", - &mVendorGuid, + &gIp4IScsiConfigGuid, NULL, &DataSize, DeviceList @@ -282,7 +279,7 @@ IScsiUpdateDeviceList ( CurMacInfo = &DeviceList->MacInfo[Index]; IScsiMacAddrToStr (&CurMacInfo->Mac, CurMacInfo->Len, CurMacInfo->VlanId, MacString); gRT->SetVariable (MacString, &gEfiIScsiInitiatorNameProtocolGuid, 0, 0, NULL); - gRT->SetVariable (MacString, &mIScsiCHAPAuthInfoGuid, 0, 0, NULL); + gRT->SetVariable (MacString, &gIScsiCHAPAuthInfoGuid, 0, 0, NULL); } FreePool (DeviceList); @@ -295,6 +292,7 @@ IScsiUpdateDeviceList ( // DeviceListSize = sizeof (ISCSI_DEVICE_LIST) + (NumHandles - 1) * sizeof (ISCSI_MAC_INFO); DeviceList = (ISCSI_DEVICE_LIST *) AllocatePool (DeviceListSize); + ASSERT (DeviceList != NULL); DeviceList->NumDevice = (UINT8) NumHandles; for (Index = 0; Index < NumHandles; Index++) { @@ -308,7 +306,7 @@ IScsiUpdateDeviceList ( gRT->SetVariable ( L"iSCSIDeviceList", - &mVendorGuid, + &gIp4IScsiConfigGuid, ISCSI_CONFIG_VAR_ATTR, DeviceListSize, DeviceList @@ -447,7 +445,7 @@ IScsiConvertDeviceConfigDataToIfrNvData ( would result in this type of error. In this case, the Progress parameter would be - set to NULL. + set to NULL. @retval EFI_NOT_FOUND Routing data doesn't match any known driver. Progress set to the first character in the routing header. @@ -488,7 +486,7 @@ IScsiFormExtractConfig ( } *Progress = Request; - if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &mVendorGuid, mVendorStorageName)) { + if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gIp4IScsiConfigGuid, mVendorStorageName)) { return EFI_NOT_FOUND; } @@ -532,7 +530,7 @@ IScsiFormExtractConfig ( // Allocate and fill a buffer large enough to hold the template // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator // - ConfigRequestHdr = HiiConstructConfigHdr (&mVendorGuid, mVendorStorageName, Private->DriverHandle); + ConfigRequestHdr = HiiConstructConfigHdr (&gIp4IScsiConfigGuid, mVendorStorageName, Private->DriverHandle); Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); ConfigRequest = AllocateZeroPool (Size); ASSERT (ConfigRequest != NULL); @@ -581,7 +579,7 @@ IScsiFormExtractConfig ( @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. @param[in] Configuration A null-terminated Unicode string in - format. + format. @param[out] Progress A pointer to a string filled in with the offset of the most recent '&' before the first failing name / value pair (or the @@ -591,7 +589,7 @@ IScsiFormExtractConfig ( successful. @retval EFI_SUCCESS The results have been distributed or are - awaiting distribution. + awaiting distribution. @retval EFI_OUT_OF_RESOURCES Not enough memory to store the parts of the results that must be stored awaiting possible future @@ -618,7 +616,7 @@ IScsiFormRouteConfig ( // Check routing data in . // Note: if only one Storage is used, then this checking could be skipped. // - if (!HiiIsConfigHdrMatch (Configuration, &mVendorGuid, mVendorStorageName)) { + if (!HiiIsConfigHdrMatch (Configuration, &gIp4IScsiConfigGuid, mVendorStorageName)) { *Progress = Configuration; return EFI_NOT_FOUND; } @@ -636,7 +634,7 @@ IScsiFormRouteConfig ( @param[in] Action Specifies the type of action taken by the browser. @param[in] QuestionId A unique value which is sent to the original exporting driver so that it can identify the type - of data to expect. The format of the data tends to + of data to expect. The format of the data tends to vary based on the opcode that enerated the callback. @param[in] Type The type of value for the question. @param[in] Value A pointer to the data being sent to the original @@ -650,8 +648,8 @@ IScsiFormRouteConfig ( @retval EFI_DEVICE_ERROR The variable could not be saved. @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.Currently not implemented. - @retval EFI_INVALID_PARAMETERS Passing in wrong parameter. - @retval Others Other errors as indicated. + @retval EFI_INVALID_PARAMETERS Passing in wrong parameter. + @retval Others Other errors as indicated. **/ EFI_STATUS EFIAPI @@ -680,19 +678,39 @@ IScsiFormCallback ( EFI_STATUS Status; EFI_INPUT_KEY Key; + if (Action != EFI_BROWSER_ACTION_CHANGING && Action != EFI_BROWSER_ACTION_CHANGED) { + return EFI_UNSUPPORTED; + } + + Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); + // + // Retrieve uncommitted data from Browser + // + IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA)); + ASSERT (IfrNvData != NULL); + if (!HiiGetBrowserData (&gIp4IScsiConfigGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData)) { + FreePool (IfrNvData); + return EFI_NOT_FOUND; + } + Status = EFI_SUCCESS; + if (Action == EFI_BROWSER_ACTION_CHANGING) { - Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); - // - // Retrive uncommitted data from Browser - // - IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA)); - ASSERT (IfrNvData != NULL); - if (!HiiGetBrowserData (&mVendorGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData)) { - FreePool (IfrNvData); - return EFI_NOT_FOUND; - } - Status = EFI_SUCCESS; + if ((QuestionId >= KEY_DEVICE_ENTRY_BASE) && (QuestionId < (mNumberOfIScsiDevices + KEY_DEVICE_ENTRY_BASE))) { + // + // In case goto the device configuration form, update the device form title. + // + ConfigFormEntry = IScsiGetConfigFormEntryByIndex ((UINT32) (QuestionId - KEY_DEVICE_ENTRY_BASE)); + ASSERT (ConfigFormEntry != NULL); + + UnicodeSPrint (PortString, (UINTN) sizeof (PortString), L"Port %s", ConfigFormEntry->MacString); + DeviceFormTitleToken = (EFI_STRING_ID) STR_ISCSI_DEVICE_FORM_TITLE; + HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString, NULL); + + IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry, IfrNvData); + Private->Current = ConfigFormEntry; + } + } else if (Action == EFI_BROWSER_ACTION_CHANGED) { switch (QuestionId) { case KEY_INITIATOR_NAME: IScsiUnicodeStrToAsciiStr (IfrNvData->InitiatorName, IScsiName); @@ -703,12 +721,15 @@ IScsiFormCallback ( CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL); } + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; break; case KEY_LOCAL_IP: IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String); Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4); - if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { + if (EFI_ERROR (Status) || + ((Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) && + !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL); Status = EFI_INVALID_PARAMETER; } else { @@ -732,7 +753,10 @@ IScsiFormCallback ( case KEY_GATE_WAY: IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String); Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4); - if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) { + if (EFI_ERROR (Status) || + ((Gateway.Addr[0] != 0) && + (Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) && + !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL); Status = EFI_INVALID_PARAMETER; } else { @@ -744,7 +768,7 @@ IScsiFormCallback ( case KEY_TARGET_IP: IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String); Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4); - if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { + if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST (EFI_NTOHL(HostIp.v4)) || IP4_IS_UNSPECIFIED (EFI_NTOHL(HostIp.v4))) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL); Status = EFI_INVALID_PARAMETER; } else { @@ -759,7 +783,7 @@ IScsiFormCallback ( if (EFI_ERROR (Status)) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL); } else { - AsciiStrCpy (Private->Current->SessionConfigData.TargetName, IScsiName); + AsciiStrCpyS (Private->Current->SessionConfigData.TargetName, ISCSI_NAME_MAX_SIZE, IScsiName); } break; @@ -848,11 +872,28 @@ IScsiFormCallback ( // if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) { CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4)); - if (!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { + if (IP4_IS_UNSPECIFIED (NTOHL (HostIp.Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (HostIp.Addr[0]))) { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Target IP is invalid!", NULL); Status = EFI_INVALID_PARAMETER; break; } + + // + // Validate iSCSI target name configuration again: + // The format of iSCSI target name is already verified when user input the name; + // here we only check the case user does not input the name. + // + if (Private->Current->SessionConfigData.TargetName[0] == '\0') { + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + L"iSCSI target name is NULL!", + NULL + ); + Status = EFI_INVALID_PARAMETER; + break; + } + } if (IfrNvData->CHAPType != ISCSI_CHAP_NONE) { @@ -884,50 +925,29 @@ IScsiFormCallback ( BufferSize = sizeof (Private->Current->AuthConfigData); gRT->SetVariable ( Private->Current->MacString, - &mIScsiCHAPAuthInfoGuid, + &gIScsiCHAPAuthInfoGuid, ISCSI_CONFIG_VAR_ATTR, BufferSize, &Private->Current->AuthConfigData ); - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; break; default: - if ((QuestionId >= KEY_DEVICE_ENTRY_BASE) && (QuestionId < (mNumberOfIScsiDevices + KEY_DEVICE_ENTRY_BASE))) { - // - // In case goto the device configuration form, update the device form title. - // - ConfigFormEntry = IScsiGetConfigFormEntryByIndex ((UINT32) (QuestionId - KEY_DEVICE_ENTRY_BASE)); - ASSERT (ConfigFormEntry != NULL); - - UnicodeSPrint (PortString, (UINTN) 128, L"Port %s", ConfigFormEntry->MacString); - DeviceFormTitleToken = (EFI_STRING_ID) STR_ISCSI_DEVICE_FORM_TITLE; - HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString, NULL); - - IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry, IfrNvData); - - Private->Current = ConfigFormEntry; - } - break; } + } - if (!EFI_ERROR (Status)) { - // - // Pass changed uncommitted data back to Form Browser - // - HiiSetBrowserData (&mVendorGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData, NULL); - } - - FreePool (IfrNvData); - - return Status; + if (!EFI_ERROR (Status)) { + // + // Pass changed uncommitted data back to Form Browser + // + HiiSetBrowserData (&gIp4IScsiConfigGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData, NULL); } - // - // All other action return unsupported. - // - return EFI_UNSUPPORTED; + FreePool (IfrNvData); + + return Status; } /** @@ -1013,12 +1033,12 @@ IScsiConfigUpdateForm ( ); if (EFI_ERROR (Status)) { ZeroMem (&ConfigFormEntry->SessionConfigData, sizeof (ConfigFormEntry->SessionConfigData)); - + // // Generate OUI-format ISID based on MAC address. // CopyMem (ConfigFormEntry->SessionConfigData.IsId, &MacAddress, 6); - ConfigFormEntry->SessionConfigData.IsId[0] = + ConfigFormEntry->SessionConfigData.IsId[0] = (UINT8) (ConfigFormEntry->SessionConfigData.IsId[0] & 0x3F); } // @@ -1027,7 +1047,7 @@ IScsiConfigUpdateForm ( BufferSize = sizeof (ConfigFormEntry->AuthConfigData); Status = gRT->GetVariable ( ConfigFormEntry->MacString, - &mIScsiCHAPAuthInfoGuid, + &gIScsiCHAPAuthInfoGuid, NULL, &BufferSize, &ConfigFormEntry->AuthConfigData @@ -1038,13 +1058,13 @@ IScsiConfigUpdateForm ( // // Compose the Port string and create a new EFI_STRING_ID. // - UnicodeSPrint (PortString, 128, L"Port %s", ConfigFormEntry->MacString); + UnicodeSPrint (PortString, sizeof (PortString), L"Port %s", ConfigFormEntry->MacString); ConfigFormEntry->PortTitleToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL); // // Compose the help string of this port and create a new EFI_STRING_ID. // - UnicodeSPrint (PortString, 128, L"Set the iSCSI parameters on port %s", ConfigFormEntry->MacString); + UnicodeSPrint (PortString, sizeof (PortString), L"Set the iSCSI parameters on port %s", ConfigFormEntry->MacString); ConfigFormEntry->PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL); InsertTailList (&mIScsiConfigFormList, &ConfigFormEntry->Link); @@ -1056,6 +1076,7 @@ IScsiConfigUpdateForm ( mNumberOfIScsiDevices--; RemoveEntryList (&ConfigFormEntry->Link); FreePool (ConfigFormEntry); + mCallbackInfo->Current = NULL; } // // Allocate space for creation of Buffer @@ -1102,7 +1123,7 @@ IScsiConfigUpdateForm ( HiiUpdateForm ( mCallbackInfo->RegisteredHandle, - &mVendorGuid, + &gIp4IScsiConfigGuid, FORMID_MAIN_FORM, StartOpCodeHandle, // Label DEVICE_ENTRY_LABEL EndOpCodeHandle // LABEL_END @@ -1168,14 +1189,14 @@ IScsiConfigFormInit ( NULL ); ASSERT_EFI_ERROR (Status); - + // // Publish our HII data // CallbackInfo->RegisteredHandle = HiiAddPackages ( - &mVendorGuid, + &gIp4IScsiConfigGuid, CallbackInfo->DriverHandle, - IScsiDxeStrings, + IScsi4DxeStrings, IScsiConfigDxeBin, NULL ); @@ -1195,7 +1216,7 @@ IScsiConfigFormInit ( free the resources used. @param[in] DriverBindingHandle The iSCSI driverbinding handle. - + @retval EFI_SUCCESS The iSCSI configuration form is unloaded. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. **/