2 Helper functions for configuring or getting the parameters relating to Ip4.
4 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
5 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.
17 CHAR16 mIp4Config2StorageName
[] = L
"IP4_CONFIG2_IFR_NVDATA";
20 Calculate the prefix length of the IPv4 subnet mask.
22 @param[in] SubnetMask The IPv4 subnet mask.
24 @return The prefix length of the subnet mask.
25 @retval 0 Other errors as indicated.
29 GetSubnetMaskPrefixLength (
30 IN EFI_IPv4_ADDRESS
*SubnetMask
37 // The SubnetMask is in network byte order.
39 ReverseMask
= SwapBytes32 (*(UINT32
*)&SubnetMask
[0]);
44 ReverseMask
= ~ReverseMask
;
46 if ((ReverseMask
& (ReverseMask
+ 1)) != 0) {
52 while (ReverseMask
!= 0) {
53 ReverseMask
= ReverseMask
>> 1;
57 return (UINT8
) (32 - Len
);
61 Convert the decimal dotted IPv4 address into the binary IPv4 address.
63 @param[in] Str The UNICODE string.
64 @param[out] Ip The storage to return the IPv4 address.
66 @retval EFI_SUCCESS The binary IP address is returned in Ip.
67 @retval EFI_INVALID_PARAMETER The IP string is malformatted.
73 OUT EFI_IPv4_ADDRESS
*Ip
81 while (*Str
!= L
'\0') {
84 return EFI_INVALID_PARAMETER
;
88 while ((*Str
>= L
'0') && (*Str
<= L
'9')) {
89 Number
= Number
* 10 + (*Str
- L
'0');
94 return EFI_INVALID_PARAMETER
;
97 Ip
->Addr
[Index
] = (UINT8
) Number
;
99 if ((*Str
!= L
'\0') && (*Str
!= L
'.')) {
101 // The current character should be either the NULL terminator or
102 // the dot delimiter.
104 return EFI_INVALID_PARAMETER
;
109 // Skip the delimiter.
118 return EFI_INVALID_PARAMETER
;
125 Convert the decimal dotted IPv4 addresses separated by space into the binary IPv4 address list.
127 @param[in] Str The UNICODE string contains IPv4 addresses.
128 @param[out] PtrIpList The storage to return the IPv4 address list.
129 @param[out] IpCount The size of the IPv4 address list.
131 @retval EFI_SUCCESS The binary IP address list is returned in PtrIpList.
132 @retval EFI_OUT_OF_RESOURCES Error occurs in allocating memory.
133 @retval EFI_INVALID_PARAMETER The IP string is malformatted.
137 Ip4Config2StrToIpList (
139 OUT EFI_IPv4_ADDRESS
**PtrIpList
,
151 EndIndex
= BeginIndex
;
165 // Get the number of Ip.
167 while (*(Str
+ Index
) != L
'\0') {
168 if (*(Str
+ Index
) == L
' ') {
185 // Allocate buffer for IpList.
187 *PtrIpList
= AllocateZeroPool(*IpCount
* sizeof(EFI_IPv4_ADDRESS
));
188 if (*PtrIpList
== NULL
) {
189 return EFI_OUT_OF_RESOURCES
;
193 // Get IpList from Str.
196 while (*(Str
+ Index
) != L
'\0') {
197 if (*(Str
+ Index
) == L
' ') {
199 StrTemp
= AllocateZeroPool((EndIndex
- BeginIndex
+ 1) * sizeof(CHAR16
));
200 if (StrTemp
== NULL
) {
201 FreePool(*PtrIpList
);
204 return EFI_OUT_OF_RESOURCES
;
207 CopyMem (StrTemp
, Str
+ BeginIndex
, (EndIndex
- BeginIndex
) * sizeof(CHAR16
));
208 *(StrTemp
+ (EndIndex
- BeginIndex
)) = L
'\0';
210 if (Ip4Config2StrToIp (StrTemp
, &((*PtrIpList
)[IpIndex
])) != EFI_SUCCESS
) {
212 FreePool(*PtrIpList
);
215 return EFI_INVALID_PARAMETER
;
218 BeginIndex
= EndIndex
;
234 if (*(Str
+ Index
) == L
'\0') {
236 StrTemp
= AllocateZeroPool((EndIndex
- BeginIndex
+ 1) * sizeof(CHAR16
));
237 if (StrTemp
== NULL
) {
238 FreePool(*PtrIpList
);
241 return EFI_OUT_OF_RESOURCES
;
244 CopyMem (StrTemp
, Str
+ BeginIndex
, (EndIndex
- BeginIndex
) * sizeof(CHAR16
));
245 *(StrTemp
+ (EndIndex
- BeginIndex
)) = L
'\0';
247 if (Ip4Config2StrToIp (StrTemp
, &((*PtrIpList
)[IpIndex
])) != EFI_SUCCESS
) {
249 FreePool(*PtrIpList
);
252 return EFI_INVALID_PARAMETER
;
264 Convert the IPv4 address into a dotted string.
266 @param[in] Ip The IPv4 address.
267 @param[out] Str The dotted IP string.
272 IN EFI_IPv4_ADDRESS
*Ip
,
278 2 * IP4_STR_MAX_SIZE
,
289 Convert the IPv4 address list into string consists of several decimal
290 dotted IPv4 addresses separated by space.
292 @param[in] Ip The IPv4 address list.
293 @param[in] IpCount The size of IPv4 address list.
294 @param[out] Str The string contains several decimal dotted
295 IPv4 addresses separated by space.
297 @retval EFI_SUCCESS Operation is success.
298 @retval EFI_OUT_OF_RESOURCES Error occurs in allocating memory.
302 Ip4Config2IpListToStr (
303 IN EFI_IPv4_ADDRESS
*Ip
,
312 EFI_IPv4_ADDRESS
*TempIp
;
320 for (Index
= 0; Index
< IpCount
; Index
++) {
322 if (TempStr
== NULL
) {
323 TempStr
= AllocateZeroPool(2 * IP4_STR_MAX_SIZE
);
324 if (TempStr
== NULL
) {
325 return EFI_OUT_OF_RESOURCES
;
331 2 * IP4_STR_MAX_SIZE
,
339 for (TemIndex
= 0; TemIndex
< IP4_STR_MAX_SIZE
; TemIndex
++) {
340 if (*(TempStr
+ TemIndex
) == L
'\0') {
341 if (Index
== IpCount
- 1) {
342 Str
[StrIndex
++] = L
'\0';
344 Str
[StrIndex
++] = L
' ';
348 Str
[StrIndex
++] = *(TempStr
+ TemIndex
);
353 if (TempStr
!= NULL
) {
361 The notify function of create event when performing a manual configuration.
363 @param[in] Event The pointer of Event.
364 @param[in] Context The pointer of Context.
369 Ip4Config2ManualAddressNotify (
374 *((BOOLEAN
*) Context
) = TRUE
;
378 Convert the network configuration data into the IFR data.
380 @param[in] Instance The IP4 config2 instance.
381 @param[in, out] IfrNvData The IFR nv data.
383 @retval EFI_SUCCESS The configure parameter to IFR data was
385 @retval EFI_INVALID_PARAMETER Source instance or target IFR data is not available.
386 @retval Others Other errors as indicated.
390 Ip4Config2ConvertConfigNvDataToIfrNvData (
391 IN IP4_CONFIG2_INSTANCE
*Instance
,
392 IN OUT IP4_CONFIG2_IFR_NVDATA
*IfrNvData
396 EFI_IP4_CONFIG2_PROTOCOL
*Ip4Config2
;
397 EFI_IP4_CONFIG2_INTERFACE_INFO
*Ip4Info
;
398 EFI_IP4_CONFIG2_POLICY Policy
;
401 EFI_IPv4_ADDRESS GatewayAddress
;
405 EFI_IPv4_ADDRESS
*DnsAddress
;
407 Status
= EFI_SUCCESS
;
408 Ip4Config2
= &Instance
->Ip4Config2
;
411 GatewaySize
= sizeof (EFI_IPv4_ADDRESS
);
413 if ((IfrNvData
== NULL
) || (Instance
== NULL
)) {
414 return EFI_INVALID_PARAMETER
;
417 NET_CHECK_SIGNATURE (Instance
, IP4_CONFIG2_INSTANCE_SIGNATURE
);
419 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
421 if (IpSb
->DefaultInterface
->Configured
) {
422 IfrNvData
->Configure
= 1;
424 IfrNvData
->Configure
= 0;
429 // Get the Policy info.
431 DataSize
= sizeof (EFI_IP4_CONFIG2_POLICY
);
432 Status
= Ip4Config2
->GetData (
434 Ip4Config2DataTypePolicy
,
438 if (EFI_ERROR (Status
)) {
442 if (Policy
== Ip4Config2PolicyStatic
) {
443 IfrNvData
->DhcpEnable
= FALSE
;
444 } else if (Policy
== Ip4Config2PolicyDhcp
) {
445 IfrNvData
->DhcpEnable
= TRUE
;
450 // Get the interface info.
453 Status
= Ip4Config2
->GetData (
455 Ip4Config2DataTypeInterfaceInfo
,
459 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
463 Ip4Info
= AllocateZeroPool (DataSize
);
464 if (Ip4Info
== NULL
) {
465 Status
= EFI_OUT_OF_RESOURCES
;
469 Status
= Ip4Config2
->GetData (
471 Ip4Config2DataTypeInterfaceInfo
,
475 if (EFI_ERROR (Status
)) {
480 // Get the Gateway info.
482 Status
= Ip4Config2
->GetData (
484 Ip4Config2DataTypeGateway
,
488 if (EFI_ERROR (Status
)) {
496 Status
= Ip4Config2
->GetData (
498 Ip4Config2DataTypeDnsServer
,
502 if ((Status
!= EFI_BUFFER_TOO_SMALL
) && (Status
!= EFI_NOT_FOUND
)) {
506 DnsCount
= (UINT32
) (DnsSize
/ sizeof (EFI_IPv4_ADDRESS
));
509 DnsAddress
= AllocateZeroPool(DnsSize
);
510 if (DnsAddress
== NULL
) {
511 Status
= EFI_OUT_OF_RESOURCES
;
515 Status
= Ip4Config2
->GetData (
517 Ip4Config2DataTypeDnsServer
,
521 if (EFI_ERROR (Status
)) {
526 Ip4Config2IpToStr (&Ip4Info
->StationAddress
, IfrNvData
->StationAddress
);
527 Ip4Config2IpToStr (&Ip4Info
->SubnetMask
, IfrNvData
->SubnetMask
);
528 Ip4Config2IpToStr (&GatewayAddress
, IfrNvData
->GatewayAddress
);
529 Status
= Ip4Config2IpListToStr (DnsAddress
, DnsCount
, IfrNvData
->DnsAddress
);
533 if (DnsAddress
!= NULL
) {
534 FreePool(DnsAddress
);
537 if (Ip4Info
!= NULL
) {
545 Convert the IFR data into the network configuration data and set the IP
546 configure parameters for the NIC.
548 @param[in] IfrFormNvData The IFR NV data.
549 @param[in, out] Instance The IP4 config2 instance.
551 @retval EFI_SUCCESS The configure parameter for this NIC was
553 @retval EFI_INVALID_PARAMETER The address information for setting is invalid.
554 @retval Others Other errors as indicated.
558 Ip4Config2ConvertIfrNvDataToConfigNvData (
559 IN IP4_CONFIG2_IFR_NVDATA
*IfrFormNvData
,
560 IN OUT IP4_CONFIG2_INSTANCE
*Instance
564 EFI_IP4_CONFIG2_PROTOCOL
*Ip4Cfg2
;
565 IP4_CONFIG2_NVDATA
*Ip4NvData
;
567 EFI_IP_ADDRESS StationAddress
;
568 EFI_IP_ADDRESS SubnetMask
;
569 EFI_IP_ADDRESS Gateway
;
571 EFI_IPv4_ADDRESS
*DnsAddress
;
575 EFI_EVENT TimeoutEvent
;
576 EFI_EVENT SetAddressEvent
;
581 Status
= EFI_SUCCESS
;
582 Ip4Cfg2
= &Instance
->Ip4Config2
;
583 Ip4NvData
= &Instance
->Ip4NvData
;
589 SetAddressEvent
= NULL
;
593 if (Instance
== NULL
|| IfrFormNvData
== NULL
) {
594 return EFI_INVALID_PARAMETER
;
597 if (IfrFormNvData
->Configure
!= TRUE
) {
601 if (IfrFormNvData
->DhcpEnable
== TRUE
) {
602 Ip4NvData
->Policy
= Ip4Config2PolicyDhcp
;
604 Status
= Ip4Cfg2
->SetData (
606 Ip4Config2DataTypePolicy
,
607 sizeof (EFI_IP4_CONFIG2_POLICY
),
610 if (EFI_ERROR(Status
)) {
615 // Get Ip4NvData from IfrFormNvData if it is valid.
617 Ip4NvData
->Policy
= Ip4Config2PolicyStatic
;
619 Status
= Ip4Config2StrToIp (IfrFormNvData
->SubnetMask
, &SubnetMask
.v4
);
620 if (EFI_ERROR (Status
) || ((SubnetMask
.Addr
[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask
.v4
) == 0))) {
621 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Subnet Mask!", NULL
);
622 return EFI_INVALID_PARAMETER
;
625 Status
= Ip4Config2StrToIp (IfrFormNvData
->StationAddress
, &StationAddress
.v4
);
626 if (EFI_ERROR (Status
) ||
627 (SubnetMask
.Addr
[0] != 0 && !NetIp4IsUnicast (NTOHL (StationAddress
.Addr
[0]), NTOHL (SubnetMask
.Addr
[0]))) ||
628 !Ip4StationAddressValid (NTOHL (StationAddress
.Addr
[0]), NTOHL (SubnetMask
.Addr
[0]))) {
629 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid IP address!", NULL
);
630 return EFI_INVALID_PARAMETER
;
633 Status
= Ip4Config2StrToIp (IfrFormNvData
->GatewayAddress
, &Gateway
.v4
);
634 if (EFI_ERROR (Status
) ||
635 (Gateway
.Addr
[0] != 0 && SubnetMask
.Addr
[0] != 0 && !NetIp4IsUnicast (NTOHL (Gateway
.Addr
[0]), NTOHL (SubnetMask
.Addr
[0])))) {
636 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Gateway!", NULL
);
637 return EFI_INVALID_PARAMETER
;
640 Status
= Ip4Config2StrToIpList (IfrFormNvData
->DnsAddress
, &DnsAddress
, &DnsCount
);
641 if (!EFI_ERROR (Status
) && DnsCount
> 0) {
642 for (Index
= 0; Index
< DnsCount
; Index
++) {
643 CopyMem (&Ip
, &DnsAddress
[Index
], sizeof (IP4_ADDR
));
644 if (IP4_IS_UNSPECIFIED (NTOHL (Ip
)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip
))) {
645 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Dns Server!", NULL
);
646 FreePool(DnsAddress
);
647 return EFI_INVALID_PARAMETER
;
651 if (EFI_ERROR (Status
)) {
652 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Dns Server!", NULL
);
656 if (Ip4NvData
->ManualAddress
!= NULL
) {
657 FreePool(Ip4NvData
->ManualAddress
);
659 Ip4NvData
->ManualAddressCount
= 1;
660 Ip4NvData
->ManualAddress
= AllocateZeroPool(sizeof(EFI_IP4_CONFIG2_MANUAL_ADDRESS
));
661 if (Ip4NvData
->ManualAddress
== NULL
) {
662 if (DnsAddress
!= NULL
) {
663 FreePool(DnsAddress
);
666 return EFI_OUT_OF_RESOURCES
;
668 CopyMem(&Ip4NvData
->ManualAddress
->Address
, &StationAddress
.v4
, sizeof(EFI_IPv4_ADDRESS
));
669 CopyMem(&Ip4NvData
->ManualAddress
->SubnetMask
, &SubnetMask
.v4
, sizeof(EFI_IPv4_ADDRESS
));
671 if (Ip4NvData
->GatewayAddress
!= NULL
) {
672 FreePool(Ip4NvData
->GatewayAddress
);
674 Ip4NvData
->GatewayAddressCount
= 1;
675 Ip4NvData
->GatewayAddress
= AllocateZeroPool(sizeof(EFI_IPv4_ADDRESS
));
676 if (Ip4NvData
->GatewayAddress
== NULL
) {
677 if (DnsAddress
!= NULL
) {
678 FreePool(DnsAddress
);
680 return EFI_OUT_OF_RESOURCES
;
682 CopyMem(Ip4NvData
->GatewayAddress
, &Gateway
.v4
, sizeof(EFI_IPv4_ADDRESS
));
684 if (Ip4NvData
->DnsAddress
!= NULL
) {
685 FreePool(Ip4NvData
->DnsAddress
);
687 Ip4NvData
->DnsAddressCount
= (UINT32
) DnsCount
;
688 Ip4NvData
->DnsAddress
= DnsAddress
;
691 // Setting Ip4NvData.
693 Status
= Ip4Cfg2
->SetData (
695 Ip4Config2DataTypePolicy
,
696 sizeof (EFI_IP4_CONFIG2_POLICY
),
699 if (EFI_ERROR(Status
)) {
704 // Create events & timers for asynchronous settings.
706 Status
= gBS
->CreateEvent (
713 if (EFI_ERROR (Status
)) {
714 return EFI_OUT_OF_RESOURCES
;
717 Status
= gBS
->CreateEvent (
720 Ip4Config2ManualAddressNotify
,
724 if (EFI_ERROR (Status
)) {
730 Status
= Ip4Cfg2
->RegisterDataNotify (
732 Ip4Config2DataTypeManualAddress
,
735 if (EFI_ERROR (Status
)) {
740 // Set ManualAddress.
742 DataSize
= Ip4NvData
->ManualAddressCount
* sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS
);
743 Status
= Ip4Cfg2
->SetData (
745 Ip4Config2DataTypeManualAddress
,
747 (VOID
*) Ip4NvData
->ManualAddress
750 if (Status
== EFI_NOT_READY
) {
751 gBS
->SetTimer (TimeoutEvent
, TimerRelative
, 50000000);
752 while (EFI_ERROR (gBS
->CheckEvent (TimeoutEvent
))) {
754 Status
= EFI_SUCCESS
;
760 Ip4Cfg2
->UnregisterDataNotify (
762 Ip4Config2DataTypeManualAddress
,
765 if (EFI_ERROR (Status
)) {
772 DataSize
= Ip4NvData
->GatewayAddressCount
* sizeof (EFI_IPv4_ADDRESS
);
773 Status
= Ip4Cfg2
->SetData (
775 Ip4Config2DataTypeGateway
,
777 Ip4NvData
->GatewayAddress
779 if (EFI_ERROR (Status
)) {
784 // Set DNS addresses.
786 if (Ip4NvData
->DnsAddressCount
> 0 && Ip4NvData
->DnsAddress
!= NULL
) {
787 DataSize
= Ip4NvData
->DnsAddressCount
* sizeof (EFI_IPv4_ADDRESS
);
788 Status
= Ip4Cfg2
->SetData (
790 Ip4Config2DataTypeDnsServer
,
792 Ip4NvData
->DnsAddress
795 if (EFI_ERROR (Status
)) {
802 if (SetAddressEvent
!= NULL
) {
803 gBS
->CloseEvent (SetAddressEvent
);
806 if (TimeoutEvent
!= NULL
) {
807 gBS
->CloseEvent (TimeoutEvent
);
814 This function allows the caller to request the current
815 configuration for one or more named elements. The resulting
816 string is in <ConfigAltResp> format. Any and all alternative
817 configuration strings shall also be appended to the end of the
818 current configuration string. If they are, they must appear
819 after the current configuration. They must contain the same
820 routing (GUID, NAME, PATH) as the current configuration string.
821 They must have an additional description indicating the type of
822 alternative configuration the string represents,
823 "ALTCFG=<StringToken>". That <StringToken> (when
824 converted from Hex UNICODE to binary) is a reference to a
825 string in the associated string pack.
827 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
828 @param[in] Request A null-terminated Unicode string in
829 <ConfigRequest> format. Note that this
830 includes the routing information as well as
831 the configurable name / value pairs. It is
832 invalid for this string to be in
833 <MultiConfigRequest> format.
834 @param[out] Progress On return, points to a character in the
835 Request string. Points to the string's null
836 terminator if request was successful. Points
837 to the most recent "&" before the first
838 failing name / value pair (or the beginning
839 of the string if the failure is in the first
840 name / value pair) if the request was not
842 @param[out] Results A null-terminated Unicode string in
843 <ConfigAltResp> format which has all values
844 filled in for the names in the Request string.
845 String to be allocated by the called function.
847 @retval EFI_SUCCESS The Results string is filled with the
848 values corresponding to all requested
850 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
851 parts of the results that must be
852 stored awaiting possible future
854 @retval EFI_NOT_FOUND Routing data doesn't match any
855 known driver. Progress set to the
856 first character in the routing header.
857 Note: There is no requirement that the
858 driver validate the routing data. It
859 must skip the <ConfigHdr> in order to
861 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
862 to most recent & before the
863 error or the beginning of the
865 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
866 to the & before the name in
867 question.Currently not implemented.
871 Ip4FormExtractConfig (
872 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
873 IN CONST EFI_STRING Request
,
874 OUT EFI_STRING
*Progress
,
875 OUT EFI_STRING
*Results
879 IP4_CONFIG2_INSTANCE
*Ip4Config2Instance
;
880 IP4_FORM_CALLBACK_INFO
*Private
;
881 IP4_CONFIG2_IFR_NVDATA
*IfrFormNvData
;
882 EFI_STRING ConfigRequestHdr
;
883 EFI_STRING ConfigRequest
;
884 BOOLEAN AllocatedRequest
;
885 EFI_STRING FormResult
;
889 if (Progress
== NULL
|| Results
== NULL
) {
890 return EFI_INVALID_PARAMETER
;
893 Status
= EFI_SUCCESS
;
894 IfrFormNvData
= NULL
;
895 ConfigRequest
= NULL
;
898 AllocatedRequest
= FALSE
;
899 ConfigRequest
= Request
;
900 Private
= IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(This
);
901 Ip4Config2Instance
= IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Private
);
902 BufferSize
= sizeof (IP4_CONFIG2_IFR_NVDATA
);
906 // Check Request data in <ConfigHdr>.
908 if ((Request
== NULL
) || HiiIsConfigHdrMatch (Request
, &gIp4Config2NvDataGuid
, mIp4Config2StorageName
)) {
909 IfrFormNvData
= AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA
));
910 if (IfrFormNvData
== NULL
) {
911 return EFI_OUT_OF_RESOURCES
;
914 Ip4Config2ConvertConfigNvDataToIfrNvData (Ip4Config2Instance
, IfrFormNvData
);
916 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
918 // Request has no request element, construct full request string.
919 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
920 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
922 ConfigRequestHdr
= HiiConstructConfigHdr (&gIp4Config2NvDataGuid
, mIp4Config2StorageName
, Private
->ChildHandle
);
923 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
924 ConfigRequest
= AllocateZeroPool (Size
);
925 if (ConfigRequest
== NULL
) {
926 Status
= EFI_OUT_OF_RESOURCES
;
929 AllocatedRequest
= TRUE
;
931 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
932 FreePool (ConfigRequestHdr
);
936 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
938 Status
= gHiiConfigRouting
->BlockToConfig (
941 (UINT8
*) IfrFormNvData
,
947 FreePool (IfrFormNvData
);
950 // Free the allocated config request string.
952 if (AllocatedRequest
) {
953 FreePool (ConfigRequest
);
954 ConfigRequest
= NULL
;
957 if (EFI_ERROR (Status
)) {
962 if (Request
== NULL
|| HiiIsConfigHdrMatch (Request
, &gIp4Config2NvDataGuid
, mIp4Config2StorageName
)) {
963 *Results
= FormResult
;
965 return EFI_NOT_FOUND
;
970 // Set Progress string to the original request string.
972 if (Request
== NULL
) {
974 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
975 *Progress
= Request
+ StrLen (Request
);
982 This function applies changes in a driver's configuration.
983 Input is a Configuration, which has the routing data for this
984 driver followed by name / value configuration pairs. The driver
985 must apply those pairs to its configurable storage. If the
986 driver's configuration is stored in a linear block of data
987 and the driver's name / value pairs are in <BlockConfig>
988 format, it may use the ConfigToBlock helper function (above) to
989 simplify the job. Currently not implemented.
991 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
992 @param[in] Configuration A null-terminated Unicode string in
993 <ConfigString> format.
994 @param[out] Progress A pointer to a string filled in with the
995 offset of the most recent '&' before the
996 first failing name / value pair (or the
997 beginn ing of the string if the failure
998 is in the first name / value pair) or
999 the terminating NULL if all was
1002 @retval EFI_SUCCESS The results have been distributed or are
1003 awaiting distribution.
1004 @retval EFI_OUT_OF_MEMORY Not enough memory to store the
1005 parts of the results that must be
1006 stored awaiting possible future
1008 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
1009 Results parameter would result
1010 in this type of error.
1011 @retval EFI_NOT_FOUND Target for the specified routing data
1016 Ip4FormRouteConfig (
1017 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1018 IN CONST EFI_STRING Configuration
,
1019 OUT EFI_STRING
*Progress
1024 IP4_CONFIG2_IFR_NVDATA
*IfrFormNvData
;
1025 IP4_CONFIG2_INSTANCE
*Ip4Config2Instance
;
1026 IP4_FORM_CALLBACK_INFO
*Private
;
1028 Status
= EFI_SUCCESS
;
1029 IfrFormNvData
= NULL
;
1031 if (Configuration
== NULL
|| Progress
== NULL
) {
1032 return EFI_INVALID_PARAMETER
;
1035 *Progress
= Configuration
;
1037 Private
= IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(This
);
1038 Ip4Config2Instance
= IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Private
);
1041 // Check Routing data in <ConfigHdr>.
1043 if (HiiIsConfigHdrMatch (Configuration
, &gIp4Config2NvDataGuid
, mIp4Config2StorageName
)) {
1045 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
1047 IfrFormNvData
= AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA
));
1048 if (IfrFormNvData
== NULL
) {
1049 return EFI_OUT_OF_RESOURCES
;
1054 Status
= gHiiConfigRouting
->ConfigToBlock (
1057 (UINT8
*) IfrFormNvData
,
1061 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1065 Status
= gHiiConfigRouting
->ConfigToBlock (
1068 (UINT8
*) IfrFormNvData
,
1072 if (!EFI_ERROR (Status
)) {
1073 Status
= Ip4Config2ConvertIfrNvDataToConfigNvData (IfrFormNvData
, Ip4Config2Instance
);
1076 FreePool (IfrFormNvData
);
1078 return EFI_NOT_FOUND
;
1086 This function is called to provide results data to the driver.
1087 This data consists of a unique key that is used to identify
1088 which data is either being passed back or being asked for.
1090 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
1091 @param[in] Action Specifies the type of action taken by the browser.
1092 @param[in] QuestionId A unique value which is sent to the original
1093 exporting driver so that it can identify the type
1094 of data to expect. The format of the data tends to
1095 vary based on the opcode that enerated the callback.
1096 @param[in] Type The type of value for the question.
1097 @param[in] Value A pointer to the data being sent to the original
1099 @param[out] ActionRequest On return, points to the action requested by the
1102 @retval EFI_SUCCESS The callback successfully handled the action.
1103 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
1104 variable and its data.
1105 @retval EFI_DEVICE_ERROR The variable could not be saved.
1106 @retval EFI_UNSUPPORTED The specified Action is not supported by the
1107 callback.Currently not implemented.
1108 @retval EFI_INVALID_PARAMETERS Passing in wrong parameter.
1109 @retval Others Other errors as indicated.
1115 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
1116 IN EFI_BROWSER_ACTION Action
,
1117 IN EFI_QUESTION_ID QuestionId
,
1119 IN EFI_IFR_TYPE_VALUE
*Value
,
1120 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
1124 IP4_CONFIG2_INSTANCE
*Instance
;
1125 IP4_CONFIG2_IFR_NVDATA
*IfrFormNvData
;
1126 IP4_FORM_CALLBACK_INFO
*Private
;
1128 EFI_IP_ADDRESS StationAddress
;
1129 EFI_IP_ADDRESS SubnetMask
;
1130 EFI_IP_ADDRESS Gateway
;
1132 EFI_IPv4_ADDRESS
*DnsAddress
;
1137 IfrFormNvData
= NULL
;
1141 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
1142 Private
= IP4_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS(This
);
1143 Instance
= IP4_CONFIG2_INSTANCE_FROM_FORM_CALLBACK(Private
);
1145 IfrFormNvData
= AllocateZeroPool (sizeof (IP4_CONFIG2_IFR_NVDATA
));
1146 if (IfrFormNvData
== NULL
) {
1147 return EFI_OUT_OF_RESOURCES
;
1151 // Retrieve uncommitted data from Browser
1153 if (!HiiGetBrowserData (&gIp4Config2NvDataGuid
, mIp4Config2StorageName
, sizeof (IP4_CONFIG2_IFR_NVDATA
), (UINT8
*) IfrFormNvData
)) {
1154 FreePool (IfrFormNvData
);
1155 return EFI_NOT_FOUND
;
1158 Status
= EFI_SUCCESS
;
1160 switch (QuestionId
) {
1162 Status
= Ip4Config2StrToIp (IfrFormNvData
->StationAddress
, &StationAddress
.v4
);
1163 if (EFI_ERROR (Status
) || IP4_IS_UNSPECIFIED (NTOHL (StationAddress
.Addr
[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (StationAddress
.Addr
[0]))) {
1164 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid IP address!", NULL
);
1165 Status
= EFI_INVALID_PARAMETER
;
1169 case KEY_SUBNET_MASK
:
1170 Status
= Ip4Config2StrToIp (IfrFormNvData
->SubnetMask
, &SubnetMask
.v4
);
1171 if (EFI_ERROR (Status
) || ((SubnetMask
.Addr
[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask
.v4
) == 0))) {
1172 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Subnet Mask!", NULL
);
1173 Status
= EFI_INVALID_PARAMETER
;
1178 Status
= Ip4Config2StrToIp (IfrFormNvData
->GatewayAddress
, &Gateway
.v4
);
1179 if (EFI_ERROR (Status
) || IP4_IS_LOCAL_BROADCAST(NTOHL(Gateway
.Addr
[0]))) {
1180 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Gateway!", NULL
);
1181 Status
= EFI_INVALID_PARAMETER
;
1186 Status
= Ip4Config2StrToIpList (IfrFormNvData
->DnsAddress
, &DnsAddress
, &DnsCount
);
1187 if (!EFI_ERROR (Status
) && DnsCount
> 0) {
1188 for (Index
= 0; Index
< DnsCount
; Index
++) {
1189 CopyMem (&Ip
, &DnsAddress
[Index
], sizeof (IP4_ADDR
));
1190 if (IP4_IS_UNSPECIFIED (NTOHL (Ip
)) || IP4_IS_LOCAL_BROADCAST (NTOHL (Ip
))) {
1191 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Dns Server!", NULL
);
1192 Status
= EFI_INVALID_PARAMETER
;
1197 if (EFI_ERROR (Status
)) {
1198 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Dns Server!", NULL
);
1202 if(DnsAddress
!= NULL
) {
1203 FreePool(DnsAddress
);
1207 case KEY_SAVE_CHANGES
:
1208 Status
= Ip4Config2ConvertIfrNvDataToConfigNvData (IfrFormNvData
, Instance
);
1209 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
1216 FreePool (IfrFormNvData
);
1222 // All other action return unsupported.
1224 return EFI_UNSUPPORTED
;
1228 Install HII Config Access protocol for network device and allocate resource.
1230 @param[in, out] Instance The IP4 config2 Instance.
1232 @retval EFI_SUCCESS The HII Config Access protocol is installed.
1233 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
1234 @retval Others Other errors as indicated.
1238 Ip4Config2FormInit (
1239 IN OUT IP4_CONFIG2_INSTANCE
*Instance
1244 IP4_FORM_CALLBACK_INFO
*CallbackInfo
;
1245 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
1246 VENDOR_DEVICE_PATH VendorDeviceNode
;
1247 EFI_SERVICE_BINDING_PROTOCOL
*MnpSb
;
1249 CHAR16 MenuString
[128];
1250 CHAR16 PortString
[128];
1251 CHAR16
*OldMenuString
;
1252 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
1254 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
1255 ASSERT (IpSb
!= NULL
);
1257 CallbackInfo
= &Instance
->CallbackInfo
;
1259 CallbackInfo
->Signature
= IP4_FORM_CALLBACK_INFO_SIGNATURE
;
1261 Status
= gBS
->HandleProtocol (
1263 &gEfiDevicePathProtocolGuid
,
1264 (VOID
**) &ParentDevicePath
1266 if (EFI_ERROR (Status
)) {
1271 // Construct device path node for EFI HII Config Access protocol,
1272 // which consists of controller physical device path and one hardware
1273 // vendor guid node.
1275 ZeroMem (&VendorDeviceNode
, sizeof (VENDOR_DEVICE_PATH
));
1276 VendorDeviceNode
.Header
.Type
= HARDWARE_DEVICE_PATH
;
1277 VendorDeviceNode
.Header
.SubType
= HW_VENDOR_DP
;
1279 CopyGuid (&VendorDeviceNode
.Guid
, &gEfiCallerIdGuid
);
1281 SetDevicePathNodeLength (&VendorDeviceNode
.Header
, sizeof (VENDOR_DEVICE_PATH
));
1282 CallbackInfo
->HiiVendorDevicePath
= AppendDevicePathNode (
1284 (EFI_DEVICE_PATH_PROTOCOL
*) &VendorDeviceNode
1286 if (CallbackInfo
->HiiVendorDevicePath
== NULL
) {
1287 Status
= EFI_OUT_OF_RESOURCES
;
1291 ConfigAccess
= &CallbackInfo
->HiiConfigAccessProtocol
;
1292 ConfigAccess
->ExtractConfig
= Ip4FormExtractConfig
;
1293 ConfigAccess
->RouteConfig
= Ip4FormRouteConfig
;
1294 ConfigAccess
->Callback
= Ip4FormCallback
;
1297 // Install Device Path Protocol and Config Access protocol on new handle
1299 Status
= gBS
->InstallMultipleProtocolInterfaces (
1300 &CallbackInfo
->ChildHandle
,
1301 &gEfiDevicePathProtocolGuid
,
1302 CallbackInfo
->HiiVendorDevicePath
,
1303 &gEfiHiiConfigAccessProtocolGuid
,
1308 if (!EFI_ERROR (Status
)) {
1310 // Open the Parent Handle for the child
1312 Status
= gBS
->OpenProtocol (
1314 &gEfiManagedNetworkServiceBindingProtocolGuid
,
1317 CallbackInfo
->ChildHandle
,
1318 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1322 if (EFI_ERROR (Status
)) {
1327 // Publish our HII data
1329 CallbackInfo
->RegisteredHandle
= HiiAddPackages (
1330 &gIp4Config2NvDataGuid
,
1331 CallbackInfo
->ChildHandle
,
1336 if (CallbackInfo
->RegisteredHandle
== NULL
) {
1337 Status
= EFI_OUT_OF_RESOURCES
;
1342 // Append MAC string in the menu help string and tile help string
1344 Status
= NetLibGetMacString (IpSb
->Controller
, IpSb
->Image
, &MacString
);
1345 if (!EFI_ERROR (Status
)) {
1346 OldMenuString
= HiiGetString (
1347 CallbackInfo
->RegisteredHandle
,
1348 STRING_TOKEN (STR_IP4_CONFIG2_FORM_HELP
),
1351 UnicodeSPrint (MenuString
, 128, L
"%s (MAC:%s)", OldMenuString
, MacString
);
1353 CallbackInfo
->RegisteredHandle
,
1354 STRING_TOKEN (STR_IP4_CONFIG2_FORM_HELP
),
1359 UnicodeSPrint (PortString
, 128, L
"MAC:%s", MacString
);
1361 CallbackInfo
->RegisteredHandle
,
1362 STRING_TOKEN (STR_IP4_DEVICE_FORM_HELP
),
1367 FreePool (MacString
);
1368 FreePool (OldMenuString
);
1374 Ip4Config2FormUnload (Instance
);
1379 Uninstall the HII Config Access protocol for network devices and free up the resources.
1381 @param[in, out] Instance The IP4 config2 instance to unload a form.
1385 Ip4Config2FormUnload (
1386 IN OUT IP4_CONFIG2_INSTANCE
*Instance
1390 IP4_FORM_CALLBACK_INFO
*CallbackInfo
;
1391 IP4_CONFIG2_NVDATA
*Ip4NvData
;
1393 IpSb
= IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance
);
1394 ASSERT (IpSb
!= NULL
);
1396 CallbackInfo
= &Instance
->CallbackInfo
;
1398 if (CallbackInfo
->ChildHandle
!= NULL
) {
1400 // Close the child handle
1402 gBS
->CloseProtocol (
1404 &gEfiManagedNetworkServiceBindingProtocolGuid
,
1406 CallbackInfo
->ChildHandle
1410 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL
1412 gBS
->UninstallMultipleProtocolInterfaces (
1413 CallbackInfo
->ChildHandle
,
1414 &gEfiDevicePathProtocolGuid
,
1415 CallbackInfo
->HiiVendorDevicePath
,
1416 &gEfiHiiConfigAccessProtocolGuid
,
1417 &CallbackInfo
->HiiConfigAccessProtocol
,
1422 if (CallbackInfo
->HiiVendorDevicePath
!= NULL
) {
1423 FreePool (CallbackInfo
->HiiVendorDevicePath
);
1426 if (CallbackInfo
->RegisteredHandle
!= NULL
) {
1428 // Remove HII package list
1430 HiiRemovePackages (CallbackInfo
->RegisteredHandle
);
1433 Ip4NvData
= &Instance
->Ip4NvData
;
1435 if(Ip4NvData
->ManualAddress
!= NULL
) {
1436 FreePool(Ip4NvData
->ManualAddress
);
1439 if(Ip4NvData
->GatewayAddress
!= NULL
) {
1440 FreePool(Ip4NvData
->GatewayAddress
);
1443 if(Ip4NvData
->DnsAddress
!= NULL
) {
1444 FreePool(Ip4NvData
->DnsAddress
);
1447 Ip4NvData
->ManualAddressCount
= 0;
1448 Ip4NvData
->GatewayAddressCount
= 0;
1449 Ip4NvData
->DnsAddressCount
= 0;