]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/IScsiDxe/IScsiConfig.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiConfig.c
CommitLineData
4c5a5e0c 1/** @file\r
2 Helper functions for configuring or getting the parameters relating to iSCSI.\r
3\r
7a49cd08 4Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
4c5a5e0c 5This 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
12\r
13**/\r
14\r
15#include "IScsiImpl.h"\r
16\r
4c5a5e0c 17CHAR16 mVendorStorageName[] = L"ISCSI_CONFIG_IFR_NVDATA";\r
18BOOLEAN mIScsiDeviceListUpdated = FALSE;\r
19UINTN mNumberOfIScsiDevices = 0;\r
20ISCSI_FORM_CALLBACK_INFO *mCallbackInfo = NULL;\r
21\r
22HII_VENDOR_DEVICE_PATH mIScsiHiiVendorDevicePath = {\r
23 {\r
24 {\r
25 HARDWARE_DEVICE_PATH,\r
26 HW_VENDOR_DP,\r
27 {\r
28 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
29 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
30 }\r
31 },\r
9bdc6592 32 ISCSI_CONFIG_GUID\r
4c5a5e0c 33 },\r
34 {\r
35 END_DEVICE_PATH_TYPE,\r
36 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
37 { \r
38 (UINT8) (END_DEVICE_PATH_LENGTH),\r
39 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
40 }\r
41 }\r
42};\r
43\r
44\r
45/**\r
46 Convert the IP address into a dotted string.\r
47\r
48 @param[in] Ip The IP address.\r
49 @param[in] Ipv6Flag Indicates whether the IP address is version 4 or version 6.\r
50 @param[out] Str The formatted IP string.\r
51\r
52**/\r
53VOID\r
54IScsiIpToStr (\r
55 IN EFI_IP_ADDRESS *Ip,\r
56 IN BOOLEAN Ipv6Flag,\r
57 OUT CHAR16 *Str\r
58 )\r
59{\r
60 EFI_IPv4_ADDRESS *Ip4;\r
61 EFI_IPv6_ADDRESS *Ip6;\r
62 UINTN Index;\r
63 BOOLEAN Short;\r
64 UINTN Number;\r
65 CHAR16 FormatString[8];\r
66\r
67 if (!Ipv6Flag) {\r
68 Ip4 = &Ip->v4;\r
69\r
70 UnicodeSPrint (\r
71 Str,\r
72 (UINTN) 2 * IP4_STR_MAX_SIZE,\r
73 L"%d.%d.%d.%d",\r
74 (UINTN) Ip4->Addr[0],\r
75 (UINTN) Ip4->Addr[1],\r
76 (UINTN) Ip4->Addr[2],\r
77 (UINTN) Ip4->Addr[3]\r
78 );\r
79\r
80 return ;\r
81 }\r
82\r
83 Ip6 = &Ip->v6;\r
84 Short = FALSE;\r
85\r
86 for (Index = 0; Index < 15; Index = Index + 2) {\r
87 if (!Short &&\r
88 Index % 2 == 0 &&\r
89 Ip6->Addr[Index] == 0 &&\r
90 Ip6->Addr[Index + 1] == 0\r
91 ) {\r
92 //\r
93 // Deal with the case of ::.\r
94 //\r
95 if (Index == 0) {\r
96 *Str = L':';\r
97 *(Str + 1) = L':';\r
98 Str = Str + 2;\r
99 } else {\r
100 *Str = L':';\r
101 Str = Str + 1;\r
102 }\r
103\r
104 while ((Index < 15) && (Ip6->Addr[Index] == 0) && (Ip6->Addr[Index + 1] == 0)) {\r
105 Index = Index + 2;\r
106 }\r
107\r
108 Short = TRUE;\r
109\r
110 if (Index == 16) {\r
111 //\r
112 // :: is at the end of the address.\r
113 //\r
114 *Str = L'\0';\r
115 break;\r
116 }\r
117 }\r
118\r
119 ASSERT (Index < 15);\r
120\r
121 if (Ip6->Addr[Index] == 0) {\r
122 Number = UnicodeSPrint (Str, 2 * IP_STR_MAX_SIZE, L"%x:", (UINTN) Ip6->Addr[Index + 1]);\r
123 } else {\r
124 if (Ip6->Addr[Index + 1] < 0x10) {\r
125 CopyMem (FormatString, L"%x0%x:", StrSize (L"%x0%x:"));\r
126 } else {\r
127 CopyMem (FormatString, L"%x%x:", StrSize (L"%x%x:"));\r
128 }\r
129\r
130 Number = UnicodeSPrint (\r
131 Str,\r
132 2 * IP_STR_MAX_SIZE,\r
133 (CONST CHAR16 *) FormatString,\r
134 (UINTN) Ip6->Addr[Index],\r
135 (UINTN) Ip6->Addr[Index + 1]\r
136 );\r
137 }\r
138\r
139 Str = Str + Number;\r
140\r
141 if (Index + 2 == 16) {\r
142 *Str = L'\0';\r
143 if (*(Str - 1) == L':') {\r
144 *(Str - 1) = L'\0';\r
145 }\r
146 }\r
147 }\r
148}\r
149\r
150/**\r
151 Check whether the input IP address is valid.\r
152\r
153 @param[in] Ip The IP address.\r
154 @param[in] IpMode Indicates iSCSI running on IP4 or IP6 stack.\r
155\r
156 @retval TRUE The input IP address is valid.\r
157 @retval FALSE Otherwise\r
158\r
159**/\r
160BOOLEAN\r
161IpIsUnicast (\r
162 IN EFI_IP_ADDRESS *Ip,\r
163 IN UINT8 IpMode\r
164 )\r
165{\r
166 if (IpMode == IP_MODE_IP4) {\r
167 return NetIp4IsUnicast (NTOHL (Ip->Addr[0]), 0);\r
168 } else if (IpMode == IP_MODE_IP6) {\r
169 return NetIp6IsValidUnicast (&Ip->v6);\r
170 } else {\r
171 DEBUG ((DEBUG_ERROR, "IpMode %d is invalid when configuring the iSCSI target IP!\n", IpMode));\r
172 return FALSE;\r
173 }\r
174}\r
175\r
176/**\r
177 Parse IsId in string format and convert it to binary.\r
178\r
179 @param[in] String The buffer of the string to be parsed.\r
180 @param[in, out] IsId The buffer to store IsId.\r
181\r
182 @retval EFI_SUCCESS The operation finished successfully.\r
183 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
184\r
185**/\r
186EFI_STATUS\r
187IScsiParseIsIdFromString (\r
188 IN CONST CHAR16 *String,\r
189 IN OUT UINT8 *IsId\r
190 )\r
191{\r
192 UINT8 Index;\r
193 CHAR16 *IsIdStr;\r
194 CHAR16 TempStr[3];\r
195 UINTN NodeVal;\r
196 CHAR16 PortString[ISCSI_NAME_IFR_MAX_SIZE];\r
197 EFI_INPUT_KEY Key;\r
198\r
199 if ((String == NULL) || (IsId == NULL)) {\r
200 return EFI_INVALID_PARAMETER;\r
201 }\r
202\r
203 IsIdStr = (CHAR16 *) String;\r
204\r
205 if (StrLen (IsIdStr) != 6) {\r
206 UnicodeSPrint (\r
207 PortString,\r
208 (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
209 L"Error! Input is incorrect, please input 6 hex numbers!\n"\r
210 );\r
211\r
212 CreatePopUp (\r
213 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
214 &Key,\r
215 PortString,\r
216 NULL\r
217 );\r
218\r
219 return EFI_INVALID_PARAMETER;\r
220 }\r
221\r
222 for (Index = 3; Index < 6; Index++) {\r
223 CopyMem (TempStr, IsIdStr, sizeof (TempStr));\r
224 TempStr[2] = L'\0';\r
225\r
226 //\r
227 // Convert the string to IsId. StrHexToUintn stops at the first character\r
228 // that is not a valid hex character, '\0' here.\r
229 //\r
230 NodeVal = StrHexToUintn (TempStr);\r
231\r
232 IsId[Index] = (UINT8) NodeVal;\r
233\r
234 IsIdStr = IsIdStr + 2;\r
235 }\r
236\r
237 return EFI_SUCCESS;\r
238}\r
239\r
240/**\r
241 Convert IsId from binary to string format.\r
242\r
243 @param[out] String The buffer to store the converted string.\r
244 @param[in] IsId The buffer to store IsId.\r
245\r
246 @retval EFI_SUCCESS The string converted successfully.\r
247 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
248\r
249**/\r
250EFI_STATUS\r
251IScsiConvertIsIdToString (\r
252 OUT CHAR16 *String,\r
253 IN UINT8 *IsId\r
254 )\r
255{\r
256 UINT8 Index;\r
257 UINTN Number;\r
258\r
259 if ((String == NULL) || (IsId == NULL)) {\r
260 return EFI_INVALID_PARAMETER;\r
261 }\r
262\r
263 for (Index = 0; Index < 6; Index++) {\r
264 if (IsId[Index] <= 0xF) {\r
265 Number = UnicodeSPrint (\r
266 String,\r
267 2 * ISID_CONFIGURABLE_STORAGE,\r
268 L"0%X",\r
269 (UINTN) IsId[Index]\r
270 );\r
271 } else {\r
272 Number = UnicodeSPrint (\r
273 String,\r
274 2 * ISID_CONFIGURABLE_STORAGE,\r
275 L"%X",\r
276 (UINTN) IsId[Index]\r
277 );\r
278\r
279 }\r
280\r
281 String = String + Number;\r
282 }\r
283\r
284 *String = L'\0';\r
285\r
286 return EFI_SUCCESS;\r
287}\r
288\r
289/**\r
290 Get the attempt config data from global structure by the ConfigIndex.\r
291\r
292 @param[in] AttemptConfigIndex The unique index indicates the attempt.\r
293\r
294 @return Pointer to the attempt config data.\r
295 @retval NULL The attempt configuration data cannot be found.\r
296\r
297**/\r
298ISCSI_ATTEMPT_CONFIG_NVDATA *\r
299IScsiConfigGetAttemptByConfigIndex (\r
300 IN UINT8 AttemptConfigIndex\r
301 )\r
302{\r
303 LIST_ENTRY *Entry;\r
304 ISCSI_ATTEMPT_CONFIG_NVDATA *Attempt;\r
305\r
306 NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {\r
307 Attempt = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);\r
308 if (Attempt->AttemptConfigIndex == AttemptConfigIndex) {\r
309 return Attempt;\r
310 }\r
311 }\r
312\r
313 return NULL;\r
314}\r
315\r
316\r
317/**\r
318 Get the existing attempt config data from global structure by the NicIndex.\r
319\r
320 @param[in] NewAttempt The created new attempt\r
321 @param[in] IScsiMode The IScsi Mode of the new attempt, Enabled or\r
322 Enabled for MPIO.\r
323\r
324 @return Pointer to the existing attempt config data which\r
325 has the same NICIndex as the new created attempt.\r
326 @retval NULL The attempt with NicIndex does not exist.\r
327\r
328**/\r
329ISCSI_ATTEMPT_CONFIG_NVDATA *\r
330IScsiConfigGetAttemptByNic (\r
331 IN ISCSI_ATTEMPT_CONFIG_NVDATA *NewAttempt,\r
332 IN UINT8 IScsiMode\r
333 )\r
334{\r
335 LIST_ENTRY *Entry;\r
336 ISCSI_ATTEMPT_CONFIG_NVDATA *Attempt;\r
337\r
338 NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {\r
339 Attempt = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);\r
340 if (Attempt != NewAttempt && Attempt->NicIndex == NewAttempt->NicIndex &&\r
341 Attempt->SessionConfigData.Enabled == IScsiMode) {\r
342 return Attempt;\r
343 }\r
344 }\r
345\r
346 return NULL;\r
347}\r
348\r
349\r
350/**\r
351 Convert the iSCSI configuration data into the IFR data.\r
352\r
353 @param[in] Attempt The iSCSI attempt config data.\r
354 @param[in, out] IfrNvData The IFR nv data.\r
355\r
356**/\r
357VOID\r
358IScsiConvertAttemptConfigDataToIfrNvData (\r
359 IN ISCSI_ATTEMPT_CONFIG_NVDATA *Attempt,\r
360 IN OUT ISCSI_CONFIG_IFR_NVDATA *IfrNvData\r
361 )\r
362{\r
363 ISCSI_SESSION_CONFIG_NVDATA *SessionConfigData;\r
364 ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfigData;\r
365 EFI_IP_ADDRESS Ip;\r
366\r
367 //\r
368 // Normal session configuration parameters.\r
369 //\r
370 SessionConfigData = &Attempt->SessionConfigData;\r
371 IfrNvData->Enabled = SessionConfigData->Enabled;\r
372 IfrNvData->IpMode = SessionConfigData->IpMode;\r
373\r
374 IfrNvData->InitiatorInfoFromDhcp = SessionConfigData->InitiatorInfoFromDhcp;\r
375 IfrNvData->TargetInfoFromDhcp = SessionConfigData->TargetInfoFromDhcp;\r
376 IfrNvData->TargetPort = SessionConfigData->TargetPort;\r
377\r
378 if (IfrNvData->IpMode == IP_MODE_IP4) {\r
379 CopyMem (&Ip.v4, &SessionConfigData->LocalIp, sizeof (EFI_IPv4_ADDRESS));\r
380 IScsiIpToStr (&Ip, FALSE, IfrNvData->LocalIp);\r
381 CopyMem (&Ip.v4, &SessionConfigData->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
382 IScsiIpToStr (&Ip, FALSE, IfrNvData->SubnetMask);\r
383 CopyMem (&Ip.v4, &SessionConfigData->Gateway, sizeof (EFI_IPv4_ADDRESS));\r
384 IScsiIpToStr (&Ip, FALSE, IfrNvData->Gateway);\r
385 CopyMem (&Ip.v4, &SessionConfigData->TargetIp, sizeof (EFI_IPv4_ADDRESS));\r
386 IScsiIpToStr (&Ip, FALSE, IfrNvData->TargetIp);\r
387 } else if (IfrNvData->IpMode == IP_MODE_IP6) {\r
388 ZeroMem (IfrNvData->TargetIp, sizeof (IfrNvData->TargetIp));\r
389 IP6_COPY_ADDRESS (&Ip.v6, &SessionConfigData->TargetIp);\r
390 IScsiIpToStr (&Ip, TRUE, IfrNvData->TargetIp);\r
391 }\r
392\r
393 AsciiStrToUnicodeStr (SessionConfigData->TargetName, IfrNvData->TargetName);\r
394 IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->BootLun);\r
395 IScsiConvertIsIdToString (IfrNvData->IsId, SessionConfigData->IsId);\r
396\r
397 IfrNvData->ConnectRetryCount = SessionConfigData->ConnectRetryCount;\r
398 IfrNvData->ConnectTimeout = SessionConfigData->ConnectTimeout;\r
399\r
400 //\r
401 // Authentication parameters.\r
402 //\r
403 IfrNvData->AuthenticationType = Attempt->AuthenticationType;\r
404\r
405 if (IfrNvData->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {\r
406 AuthConfigData = &Attempt->AuthConfigData.CHAP;\r
407 IfrNvData->CHAPType = AuthConfigData->CHAPType;\r
408 AsciiStrToUnicodeStr (AuthConfigData->CHAPName, IfrNvData->CHAPName);\r
409 AsciiStrToUnicodeStr (AuthConfigData->CHAPSecret, IfrNvData->CHAPSecret);\r
410 AsciiStrToUnicodeStr (AuthConfigData->ReverseCHAPName, IfrNvData->ReverseCHAPName);\r
411 AsciiStrToUnicodeStr (AuthConfigData->ReverseCHAPSecret, IfrNvData->ReverseCHAPSecret);\r
412 }\r
413\r
414 //\r
415 // Other parameters.\r
416 //\r
417 AsciiStrToUnicodeStr (Attempt->AttemptName, IfrNvData->AttemptName);\r
418}\r
419\r
4c5a5e0c 420/**\r
421 Convert the IFR data to iSCSI configuration data.\r
422\r
c0d494b5 423 @param[in] IfrNvData Point to ISCSI_CONFIG_IFR_NVDATA.\r
4c5a5e0c 424 @param[in, out] Attempt The iSCSI attempt config data.\r
425\r
426 @retval EFI_INVALID_PARAMETER Any input or configured parameter is invalid.\r
427 @retval EFI_NOT_FOUND Cannot find the corresponding variable.\r
c0d494b5 428 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.\r
429 @retval EFI_ABORTED The operation is aborted.\r
4c5a5e0c 430 @retval EFI_SUCCESS The operation is completed successfully.\r
431\r
432**/\r
433EFI_STATUS\r
434IScsiConvertIfrNvDataToAttemptConfigData (\r
435 IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData,\r
436 IN OUT ISCSI_ATTEMPT_CONFIG_NVDATA *Attempt\r
437 )\r
438{\r
439 EFI_IP_ADDRESS HostIp;\r
440 EFI_IP_ADDRESS SubnetMask;\r
441 EFI_IP_ADDRESS Gateway;\r
442 CHAR16 *MacString;\r
443 CHAR16 *AttemptName1;\r
444 CHAR16 *AttemptName2;\r
445 ISCSI_ATTEMPT_CONFIG_NVDATA *ExistAttempt;\r
446 ISCSI_ATTEMPT_CONFIG_NVDATA *SameNicAttempt;\r
447 CHAR16 IScsiMode[64];\r
448 CHAR16 IpMode[64];\r
449 ISCSI_NIC_INFO *NicInfo;\r
450 EFI_INPUT_KEY Key;\r
c0d494b5 451 UINT8 *AttemptConfigOrder;\r
452 UINTN AttemptConfigOrderSize;\r
453 UINT8 *AttemptOrderTmp;\r
454 UINTN TotalNumber;\r
455 EFI_STATUS Status;\r
4c5a5e0c 456\r
457 if (IfrNvData == NULL || Attempt == NULL) {\r
458 return EFI_INVALID_PARAMETER;\r
459 }\r
460\r
461 //\r
462 // Update those fields which don't have INTERACTIVE attribute.\r
463 //\r
464 Attempt->SessionConfigData.ConnectRetryCount = IfrNvData->ConnectRetryCount;\r
465 Attempt->SessionConfigData.ConnectTimeout = IfrNvData->ConnectTimeout;\r
466 Attempt->SessionConfigData.IpMode = IfrNvData->IpMode;\r
467\r
468 if (IfrNvData->IpMode < IP_MODE_AUTOCONFIG) {\r
469 Attempt->SessionConfigData.InitiatorInfoFromDhcp = IfrNvData->InitiatorInfoFromDhcp;\r
470 Attempt->SessionConfigData.TargetPort = IfrNvData->TargetPort;\r
471\r
472 if (Attempt->SessionConfigData.TargetPort == 0) {\r
473 Attempt->SessionConfigData.TargetPort = ISCSI_WELL_KNOWN_PORT;\r
474 }\r
475\r
476 Attempt->SessionConfigData.TargetInfoFromDhcp = IfrNvData->TargetInfoFromDhcp;\r
477 }\r
478\r
479 Attempt->AuthenticationType = IfrNvData->AuthenticationType;\r
480\r
481 if (Attempt->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {\r
482 Attempt->AuthConfigData.CHAP.CHAPType = IfrNvData->CHAPType;\r
483 }\r
484\r
485 //\r
486 // Only do full parameter validation if iSCSI is enabled on this device.\r
487 //\r
488 if (IfrNvData->Enabled != ISCSI_DISABLED) {\r
489 if (Attempt->SessionConfigData.ConnectTimeout < CONNECT_MIN_TIMEOUT) {\r
490 CreatePopUp (\r
491 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
492 &Key,\r
493 L"Connection Establishing Timeout is less than minimum value 100ms.",\r
494 NULL\r
495 );\r
496 \r
497 return EFI_INVALID_PARAMETER;\r
498 }\r
499\r
500 //\r
501 // Validate the address configuration of the Initiator if DHCP isn't\r
502 // deployed.\r
503 //\r
504 if (!Attempt->SessionConfigData.InitiatorInfoFromDhcp) {\r
505 CopyMem (&HostIp.v4, &Attempt->SessionConfigData.LocalIp, sizeof (HostIp.v4));\r
506 CopyMem (&SubnetMask.v4, &Attempt->SessionConfigData.SubnetMask, sizeof (SubnetMask.v4));\r
507 CopyMem (&Gateway.v4, &Attempt->SessionConfigData.Gateway, sizeof (Gateway.v4));\r
508\r
509 if ((Gateway.Addr[0] != 0)) {\r
510 if (SubnetMask.Addr[0] == 0) {\r
511 CreatePopUp (\r
512 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
513 &Key,\r
514 L"Gateway address is set but subnet mask is zero.",\r
515 NULL\r
516 );\r
517 \r
518 return EFI_INVALID_PARAMETER;\r
519 } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) {\r
520 CreatePopUp (\r
521 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
522 &Key,\r
523 L"Local IP and Gateway are not in the same subnet.",\r
524 NULL\r
525 );\r
526 \r
527 return EFI_INVALID_PARAMETER;\r
528 }\r
529 }\r
530 }\r
531 //\r
532 // Validate target configuration if DHCP isn't deployed.\r
533 //\r
534 if (!Attempt->SessionConfigData.TargetInfoFromDhcp && Attempt->SessionConfigData.IpMode < IP_MODE_AUTOCONFIG) {\r
535 if (!IpIsUnicast (&Attempt->SessionConfigData.TargetIp, IfrNvData->IpMode)) {\r
536 CreatePopUp (\r
537 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
538 &Key,\r
539 L"Target IP is invalid!",\r
540 NULL\r
541 );\r
542 return EFI_INVALID_PARAMETER;\r
543 }\r
544 }\r
545 //\r
546 // Validate the authentication info.\r
547 //\r
548 if (IfrNvData->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {\r
549 if ((IfrNvData->CHAPName[0] == '\0') || (IfrNvData->CHAPSecret[0] == '\0')) {\r
550 CreatePopUp (\r
551 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
552 &Key,\r
553 L"CHAP Name or CHAP Secret is invalid!",\r
554 NULL\r
555 );\r
556 \r
557 return EFI_INVALID_PARAMETER;\r
558 }\r
559\r
560 if ((IfrNvData->CHAPType == ISCSI_CHAP_MUTUAL) &&\r
561 ((IfrNvData->ReverseCHAPName[0] == '\0') || (IfrNvData->ReverseCHAPSecret[0] == '\0'))\r
562 ) {\r
563 CreatePopUp (\r
564 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
565 &Key,\r
566 L"Reverse CHAP Name or Reverse CHAP Secret is invalid!",\r
567 NULL\r
568 ); \r
569 return EFI_INVALID_PARAMETER;\r
570 }\r
571 }\r
572\r
573 //\r
574 // Check whether this attempt uses NIC which is already used by existing attempt.\r
575 //\r
576 SameNicAttempt = IScsiConfigGetAttemptByNic (Attempt, IfrNvData->Enabled);\r
577 if (SameNicAttempt != NULL) {\r
578 AttemptName1 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_MAX_SIZE * sizeof (CHAR16));\r
579 if (AttemptName1 == NULL) {\r
580 return EFI_OUT_OF_RESOURCES;\r
581 }\r
582\r
583 AttemptName2 = (CHAR16 *) AllocateZeroPool (ATTEMPT_NAME_MAX_SIZE * sizeof (CHAR16));\r
584 if (AttemptName2 == NULL) {\r
585 FreePool (AttemptName1);\r
586 return EFI_OUT_OF_RESOURCES;\r
587 } \r
588 \r
589 AsciiStrToUnicodeStr (Attempt->AttemptName, AttemptName1);\r
590 if (StrLen (AttemptName1) > ATTEMPT_NAME_SIZE) {\r
591 CopyMem (&AttemptName1[ATTEMPT_NAME_SIZE], L"...", 4 * sizeof (CHAR16));\r
592 }\r
593\r
594 AsciiStrToUnicodeStr (SameNicAttempt->AttemptName, AttemptName2);\r
595 if (StrLen (AttemptName2) > ATTEMPT_NAME_SIZE) {\r
596 CopyMem (&AttemptName2[ATTEMPT_NAME_SIZE], L"...", 4 * sizeof (CHAR16));\r
597 }\r
598\r
599 UnicodeSPrint (\r
600 mPrivate->PortString,\r
601 (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
602 L"Warning! Attempt \"%s\" uses same NIC as Attempt \"%s\".",\r
603 AttemptName1,\r
604 AttemptName2\r
605 );\r
606\r
607 CreatePopUp (\r
608 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
609 &Key,\r
610 mPrivate->PortString,\r
611 NULL\r
612 ); \r
613\r
614 FreePool (AttemptName1);\r
615 FreePool (AttemptName2);\r
616 }\r
617 }\r
618\r
c0d494b5 619 //\r
620 // Update the iSCSI Mode data and record it in attempt help info.\r
621 //\r
622 Attempt->SessionConfigData.Enabled = IfrNvData->Enabled;\r
623 if (IfrNvData->Enabled == ISCSI_DISABLED) {\r
624 UnicodeSPrint (IScsiMode, 64, L"Disabled");\r
625 } else if (IfrNvData->Enabled == ISCSI_ENABLED) {\r
626 UnicodeSPrint (IScsiMode, 64, L"Enabled");\r
627 } else if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO) {\r
628 UnicodeSPrint (IScsiMode, 64, L"Enabled for MPIO");\r
629 }\r
630\r
631 if (IfrNvData->IpMode == IP_MODE_IP4) {\r
632 UnicodeSPrint (IpMode, 64, L"IP4");\r
633 } else if (IfrNvData->IpMode == IP_MODE_IP6) {\r
634 UnicodeSPrint (IpMode, 64, L"IP6");\r
635 } else if (IfrNvData->IpMode == IP_MODE_AUTOCONFIG) {\r
636 UnicodeSPrint (IpMode, 64, L"Autoconfigure");\r
637 }\r
638\r
639 NicInfo = IScsiGetNicInfoByIndex (Attempt->NicIndex);\r
640 if (NicInfo == NULL) {\r
641 return EFI_NOT_FOUND;\r
642 }\r
643\r
644 MacString = (CHAR16 *) AllocateZeroPool (ISCSI_MAX_MAC_STRING_LEN * sizeof (CHAR16));\r
645 if (MacString == NULL) {\r
646 return EFI_OUT_OF_RESOURCES;\r
647 }\r
648\r
649 AsciiStrToUnicodeStr (Attempt->MacString, MacString);\r
650\r
651 UnicodeSPrint (\r
652 mPrivate->PortString,\r
653 (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
654 L"MAC: %s, PFA: Bus %d | Dev %d | Func %d, iSCSI mode: %s, IP version: %s",\r
655 MacString,\r
656 NicInfo->BusNumber,\r
657 NicInfo->DeviceNumber,\r
658 NicInfo->FunctionNumber,\r
659 IScsiMode,\r
660 IpMode\r
661 );\r
662\r
663 Attempt->AttemptTitleHelpToken = HiiSetString (\r
664 mCallbackInfo->RegisteredHandle,\r
665 Attempt->AttemptTitleHelpToken,\r
666 mPrivate->PortString,\r
667 NULL\r
668 );\r
669 if (Attempt->AttemptTitleHelpToken == 0) {\r
670 FreePool (MacString);\r
671 return EFI_OUT_OF_RESOURCES;\r
672 }\r
673\r
4c5a5e0c 674 //\r
675 // Check whether this attempt is an existing one.\r
676 //\r
677 ExistAttempt = IScsiConfigGetAttemptByConfigIndex (Attempt->AttemptConfigIndex);\r
678 if (ExistAttempt != NULL) {\r
679 ASSERT (ExistAttempt == Attempt);\r
680\r
681 if (IfrNvData->Enabled == ISCSI_DISABLED &&\r
682 Attempt->SessionConfigData.Enabled != ISCSI_DISABLED) {\r
683\r
684 //\r
685 // User updates the Attempt from "Enabled"/"Enabled for MPIO" to "Disabled".\r
686 //\r
687 if (Attempt->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {\r
688 if (mPrivate->MpioCount < 1) {\r
689 return EFI_ABORTED;\r
690 }\r
691\r
692 if (--mPrivate->MpioCount == 0) {\r
693 mPrivate->EnableMpio = FALSE;\r
694 }\r
695 } else if (Attempt->SessionConfigData.Enabled == ISCSI_ENABLED) {\r
696 if (mPrivate->SinglePathCount < 1) {\r
697 return EFI_ABORTED;\r
698 }\r
699 mPrivate->SinglePathCount--;\r
700 }\r
701\r
702 } else if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO &&\r
703 Attempt->SessionConfigData.Enabled == ISCSI_ENABLED) {\r
704 //\r
705 // User updates the Attempt from "Enabled" to "Enabled for MPIO".\r
706 //\r
707 if (mPrivate->SinglePathCount < 1) {\r
708 return EFI_ABORTED;\r
709 }\r
710\r
711 mPrivate->EnableMpio = TRUE;\r
712 mPrivate->MpioCount++;\r
713 mPrivate->SinglePathCount--;\r
714\r
715 } else if (IfrNvData->Enabled == ISCSI_ENABLED &&\r
716 Attempt->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {\r
717 //\r
718 // User updates the Attempt from "Enabled for MPIO" to "Enabled".\r
719 //\r
720 if (mPrivate->MpioCount < 1) {\r
721 return EFI_ABORTED;\r
722 }\r
723\r
724 if (--mPrivate->MpioCount == 0) {\r
725 mPrivate->EnableMpio = FALSE;\r
726 }\r
727 mPrivate->SinglePathCount++;\r
728\r
729 } else if (IfrNvData->Enabled != ISCSI_DISABLED &&\r
730 Attempt->SessionConfigData.Enabled == ISCSI_DISABLED) {\r
731 //\r
732 // User updates the Attempt from "Disabled" to "Enabled"/"Enabled for MPIO".\r
733 //\r
734 if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO) {\r
735 mPrivate->EnableMpio = TRUE;\r
736 mPrivate->MpioCount++;\r
737\r
738 } else if (IfrNvData->Enabled == ISCSI_ENABLED) {\r
739 mPrivate->SinglePathCount++;\r
740 }\r
741 }\r
742\r
c0d494b5 743 } else if (ExistAttempt == NULL) {\r
744 //\r
745 // When a new attempt is created, pointer of the attempt is saved to\r
746 // mPrivate->NewAttempt, and also saved to mCallbackInfo->Current in\r
747 // IScsiConfigProcessDefault. If input Attempt does not match any existing\r
748 // attempt, it should be a new created attempt. Save it to system now.\r
749 // \r
750 ASSERT (Attempt == mPrivate->NewAttempt);\r
751\r
752 //\r
753 // Save current order number for this attempt.\r
754 //\r
755 AttemptConfigOrder = IScsiGetVariableAndSize (\r
756 L"AttemptOrder",\r
9bdc6592 757 &gIScsiConfigGuid,\r
c0d494b5 758 &AttemptConfigOrderSize\r
759 );\r
760\r
761 TotalNumber = AttemptConfigOrderSize / sizeof (UINT8);\r
762 TotalNumber++;\r
763\r
764 //\r
765 // Append the new created attempt order to the end.\r
766 //\r
767 AttemptOrderTmp = AllocateZeroPool (TotalNumber * sizeof (UINT8));\r
768 if (AttemptOrderTmp == NULL) {\r
769 if (AttemptConfigOrder != NULL) {\r
770 FreePool (AttemptConfigOrder);\r
771 }\r
772 return EFI_OUT_OF_RESOURCES;\r
773 }\r
774\r
775 if (AttemptConfigOrder != NULL) {\r
776 CopyMem (AttemptOrderTmp, AttemptConfigOrder, AttemptConfigOrderSize);\r
777 FreePool (AttemptConfigOrder);\r
778 }\r
779\r
780 AttemptOrderTmp[TotalNumber - 1] = Attempt->AttemptConfigIndex;\r
781 AttemptConfigOrder = AttemptOrderTmp;\r
782 AttemptConfigOrderSize = TotalNumber * sizeof (UINT8);\r
783\r
784 Status = gRT->SetVariable (\r
785 L"AttemptOrder",\r
9bdc6592 786 &gIScsiConfigGuid,\r
c0d494b5 787 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
788 AttemptConfigOrderSize,\r
789 AttemptConfigOrder\r
790 );\r
791 FreePool (AttemptConfigOrder);\r
792 if (EFI_ERROR (Status)) {\r
793 return Status;\r
794 }\r
795\r
796 //\r
797 // Insert new created attempt to array.\r
798 //\r
799 InsertTailList (&mPrivate->AttemptConfigs, &Attempt->Link);\r
800 mPrivate->AttemptCount++;\r
801 //\r
802 // Reset mPrivate->NewAttempt to NULL, which indicates none attempt is created\r
803 // but not saved now.\r
804 //\r
805 mPrivate->NewAttempt = NULL;\r
806\r
4c5a5e0c 807 if (IfrNvData->Enabled == ISCSI_ENABLED_FOR_MPIO) {\r
808 //\r
809 // This new Attempt is enabled for MPIO; enable the multipath mode.\r
810 //\r
811 mPrivate->EnableMpio = TRUE;\r
812 mPrivate->MpioCount++;\r
813 } else if (IfrNvData->Enabled == ISCSI_ENABLED) {\r
814 mPrivate->SinglePathCount++;\r
815 }\r
4c5a5e0c 816\r
c0d494b5 817 IScsiConfigUpdateAttempt ();\r
4c5a5e0c 818 }\r
819\r
820 //\r
821 // Record the user configuration information in NVR.\r
822 //\r
823 UnicodeSPrint (\r
824 mPrivate->PortString,\r
825 (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
826 L"%s%d",\r
827 MacString,\r
828 (UINTN) Attempt->AttemptConfigIndex\r
829 );\r
830\r
831 FreePool (MacString);\r
832\r
833 return gRT->SetVariable (\r
834 mPrivate->PortString,\r
835 &gEfiIScsiInitiatorNameProtocolGuid,\r
836 ISCSI_CONFIG_VAR_ATTR,\r
837 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),\r
838 Attempt\r
839 );\r
840}\r
841\r
842/**\r
843 Create Hii Extend Label OpCode as the start opcode and end opcode. It is \r
844 a help function.\r
845\r
846 @param[in] StartLabelNumber The number of start label.\r
847 @param[out] StartOpCodeHandle Points to the start opcode handle.\r
848 @param[out] StartLabel Points to the created start opcode.\r
849 @param[out] EndOpCodeHandle Points to the end opcode handle.\r
850 @param[out] EndLabel Points to the created end opcode.\r
851\r
852 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this\r
853 operation.\r
854 @retval EFI_INVALID_PARAMETER Any input parameter is invalid. \r
855 @retval EFI_SUCCESS The operation is completed successfully.\r
856\r
857**/\r
858EFI_STATUS\r
859IScsiCreateOpCode (\r
860 IN UINT16 StartLabelNumber,\r
861 OUT VOID **StartOpCodeHandle,\r
862 OUT EFI_IFR_GUID_LABEL **StartLabel,\r
863 OUT VOID **EndOpCodeHandle,\r
864 OUT EFI_IFR_GUID_LABEL **EndLabel\r
865 )\r
866{\r
867 EFI_STATUS Status;\r
868 EFI_IFR_GUID_LABEL *InternalStartLabel;\r
869 EFI_IFR_GUID_LABEL *InternalEndLabel;\r
870\r
871 if (StartOpCodeHandle == NULL || StartLabel == NULL || EndOpCodeHandle == NULL || EndLabel == NULL) {\r
872 return EFI_INVALID_PARAMETER;\r
873 }\r
874\r
875 *StartOpCodeHandle = NULL;\r
876 *EndOpCodeHandle = NULL;\r
877 Status = EFI_OUT_OF_RESOURCES;\r
878\r
879 //\r
880 // Initialize the container for dynamic opcodes.\r
881 //\r
882 *StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
883 if (*StartOpCodeHandle == NULL) {\r
884 return Status;\r
885 }\r
886\r
887 *EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
888 if (*EndOpCodeHandle == NULL) {\r
889 goto Exit;\r
890 }\r
891\r
892 //\r
893 // Create Hii Extend Label OpCode as the start opcode.\r
894 //\r
895 InternalStartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
896 *StartOpCodeHandle,\r
897 &gEfiIfrTianoGuid,\r
898 NULL,\r
899 sizeof (EFI_IFR_GUID_LABEL)\r
900 );\r
901 if (InternalStartLabel == NULL) {\r
902 goto Exit;\r
903 }\r
904 \r
905 InternalStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
906 InternalStartLabel->Number = StartLabelNumber;\r
907\r
908 //\r
909 // Create Hii Extend Label OpCode as the end opcode.\r
910 //\r
911 InternalEndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (\r
912 *EndOpCodeHandle,\r
913 &gEfiIfrTianoGuid,\r
914 NULL,\r
915 sizeof (EFI_IFR_GUID_LABEL)\r
916 );\r
917 if (InternalEndLabel == NULL) {\r
918 goto Exit;\r
919 }\r
920\r
921 InternalEndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
922 InternalEndLabel->Number = LABEL_END;\r
923\r
924 *StartLabel = InternalStartLabel;\r
925 *EndLabel = InternalEndLabel;\r
926\r
927 return EFI_SUCCESS;\r
928\r
929Exit:\r
930\r
931 if (*StartOpCodeHandle != NULL) {\r
932 HiiFreeOpCodeHandle (*StartOpCodeHandle);\r
933 }\r
934\r
935 if (*EndOpCodeHandle != NULL) {\r
936 HiiFreeOpCodeHandle (*EndOpCodeHandle);\r
937 }\r
938 \r
939 return Status;\r
940}\r
941\r
942/**\r
943 Callback function when user presses "Add an Attempt".\r
944\r
945 @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this\r
946 operation.\r
947 @retval EFI_SUCCESS The operation is completed successfully.\r
948\r
949**/\r
950EFI_STATUS\r
951IScsiConfigAddAttempt (\r
952 VOID\r
953 )\r
954{\r
955 LIST_ENTRY *Entry;\r
956 ISCSI_NIC_INFO *NicInfo;\r
957 EFI_STRING_ID PortTitleToken;\r
958 EFI_STRING_ID PortTitleHelpToken;\r
959 CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN];\r
960 EFI_STATUS Status;\r
961 VOID *StartOpCodeHandle;\r
962 EFI_IFR_GUID_LABEL *StartLabel;\r
963 VOID *EndOpCodeHandle;\r
964 EFI_IFR_GUID_LABEL *EndLabel;\r
965\r
966 Status = IScsiCreateOpCode (\r
967 MAC_ENTRY_LABEL,\r
968 &StartOpCodeHandle,\r
969 &StartLabel,\r
970 &EndOpCodeHandle,\r
971 &EndLabel\r
972 );\r
973 if (EFI_ERROR (Status)) {\r
974 return Status;\r
975 }\r
976\r
977 //\r
978 // Ask user to select a MAC for this attempt.\r
979 //\r
980 NET_LIST_FOR_EACH (Entry, &mPrivate->NicInfoList) {\r
981 NicInfo = NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link);\r
982 IScsiMacAddrToStr (\r
983 &NicInfo->PermanentAddress,\r
984 NicInfo->HwAddressSize,\r
985 NicInfo->VlanId,\r
986 MacString\r
987 );\r
988\r
c0d494b5 989 UnicodeSPrint (mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, L"MAC %s", MacString);\r
4c5a5e0c 990 PortTitleToken = HiiSetString (\r
991 mCallbackInfo->RegisteredHandle,\r
992 0,\r
993 mPrivate->PortString,\r
994 NULL\r
995 );\r
996 if (PortTitleToken == 0) {\r
997 Status = EFI_INVALID_PARAMETER;\r
998 goto Exit;\r
999 }\r
1000\r
1001 UnicodeSPrint (\r
1002 mPrivate->PortString,\r
1003 (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
1004 L"PFA: Bus %d | Dev %d | Func %d",\r
1005 NicInfo->BusNumber,\r
1006 NicInfo->DeviceNumber,\r
1007 NicInfo->FunctionNumber\r
1008 );\r
1009 PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, mPrivate->PortString, NULL);\r
1010 if (PortTitleHelpToken == 0) {\r
1011 Status = EFI_INVALID_PARAMETER;\r
1012 goto Exit; \r
1013 }\r
1014\r
1015 HiiCreateGotoOpCode (\r
1016 StartOpCodeHandle, // Container for dynamic created opcodes\r
1017 FORMID_ATTEMPT_FORM,\r
1018 PortTitleToken,\r
1019 PortTitleHelpToken,\r
1020 EFI_IFR_FLAG_CALLBACK, // Question flag\r
1021 (UINT16) (KEY_MAC_ENTRY_BASE + NicInfo->NicIndex)\r
1022 );\r
1023 }\r
1024\r
1025 Status = HiiUpdateForm (\r
1026 mCallbackInfo->RegisteredHandle, // HII handle\r
9bdc6592 1027 &gIScsiConfigGuid, // Formset GUID\r
4c5a5e0c 1028 FORMID_MAC_FORM, // Form ID\r
1029 StartOpCodeHandle, // Label for where to insert opcodes\r
1030 EndOpCodeHandle // Replace data\r
1031 );\r
1032\r
1033Exit:\r
1034 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1035 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
1036 \r
1037 return Status;\r
1038}\r
1039\r
1040\r
1041/**\r
1042 Update the MAIN form to display the configured attempts.\r
1043\r
1044**/\r
1045VOID\r
1046IScsiConfigUpdateAttempt (\r
1047 VOID\r
1048 )\r
1049{\r
1050 CHAR16 AttemptName[ATTEMPT_NAME_MAX_SIZE];\r
1051 LIST_ENTRY *Entry;\r
1052 ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;\r
1053 VOID *StartOpCodeHandle;\r
1054 EFI_IFR_GUID_LABEL *StartLabel;\r
1055 VOID *EndOpCodeHandle;\r
1056 EFI_IFR_GUID_LABEL *EndLabel;\r
1057 EFI_STATUS Status;\r
1058\r
1059 Status = IScsiCreateOpCode (\r
1060 ATTEMPT_ENTRY_LABEL,\r
1061 &StartOpCodeHandle,\r
1062 &StartLabel,\r
1063 &EndOpCodeHandle,\r
1064 &EndLabel\r
1065 );\r
1066 if (EFI_ERROR (Status)) {\r
1067 return ;\r
1068 }\r
1069\r
1070 NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {\r
1071 AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);\r
1072\r
1073 AsciiStrToUnicodeStr (AttemptConfigData->AttemptName, AttemptName);\r
1074 UnicodeSPrint (mPrivate->PortString, (UINTN) 128, L"Attempt %s", AttemptName);\r
1075 AttemptConfigData->AttemptTitleToken = HiiSetString (\r
1076 mCallbackInfo->RegisteredHandle,\r
1077 0,\r
1078 mPrivate->PortString,\r
1079 NULL\r
1080 );\r
1081 if (AttemptConfigData->AttemptTitleToken == 0) {\r
1082 return ;\r
1083 }\r
1084\r
1085 HiiCreateGotoOpCode (\r
1086 StartOpCodeHandle, // Container for dynamic created opcodes\r
1087 FORMID_ATTEMPT_FORM, // Form ID\r
1088 AttemptConfigData->AttemptTitleToken, // Prompt text\r
1089 AttemptConfigData->AttemptTitleHelpToken, // Help text\r
1090 EFI_IFR_FLAG_CALLBACK, // Question flag\r
1091 (UINT16) (KEY_ATTEMPT_ENTRY_BASE + AttemptConfigData->AttemptConfigIndex) // Question ID\r
1092 );\r
1093 }\r
1094\r
1095 HiiUpdateForm (\r
1096 mCallbackInfo->RegisteredHandle, // HII handle\r
9bdc6592 1097 &gIScsiConfigGuid, // Formset GUID\r
4c5a5e0c 1098 FORMID_MAIN_FORM, // Form ID\r
1099 StartOpCodeHandle, // Label for where to insert opcodes\r
1100 EndOpCodeHandle // Replace data\r
1101 ); \r
1102\r
1103 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1104 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
1105}\r
1106\r
1107\r
1108/**\r
1109 Callback function when user presses "Commit Changes and Exit" in Delete Attempts.\r
1110\r
1111 @param[in] IfrNvData The IFR NV data.\r
1112\r
1113 @retval EFI_NOT_FOUND Cannot find the corresponding variable.\r
1114 @retval EFI_SUCCESS The operation is completed successfully.\r
1115 @retval EFI_ABOTRED This operation is aborted cause of error\r
1116 configuration.\r
1117 @retval EFI_OUT_OF_RESOURCES Fail to finish the operation due to lack of\r
1118 resources.\r
1119\r
1120**/\r
1121EFI_STATUS\r
1122IScsiConfigDeleteAttempts (\r
1123 IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData\r
1124 )\r
1125{\r
1126 EFI_STATUS Status;\r
1127 UINTN Index;\r
1128 UINTN NewIndex;\r
1129 ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;\r
1130 UINT8 *AttemptConfigOrder;\r
1131 UINTN AttemptConfigOrderSize;\r
1132 UINT8 *AttemptNewOrder;\r
1133 UINT32 Attribute;\r
1134 UINTN Total;\r
1135 UINTN NewTotal;\r
1136 LIST_ENTRY *Entry;\r
1137 LIST_ENTRY *NextEntry;\r
1138 CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN];\r
1139\r
1140 AttemptConfigOrder = IScsiGetVariableAndSize (\r
1141 L"AttemptOrder",\r
9bdc6592 1142 &gIScsiConfigGuid,\r
4c5a5e0c 1143 &AttemptConfigOrderSize\r
1144 );\r
1145 if ((AttemptConfigOrder == NULL) || (AttemptConfigOrderSize == 0)) {\r
1146 return EFI_NOT_FOUND;\r
1147 }\r
1148\r
1149 AttemptNewOrder = AllocateZeroPool (AttemptConfigOrderSize);\r
1150 if (AttemptNewOrder == NULL) {\r
c0d494b5 1151 Status = EFI_OUT_OF_RESOURCES;\r
1152 goto Error;\r
4c5a5e0c 1153 }\r
1154\r
1155 Total = AttemptConfigOrderSize / sizeof (UINT8);\r
1156 NewTotal = Total;\r
1157 Index = 0;\r
1158\r
1159 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &mPrivate->AttemptConfigs) {\r
1160 if (IfrNvData->DeleteAttemptList[Index] == 0) {\r
1161 Index++;\r
1162 continue;\r
1163 }\r
1164\r
1165 //\r
1166 // Delete the attempt.\r
1167 //\r
1168\r
1169 AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);\r
1170 if (AttemptConfigData == NULL) {\r
1171 Status = EFI_NOT_FOUND;\r
1172 goto Error;\r
1173 }\r
1174\r
1175 //\r
1176 // Remove this attempt from UI configured attempt list.\r
1177 //\r
1178 RemoveEntryList (&AttemptConfigData->Link);\r
1179 mPrivate->AttemptCount--;\r
1180\r
1181 if (AttemptConfigData->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {\r
1182 if (mPrivate->MpioCount < 1) {\r
1183 Status = EFI_ABORTED;\r
1184 goto Error;\r
1185 }\r
1186\r
1187 //\r
1188 // No more attempt is enabled for MPIO. Transit the iSCSI mode to single path.\r
1189 //\r
1190 if (--mPrivate->MpioCount == 0) {\r
1191 mPrivate->EnableMpio = FALSE;\r
1192 }\r
1193 } else if (AttemptConfigData->SessionConfigData.Enabled == ISCSI_ENABLED) {\r
1194 if (mPrivate->SinglePathCount < 1) {\r
1195 Status = EFI_ABORTED;\r
1196 goto Error;\r
1197 }\r
1198\r
1199 mPrivate->SinglePathCount--;\r
1200 }\r
1201\r
1202 AsciiStrToUnicodeStr (AttemptConfigData->MacString, MacString);\r
1203\r
1204 UnicodeSPrint (\r
1205 mPrivate->PortString,\r
1206 (UINTN) 128,\r
1207 L"%s%d",\r
1208 MacString,\r
1209 (UINTN) AttemptConfigData->AttemptConfigIndex\r
1210 );\r
1211\r
1212 gRT->SetVariable (\r
1213 mPrivate->PortString,\r
1214 &gEfiIScsiInitiatorNameProtocolGuid,\r
1215 0,\r
1216 0,\r
1217 NULL\r
1218 );\r
1219\r
1220 //\r
1221 // Mark the attempt order in NVR to be deleted - 0.\r
1222 //\r
1223 for (NewIndex = 0; NewIndex < Total; NewIndex++) {\r
1224 if (AttemptConfigOrder[NewIndex] == AttemptConfigData->AttemptConfigIndex) {\r
1225 AttemptConfigOrder[NewIndex] = 0;\r
1226 break;\r
1227 }\r
1228 }\r
1229\r
1230 NewTotal--;\r
1231 FreePool (AttemptConfigData);\r
1232\r
1233 //\r
1234 // Check next Attempt.\r
1235 //\r
1236 Index++;\r
1237 }\r
1238\r
1239 //\r
1240 // Construct AttemptNewOrder.\r
1241 //\r
1242 for (Index = 0, NewIndex = 0; Index < Total; Index++) {\r
1243 if (AttemptConfigOrder[Index] != 0) {\r
1244 AttemptNewOrder[NewIndex] = AttemptConfigOrder[Index];\r
1245 NewIndex++;\r
1246 }\r
1247 }\r
1248\r
1249 Attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS\r
1250 | EFI_VARIABLE_NON_VOLATILE;\r
1251\r
1252 //\r
1253 // Update AttemptOrder in NVR.\r
1254 //\r
1255 Status = gRT->SetVariable (\r
1256 L"AttemptOrder",\r
9bdc6592 1257 &gIScsiConfigGuid,\r
4c5a5e0c 1258 Attribute,\r
1259 NewTotal * sizeof (UINT8),\r
1260 AttemptNewOrder\r
1261 );\r
1262\r
1263Error:\r
c0d494b5 1264 if (AttemptConfigOrder != NULL) {\r
1265 FreePool (AttemptConfigOrder);\r
1266 }\r
1267\r
1268 if (AttemptNewOrder != NULL) {\r
1269 FreePool (AttemptNewOrder);\r
1270 }\r
4c5a5e0c 1271 \r
1272 return Status;\r
1273}\r
1274\r
1275\r
1276/**\r
1277 Callback function when user presses "Delete Attempts".\r
1278\r
1279 @param[in] IfrNvData The IFR nv data.\r
1280\r
1281 @retval EFI_INVALID_PARAMETER Any parameter is invalid.\r
1282 @retval EFI_BUFFER_TOO_SMALL The buffer in UpdateData is too small.\r
1283 @retval EFI_SUCCESS The operation is completed successfully.\r
1284\r
1285**/\r
1286EFI_STATUS\r
1287IScsiConfigDisplayDeleteAttempts (\r
1288 IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData\r
1289 )\r
1290{\r
1291\r
1292 UINT8 *AttemptConfigOrder;\r
1293 UINTN AttemptConfigOrderSize;\r
1294 LIST_ENTRY *Entry;\r
1295 ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;\r
1296 UINT8 Index;\r
1297 VOID *StartOpCodeHandle;\r
1298 EFI_IFR_GUID_LABEL *StartLabel;\r
1299 VOID *EndOpCodeHandle;\r
1300 EFI_IFR_GUID_LABEL *EndLabel;\r
1301 EFI_STATUS Status;\r
1302\r
1303 Status = IScsiCreateOpCode (\r
1304 DELETE_ENTRY_LABEL,\r
1305 &StartOpCodeHandle,\r
1306 &StartLabel,\r
1307 &EndOpCodeHandle,\r
1308 &EndLabel\r
1309 );\r
1310 if (EFI_ERROR (Status)) {\r
1311 return Status;\r
1312 }\r
1313\r
1314 AttemptConfigOrder = IScsiGetVariableAndSize (\r
1315 L"AttemptOrder",\r
9bdc6592 1316 &gIScsiConfigGuid,\r
4c5a5e0c 1317 &AttemptConfigOrderSize\r
1318 );\r
1319 if (AttemptConfigOrder != NULL) {\r
1320 //\r
1321 // Create the check box opcode to be deleted.\r
1322 //\r
1323 Index = 0;\r
1324\r
1325 NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {\r
1326 AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);\r
1327 IfrNvData->DeleteAttemptList[Index] = 0x00;\r
1328\r
1329 HiiCreateCheckBoxOpCode(\r
1330 StartOpCodeHandle,\r
1331 (EFI_QUESTION_ID) (ATTEMPT_DEL_QUESTION_ID + Index),\r
1332 CONFIGURATION_VARSTORE_ID,\r
1333 (UINT16) (ATTEMPT_DEL_VAR_OFFSET + Index),\r
1334 AttemptConfigData->AttemptTitleToken,\r
1335 AttemptConfigData->AttemptTitleHelpToken,\r
1336 0,\r
1337 0,\r
1338 NULL\r
1339 );\r
1340\r
1341 Index++;\r
1342\r
1343 if (Index == ISCSI_MAX_ATTEMPTS_NUM) {\r
1344 break;\r
1345 }\r
1346 }\r
1347\r
1348 FreePool (AttemptConfigOrder);\r
1349 }\r
1350\r
1351 Status = HiiUpdateForm (\r
1352 mCallbackInfo->RegisteredHandle, // HII handle\r
9bdc6592 1353 &gIScsiConfigGuid, // Formset GUID\r
4c5a5e0c 1354 FORMID_DELETE_FORM, // Form ID\r
1355 StartOpCodeHandle, // Label for where to insert opcodes\r
1356 EndOpCodeHandle // Replace data\r
1357 ); \r
1358\r
1359 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1360 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
1361\r
1362 return Status;\r
1363}\r
1364\r
1365\r
1366/**\r
1367 Callback function when user presses "Change Attempt Order".\r
1368\r
1369 @retval EFI_INVALID_PARAMETER Any parameter is invalid.\r
1370 @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this\r
1371 operation.\r
1372 @retval EFI_SUCCESS The operation is completed successfully.\r
1373\r
1374**/\r
1375EFI_STATUS\r
1376IScsiConfigDisplayOrderAttempts (\r
1377 VOID\r
1378 )\r
1379{\r
1380 EFI_STATUS Status;\r
1381 UINT8 Index;\r
1382 LIST_ENTRY *Entry;\r
1383 ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;\r
1384 VOID *StartOpCodeHandle;\r
1385 EFI_IFR_GUID_LABEL *StartLabel;\r
1386 VOID *EndOpCodeHandle;\r
1387 EFI_IFR_GUID_LABEL *EndLabel;\r
1388 VOID *OptionsOpCodeHandle; \r
1389 \r
1390 Status = IScsiCreateOpCode (\r
1391 ORDER_ENTRY_LABEL,\r
1392 &StartOpCodeHandle,\r
1393 &StartLabel,\r
1394 &EndOpCodeHandle,\r
1395 &EndLabel\r
1396 );\r
1397 if (EFI_ERROR (Status)) {\r
1398 return Status;\r
1399 }\r
7a49cd08 1400 ASSERT (StartOpCodeHandle != NULL);\r
4c5a5e0c 1401\r
1402 OptionsOpCodeHandle = NULL;\r
1403\r
1404 //\r
1405 // If no attempt to be ordered, update the original form and exit.\r
1406 //\r
1407 if (mPrivate->AttemptCount == 0) {\r
1408 goto Exit;\r
1409 }\r
1410\r
1411 //\r
1412 // Create Option OpCode.\r
1413 //\r
1414 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1415 if (OptionsOpCodeHandle == NULL) {\r
1416 Status = EFI_OUT_OF_RESOURCES;\r
1417 goto Error;\r
1418 }\r
1419\r
1420 Index = 0;\r
1421\r
1422 NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {\r
1423 AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);\r
1424 HiiCreateOneOfOptionOpCode (\r
1425 OptionsOpCodeHandle,\r
1426 AttemptConfigData->AttemptTitleToken,\r
1427 0,\r
1428 EFI_IFR_NUMERIC_SIZE_1,\r
1429 AttemptConfigData->AttemptConfigIndex\r
1430 );\r
1431 Index++;\r
1432 }\r
1433\r
1434 ASSERT (Index == mPrivate->AttemptCount);\r
1435\r
1436 HiiCreateOrderedListOpCode (\r
1437 StartOpCodeHandle, // Container for dynamic created opcodes\r
1438 DYNAMIC_ORDERED_LIST_QUESTION_ID, // Question ID\r
1439 CONFIGURATION_VARSTORE_ID, // VarStore ID\r
1440 DYNAMIC_ORDERED_LIST_VAR_OFFSET, // Offset in Buffer Storage\r
1441 STRING_TOKEN (STR_ORDER_ATTEMPT_ENTRY), // Question prompt text \r
1442 STRING_TOKEN (STR_ORDER_ATTEMPT_ENTRY), // Question help text \r
1443 0, // Question flag\r
1444 EFI_IFR_UNIQUE_SET, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET\r
1445 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value\r
1446 ISCSI_MAX_ATTEMPTS_NUM, // Maximum container\r
1447 OptionsOpCodeHandle, // Option Opcode list \r
1448 NULL // Default Opcode is NULL \r
1449 );\r
1450\r
1451Exit:\r
1452 Status = HiiUpdateForm (\r
1453 mCallbackInfo->RegisteredHandle, // HII handle\r
9bdc6592 1454 &gIScsiConfigGuid, // Formset GUID\r
4c5a5e0c 1455 FORMID_ORDER_FORM, // Form ID\r
1456 StartOpCodeHandle, // Label for where to insert opcodes\r
1457 EndOpCodeHandle // Replace data\r
1458 ); \r
1459\r
1460Error:\r
1461 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1462 HiiFreeOpCodeHandle (EndOpCodeHandle); \r
1463 if (OptionsOpCodeHandle != NULL) {\r
1464 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
1465 }\r
1466\r
1467 return Status;\r
1468}\r
1469\r
1470\r
1471/**\r
1472 Callback function when user presses "Commit Changes and Exit" in Change Attempt Order.\r
1473\r
1474 @param[in] IfrNvData The IFR nv data.\r
1475\r
1476 @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this\r
1477 operation.\r
1478 @retval EFI_NOT_FOUND Cannot find the corresponding variable.\r
1479 @retval EFI_SUCCESS The operation is completed successfully.\r
1480\r
1481**/\r
1482EFI_STATUS\r
1483IScsiConfigOrderAttempts (\r
1484 IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData\r
1485 )\r
1486{\r
1487 EFI_STATUS Status;\r
1488 UINTN Index;\r
1489 UINTN Indexj;\r
1490 UINT8 AttemptConfigIndex;\r
1491 ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;\r
1492 UINT8 *AttemptConfigOrder;\r
1493 UINT8 *AttemptConfigOrderTmp;\r
1494 UINTN AttemptConfigOrderSize;\r
1495\r
1496 AttemptConfigOrder = IScsiGetVariableAndSize (\r
1497 L"AttemptOrder",\r
9bdc6592 1498 &gIScsiConfigGuid,\r
4c5a5e0c 1499 &AttemptConfigOrderSize\r
1500 );\r
1501 if (AttemptConfigOrder == NULL) {\r
1502 return EFI_NOT_FOUND;\r
1503 }\r
1504\r
1505 AttemptConfigOrderTmp = AllocateZeroPool (AttemptConfigOrderSize);\r
1506 if (AttemptConfigOrderTmp == NULL) {\r
1507 Status = EFI_OUT_OF_RESOURCES;\r
1508 goto Exit;\r
1509 }\r
1510\r
1511 for (Index = 0; Index < ISCSI_MAX_ATTEMPTS_NUM; Index++) {\r
1512 //\r
1513 // The real content ends with 0.\r
1514 //\r
1515 if (IfrNvData->DynamicOrderedList[Index] == 0) {\r
1516 break;\r
1517 }\r
1518\r
1519 AttemptConfigIndex = IfrNvData->DynamicOrderedList[Index];\r
1520 AttemptConfigData = IScsiConfigGetAttemptByConfigIndex (AttemptConfigIndex);\r
1521 if (AttemptConfigData == NULL) {\r
1522 Status = EFI_NOT_FOUND;\r
1523 goto Exit;\r
1524 }\r
1525\r
1526 //\r
1527 // Reorder the Attempt List.\r
1528 //\r
1529 RemoveEntryList (&AttemptConfigData->Link);\r
1530 InsertTailList (&mPrivate->AttemptConfigs, &AttemptConfigData->Link);\r
1531\r
1532 AttemptConfigOrderTmp[Index] = AttemptConfigIndex;\r
1533\r
1534 //\r
1535 // Mark it to be deleted - 0.\r
1536 //\r
1537 for (Indexj = 0; Indexj < AttemptConfigOrderSize / sizeof (UINT8); Indexj++) {\r
1538 if (AttemptConfigOrder[Indexj] == AttemptConfigIndex) {\r
1539 AttemptConfigOrder[Indexj] = 0;\r
1540 break;\r
1541 }\r
1542 }\r
1543 }\r
1544\r
1545 //\r
1546 // Adjust the attempt order in NVR.\r
1547 //\r
1548 for (; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {\r
1549 for (Indexj = 0; Indexj < AttemptConfigOrderSize / sizeof (UINT8); Indexj++) {\r
1550 if (AttemptConfigOrder[Indexj] != 0) {\r
1551 AttemptConfigOrderTmp[Index] = AttemptConfigOrder[Indexj];\r
1552 AttemptConfigOrder[Indexj] = 0;\r
1553 continue;\r
1554 }\r
1555 }\r
1556 }\r
1557\r
1558 Status = gRT->SetVariable (\r
1559 L"AttemptOrder",\r
9bdc6592 1560 &gIScsiConfigGuid,\r
4c5a5e0c 1561 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1562 AttemptConfigOrderSize,\r
1563 AttemptConfigOrderTmp\r
1564 );\r
1565\r
1566Exit:\r
1567 if (AttemptConfigOrderTmp != NULL) {\r
1568 FreePool (AttemptConfigOrderTmp);\r
1569 }\r
1570\r
1571 FreePool (AttemptConfigOrder);\r
1572 return Status;\r
1573}\r
1574\r
1575\r
1576/**\r
1577 Callback function when a user presses "Attempt *" or when a user selects a NIC to\r
1578 create the new attempt.\r
1579\r
1580 @param[in] KeyValue A unique value which is sent to the original\r
1581 exporting driver so that it can identify the type\r
1582 of data to expect.\r
1583 @param[in] IfrNvData The IFR nv data.\r
1584\r
1585 @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this\r
1586 operation.\r
1587 @retval EFI_NOT_FOUND Cannot find the corresponding variable.\r
1588 @retval EFI_SUCCESS The operation is completed successfully.\r
1589\r
1590**/\r
1591EFI_STATUS\r
1592IScsiConfigProcessDefault (\r
1593 IN EFI_QUESTION_ID KeyValue,\r
1594 IN ISCSI_CONFIG_IFR_NVDATA *IfrNvData\r
1595 )\r
1596{\r
1597 BOOLEAN NewAttempt;\r
1598 ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;\r
1599 ISCSI_SESSION_CONFIG_NVDATA *ConfigData;\r
1600 UINT8 CurrentAttemptConfigIndex;\r
1601 ISCSI_NIC_INFO *NicInfo;\r
1602 UINT8 NicIndex;\r
1603 CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN];\r
1604 UINT8 *AttemptConfigOrder;\r
1605 UINTN AttemptConfigOrderSize;\r
1606 UINTN TotalNumber;\r
4c5a5e0c 1607 UINTN Index;\r
4c5a5e0c 1608\r
c0d494b5 1609 //\r
1610 // Is User creating a new attempt?\r
1611 //\r
4c5a5e0c 1612 NewAttempt = FALSE;\r
1613\r
1614 if ((KeyValue >= KEY_MAC_ENTRY_BASE) &&\r
1615 (KeyValue <= (UINT16) (mPrivate->MaxNic + KEY_MAC_ENTRY_BASE))) {\r
1616 //\r
1617 // User has pressed "Add an Attempt" and then selects a NIC.\r
1618 //\r
1619 NewAttempt = TRUE;\r
1620 } else if ((KeyValue >= KEY_ATTEMPT_ENTRY_BASE) &&\r
1621 (KeyValue < (ISCSI_MAX_ATTEMPTS_NUM + KEY_ATTEMPT_ENTRY_BASE))) {\r
1622\r
1623 //\r
1624 // User has pressed "Attempt *".\r
1625 //\r
1626 NewAttempt = FALSE;\r
1627 } else {\r
1628 //\r
1629 // Don't process anything.\r
1630 //\r
1631 return EFI_SUCCESS;\r
1632 }\r
639a76d1
ED
1633 \r
1634 //\r
1635 // Free any attempt that is previously created but not saved to system.\r
1636 //\r
1637 if (mPrivate->NewAttempt != NULL) {\r
1638 FreePool (mPrivate->NewAttempt);\r
1639 mPrivate->NewAttempt = NULL;\r
1640 }\r
4c5a5e0c 1641\r
1642 if (NewAttempt) {\r
1643 //\r
1644 // Determine which NIC user has selected for the new created attempt.\r
1645 //\r
1646 NicIndex = (UINT8) (KeyValue - KEY_MAC_ENTRY_BASE);\r
1647 NicInfo = IScsiGetNicInfoByIndex (NicIndex);\r
1648 if (NicInfo == NULL) {\r
1649 return EFI_NOT_FOUND;\r
1650 }\r
1651 \r
1652 //\r
c0d494b5 1653 // Create new attempt.\r
4c5a5e0c 1654 //\r
1655\r
1656 AttemptConfigData = AllocateZeroPool (sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA));\r
1657 if (AttemptConfigData == NULL) {\r
1658 return EFI_OUT_OF_RESOURCES;\r
1659 }\r
1660\r
1661 ConfigData = &AttemptConfigData->SessionConfigData;\r
1662 ConfigData->TargetPort = ISCSI_WELL_KNOWN_PORT;\r
1663 ConfigData->ConnectTimeout = CONNECT_DEFAULT_TIMEOUT;\r
1664 ConfigData->ConnectRetryCount = CONNECT_MIN_RETRY;\r
1665\r
1666 AttemptConfigData->AuthenticationType = ISCSI_AUTH_TYPE_CHAP;\r
1667 AttemptConfigData->AuthConfigData.CHAP.CHAPType = ISCSI_CHAP_UNI;\r
1668\r
1669 //\r
1670 // Get current order number for this attempt.\r
1671 //\r
1672 AttemptConfigOrder = IScsiGetVariableAndSize (\r
1673 L"AttemptOrder",\r
9bdc6592 1674 &gIScsiConfigGuid,\r
4c5a5e0c 1675 &AttemptConfigOrderSize\r
1676 );\r
1677\r
1678 TotalNumber = AttemptConfigOrderSize / sizeof (UINT8);\r
1679\r
1680 if (AttemptConfigOrder == NULL) {\r
1681 CurrentAttemptConfigIndex = 1;\r
1682 } else {\r
1683 //\r
1684 // Get the max attempt config index.\r
1685 //\r
1686 CurrentAttemptConfigIndex = AttemptConfigOrder[0];\r
1687 for (Index = 1; Index < TotalNumber; Index++) {\r
1688 if (CurrentAttemptConfigIndex < AttemptConfigOrder[Index]) {\r
1689 CurrentAttemptConfigIndex = AttemptConfigOrder[Index];\r
1690 }\r
1691 }\r
1692\r
1693 CurrentAttemptConfigIndex++;\r
1694 }\r
1695\r
1696 TotalNumber++;\r
1697\r
1698 //\r
c0d494b5 1699 // Record the mapping between attempt order and attempt's configdata.\r
4c5a5e0c 1700 //\r
c0d494b5 1701 AttemptConfigData->AttemptConfigIndex = CurrentAttemptConfigIndex;\r
4c5a5e0c 1702\r
1703 if (AttemptConfigOrder != NULL) {\r
c0d494b5 1704 FreePool (AttemptConfigOrder);\r
4c5a5e0c 1705 }\r
1706\r
4c5a5e0c 1707 //\r
1708 // Record the MAC info in Config Data.\r
1709 //\r
1710 IScsiMacAddrToStr (\r
1711 &NicInfo->PermanentAddress,\r
1712 NicInfo->HwAddressSize,\r
1713 NicInfo->VlanId,\r
1714 MacString\r
1715 );\r
1716\r
1717 UnicodeStrToAsciiStr (MacString, AttemptConfigData->MacString);\r
1718 AttemptConfigData->NicIndex = NicIndex;\r
1719\r
1720 //\r
1721 // Generate OUI-format ISID based on MAC address.\r
1722 //\r
1723 CopyMem (AttemptConfigData->SessionConfigData.IsId, &NicInfo->PermanentAddress, 6);\r
1724 AttemptConfigData->SessionConfigData.IsId[0] = \r
1725 (UINT8) (AttemptConfigData->SessionConfigData.IsId[0] & 0x3F);\r
1726\r
1727 //\r
1728 // Add the help info for the new attempt.\r
1729 //\r
1730 UnicodeSPrint (\r
1731 mPrivate->PortString,\r
1732 (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
1733 L"MAC: %s, PFA: Bus %d | Dev %d | Func %d",\r
1734 MacString,\r
1735 NicInfo->BusNumber,\r
1736 NicInfo->DeviceNumber,\r
1737 NicInfo->FunctionNumber\r
1738 );\r
1739\r
1740 AttemptConfigData->AttemptTitleHelpToken = HiiSetString (\r
1741 mCallbackInfo->RegisteredHandle,\r
1742 0,\r
1743 mPrivate->PortString,\r
1744 NULL\r
1745 );\r
1746 if (AttemptConfigData->AttemptTitleHelpToken == 0) {\r
1747 FreePool (AttemptConfigData);\r
1748 return EFI_INVALID_PARAMETER;\r
1749 }\r
1750\r
1751 //\r
1752 // Set the attempt name to default.\r
1753 //\r
1754 UnicodeSPrint (\r
1755 mPrivate->PortString,\r
1756 (UINTN) 128,\r
1757 L"%d",\r
1758 (UINTN) AttemptConfigData->AttemptConfigIndex\r
1759 );\r
1760 UnicodeStrToAsciiStr (mPrivate->PortString, AttemptConfigData->AttemptName);\r
1761\r
c0d494b5 1762 //\r
1763 // Save the created Attempt temporarily. If user does not save the attempt\r
1764 // by press 'KEY_SAVE_ATTEMPT_CONFIG' later, iSCSI driver would know that\r
1765 // and free resources.\r
1766 //\r
1767 mPrivate->NewAttempt = (VOID *) AttemptConfigData;\r
1768\r
4c5a5e0c 1769 } else {\r
1770 //\r
1771 // Determine which Attempt user has selected to configure.\r
1772 // Get the attempt configuration data.\r
1773 //\r
1774 CurrentAttemptConfigIndex = (UINT8) (KeyValue - KEY_ATTEMPT_ENTRY_BASE);\r
1775\r
1776 AttemptConfigData = IScsiConfigGetAttemptByConfigIndex (CurrentAttemptConfigIndex);\r
1777 if (AttemptConfigData == NULL) {\r
1778 DEBUG ((DEBUG_ERROR, "Corresponding configuration data can not be retrieved!\n"));\r
1779 return EFI_NOT_FOUND;\r
1780 }\r
1781 }\r
1782\r
1783 //\r
1784 // Clear the old IFR data to avoid sharing it with other attempts.\r
1785 //\r
1786 if (IfrNvData->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) {\r
1787 ZeroMem (IfrNvData->CHAPName, sizeof (IfrNvData->CHAPName));\r
1788 ZeroMem (IfrNvData->CHAPSecret, sizeof (IfrNvData->CHAPSecret));\r
1789 ZeroMem (IfrNvData->ReverseCHAPName, sizeof (IfrNvData->ReverseCHAPName));\r
1790 ZeroMem (IfrNvData->ReverseCHAPSecret, sizeof (IfrNvData->ReverseCHAPSecret));\r
1791 }\r
1792 \r
1793 IScsiConvertAttemptConfigDataToIfrNvData (AttemptConfigData, IfrNvData);\r
1794\r
c0d494b5 1795 //\r
1796 // Update current attempt to be a new created attempt or an existing attempt.\r
1797 //\r
4c5a5e0c 1798 mCallbackInfo->Current = AttemptConfigData;\r
1799\r
4c5a5e0c 1800 return EFI_SUCCESS;\r
1801}\r
1802\r
1803\r
1804/**\r
1805 \r
1806 This function allows the caller to request the current\r
1807 configuration for one or more named elements. The resulting\r
1808 string is in <ConfigAltResp> format. Also, any and all alternative\r
1809 configuration strings shall be appended to the end of the\r
1810 current configuration string. If they are, they must appear\r
1811 after the current configuration. They must contain the same\r
1812 routing (GUID, NAME, PATH) as the current configuration string.\r
1813 They must have an additional description indicating the type of\r
1814 alternative configuration the string represents,\r
1815 "ALTCFG=<StringToken>". That <StringToken> (when\r
1816 converted from Hex UNICODE to binary) is a reference to a\r
1817 string in the associated string pack.\r
1818\r
1819 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
1820\r
1821 @param[in] Request A null-terminated Unicode string in\r
1822 <ConfigRequest> format. Note that this\r
1823 includes the routing information as well as\r
1824 the configurable name / value pairs. It is\r
1825 invalid for this string to be in\r
1826 <MultiConfigRequest> format.\r
1827\r
1828 @param[out] Progress On return, points to a character in the\r
1829 Request string. Points to the string's null\r
1830 terminator if request was successful. Points\r
1831 to the most recent "&" before the first\r
1832 failing name / value pair (or the beginning\r
1833 of the string if the failure is in the first\r
1834 name / value pair) if the request was not successful. \r
1835\r
1836 @param[out] Results A null-terminated Unicode string in\r
1837 <ConfigAltResp> format which has all values\r
1838 filled in for the names in the Request string.\r
1839 String to be allocated by the called function.\r
1840\r
1841 @retval EFI_SUCCESS The Results string is filled with the\r
1842 values corresponding to all requested\r
1843 names.\r
1844\r
1845 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the\r
1846 parts of the results that must be\r
1847 stored awaiting possible future\r
1848 protocols.\r
1849\r
1850 @retval EFI_INVALID_PARAMETER For example, passing in a NULL\r
1851 for the Request parameter\r
1852 would result in this type of\r
1853 error. In this case, the\r
1854 Progress parameter would be\r
1855 set to NULL. \r
1856\r
1857 @retval EFI_NOT_FOUND Routing data doesn't match any\r
1858 known driver. Progress set to the\r
1859 first character in the routing header.\r
1860 Note: There is no requirement that the\r
1861 driver validate the routing data. It\r
1862 must skip the <ConfigHdr> in order to\r
1863 process the names.\r
1864\r
1865 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set\r
1866 to most recent "&" before the\r
1867 error or the beginning of the\r
1868 string.\r
1869\r
1870 @retval EFI_INVALID_PARAMETER Unknown name. Progress points\r
1871 to the & before the name in\r
1872 question.\r
1873\r
1874**/\r
1875EFI_STATUS\r
1876EFIAPI\r
1877IScsiFormExtractConfig (\r
1878 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
1879 IN CONST EFI_STRING Request,\r
1880 OUT EFI_STRING *Progress,\r
1881 OUT EFI_STRING *Results\r
1882 )\r
1883{\r
1884 EFI_STATUS Status;\r
1885 CHAR8 *InitiatorName;\r
1886 UINTN BufferSize;\r
1887 ISCSI_CONFIG_IFR_NVDATA *IfrNvData;\r
1888 ISCSI_FORM_CALLBACK_INFO *Private;\r
1889 EFI_STRING ConfigRequestHdr;\r
1890 EFI_STRING ConfigRequest;\r
1891 BOOLEAN AllocatedRequest;\r
1892 UINTN Size;\r
1893\r
1894 if (This == NULL || Progress == NULL || Results == NULL) {\r
1895 return EFI_INVALID_PARAMETER;\r
1896 }\r
1897\r
1898 *Progress = Request;\r
9bdc6592 1899 if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gIScsiConfigGuid, mVendorStorageName)) {\r
4c5a5e0c 1900 return EFI_NOT_FOUND;\r
1901 }\r
1902\r
1903 ConfigRequestHdr = NULL;\r
1904 ConfigRequest = NULL;\r
1905 AllocatedRequest = FALSE;\r
1906 Size = 0;\r
1907\r
1908 Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);\r
1909 IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA));\r
1910 if (IfrNvData == NULL) {\r
1911 return EFI_OUT_OF_RESOURCES;\r
1912 }\r
1913 \r
1914 if (Private->Current != NULL) {\r
1915 IScsiConvertAttemptConfigDataToIfrNvData (Private->Current, IfrNvData);\r
1916 }\r
1917\r
1918 BufferSize = ISCSI_NAME_MAX_SIZE;\r
1919 InitiatorName = (CHAR8 *) AllocateZeroPool (BufferSize);\r
1920 if (InitiatorName == NULL) {\r
1921 FreePool (IfrNvData);\r
1922 return EFI_OUT_OF_RESOURCES;\r
1923 }\r
1924 \r
1925 Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize, InitiatorName);\r
1926 if (EFI_ERROR (Status)) {\r
1927 IfrNvData->InitiatorName[0] = L'\0';\r
1928 } else {\r
1929 AsciiStrToUnicodeStr (InitiatorName, IfrNvData->InitiatorName);\r
1930 }\r
1931\r
1932 //\r
1933 // Convert buffer data to <ConfigResp> by helper function BlockToConfig().\r
1934 //\r
1935 BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);\r
1936 ConfigRequest = Request;\r
1937 if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r
1938 //\r
1939 // Request has no request element, construct full request string.\r
1940 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
1941 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
1942 //\r
9bdc6592 1943 ConfigRequestHdr = HiiConstructConfigHdr (&gIScsiConfigGuid, mVendorStorageName, Private->DriverHandle);\r
4c5a5e0c 1944 Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
1945 ConfigRequest = AllocateZeroPool (Size);\r
1946 ASSERT (ConfigRequest != NULL);\r
1947 AllocatedRequest = TRUE;\r
1948 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
1949 FreePool (ConfigRequestHdr);\r
1950 }\r
1951\r
1952 Status = gHiiConfigRouting->BlockToConfig (\r
1953 gHiiConfigRouting,\r
1954 ConfigRequest,\r
1955 (UINT8 *) IfrNvData,\r
1956 BufferSize,\r
1957 Results,\r
1958 Progress\r
1959 );\r
1960 FreePool (IfrNvData);\r
1961 FreePool (InitiatorName);\r
1962\r
1963 //\r
1964 // Free the allocated config request string.\r
1965 //\r
1966 if (AllocatedRequest) {\r
1967 FreePool (ConfigRequest);\r
1968 ConfigRequest = NULL;\r
1969 }\r
1970 //\r
1971 // Set Progress string to the original request string.\r
1972 //\r
1973 if (Request == NULL) {\r
1974 *Progress = NULL;\r
1975 } else if (StrStr (Request, L"OFFSET") == NULL) {\r
1976 *Progress = Request + StrLen (Request);\r
1977 }\r
1978\r
1979 return Status;\r
1980}\r
1981\r
1982\r
1983/**\r
1984 \r
1985 This function applies changes in a driver's configuration.\r
1986 Input is a Configuration, which has the routing data for this\r
1987 driver followed by name / value configuration pairs. The driver\r
1988 must apply those pairs to its configurable storage. If the\r
1989 driver's configuration is stored in a linear block of data\r
1990 and the driver's name / value pairs are in <BlockConfig>\r
1991 format, it may use the ConfigToBlock helper function (above) to\r
1992 simplify the job.\r
1993\r
1994 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
1995\r
1996 @param[in] Configuration A null-terminated Unicode string in\r
1997 <ConfigString> format. \r
1998 \r
1999 @param[out] Progress A pointer to a string filled in with the\r
2000 offset of the most recent '&' before the\r
2001 first failing name / value pair (or the\r
2002 beginning of the string if the failure\r
2003 is in the first name / value pair) or\r
2004 the terminating NULL if all was\r
2005 successful.\r
2006\r
2007 @retval EFI_SUCCESS The results have been distributed or are\r
2008 awaiting distribution.\r
2009 \r
2010 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the\r
2011 parts of the results that must be\r
2012 stored awaiting possible future\r
2013 protocols.\r
2014 \r
2015 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the\r
2016 Results parameter would result\r
2017 in this type of error.\r
2018 \r
2019 @retval EFI_NOT_FOUND Target for the specified routing data\r
2020 was not found.\r
2021\r
2022**/\r
2023EFI_STATUS\r
2024EFIAPI\r
2025IScsiFormRouteConfig (\r
2026 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
2027 IN CONST EFI_STRING Configuration,\r
2028 OUT EFI_STRING *Progress\r
2029 )\r
2030{\r
2031 if (This == NULL || Configuration == NULL || Progress == NULL) {\r
2032 return EFI_INVALID_PARAMETER;\r
2033 }\r
2034\r
2035 //\r
2036 // Check routing data in <ConfigHdr>.\r
2037 // Note: if only one Storage is used, then this checking could be skipped.\r
2038 //\r
9bdc6592 2039 if (!HiiIsConfigHdrMatch (Configuration, &gIScsiConfigGuid, mVendorStorageName)) {\r
4c5a5e0c 2040 *Progress = Configuration;\r
2041 return EFI_NOT_FOUND;\r
2042 }\r
2043\r
2044 *Progress = Configuration + StrLen (Configuration);\r
2045 return EFI_SUCCESS;\r
2046}\r
2047\r
2048\r
2049/**\r
2050 \r
2051 This function is called to provide results data to the driver.\r
2052 This data consists of a unique key that is used to identify\r
2053 which data is either being passed back or being asked for.\r
2054\r
2055 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
2056 @param[in] Action Specifies the type of action taken by the browser.\r
2057 @param[in] QuestionId A unique value which is sent to the original\r
2058 exporting driver so that it can identify the type\r
2059 of data to expect. The format of the data tends to \r
2060 vary based on the opcode that generated the callback.\r
2061 @param[in] Type The type of value for the question.\r
2062 @param[in, out] Value A pointer to the data being sent to the original\r
2063 exporting driver.\r
2064 @param[out] ActionRequest On return, points to the action requested by the\r
2065 callback function.\r
2066\r
2067 @retval EFI_SUCCESS The callback successfully handled the action.\r
2068 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
2069 variable and its data.\r
2070 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
2071 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
2072 callback.\r
2073**/\r
2074EFI_STATUS\r
2075EFIAPI\r
2076IScsiFormCallback (\r
2077 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
2078 IN EFI_BROWSER_ACTION Action,\r
2079 IN EFI_QUESTION_ID QuestionId,\r
2080 IN UINT8 Type,\r
2081 IN OUT EFI_IFR_TYPE_VALUE *Value,\r
2082 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
2083 )\r
2084{\r
2085 ISCSI_FORM_CALLBACK_INFO *Private;\r
2086 UINTN BufferSize;\r
2087 CHAR8 *IScsiName;\r
2088 CHAR8 IpString[IP_STR_MAX_SIZE];\r
2089 CHAR8 LunString[ISCSI_LUN_STR_MAX_LEN];\r
2090 UINT64 Lun;\r
2091 EFI_IP_ADDRESS HostIp;\r
2092 EFI_IP_ADDRESS SubnetMask;\r
2093 EFI_IP_ADDRESS Gateway;\r
2094 ISCSI_CONFIG_IFR_NVDATA *IfrNvData;\r
2095 ISCSI_CONFIG_IFR_NVDATA OldIfrNvData;\r
2096 EFI_STATUS Status;\r
2097 CHAR16 AttemptName[ATTEMPT_NAME_SIZE + 4];\r
2098 EFI_INPUT_KEY Key;\r
2099\r
2100 if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {\r
2101 //\r
2102 // Do nothing for UEFI OPEN/CLOSE Action\r
2103 //\r
2104 return EFI_SUCCESS;\r
2105 }\r
2106\r
639a76d1 2107 if ((Action != EFI_BROWSER_ACTION_CHANGING) && (Action != EFI_BROWSER_ACTION_CHANGED)) {\r
4c5a5e0c 2108 //\r
639a76d1 2109 // All other type return unsupported.\r
4c5a5e0c 2110 //\r
639a76d1
ED
2111 return EFI_UNSUPPORTED;\r
2112 }\r
4c5a5e0c 2113\r
639a76d1
ED
2114 if ((Value == NULL) || (ActionRequest == NULL)) {\r
2115 return EFI_INVALID_PARAMETER;\r
2116 }\r
4c5a5e0c 2117\r
639a76d1
ED
2118 Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);\r
2119 \r
2120 //\r
2121 // Retrieve uncommitted data from Browser\r
2122 //\r
2123 \r
2124 BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);\r
2125 IfrNvData = AllocateZeroPool (BufferSize);\r
2126 if (IfrNvData == NULL) {\r
2127 return EFI_OUT_OF_RESOURCES;\r
2128 }\r
2129 \r
2130 IScsiName = (CHAR8 *) AllocateZeroPool (ISCSI_NAME_MAX_SIZE);\r
2131 if (IScsiName == NULL) {\r
2132 FreePool (IfrNvData);\r
2133 return EFI_OUT_OF_RESOURCES;\r
2134 }\r
2135 \r
2136 Status = EFI_SUCCESS;\r
2137 \r
2138 ZeroMem (&OldIfrNvData, BufferSize);\r
2139 \r
2140 HiiGetBrowserData (NULL, NULL, BufferSize, (UINT8 *) IfrNvData);\r
2141 \r
2142 CopyMem (&OldIfrNvData, IfrNvData, BufferSize);\r
4c5a5e0c 2143\r
639a76d1
ED
2144 if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
2145 switch (QuestionId) {\r
2146 case KEY_ADD_ATTEMPT:\r
2147 Status = IScsiConfigAddAttempt ();\r
2148 break;\r
4c5a5e0c 2149\r
639a76d1
ED
2150 case KEY_DELETE_ATTEMPT:\r
2151 CopyMem (\r
2152 OldIfrNvData.DeleteAttemptList,\r
2153 IfrNvData->DeleteAttemptList,\r
2154 sizeof (IfrNvData->DeleteAttemptList)\r
2155 );\r
2156 Status = IScsiConfigDisplayDeleteAttempts (IfrNvData);\r
2157 break;\r
4c5a5e0c 2158\r
639a76d1
ED
2159 case KEY_ORDER_ATTEMPT_CONFIG:\r
2160 //\r
2161 // Order the attempt according to user input.\r
2162 //\r
2163 CopyMem (\r
2164 OldIfrNvData.DynamicOrderedList,\r
2165 IfrNvData->DynamicOrderedList,\r
2166 sizeof (IfrNvData->DynamicOrderedList)\r
2167 );\r
2168 IScsiConfigDisplayOrderAttempts ();\r
2169 break;\r
2170 \r
2171 default:\r
2172 Status = IScsiConfigProcessDefault (QuestionId, IfrNvData);\r
2173 break;\r
2174 }\r
2175 } else if (Action == EFI_BROWSER_ACTION_CHANGED) { \r
4c5a5e0c 2176 switch (QuestionId) {\r
2177 case KEY_INITIATOR_NAME:\r
2178 UnicodeStrToAsciiStr (IfrNvData->InitiatorName, IScsiName);\r
2179 BufferSize = AsciiStrSize (IScsiName);\r
2180\r
2181 Status = gIScsiInitiatorName.Set (&gIScsiInitiatorName, &BufferSize, IScsiName);\r
2182 if (EFI_ERROR (Status)) {\r
2183 CreatePopUp (\r
2184 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2185 &Key,\r
2186 L"Invalid iSCSI Name!",\r
2187 NULL\r
2188 ); \r
2189 }\r
2190\r
f10810ca 2191 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
4c5a5e0c 2192 break;\r
639a76d1
ED
2193 case KEY_ATTEMPT_NAME:\r
2194 if (StrLen (IfrNvData->AttemptName) > ATTEMPT_NAME_SIZE) {\r
2195 CopyMem (AttemptName, IfrNvData->AttemptName, ATTEMPT_NAME_SIZE * sizeof (CHAR16));\r
2196 CopyMem (&AttemptName[ATTEMPT_NAME_SIZE], L"...", 4 * sizeof (CHAR16));\r
2197 } else {\r
2198 CopyMem (\r
2199 AttemptName,\r
2200 IfrNvData->AttemptName,\r
2201 (StrLen (IfrNvData->AttemptName) + 1) * sizeof (CHAR16)\r
2202 );\r
2203 }\r
4c5a5e0c 2204\r
639a76d1 2205 UnicodeStrToAsciiStr (IfrNvData->AttemptName, Private->Current->AttemptName);\r
4c5a5e0c 2206\r
639a76d1 2207 IScsiConfigUpdateAttempt ();\r
4c5a5e0c 2208\r
639a76d1
ED
2209 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
2210 break;\r
2211 \r
2212 case KEY_SAVE_ATTEMPT_CONFIG:\r
2213 Status = IScsiConvertIfrNvDataToAttemptConfigData (IfrNvData, Private->Current);\r
4c5a5e0c 2214 if (EFI_ERROR (Status)) {\r
2215 break;\r
2216 }\r
2217\r
f10810ca 2218 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
4c5a5e0c 2219 break;\r
2220\r
4c5a5e0c 2221 case KEY_SAVE_ORDER_CHANGES:\r
2222 //\r
2223 // Sync the Attempt Order to NVR.\r
2224 //\r
2225 Status = IScsiConfigOrderAttempts (IfrNvData);\r
2226 if (EFI_ERROR (Status)) {\r
2227 break;\r
2228 }\r
2229\r
2230 IScsiConfigUpdateAttempt ();\r
639a76d1 2231 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r
4c5a5e0c 2232 break;\r
2233\r
2234 case KEY_IGNORE_ORDER_CHANGES:\r
2235 CopyMem (\r
2236 IfrNvData->DynamicOrderedList,\r
2237 OldIfrNvData.DynamicOrderedList,\r
2238 sizeof (IfrNvData->DynamicOrderedList)\r
2239 );\r
639a76d1 2240 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r
4c5a5e0c 2241 break;\r
2242\r
639a76d1
ED
2243 case KEY_SAVE_DELETE_ATTEMPT:\r
2244 //\r
2245 // Delete the Attempt Order from NVR\r
2246 //\r
2247 Status = IScsiConfigDeleteAttempts (IfrNvData);\r
2248 if (EFI_ERROR (Status)) {\r
2249 break;\r
4c5a5e0c 2250 }\r
2251\r
4c5a5e0c 2252 IScsiConfigUpdateAttempt ();\r
639a76d1
ED
2253 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r
2254 break;\r
4c5a5e0c 2255\r
639a76d1
ED
2256 case KEY_IGNORE_DELETE_ATTEMPT:\r
2257 CopyMem (\r
2258 IfrNvData->DeleteAttemptList,\r
2259 OldIfrNvData.DeleteAttemptList,\r
2260 sizeof (IfrNvData->DeleteAttemptList)\r
2261 );\r
2262 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r
4c5a5e0c 2263 break;\r
2264\r
2265 case KEY_IP_MODE:\r
2266 switch (Value->u8) {\r
2267 case IP_MODE_IP6:\r
2268 ZeroMem (IfrNvData->TargetIp, sizeof (IfrNvData->TargetIp));\r
2269 IScsiIpToStr (&Private->Current->SessionConfigData.TargetIp, TRUE, IfrNvData->TargetIp);\r
2270 Private->Current->AutoConfigureMode = 0;\r
2271 break;\r
2272\r
2273 case IP_MODE_IP4:\r
2274 ZeroMem (IfrNvData->TargetIp, sizeof (IfrNvData->TargetIp));\r
2275 IScsiIpToStr (&Private->Current->SessionConfigData.TargetIp, FALSE, IfrNvData->TargetIp);\r
2276 Private->Current->AutoConfigureMode = 0;\r
2277\r
2278 break;\r
2279 }\r
2280\r
2281 break;\r
2282\r
2283 case KEY_LOCAL_IP:\r
2284 Status = NetLibStrToIp4 (IfrNvData->LocalIp, &HostIp.v4);\r
2285 if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
2286 CreatePopUp (\r
2287 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2288 &Key,\r
2289 L"Invalid IP address!",\r
2290 NULL\r
2291 ); \r
2292 \r
2293 Status = EFI_INVALID_PARAMETER;\r
2294 } else {\r
2295 CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4));\r
2296 }\r
2297\r
2298 break;\r
2299\r
2300 case KEY_SUBNET_MASK:\r
2301 Status = NetLibStrToIp4 (IfrNvData->SubnetMask, &SubnetMask.v4);\r
2302 if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {\r
2303 CreatePopUp (\r
2304 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2305 &Key,\r
2306 L"Invalid Subnet Mask!",\r
2307 NULL\r
2308 ); \r
2309 \r
2310 Status = EFI_INVALID_PARAMETER;\r
2311 } else {\r
2312 CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));\r
2313 }\r
2314\r
2315 break;\r
2316\r
2317 case KEY_GATE_WAY:\r
2318 Status = NetLibStrToIp4 (IfrNvData->Gateway, &Gateway.v4);\r
2319 if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
2320 CreatePopUp (\r
2321 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2322 &Key,\r
2323 L"Invalid Gateway!",\r
2324 NULL\r
2325 ); \r
2326 Status = EFI_INVALID_PARAMETER;\r
2327 } else {\r
2328 CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4));\r
2329 }\r
2330\r
2331 break;\r
2332\r
2333 case KEY_TARGET_IP:\r
2334 UnicodeStrToAsciiStr (IfrNvData->TargetIp, IpString);\r
2335 Status = IScsiAsciiStrToIp (IpString, IfrNvData->IpMode, &HostIp);\r
2336 if (EFI_ERROR (Status) || !IpIsUnicast (&HostIp, IfrNvData->IpMode)) {\r
2337 CreatePopUp (\r
2338 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2339 &Key,\r
2340 L"Invalid IP address!",\r
2341 NULL\r
2342 ); \r
2343 Status = EFI_INVALID_PARAMETER;\r
2344 } else {\r
2345 CopyMem (&Private->Current->SessionConfigData.TargetIp, &HostIp, sizeof (HostIp));\r
2346 }\r
2347\r
2348 break;\r
2349\r
2350 case KEY_TARGET_NAME:\r
2351 UnicodeStrToAsciiStr (IfrNvData->TargetName, IScsiName);\r
2352 Status = IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName));\r
2353 if (EFI_ERROR (Status)) {\r
2354 CreatePopUp (\r
2355 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2356 &Key,\r
2357 L"Invalid iSCSI Name!",\r
2358 NULL\r
2359 ); \r
2360 } else {\r
2361 AsciiStrCpy (Private->Current->SessionConfigData.TargetName, IScsiName);\r
2362 }\r
2363\r
2364 break;\r
2365\r
2366 case KEY_DHCP_ENABLE:\r
2367 if (IfrNvData->InitiatorInfoFromDhcp == 0) {\r
2368 IfrNvData->TargetInfoFromDhcp = 0;\r
2369 }\r
2370\r
2371 break;\r
2372\r
2373 case KEY_BOOT_LUN:\r
2374 UnicodeStrToAsciiStr (IfrNvData->BootLun, LunString);\r
2375 Status = IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun);\r
2376 if (EFI_ERROR (Status)) {\r
2377 CreatePopUp (\r
2378 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2379 &Key,\r
2380 L"Invalid LUN string!",\r
2381 NULL\r
2382 ); \r
2383 } else {\r
2384 CopyMem (Private->Current->SessionConfigData.BootLun, &Lun, sizeof (Lun));\r
2385 }\r
2386\r
2387 break;\r
2388\r
2389 case KEY_AUTH_TYPE:\r
2390 switch (Value->u8) {\r
2391 case ISCSI_AUTH_TYPE_CHAP:\r
2392 IfrNvData->CHAPType = ISCSI_CHAP_UNI;\r
2393 break;\r
2394 default:\r
2395 break;\r
2396 }\r
2397\r
2398 break;\r
2399\r
2400 case KEY_CHAP_NAME:\r
2401 UnicodeStrToAsciiStr (\r
2402 IfrNvData->CHAPName,\r
2403 Private->Current->AuthConfigData.CHAP.CHAPName\r
2404 );\r
2405 break;\r
2406\r
2407 case KEY_CHAP_SECRET:\r
2408 UnicodeStrToAsciiStr (\r
2409 IfrNvData->CHAPSecret,\r
2410 Private->Current->AuthConfigData.CHAP.CHAPSecret\r
2411 );\r
2412 break;\r
2413\r
2414 case KEY_REVERSE_CHAP_NAME:\r
2415 UnicodeStrToAsciiStr (\r
2416 IfrNvData->ReverseCHAPName,\r
2417 Private->Current->AuthConfigData.CHAP.ReverseCHAPName\r
2418 );\r
2419 break;\r
2420\r
2421 case KEY_REVERSE_CHAP_SECRET:\r
2422 UnicodeStrToAsciiStr (\r
2423 IfrNvData->ReverseCHAPSecret,\r
2424 Private->Current->AuthConfigData.CHAP.ReverseCHAPSecret\r
2425 );\r
2426 break;\r
2427\r
2428 case KEY_CONFIG_ISID:\r
2429 IScsiParseIsIdFromString (IfrNvData->IsId, Private->Current->SessionConfigData.IsId);\r
2430 IScsiConvertIsIdToString (IfrNvData->IsId, Private->Current->SessionConfigData.IsId);\r
2431\r
2432 break;\r
2433\r
4c5a5e0c 2434 default:\r
4c5a5e0c 2435 break;\r
2436 }\r
639a76d1 2437 }\r
4c5a5e0c 2438\r
639a76d1
ED
2439 if (!EFI_ERROR (Status)) {\r
2440 //\r
2441 // Pass changed uncommitted data back to Form Browser.\r
2442 //\r
2443 BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);\r
2444 HiiSetBrowserData (NULL, NULL, BufferSize, (UINT8 *) IfrNvData, NULL);\r
4c5a5e0c 2445 }\r
2446\r
639a76d1
ED
2447 FreePool (IfrNvData);\r
2448 FreePool (IScsiName);\r
2449\r
2450 return Status;\r
4c5a5e0c 2451}\r
2452\r
2453\r
2454/**\r
2455 Initialize the iSCSI configuration form.\r
2456\r
2457 @param[in] DriverBindingHandle The iSCSI driverbinding handle.\r
2458\r
2459 @retval EFI_SUCCESS The iSCSI configuration form is initialized.\r
2460 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
2461\r
2462**/\r
2463EFI_STATUS\r
2464IScsiConfigFormInit (\r
2465 IN EFI_HANDLE DriverBindingHandle\r
2466 )\r
2467{\r
2468 EFI_STATUS Status;\r
2469 ISCSI_FORM_CALLBACK_INFO *CallbackInfo;\r
2470\r
2471 CallbackInfo = (ISCSI_FORM_CALLBACK_INFO *) AllocateZeroPool (sizeof (ISCSI_FORM_CALLBACK_INFO));\r
2472 if (CallbackInfo == NULL) {\r
2473 return EFI_OUT_OF_RESOURCES;\r
2474 }\r
2475\r
2476 CallbackInfo->Signature = ISCSI_FORM_CALLBACK_INFO_SIGNATURE;\r
2477 CallbackInfo->Current = NULL;\r
2478\r
2479 CallbackInfo->ConfigAccess.ExtractConfig = IScsiFormExtractConfig;\r
2480 CallbackInfo->ConfigAccess.RouteConfig = IScsiFormRouteConfig;\r
2481 CallbackInfo->ConfigAccess.Callback = IScsiFormCallback;\r
2482\r
2483 //\r
2484 // Install Device Path Protocol and Config Access protocol to driver handle.\r
2485 //\r
2486 Status = gBS->InstallMultipleProtocolInterfaces (\r
2487 &CallbackInfo->DriverHandle,\r
2488 &gEfiDevicePathProtocolGuid,\r
2489 &mIScsiHiiVendorDevicePath,\r
2490 &gEfiHiiConfigAccessProtocolGuid,\r
2491 &CallbackInfo->ConfigAccess,\r
2492 NULL\r
2493 );\r
2494 ASSERT_EFI_ERROR (Status);\r
2495 \r
2496 //\r
2497 // Publish our HII data.\r
2498 //\r
2499 CallbackInfo->RegisteredHandle = HiiAddPackages (\r
9bdc6592 2500 &gIScsiConfigGuid,\r
4c5a5e0c 2501 CallbackInfo->DriverHandle,\r
2502 IScsiDxeStrings,\r
2503 IScsiConfigVfrBin,\r
2504 NULL\r
2505 );\r
2506 if (CallbackInfo->RegisteredHandle == NULL) {\r
2507 gBS->UninstallMultipleProtocolInterfaces (\r
2508 &CallbackInfo->DriverHandle,\r
2509 &gEfiDevicePathProtocolGuid,\r
2510 &mIScsiHiiVendorDevicePath,\r
2511 &gEfiHiiConfigAccessProtocolGuid,\r
2512 &CallbackInfo->ConfigAccess,\r
2513 NULL\r
2514 );\r
2515 FreePool(CallbackInfo);\r
2516 return EFI_OUT_OF_RESOURCES;\r
2517 }\r
2518\r
2519 mCallbackInfo = CallbackInfo;\r
2520\r
2521 return EFI_SUCCESS;\r
2522}\r
2523\r
2524\r
2525/**\r
2526 Unload the iSCSI configuration form, this includes: delete all the iSCSI\r
2527 configuration entries, uninstall the form callback protocol, and\r
2528 free the resources used.\r
2529\r
2530 @param[in] DriverBindingHandle The iSCSI driverbinding handle.\r
2531\r
2532 @retval EFI_SUCCESS The iSCSI configuration form is unloaded.\r
2533 @retval Others Failed to unload the form.\r
2534\r
2535**/\r
2536EFI_STATUS\r
2537IScsiConfigFormUnload (\r
2538 IN EFI_HANDLE DriverBindingHandle\r
2539 )\r
2540{\r
2541 ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;\r
2542 ISCSI_NIC_INFO *NicInfo;\r
2543 LIST_ENTRY *Entry;\r
2544 EFI_STATUS Status;\r
2545\r
2546 while (!IsListEmpty (&mPrivate->AttemptConfigs)) {\r
2547 Entry = NetListRemoveHead (&mPrivate->AttemptConfigs);\r
2548 AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);\r
2549 FreePool (AttemptConfigData);\r
2550 mPrivate->AttemptCount--;\r
2551 }\r
2552\r
2553 ASSERT (mPrivate->AttemptCount == 0);\r
2554\r
2555 while (!IsListEmpty (&mPrivate->NicInfoList)) {\r
2556 Entry = NetListRemoveHead (&mPrivate->NicInfoList);\r
2557 NicInfo = NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link);\r
2558 FreePool (NicInfo);\r
2559 mPrivate->NicCount--;\r
2560 }\r
2561\r
2562 ASSERT (mPrivate->NicCount == 0);\r
2563\r
c0d494b5 2564 //\r
2565 // Free attempt is created but not saved to system.\r
2566 //\r
2567 if (mPrivate->NewAttempt != NULL) {\r
2568 FreePool (mPrivate->NewAttempt);\r
2569 }\r
2570\r
4c5a5e0c 2571 FreePool (mPrivate);\r
2572 mPrivate = NULL;\r
2573\r
2574 //\r
2575 // Remove HII package list.\r
2576 //\r
2577 HiiRemovePackages (mCallbackInfo->RegisteredHandle);\r
2578\r
2579 //\r
2580 // Uninstall Device Path Protocol and Config Access protocol.\r
2581 //\r
2582 Status = gBS->UninstallMultipleProtocolInterfaces (\r
2583 mCallbackInfo->DriverHandle,\r
2584 &gEfiDevicePathProtocolGuid,\r
2585 &mIScsiHiiVendorDevicePath,\r
2586 &gEfiHiiConfigAccessProtocolGuid,\r
2587 &mCallbackInfo->ConfigAccess,\r
2588 NULL\r
2589 );\r
2590\r
2591 FreePool (mCallbackInfo);\r
2592\r
2593 return Status;\r
2594}\r