]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c
Update GenFw help usage information to clarify -z option.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiConfig.c
CommitLineData
12618416 1/** @file\r
55a64ae0 2 Helper functions for configuring or getting the parameters relating to iSCSI.\r
6a690e23 3\r
669314e5 4Copyright (c) 2004 - 2008, Intel Corporation.<BR>\r
7a444476 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
6a690e23 12\r
12618416 13**/\r
6a690e23 14\r
15#include "IScsiImpl.h"\r
16\r
f2a94e25 17EFI_GUID mVendorGuid = ISCSI_CONFIG_GUID;\r
7e3bcccb 18CHAR16 mVendorStorageName[] = L"ISCSI_CONFIG_IFR_NVDATA";\r
f2a94e25 19BOOLEAN mIScsiDeviceListUpdated = FALSE;\r
20UINTN mNumberOfIScsiDevices = 0;\r
21ISCSI_FORM_CALLBACK_INFO *mCallbackInfo = NULL;\r
6a690e23 22\r
e48e37fc 23LIST_ENTRY mIScsiConfigFormList = {\r
6a690e23 24 &mIScsiConfigFormList,\r
25 &mIScsiConfigFormList\r
26};\r
27\r
f6f910dd 28HII_VENDOR_DEVICE_PATH mIScsiHiiVendorDevicePath = {\r
29 {\r
30 {\r
31 HARDWARE_DEVICE_PATH,\r
32 HW_VENDOR_DP,\r
33 {\r
34 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
35 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
36 }\r
37 },\r
38 //\r
39 // {49D7B73E-143D-4716-977B-C45F1CB038CC}\r
40 //\r
41 { 0x49d7b73e, 0x143d, 0x4716, { 0x97, 0x7b, 0xc4, 0x5f, 0x1c, 0xb0, 0x38, 0xcc } }\r
42 },\r
43 {\r
44 END_DEVICE_PATH_TYPE,\r
45 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
46 { \r
47 (UINT8) (END_DEVICE_PATH_LENGTH),\r
48 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
49 }\r
50 }\r
51};\r
52\r
12618416 53/**\r
54 Convert the IPv4 address into a dotted string.\r
55\r
669314e5 56 @param[in] Ip The IPv4 address.\r
57 @param[out] Str The dotted IP string.\r
12618416 58**/\r
6a690e23 59VOID\r
60IScsiIpToStr (\r
61 IN EFI_IPv4_ADDRESS *Ip,\r
62 OUT CHAR16 *Str\r
63 )\r
6a690e23 64{\r
65 UnicodeSPrint ( Str, 2 * IP4_STR_MAX_SIZE, L"%d.%d.%d.%d", Ip->Addr[0], Ip->Addr[1], Ip->Addr[2], Ip->Addr[3]);\r
66}\r
67\r
12618416 68/**\r
6a690e23 69 Update the list of iSCSI devices the iSCSI driver is controlling.\r
669314e5 70 \r
71 @retval EFI_SUCCESS The callback successfully handled the action.\r
963dbb30 72 @retval Others Other errors as indicated. \r
12618416 73**/\r
74EFI_STATUS\r
75IScsiUpdateDeviceList (\r
76 VOID\r
77 )\r
6a690e23 78{\r
79 EFI_STATUS Status;\r
80 ISCSI_DEVICE_LIST *DeviceList;\r
81 UINTN DataSize;\r
82 UINTN NumHandles;\r
83 EFI_HANDLE *Handles;\r
84 UINTN HandleIndex;\r
85 UINTN Index;\r
86 UINTN LastDeviceIndex;\r
87 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
88 EFI_SIMPLE_NETWORK_MODE *Mode;\r
89 ISCSI_MAC_INFO *CurMacInfo;\r
90 ISCSI_MAC_INFO TempMacInfo;\r
91 CHAR16 MacString[65];\r
92 UINTN DeviceListSize;\r
93\r
94 //\r
95 // Dump all the handles the Simple Network Protocol is installed on.\r
96 //\r
97 Status = gBS->LocateHandleBuffer (\r
98 ByProtocol,\r
99 &gEfiSimpleNetworkProtocolGuid,\r
100 NULL,\r
101 &NumHandles,\r
102 &Handles\r
103 );\r
104 if (EFI_ERROR (Status)) {\r
105 return Status;\r
106 }\r
107\r
108 DataSize = 0;\r
109 Status = gRT->GetVariable (\r
110 L"iSCSIDeviceList",\r
111 &mVendorGuid,\r
112 NULL,\r
113 &DataSize,\r
114 NULL\r
115 );\r
116 if (Status == EFI_BUFFER_TOO_SMALL) {\r
e48e37fc 117 DeviceList = (ISCSI_DEVICE_LIST *) AllocatePool (DataSize);\r
6a690e23 118\r
119 gRT->GetVariable (\r
120 L"iSCSIDeviceList",\r
121 &mVendorGuid,\r
122 NULL,\r
123 &DataSize,\r
124 DeviceList\r
125 );\r
126\r
127 LastDeviceIndex = 0;\r
128\r
129 for (HandleIndex = 0; HandleIndex < NumHandles; HandleIndex++) {\r
130 gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
131\r
132 Mode = Snp->Mode;\r
133\r
134 for (Index = LastDeviceIndex; Index < DeviceList->NumDevice; Index++) {\r
135 CurMacInfo = &DeviceList->MacInfo[Index];\r
136 if ((CurMacInfo->Len == Mode->HwAddressSize) &&\r
137 (NET_MAC_EQUAL (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize))\r
138 ) {\r
139 //\r
140 // The previous configured NIC is still here.\r
141 //\r
142 if (Index != LastDeviceIndex) {\r
143 //\r
144 // Swap the current MAC address entry with the one indexed by\r
145 // LastDeviceIndex.\r
146 //\r
e48e37fc 147 CopyMem (&TempMacInfo, CurMacInfo, sizeof (ISCSI_MAC_INFO));\r
148 CopyMem (CurMacInfo, &DeviceList->MacInfo[LastDeviceIndex], sizeof (ISCSI_MAC_INFO));\r
149 CopyMem (&DeviceList->MacInfo[LastDeviceIndex], &TempMacInfo, sizeof (ISCSI_MAC_INFO));\r
6a690e23 150 }\r
151\r
152 LastDeviceIndex++;\r
153 }\r
154 }\r
155\r
156 if (LastDeviceIndex == DeviceList->NumDevice) {\r
157 break;\r
158 }\r
159 }\r
160\r
161 for (Index = LastDeviceIndex; Index < DeviceList->NumDevice; Index++) {\r
162 //\r
163 // delete the variables\r
164 //\r
165 CurMacInfo = &DeviceList->MacInfo[Index];\r
166 IScsiMacAddrToStr (&CurMacInfo->Mac, CurMacInfo->Len, MacString);\r
167 gRT->SetVariable (MacString, &gEfiIScsiInitiatorNameProtocolGuid, 0, 0, NULL);\r
168 gRT->SetVariable (MacString, &mIScsiCHAPAuthInfoGuid, 0, 0, NULL);\r
169 }\r
170\r
e48e37fc 171 gBS->FreePool (DeviceList);\r
6a690e23 172 } else if (Status != EFI_NOT_FOUND) {\r
e48e37fc 173 gBS->FreePool (Handles);\r
6a690e23 174 return Status;\r
175 }\r
176 //\r
177 // Construct the new iSCSI device list.\r
178 //\r
179 DeviceListSize = sizeof (ISCSI_DEVICE_LIST) + (NumHandles - 1) * sizeof (ISCSI_MAC_INFO);\r
e48e37fc 180 DeviceList = (ISCSI_DEVICE_LIST *) AllocatePool (DeviceListSize);\r
6a690e23 181 DeviceList->NumDevice = (UINT8) NumHandles;\r
182\r
183 for (Index = 0; Index < NumHandles; Index++) {\r
184 gBS->HandleProtocol (Handles[Index], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
185 Mode = Snp->Mode;\r
186\r
187 CurMacInfo = &DeviceList->MacInfo[Index];\r
e48e37fc 188 CopyMem (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize);\r
6a690e23 189 CurMacInfo->Len = (UINT8) Mode->HwAddressSize;\r
190 }\r
191\r
192 gRT->SetVariable (\r
193 L"iSCSIDeviceList",\r
194 &mVendorGuid,\r
195 ISCSI_CONFIG_VAR_ATTR,\r
196 DeviceListSize,\r
197 DeviceList\r
198 );\r
199\r
e48e37fc 200 gBS->FreePool (DeviceList);\r
356e635c 201 gBS->FreePool (Handles);\r
6a690e23 202\r
203 return Status;\r
204}\r
205\r
12618416 206/**\r
207 Get the iSCSI configuration form entry by the index of the goto opcode actived.\r
208\r
669314e5 209 @param[in] Index The 0-based index of the goto opcode actived.\r
12618416 210\r
669314e5 211 @return The iSCSI configuration form entry found.\r
12618416 212**/\r
6a690e23 213ISCSI_CONFIG_FORM_ENTRY *\r
214IScsiGetConfigFormEntryByIndex (\r
215 IN UINT32 Index\r
216 )\r
6a690e23 217{\r
218 UINT32 CurrentIndex;\r
e48e37fc 219 LIST_ENTRY *Entry;\r
6a690e23 220 ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry;\r
221\r
222 CurrentIndex = 0;\r
223 ConfigFormEntry = NULL;\r
224\r
225 NET_LIST_FOR_EACH (Entry, &mIScsiConfigFormList) {\r
226 if (CurrentIndex == Index) {\r
227 ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, ISCSI_CONFIG_FORM_ENTRY, Link);\r
228 break;\r
229 }\r
230\r
231 CurrentIndex++;\r
232 }\r
233\r
234 return ConfigFormEntry;\r
235}\r
236\r
12618416 237/**\r
238 Convert the iSCSI configuration data into the IFR data.\r
239\r
c5de0d55 240 @param[in] ConfigFormEntry The iSCSI configuration form entry.\r
241 @param[out] IfrNvData The IFR nv data.\r
12618416 242**/\r
6a690e23 243VOID\r
244IScsiConvertDeviceConfigDataToIfrNvData (\r
c5de0d55 245 IN ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry,\r
246 OUT ISCSI_CONFIG_IFR_NVDATA *IfrNvData\r
6a690e23 247 )\r
6a690e23 248{\r
249 ISCSI_SESSION_CONFIG_NVDATA *SessionConfigData;\r
250 ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfigData;\r
251\r
252 //\r
253 // Normal session configuration parameters.\r
254 //\r
255 SessionConfigData = &ConfigFormEntry->SessionConfigData;\r
256 IfrNvData->Enabled = SessionConfigData->Enabled;\r
257\r
258 IfrNvData->InitiatorInfoFromDhcp = SessionConfigData->InitiatorInfoFromDhcp;\r
259 IfrNvData->TargetInfoFromDhcp = SessionConfigData->TargetInfoFromDhcp;\r
260 IfrNvData->TargetPort = SessionConfigData->TargetPort;\r
261\r
262 IScsiIpToStr (&SessionConfigData->LocalIp, IfrNvData->LocalIp);\r
263 IScsiIpToStr (&SessionConfigData->SubnetMask, IfrNvData->SubnetMask);\r
264 IScsiIpToStr (&SessionConfigData->Gateway, IfrNvData->Gateway);\r
265 IScsiIpToStr (&SessionConfigData->TargetIp, IfrNvData->TargetIp);\r
266\r
267 IScsiAsciiStrToUnicodeStr (SessionConfigData->TargetName, IfrNvData->TargetName);\r
268\r
269 IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->BootLun);\r
270\r
271 //\r
272 // CHAP authentication parameters.\r
273 //\r
274 AuthConfigData = &ConfigFormEntry->AuthConfigData;\r
275\r
276 IfrNvData->CHAPType = AuthConfigData->CHAPType;\r
277\r
278 IScsiAsciiStrToUnicodeStr (AuthConfigData->CHAPName, IfrNvData->CHAPName);\r
279 IScsiAsciiStrToUnicodeStr (AuthConfigData->CHAPSecret, IfrNvData->CHAPSecret);\r
280 IScsiAsciiStrToUnicodeStr (AuthConfigData->ReverseCHAPName, IfrNvData->ReverseCHAPName);\r
281 IScsiAsciiStrToUnicodeStr (AuthConfigData->ReverseCHAPSecret, IfrNvData->ReverseCHAPSecret);\r
282}\r
283\r
12618416 284/**\r
669314e5 285 This function allows the caller to request the current\r
286 configuration for one or more named elements. The resulting\r
287 string is in <ConfigAltResp> format. Any and all alternative\r
288 configuration strings shall also be appended to the end of the\r
289 current configuration string. If they are, they must appear\r
290 after the current configuration. They must contain the same\r
291 routing (GUID, NAME, PATH) as the current configuration string.\r
292 They must have an additional description indicating the type of\r
293 alternative configuration the string represents,\r
294 "ALTCFG=<StringToken>". That <StringToken> (when\r
295 converted from Hex UNICODE to binary) is a reference to a\r
296 string in the associated string pack.\r
297\r
298 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
299 @param[in] Request A null-terminated Unicode string in\r
300 <ConfigRequest> format. Note that this\r
301 includes the routing information as well as\r
302 the configurable name / value pairs. It is\r
303 invalid for this string to be in\r
304 <MultiConfigRequest> format.\r
305 @param[out] Progress On return, points to a character in the\r
306 Request string. Points to the string's null\r
307 terminator if request was successful. Points\r
308 to the most recent "&" before the first\r
309 failing name / value pair (or the beginning\r
310 of the string if the failure is in the first\r
311 name / value pair) if the request was not\r
312 successful.\r
313 @param[out] Results A null-terminated Unicode string in\r
314 <ConfigAltResp> format which has all values\r
315 filled in for the names in the Request string.\r
316 String to be allocated by the called function.\r
317\r
318 @retval EFI_SUCCESS The Results string is filled with the\r
319 values corresponding to all requested\r
320 names.\r
321 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the\r
322 parts of the results that must be\r
323 stored awaiting possible future\r
324 protocols.\r
325 @retval EFI_INVALID_PARAMETER For example, passing in a NULL\r
326 for the Request parameter\r
327 would result in this type of\r
328 error. In this case, the\r
329 Progress parameter would be\r
330 set to NULL. \r
331 @retval EFI_NOT_FOUND Routing data doesn't match any\r
332 known driver. Progress set to the\r
333 first character in the routing header.\r
334 Note: There is no requirement that the\r
335 driver validate the routing data. It\r
336 must skip the <ConfigHdr> in order to\r
337 process the names.\r
338 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set\r
339 to most recent & before the\r
340 error or the beginning of the\r
341 string.\r
342 @retval EFI_INVALID_PARAMETER Unknown name. Progress points\r
343 to the & before the name in\r
344 question.Currently not implemented.\r
12618416 345**/\r
6a690e23 346EFI_STATUS\r
347EFIAPI\r
93e3992d 348IScsiFormExtractConfig (\r
349 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
350 IN CONST EFI_STRING Request,\r
351 OUT EFI_STRING *Progress,\r
352 OUT EFI_STRING *Results\r
6a690e23 353 )\r
6a690e23 354{\r
93e3992d 355 EFI_STATUS Status;\r
356 CHAR8 InitiatorName[ISCSI_NAME_IFR_MAX_SIZE];\r
357 UINTN BufferSize;\r
358 ISCSI_CONFIG_IFR_NVDATA *IfrNvData;\r
359 ISCSI_FORM_CALLBACK_INFO *Private;\r
360 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r
6a690e23 361\r
8d00a0f1 362 if (Request == NULL) {\r
669314e5 363 return EFI_INVALID_PARAMETER;\r
8d00a0f1 364 }\r
365\r
6a690e23 366 if (!mIScsiDeviceListUpdated) {\r
367 //\r
368 // Update the device list.\r
369 //\r
370 IScsiUpdateDeviceList ();\r
371 mIScsiDeviceListUpdated = TRUE;\r
372 }\r
373\r
93e3992d 374 Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);\r
375 IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA));\r
376 ASSERT (IfrNvData != NULL);\r
377 if (Private->Current != NULL) {\r
378 IScsiConvertDeviceConfigDataToIfrNvData (Private->Current, IfrNvData);\r
379 }\r
6a690e23 380\r
93e3992d 381 BufferSize = ISCSI_NAME_IFR_MAX_SIZE;\r
6a690e23 382 Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize, InitiatorName);\r
383 if (EFI_ERROR (Status)) {\r
384 IfrNvData->InitiatorName[0] = L'\0';\r
385 } else {\r
386 IScsiAsciiStrToUnicodeStr (InitiatorName, IfrNvData->InitiatorName);\r
387 }\r
388\r
93e3992d 389 //\r
390 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
391 //\r
392 HiiConfigRouting = Private->ConfigRouting;\r
393 BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);\r
394 Status = HiiConfigRouting->BlockToConfig (\r
395 HiiConfigRouting,\r
396 Request,\r
397 (UINT8 *) IfrNvData,\r
398 BufferSize,\r
399 Results,\r
400 Progress\r
401 );\r
e48e37fc 402 gBS->FreePool (IfrNvData);\r
93e3992d 403 return Status;\r
6a690e23 404}\r
405\r
12618416 406/**\r
669314e5 407 This function applies changes in a driver's configuration.\r
408 Input is a Configuration, which has the routing data for this\r
409 driver followed by name / value configuration pairs. The driver\r
410 must apply those pairs to its configurable storage. If the\r
411 driver's configuration is stored in a linear block of data\r
55a64ae0 412 and the driver's name / value pairs are in <BlockConfig>\r
669314e5 413 format, it may use the ConfigToBlock helper function (above) to\r
414 simplify the job. Currently not implemented.\r
415\r
416 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
417 @param[in] Configuration A null-terminated Unicode string in\r
418 <ConfigString> format. \r
419 @param[out] Progress A pointer to a string filled in with the\r
420 offset of the most recent '&' before the\r
421 first failing name / value pair (or the\r
422 beginn ing of the string if the failure\r
423 is in the first name / value pair) or\r
424 the terminating NULL if all was\r
425 successful.\r
426\r
427 @retval EFI_SUCCESS The results have been distributed or are\r
428 awaiting distribution. \r
429 @retval EFI_OUT_OF_MEMORY Not enough memory to store the\r
430 parts of the results that must be\r
431 stored awaiting possible future\r
432 protocols.\r
433 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the\r
434 Results parameter would result\r
435 in this type of error.\r
436 @retval EFI_NOT_FOUND Target for the specified routing data\r
437 was not found.\r
12618416 438**/\r
6a690e23 439EFI_STATUS\r
440EFIAPI\r
93e3992d 441IScsiFormRouteConfig (\r
442 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
443 IN CONST EFI_STRING Configuration,\r
444 OUT EFI_STRING *Progress\r
6a690e23 445 )\r
12618416 446{\r
447 return EFI_SUCCESS;\r
448}\r
6a690e23 449\r
12618416 450/**\r
669314e5 451 This function is called to provide results data to the driver.\r
452 This data consists of a unique key that is used to identify\r
453 which data is either being passed back or being asked for.\r
454\r
455 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
456 @param[in] Action Specifies the type of action taken by the browser.\r
457 @param[in] QuestionId A unique value which is sent to the original\r
458 exporting driver so that it can identify the type\r
459 of data to expect. The format of the data tends to \r
460 vary based on the opcode that enerated the callback.\r
461 @param[in] Type The type of value for the question.\r
462 @param[in] Value A pointer to the data being sent to the original\r
463 exporting driver.\r
464 @param[out] ActionRequest On return, points to the action requested by the\r
465 callback function.\r
466\r
467 @retval EFI_SUCCESS The callback successfully handled the action.\r
468 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
469 variable and its data.\r
470 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
471 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
472 callback.Currently not implemented.\r
473 @retval EFI_INVALID_PARAMETERS Passing in wrong parameter. \r
963dbb30 474 @retval Others Other errors as indicated. \r
12618416 475**/\r
93e3992d 476EFI_STATUS\r
477EFIAPI\r
478IScsiFormCallback (\r
479 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
f3e1569d 480 IN EFI_BROWSER_ACTION Action,\r
669314e5 481 IN EFI_QUESTION_ID QuestionId,\r
93e3992d 482 IN UINT8 Type,\r
483 IN EFI_IFR_TYPE_VALUE *Value,\r
484 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
485 )\r
6a690e23 486{\r
487 ISCSI_FORM_CALLBACK_INFO *Private;\r
488 UINTN BufferSize;\r
489 CHAR8 IScsiName[ISCSI_NAME_IFR_MAX_SIZE];\r
490 CHAR16 PortString[128];\r
491 CHAR8 Ip4String[IP4_STR_MAX_SIZE];\r
492 CHAR8 LunString[ISCSI_LUN_STR_MAX_LEN];\r
493 UINT64 Lun;\r
6c7a807a 494 EFI_STRING_ID DeviceFormTitleToken;\r
6a690e23 495 ISCSI_CONFIG_IFR_NVDATA *IfrNvData;\r
496 ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry;\r
497 EFI_IP_ADDRESS HostIp;\r
498 EFI_IP_ADDRESS SubnetMask;\r
499 EFI_IP_ADDRESS Gateway;\r
500 EFI_STATUS Status;\r
63d55bb9 501 EFI_INPUT_KEY Key;\r
6a690e23 502\r
503 Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);\r
93e3992d 504\r
505 //\r
506 // Retrive uncommitted data from Browser\r
507 //\r
1d451ff9
LG
508 IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA));\r
509 ASSERT (IfrNvData != NULL);\r
510 if (!HiiGetBrowserData (&mVendorGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData)) {\r
511 FreePool (IfrNvData);\r
7e3bcccb 512 return EFI_NOT_FOUND;\r
93e3992d 513 }\r
7e3bcccb
LG
514 \r
515 Status = EFI_SUCCESS;\r
6a690e23 516\r
669314e5 517 switch (QuestionId) {\r
6a690e23 518 case KEY_INITIATOR_NAME:\r
519 IScsiUnicodeStrToAsciiStr (IfrNvData->InitiatorName, IScsiName);\r
520 BufferSize = AsciiStrLen (IScsiName) + 1;\r
521\r
522 Status = gIScsiInitiatorName.Set (&gIScsiInitiatorName, &BufferSize, IScsiName);\r
523 if (EFI_ERROR (Status)) {\r
63d55bb9 524 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL);\r
6a690e23 525 }\r
526\r
527 break;\r
528\r
529 case KEY_LOCAL_IP:\r
530 IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String);\r
531 Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
532 if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
63d55bb9 533 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
6a690e23 534 Status = EFI_INVALID_PARAMETER;\r
535 } else {\r
e48e37fc 536 CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4));\r
6a690e23 537 }\r
538\r
539 break;\r
540\r
541 case KEY_SUBNET_MASK:\r
542 IScsiUnicodeStrToAsciiStr (IfrNvData->SubnetMask, Ip4String);\r
543 Status = IScsiAsciiStrToIp (Ip4String, &SubnetMask.v4);\r
544 if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {\r
63d55bb9 545 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);\r
6a690e23 546 Status = EFI_INVALID_PARAMETER;\r
547 } else {\r
e48e37fc 548 CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));\r
6a690e23 549 }\r
550\r
551 break;\r
552\r
553 case KEY_GATE_WAY:\r
554 IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String);\r
555 Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4);\r
556 if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
63d55bb9 557 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
6a690e23 558 Status = EFI_INVALID_PARAMETER;\r
559 } else {\r
e48e37fc 560 CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4));\r
6a690e23 561 }\r
562\r
563 break;\r
564\r
565 case KEY_TARGET_IP:\r
566 IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String);\r
567 Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
568 if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
63d55bb9 569 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
6a690e23 570 Status = EFI_INVALID_PARAMETER;\r
571 } else {\r
e48e37fc 572 CopyMem (&Private->Current->SessionConfigData.TargetIp, &HostIp.v4, sizeof (HostIp.v4));\r
6a690e23 573 }\r
574\r
575 break;\r
576\r
577 case KEY_TARGET_NAME:\r
578 IScsiUnicodeStrToAsciiStr (IfrNvData->TargetName, IScsiName);\r
579 Status = IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName));\r
580 if (EFI_ERROR (Status)) {\r
63d55bb9 581 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL);\r
6a690e23 582 } else {\r
583 AsciiStrCpy (Private->Current->SessionConfigData.TargetName, IScsiName);\r
584 }\r
585\r
586 break;\r
587\r
588 case KEY_DHCP_ENABLE:\r
589 if (IfrNvData->InitiatorInfoFromDhcp == 0) {\r
590 IfrNvData->TargetInfoFromDhcp = 0;\r
591 }\r
592\r
593 break;\r
594\r
595 case KEY_BOOT_LUN:\r
596 IScsiUnicodeStrToAsciiStr (IfrNvData->BootLun, LunString);\r
597 Status = IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun);\r
598 if (EFI_ERROR (Status)) {\r
63d55bb9 599 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid LUN string!", NULL);\r
6a690e23 600 } else {\r
e48e37fc 601 CopyMem (Private->Current->SessionConfigData.BootLun, &Lun, sizeof (Lun));\r
6a690e23 602 }\r
603\r
604 break;\r
605\r
606 case KEY_CHAP_NAME:\r
607 IScsiUnicodeStrToAsciiStr (IfrNvData->CHAPName, Private->Current->AuthConfigData.CHAPName);\r
608 break;\r
609\r
610 case KEY_CHAP_SECRET:\r
611 IScsiUnicodeStrToAsciiStr (IfrNvData->CHAPSecret, Private->Current->AuthConfigData.CHAPSecret);\r
612 break;\r
613\r
614 case KEY_REVERSE_CHAP_NAME:\r
615 IScsiUnicodeStrToAsciiStr (IfrNvData->ReverseCHAPName, Private->Current->AuthConfigData.ReverseCHAPName);\r
616 break;\r
617\r
618 case KEY_REVERSE_CHAP_SECRET:\r
619 IScsiUnicodeStrToAsciiStr (IfrNvData->ReverseCHAPSecret, Private->Current->AuthConfigData.ReverseCHAPSecret);\r
620 break;\r
621\r
622 case KEY_SAVE_CHANGES:\r
623 //\r
624 // First, update those fields which don't have INTERACTIVE set.\r
625 //\r
626 Private->Current->SessionConfigData.Enabled = IfrNvData->Enabled;\r
627 Private->Current->SessionConfigData.InitiatorInfoFromDhcp = IfrNvData->InitiatorInfoFromDhcp;\r
628 Private->Current->SessionConfigData.TargetPort = IfrNvData->TargetPort;\r
629 if (Private->Current->SessionConfigData.TargetPort == 0) {\r
630 Private->Current->SessionConfigData.TargetPort = ISCSI_WELL_KNOWN_PORT;\r
631 }\r
632\r
633 Private->Current->SessionConfigData.TargetInfoFromDhcp = IfrNvData->TargetInfoFromDhcp;\r
634 Private->Current->AuthConfigData.CHAPType = IfrNvData->CHAPType;\r
635\r
636 //\r
637 // Only do full parameter validation if iSCSI is enabled on this device.\r
638 //\r
639 if (Private->Current->SessionConfigData.Enabled) {\r
640 //\r
641 // Validate the address configuration of the Initiator if DHCP isn't\r
642 // deployed.\r
643 //\r
644 if (!Private->Current->SessionConfigData.InitiatorInfoFromDhcp) {\r
e48e37fc 645 CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.LocalIp, sizeof (HostIp.v4));\r
646 CopyMem (&SubnetMask.v4, &Private->Current->SessionConfigData.SubnetMask, sizeof (SubnetMask.v4));\r
647 CopyMem (&Gateway.v4, &Private->Current->SessionConfigData.Gateway, sizeof (Gateway.v4));\r
6a690e23 648\r
649 if ((Gateway.Addr[0] != 0)) {\r
650 if (SubnetMask.Addr[0] == 0) {\r
63d55bb9 651 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Gateway address is set but subnet mask is zero.", NULL);\r
6a690e23 652 Status = EFI_INVALID_PARAMETER;\r
653 break;\r
654 } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) {\r
63d55bb9 655 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Local IP and Gateway are not in the same subnet.", NULL);\r
6a690e23 656 Status = EFI_INVALID_PARAMETER;\r
657 break;\r
658 }\r
659 }\r
660 }\r
661 //\r
662 // Validate target configuration if DHCP isn't deployed.\r
663 //\r
664 if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) {\r
e48e37fc 665 CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4));\r
6a690e23 666 if (!Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
63d55bb9 667 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Target IP is invalid!", NULL);\r
6a690e23 668 Status = EFI_INVALID_PARAMETER;\r
669 break;\r
670 }\r
671 }\r
672\r
673 if (IfrNvData->CHAPType != ISCSI_CHAP_NONE) {\r
674 if ((IfrNvData->CHAPName[0] == '\0') || (IfrNvData->CHAPSecret[0] == '\0')) {\r
63d55bb9 675 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"CHAP Name or CHAP Secret is invalid!", NULL);\r
6a690e23 676 Status = EFI_INVALID_PARAMETER;\r
677 break;\r
678 }\r
679\r
680 if ((IfrNvData->CHAPType == ISCSI_CHAP_MUTUAL) &&\r
681 ((IfrNvData->ReverseCHAPName[0] == '\0') || (IfrNvData->ReverseCHAPSecret[0] == '\0'))\r
682 ) {\r
63d55bb9 683 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Reverse CHAP Name or Reverse CHAP Secret is invalid!", NULL);\r
6a690e23 684 Status = EFI_INVALID_PARAMETER;\r
685 break;\r
686 }\r
687 }\r
688 }\r
689\r
690 BufferSize = sizeof (Private->Current->SessionConfigData);\r
691 gRT->SetVariable (\r
692 Private->Current->MacString,\r
693 &gEfiIScsiInitiatorNameProtocolGuid,\r
694 ISCSI_CONFIG_VAR_ATTR,\r
695 BufferSize,\r
696 &Private->Current->SessionConfigData\r
697 );\r
698\r
699 BufferSize = sizeof (Private->Current->AuthConfigData);\r
700 gRT->SetVariable (\r
701 Private->Current->MacString,\r
702 &mIScsiCHAPAuthInfoGuid,\r
703 ISCSI_CONFIG_VAR_ATTR,\r
704 BufferSize,\r
705 &Private->Current->AuthConfigData\r
706 );\r
93e3992d 707 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
6a690e23 708 break;\r
709\r
710 default:\r
669314e5 711 if ((QuestionId >= KEY_DEVICE_ENTRY_BASE) && (QuestionId < (mNumberOfIScsiDevices + KEY_DEVICE_ENTRY_BASE))) {\r
6a690e23 712 //\r
713 // In case goto the device configuration form, update the device form title.\r
714 //\r
669314e5 715 ConfigFormEntry = IScsiGetConfigFormEntryByIndex ((UINT32) (QuestionId - KEY_DEVICE_ENTRY_BASE));\r
6a690e23 716 ASSERT (ConfigFormEntry != NULL);\r
717\r
93e3992d 718 UnicodeSPrint (PortString, (UINTN) 128, L"Port %s", ConfigFormEntry->MacString);\r
6c7a807a 719 DeviceFormTitleToken = (EFI_STRING_ID) STR_ISCSI_DEVICE_FORM_TITLE;\r
cb7d01c0 720 HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString, NULL);\r
6a690e23 721\r
722 IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry, IfrNvData);\r
723\r
724 Private->Current = ConfigFormEntry;\r
725 }\r
726\r
727 break;\r
728 }\r
729\r
93e3992d 730 if (!EFI_ERROR (Status)) {\r
731 //\r
732 // Pass changed uncommitted data back to Form Browser\r
733 //\r
7e3bcccb 734 HiiSetBrowserData (&mVendorGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData, NULL);\r
93e3992d 735 }\r
736\r
7e3bcccb 737 FreePool (IfrNvData);\r
6a690e23 738 return Status;\r
739}\r
740\r
12618416 741/**\r
6a690e23 742 Updates the iSCSI configuration form to add/delete an entry for the iSCSI\r
743 device specified by the Controller.\r
744\r
669314e5 745 @param[in] DriverBindingHandle The driverbinding handle.\r
746 @param[in] Controller The controller handle of the iSCSI device.\r
747 @param[in] AddForm Whether to add or delete a form entry.\r
6a690e23 748\r
12618416 749 @retval EFI_SUCCESS The iSCSI configuration form is updated.\r
12618416 750 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
963dbb30 751 @retval Others Other errors as indicated.\r
12618416 752**/\r
753EFI_STATUS\r
754IScsiConfigUpdateForm (\r
755 IN EFI_HANDLE DriverBindingHandle,\r
756 IN EFI_HANDLE Controller,\r
757 IN BOOLEAN AddForm\r
758 )\r
6a690e23 759{\r
e48e37fc 760 LIST_ENTRY *Entry;\r
6a690e23 761 ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry;\r
762 BOOLEAN EntryExisted;\r
6a690e23 763 EFI_STATUS Status;\r
6a690e23 764 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
765 CHAR16 PortString[128];\r
766 UINT16 FormIndex;\r
767 UINTN BufferSize;\r
7e3bcccb
LG
768 VOID *StartOpCodeHandle;\r
769 VOID *EndOpCodeHandle;\r
770 EFI_IFR_GUID_LABEL *StartLabel;\r
771 EFI_IFR_GUID_LABEL *EndLabel;\r
6a690e23 772\r
773 ConfigFormEntry = NULL;\r
774 EntryExisted = FALSE;\r
775\r
776 NET_LIST_FOR_EACH (Entry, &mIScsiConfigFormList) {\r
777 ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, ISCSI_CONFIG_FORM_ENTRY, Link);\r
778\r
779 if (ConfigFormEntry->Controller == Controller) {\r
780 EntryExisted = TRUE;\r
781 break;\r
782 }\r
783 }\r
784\r
785 if (AddForm) {\r
786 if (EntryExisted) {\r
787 return EFI_SUCCESS;\r
788 } else {\r
789 //\r
790 // Add a new form.\r
791 //\r
e48e37fc 792 ConfigFormEntry = (ISCSI_CONFIG_FORM_ENTRY *) AllocateZeroPool (sizeof (ISCSI_CONFIG_FORM_ENTRY));\r
6a690e23 793 if (ConfigFormEntry == NULL) {\r
794 return EFI_OUT_OF_RESOURCES;\r
795 }\r
796\r
e48e37fc 797 InitializeListHead (&ConfigFormEntry->Link);\r
6a690e23 798 ConfigFormEntry->Controller = Controller;\r
799\r
800 //\r
801 // Get the simple network protocol and convert the MAC address into\r
802 // the formatted string.\r
803 //\r
804 Status = gBS->HandleProtocol (\r
805 Controller,\r
806 &gEfiSimpleNetworkProtocolGuid,\r
807 (VOID **)&Snp\r
808 );\r
809 ASSERT (Status == EFI_SUCCESS);\r
810\r
811 IScsiMacAddrToStr (&Snp->Mode->PermanentAddress, Snp->Mode->HwAddressSize, ConfigFormEntry->MacString);\r
812\r
813 //\r
814 // Get the normal session configuration data.\r
815 //\r
816 BufferSize = sizeof (ConfigFormEntry->SessionConfigData);\r
817 Status = gRT->GetVariable (\r
818 ConfigFormEntry->MacString,\r
819 &gEfiIScsiInitiatorNameProtocolGuid,\r
820 NULL,\r
821 &BufferSize,\r
822 &ConfigFormEntry->SessionConfigData\r
823 );\r
824 if (EFI_ERROR (Status)) {\r
e48e37fc 825 ZeroMem (&ConfigFormEntry->SessionConfigData, sizeof (ConfigFormEntry->SessionConfigData));\r
6a690e23 826 }\r
827 //\r
828 // Get the CHAP authentication configuration data.\r
829 //\r
830 BufferSize = sizeof (ConfigFormEntry->AuthConfigData);\r
831 Status = gRT->GetVariable (\r
832 ConfigFormEntry->MacString,\r
833 &mIScsiCHAPAuthInfoGuid,\r
834 NULL,\r
835 &BufferSize,\r
836 &ConfigFormEntry->AuthConfigData\r
837 );\r
838 if (EFI_ERROR (Status)) {\r
e48e37fc 839 ZeroMem (&ConfigFormEntry->AuthConfigData, sizeof (ConfigFormEntry->AuthConfigData));\r
6a690e23 840 }\r
841 //\r
6c7a807a 842 // Compose the Port string and create a new EFI_STRING_ID.\r
6a690e23 843 //\r
844 UnicodeSPrint (PortString, 128, L"Port %s", ConfigFormEntry->MacString);\r
cb7d01c0 845 ConfigFormEntry->PortTitleToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL);\r
6a690e23 846\r
847 //\r
6c7a807a 848 // Compose the help string of this port and create a new EFI_STRING_ID.\r
6a690e23 849 //\r
850 UnicodeSPrint (PortString, 128, L"Set the iSCSI parameters on port %s", ConfigFormEntry->MacString);\r
cb7d01c0 851 ConfigFormEntry->PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL);\r
6a690e23 852\r
e48e37fc 853 InsertTailList (&mIScsiConfigFormList, &ConfigFormEntry->Link);\r
6a690e23 854 mNumberOfIScsiDevices++;\r
855 }\r
856 } else {\r
857 ASSERT (EntryExisted);\r
858\r
859 mNumberOfIScsiDevices--;\r
e48e37fc 860 RemoveEntryList (&ConfigFormEntry->Link);\r
861 gBS->FreePool (ConfigFormEntry);\r
6a690e23 862 }\r
863 //\r
864 // Allocate space for creation of Buffer\r
865 //\r
7e3bcccb
LG
866\r
867 //\r
868 // Init OpCode Handle\r
869 //\r
870 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
871 ASSERT (StartOpCodeHandle != NULL);\r
872\r
873 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
874 ASSERT (EndOpCodeHandle != NULL);\r
875\r
876 //\r
877 // Create Hii Extend Label OpCode as the start opcode\r
878 //\r
879 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
880 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
881 StartLabel->Number = DEVICE_ENTRY_LABEL;\r
882\r
883 //\r
884 // Create Hii Extend Label OpCode as the end opcode\r
885 //\r
886 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
887 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
888 EndLabel->Number = LABEL_END;\r
6a690e23 889\r
93e3992d 890 FormIndex = 0;\r
6a690e23 891 NET_LIST_FOR_EACH (Entry, &mIScsiConfigFormList) {\r
892 ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, ISCSI_CONFIG_FORM_ENTRY, Link);\r
893\r
7e3bcccb
LG
894 HiiCreateGotoOpCode (\r
895 StartOpCodeHandle, // Container for dynamic created opcodes\r
896 FORMID_DEVICE_FORM, // Target Form ID\r
897 ConfigFormEntry->PortTitleToken, // Prompt text\r
898 ConfigFormEntry->PortTitleHelpToken, // Help text\r
899 EFI_IFR_FLAG_CALLBACK, // Question flag\r
900 (UINT16)(KEY_DEVICE_ENTRY_BASE + FormIndex) // Question ID\r
6a690e23 901 );\r
902\r
6a690e23 903 FormIndex++;\r
904 }\r
905\r
7e3bcccb 906 HiiUpdateForm (\r
93e3992d 907 mCallbackInfo->RegisteredHandle,\r
908 &mVendorGuid,\r
909 FORMID_MAIN_FORM,\r
7e3bcccb
LG
910 StartOpCodeHandle, // Label DEVICE_ENTRY_LABEL\r
911 EndOpCodeHandle // LABEL_END\r
93e3992d 912 );\r
913\r
7e3bcccb
LG
914 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
915 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
6a690e23 916\r
917 return EFI_SUCCESS;\r
918}\r
919\r
12618416 920/**\r
6a690e23 921 Initialize the iSCSI configuration form.\r
922\r
669314e5 923 @param[in] DriverBindingHandle The iSCSI driverbinding handle.\r
6a690e23 924\r
669314e5 925 @retval EFI_SUCCESS The iSCSI configuration form is initialized.\r
926 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
963dbb30 927 @retval Others Other errors as indicated.\r
12618416 928**/\r
929EFI_STATUS\r
930IScsiConfigFormInit (\r
963dbb30 931 VOID\r
12618416 932 )\r
6a690e23 933{\r
93e3992d 934 EFI_STATUS Status;\r
935 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;\r
93e3992d 936 ISCSI_FORM_CALLBACK_INFO *CallbackInfo;\r
937\r
69b0882d 938 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase);\r
6a690e23 939 if (EFI_ERROR (Status)) {\r
93e3992d 940 return Status;\r
6a690e23 941 }\r
942\r
f6f910dd 943 CallbackInfo = (ISCSI_FORM_CALLBACK_INFO *) AllocateZeroPool (sizeof (ISCSI_FORM_CALLBACK_INFO));\r
6a690e23 944 if (CallbackInfo == NULL) {\r
945 return EFI_OUT_OF_RESOURCES;\r
946 }\r
947\r
f2a94e25 948 CallbackInfo->Signature = ISCSI_FORM_CALLBACK_INFO_SIGNATURE;\r
93e3992d 949 CallbackInfo->HiiDatabase = HiiDatabase;\r
f2a94e25 950 CallbackInfo->Current = NULL;\r
6a690e23 951\r
93e3992d 952 CallbackInfo->ConfigAccess.ExtractConfig = IScsiFormExtractConfig;\r
953 CallbackInfo->ConfigAccess.RouteConfig = IScsiFormRouteConfig;\r
954 CallbackInfo->ConfigAccess.Callback = IScsiFormCallback;\r
6a690e23 955\r
69b0882d 956 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&CallbackInfo->ConfigRouting);\r
93e3992d 957 if (EFI_ERROR (Status)) {\r
f2a94e25 958 FreePool(CallbackInfo);\r
93e3992d 959 return Status;\r
960 }\r
961\r
962 //\r
f6f910dd 963 // Install Device Path Protocol and Config Access protocol to driver handle\r
93e3992d 964 //\r
f6f910dd 965 Status = gBS->InstallMultipleProtocolInterfaces (\r
93e3992d 966 &CallbackInfo->DriverHandle,\r
f6f910dd 967 &gEfiDevicePathProtocolGuid,\r
968 &mIScsiHiiVendorDevicePath,\r
93e3992d 969 &gEfiHiiConfigAccessProtocolGuid,\r
f6f910dd 970 &CallbackInfo->ConfigAccess,\r
971 NULL\r
6a690e23 972 );\r
6a690e23 973 ASSERT_EFI_ERROR (Status);\r
93e3992d 974 \r
6a690e23 975 //\r
93e3992d 976 // Publish our HII data\r
6a690e23 977 //\r
cb7d01c0 978 CallbackInfo->RegisteredHandle = HiiAddPackages (\r
979 &mVendorGuid,\r
980 CallbackInfo->DriverHandle,\r
981 IScsiDxeStrings,\r
982 IScsiConfigDxeBin,\r
983 NULL\r
984 );\r
985 if (CallbackInfo->RegisteredHandle == NULL) {\r
f2a94e25 986 FreePool(CallbackInfo);\r
cb7d01c0 987 return EFI_OUT_OF_RESOURCES;\r
6a690e23 988 }\r
989\r
93e3992d 990 mCallbackInfo = CallbackInfo;\r
6a690e23 991\r
992 return Status;\r
993}\r
994\r
12618416 995/**\r
6a690e23 996 Unload the iSCSI configuration form, this includes: delete all the iSCSI\r
997 device configuration entries, uninstall the form callback protocol and\r
998 free the resources used.\r
999\r
669314e5 1000 @param[in] DriverBindingHandle The iSCSI driverbinding handle.\r
1001 \r
12618416 1002 @retval EFI_SUCCESS The iSCSI configuration form is unloaded.\r
12618416 1003 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
12618416 1004**/\r
1005EFI_STATUS\r
1006IScsiConfigFormUnload (\r
1007 IN EFI_HANDLE DriverBindingHandle\r
1008 )\r
6a690e23 1009{\r
1010 ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry;\r
6a690e23 1011\r
e48e37fc 1012 while (!IsListEmpty (&mIScsiConfigFormList)) {\r
6a690e23 1013 //\r
1014 // Uninstall the device forms as the iSCSI driver instance may fail to\r
1015 // control the controller but still install the device configuration form.\r
1016 // In such case, upon driver unloading, the driver instance's driverbinding.\r
1017 // stop () won't be called, so we have to take this chance here to uninstall\r
1018 // the device form.\r
1019 //\r
1020 ConfigFormEntry = NET_LIST_USER_STRUCT (mIScsiConfigFormList.ForwardLink, ISCSI_CONFIG_FORM_ENTRY, Link);\r
1021 IScsiConfigUpdateForm (DriverBindingHandle, ConfigFormEntry->Controller, FALSE);\r
1022 }\r
1023\r
6a690e23 1024 //\r
93e3992d 1025 // Remove HII package list\r
6a690e23 1026 //\r
93e3992d 1027 mCallbackInfo->HiiDatabase->RemovePackageList (\r
1028 mCallbackInfo->HiiDatabase,\r
1029 mCallbackInfo->RegisteredHandle\r
1030 );\r
6a690e23 1031\r
1032 //\r
93e3992d 1033 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL\r
6a690e23 1034 //\r
f6f910dd 1035 gBS->UninstallMultipleProtocolInterfaces (\r
1036 mCallbackInfo->DriverHandle,\r
1037 &gEfiDevicePathProtocolGuid,\r
1038 &mIScsiHiiVendorDevicePath,\r
1039 &gEfiHiiConfigAccessProtocolGuid,\r
1040 &mCallbackInfo->ConfigAccess,\r
1041 NULL\r
1042 );\r
e48e37fc 1043 gBS->FreePool (mCallbackInfo);\r
6a690e23 1044\r
1045 return EFI_SUCCESS;\r
1046}\r