X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIScsiDxe%2FIScsiConfig.c;h=cb1eff1b690cc8494bc631e6f3e2c0497f64e992;hp=4c42a560b71ea3738a4cee201375161bbbea1c52;hb=d1102dba7210b95e41d06c2338a22ba6af248645;hpb=6c7a807a54b14827a6510baa5edfdbe8b5f1f085 diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c index 4c42a560b7..cb1eff1b69 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c @@ -1,8 +1,8 @@ /** @file - Helper functions for configuring or getting the parameters relating to ISCSI + Helper functions for configuring or getting the parameters relating to iSCSI. -Copyright (c) 2004 - 2008, Intel Corporation -All rights reserved. This program and the accompanying materials +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 http://opensource.org/licenses/bsd-license.php @@ -10,19 +10,11 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - IScsiConfig.c - -Abstract: - - Helper functions for configuring or getting the parameters relating to ISCSI - **/ #include "IScsiImpl.h" -EFI_GUID mVendorGuid = ISCSI_CONFIG_GUID; +CHAR16 mVendorStorageName[] = L"ISCSI_CONFIG_IFR_NVDATA"; BOOLEAN mIScsiDeviceListUpdated = FALSE; UINTN mNumberOfIScsiDevices = 0; ISCSI_FORM_CALLBACK_INFO *mCallbackInfo = NULL; @@ -32,17 +24,34 @@ LIST_ENTRY mIScsiConfigFormList = { &mIScsiConfigFormList }; +HII_VENDOR_DEVICE_PATH mIScsiHiiVendorDevicePath = { + { + { + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + { + (UINT8) (sizeof (VENDOR_DEVICE_PATH)), + (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) + } + }, + IP4_ISCSI_CONFIG_GUID + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + (UINT8) (END_DEVICE_PATH_LENGTH), + (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) + } + } +}; + /** Convert the IPv4 address into a dotted string. - @param Ip[in] The IPv4 address. - - @param Str[out] The dotted IP string. - - @retval None. - + @param[in] Ip The IPv4 address. + @param[out] Str The dotted IP string. **/ -STATIC VOID IScsiIpToStr ( IN EFI_IPv4_ADDRESS *Ip, @@ -52,33 +61,128 @@ IScsiIpToStr ( UnicodeSPrint ( Str, 2 * IP4_STR_MAX_SIZE, L"%d.%d.%d.%d", Ip->Addr[0], Ip->Addr[1], Ip->Addr[2], Ip->Addr[3]); } + /** - Pop up an invalid notify which displays the message in Warning. + Parse IsId in string format and convert it to binary. - @param Warning[in] The warning message. + @param[in] String The buffer of the string to be parsed. + @param[in, out] IsId The buffer to store IsId. - @retval None. + @retval EFI_SUCCESS The operation finished successfully. + @retval EFI_INVALID_PARAMETER Any input parameter is invalid. **/ -VOID -PopUpInvalidNotify ( - IN CHAR16 *Warning +EFI_STATUS +IScsiParseIsIdFromString ( + IN CONST CHAR16 *String, + IN OUT UINT8 *IsId ) { - EFI_INPUT_KEY Key; + UINT8 Index; + CHAR16 *IsIdStr; + CHAR16 TempStr[3]; + UINTN NodeVal; + CHAR16 PortString[ISCSI_NAME_IFR_MAX_SIZE]; + EFI_INPUT_KEY Key; + + if ((String == NULL) || (IsId == NULL)) { + return EFI_INVALID_PARAMETER; + } + + IsIdStr = (CHAR16 *) String; + + if (StrLen (IsIdStr) != 6) { + UnicodeSPrint ( + PortString, + (UINTN) sizeof (PortString), + L"Error! Input is incorrect, please input 6 hex numbers!\n" + ); + + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + PortString, + NULL + ); + + return EFI_INVALID_PARAMETER; + } - IfrLibCreatePopUp (1, &Key, Warning); + for (Index = 3; Index < 6; Index++) { + CopyMem (TempStr, IsIdStr, sizeof (TempStr)); + TempStr[2] = L'\0'; + + // + // Convert the string to IsId. StrHexToUintn stops at the first character + // that is not a valid hex character, '\0' here. + // + NodeVal = StrHexToUintn (TempStr); + + IsId[Index] = (UINT8) NodeVal; + + IsIdStr = IsIdStr + 2; + } + + return EFI_SUCCESS; } /** - Update the list of iSCSI devices the iSCSI driver is controlling. + Convert IsId from binary to string format. - @param None. + @param[out] String The buffer to store the converted string. + @param[in] IsId The buffer to store IsId. - @retval None. + @retval EFI_SUCCESS The string converted successfully. + @retval EFI_INVALID_PARAMETER Any input parameter is invalid. **/ EFI_STATUS +IScsiConvertIsIdToString ( + OUT CHAR16 *String, + IN UINT8 *IsId + ) +{ + UINT8 Index; + UINTN Number; + + if ((String == NULL) || (IsId == NULL)) { + return EFI_INVALID_PARAMETER; + } + + for (Index = 0; Index < 6; Index++) { + if (IsId[Index] <= 0xF) { + Number = UnicodeSPrint ( + String, + 2 * ISID_CONFIGURABLE_STORAGE, + L"0%X", + (UINTN) IsId[Index] + ); + } else { + Number = UnicodeSPrint ( + String, + 2 * ISID_CONFIGURABLE_STORAGE, + L"%X", + (UINTN) IsId[Index] + ); + + } + + String = String + Number; + } + + *String = L'\0'; + + return EFI_SUCCESS; +} + + +/** + 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. +**/ +EFI_STATUS IScsiUpdateDeviceList ( VOID ) @@ -91,19 +195,20 @@ IScsiUpdateDeviceList ( UINTN HandleIndex; UINTN Index; UINTN LastDeviceIndex; - EFI_SIMPLE_NETWORK_PROTOCOL *Snp; - EFI_SIMPLE_NETWORK_MODE *Mode; + EFI_MAC_ADDRESS MacAddress; + UINTN HwAddressSize; + UINT16 VlanId; ISCSI_MAC_INFO *CurMacInfo; ISCSI_MAC_INFO TempMacInfo; - CHAR16 MacString[65]; + CHAR16 MacString[70]; UINTN DeviceListSize; // - // Dump all the handles the Simple Network Protocol is installed on. + // Dump all the handles the Managed Network Service Binding Protocol is installed on. // Status = gBS->LocateHandleBuffer ( ByProtocol, - &gEfiSimpleNetworkProtocolGuid, + &gEfiManagedNetworkServiceBindingProtocolGuid, NULL, &NumHandles, &Handles @@ -115,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 @@ -134,14 +240,15 @@ IScsiUpdateDeviceList ( LastDeviceIndex = 0; for (HandleIndex = 0; HandleIndex < NumHandles; HandleIndex++) { - gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp); - - Mode = Snp->Mode; + Status = NetLibGetMacAddress (Handles[HandleIndex], &MacAddress, &HwAddressSize); + ASSERT (Status == EFI_SUCCESS); + VlanId = NetLibGetVlanId (Handles[HandleIndex]); for (Index = LastDeviceIndex; Index < DeviceList->NumDevice; Index++) { CurMacInfo = &DeviceList->MacInfo[Index]; - if ((CurMacInfo->Len == Mode->HwAddressSize) && - (NET_MAC_EQUAL (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize)) + if ((CurMacInfo->Len == HwAddressSize) && + (CurMacInfo->VlanId == VlanId) && + (NET_MAC_EQUAL (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize)) ) { // // The previous configured NIC is still here. @@ -170,14 +277,14 @@ IScsiUpdateDeviceList ( // delete the variables // CurMacInfo = &DeviceList->MacInfo[Index]; - IScsiMacAddrToStr (&CurMacInfo->Mac, CurMacInfo->Len, MacString); + 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); } - gBS->FreePool (DeviceList); + FreePool (DeviceList); } else if (Status != EFI_NOT_FOUND) { - gBS->FreePool (Handles); + FreePool (Handles); return Status; } // @@ -185,27 +292,28 @@ 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++) { - gBS->HandleProtocol (Handles[Index], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp); - Mode = Snp->Mode; + NetLibGetMacAddress (Handles[Index], &MacAddress, &HwAddressSize); CurMacInfo = &DeviceList->MacInfo[Index]; - CopyMem (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize); - CurMacInfo->Len = (UINT8) Mode->HwAddressSize; + CopyMem (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize); + CurMacInfo->Len = (UINT8) HwAddressSize; + CurMacInfo->VlanId = NetLibGetVlanId (Handles[Index]); } gRT->SetVariable ( L"iSCSIDeviceList", - &mVendorGuid, + &gIp4IScsiConfigGuid, ISCSI_CONFIG_VAR_ATTR, DeviceListSize, DeviceList ); - gBS->FreePool (DeviceList); - gBS->FreePool (Handles); + FreePool (DeviceList); + FreePool (Handles); return Status; } @@ -213,12 +321,10 @@ IScsiUpdateDeviceList ( /** Get the iSCSI configuration form entry by the index of the goto opcode actived. - @param Index[in] The 0-based index of the goto opcode actived. - - @retval The iSCSI configuration form entry found. + @param[in] Index The 0-based index of the goto opcode actived. + @return The iSCSI configuration form entry found. **/ -STATIC ISCSI_CONFIG_FORM_ENTRY * IScsiGetConfigFormEntryByIndex ( IN UINT32 Index @@ -246,18 +352,14 @@ IScsiGetConfigFormEntryByIndex ( /** Convert the iSCSI configuration data into the IFR data. - @param ConfigFormEntry[in] The iSCSI configuration form entry. - - @param IfrNvData[in] The IFR nv data. - - @retval None. + @param[in] ConfigFormEntry The iSCSI configuration form entry. + @param[out] IfrNvData The IFR nv data. **/ -STATIC VOID IScsiConvertDeviceConfigDataToIfrNvData ( - IN ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry, - IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData + IN ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry, + OUT ISCSI_CONFIG_IFR_NVDATA *IfrNvData ) { ISCSI_SESSION_CONFIG_NVDATA *SessionConfigData; @@ -282,6 +384,8 @@ IScsiConvertDeviceConfigDataToIfrNvData ( IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->BootLun); + IScsiConvertIsIdToString (IfrNvData->IsId, SessionConfigData->IsId); + // // CHAP authentication parameters. // @@ -296,31 +400,66 @@ IScsiConvertDeviceConfigDataToIfrNvData ( } /** - This function allows a caller to extract the current configuration for one - or more named elements from the target driver. - - @param This[in] Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. - - @param Request[in] A null-terminated Unicode string in format. - - @param Progress[out] On return, points to a character in the Request string. - Points to the string's null terminator if request was successful. - Points to the most recent '&' before the first failing name/value - pair (or the beginning of the string if the failure is in the - first name/value pair) if the request was not successful. - - @param Results[out] A null-terminated Unicode string in format which - has all values filled in for the names in the Request string. - String to be allocated by the called function. - - @retval EFI_SUCCESS The Results is filled with the requested values. - - @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results. - - @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name. - - @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver. - + This function allows the caller to request the current + configuration for one or more named elements. The resulting + string is in format. Any and all alternative + configuration strings shall also be appended to the end of the + current configuration string. If they are, they must appear + after the current configuration. They must contain the same + routing (GUID, NAME, PATH) as the current configuration string. + They must have an additional description indicating the type of + alternative configuration the string represents, + "ALTCFG=". That (when + converted from Hex UNICODE to binary) is a reference to a + string in the associated string pack. + + @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. + @param[in] Request A null-terminated Unicode string in + format. Note that this + includes the routing information as well as + the configurable name / value pairs. It is + invalid for this string to be in + format. + @param[out] Progress On return, points to a character in the + Request string. Points to the string's null + terminator if request was successful. Points + to the most recent "&" before the first + failing name / value pair (or the beginning + of the string if the failure is in the first + name / value pair) if the request was not + successful. + @param[out] Results A null-terminated Unicode string in + format which has all values + filled in for the names in the Request string. + String to be allocated by the called function. + + @retval EFI_SUCCESS The Results string is filled with the + values corresponding to all requested + names. + @retval EFI_OUT_OF_RESOURCES Not enough memory to store the + parts of the results that must be + stored awaiting possible future + protocols. + @retval EFI_INVALID_PARAMETER For example, passing in a NULL + for the Request parameter + would result in this type of + error. In this case, the + Progress parameter would be + 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. + Note: There is no requirement that the + driver validate the routing data. It + must skip the in order to + process the names. + @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set + to most recent & before the + error or the beginning of the + string. + @retval EFI_INVALID_PARAMETER Unknown name. Progress points + to the & before the name in + question.Currently not implemented. **/ EFI_STATUS EFIAPI @@ -332,11 +471,29 @@ IScsiFormExtractConfig ( ) { EFI_STATUS Status; - CHAR8 InitiatorName[ISCSI_NAME_IFR_MAX_SIZE]; + CHAR8 InitiatorName[ISCSI_NAME_MAX_SIZE]; UINTN BufferSize; ISCSI_CONFIG_IFR_NVDATA *IfrNvData; ISCSI_FORM_CALLBACK_INFO *Private; EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + EFI_STRING ConfigRequestHdr; + EFI_STRING ConfigRequest; + BOOLEAN AllocatedRequest; + UINTN Size; + + if (Progress == NULL || Results == NULL) { + return EFI_INVALID_PARAMETER; + } + + *Progress = Request; + if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gIp4IScsiConfigGuid, mVendorStorageName)) { + return EFI_NOT_FOUND; + } + + ConfigRequestHdr = NULL; + ConfigRequest = NULL; + AllocatedRequest = FALSE; + Size = 0; if (!mIScsiDeviceListUpdated) { // @@ -353,7 +510,7 @@ IScsiFormExtractConfig ( IScsiConvertDeviceConfigDataToIfrNvData (Private->Current, IfrNvData); } - BufferSize = ISCSI_NAME_IFR_MAX_SIZE; + BufferSize = ISCSI_NAME_MAX_SIZE; Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize, InitiatorName); if (EFI_ERROR (Status)) { IfrNvData->InitiatorName[0] = L'\0'; @@ -366,36 +523,82 @@ IScsiFormExtractConfig ( // HiiConfigRouting = Private->ConfigRouting; BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA); + ConfigRequest = Request; + if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) { + // + // Request has no request element, construct full request string. + // Allocate and fill a buffer large enough to hold the template + // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator + // + ConfigRequestHdr = HiiConstructConfigHdr (&gIp4IScsiConfigGuid, mVendorStorageName, Private->DriverHandle); + Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); + ConfigRequest = AllocateZeroPool (Size); + ASSERT (ConfigRequest != NULL); + AllocatedRequest = TRUE; + UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize); + FreePool (ConfigRequestHdr); + } Status = HiiConfigRouting->BlockToConfig ( HiiConfigRouting, - Request, + ConfigRequest, (UINT8 *) IfrNvData, BufferSize, Results, Progress ); - gBS->FreePool (IfrNvData); + FreePool (IfrNvData); + // + // Free the allocated config request string. + // + if (AllocatedRequest) { + FreePool (ConfigRequest); + ConfigRequest = NULL; + } + + // + // Set Progress string to the original request string. + // + if (Request == NULL) { + *Progress = NULL; + } else if (StrStr (Request, L"OFFSET") == NULL) { + *Progress = Request + StrLen (Request); + } + return Status; } /** - This function processes the results of changes in configuration. - - @param This[in] Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. - - @param Configuration[in] A null-terminated Unicode string in format. - - @param Progress[out] A pointer to a string filled in with the offset of the most - recent '&' before the first failing name/value pair (or the - beginning of the string if the failure is in the first - name/value pair) or the terminating NULL if all was successful. - - @retval EFI_SUCCESS The Results is processed successfully. - - @retval EFI_INVALID_PARAMETER Configuration is NULL. - - @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver. - + This function applies changes in a driver's configuration. + Input is a Configuration, which has the routing data for this + driver followed by name / value configuration pairs. The driver + must apply those pairs to its configurable storage. If the + driver's configuration is stored in a linear block of data + and the driver's name / value pairs are in + format, it may use the ConfigToBlock helper function (above) to + simplify the job. Currently not implemented. + + @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. + @param[in] Configuration A null-terminated Unicode string in + 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 + beginn ing of the string if the failure + is in the first name / value pair) or + the terminating NULL if all was + successful. + + @retval EFI_SUCCESS The results have been distributed or are + awaiting distribution. + @retval EFI_OUT_OF_RESOURCES Not enough memory to store the + parts of the results that must be + stored awaiting possible future + protocols. + @retval EFI_INVALID_PARAMETERS Passing in a NULL for the + Results parameter would result + in this type of error. + @retval EFI_NOT_FOUND Target for the specified routing data + was not found. **/ EFI_STATUS EFIAPI @@ -405,40 +608,55 @@ IScsiFormRouteConfig ( OUT EFI_STRING *Progress ) { + if (Configuration == NULL || Progress == NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Check routing data in . + // Note: if only one Storage is used, then this checking could be skipped. + // + if (!HiiIsConfigHdrMatch (Configuration, &gIp4IScsiConfigGuid, mVendorStorageName)) { + *Progress = Configuration; + return EFI_NOT_FOUND; + } + + *Progress = Configuration + StrLen (Configuration); return EFI_SUCCESS; } /** - This function processes the results of changes in configuration. - - @param This[in] Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. - - @param Action[in] Specifies the type of action taken by the browser. - - @param QuestionId[in] A unique value which is sent to the original exporting driver - so that it can identify the type of data to expect. - - @param Type[in] The type of value for the question. - - @param Value[in] A pointer to the data being sent to the original exporting driver. - - @param ActionRequest[out] On return, points to the action requested by the callback function. - - @retval EFI_SUCCESS The callback successfully handled the action. - - @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data. - - @retval EFI_DEVICE_ERROR The variable could not be saved. - - @retval EFI_UNSUPPORTED The specified Action is not supported by the callback. - + This function is called to provide results data to the driver. + This data consists of a unique key that is used to identify + which data is either being passed back or being asked for. + + @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL. + @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 + 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 + exporting driver. + @param[out] ActionRequest On return, points to the action requested by the + callback function. + + @retval EFI_SUCCESS The callback successfully handled the action. + @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the + variable and its data. + @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. **/ EFI_STATUS EFIAPI IScsiFormCallback ( IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN EFI_BROWSER_ACTION Action, - IN EFI_QUESTION_ID KeyValue, + IN EFI_QUESTION_ID QuestionId, IN UINT8 Type, IN EFI_IFR_TYPE_VALUE *Value, OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest @@ -446,7 +664,7 @@ IScsiFormCallback ( { ISCSI_FORM_CALLBACK_INFO *Private; UINTN BufferSize; - CHAR8 IScsiName[ISCSI_NAME_IFR_MAX_SIZE]; + CHAR8 IScsiName[ISCSI_NAME_MAX_SIZE]; CHAR16 PortString[128]; CHAR8 Ip4String[IP4_STR_MAX_SIZE]; CHAR8 LunString[ISCSI_LUN_STR_MAX_LEN]; @@ -458,243 +676,277 @@ IScsiFormCallback ( EFI_IP_ADDRESS SubnetMask; EFI_IP_ADDRESS Gateway; EFI_STATUS Status; + EFI_INPUT_KEY Key; - Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); + if (Action != EFI_BROWSER_ACTION_CHANGING && Action != EFI_BROWSER_ACTION_CHANGED) { + return EFI_UNSUPPORTED; + } + Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This); // - // Retrive uncommitted data from Browser + // Retrieve uncommitted data from Browser // - BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA); - IfrNvData = AllocateZeroPool (BufferSize); + IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA)); ASSERT (IfrNvData != NULL); - Status = GetBrowserData (NULL, NULL, &BufferSize, (UINT8 *) IfrNvData); - if (EFI_ERROR (Status)) { - gBS->FreePool (IfrNvData); - return Status; + if (!HiiGetBrowserData (&gIp4IScsiConfigGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData)) { + FreePool (IfrNvData); + return EFI_NOT_FOUND; } + Status = EFI_SUCCESS; - switch (KeyValue) { - case KEY_INITIATOR_NAME: - IScsiUnicodeStrToAsciiStr (IfrNvData->InitiatorName, IScsiName); - BufferSize = AsciiStrLen (IScsiName) + 1; + if (Action == EFI_BROWSER_ACTION_CHANGING) { + 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); - Status = gIScsiInitiatorName.Set (&gIScsiInitiatorName, &BufferSize, IScsiName); - if (EFI_ERROR (Status)) { - PopUpInvalidNotify (L"Invalid iSCSI Name!"); - } + 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); - break; + IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry, IfrNvData); - case KEY_LOCAL_IP: - IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String); - Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4); - if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { - PopUpInvalidNotify (L"Invalid IP address!"); - Status = EFI_INVALID_PARAMETER; - } else { - CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4)); + Private->Current = ConfigFormEntry; } + } else if (Action == EFI_BROWSER_ACTION_CHANGED) { + switch (QuestionId) { + case KEY_INITIATOR_NAME: + IScsiUnicodeStrToAsciiStr (IfrNvData->InitiatorName, IScsiName); + BufferSize = AsciiStrSize (IScsiName); - break; + Status = gIScsiInitiatorName.Set (&gIScsiInitiatorName, &BufferSize, IScsiName); + if (EFI_ERROR (Status)) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL); + } - case KEY_SUBNET_MASK: - IScsiUnicodeStrToAsciiStr (IfrNvData->SubnetMask, Ip4String); - Status = IScsiAsciiStrToIp (Ip4String, &SubnetMask.v4); - if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) { - PopUpInvalidNotify (L"Invalid Subnet Mask!"); - Status = EFI_INVALID_PARAMETER; - } else { - CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4)); - } + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; + break; - break; + case KEY_LOCAL_IP: + IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String); + Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4); + 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 { + CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4)); + } - case KEY_GATE_WAY: - IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String); - Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4); - if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) { - PopUpInvalidNotify (L"Invalid Gateway!"); - Status = EFI_INVALID_PARAMETER; - } else { - CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4)); - } + break; - break; + case KEY_SUBNET_MASK: + IScsiUnicodeStrToAsciiStr (IfrNvData->SubnetMask, Ip4String); + Status = IScsiAsciiStrToIp (Ip4String, &SubnetMask.v4); + if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL); + Status = EFI_INVALID_PARAMETER; + } else { + CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4)); + } - case KEY_TARGET_IP: - IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String); - Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4); - if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { - PopUpInvalidNotify (L"Invalid IP address!"); - Status = EFI_INVALID_PARAMETER; - } else { - CopyMem (&Private->Current->SessionConfigData.TargetIp, &HostIp.v4, sizeof (HostIp.v4)); - } + break; - break; + case KEY_GATE_WAY: + IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String); + Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4); + 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 { + CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4)); + } - case KEY_TARGET_NAME: - IScsiUnicodeStrToAsciiStr (IfrNvData->TargetName, IScsiName); - Status = IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName)); - if (EFI_ERROR (Status)) { - PopUpInvalidNotify (L"Invalid iSCSI Name!"); - } else { - AsciiStrCpy (Private->Current->SessionConfigData.TargetName, IScsiName); - } + break; - break; + case KEY_TARGET_IP: + IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String); + Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4); + 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 { + CopyMem (&Private->Current->SessionConfigData.TargetIp, &HostIp.v4, sizeof (HostIp.v4)); + } - case KEY_DHCP_ENABLE: - if (IfrNvData->InitiatorInfoFromDhcp == 0) { - IfrNvData->TargetInfoFromDhcp = 0; - } + break; - break; + case KEY_TARGET_NAME: + IScsiUnicodeStrToAsciiStr (IfrNvData->TargetName, IScsiName); + Status = IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName)); + if (EFI_ERROR (Status)) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL); + } else { + AsciiStrCpyS (Private->Current->SessionConfigData.TargetName, ISCSI_NAME_MAX_SIZE, IScsiName); + } - case KEY_BOOT_LUN: - IScsiUnicodeStrToAsciiStr (IfrNvData->BootLun, LunString); - Status = IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun); - if (EFI_ERROR (Status)) { - PopUpInvalidNotify (L"Invalid LUN string!"); - } else { - CopyMem (Private->Current->SessionConfigData.BootLun, &Lun, sizeof (Lun)); - } + break; + + case KEY_DHCP_ENABLE: + if (IfrNvData->InitiatorInfoFromDhcp == 0) { + IfrNvData->TargetInfoFromDhcp = 0; + } + + break; + + case KEY_BOOT_LUN: + IScsiUnicodeStrToAsciiStr (IfrNvData->BootLun, LunString); + Status = IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun); + if (EFI_ERROR (Status)) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid LUN string!", NULL); + } else { + CopyMem (Private->Current->SessionConfigData.BootLun, &Lun, sizeof (Lun)); + } - break; + break; - case KEY_CHAP_NAME: - IScsiUnicodeStrToAsciiStr (IfrNvData->CHAPName, Private->Current->AuthConfigData.CHAPName); - break; + case KEY_CHAP_NAME: + IScsiUnicodeStrToAsciiStr (IfrNvData->CHAPName, Private->Current->AuthConfigData.CHAPName); + break; - case KEY_CHAP_SECRET: - IScsiUnicodeStrToAsciiStr (IfrNvData->CHAPSecret, Private->Current->AuthConfigData.CHAPSecret); - break; + case KEY_CHAP_SECRET: + IScsiUnicodeStrToAsciiStr (IfrNvData->CHAPSecret, Private->Current->AuthConfigData.CHAPSecret); + break; - case KEY_REVERSE_CHAP_NAME: - IScsiUnicodeStrToAsciiStr (IfrNvData->ReverseCHAPName, Private->Current->AuthConfigData.ReverseCHAPName); - break; + case KEY_REVERSE_CHAP_NAME: + IScsiUnicodeStrToAsciiStr (IfrNvData->ReverseCHAPName, Private->Current->AuthConfigData.ReverseCHAPName); + break; - case KEY_REVERSE_CHAP_SECRET: - IScsiUnicodeStrToAsciiStr (IfrNvData->ReverseCHAPSecret, Private->Current->AuthConfigData.ReverseCHAPSecret); - break; + case KEY_REVERSE_CHAP_SECRET: + IScsiUnicodeStrToAsciiStr (IfrNvData->ReverseCHAPSecret, Private->Current->AuthConfigData.ReverseCHAPSecret); + break; - case KEY_SAVE_CHANGES: - // - // First, update those fields which don't have INTERACTIVE set. - // - Private->Current->SessionConfigData.Enabled = IfrNvData->Enabled; - Private->Current->SessionConfigData.InitiatorInfoFromDhcp = IfrNvData->InitiatorInfoFromDhcp; - Private->Current->SessionConfigData.TargetPort = IfrNvData->TargetPort; - if (Private->Current->SessionConfigData.TargetPort == 0) { - Private->Current->SessionConfigData.TargetPort = ISCSI_WELL_KNOWN_PORT; - } + case KEY_CONFIG_ISID: + IScsiParseIsIdFromString (IfrNvData->IsId, Private->Current->SessionConfigData.IsId); + IScsiConvertIsIdToString (IfrNvData->IsId, Private->Current->SessionConfigData.IsId); - Private->Current->SessionConfigData.TargetInfoFromDhcp = IfrNvData->TargetInfoFromDhcp; - Private->Current->AuthConfigData.CHAPType = IfrNvData->CHAPType; + break; - // - // Only do full parameter validation if iSCSI is enabled on this device. - // - if (Private->Current->SessionConfigData.Enabled) { + case KEY_SAVE_CHANGES: // - // Validate the address configuration of the Initiator if DHCP isn't - // deployed. + // First, update those fields which don't have INTERACTIVE set. // - if (!Private->Current->SessionConfigData.InitiatorInfoFromDhcp) { - CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.LocalIp, sizeof (HostIp.v4)); - CopyMem (&SubnetMask.v4, &Private->Current->SessionConfigData.SubnetMask, sizeof (SubnetMask.v4)); - CopyMem (&Gateway.v4, &Private->Current->SessionConfigData.Gateway, sizeof (Gateway.v4)); - - if ((Gateway.Addr[0] != 0)) { - if (SubnetMask.Addr[0] == 0) { - PopUpInvalidNotify (L"Gateway address is set but subnet mask is zero."); + Private->Current->SessionConfigData.Enabled = IfrNvData->Enabled; + Private->Current->SessionConfigData.InitiatorInfoFromDhcp = IfrNvData->InitiatorInfoFromDhcp; + Private->Current->SessionConfigData.TargetPort = IfrNvData->TargetPort; + if (Private->Current->SessionConfigData.TargetPort == 0) { + Private->Current->SessionConfigData.TargetPort = ISCSI_WELL_KNOWN_PORT; + } + + Private->Current->SessionConfigData.TargetInfoFromDhcp = IfrNvData->TargetInfoFromDhcp; + Private->Current->AuthConfigData.CHAPType = IfrNvData->CHAPType; + + // + // Only do full parameter validation if iSCSI is enabled on this device. + // + if (Private->Current->SessionConfigData.Enabled) { + // + // Validate the address configuration of the Initiator if DHCP isn't + // deployed. + // + if (!Private->Current->SessionConfigData.InitiatorInfoFromDhcp) { + CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.LocalIp, sizeof (HostIp.v4)); + CopyMem (&SubnetMask.v4, &Private->Current->SessionConfigData.SubnetMask, sizeof (SubnetMask.v4)); + CopyMem (&Gateway.v4, &Private->Current->SessionConfigData.Gateway, sizeof (Gateway.v4)); + + if ((Gateway.Addr[0] != 0)) { + if (SubnetMask.Addr[0] == 0) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Gateway address is set but subnet mask is zero.", NULL); + Status = EFI_INVALID_PARAMETER; + break; + } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Local IP and Gateway are not in the same subnet.", NULL); + Status = EFI_INVALID_PARAMETER; + break; + } + } + } + // + // Validate target configuration if DHCP isn't deployed. + // + if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) { + CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4)); + 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; - } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) { - PopUpInvalidNotify (L"Local IP and Gateway are not in the same subnet."); + } + + // + // 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; } - } - } - // - // Validate target configuration if DHCP isn't deployed. - // - if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) { - CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4)); - if (!Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) { - PopUpInvalidNotify (L"Target IP is invalid!"); - Status = EFI_INVALID_PARAMETER; - break; - } - } - if (IfrNvData->CHAPType != ISCSI_CHAP_NONE) { - if ((IfrNvData->CHAPName[0] == '\0') || (IfrNvData->CHAPSecret[0] == '\0')) { - PopUpInvalidNotify (L"CHAP Name or CHAP Secret is invalid!"); - Status = EFI_INVALID_PARAMETER; - break; } - if ((IfrNvData->CHAPType == ISCSI_CHAP_MUTUAL) && - ((IfrNvData->ReverseCHAPName[0] == '\0') || (IfrNvData->ReverseCHAPSecret[0] == '\0')) - ) { - PopUpInvalidNotify (L"Reverse CHAP Name or Reverse CHAP Secret is invalid!"); - Status = EFI_INVALID_PARAMETER; - break; + if (IfrNvData->CHAPType != ISCSI_CHAP_NONE) { + if ((IfrNvData->CHAPName[0] == '\0') || (IfrNvData->CHAPSecret[0] == '\0')) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"CHAP Name or CHAP Secret is invalid!", NULL); + Status = EFI_INVALID_PARAMETER; + break; + } + + if ((IfrNvData->CHAPType == ISCSI_CHAP_MUTUAL) && + ((IfrNvData->ReverseCHAPName[0] == '\0') || (IfrNvData->ReverseCHAPSecret[0] == '\0')) + ) { + CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Reverse CHAP Name or Reverse CHAP Secret is invalid!", NULL); + Status = EFI_INVALID_PARAMETER; + break; + } } } - } - BufferSize = sizeof (Private->Current->SessionConfigData); - gRT->SetVariable ( - Private->Current->MacString, - &gEfiIScsiInitiatorNameProtocolGuid, - ISCSI_CONFIG_VAR_ATTR, - BufferSize, - &Private->Current->SessionConfigData - ); - - BufferSize = sizeof (Private->Current->AuthConfigData); - gRT->SetVariable ( - Private->Current->MacString, - &mIScsiCHAPAuthInfoGuid, - ISCSI_CONFIG_VAR_ATTR, - BufferSize, - &Private->Current->AuthConfigData - ); - *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT; - break; - - default: - if ((KeyValue >= KEY_DEVICE_ENTRY_BASE) && (KeyValue < (mNumberOfIScsiDevices + KEY_DEVICE_ENTRY_BASE))) { - // - // In case goto the device configuration form, update the device form title. - // - ConfigFormEntry = IScsiGetConfigFormEntryByIndex ((UINT32) (KeyValue - 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; - HiiLibSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString); - - IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry, IfrNvData); + BufferSize = sizeof (Private->Current->SessionConfigData); + gRT->SetVariable ( + Private->Current->MacString, + &gEfiIScsiInitiatorNameProtocolGuid, + ISCSI_CONFIG_VAR_ATTR, + BufferSize, + &Private->Current->SessionConfigData + ); + + BufferSize = sizeof (Private->Current->AuthConfigData); + gRT->SetVariable ( + Private->Current->MacString, + &gIScsiCHAPAuthInfoGuid, + ISCSI_CONFIG_VAR_ATTR, + BufferSize, + &Private->Current->AuthConfigData + ); + *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY; + break; - Private->Current = ConfigFormEntry; + default: + break; } - - break; } if (!EFI_ERROR (Status)) { // // Pass changed uncommitted data back to Form Browser // - BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA); - Status = SetBrowserData (NULL, NULL, BufferSize, (UINT8 *) IfrNvData, NULL); + HiiSetBrowserData (&gIp4IScsiConfigGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData, NULL); } - gBS->FreePool (IfrNvData); + FreePool (IfrNvData); + return Status; } @@ -702,16 +954,13 @@ IScsiFormCallback ( Updates the iSCSI configuration form to add/delete an entry for the iSCSI device specified by the Controller. - @param DriverBindingHandle[in] The driverbinding handle. - - @param Controller[in] The controller handle of the iSCSI device. - - @param AddForm[in] Whether to add or delete a form entry. + @param[in] DriverBindingHandle The driverbinding handle. + @param[in] Controller The controller handle of the iSCSI device. + @param[in] AddForm Whether to add or delete a form entry. @retval EFI_SUCCESS The iSCSI configuration form is updated. - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. - + @retval Others Other errors as indicated. **/ EFI_STATUS IScsiConfigUpdateForm ( @@ -724,12 +973,16 @@ IScsiConfigUpdateForm ( ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry; BOOLEAN EntryExisted; EFI_STATUS Status; - EFI_HII_UPDATE_DATA UpdateData; - EFI_SIMPLE_NETWORK_PROTOCOL *Snp; + EFI_MAC_ADDRESS MacAddress; + UINTN HwAddressSize; + UINT16 VlanId; CHAR16 PortString[128]; UINT16 FormIndex; UINTN BufferSize; - + VOID *StartOpCodeHandle; + VOID *EndOpCodeHandle; + EFI_IFR_GUID_LABEL *StartLabel; + EFI_IFR_GUID_LABEL *EndLabel; ConfigFormEntry = NULL; EntryExisted = FALSE; @@ -759,17 +1012,13 @@ IScsiConfigUpdateForm ( ConfigFormEntry->Controller = Controller; // - // Get the simple network protocol and convert the MAC address into - // the formatted string. + // Get the MAC address and convert it into the formatted string. // - Status = gBS->HandleProtocol ( - Controller, - &gEfiSimpleNetworkProtocolGuid, - (VOID **)&Snp - ); + Status = NetLibGetMacAddress (Controller, &MacAddress, &HwAddressSize); ASSERT (Status == EFI_SUCCESS); + VlanId = NetLibGetVlanId (Controller); - IScsiMacAddrToStr (&Snp->Mode->PermanentAddress, Snp->Mode->HwAddressSize, ConfigFormEntry->MacString); + IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, ConfigFormEntry->MacString); // // Get the normal session configuration data. @@ -784,6 +1033,13 @@ 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] = + (UINT8) (ConfigFormEntry->SessionConfigData.IsId[0] & 0x3F); } // // Get the CHAP authentication configuration data. @@ -791,7 +1047,7 @@ IScsiConfigUpdateForm ( BufferSize = sizeof (ConfigFormEntry->AuthConfigData); Status = gRT->GetVariable ( ConfigFormEntry->MacString, - &mIScsiCHAPAuthInfoGuid, + &gIScsiCHAPAuthInfoGuid, NULL, &BufferSize, &ConfigFormEntry->AuthConfigData @@ -802,14 +1058,14 @@ IScsiConfigUpdateForm ( // // Compose the Port string and create a new EFI_STRING_ID. // - UnicodeSPrint (PortString, 128, L"Port %s", ConfigFormEntry->MacString); - HiiLibNewString (mCallbackInfo->RegisteredHandle, &ConfigFormEntry->PortTitleToken, PortString); + 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); - HiiLibNewString (mCallbackInfo->RegisteredHandle, &ConfigFormEntry->PortTitleHelpToken, PortString); + 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); mNumberOfIScsiDevices++; @@ -819,41 +1075,62 @@ IScsiConfigUpdateForm ( mNumberOfIScsiDevices--; RemoveEntryList (&ConfigFormEntry->Link); - gBS->FreePool (ConfigFormEntry); + FreePool (ConfigFormEntry); + mCallbackInfo->Current = NULL; } // // Allocate space for creation of Buffer // - UpdateData.BufferSize = 0x1000; - UpdateData.Data = AllocateZeroPool (0x1000); - UpdateData.Offset = 0; + + // + // Init OpCode Handle + // + StartOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (StartOpCodeHandle != NULL); + + EndOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle != NULL); + + // + // Create Hii Extend Label OpCode as the start opcode + // + StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + StartLabel->Number = DEVICE_ENTRY_LABEL; + + // + // Create Hii Extend Label OpCode as the end opcode + // + EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + EndLabel->Number = LABEL_END; FormIndex = 0; NET_LIST_FOR_EACH (Entry, &mIScsiConfigFormList) { ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, ISCSI_CONFIG_FORM_ENTRY, Link); - CreateGotoOpCode ( - FORMID_DEVICE_FORM, - ConfigFormEntry->PortTitleToken, - ConfigFormEntry->PortTitleHelpToken, - EFI_IFR_FLAG_CALLBACK, - (UINT16)(KEY_DEVICE_ENTRY_BASE + FormIndex), - &UpdateData + HiiCreateGotoOpCode ( + StartOpCodeHandle, // Container for dynamic created opcodes + FORMID_DEVICE_FORM, // Target Form ID + ConfigFormEntry->PortTitleToken, // Prompt text + ConfigFormEntry->PortTitleHelpToken, // Help text + EFI_IFR_FLAG_CALLBACK, // Question flag + (UINT16)(KEY_DEVICE_ENTRY_BASE + FormIndex) // Question ID ); FormIndex++; } - IfrLibUpdateForm ( + HiiUpdateForm ( mCallbackInfo->RegisteredHandle, - &mVendorGuid, + &gIp4IScsiConfigGuid, FORMID_MAIN_FORM, - DEVICE_ENTRY_LABEL, - FALSE, - &UpdateData + StartOpCodeHandle, // Label DEVICE_ENTRY_LABEL + EndOpCodeHandle // LABEL_END ); - gBS->FreePool (UpdateData.Data); + HiiFreeOpCodeHandle (StartOpCodeHandle); + HiiFreeOpCodeHandle (EndOpCodeHandle); return EFI_SUCCESS; } @@ -861,21 +1138,19 @@ IScsiConfigUpdateForm ( /** Initialize the iSCSI configuration form. - @param DriverBindingHandle[in] The iSCSI driverbinding handle. - - @retval EFI_SUCCESS The iSCSI configuration form is initialized. - - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @param[in] DriverBindingHandle The iSCSI driverbinding handle. + @retval EFI_SUCCESS The iSCSI configuration form is initialized. + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory. + @retval Others Other errors as indicated. **/ EFI_STATUS IScsiConfigFormInit ( - IN EFI_HANDLE DriverBindingHandle + VOID ) { EFI_STATUS Status; EFI_HII_DATABASE_PROTOCOL *HiiDatabase; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; ISCSI_FORM_CALLBACK_INFO *CallbackInfo; Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase); @@ -883,7 +1158,7 @@ IScsiConfigFormInit ( return Status; } - CallbackInfo = (ISCSI_FORM_CALLBACK_INFO *) AllocatePool (sizeof (ISCSI_FORM_CALLBACK_INFO)); + CallbackInfo = (ISCSI_FORM_CALLBACK_INFO *) AllocateZeroPool (sizeof (ISCSI_FORM_CALLBACK_INFO)); if (CallbackInfo == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -903,41 +1178,31 @@ IScsiConfigFormInit ( } // - // Create driver handle used by HII database + // Install Device Path Protocol and Config Access protocol to driver handle // - Status = HiiLibCreateHiiDriverHandle (&CallbackInfo->DriverHandle); - if (EFI_ERROR (Status)) { - FreePool(CallbackInfo); - return Status; - } - - // - // Install Config Access protocol to driver handle - // - Status = gBS->InstallProtocolInterface ( + Status = gBS->InstallMultipleProtocolInterfaces ( &CallbackInfo->DriverHandle, + &gEfiDevicePathProtocolGuid, + &mIScsiHiiVendorDevicePath, &gEfiHiiConfigAccessProtocolGuid, - EFI_NATIVE_INTERFACE, - &CallbackInfo->ConfigAccess + &CallbackInfo->ConfigAccess, + NULL ); ASSERT_EFI_ERROR (Status); - + // // Publish our HII data // - PackageList = HiiLibPreparePackageList (2, &mVendorGuid, IScsiDxeStrings, IScsiConfigDxeBin); - ASSERT (PackageList != NULL); - - Status = HiiDatabase->NewPackageList ( - HiiDatabase, - PackageList, - CallbackInfo->DriverHandle, - &CallbackInfo->RegisteredHandle - ); - FreePool (PackageList); - if (EFI_ERROR (Status)) { + CallbackInfo->RegisteredHandle = HiiAddPackages ( + &gIp4IScsiConfigGuid, + CallbackInfo->DriverHandle, + IScsi4DxeStrings, + IScsiConfigDxeBin, + NULL + ); + if (CallbackInfo->RegisteredHandle == NULL) { FreePool(CallbackInfo); - return Status; + return EFI_OUT_OF_RESOURCES; } mCallbackInfo = CallbackInfo; @@ -950,12 +1215,10 @@ IScsiConfigFormInit ( device configuration entries, uninstall the form callback protocol and free the resources used. - @param DriverBindingHandle[in] The iSCSI driverbinding handle. + @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. - **/ EFI_STATUS IScsiConfigFormUnload ( @@ -987,14 +1250,15 @@ IScsiConfigFormUnload ( // // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL // - gBS->UninstallProtocolInterface ( - mCallbackInfo->DriverHandle, - &gEfiHiiConfigAccessProtocolGuid, - &mCallbackInfo->ConfigAccess - ); - HiiLibDestroyHiiDriverHandle (mCallbackInfo->DriverHandle); - - gBS->FreePool (mCallbackInfo); + gBS->UninstallMultipleProtocolInterfaces ( + mCallbackInfo->DriverHandle, + &gEfiDevicePathProtocolGuid, + &mIScsiHiiVendorDevicePath, + &gEfiHiiConfigAccessProtocolGuid, + &mCallbackInfo->ConfigAccess, + NULL + ); + FreePool (mCallbackInfo); return EFI_SUCCESS; }