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
,
27 HII_VENDOR_DEVICE_PATH mIScsiHiiVendorDevicePath
= {
33 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
34 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
38 // {49D7B73E-143D-4716-977B-C45F1CB038CC}
40 { 0x49d7b73e, 0x143d, 0x4716, { 0x97, 0x7b, 0xc4, 0x5f, 0x1c, 0xb0, 0x38, 0xcc } }
44 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
46 (UINT8
) (END_DEVICE_PATH_LENGTH
),
47 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
53 Convert the IPv4 address into a dotted string.
55 @param[in] Ip The IPv4 address.
56 @param[out] Str The dotted IP string.
60 IN EFI_IPv4_ADDRESS
*Ip
,
64 UnicodeSPrint ( Str
, 2 * IP4_STR_MAX_SIZE
, L
"%d.%d.%d.%d", Ip
->Addr
[0], Ip
->Addr
[1], Ip
->Addr
[2], Ip
->Addr
[3]);
68 Update the list of iSCSI devices the iSCSI driver is controlling.
70 @retval EFI_SUCCESS The callback successfully handled the action.
71 @retval Others Other errors as indicated.
74 IScsiUpdateDeviceList (
79 ISCSI_DEVICE_LIST
*DeviceList
;
85 UINTN LastDeviceIndex
;
86 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
87 EFI_SIMPLE_NETWORK_MODE
*Mode
;
88 ISCSI_MAC_INFO
*CurMacInfo
;
89 ISCSI_MAC_INFO TempMacInfo
;
94 // Dump all the handles the Simple Network Protocol is installed on.
96 Status
= gBS
->LocateHandleBuffer (
98 &gEfiSimpleNetworkProtocolGuid
,
103 if (EFI_ERROR (Status
)) {
108 Status
= gRT
->GetVariable (
115 if (Status
== EFI_BUFFER_TOO_SMALL
) {
116 DeviceList
= (ISCSI_DEVICE_LIST
*) AllocatePool (DataSize
);
128 for (HandleIndex
= 0; HandleIndex
< NumHandles
; HandleIndex
++) {
129 gBS
->HandleProtocol (Handles
[HandleIndex
], &gEfiSimpleNetworkProtocolGuid
, (VOID
**)&Snp
);
133 for (Index
= LastDeviceIndex
; Index
< DeviceList
->NumDevice
; Index
++) {
134 CurMacInfo
= &DeviceList
->MacInfo
[Index
];
135 if ((CurMacInfo
->Len
== Mode
->HwAddressSize
) &&
136 (NET_MAC_EQUAL (&CurMacInfo
->Mac
, &Mode
->PermanentAddress
, Mode
->HwAddressSize
))
139 // The previous configured NIC is still here.
141 if (Index
!= LastDeviceIndex
) {
143 // Swap the current MAC address entry with the one indexed by
146 CopyMem (&TempMacInfo
, CurMacInfo
, sizeof (ISCSI_MAC_INFO
));
147 CopyMem (CurMacInfo
, &DeviceList
->MacInfo
[LastDeviceIndex
], sizeof (ISCSI_MAC_INFO
));
148 CopyMem (&DeviceList
->MacInfo
[LastDeviceIndex
], &TempMacInfo
, sizeof (ISCSI_MAC_INFO
));
155 if (LastDeviceIndex
== DeviceList
->NumDevice
) {
160 for (Index
= LastDeviceIndex
; Index
< DeviceList
->NumDevice
; Index
++) {
162 // delete the variables
164 CurMacInfo
= &DeviceList
->MacInfo
[Index
];
165 IScsiMacAddrToStr (&CurMacInfo
->Mac
, CurMacInfo
->Len
, MacString
);
166 gRT
->SetVariable (MacString
, &gEfiIScsiInitiatorNameProtocolGuid
, 0, 0, NULL
);
167 gRT
->SetVariable (MacString
, &mIScsiCHAPAuthInfoGuid
, 0, 0, NULL
);
170 gBS
->FreePool (DeviceList
);
171 } else if (Status
!= EFI_NOT_FOUND
) {
172 gBS
->FreePool (Handles
);
176 // Construct the new iSCSI device list.
178 DeviceListSize
= sizeof (ISCSI_DEVICE_LIST
) + (NumHandles
- 1) * sizeof (ISCSI_MAC_INFO
);
179 DeviceList
= (ISCSI_DEVICE_LIST
*) AllocatePool (DeviceListSize
);
180 DeviceList
->NumDevice
= (UINT8
) NumHandles
;
182 for (Index
= 0; Index
< NumHandles
; Index
++) {
183 gBS
->HandleProtocol (Handles
[Index
], &gEfiSimpleNetworkProtocolGuid
, (VOID
**)&Snp
);
186 CurMacInfo
= &DeviceList
->MacInfo
[Index
];
187 CopyMem (&CurMacInfo
->Mac
, &Mode
->PermanentAddress
, Mode
->HwAddressSize
);
188 CurMacInfo
->Len
= (UINT8
) Mode
->HwAddressSize
;
194 ISCSI_CONFIG_VAR_ATTR
,
199 gBS
->FreePool (DeviceList
);
200 gBS
->FreePool (Handles
);
206 Get the iSCSI configuration form entry by the index of the goto opcode actived.
208 @param[in] Index The 0-based index of the goto opcode actived.
210 @return The iSCSI configuration form entry found.
212 ISCSI_CONFIG_FORM_ENTRY
*
213 IScsiGetConfigFormEntryByIndex (
219 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
222 ConfigFormEntry
= NULL
;
224 NET_LIST_FOR_EACH (Entry
, &mIScsiConfigFormList
) {
225 if (CurrentIndex
== Index
) {
226 ConfigFormEntry
= NET_LIST_USER_STRUCT (Entry
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
233 return ConfigFormEntry
;
237 Convert the iSCSI configuration data into the IFR data.
239 @param[in] ConfigFormEntry The iSCSI configuration form entry.
240 @param[out] IfrNvData The IFR nv data.
243 IScsiConvertDeviceConfigDataToIfrNvData (
244 IN ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
,
245 OUT ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
248 ISCSI_SESSION_CONFIG_NVDATA
*SessionConfigData
;
249 ISCSI_CHAP_AUTH_CONFIG_NVDATA
*AuthConfigData
;
252 // Normal session configuration parameters.
254 SessionConfigData
= &ConfigFormEntry
->SessionConfigData
;
255 IfrNvData
->Enabled
= SessionConfigData
->Enabled
;
257 IfrNvData
->InitiatorInfoFromDhcp
= SessionConfigData
->InitiatorInfoFromDhcp
;
258 IfrNvData
->TargetInfoFromDhcp
= SessionConfigData
->TargetInfoFromDhcp
;
259 IfrNvData
->TargetPort
= SessionConfigData
->TargetPort
;
261 IScsiIpToStr (&SessionConfigData
->LocalIp
, IfrNvData
->LocalIp
);
262 IScsiIpToStr (&SessionConfigData
->SubnetMask
, IfrNvData
->SubnetMask
);
263 IScsiIpToStr (&SessionConfigData
->Gateway
, IfrNvData
->Gateway
);
264 IScsiIpToStr (&SessionConfigData
->TargetIp
, IfrNvData
->TargetIp
);
266 IScsiAsciiStrToUnicodeStr (SessionConfigData
->TargetName
, IfrNvData
->TargetName
);
268 IScsiLunToUnicodeStr (SessionConfigData
->BootLun
, IfrNvData
->BootLun
);
271 // CHAP authentication parameters.
273 AuthConfigData
= &ConfigFormEntry
->AuthConfigData
;
275 IfrNvData
->CHAPType
= AuthConfigData
->CHAPType
;
277 IScsiAsciiStrToUnicodeStr (AuthConfigData
->CHAPName
, IfrNvData
->CHAPName
);
278 IScsiAsciiStrToUnicodeStr (AuthConfigData
->CHAPSecret
, IfrNvData
->CHAPSecret
);
279 IScsiAsciiStrToUnicodeStr (AuthConfigData
->ReverseCHAPName
, IfrNvData
->ReverseCHAPName
);
280 IScsiAsciiStrToUnicodeStr (AuthConfigData
->ReverseCHAPSecret
, IfrNvData
->ReverseCHAPSecret
);
284 This function allows the caller to request the current
285 configuration for one or more named elements. The resulting
286 string is in <ConfigAltResp> format. Any and all alternative
287 configuration strings shall also be appended to the end of the
288 current configuration string. If they are, they must appear
289 after the current configuration. They must contain the same
290 routing (GUID, NAME, PATH) as the current configuration string.
291 They must have an additional description indicating the type of
292 alternative configuration the string represents,
293 "ALTCFG=<StringToken>". That <StringToken> (when
294 converted from Hex UNICODE to binary) is a reference to a
295 string in the associated string pack.
297 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
298 @param[in] Request A null-terminated Unicode string in
299 <ConfigRequest> format. Note that this
300 includes the routing information as well as
301 the configurable name / value pairs. It is
302 invalid for this string to be in
303 <MultiConfigRequest> format.
304 @param[out] Progress On return, points to a character in the
305 Request string. Points to the string's null
306 terminator if request was successful. Points
307 to the most recent "&" before the first
308 failing name / value pair (or the beginning
309 of the string if the failure is in the first
310 name / value pair) if the request was not
312 @param[out] Results A null-terminated Unicode string in
313 <ConfigAltResp> format which has all values
314 filled in for the names in the Request string.
315 String to be allocated by the called function.
317 @retval EFI_SUCCESS The Results string is filled with the
318 values corresponding to all requested
320 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
321 parts of the results that must be
322 stored awaiting possible future
324 @retval EFI_INVALID_PARAMETER For example, passing in a NULL
325 for the Request parameter
326 would result in this type of
327 error. In this case, the
328 Progress parameter would be
330 @retval EFI_NOT_FOUND Routing data doesn't match any
331 known driver. Progress set to the
332 first character in the routing header.
333 Note: There is no requirement that the
334 driver validate the routing data. It
335 must skip the <ConfigHdr> in order to
337 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
338 to most recent & before the
339 error or the beginning of the
341 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
342 to the & before the name in
343 question.Currently not implemented.
347 IScsiFormExtractConfig (
348 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
349 IN CONST EFI_STRING Request
,
350 OUT EFI_STRING
*Progress
,
351 OUT EFI_STRING
*Results
355 CHAR8 InitiatorName
[ISCSI_NAME_IFR_MAX_SIZE
];
357 ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
;
358 ISCSI_FORM_CALLBACK_INFO
*Private
;
359 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
361 if (Request
== NULL
) {
362 return EFI_INVALID_PARAMETER
;
365 if (!mIScsiDeviceListUpdated
) {
367 // Update the device list.
369 IScsiUpdateDeviceList ();
370 mIScsiDeviceListUpdated
= TRUE
;
373 Private
= ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This
);
374 IfrNvData
= AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA
));
375 ASSERT (IfrNvData
!= NULL
);
376 if (Private
->Current
!= NULL
) {
377 IScsiConvertDeviceConfigDataToIfrNvData (Private
->Current
, IfrNvData
);
380 BufferSize
= ISCSI_NAME_IFR_MAX_SIZE
;
381 Status
= gIScsiInitiatorName
.Get (&gIScsiInitiatorName
, &BufferSize
, InitiatorName
);
382 if (EFI_ERROR (Status
)) {
383 IfrNvData
->InitiatorName
[0] = L
'\0';
385 IScsiAsciiStrToUnicodeStr (InitiatorName
, IfrNvData
->InitiatorName
);
389 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
391 HiiConfigRouting
= Private
->ConfigRouting
;
392 BufferSize
= sizeof (ISCSI_CONFIG_IFR_NVDATA
);
393 Status
= HiiConfigRouting
->BlockToConfig (
401 gBS
->FreePool (IfrNvData
);
406 This function applies changes in a driver's configuration.
407 Input is a Configuration, which has the routing data for this
408 driver followed by name / value configuration pairs. The driver
409 must apply those pairs to its configurable storage. If the
410 driver's configuration is stored in a linear block of data
411 and the driver's name / value pairs are in <BlockConfig>
412 format, it may use the ConfigToBlock helper function (above) to
413 simplify the job. Currently not implemented.
415 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
416 @param[in] Configuration A null-terminated Unicode string in
417 <ConfigString> format.
418 @param[out] Progress A pointer to a string filled in with the
419 offset of the most recent '&' before the
420 first failing name / value pair (or the
421 beginn ing of the string if the failure
422 is in the first name / value pair) or
423 the terminating NULL if all was
426 @retval EFI_SUCCESS The results have been distributed or are
427 awaiting distribution.
428 @retval EFI_OUT_OF_MEMORY Not enough memory to store the
429 parts of the results that must be
430 stored awaiting possible future
432 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
433 Results parameter would result
434 in this type of error.
435 @retval EFI_NOT_FOUND Target for the specified routing data
440 IScsiFormRouteConfig (
441 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
442 IN CONST EFI_STRING Configuration
,
443 OUT EFI_STRING
*Progress
450 This function is called to provide results data to the driver.
451 This data consists of a unique key that is used to identify
452 which data is either being passed back or being asked for.
454 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
455 @param[in] Action Specifies the type of action taken by the browser.
456 @param[in] QuestionId A unique value which is sent to the original
457 exporting driver so that it can identify the type
458 of data to expect. The format of the data tends to
459 vary based on the opcode that enerated the callback.
460 @param[in] Type The type of value for the question.
461 @param[in] Value A pointer to the data being sent to the original
463 @param[out] ActionRequest On return, points to the action requested by the
466 @retval EFI_SUCCESS The callback successfully handled the action.
467 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
468 variable and its data.
469 @retval EFI_DEVICE_ERROR The variable could not be saved.
470 @retval EFI_UNSUPPORTED The specified Action is not supported by the
471 callback.Currently not implemented.
472 @retval EFI_INVALID_PARAMETERS Passing in wrong parameter.
473 @retval Others Other errors as indicated.
478 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
479 IN EFI_BROWSER_ACTION Action
,
480 IN EFI_QUESTION_ID QuestionId
,
482 IN EFI_IFR_TYPE_VALUE
*Value
,
483 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
486 ISCSI_FORM_CALLBACK_INFO
*Private
;
488 CHAR8 IScsiName
[ISCSI_NAME_IFR_MAX_SIZE
];
489 CHAR16 PortString
[128];
490 CHAR8 Ip4String
[IP4_STR_MAX_SIZE
];
491 CHAR8 LunString
[ISCSI_LUN_STR_MAX_LEN
];
493 EFI_STRING_ID DeviceFormTitleToken
;
494 ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
;
495 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
496 EFI_IP_ADDRESS HostIp
;
497 EFI_IP_ADDRESS SubnetMask
;
498 EFI_IP_ADDRESS Gateway
;
502 Private
= ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This
);
505 // Retrive uncommitted data from Browser
507 BufferSize
= sizeof (ISCSI_CONFIG_IFR_NVDATA
);
508 IfrNvData
= AllocateZeroPool (BufferSize
);
509 ASSERT (IfrNvData
!= NULL
);
510 Status
= GetBrowserData (NULL
, NULL
, &BufferSize
, (UINT8
*) IfrNvData
);
511 if (EFI_ERROR (Status
)) {
512 gBS
->FreePool (IfrNvData
);
516 switch (QuestionId
) {
517 case KEY_INITIATOR_NAME
:
518 IScsiUnicodeStrToAsciiStr (IfrNvData
->InitiatorName
, IScsiName
);
519 BufferSize
= AsciiStrLen (IScsiName
) + 1;
521 Status
= gIScsiInitiatorName
.Set (&gIScsiInitiatorName
, &BufferSize
, IScsiName
);
522 if (EFI_ERROR (Status
)) {
523 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid iSCSI Name!", NULL
);
529 IScsiUnicodeStrToAsciiStr (IfrNvData
->LocalIp
, Ip4String
);
530 Status
= IScsiAsciiStrToIp (Ip4String
, &HostIp
.v4
);
531 if (EFI_ERROR (Status
) || !Ip4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
532 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid IP address!", NULL
);
533 Status
= EFI_INVALID_PARAMETER
;
535 CopyMem (&Private
->Current
->SessionConfigData
.LocalIp
, &HostIp
.v4
, sizeof (HostIp
.v4
));
540 case KEY_SUBNET_MASK
:
541 IScsiUnicodeStrToAsciiStr (IfrNvData
->SubnetMask
, Ip4String
);
542 Status
= IScsiAsciiStrToIp (Ip4String
, &SubnetMask
.v4
);
543 if (EFI_ERROR (Status
) || ((SubnetMask
.Addr
[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask
.v4
) == 0))) {
544 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Subnet Mask!", NULL
);
545 Status
= EFI_INVALID_PARAMETER
;
547 CopyMem (&Private
->Current
->SessionConfigData
.SubnetMask
, &SubnetMask
.v4
, sizeof (SubnetMask
.v4
));
553 IScsiUnicodeStrToAsciiStr (IfrNvData
->Gateway
, Ip4String
);
554 Status
= IScsiAsciiStrToIp (Ip4String
, &Gateway
.v4
);
555 if (EFI_ERROR (Status
) || ((Gateway
.Addr
[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway
.Addr
[0]), 0))) {
556 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Gateway!", NULL
);
557 Status
= EFI_INVALID_PARAMETER
;
559 CopyMem (&Private
->Current
->SessionConfigData
.Gateway
, &Gateway
.v4
, sizeof (Gateway
.v4
));
565 IScsiUnicodeStrToAsciiStr (IfrNvData
->TargetIp
, Ip4String
);
566 Status
= IScsiAsciiStrToIp (Ip4String
, &HostIp
.v4
);
567 if (EFI_ERROR (Status
) || !Ip4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
568 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid IP address!", NULL
);
569 Status
= EFI_INVALID_PARAMETER
;
571 CopyMem (&Private
->Current
->SessionConfigData
.TargetIp
, &HostIp
.v4
, sizeof (HostIp
.v4
));
576 case KEY_TARGET_NAME
:
577 IScsiUnicodeStrToAsciiStr (IfrNvData
->TargetName
, IScsiName
);
578 Status
= IScsiNormalizeName (IScsiName
, AsciiStrLen (IScsiName
));
579 if (EFI_ERROR (Status
)) {
580 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid iSCSI Name!", NULL
);
582 AsciiStrCpy (Private
->Current
->SessionConfigData
.TargetName
, IScsiName
);
587 case KEY_DHCP_ENABLE
:
588 if (IfrNvData
->InitiatorInfoFromDhcp
== 0) {
589 IfrNvData
->TargetInfoFromDhcp
= 0;
595 IScsiUnicodeStrToAsciiStr (IfrNvData
->BootLun
, LunString
);
596 Status
= IScsiAsciiStrToLun (LunString
, (UINT8
*) &Lun
);
597 if (EFI_ERROR (Status
)) {
598 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid LUN string!", NULL
);
600 CopyMem (Private
->Current
->SessionConfigData
.BootLun
, &Lun
, sizeof (Lun
));
606 IScsiUnicodeStrToAsciiStr (IfrNvData
->CHAPName
, Private
->Current
->AuthConfigData
.CHAPName
);
609 case KEY_CHAP_SECRET
:
610 IScsiUnicodeStrToAsciiStr (IfrNvData
->CHAPSecret
, Private
->Current
->AuthConfigData
.CHAPSecret
);
613 case KEY_REVERSE_CHAP_NAME
:
614 IScsiUnicodeStrToAsciiStr (IfrNvData
->ReverseCHAPName
, Private
->Current
->AuthConfigData
.ReverseCHAPName
);
617 case KEY_REVERSE_CHAP_SECRET
:
618 IScsiUnicodeStrToAsciiStr (IfrNvData
->ReverseCHAPSecret
, Private
->Current
->AuthConfigData
.ReverseCHAPSecret
);
621 case KEY_SAVE_CHANGES
:
623 // First, update those fields which don't have INTERACTIVE set.
625 Private
->Current
->SessionConfigData
.Enabled
= IfrNvData
->Enabled
;
626 Private
->Current
->SessionConfigData
.InitiatorInfoFromDhcp
= IfrNvData
->InitiatorInfoFromDhcp
;
627 Private
->Current
->SessionConfigData
.TargetPort
= IfrNvData
->TargetPort
;
628 if (Private
->Current
->SessionConfigData
.TargetPort
== 0) {
629 Private
->Current
->SessionConfigData
.TargetPort
= ISCSI_WELL_KNOWN_PORT
;
632 Private
->Current
->SessionConfigData
.TargetInfoFromDhcp
= IfrNvData
->TargetInfoFromDhcp
;
633 Private
->Current
->AuthConfigData
.CHAPType
= IfrNvData
->CHAPType
;
636 // Only do full parameter validation if iSCSI is enabled on this device.
638 if (Private
->Current
->SessionConfigData
.Enabled
) {
640 // Validate the address configuration of the Initiator if DHCP isn't
643 if (!Private
->Current
->SessionConfigData
.InitiatorInfoFromDhcp
) {
644 CopyMem (&HostIp
.v4
, &Private
->Current
->SessionConfigData
.LocalIp
, sizeof (HostIp
.v4
));
645 CopyMem (&SubnetMask
.v4
, &Private
->Current
->SessionConfigData
.SubnetMask
, sizeof (SubnetMask
.v4
));
646 CopyMem (&Gateway
.v4
, &Private
->Current
->SessionConfigData
.Gateway
, sizeof (Gateway
.v4
));
648 if ((Gateway
.Addr
[0] != 0)) {
649 if (SubnetMask
.Addr
[0] == 0) {
650 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Gateway address is set but subnet mask is zero.", NULL
);
651 Status
= EFI_INVALID_PARAMETER
;
653 } else if (!IP4_NET_EQUAL (HostIp
.Addr
[0], Gateway
.Addr
[0], SubnetMask
.Addr
[0])) {
654 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Local IP and Gateway are not in the same subnet.", NULL
);
655 Status
= EFI_INVALID_PARAMETER
;
661 // Validate target configuration if DHCP isn't deployed.
663 if (!Private
->Current
->SessionConfigData
.TargetInfoFromDhcp
) {
664 CopyMem (&HostIp
.v4
, &Private
->Current
->SessionConfigData
.TargetIp
, sizeof (HostIp
.v4
));
665 if (!Ip4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
666 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Target IP is invalid!", NULL
);
667 Status
= EFI_INVALID_PARAMETER
;
672 if (IfrNvData
->CHAPType
!= ISCSI_CHAP_NONE
) {
673 if ((IfrNvData
->CHAPName
[0] == '\0') || (IfrNvData
->CHAPSecret
[0] == '\0')) {
674 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"CHAP Name or CHAP Secret is invalid!", NULL
);
675 Status
= EFI_INVALID_PARAMETER
;
679 if ((IfrNvData
->CHAPType
== ISCSI_CHAP_MUTUAL
) &&
680 ((IfrNvData
->ReverseCHAPName
[0] == '\0') || (IfrNvData
->ReverseCHAPSecret
[0] == '\0'))
682 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Reverse CHAP Name or Reverse CHAP Secret is invalid!", NULL
);
683 Status
= EFI_INVALID_PARAMETER
;
689 BufferSize
= sizeof (Private
->Current
->SessionConfigData
);
691 Private
->Current
->MacString
,
692 &gEfiIScsiInitiatorNameProtocolGuid
,
693 ISCSI_CONFIG_VAR_ATTR
,
695 &Private
->Current
->SessionConfigData
698 BufferSize
= sizeof (Private
->Current
->AuthConfigData
);
700 Private
->Current
->MacString
,
701 &mIScsiCHAPAuthInfoGuid
,
702 ISCSI_CONFIG_VAR_ATTR
,
704 &Private
->Current
->AuthConfigData
706 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
710 if ((QuestionId
>= KEY_DEVICE_ENTRY_BASE
) && (QuestionId
< (mNumberOfIScsiDevices
+ KEY_DEVICE_ENTRY_BASE
))) {
712 // In case goto the device configuration form, update the device form title.
714 ConfigFormEntry
= IScsiGetConfigFormEntryByIndex ((UINT32
) (QuestionId
- KEY_DEVICE_ENTRY_BASE
));
715 ASSERT (ConfigFormEntry
!= NULL
);
717 UnicodeSPrint (PortString
, (UINTN
) 128, L
"Port %s", ConfigFormEntry
->MacString
);
718 DeviceFormTitleToken
= (EFI_STRING_ID
) STR_ISCSI_DEVICE_FORM_TITLE
;
719 HiiLibSetString (Private
->RegisteredHandle
, DeviceFormTitleToken
, PortString
);
721 IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry
, IfrNvData
);
723 Private
->Current
= ConfigFormEntry
;
729 if (!EFI_ERROR (Status
)) {
731 // Pass changed uncommitted data back to Form Browser
733 BufferSize
= sizeof (ISCSI_CONFIG_IFR_NVDATA
);
734 Status
= SetBrowserData (NULL
, NULL
, BufferSize
, (UINT8
*) IfrNvData
, NULL
);
737 gBS
->FreePool (IfrNvData
);
742 Updates the iSCSI configuration form to add/delete an entry for the iSCSI
743 device specified by the Controller.
745 @param[in] DriverBindingHandle The driverbinding handle.
746 @param[in] Controller The controller handle of the iSCSI device.
747 @param[in] AddForm Whether to add or delete a form entry.
749 @retval EFI_SUCCESS The iSCSI configuration form is updated.
750 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
751 @retval Others Other errors as indicated.
754 IScsiConfigUpdateForm (
755 IN EFI_HANDLE DriverBindingHandle
,
756 IN EFI_HANDLE Controller
,
761 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
762 BOOLEAN EntryExisted
;
764 EFI_HII_UPDATE_DATA UpdateData
;
765 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
766 CHAR16 PortString
[128];
771 ConfigFormEntry
= NULL
;
772 EntryExisted
= FALSE
;
774 NET_LIST_FOR_EACH (Entry
, &mIScsiConfigFormList
) {
775 ConfigFormEntry
= NET_LIST_USER_STRUCT (Entry
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
777 if (ConfigFormEntry
->Controller
== Controller
) {
790 ConfigFormEntry
= (ISCSI_CONFIG_FORM_ENTRY
*) AllocateZeroPool (sizeof (ISCSI_CONFIG_FORM_ENTRY
));
791 if (ConfigFormEntry
== NULL
) {
792 return EFI_OUT_OF_RESOURCES
;
795 InitializeListHead (&ConfigFormEntry
->Link
);
796 ConfigFormEntry
->Controller
= Controller
;
799 // Get the simple network protocol and convert the MAC address into
800 // the formatted string.
802 Status
= gBS
->HandleProtocol (
804 &gEfiSimpleNetworkProtocolGuid
,
807 ASSERT (Status
== EFI_SUCCESS
);
809 IScsiMacAddrToStr (&Snp
->Mode
->PermanentAddress
, Snp
->Mode
->HwAddressSize
, ConfigFormEntry
->MacString
);
812 // Get the normal session configuration data.
814 BufferSize
= sizeof (ConfigFormEntry
->SessionConfigData
);
815 Status
= gRT
->GetVariable (
816 ConfigFormEntry
->MacString
,
817 &gEfiIScsiInitiatorNameProtocolGuid
,
820 &ConfigFormEntry
->SessionConfigData
822 if (EFI_ERROR (Status
)) {
823 ZeroMem (&ConfigFormEntry
->SessionConfigData
, sizeof (ConfigFormEntry
->SessionConfigData
));
826 // Get the CHAP authentication configuration data.
828 BufferSize
= sizeof (ConfigFormEntry
->AuthConfigData
);
829 Status
= gRT
->GetVariable (
830 ConfigFormEntry
->MacString
,
831 &mIScsiCHAPAuthInfoGuid
,
834 &ConfigFormEntry
->AuthConfigData
836 if (EFI_ERROR (Status
)) {
837 ZeroMem (&ConfigFormEntry
->AuthConfigData
, sizeof (ConfigFormEntry
->AuthConfigData
));
840 // Compose the Port string and create a new EFI_STRING_ID.
842 UnicodeSPrint (PortString
, 128, L
"Port %s", ConfigFormEntry
->MacString
);
843 HiiLibNewString (mCallbackInfo
->RegisteredHandle
, &ConfigFormEntry
->PortTitleToken
, PortString
);
846 // Compose the help string of this port and create a new EFI_STRING_ID.
848 UnicodeSPrint (PortString
, 128, L
"Set the iSCSI parameters on port %s", ConfigFormEntry
->MacString
);
849 HiiLibNewString (mCallbackInfo
->RegisteredHandle
, &ConfigFormEntry
->PortTitleHelpToken
, PortString
);
851 InsertTailList (&mIScsiConfigFormList
, &ConfigFormEntry
->Link
);
852 mNumberOfIScsiDevices
++;
855 ASSERT (EntryExisted
);
857 mNumberOfIScsiDevices
--;
858 RemoveEntryList (&ConfigFormEntry
->Link
);
859 gBS
->FreePool (ConfigFormEntry
);
862 // Allocate space for creation of Buffer
864 UpdateData
.BufferSize
= 0x1000;
865 UpdateData
.Data
= AllocateZeroPool (0x1000);
866 UpdateData
.Offset
= 0;
869 NET_LIST_FOR_EACH (Entry
, &mIScsiConfigFormList
) {
870 ConfigFormEntry
= NET_LIST_USER_STRUCT (Entry
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
874 ConfigFormEntry
->PortTitleToken
,
875 ConfigFormEntry
->PortTitleHelpToken
,
876 EFI_IFR_FLAG_CALLBACK
,
877 (UINT16
)(KEY_DEVICE_ENTRY_BASE
+ FormIndex
),
885 mCallbackInfo
->RegisteredHandle
,
893 gBS
->FreePool (UpdateData
.Data
);
899 Initialize the iSCSI configuration form.
901 @param[in] DriverBindingHandle The iSCSI driverbinding handle.
903 @retval EFI_SUCCESS The iSCSI configuration form is initialized.
904 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
905 @retval Others Other errors as indicated.
908 IScsiConfigFormInit (
913 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
914 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
915 ISCSI_FORM_CALLBACK_INFO
*CallbackInfo
;
917 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**)&HiiDatabase
);
918 if (EFI_ERROR (Status
)) {
922 CallbackInfo
= (ISCSI_FORM_CALLBACK_INFO
*) AllocateZeroPool (sizeof (ISCSI_FORM_CALLBACK_INFO
));
923 if (CallbackInfo
== NULL
) {
924 return EFI_OUT_OF_RESOURCES
;
927 CallbackInfo
->Signature
= ISCSI_FORM_CALLBACK_INFO_SIGNATURE
;
928 CallbackInfo
->HiiDatabase
= HiiDatabase
;
929 CallbackInfo
->Current
= NULL
;
931 CallbackInfo
->ConfigAccess
.ExtractConfig
= IScsiFormExtractConfig
;
932 CallbackInfo
->ConfigAccess
.RouteConfig
= IScsiFormRouteConfig
;
933 CallbackInfo
->ConfigAccess
.Callback
= IScsiFormCallback
;
935 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**)&CallbackInfo
->ConfigRouting
);
936 if (EFI_ERROR (Status
)) {
937 FreePool(CallbackInfo
);
942 // Install Device Path Protocol and Config Access protocol to driver handle
944 Status
= gBS
->InstallMultipleProtocolInterfaces (
945 &CallbackInfo
->DriverHandle
,
946 &gEfiDevicePathProtocolGuid
,
947 &mIScsiHiiVendorDevicePath
,
948 &gEfiHiiConfigAccessProtocolGuid
,
949 &CallbackInfo
->ConfigAccess
,
952 ASSERT_EFI_ERROR (Status
);
955 // Publish our HII data
957 PackageList
= HiiLibPreparePackageList (2, &mVendorGuid
, IScsiDxeStrings
, IScsiConfigDxeBin
);
958 ASSERT (PackageList
!= NULL
);
960 Status
= HiiDatabase
->NewPackageList (
963 CallbackInfo
->DriverHandle
,
964 &CallbackInfo
->RegisteredHandle
966 FreePool (PackageList
);
967 if (EFI_ERROR (Status
)) {
968 FreePool(CallbackInfo
);
972 mCallbackInfo
= CallbackInfo
;
978 Unload the iSCSI configuration form, this includes: delete all the iSCSI
979 device configuration entries, uninstall the form callback protocol and
980 free the resources used.
982 @param[in] DriverBindingHandle The iSCSI driverbinding handle.
984 @retval EFI_SUCCESS The iSCSI configuration form is unloaded.
985 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
988 IScsiConfigFormUnload (
989 IN EFI_HANDLE DriverBindingHandle
992 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
994 while (!IsListEmpty (&mIScsiConfigFormList
)) {
996 // Uninstall the device forms as the iSCSI driver instance may fail to
997 // control the controller but still install the device configuration form.
998 // In such case, upon driver unloading, the driver instance's driverbinding.
999 // stop () won't be called, so we have to take this chance here to uninstall
1002 ConfigFormEntry
= NET_LIST_USER_STRUCT (mIScsiConfigFormList
.ForwardLink
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
1003 IScsiConfigUpdateForm (DriverBindingHandle
, ConfigFormEntry
->Controller
, FALSE
);
1007 // Remove HII package list
1009 mCallbackInfo
->HiiDatabase
->RemovePackageList (
1010 mCallbackInfo
->HiiDatabase
,
1011 mCallbackInfo
->RegisteredHandle
1015 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL
1017 gBS
->UninstallMultipleProtocolInterfaces (
1018 mCallbackInfo
->DriverHandle
,
1019 &gEfiDevicePathProtocolGuid
,
1020 &mIScsiHiiVendorDevicePath
,
1021 &gEfiHiiConfigAccessProtocolGuid
,
1022 &mCallbackInfo
->ConfigAccess
,
1025 gBS
->FreePool (mCallbackInfo
);