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 CHAR16 mVendorStorageName
[] = L
"ISCSI_CONFIG_IFR_NVDATA";
19 BOOLEAN mIScsiDeviceListUpdated
= FALSE
;
20 UINTN mNumberOfIScsiDevices
= 0;
21 ISCSI_FORM_CALLBACK_INFO
*mCallbackInfo
= NULL
;
23 LIST_ENTRY mIScsiConfigFormList
= {
24 &mIScsiConfigFormList
,
28 HII_VENDOR_DEVICE_PATH mIScsiHiiVendorDevicePath
= {
34 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
35 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
39 // {49D7B73E-143D-4716-977B-C45F1CB038CC}
41 { 0x49d7b73e, 0x143d, 0x4716, { 0x97, 0x7b, 0xc4, 0x5f, 0x1c, 0xb0, 0x38, 0xcc } }
45 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
47 (UINT8
) (END_DEVICE_PATH_LENGTH
),
48 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
54 Convert the IPv4 address into a dotted string.
56 @param[in] Ip The IPv4 address.
57 @param[out] Str The dotted IP string.
61 IN EFI_IPv4_ADDRESS
*Ip
,
65 UnicodeSPrint ( Str
, 2 * IP4_STR_MAX_SIZE
, L
"%d.%d.%d.%d", Ip
->Addr
[0], Ip
->Addr
[1], Ip
->Addr
[2], Ip
->Addr
[3]);
69 Update the list of iSCSI devices the iSCSI driver is controlling.
71 @retval EFI_SUCCESS The callback successfully handled the action.
72 @retval Others Other errors as indicated.
75 IScsiUpdateDeviceList (
80 ISCSI_DEVICE_LIST
*DeviceList
;
86 UINTN LastDeviceIndex
;
87 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
88 EFI_SIMPLE_NETWORK_MODE
*Mode
;
89 ISCSI_MAC_INFO
*CurMacInfo
;
90 ISCSI_MAC_INFO TempMacInfo
;
95 // Dump all the handles the Simple Network Protocol is installed on.
97 Status
= gBS
->LocateHandleBuffer (
99 &gEfiSimpleNetworkProtocolGuid
,
104 if (EFI_ERROR (Status
)) {
109 Status
= gRT
->GetVariable (
116 if (Status
== EFI_BUFFER_TOO_SMALL
) {
117 DeviceList
= (ISCSI_DEVICE_LIST
*) AllocatePool (DataSize
);
129 for (HandleIndex
= 0; HandleIndex
< NumHandles
; HandleIndex
++) {
130 gBS
->HandleProtocol (Handles
[HandleIndex
], &gEfiSimpleNetworkProtocolGuid
, (VOID
**)&Snp
);
134 for (Index
= LastDeviceIndex
; Index
< DeviceList
->NumDevice
; Index
++) {
135 CurMacInfo
= &DeviceList
->MacInfo
[Index
];
136 if ((CurMacInfo
->Len
== Mode
->HwAddressSize
) &&
137 (NET_MAC_EQUAL (&CurMacInfo
->Mac
, &Mode
->PermanentAddress
, Mode
->HwAddressSize
))
140 // The previous configured NIC is still here.
142 if (Index
!= LastDeviceIndex
) {
144 // Swap the current MAC address entry with the one indexed by
147 CopyMem (&TempMacInfo
, CurMacInfo
, sizeof (ISCSI_MAC_INFO
));
148 CopyMem (CurMacInfo
, &DeviceList
->MacInfo
[LastDeviceIndex
], sizeof (ISCSI_MAC_INFO
));
149 CopyMem (&DeviceList
->MacInfo
[LastDeviceIndex
], &TempMacInfo
, sizeof (ISCSI_MAC_INFO
));
156 if (LastDeviceIndex
== DeviceList
->NumDevice
) {
161 for (Index
= LastDeviceIndex
; Index
< DeviceList
->NumDevice
; Index
++) {
163 // delete the variables
165 CurMacInfo
= &DeviceList
->MacInfo
[Index
];
166 IScsiMacAddrToStr (&CurMacInfo
->Mac
, CurMacInfo
->Len
, MacString
);
167 gRT
->SetVariable (MacString
, &gEfiIScsiInitiatorNameProtocolGuid
, 0, 0, NULL
);
168 gRT
->SetVariable (MacString
, &mIScsiCHAPAuthInfoGuid
, 0, 0, NULL
);
171 gBS
->FreePool (DeviceList
);
172 } else if (Status
!= EFI_NOT_FOUND
) {
173 gBS
->FreePool (Handles
);
177 // Construct the new iSCSI device list.
179 DeviceListSize
= sizeof (ISCSI_DEVICE_LIST
) + (NumHandles
- 1) * sizeof (ISCSI_MAC_INFO
);
180 DeviceList
= (ISCSI_DEVICE_LIST
*) AllocatePool (DeviceListSize
);
181 DeviceList
->NumDevice
= (UINT8
) NumHandles
;
183 for (Index
= 0; Index
< NumHandles
; Index
++) {
184 gBS
->HandleProtocol (Handles
[Index
], &gEfiSimpleNetworkProtocolGuid
, (VOID
**)&Snp
);
187 CurMacInfo
= &DeviceList
->MacInfo
[Index
];
188 CopyMem (&CurMacInfo
->Mac
, &Mode
->PermanentAddress
, Mode
->HwAddressSize
);
189 CurMacInfo
->Len
= (UINT8
) Mode
->HwAddressSize
;
195 ISCSI_CONFIG_VAR_ATTR
,
200 gBS
->FreePool (DeviceList
);
201 gBS
->FreePool (Handles
);
207 Get the iSCSI configuration form entry by the index of the goto opcode actived.
209 @param[in] Index The 0-based index of the goto opcode actived.
211 @return The iSCSI configuration form entry found.
213 ISCSI_CONFIG_FORM_ENTRY
*
214 IScsiGetConfigFormEntryByIndex (
220 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
223 ConfigFormEntry
= NULL
;
225 NET_LIST_FOR_EACH (Entry
, &mIScsiConfigFormList
) {
226 if (CurrentIndex
== Index
) {
227 ConfigFormEntry
= NET_LIST_USER_STRUCT (Entry
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
234 return ConfigFormEntry
;
238 Convert the iSCSI configuration data into the IFR data.
240 @param[in] ConfigFormEntry The iSCSI configuration form entry.
241 @param[out] IfrNvData The IFR nv data.
244 IScsiConvertDeviceConfigDataToIfrNvData (
245 IN ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
,
246 OUT ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
249 ISCSI_SESSION_CONFIG_NVDATA
*SessionConfigData
;
250 ISCSI_CHAP_AUTH_CONFIG_NVDATA
*AuthConfigData
;
253 // Normal session configuration parameters.
255 SessionConfigData
= &ConfigFormEntry
->SessionConfigData
;
256 IfrNvData
->Enabled
= SessionConfigData
->Enabled
;
258 IfrNvData
->InitiatorInfoFromDhcp
= SessionConfigData
->InitiatorInfoFromDhcp
;
259 IfrNvData
->TargetInfoFromDhcp
= SessionConfigData
->TargetInfoFromDhcp
;
260 IfrNvData
->TargetPort
= SessionConfigData
->TargetPort
;
262 IScsiIpToStr (&SessionConfigData
->LocalIp
, IfrNvData
->LocalIp
);
263 IScsiIpToStr (&SessionConfigData
->SubnetMask
, IfrNvData
->SubnetMask
);
264 IScsiIpToStr (&SessionConfigData
->Gateway
, IfrNvData
->Gateway
);
265 IScsiIpToStr (&SessionConfigData
->TargetIp
, IfrNvData
->TargetIp
);
267 IScsiAsciiStrToUnicodeStr (SessionConfigData
->TargetName
, IfrNvData
->TargetName
);
269 IScsiLunToUnicodeStr (SessionConfigData
->BootLun
, IfrNvData
->BootLun
);
272 // CHAP authentication parameters.
274 AuthConfigData
= &ConfigFormEntry
->AuthConfigData
;
276 IfrNvData
->CHAPType
= AuthConfigData
->CHAPType
;
278 IScsiAsciiStrToUnicodeStr (AuthConfigData
->CHAPName
, IfrNvData
->CHAPName
);
279 IScsiAsciiStrToUnicodeStr (AuthConfigData
->CHAPSecret
, IfrNvData
->CHAPSecret
);
280 IScsiAsciiStrToUnicodeStr (AuthConfigData
->ReverseCHAPName
, IfrNvData
->ReverseCHAPName
);
281 IScsiAsciiStrToUnicodeStr (AuthConfigData
->ReverseCHAPSecret
, IfrNvData
->ReverseCHAPSecret
);
285 This function allows the caller to request the current
286 configuration for one or more named elements. The resulting
287 string is in <ConfigAltResp> format. Any and all alternative
288 configuration strings shall also be appended to the end of the
289 current configuration string. If they are, they must appear
290 after the current configuration. They must contain the same
291 routing (GUID, NAME, PATH) as the current configuration string.
292 They must have an additional description indicating the type of
293 alternative configuration the string represents,
294 "ALTCFG=<StringToken>". That <StringToken> (when
295 converted from Hex UNICODE to binary) is a reference to a
296 string in the associated string pack.
298 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
299 @param[in] Request A null-terminated Unicode string in
300 <ConfigRequest> format. Note that this
301 includes the routing information as well as
302 the configurable name / value pairs. It is
303 invalid for this string to be in
304 <MultiConfigRequest> format.
305 @param[out] Progress On return, points to a character in the
306 Request string. Points to the string's null
307 terminator if request was successful. Points
308 to the most recent "&" before the first
309 failing name / value pair (or the beginning
310 of the string if the failure is in the first
311 name / value pair) if the request was not
313 @param[out] Results A null-terminated Unicode string in
314 <ConfigAltResp> format which has all values
315 filled in for the names in the Request string.
316 String to be allocated by the called function.
318 @retval EFI_SUCCESS The Results string is filled with the
319 values corresponding to all requested
321 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
322 parts of the results that must be
323 stored awaiting possible future
325 @retval EFI_INVALID_PARAMETER For example, passing in a NULL
326 for the Request parameter
327 would result in this type of
328 error. In this case, the
329 Progress parameter would be
331 @retval EFI_NOT_FOUND Routing data doesn't match any
332 known driver. Progress set to the
333 first character in the routing header.
334 Note: There is no requirement that the
335 driver validate the routing data. It
336 must skip the <ConfigHdr> in order to
338 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
339 to most recent & before the
340 error or the beginning of the
342 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
343 to the & before the name in
344 question.Currently not implemented.
348 IScsiFormExtractConfig (
349 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
350 IN CONST EFI_STRING Request
,
351 OUT EFI_STRING
*Progress
,
352 OUT EFI_STRING
*Results
356 CHAR8 InitiatorName
[ISCSI_NAME_IFR_MAX_SIZE
];
358 ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
;
359 ISCSI_FORM_CALLBACK_INFO
*Private
;
360 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
362 if (Request
== NULL
) {
363 return EFI_INVALID_PARAMETER
;
366 if (!mIScsiDeviceListUpdated
) {
368 // Update the device list.
370 IScsiUpdateDeviceList ();
371 mIScsiDeviceListUpdated
= TRUE
;
374 Private
= ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This
);
375 IfrNvData
= AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA
));
376 ASSERT (IfrNvData
!= NULL
);
377 if (Private
->Current
!= NULL
) {
378 IScsiConvertDeviceConfigDataToIfrNvData (Private
->Current
, IfrNvData
);
381 BufferSize
= ISCSI_NAME_IFR_MAX_SIZE
;
382 Status
= gIScsiInitiatorName
.Get (&gIScsiInitiatorName
, &BufferSize
, InitiatorName
);
383 if (EFI_ERROR (Status
)) {
384 IfrNvData
->InitiatorName
[0] = L
'\0';
386 IScsiAsciiStrToUnicodeStr (InitiatorName
, IfrNvData
->InitiatorName
);
390 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
392 HiiConfigRouting
= Private
->ConfigRouting
;
393 BufferSize
= sizeof (ISCSI_CONFIG_IFR_NVDATA
);
394 Status
= HiiConfigRouting
->BlockToConfig (
402 gBS
->FreePool (IfrNvData
);
407 This function applies changes in a driver's configuration.
408 Input is a Configuration, which has the routing data for this
409 driver followed by name / value configuration pairs. The driver
410 must apply those pairs to its configurable storage. If the
411 driver's configuration is stored in a linear block of data
412 and the driver's name / value pairs are in <BlockConfig>
413 format, it may use the ConfigToBlock helper function (above) to
414 simplify the job. Currently not implemented.
416 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
417 @param[in] Configuration A null-terminated Unicode string in
418 <ConfigString> format.
419 @param[out] Progress A pointer to a string filled in with the
420 offset of the most recent '&' before the
421 first failing name / value pair (or the
422 beginn ing of the string if the failure
423 is in the first name / value pair) or
424 the terminating NULL if all was
427 @retval EFI_SUCCESS The results have been distributed or are
428 awaiting distribution.
429 @retval EFI_OUT_OF_MEMORY Not enough memory to store the
430 parts of the results that must be
431 stored awaiting possible future
433 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
434 Results parameter would result
435 in this type of error.
436 @retval EFI_NOT_FOUND Target for the specified routing data
441 IScsiFormRouteConfig (
442 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
443 IN CONST EFI_STRING Configuration
,
444 OUT EFI_STRING
*Progress
451 This function is called to provide results data to the driver.
452 This data consists of a unique key that is used to identify
453 which data is either being passed back or being asked for.
455 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
456 @param[in] Action Specifies the type of action taken by the browser.
457 @param[in] QuestionId A unique value which is sent to the original
458 exporting driver so that it can identify the type
459 of data to expect. The format of the data tends to
460 vary based on the opcode that enerated the callback.
461 @param[in] Type The type of value for the question.
462 @param[in] Value A pointer to the data being sent to the original
464 @param[out] ActionRequest On return, points to the action requested by the
467 @retval EFI_SUCCESS The callback successfully handled the action.
468 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
469 variable and its data.
470 @retval EFI_DEVICE_ERROR The variable could not be saved.
471 @retval EFI_UNSUPPORTED The specified Action is not supported by the
472 callback.Currently not implemented.
473 @retval EFI_INVALID_PARAMETERS Passing in wrong parameter.
474 @retval Others Other errors as indicated.
479 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
480 IN EFI_BROWSER_ACTION Action
,
481 IN EFI_QUESTION_ID QuestionId
,
483 IN EFI_IFR_TYPE_VALUE
*Value
,
484 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
487 ISCSI_FORM_CALLBACK_INFO
*Private
;
489 CHAR8 IScsiName
[ISCSI_NAME_IFR_MAX_SIZE
];
490 CHAR16 PortString
[128];
491 CHAR8 Ip4String
[IP4_STR_MAX_SIZE
];
492 CHAR8 LunString
[ISCSI_LUN_STR_MAX_LEN
];
494 EFI_STRING_ID DeviceFormTitleToken
;
495 ISCSI_CONFIG_IFR_NVDATA
*IfrNvData
;
496 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
497 EFI_IP_ADDRESS HostIp
;
498 EFI_IP_ADDRESS SubnetMask
;
499 EFI_IP_ADDRESS Gateway
;
503 Private
= ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This
);
506 // Retrive uncommitted data from Browser
508 IfrNvData
= (ISCSI_CONFIG_IFR_NVDATA
*) HiiGetBrowserData (&mVendorGuid
, mVendorStorageName
, sizeof (ISCSI_CONFIG_IFR_NVDATA
));
509 if (IfrNvData
== NULL
) {
510 return EFI_NOT_FOUND
;
513 Status
= EFI_SUCCESS
;
515 switch (QuestionId
) {
516 case KEY_INITIATOR_NAME
:
517 IScsiUnicodeStrToAsciiStr (IfrNvData
->InitiatorName
, IScsiName
);
518 BufferSize
= AsciiStrLen (IScsiName
) + 1;
520 Status
= gIScsiInitiatorName
.Set (&gIScsiInitiatorName
, &BufferSize
, IScsiName
);
521 if (EFI_ERROR (Status
)) {
522 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid iSCSI Name!", NULL
);
528 IScsiUnicodeStrToAsciiStr (IfrNvData
->LocalIp
, Ip4String
);
529 Status
= IScsiAsciiStrToIp (Ip4String
, &HostIp
.v4
);
530 if (EFI_ERROR (Status
) || !Ip4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
531 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid IP address!", NULL
);
532 Status
= EFI_INVALID_PARAMETER
;
534 CopyMem (&Private
->Current
->SessionConfigData
.LocalIp
, &HostIp
.v4
, sizeof (HostIp
.v4
));
539 case KEY_SUBNET_MASK
:
540 IScsiUnicodeStrToAsciiStr (IfrNvData
->SubnetMask
, Ip4String
);
541 Status
= IScsiAsciiStrToIp (Ip4String
, &SubnetMask
.v4
);
542 if (EFI_ERROR (Status
) || ((SubnetMask
.Addr
[0] != 0) && (IScsiGetSubnetMaskPrefixLength (&SubnetMask
.v4
) == 0))) {
543 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Subnet Mask!", NULL
);
544 Status
= EFI_INVALID_PARAMETER
;
546 CopyMem (&Private
->Current
->SessionConfigData
.SubnetMask
, &SubnetMask
.v4
, sizeof (SubnetMask
.v4
));
552 IScsiUnicodeStrToAsciiStr (IfrNvData
->Gateway
, Ip4String
);
553 Status
= IScsiAsciiStrToIp (Ip4String
, &Gateway
.v4
);
554 if (EFI_ERROR (Status
) || ((Gateway
.Addr
[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway
.Addr
[0]), 0))) {
555 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Gateway!", NULL
);
556 Status
= EFI_INVALID_PARAMETER
;
558 CopyMem (&Private
->Current
->SessionConfigData
.Gateway
, &Gateway
.v4
, sizeof (Gateway
.v4
));
564 IScsiUnicodeStrToAsciiStr (IfrNvData
->TargetIp
, Ip4String
);
565 Status
= IScsiAsciiStrToIp (Ip4String
, &HostIp
.v4
);
566 if (EFI_ERROR (Status
) || !Ip4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
567 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid IP address!", NULL
);
568 Status
= EFI_INVALID_PARAMETER
;
570 CopyMem (&Private
->Current
->SessionConfigData
.TargetIp
, &HostIp
.v4
, sizeof (HostIp
.v4
));
575 case KEY_TARGET_NAME
:
576 IScsiUnicodeStrToAsciiStr (IfrNvData
->TargetName
, IScsiName
);
577 Status
= IScsiNormalizeName (IScsiName
, AsciiStrLen (IScsiName
));
578 if (EFI_ERROR (Status
)) {
579 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid iSCSI Name!", NULL
);
581 AsciiStrCpy (Private
->Current
->SessionConfigData
.TargetName
, IScsiName
);
586 case KEY_DHCP_ENABLE
:
587 if (IfrNvData
->InitiatorInfoFromDhcp
== 0) {
588 IfrNvData
->TargetInfoFromDhcp
= 0;
594 IScsiUnicodeStrToAsciiStr (IfrNvData
->BootLun
, LunString
);
595 Status
= IScsiAsciiStrToLun (LunString
, (UINT8
*) &Lun
);
596 if (EFI_ERROR (Status
)) {
597 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid LUN string!", NULL
);
599 CopyMem (Private
->Current
->SessionConfigData
.BootLun
, &Lun
, sizeof (Lun
));
605 IScsiUnicodeStrToAsciiStr (IfrNvData
->CHAPName
, Private
->Current
->AuthConfigData
.CHAPName
);
608 case KEY_CHAP_SECRET
:
609 IScsiUnicodeStrToAsciiStr (IfrNvData
->CHAPSecret
, Private
->Current
->AuthConfigData
.CHAPSecret
);
612 case KEY_REVERSE_CHAP_NAME
:
613 IScsiUnicodeStrToAsciiStr (IfrNvData
->ReverseCHAPName
, Private
->Current
->AuthConfigData
.ReverseCHAPName
);
616 case KEY_REVERSE_CHAP_SECRET
:
617 IScsiUnicodeStrToAsciiStr (IfrNvData
->ReverseCHAPSecret
, Private
->Current
->AuthConfigData
.ReverseCHAPSecret
);
620 case KEY_SAVE_CHANGES
:
622 // First, update those fields which don't have INTERACTIVE set.
624 Private
->Current
->SessionConfigData
.Enabled
= IfrNvData
->Enabled
;
625 Private
->Current
->SessionConfigData
.InitiatorInfoFromDhcp
= IfrNvData
->InitiatorInfoFromDhcp
;
626 Private
->Current
->SessionConfigData
.TargetPort
= IfrNvData
->TargetPort
;
627 if (Private
->Current
->SessionConfigData
.TargetPort
== 0) {
628 Private
->Current
->SessionConfigData
.TargetPort
= ISCSI_WELL_KNOWN_PORT
;
631 Private
->Current
->SessionConfigData
.TargetInfoFromDhcp
= IfrNvData
->TargetInfoFromDhcp
;
632 Private
->Current
->AuthConfigData
.CHAPType
= IfrNvData
->CHAPType
;
635 // Only do full parameter validation if iSCSI is enabled on this device.
637 if (Private
->Current
->SessionConfigData
.Enabled
) {
639 // Validate the address configuration of the Initiator if DHCP isn't
642 if (!Private
->Current
->SessionConfigData
.InitiatorInfoFromDhcp
) {
643 CopyMem (&HostIp
.v4
, &Private
->Current
->SessionConfigData
.LocalIp
, sizeof (HostIp
.v4
));
644 CopyMem (&SubnetMask
.v4
, &Private
->Current
->SessionConfigData
.SubnetMask
, sizeof (SubnetMask
.v4
));
645 CopyMem (&Gateway
.v4
, &Private
->Current
->SessionConfigData
.Gateway
, sizeof (Gateway
.v4
));
647 if ((Gateway
.Addr
[0] != 0)) {
648 if (SubnetMask
.Addr
[0] == 0) {
649 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Gateway address is set but subnet mask is zero.", NULL
);
650 Status
= EFI_INVALID_PARAMETER
;
652 } else if (!IP4_NET_EQUAL (HostIp
.Addr
[0], Gateway
.Addr
[0], SubnetMask
.Addr
[0])) {
653 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Local IP and Gateway are not in the same subnet.", NULL
);
654 Status
= EFI_INVALID_PARAMETER
;
660 // Validate target configuration if DHCP isn't deployed.
662 if (!Private
->Current
->SessionConfigData
.TargetInfoFromDhcp
) {
663 CopyMem (&HostIp
.v4
, &Private
->Current
->SessionConfigData
.TargetIp
, sizeof (HostIp
.v4
));
664 if (!Ip4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
665 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Target IP is invalid!", NULL
);
666 Status
= EFI_INVALID_PARAMETER
;
671 if (IfrNvData
->CHAPType
!= ISCSI_CHAP_NONE
) {
672 if ((IfrNvData
->CHAPName
[0] == '\0') || (IfrNvData
->CHAPSecret
[0] == '\0')) {
673 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"CHAP Name or CHAP Secret is invalid!", NULL
);
674 Status
= EFI_INVALID_PARAMETER
;
678 if ((IfrNvData
->CHAPType
== ISCSI_CHAP_MUTUAL
) &&
679 ((IfrNvData
->ReverseCHAPName
[0] == '\0') || (IfrNvData
->ReverseCHAPSecret
[0] == '\0'))
681 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Reverse CHAP Name or Reverse CHAP Secret is invalid!", NULL
);
682 Status
= EFI_INVALID_PARAMETER
;
688 BufferSize
= sizeof (Private
->Current
->SessionConfigData
);
690 Private
->Current
->MacString
,
691 &gEfiIScsiInitiatorNameProtocolGuid
,
692 ISCSI_CONFIG_VAR_ATTR
,
694 &Private
->Current
->SessionConfigData
697 BufferSize
= sizeof (Private
->Current
->AuthConfigData
);
699 Private
->Current
->MacString
,
700 &mIScsiCHAPAuthInfoGuid
,
701 ISCSI_CONFIG_VAR_ATTR
,
703 &Private
->Current
->AuthConfigData
705 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
709 if ((QuestionId
>= KEY_DEVICE_ENTRY_BASE
) && (QuestionId
< (mNumberOfIScsiDevices
+ KEY_DEVICE_ENTRY_BASE
))) {
711 // In case goto the device configuration form, update the device form title.
713 ConfigFormEntry
= IScsiGetConfigFormEntryByIndex ((UINT32
) (QuestionId
- KEY_DEVICE_ENTRY_BASE
));
714 ASSERT (ConfigFormEntry
!= NULL
);
716 UnicodeSPrint (PortString
, (UINTN
) 128, L
"Port %s", ConfigFormEntry
->MacString
);
717 DeviceFormTitleToken
= (EFI_STRING_ID
) STR_ISCSI_DEVICE_FORM_TITLE
;
718 HiiSetString (Private
->RegisteredHandle
, DeviceFormTitleToken
, PortString
, NULL
);
720 IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry
, IfrNvData
);
722 Private
->Current
= ConfigFormEntry
;
728 if (!EFI_ERROR (Status
)) {
730 // Pass changed uncommitted data back to Form Browser
732 HiiSetBrowserData (&mVendorGuid
, mVendorStorageName
, sizeof (ISCSI_CONFIG_IFR_NVDATA
), (UINT8
*) IfrNvData
, NULL
);
735 FreePool (IfrNvData
);
740 Updates the iSCSI configuration form to add/delete an entry for the iSCSI
741 device specified by the Controller.
743 @param[in] DriverBindingHandle The driverbinding handle.
744 @param[in] Controller The controller handle of the iSCSI device.
745 @param[in] AddForm Whether to add or delete a form entry.
747 @retval EFI_SUCCESS The iSCSI configuration form is updated.
748 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
749 @retval Others Other errors as indicated.
752 IScsiConfigUpdateForm (
753 IN EFI_HANDLE DriverBindingHandle
,
754 IN EFI_HANDLE Controller
,
759 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
760 BOOLEAN EntryExisted
;
762 EFI_SIMPLE_NETWORK_PROTOCOL
*Snp
;
763 CHAR16 PortString
[128];
766 VOID
*StartOpCodeHandle
;
767 VOID
*EndOpCodeHandle
;
768 EFI_IFR_GUID_LABEL
*StartLabel
;
769 EFI_IFR_GUID_LABEL
*EndLabel
;
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 ConfigFormEntry
->PortTitleToken
= HiiSetString (mCallbackInfo
->RegisteredHandle
, 0, PortString
, NULL
);
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 ConfigFormEntry
->PortTitleHelpToken
= HiiSetString (mCallbackInfo
->RegisteredHandle
, 0, PortString
, NULL
);
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
866 // Init OpCode Handle
868 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
869 ASSERT (StartOpCodeHandle
!= NULL
);
871 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
872 ASSERT (EndOpCodeHandle
!= NULL
);
875 // Create Hii Extend Label OpCode as the start opcode
877 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
878 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
879 StartLabel
->Number
= DEVICE_ENTRY_LABEL
;
882 // Create Hii Extend Label OpCode as the end opcode
884 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
885 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
886 EndLabel
->Number
= LABEL_END
;
889 NET_LIST_FOR_EACH (Entry
, &mIScsiConfigFormList
) {
890 ConfigFormEntry
= NET_LIST_USER_STRUCT (Entry
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
892 HiiCreateGotoOpCode (
893 StartOpCodeHandle
, // Container for dynamic created opcodes
894 FORMID_DEVICE_FORM
, // Target Form ID
895 ConfigFormEntry
->PortTitleToken
, // Prompt text
896 ConfigFormEntry
->PortTitleHelpToken
, // Help text
897 EFI_IFR_FLAG_CALLBACK
, // Question flag
898 (UINT16
)(KEY_DEVICE_ENTRY_BASE
+ FormIndex
) // Question ID
905 mCallbackInfo
->RegisteredHandle
,
908 StartOpCodeHandle
, // Label DEVICE_ENTRY_LABEL
909 EndOpCodeHandle
// LABEL_END
912 HiiFreeOpCodeHandle (StartOpCodeHandle
);
913 HiiFreeOpCodeHandle (EndOpCodeHandle
);
919 Initialize the iSCSI configuration form.
921 @param[in] DriverBindingHandle The iSCSI driverbinding handle.
923 @retval EFI_SUCCESS The iSCSI configuration form is initialized.
924 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
925 @retval Others Other errors as indicated.
928 IScsiConfigFormInit (
933 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
934 ISCSI_FORM_CALLBACK_INFO
*CallbackInfo
;
936 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**)&HiiDatabase
);
937 if (EFI_ERROR (Status
)) {
941 CallbackInfo
= (ISCSI_FORM_CALLBACK_INFO
*) AllocateZeroPool (sizeof (ISCSI_FORM_CALLBACK_INFO
));
942 if (CallbackInfo
== NULL
) {
943 return EFI_OUT_OF_RESOURCES
;
946 CallbackInfo
->Signature
= ISCSI_FORM_CALLBACK_INFO_SIGNATURE
;
947 CallbackInfo
->HiiDatabase
= HiiDatabase
;
948 CallbackInfo
->Current
= NULL
;
950 CallbackInfo
->ConfigAccess
.ExtractConfig
= IScsiFormExtractConfig
;
951 CallbackInfo
->ConfigAccess
.RouteConfig
= IScsiFormRouteConfig
;
952 CallbackInfo
->ConfigAccess
.Callback
= IScsiFormCallback
;
954 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**)&CallbackInfo
->ConfigRouting
);
955 if (EFI_ERROR (Status
)) {
956 FreePool(CallbackInfo
);
961 // Install Device Path Protocol and Config Access protocol to driver handle
963 Status
= gBS
->InstallMultipleProtocolInterfaces (
964 &CallbackInfo
->DriverHandle
,
965 &gEfiDevicePathProtocolGuid
,
966 &mIScsiHiiVendorDevicePath
,
967 &gEfiHiiConfigAccessProtocolGuid
,
968 &CallbackInfo
->ConfigAccess
,
971 ASSERT_EFI_ERROR (Status
);
974 // Publish our HII data
976 CallbackInfo
->RegisteredHandle
= HiiAddPackages (
978 CallbackInfo
->DriverHandle
,
983 if (CallbackInfo
->RegisteredHandle
== NULL
) {
984 FreePool(CallbackInfo
);
985 return EFI_OUT_OF_RESOURCES
;
988 mCallbackInfo
= CallbackInfo
;
994 Unload the iSCSI configuration form, this includes: delete all the iSCSI
995 device configuration entries, uninstall the form callback protocol and
996 free the resources used.
998 @param[in] DriverBindingHandle The iSCSI driverbinding handle.
1000 @retval EFI_SUCCESS The iSCSI configuration form is unloaded.
1001 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1004 IScsiConfigFormUnload (
1005 IN EFI_HANDLE DriverBindingHandle
1008 ISCSI_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
1010 while (!IsListEmpty (&mIScsiConfigFormList
)) {
1012 // Uninstall the device forms as the iSCSI driver instance may fail to
1013 // control the controller but still install the device configuration form.
1014 // In such case, upon driver unloading, the driver instance's driverbinding.
1015 // stop () won't be called, so we have to take this chance here to uninstall
1018 ConfigFormEntry
= NET_LIST_USER_STRUCT (mIScsiConfigFormList
.ForwardLink
, ISCSI_CONFIG_FORM_ENTRY
, Link
);
1019 IScsiConfigUpdateForm (DriverBindingHandle
, ConfigFormEntry
->Controller
, FALSE
);
1023 // Remove HII package list
1025 mCallbackInfo
->HiiDatabase
->RemovePackageList (
1026 mCallbackInfo
->HiiDatabase
,
1027 mCallbackInfo
->RegisteredHandle
1031 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL
1033 gBS
->UninstallMultipleProtocolInterfaces (
1034 mCallbackInfo
->DriverHandle
,
1035 &gEfiDevicePathProtocolGuid
,
1036 &mIScsiHiiVendorDevicePath
,
1037 &gEfiHiiConfigAccessProtocolGuid
,
1038 &mCallbackInfo
->ConfigAccess
,
1041 gBS
->FreePool (mCallbackInfo
);