]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c
HII Library Class interface refine.
[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
7e3bcccb
LG
508 IfrNvData = (ISCSI_CONFIG_IFR_NVDATA *) HiiGetBrowserData (&mVendorGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA));\r
509 if (IfrNvData == NULL) {\r
510 return EFI_NOT_FOUND;\r
93e3992d 511 }\r
7e3bcccb
LG
512 \r
513 Status = EFI_SUCCESS;\r
6a690e23 514\r
669314e5 515 switch (QuestionId) {\r
6a690e23 516 case KEY_INITIATOR_NAME:\r
517 IScsiUnicodeStrToAsciiStr (IfrNvData->InitiatorName, IScsiName);\r
518 BufferSize = AsciiStrLen (IScsiName) + 1;\r
519\r
520 Status = gIScsiInitiatorName.Set (&gIScsiInitiatorName, &BufferSize, IScsiName);\r
521 if (EFI_ERROR (Status)) {\r
63d55bb9 522 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL);\r
6a690e23 523 }\r
524\r
525 break;\r
526\r
527 case KEY_LOCAL_IP:\r
528 IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String);\r
529 Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
530 if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
63d55bb9 531 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
6a690e23 532 Status = EFI_INVALID_PARAMETER;\r
533 } else {\r
e48e37fc 534 CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4));\r
6a690e23 535 }\r
536\r
537 break;\r
538\r
539 case KEY_SUBNET_MASK:\r
540 IScsiUnicodeStrToAsciiStr (IfrNvData->SubnetMask, Ip4String);\r
541 Status = IScsiAsciiStrToIp (Ip4String, &SubnetMask.v4);\r
542 if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {\r
63d55bb9 543 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);\r
6a690e23 544 Status = EFI_INVALID_PARAMETER;\r
545 } else {\r
e48e37fc 546 CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));\r
6a690e23 547 }\r
548\r
549 break;\r
550\r
551 case KEY_GATE_WAY:\r
552 IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String);\r
553 Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4);\r
554 if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
63d55bb9 555 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
6a690e23 556 Status = EFI_INVALID_PARAMETER;\r
557 } else {\r
e48e37fc 558 CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4));\r
6a690e23 559 }\r
560\r
561 break;\r
562\r
563 case KEY_TARGET_IP:\r
564 IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String);\r
565 Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
566 if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
63d55bb9 567 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
6a690e23 568 Status = EFI_INVALID_PARAMETER;\r
569 } else {\r
e48e37fc 570 CopyMem (&Private->Current->SessionConfigData.TargetIp, &HostIp.v4, sizeof (HostIp.v4));\r
6a690e23 571 }\r
572\r
573 break;\r
574\r
575 case KEY_TARGET_NAME:\r
576 IScsiUnicodeStrToAsciiStr (IfrNvData->TargetName, IScsiName);\r
577 Status = IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName));\r
578 if (EFI_ERROR (Status)) {\r
63d55bb9 579 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL);\r
6a690e23 580 } else {\r
581 AsciiStrCpy (Private->Current->SessionConfigData.TargetName, IScsiName);\r
582 }\r
583\r
584 break;\r
585\r
586 case KEY_DHCP_ENABLE:\r
587 if (IfrNvData->InitiatorInfoFromDhcp == 0) {\r
588 IfrNvData->TargetInfoFromDhcp = 0;\r
589 }\r
590\r
591 break;\r
592\r
593 case KEY_BOOT_LUN:\r
594 IScsiUnicodeStrToAsciiStr (IfrNvData->BootLun, LunString);\r
595 Status = IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun);\r
596 if (EFI_ERROR (Status)) {\r
63d55bb9 597 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid LUN string!", NULL);\r
6a690e23 598 } else {\r
e48e37fc 599 CopyMem (Private->Current->SessionConfigData.BootLun, &Lun, sizeof (Lun));\r
6a690e23 600 }\r
601\r
602 break;\r
603\r
604 case KEY_CHAP_NAME:\r
605 IScsiUnicodeStrToAsciiStr (IfrNvData->CHAPName, Private->Current->AuthConfigData.CHAPName);\r
606 break;\r
607\r
608 case KEY_CHAP_SECRET:\r
609 IScsiUnicodeStrToAsciiStr (IfrNvData->CHAPSecret, Private->Current->AuthConfigData.CHAPSecret);\r
610 break;\r
611\r
612 case KEY_REVERSE_CHAP_NAME:\r
613 IScsiUnicodeStrToAsciiStr (IfrNvData->ReverseCHAPName, Private->Current->AuthConfigData.ReverseCHAPName);\r
614 break;\r
615\r
616 case KEY_REVERSE_CHAP_SECRET:\r
617 IScsiUnicodeStrToAsciiStr (IfrNvData->ReverseCHAPSecret, Private->Current->AuthConfigData.ReverseCHAPSecret);\r
618 break;\r
619\r
620 case KEY_SAVE_CHANGES:\r
621 //\r
622 // First, update those fields which don't have INTERACTIVE set.\r
623 //\r
624 Private->Current->SessionConfigData.Enabled = IfrNvData->Enabled;\r
625 Private->Current->SessionConfigData.InitiatorInfoFromDhcp = IfrNvData->InitiatorInfoFromDhcp;\r
626 Private->Current->SessionConfigData.TargetPort = IfrNvData->TargetPort;\r
627 if (Private->Current->SessionConfigData.TargetPort == 0) {\r
628 Private->Current->SessionConfigData.TargetPort = ISCSI_WELL_KNOWN_PORT;\r
629 }\r
630\r
631 Private->Current->SessionConfigData.TargetInfoFromDhcp = IfrNvData->TargetInfoFromDhcp;\r
632 Private->Current->AuthConfigData.CHAPType = IfrNvData->CHAPType;\r
633\r
634 //\r
635 // Only do full parameter validation if iSCSI is enabled on this device.\r
636 //\r
637 if (Private->Current->SessionConfigData.Enabled) {\r
638 //\r
639 // Validate the address configuration of the Initiator if DHCP isn't\r
640 // deployed.\r
641 //\r
642 if (!Private->Current->SessionConfigData.InitiatorInfoFromDhcp) {\r
e48e37fc 643 CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.LocalIp, sizeof (HostIp.v4));\r
644 CopyMem (&SubnetMask.v4, &Private->Current->SessionConfigData.SubnetMask, sizeof (SubnetMask.v4));\r
645 CopyMem (&Gateway.v4, &Private->Current->SessionConfigData.Gateway, sizeof (Gateway.v4));\r
6a690e23 646\r
647 if ((Gateway.Addr[0] != 0)) {\r
648 if (SubnetMask.Addr[0] == 0) {\r
63d55bb9 649 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Gateway address is set but subnet mask is zero.", NULL);\r
6a690e23 650 Status = EFI_INVALID_PARAMETER;\r
651 break;\r
652 } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) {\r
63d55bb9 653 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Local IP and Gateway are not in the same subnet.", NULL);\r
6a690e23 654 Status = EFI_INVALID_PARAMETER;\r
655 break;\r
656 }\r
657 }\r
658 }\r
659 //\r
660 // Validate target configuration if DHCP isn't deployed.\r
661 //\r
662 if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) {\r
e48e37fc 663 CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4));\r
6a690e23 664 if (!Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
63d55bb9 665 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Target IP is invalid!", NULL);\r
6a690e23 666 Status = EFI_INVALID_PARAMETER;\r
667 break;\r
668 }\r
669 }\r
670\r
671 if (IfrNvData->CHAPType != ISCSI_CHAP_NONE) {\r
672 if ((IfrNvData->CHAPName[0] == '\0') || (IfrNvData->CHAPSecret[0] == '\0')) {\r
63d55bb9 673 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"CHAP Name or CHAP Secret is invalid!", NULL);\r
6a690e23 674 Status = EFI_INVALID_PARAMETER;\r
675 break;\r
676 }\r
677\r
678 if ((IfrNvData->CHAPType == ISCSI_CHAP_MUTUAL) &&\r
679 ((IfrNvData->ReverseCHAPName[0] == '\0') || (IfrNvData->ReverseCHAPSecret[0] == '\0'))\r
680 ) {\r
63d55bb9 681 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Reverse CHAP Name or Reverse CHAP Secret is invalid!", NULL);\r
6a690e23 682 Status = EFI_INVALID_PARAMETER;\r
683 break;\r
684 }\r
685 }\r
686 }\r
687\r
688 BufferSize = sizeof (Private->Current->SessionConfigData);\r
689 gRT->SetVariable (\r
690 Private->Current->MacString,\r
691 &gEfiIScsiInitiatorNameProtocolGuid,\r
692 ISCSI_CONFIG_VAR_ATTR,\r
693 BufferSize,\r
694 &Private->Current->SessionConfigData\r
695 );\r
696\r
697 BufferSize = sizeof (Private->Current->AuthConfigData);\r
698 gRT->SetVariable (\r
699 Private->Current->MacString,\r
700 &mIScsiCHAPAuthInfoGuid,\r
701 ISCSI_CONFIG_VAR_ATTR,\r
702 BufferSize,\r
703 &Private->Current->AuthConfigData\r
704 );\r
93e3992d 705 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
6a690e23 706 break;\r
707\r
708 default:\r
669314e5 709 if ((QuestionId >= KEY_DEVICE_ENTRY_BASE) && (QuestionId < (mNumberOfIScsiDevices + KEY_DEVICE_ENTRY_BASE))) {\r
6a690e23 710 //\r
711 // In case goto the device configuration form, update the device form title.\r
712 //\r
669314e5 713 ConfigFormEntry = IScsiGetConfigFormEntryByIndex ((UINT32) (QuestionId - KEY_DEVICE_ENTRY_BASE));\r
6a690e23 714 ASSERT (ConfigFormEntry != NULL);\r
715\r
93e3992d 716 UnicodeSPrint (PortString, (UINTN) 128, L"Port %s", ConfigFormEntry->MacString);\r
6c7a807a 717 DeviceFormTitleToken = (EFI_STRING_ID) STR_ISCSI_DEVICE_FORM_TITLE;\r
cb7d01c0 718 HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString, NULL);\r
6a690e23 719\r
720 IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry, IfrNvData);\r
721\r
722 Private->Current = ConfigFormEntry;\r
723 }\r
724\r
725 break;\r
726 }\r
727\r
93e3992d 728 if (!EFI_ERROR (Status)) {\r
729 //\r
730 // Pass changed uncommitted data back to Form Browser\r
731 //\r
7e3bcccb 732 HiiSetBrowserData (&mVendorGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData, NULL);\r
93e3992d 733 }\r
734\r
7e3bcccb 735 FreePool (IfrNvData);\r
6a690e23 736 return Status;\r
737}\r
738\r
12618416 739/**\r
6a690e23 740 Updates the iSCSI configuration form to add/delete an entry for the iSCSI\r
741 device specified by the Controller.\r
742\r
669314e5 743 @param[in] DriverBindingHandle The driverbinding handle.\r
744 @param[in] Controller The controller handle of the iSCSI device.\r
745 @param[in] AddForm Whether to add or delete a form entry.\r
6a690e23 746\r
12618416 747 @retval EFI_SUCCESS The iSCSI configuration form is updated.\r
12618416 748 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
963dbb30 749 @retval Others Other errors as indicated.\r
12618416 750**/\r
751EFI_STATUS\r
752IScsiConfigUpdateForm (\r
753 IN EFI_HANDLE DriverBindingHandle,\r
754 IN EFI_HANDLE Controller,\r
755 IN BOOLEAN AddForm\r
756 )\r
6a690e23 757{\r
e48e37fc 758 LIST_ENTRY *Entry;\r
6a690e23 759 ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry;\r
760 BOOLEAN EntryExisted;\r
6a690e23 761 EFI_STATUS Status;\r
6a690e23 762 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
763 CHAR16 PortString[128];\r
764 UINT16 FormIndex;\r
765 UINTN BufferSize;\r
7e3bcccb
LG
766 VOID *StartOpCodeHandle;\r
767 VOID *EndOpCodeHandle;\r
768 EFI_IFR_GUID_LABEL *StartLabel;\r
769 EFI_IFR_GUID_LABEL *EndLabel;\r
6a690e23 770\r
771 ConfigFormEntry = NULL;\r
772 EntryExisted = FALSE;\r
773\r
774 NET_LIST_FOR_EACH (Entry, &mIScsiConfigFormList) {\r
775 ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, ISCSI_CONFIG_FORM_ENTRY, Link);\r
776\r
777 if (ConfigFormEntry->Controller == Controller) {\r
778 EntryExisted = TRUE;\r
779 break;\r
780 }\r
781 }\r
782\r
783 if (AddForm) {\r
784 if (EntryExisted) {\r
785 return EFI_SUCCESS;\r
786 } else {\r
787 //\r
788 // Add a new form.\r
789 //\r
e48e37fc 790 ConfigFormEntry = (ISCSI_CONFIG_FORM_ENTRY *) AllocateZeroPool (sizeof (ISCSI_CONFIG_FORM_ENTRY));\r
6a690e23 791 if (ConfigFormEntry == NULL) {\r
792 return EFI_OUT_OF_RESOURCES;\r
793 }\r
794\r
e48e37fc 795 InitializeListHead (&ConfigFormEntry->Link);\r
6a690e23 796 ConfigFormEntry->Controller = Controller;\r
797\r
798 //\r
799 // Get the simple network protocol and convert the MAC address into\r
800 // the formatted string.\r
801 //\r
802 Status = gBS->HandleProtocol (\r
803 Controller,\r
804 &gEfiSimpleNetworkProtocolGuid,\r
805 (VOID **)&Snp\r
806 );\r
807 ASSERT (Status == EFI_SUCCESS);\r
808\r
809 IScsiMacAddrToStr (&Snp->Mode->PermanentAddress, Snp->Mode->HwAddressSize, ConfigFormEntry->MacString);\r
810\r
811 //\r
812 // Get the normal session configuration data.\r
813 //\r
814 BufferSize = sizeof (ConfigFormEntry->SessionConfigData);\r
815 Status = gRT->GetVariable (\r
816 ConfigFormEntry->MacString,\r
817 &gEfiIScsiInitiatorNameProtocolGuid,\r
818 NULL,\r
819 &BufferSize,\r
820 &ConfigFormEntry->SessionConfigData\r
821 );\r
822 if (EFI_ERROR (Status)) {\r
e48e37fc 823 ZeroMem (&ConfigFormEntry->SessionConfigData, sizeof (ConfigFormEntry->SessionConfigData));\r
6a690e23 824 }\r
825 //\r
826 // Get the CHAP authentication configuration data.\r
827 //\r
828 BufferSize = sizeof (ConfigFormEntry->AuthConfigData);\r
829 Status = gRT->GetVariable (\r
830 ConfigFormEntry->MacString,\r
831 &mIScsiCHAPAuthInfoGuid,\r
832 NULL,\r
833 &BufferSize,\r
834 &ConfigFormEntry->AuthConfigData\r
835 );\r
836 if (EFI_ERROR (Status)) {\r
e48e37fc 837 ZeroMem (&ConfigFormEntry->AuthConfigData, sizeof (ConfigFormEntry->AuthConfigData));\r
6a690e23 838 }\r
839 //\r
6c7a807a 840 // Compose the Port string and create a new EFI_STRING_ID.\r
6a690e23 841 //\r
842 UnicodeSPrint (PortString, 128, L"Port %s", ConfigFormEntry->MacString);\r
cb7d01c0 843 ConfigFormEntry->PortTitleToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL);\r
6a690e23 844\r
845 //\r
6c7a807a 846 // Compose the help string of this port and create a new EFI_STRING_ID.\r
6a690e23 847 //\r
848 UnicodeSPrint (PortString, 128, L"Set the iSCSI parameters on port %s", ConfigFormEntry->MacString);\r
cb7d01c0 849 ConfigFormEntry->PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL);\r
6a690e23 850\r
e48e37fc 851 InsertTailList (&mIScsiConfigFormList, &ConfigFormEntry->Link);\r
6a690e23 852 mNumberOfIScsiDevices++;\r
853 }\r
854 } else {\r
855 ASSERT (EntryExisted);\r
856\r
857 mNumberOfIScsiDevices--;\r
e48e37fc 858 RemoveEntryList (&ConfigFormEntry->Link);\r
859 gBS->FreePool (ConfigFormEntry);\r
6a690e23 860 }\r
861 //\r
862 // Allocate space for creation of Buffer\r
863 //\r
7e3bcccb
LG
864\r
865 //\r
866 // Init OpCode Handle\r
867 //\r
868 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
869 ASSERT (StartOpCodeHandle != NULL);\r
870\r
871 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
872 ASSERT (EndOpCodeHandle != NULL);\r
873\r
874 //\r
875 // Create Hii Extend Label OpCode as the start opcode\r
876 //\r
877 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
878 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
879 StartLabel->Number = DEVICE_ENTRY_LABEL;\r
880\r
881 //\r
882 // Create Hii Extend Label OpCode as the end opcode\r
883 //\r
884 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
885 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
886 EndLabel->Number = LABEL_END;\r
6a690e23 887\r
93e3992d 888 FormIndex = 0;\r
6a690e23 889 NET_LIST_FOR_EACH (Entry, &mIScsiConfigFormList) {\r
890 ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, ISCSI_CONFIG_FORM_ENTRY, Link);\r
891\r
7e3bcccb
LG
892 HiiCreateGotoOpCode (\r
893 StartOpCodeHandle, // Container for dynamic created opcodes\r
894 FORMID_DEVICE_FORM, // Target Form ID\r
895 ConfigFormEntry->PortTitleToken, // Prompt text\r
896 ConfigFormEntry->PortTitleHelpToken, // Help text\r
897 EFI_IFR_FLAG_CALLBACK, // Question flag\r
898 (UINT16)(KEY_DEVICE_ENTRY_BASE + FormIndex) // Question ID\r
6a690e23 899 );\r
900\r
6a690e23 901 FormIndex++;\r
902 }\r
903\r
7e3bcccb 904 HiiUpdateForm (\r
93e3992d 905 mCallbackInfo->RegisteredHandle,\r
906 &mVendorGuid,\r
907 FORMID_MAIN_FORM,\r
7e3bcccb
LG
908 StartOpCodeHandle, // Label DEVICE_ENTRY_LABEL\r
909 EndOpCodeHandle // LABEL_END\r
93e3992d 910 );\r
911\r
7e3bcccb
LG
912 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
913 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
6a690e23 914\r
915 return EFI_SUCCESS;\r
916}\r
917\r
12618416 918/**\r
6a690e23 919 Initialize the iSCSI configuration form.\r
920\r
669314e5 921 @param[in] DriverBindingHandle The iSCSI driverbinding handle.\r
6a690e23 922\r
669314e5 923 @retval EFI_SUCCESS The iSCSI configuration form is initialized.\r
924 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
963dbb30 925 @retval Others Other errors as indicated.\r
12618416 926**/\r
927EFI_STATUS\r
928IScsiConfigFormInit (\r
963dbb30 929 VOID\r
12618416 930 )\r
6a690e23 931{\r
93e3992d 932 EFI_STATUS Status;\r
933 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;\r
93e3992d 934 ISCSI_FORM_CALLBACK_INFO *CallbackInfo;\r
935\r
69b0882d 936 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase);\r
6a690e23 937 if (EFI_ERROR (Status)) {\r
93e3992d 938 return Status;\r
6a690e23 939 }\r
940\r
f6f910dd 941 CallbackInfo = (ISCSI_FORM_CALLBACK_INFO *) AllocateZeroPool (sizeof (ISCSI_FORM_CALLBACK_INFO));\r
6a690e23 942 if (CallbackInfo == NULL) {\r
943 return EFI_OUT_OF_RESOURCES;\r
944 }\r
945\r
f2a94e25 946 CallbackInfo->Signature = ISCSI_FORM_CALLBACK_INFO_SIGNATURE;\r
93e3992d 947 CallbackInfo->HiiDatabase = HiiDatabase;\r
f2a94e25 948 CallbackInfo->Current = NULL;\r
6a690e23 949\r
93e3992d 950 CallbackInfo->ConfigAccess.ExtractConfig = IScsiFormExtractConfig;\r
951 CallbackInfo->ConfigAccess.RouteConfig = IScsiFormRouteConfig;\r
952 CallbackInfo->ConfigAccess.Callback = IScsiFormCallback;\r
6a690e23 953\r
69b0882d 954 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&CallbackInfo->ConfigRouting);\r
93e3992d 955 if (EFI_ERROR (Status)) {\r
f2a94e25 956 FreePool(CallbackInfo);\r
93e3992d 957 return Status;\r
958 }\r
959\r
960 //\r
f6f910dd 961 // Install Device Path Protocol and Config Access protocol to driver handle\r
93e3992d 962 //\r
f6f910dd 963 Status = gBS->InstallMultipleProtocolInterfaces (\r
93e3992d 964 &CallbackInfo->DriverHandle,\r
f6f910dd 965 &gEfiDevicePathProtocolGuid,\r
966 &mIScsiHiiVendorDevicePath,\r
93e3992d 967 &gEfiHiiConfigAccessProtocolGuid,\r
f6f910dd 968 &CallbackInfo->ConfigAccess,\r
969 NULL\r
6a690e23 970 );\r
6a690e23 971 ASSERT_EFI_ERROR (Status);\r
93e3992d 972 \r
6a690e23 973 //\r
93e3992d 974 // Publish our HII data\r
6a690e23 975 //\r
cb7d01c0 976 CallbackInfo->RegisteredHandle = HiiAddPackages (\r
977 &mVendorGuid,\r
978 CallbackInfo->DriverHandle,\r
979 IScsiDxeStrings,\r
980 IScsiConfigDxeBin,\r
981 NULL\r
982 );\r
983 if (CallbackInfo->RegisteredHandle == NULL) {\r
f2a94e25 984 FreePool(CallbackInfo);\r
cb7d01c0 985 return EFI_OUT_OF_RESOURCES;\r
6a690e23 986 }\r
987\r
93e3992d 988 mCallbackInfo = CallbackInfo;\r
6a690e23 989\r
990 return Status;\r
991}\r
992\r
12618416 993/**\r
6a690e23 994 Unload the iSCSI configuration form, this includes: delete all the iSCSI\r
995 device configuration entries, uninstall the form callback protocol and\r
996 free the resources used.\r
997\r
669314e5 998 @param[in] DriverBindingHandle The iSCSI driverbinding handle.\r
999 \r
12618416 1000 @retval EFI_SUCCESS The iSCSI configuration form is unloaded.\r
12618416 1001 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
12618416 1002**/\r
1003EFI_STATUS\r
1004IScsiConfigFormUnload (\r
1005 IN EFI_HANDLE DriverBindingHandle\r
1006 )\r
6a690e23 1007{\r
1008 ISCSI_CONFIG_FORM_ENTRY *ConfigFormEntry;\r
6a690e23 1009\r
e48e37fc 1010 while (!IsListEmpty (&mIScsiConfigFormList)) {\r
6a690e23 1011 //\r
1012 // Uninstall the device forms as the iSCSI driver instance may fail to\r
1013 // control the controller but still install the device configuration form.\r
1014 // In such case, upon driver unloading, the driver instance's driverbinding.\r
1015 // stop () won't be called, so we have to take this chance here to uninstall\r
1016 // the device form.\r
1017 //\r
1018 ConfigFormEntry = NET_LIST_USER_STRUCT (mIScsiConfigFormList.ForwardLink, ISCSI_CONFIG_FORM_ENTRY, Link);\r
1019 IScsiConfigUpdateForm (DriverBindingHandle, ConfigFormEntry->Controller, FALSE);\r
1020 }\r
1021\r
6a690e23 1022 //\r
93e3992d 1023 // Remove HII package list\r
6a690e23 1024 //\r
93e3992d 1025 mCallbackInfo->HiiDatabase->RemovePackageList (\r
1026 mCallbackInfo->HiiDatabase,\r
1027 mCallbackInfo->RegisteredHandle\r
1028 );\r
6a690e23 1029\r
1030 //\r
93e3992d 1031 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL\r
6a690e23 1032 //\r
f6f910dd 1033 gBS->UninstallMultipleProtocolInterfaces (\r
1034 mCallbackInfo->DriverHandle,\r
1035 &gEfiDevicePathProtocolGuid,\r
1036 &mIScsiHiiVendorDevicePath,\r
1037 &gEfiHiiConfigAccessProtocolGuid,\r
1038 &mCallbackInfo->ConfigAccess,\r
1039 NULL\r
1040 );\r
e48e37fc 1041 gBS->FreePool (mCallbackInfo);\r
6a690e23 1042\r
1043 return EFI_SUCCESS;\r
1044}\r