2 Helper functions for configuring or getting the parameters relating to iSCSI.
4 Copyright (c) 2004 - 2008, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "IScsiImpl.h"
17 EFI_GUID mVendorGuid
= ISCSI_CONFIG_GUID
;
18 BOOLEAN mIScsiDeviceListUpdated
= FALSE
;
19 UINTN mNumberOfIScsiDevices
= 0;
20 ISCSI_FORM_CALLBACK_INFO
*mCallbackInfo
= NULL
;
22 LIST_ENTRY mIScsiConfigFormList
= {
23 &mIScsiConfigFormList
,
28 Convert the IPv4 address into a dotted string.
30 @param[in] Ip The IPv4 address.
31 @param[out] Str The dotted IP string.
35 IN EFI_IPv4_ADDRESS
*Ip
,
39 UnicodeSPrint ( Str
, 2 * IP4_STR_MAX_SIZE
, L
"%d.%d.%d.%d", Ip
->Addr
[0], Ip
->Addr
[1], Ip
->Addr
[2], Ip
->Addr
[3]);
43 Pop up an invalid notify which displays the message in Warning.
45 @param[in] Warning The warning message.
54 IfrLibCreatePopUp (1, &Key
, Warning
);
58 Update the list of iSCSI devices the iSCSI driver is controlling.
60 @retval EFI_SUCCESS The callback successfully handled the action.
61 @retval Others Other errors as indicated.
64 IScsiUpdateDeviceList (
69 ISCSI_DEVICE_LIST
*DeviceList
;
75 UINTN LastDeviceIndex
;
76 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
77 EFI_SIMPLE_NETWORK_MODE
*Mode
;
78 ISCSI_MAC_INFO
*CurMacInfo
;
79 ISCSI_MAC_INFO TempMacInfo
;
84 // Dump all the handles the Simple Network Protocol is installed on.
86 Status
= gBS
->LocateHandleBuffer (
88 &gEfiSimpleNetworkProtocolGuid
,
93 if (EFI_ERROR (Status
)) {
98 Status
= gRT
->GetVariable (
105 if (Status
== EFI_BUFFER_TOO_SMALL
) {
106 DeviceList
= (ISCSI_DEVICE_LIST
*) AllocatePool (DataSize
);
118 for (HandleIndex
= 0; HandleIndex
< NumHandles
; HandleIndex
++) {
119 gBS
->HandleProtocol (Handles
[HandleIndex
], &gEfiSimpleNetworkProtocolGuid
, (VOID
**)&Snp
);
123 for (Index
= LastDeviceIndex
; Index
< DeviceList
->NumDevice
; Index
++) {
124 CurMacInfo
= &DeviceList
->MacInfo
[Index
];
125 if ((CurMacInfo
->Len
== Mode
->HwAddressSize
) &&
126 (NET_MAC_EQUAL (&CurMacInfo
->Mac
, &Mode
->PermanentAddress
, Mode
->HwAddressSize
))
129 // The previous configured NIC is still here.
131 if (Index
!= LastDeviceIndex
) {
133 // Swap the current MAC address entry with the one indexed by
136 CopyMem (&TempMacInfo
, CurMacInfo
, sizeof (ISCSI_MAC_INFO
));
137 CopyMem (CurMacInfo
, &DeviceList
->MacInfo
[LastDeviceIndex
], sizeof (ISCSI_MAC_INFO
));
138 CopyMem (&DeviceList
->MacInfo
[LastDeviceIndex
], &TempMacInfo
, sizeof (ISCSI_MAC_INFO
));
145 if (LastDeviceIndex
== DeviceList
->NumDevice
) {
150 for (Index
= LastDeviceIndex
; Index
< DeviceList
->NumDevice
; Index
++) {
152 // delete the variables
154 CurMacInfo
= &DeviceList
->MacInfo
[Index
];
155 IScsiMacAddrToStr (&CurMacInfo
->Mac
, CurMacInfo
->Len
, MacString
);
156 gRT
->SetVariable (MacString
, &gEfiIScsiInitiatorNameProtocolGuid
, 0, 0, NULL
);
157 gRT
->SetVariable (MacString
, &mIScsiCHAPAuthInfoGuid
, 0, 0, NULL
);
160 gBS
->FreePool (DeviceList
);
161 } else if (Status
!= EFI_NOT_FOUND
) {
162 gBS
->FreePool (Handles
);
166 // Construct the new iSCSI device list.
168 DeviceListSize
= sizeof (ISCSI_DEVICE_LIST
) + (NumHandles
- 1) * sizeof (ISCSI_MAC_INFO
);
169 DeviceList
= (ISCSI_DEVICE_LIST
*) AllocatePool (DeviceListSize
);
170 DeviceList
->NumDevice
= (UINT8
) NumHandles
;
172 for (Index
= 0; Index
< NumHandles
; Index
++) {
173 gBS
->HandleProtocol (Handles
[Index
], &gEfiSimpleNetworkProtocolGuid
, (VOID
**)&Snp
);
176 CurMacInfo
= &DeviceList
->MacInfo
[Index
];
177 CopyMem (&CurMacInfo
->Mac
, &Mode
->PermanentAddress
, Mode
->HwAddressSize
);
178 CurMacInfo
->Len
= (UINT8
) Mode
->HwAddressSize
;
184 ISCSI_CONFIG_VAR_ATTR
,
189 gBS
->FreePool (DeviceList
);
190 gBS
->FreePool (Handles
);
196 Get the iSCSI configuration form entry by the index of the goto opcode actived.
198 @param[in] Index The 0-based index of the goto opcode actived.
200 @return The iSCSI configuration form entry found.
202 ISCSI_CONFIG_FORM_ENTRY
*
203 IScsiGetConfigFormEntryByIndex (
209 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
212 ConfigFormEntry
= NULL
;
214 NET_LIST_FOR_EACH (Entry
, &mIScsiConfigFormList
) {
215 if (CurrentIndex
== Index
) {
216 ConfigFormEntry
= NET_LIST_USER_STRUCT (Entry
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
223 return ConfigFormEntry
;
227 Convert the iSCSI configuration data into the IFR data.
229 @param[in] ConfigFormEntry The iSCSI configuration form entry.
230 @param[out] IfrNvData The IFR nv data.
233 IScsiConvertDeviceConfigDataToIfrNvData (
234 IN ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
,
235 OUT ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
238 ISCSI_SESSION_CONFIG_NVDATA
*SessionConfigData
;
239 ISCSI_CHAP_AUTH_CONFIG_NVDATA
*AuthConfigData
;
242 // Normal session configuration parameters.
244 SessionConfigData
= &ConfigFormEntry
->SessionConfigData
;
245 IfrNvData
->Enabled
= SessionConfigData
->Enabled
;
247 IfrNvData
->InitiatorInfoFromDhcp
= SessionConfigData
->InitiatorInfoFromDhcp
;
248 IfrNvData
->TargetInfoFromDhcp
= SessionConfigData
->TargetInfoFromDhcp
;
249 IfrNvData
->TargetPort
= SessionConfigData
->TargetPort
;
251 IScsiIpToStr (&SessionConfigData
->LocalIp
, IfrNvData
->LocalIp
);
252 IScsiIpToStr (&SessionConfigData
->SubnetMask
, IfrNvData
->SubnetMask
);
253 IScsiIpToStr (&SessionConfigData
->Gateway
, IfrNvData
->Gateway
);
254 IScsiIpToStr (&SessionConfigData
->TargetIp
, IfrNvData
->TargetIp
);
256 IScsiAsciiStrToUnicodeStr (SessionConfigData
->TargetName
, IfrNvData
->TargetName
);
258 IScsiLunToUnicodeStr (SessionConfigData
->BootLun
, IfrNvData
->BootLun
);
261 // CHAP authentication parameters.
263 AuthConfigData
= &ConfigFormEntry
->AuthConfigData
;
265 IfrNvData
->CHAPType
= AuthConfigData
->CHAPType
;
267 IScsiAsciiStrToUnicodeStr (AuthConfigData
->CHAPName
, IfrNvData
->CHAPName
);
268 IScsiAsciiStrToUnicodeStr (AuthConfigData
->CHAPSecret
, IfrNvData
->CHAPSecret
);
269 IScsiAsciiStrToUnicodeStr (AuthConfigData
->ReverseCHAPName
, IfrNvData
->ReverseCHAPName
);
270 IScsiAsciiStrToUnicodeStr (AuthConfigData
->ReverseCHAPSecret
, IfrNvData
->ReverseCHAPSecret
);
274 This function allows the caller to request the current
275 configuration for one or more named elements. The resulting
276 string is in <ConfigAltResp> format. Any and all alternative
277 configuration strings shall also be appended to the end of the
278 current configuration string. If they are, they must appear
279 after the current configuration. They must contain the same
280 routing (GUID, NAME, PATH) as the current configuration string.
281 They must have an additional description indicating the type of
282 alternative configuration the string represents,
283 "ALTCFG=<StringToken>". That <StringToken> (when
284 converted from Hex UNICODE to binary) is a reference to a
285 string in the associated string pack.
287 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
288 @param[in] Request A null-terminated Unicode string in
289 <ConfigRequest> format. Note that this
290 includes the routing information as well as
291 the configurable name / value pairs. It is
292 invalid for this string to be in
293 <MultiConfigRequest> format.
294 @param[out] Progress On return, points to a character in the
295 Request string. Points to the string's null
296 terminator if request was successful. Points
297 to the most recent "&" before the first
298 failing name / value pair (or the beginning
299 of the string if the failure is in the first
300 name / value pair) if the request was not
302 @param[out] Results A null-terminated Unicode string in
303 <ConfigAltResp> format which has all values
304 filled in for the names in the Request string.
305 String to be allocated by the called function.
307 @retval EFI_SUCCESS The Results string is filled with the
308 values corresponding to all requested
310 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
311 parts of the results that must be
312 stored awaiting possible future
314 @retval EFI_INVALID_PARAMETER For example, passing in a NULL
315 for the Request parameter
316 would result in this type of
317 error. In this case, the
318 Progress parameter would be
320 @retval EFI_NOT_FOUND Routing data doesn't match any
321 known driver. Progress set to the
322 first character in the routing header.
323 Note: There is no requirement that the
324 driver validate the routing data. It
325 must skip the <ConfigHdr> in order to
327 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
328 to most recent & before the
329 error or the beginning of the
331 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
332 to the & before the name in
333 question.Currently not implemented.
337 IScsiFormExtractConfig (
338 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
339 IN CONST EFI_STRING Request
,
340 OUT EFI_STRING
*Progress
,
341 OUT EFI_STRING
*Results
345 CHAR8 InitiatorName
[ISCSI_NAME_IFR_MAX_SIZE
];
347 ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
;
348 ISCSI_FORM_CALLBACK_INFO
*Private
;
349 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
351 if (Request
== NULL
) {
352 return EFI_INVALID_PARAMETER
;
355 if (!mIScsiDeviceListUpdated
) {
357 // Update the device list.
359 IScsiUpdateDeviceList ();
360 mIScsiDeviceListUpdated
= TRUE
;
363 Private
= ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This
);
364 IfrNvData
= AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA
));
365 ASSERT (IfrNvData
!= NULL
);
366 if (Private
->Current
!= NULL
) {
367 IScsiConvertDeviceConfigDataToIfrNvData (Private
->Current
, IfrNvData
);
370 BufferSize
= ISCSI_NAME_IFR_MAX_SIZE
;
371 Status
= gIScsiInitiatorName
.Get (&gIScsiInitiatorName
, &BufferSize
, InitiatorName
);
372 if (EFI_ERROR (Status
)) {
373 IfrNvData
->InitiatorName
[0] = L
'\0';
375 IScsiAsciiStrToUnicodeStr (InitiatorName
, IfrNvData
->InitiatorName
);
379 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
381 HiiConfigRouting
= Private
->ConfigRouting
;
382 BufferSize
= sizeof (ISCSI_CONFIG_IFR_NVDATA
);
383 Status
= HiiConfigRouting
->BlockToConfig (
391 gBS
->FreePool (IfrNvData
);
396 This function applies changes in a driver's configuration.
397 Input is a Configuration, which has the routing data for this
398 driver followed by name / value configuration pairs. The driver
399 must apply those pairs to its configurable storage. If the
400 driver's configuration is stored in a linear block of data
401 and the driver's name / value pairs are in <BlockConfig>
402 format, it may use the ConfigToBlock helper function (above) to
403 simplify the job. Currently not implemented.
405 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
406 @param[in] Configuration A null-terminated Unicode string in
407 <ConfigString> format.
408 @param[out] Progress A pointer to a string filled in with the
409 offset of the most recent '&' before the
410 first failing name / value pair (or the
411 beginn ing of the string if the failure
412 is in the first name / value pair) or
413 the terminating NULL if all was
416 @retval EFI_SUCCESS The results have been distributed or are
417 awaiting distribution.
418 @retval EFI_OUT_OF_MEMORY Not enough memory to store the
419 parts of the results that must be
420 stored awaiting possible future
422 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
423 Results parameter would result
424 in this type of error.
425 @retval EFI_NOT_FOUND Target for the specified routing data
430 IScsiFormRouteConfig (
431 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
432 IN CONST EFI_STRING Configuration
,
433 OUT EFI_STRING
*Progress
440 This function is called to provide results data to the driver.
441 This data consists of a unique key that is used to identify
442 which data is either being passed back or being asked for.
444 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
445 @param[in] Action Specifies the type of action taken by the browser.
446 @param[in] QuestionId A unique value which is sent to the original
447 exporting driver so that it can identify the type
448 of data to expect. The format of the data tends to
449 vary based on the opcode that enerated the callback.
450 @param[in] Type The type of value for the question.
451 @param[in] Value A pointer to the data being sent to the original
453 @param[out] ActionRequest On return, points to the action requested by the
456 @retval EFI_SUCCESS The callback successfully handled the action.
457 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
458 variable and its data.
459 @retval EFI_DEVICE_ERROR The variable could not be saved.
460 @retval EFI_UNSUPPORTED The specified Action is not supported by the
461 callback.Currently not implemented.
462 @retval EFI_INVALID_PARAMETERS Passing in wrong parameter.
463 @retval Others Other errors as indicated.
468 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
469 IN EFI_BROWSER_ACTION Action
,
470 IN EFI_QUESTION_ID QuestionId
,
472 IN EFI_IFR_TYPE_VALUE
*Value
,
473 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
476 ISCSI_FORM_CALLBACK_INFO
*Private
;
478 CHAR8 IScsiName
[ISCSI_NAME_IFR_MAX_SIZE
];
479 CHAR16 PortString
[128];
480 CHAR8 Ip4String
[IP4_STR_MAX_SIZE
];
481 CHAR8 LunString
[ISCSI_LUN_STR_MAX_LEN
];
483 EFI_STRING_ID DeviceFormTitleToken
;
484 ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
;
485 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
486 EFI_IP_ADDRESS HostIp
;
487 EFI_IP_ADDRESS SubnetMask
;
488 EFI_IP_ADDRESS Gateway
;
491 Private
= ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This
);
494 // Retrive uncommitted data from Browser
496 BufferSize
= sizeof (ISCSI_CONFIG_IFR_NVDATA
);
497 IfrNvData
= AllocateZeroPool (BufferSize
);
498 ASSERT (IfrNvData
!= NULL
);
499 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) IfrNvData
);
500 if (EFI_ERROR (Status
)) {
501 gBS
->FreePool (IfrNvData
);
505 switch (QuestionId
) {
506 case KEY_INITIATOR_NAME
:
507 IScsiUnicodeStrToAsciiStr (IfrNvData
->InitiatorName
, IScsiName
);
508 BufferSize
= AsciiStrLen (IScsiName
) + 1;
510 Status
= gIScsiInitiatorName
.Set (&gIScsiInitiatorName
, &BufferSize
, IScsiName
);
511 if (EFI_ERROR (Status
)) {
512 PopUpInvalidNotify (L
"Invalid iSCSI Name!");
518 IScsiUnicodeStrToAsciiStr (IfrNvData
->LocalIp
, Ip4String
);
519 Status
= IScsiAsciiStrToIp (Ip4String
, &HostIp
.v4
);
520 if (EFI_ERROR (Status
) || !Ip4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
521 PopUpInvalidNotify (L
"Invalid IP address!");
522 Status
= EFI_INVALID_PARAMETER
;
524 CopyMem (&Private
->Current
->SessionConfigData
.LocalIp
, &HostIp
.v4
, sizeof (HostIp
.v4
));
529 case KEY_SUBNET_MASK
:
530 IScsiUnicodeStrToAsciiStr (IfrNvData
->SubnetMask
, Ip4String
);
531 Status
= IScsiAsciiStrToIp (Ip4String
, &SubnetMask
.v4
);
532 if (EFI_ERROR (Status
) || ((SubnetMask
.Addr
[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask
.v4
) == 0))) {
533 PopUpInvalidNotify (L
"Invalid Subnet Mask!");
534 Status
= EFI_INVALID_PARAMETER
;
536 CopyMem (&Private
->Current
->SessionConfigData
.SubnetMask
, &SubnetMask
.v4
, sizeof (SubnetMask
.v4
));
542 IScsiUnicodeStrToAsciiStr (IfrNvData
->Gateway
, Ip4String
);
543 Status
= IScsiAsciiStrToIp (Ip4String
, &Gateway
.v4
);
544 if (EFI_ERROR (Status
) || ((Gateway
.Addr
[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway
.Addr
[0]), 0))) {
545 PopUpInvalidNotify (L
"Invalid Gateway!");
546 Status
= EFI_INVALID_PARAMETER
;
548 CopyMem (&Private
->Current
->SessionConfigData
.Gateway
, &Gateway
.v4
, sizeof (Gateway
.v4
));
554 IScsiUnicodeStrToAsciiStr (IfrNvData
->TargetIp
, Ip4String
);
555 Status
= IScsiAsciiStrToIp (Ip4String
, &HostIp
.v4
);
556 if (EFI_ERROR (Status
) || !Ip4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
557 PopUpInvalidNotify (L
"Invalid IP address!");
558 Status
= EFI_INVALID_PARAMETER
;
560 CopyMem (&Private
->Current
->SessionConfigData
.TargetIp
, &HostIp
.v4
, sizeof (HostIp
.v4
));
565 case KEY_TARGET_NAME
:
566 IScsiUnicodeStrToAsciiStr (IfrNvData
->TargetName
, IScsiName
);
567 Status
= IScsiNormalizeName (IScsiName
, AsciiStrLen (IScsiName
));
568 if (EFI_ERROR (Status
)) {
569 PopUpInvalidNotify (L
"Invalid iSCSI Name!");
571 AsciiStrCpy (Private
->Current
->SessionConfigData
.TargetName
, IScsiName
);
576 case KEY_DHCP_ENABLE
:
577 if (IfrNvData
->InitiatorInfoFromDhcp
== 0) {
578 IfrNvData
->TargetInfoFromDhcp
= 0;
584 IScsiUnicodeStrToAsciiStr (IfrNvData
->BootLun
, LunString
);
585 Status
= IScsiAsciiStrToLun (LunString
, (UINT8
*) &Lun
);
586 if (EFI_ERROR (Status
)) {
587 PopUpInvalidNotify (L
"Invalid LUN string!");
589 CopyMem (Private
->Current
->SessionConfigData
.BootLun
, &Lun
, sizeof (Lun
));
595 IScsiUnicodeStrToAsciiStr (IfrNvData
->CHAPName
, Private
->Current
->AuthConfigData
.CHAPName
);
598 case KEY_CHAP_SECRET
:
599 IScsiUnicodeStrToAsciiStr (IfrNvData
->CHAPSecret
, Private
->Current
->AuthConfigData
.CHAPSecret
);
602 case KEY_REVERSE_CHAP_NAME
:
603 IScsiUnicodeStrToAsciiStr (IfrNvData
->ReverseCHAPName
, Private
->Current
->AuthConfigData
.ReverseCHAPName
);
606 case KEY_REVERSE_CHAP_SECRET
:
607 IScsiUnicodeStrToAsciiStr (IfrNvData
->ReverseCHAPSecret
, Private
->Current
->AuthConfigData
.ReverseCHAPSecret
);
610 case KEY_SAVE_CHANGES
:
612 // First, update those fields which don't have INTERACTIVE set.
614 Private
->Current
->SessionConfigData
.Enabled
= IfrNvData
->Enabled
;
615 Private
->Current
->SessionConfigData
.InitiatorInfoFromDhcp
= IfrNvData
->InitiatorInfoFromDhcp
;
616 Private
->Current
->SessionConfigData
.TargetPort
= IfrNvData
->TargetPort
;
617 if (Private
->Current
->SessionConfigData
.TargetPort
== 0) {
618 Private
->Current
->SessionConfigData
.TargetPort
= ISCSI_WELL_KNOWN_PORT
;
621 Private
->Current
->SessionConfigData
.TargetInfoFromDhcp
= IfrNvData
->TargetInfoFromDhcp
;
622 Private
->Current
->AuthConfigData
.CHAPType
= IfrNvData
->CHAPType
;
625 // Only do full parameter validation if iSCSI is enabled on this device.
627 if (Private
->Current
->SessionConfigData
.Enabled
) {
629 // Validate the address configuration of the Initiator if DHCP isn't
632 if (!Private
->Current
->SessionConfigData
.InitiatorInfoFromDhcp
) {
633 CopyMem (&HostIp
.v4
, &Private
->Current
->SessionConfigData
.LocalIp
, sizeof (HostIp
.v4
));
634 CopyMem (&SubnetMask
.v4
, &Private
->Current
->SessionConfigData
.SubnetMask
, sizeof (SubnetMask
.v4
));
635 CopyMem (&Gateway
.v4
, &Private
->Current
->SessionConfigData
.Gateway
, sizeof (Gateway
.v4
));
637 if ((Gateway
.Addr
[0] != 0)) {
638 if (SubnetMask
.Addr
[0] == 0) {
639 PopUpInvalidNotify (L
"Gateway address is set but subnet mask is zero.");
640 Status
= EFI_INVALID_PARAMETER
;
642 } else if (!IP4_NET_EQUAL (HostIp
.Addr
[0], Gateway
.Addr
[0], SubnetMask
.Addr
[0])) {
643 PopUpInvalidNotify (L
"Local IP and Gateway are not in the same subnet.");
644 Status
= EFI_INVALID_PARAMETER
;
650 // Validate target configuration if DHCP isn't deployed.
652 if (!Private
->Current
->SessionConfigData
.TargetInfoFromDhcp
) {
653 CopyMem (&HostIp
.v4
, &Private
->Current
->SessionConfigData
.TargetIp
, sizeof (HostIp
.v4
));
654 if (!Ip4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
655 PopUpInvalidNotify (L
"Target IP is invalid!");
656 Status
= EFI_INVALID_PARAMETER
;
661 if (IfrNvData
->CHAPType
!= ISCSI_CHAP_NONE
) {
662 if ((IfrNvData
->CHAPName
[0] == '\0') || (IfrNvData
->CHAPSecret
[0] == '\0')) {
663 PopUpInvalidNotify (L
"CHAP Name or CHAP Secret is invalid!");
664 Status
= EFI_INVALID_PARAMETER
;
668 if ((IfrNvData
->CHAPType
== ISCSI_CHAP_MUTUAL
) &&
669 ((IfrNvData
->ReverseCHAPName
[0] == '\0') || (IfrNvData
->ReverseCHAPSecret
[0] == '\0'))
671 PopUpInvalidNotify (L
"Reverse CHAP Name or Reverse CHAP Secret is invalid!");
672 Status
= EFI_INVALID_PARAMETER
;
678 BufferSize
= sizeof (Private
->Current
->SessionConfigData
);
680 Private
->Current
->MacString
,
681 &gEfiIScsiInitiatorNameProtocolGuid
,
682 ISCSI_CONFIG_VAR_ATTR
,
684 &Private
->Current
->SessionConfigData
687 BufferSize
= sizeof (Private
->Current
->AuthConfigData
);
689 Private
->Current
->MacString
,
690 &mIScsiCHAPAuthInfoGuid
,
691 ISCSI_CONFIG_VAR_ATTR
,
693 &Private
->Current
->AuthConfigData
695 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
699 if ((QuestionId
>= KEY_DEVICE_ENTRY_BASE
) && (QuestionId
< (mNumberOfIScsiDevices
+ KEY_DEVICE_ENTRY_BASE
))) {
701 // In case goto the device configuration form, update the device form title.
703 ConfigFormEntry
= IScsiGetConfigFormEntryByIndex ((UINT32
) (QuestionId
- KEY_DEVICE_ENTRY_BASE
));
704 ASSERT (ConfigFormEntry
!= NULL
);
706 UnicodeSPrint (PortString
, (UINTN
) 128, L
"Port %s", ConfigFormEntry
->MacString
);
707 DeviceFormTitleToken
= (EFI_STRING_ID
) STR_ISCSI_DEVICE_FORM_TITLE
;
708 HiiLibSetString (Private
->RegisteredHandle
, DeviceFormTitleToken
, PortString
);
710 IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry
, IfrNvData
);
712 Private
->Current
= ConfigFormEntry
;
718 if (!EFI_ERROR (Status
)) {
720 // Pass changed uncommitted data back to Form Browser
722 BufferSize
= sizeof (ISCSI_CONFIG_IFR_NVDATA
);
723 Status
= SetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) IfrNvData
, NULL
);
726 gBS
->FreePool (IfrNvData
);
731 Updates the iSCSI configuration form to add/delete an entry for the iSCSI
732 device specified by the Controller.
734 @param[in] DriverBindingHandle The driverbinding handle.
735 @param[in] Controller The controller handle of the iSCSI device.
736 @param[in] AddForm Whether to add or delete a form entry.
738 @retval EFI_SUCCESS The iSCSI configuration form is updated.
739 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
740 @retval Others Other errors as indicated.
743 IScsiConfigUpdateForm (
744 IN EFI_HANDLE DriverBindingHandle
,
745 IN EFI_HANDLE Controller
,
750 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
751 BOOLEAN EntryExisted
;
753 EFI_HII_UPDATE_DATA UpdateData
;
754 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
755 CHAR16 PortString
[128];
760 ConfigFormEntry
= NULL
;
761 EntryExisted
= FALSE
;
763 NET_LIST_FOR_EACH (Entry
, &mIScsiConfigFormList
) {
764 ConfigFormEntry
= NET_LIST_USER_STRUCT (Entry
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
766 if (ConfigFormEntry
->Controller
== Controller
) {
779 ConfigFormEntry
= (ISCSI_CONFIG_FORM_ENTRY
*) AllocateZeroPool (sizeof (ISCSI_CONFIG_FORM_ENTRY
));
780 if (ConfigFormEntry
== NULL
) {
781 return EFI_OUT_OF_RESOURCES
;
784 InitializeListHead (&ConfigFormEntry
->Link
);
785 ConfigFormEntry
->Controller
= Controller
;
788 // Get the simple network protocol and convert the MAC address into
789 // the formatted string.
791 Status
= gBS
->HandleProtocol (
793 &gEfiSimpleNetworkProtocolGuid
,
796 ASSERT (Status
== EFI_SUCCESS
);
798 IScsiMacAddrToStr (&Snp
->Mode
->PermanentAddress
, Snp
->Mode
->HwAddressSize
, ConfigFormEntry
->MacString
);
801 // Get the normal session configuration data.
803 BufferSize
= sizeof (ConfigFormEntry
->SessionConfigData
);
804 Status
= gRT
->GetVariable (
805 ConfigFormEntry
->MacString
,
806 &gEfiIScsiInitiatorNameProtocolGuid
,
809 &ConfigFormEntry
->SessionConfigData
811 if (EFI_ERROR (Status
)) {
812 ZeroMem (&ConfigFormEntry
->SessionConfigData
, sizeof (ConfigFormEntry
->SessionConfigData
));
815 // Get the CHAP authentication configuration data.
817 BufferSize
= sizeof (ConfigFormEntry
->AuthConfigData
);
818 Status
= gRT
->GetVariable (
819 ConfigFormEntry
->MacString
,
820 &mIScsiCHAPAuthInfoGuid
,
823 &ConfigFormEntry
->AuthConfigData
825 if (EFI_ERROR (Status
)) {
826 ZeroMem (&ConfigFormEntry
->AuthConfigData
, sizeof (ConfigFormEntry
->AuthConfigData
));
829 // Compose the Port string and create a new EFI_STRING_ID.
831 UnicodeSPrint (PortString
, 128, L
"Port %s", ConfigFormEntry
->MacString
);
832 HiiLibNewString (mCallbackInfo
->RegisteredHandle
, &ConfigFormEntry
->PortTitleToken
, PortString
);
835 // Compose the help string of this port and create a new EFI_STRING_ID.
837 UnicodeSPrint (PortString
, 128, L
"Set the iSCSI parameters on port %s", ConfigFormEntry
->MacString
);
838 HiiLibNewString (mCallbackInfo
->RegisteredHandle
, &ConfigFormEntry
->PortTitleHelpToken
, PortString
);
840 InsertTailList (&mIScsiConfigFormList
, &ConfigFormEntry
->Link
);
841 mNumberOfIScsiDevices
++;
844 ASSERT (EntryExisted
);
846 mNumberOfIScsiDevices
--;
847 RemoveEntryList (&ConfigFormEntry
->Link
);
848 gBS
->FreePool (ConfigFormEntry
);
851 // Allocate space for creation of Buffer
853 UpdateData
.BufferSize
= 0x1000;
854 UpdateData
.Data
= AllocateZeroPool (0x1000);
855 UpdateData
.Offset
= 0;
858 NET_LIST_FOR_EACH (Entry
, &mIScsiConfigFormList
) {
859 ConfigFormEntry
= NET_LIST_USER_STRUCT (Entry
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
863 ConfigFormEntry
->PortTitleToken
,
864 ConfigFormEntry
->PortTitleHelpToken
,
865 EFI_IFR_FLAG_CALLBACK
,
866 (UINT16
)(KEY_DEVICE_ENTRY_BASE
+ FormIndex
),
874 mCallbackInfo
->RegisteredHandle
,
882 gBS
->FreePool (UpdateData
.Data
);
888 Initialize the iSCSI configuration form.
890 @param[in] DriverBindingHandle The iSCSI driverbinding handle.
892 @retval EFI_SUCCESS The iSCSI configuration form is initialized.
893 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
894 @retval Others Other errors as indicated.
897 IScsiConfigFormInit (
902 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
903 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
904 ISCSI_FORM_CALLBACK_INFO
*CallbackInfo
;
906 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**)&HiiDatabase
);
907 if (EFI_ERROR (Status
)) {
911 CallbackInfo
= (ISCSI_FORM_CALLBACK_INFO
*) AllocatePool (sizeof (ISCSI_FORM_CALLBACK_INFO
));
912 if (CallbackInfo
== NULL
) {
913 return EFI_OUT_OF_RESOURCES
;
916 CallbackInfo
->Signature
= ISCSI_FORM_CALLBACK_INFO_SIGNATURE
;
917 CallbackInfo
->HiiDatabase
= HiiDatabase
;
918 CallbackInfo
->Current
= NULL
;
920 CallbackInfo
->ConfigAccess
.ExtractConfig
= IScsiFormExtractConfig
;
921 CallbackInfo
->ConfigAccess
.RouteConfig
= IScsiFormRouteConfig
;
922 CallbackInfo
->ConfigAccess
.Callback
= IScsiFormCallback
;
924 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**)&CallbackInfo
->ConfigRouting
);
925 if (EFI_ERROR (Status
)) {
926 FreePool(CallbackInfo
);
931 // Create driver handle used by HII database
933 Status
= HiiLibCreateHiiDriverHandle (&CallbackInfo
->DriverHandle
);
934 if (EFI_ERROR (Status
)) {
935 FreePool(CallbackInfo
);
940 // Install Config Access protocol to driver handle
942 Status
= gBS
->InstallProtocolInterface (
943 &CallbackInfo
->DriverHandle
,
944 &gEfiHiiConfigAccessProtocolGuid
,
945 EFI_NATIVE_INTERFACE
,
946 &CallbackInfo
->ConfigAccess
948 ASSERT_EFI_ERROR (Status
);
951 // Publish our HII data
953 PackageList
= HiiLibPreparePackageList (2, &mVendorGuid
, IScsiDxeStrings
, IScsiConfigDxeBin
);
954 ASSERT (PackageList
!= NULL
);
956 Status
= HiiDatabase
->NewPackageList (
959 CallbackInfo
->DriverHandle
,
960 &CallbackInfo
->RegisteredHandle
962 FreePool (PackageList
);
963 if (EFI_ERROR (Status
)) {
964 FreePool(CallbackInfo
);
968 mCallbackInfo
= CallbackInfo
;
974 Unload the iSCSI configuration form, this includes: delete all the iSCSI
975 device configuration entries, uninstall the form callback protocol and
976 free the resources used.
978 @param[in] DriverBindingHandle The iSCSI driverbinding handle.
980 @retval EFI_SUCCESS The iSCSI configuration form is unloaded.
981 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
984 IScsiConfigFormUnload (
985 IN EFI_HANDLE DriverBindingHandle
988 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
990 while (!IsListEmpty (&mIScsiConfigFormList
)) {
992 // Uninstall the device forms as the iSCSI driver instance may fail to
993 // control the controller but still install the device configuration form.
994 // In such case, upon driver unloading, the driver instance's driverbinding.
995 // stop () won't be called, so we have to take this chance here to uninstall
998 ConfigFormEntry
= NET_LIST_USER_STRUCT (mIScsiConfigFormList
.ForwardLink
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
999 IScsiConfigUpdateForm (DriverBindingHandle
, ConfigFormEntry
->Controller
, FALSE
);
1003 // Remove HII package list
1005 mCallbackInfo
->HiiDatabase
->RemovePackageList (
1006 mCallbackInfo
->HiiDatabase
,
1007 mCallbackInfo
->RegisteredHandle
1011 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL
1013 gBS
->UninstallProtocolInterface (
1014 mCallbackInfo
->DriverHandle
,
1015 &gEfiHiiConfigAccessProtocolGuid
,
1016 &mCallbackInfo
->ConfigAccess
1018 HiiLibDestroyHiiDriverHandle (mCallbackInfo
->DriverHandle
);
1020 gBS
->FreePool (mCallbackInfo
);