2 Helper functions for configuring or getting the parameters relating to Ip4.
4 Copyright (c) 2009 - 2010, 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 "Ip4ConfigNv.h"
17 EFI_GUID mNicIp4ConfigNvDataGuid
= EFI_NIC_IP4_CONFIG_NVDATA_GUID
;
21 Calculate the prefix length of the IPv4 subnet mask.
23 @param[in] SubnetMask The IPv4 subnet mask.
25 @return The prefix length of the subnet mask.
26 @retval 0 Other errors as indicated.
29 GetSubnetMaskPrefixLength (
30 IN EFI_IPv4_ADDRESS
*SubnetMask
37 // The SubnetMask is in network byte order.
39 ReverseMask
= (SubnetMask
->Addr
[0] << 24) | (SubnetMask
->Addr
[1] << 16) | (SubnetMask
->Addr
[2] << 8) | (SubnetMask
->Addr
[3]);
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 ASCII string.
66 @retval EFI_SUCCESS The binary IP address is returned in Ip.
67 @retval EFI_INVALID_PARAMETER The IP string is malformatted.
72 OUT EFI_IPv4_ADDRESS
*Ip
83 return EFI_INVALID_PARAMETER
;
87 while (NET_IS_DIGIT (*Str
)) {
88 Number
= Number
* 10 + (*Str
- '0');
93 return EFI_INVALID_PARAMETER
;
96 Ip
->Addr
[Index
] = (UINT8
) Number
;
98 if ((*Str
!= '\0') && (*Str
!= '.')) {
100 // The current character should be either the NULL terminator or
101 // the dot delimiter.
103 return EFI_INVALID_PARAMETER
;
108 // Skip the delimiter.
117 return EFI_INVALID_PARAMETER
;
124 Convert the IPv4 address into a dotted string.
126 @param[in] Ip The IPv4 address.
127 @param[out] Str The dotted IP string.
131 IN EFI_IPv4_ADDRESS
*Ip
,
135 UnicodeSPrint (Str
, 2 * IP4_STR_MAX_SIZE
, L
"%d.%d.%d.%d", Ip
->Addr
[0], Ip
->Addr
[1], Ip
->Addr
[2], Ip
->Addr
[3]);
140 Convert the network configuration data into the IFR data.
142 @param[in] Ip4ConfigInstance The IP4Config instance
143 @param[out] IfrFormNvData The IFR nv data.
146 Ip4ConfigConvertDeviceConfigDataToIfrNvData (
147 IN IP4_CONFIG_INSTANCE
*Ip4ConfigInstance
,
148 OUT IP4_CONFIG_IFR_NVDATA
*IfrFormNvData
152 NIC_IP4_CONFIG_INFO
*NicConfig
;
155 ConfigLen
= sizeof (NIC_IP4_CONFIG_INFO
) + sizeof (EFI_IP4_ROUTE_TABLE
) * 2;
156 NicConfig
= AllocateZeroPool (ConfigLen
);
157 ASSERT (NicConfig
!= NULL
);
158 Status
= EfiNicIp4ConfigGetInfo (Ip4ConfigInstance
, &ConfigLen
, NicConfig
);
159 if (!EFI_ERROR (Status
)) {
160 IfrFormNvData
->Configure
= 1;
161 if (NicConfig
->Source
== IP4_CONFIG_SOURCE_DHCP
) {
162 IfrFormNvData
->DhcpEnable
= 1;
164 IfrFormNvData
->DhcpEnable
= 0;
165 Ip4ConfigIpToStr (&NicConfig
->Ip4Info
.StationAddress
, IfrFormNvData
->StationAddress
);
166 Ip4ConfigIpToStr (&NicConfig
->Ip4Info
.SubnetMask
, IfrFormNvData
->SubnetMask
);
167 Ip4ConfigIpToStr (&NicConfig
->Ip4Info
.RouteTable
[1].GatewayAddress
, IfrFormNvData
->GatewayAddress
);
170 IfrFormNvData
->Configure
= 0;
173 FreePool (NicConfig
);
177 Convert the IFR data into the network configuration data and set the IP
178 configure parameters for the NIC.
180 @param[in, out] Ip4ConfigInstance The IP4Config instance.
182 @retval EFI_SUCCESS The configure parameter for this NIC was
184 @retval EFI_ALREADY_STARTED There is a pending auto configuration.
185 @retval EFI_NOT_FOUND No auto configure parameter is found.
189 Ip4ConfigConvertIfrNvDataToDeviceConfigData (
190 IN OUT IP4_CONFIG_INSTANCE
*Ip4ConfigInstance
194 EFI_IP_ADDRESS HostIp
;
195 EFI_IP_ADDRESS SubnetMask
;
196 EFI_IP_ADDRESS Gateway
;
198 NIC_IP4_CONFIG_INFO
*NicInfo
;
201 if (!Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.Configured
) {
203 // Clear the variable
205 ZeroMem (&Ip4ConfigInstance
->Ip4ConfigCallbackInfo
, sizeof (IP4_SETTING_INFO
));
207 Status
= EfiNicIp4ConfigSetInfo (Ip4ConfigInstance
, NULL
, TRUE
);
208 if (Status
== EFI_NOT_FOUND
) {
215 NicInfo
= AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO
) + 2 * sizeof (EFI_IP4_ROUTE_TABLE
));
216 ASSERT (NicInfo
!= NULL
);
218 NicInfo
->Ip4Info
.RouteTable
= (EFI_IP4_ROUTE_TABLE
*) (NicInfo
+ 1);
220 if (!Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.DhcpEnabled
) {
221 CopyMem (&HostIp
.v4
, &Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.LocalIp
, sizeof (HostIp
.v4
));
222 CopyMem (&SubnetMask
.v4
, &Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.SubnetMask
, sizeof (SubnetMask
.v4
));
223 CopyMem (&Gateway
.v4
, &Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.Gateway
, sizeof (Gateway
.v4
));
225 if (!NetIp4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
226 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid IP address!", NULL
);
227 return EFI_INVALID_PARAMETER
;
229 if (EFI_IP4_EQUAL (&SubnetMask
, &mZeroIp4Addr
)) {
230 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Subnet Mask!", NULL
);
231 return EFI_INVALID_PARAMETER
;
234 if ((Gateway
.Addr
[0] != 0)) {
235 if (SubnetMask
.Addr
[0] == 0) {
236 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Gateway address is set but subnet mask is zero.", NULL
);
237 return EFI_INVALID_PARAMETER
;
239 } else if (!IP4_NET_EQUAL (HostIp
.Addr
[0], Gateway
.Addr
[0], SubnetMask
.Addr
[0])) {
240 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Local IP and Gateway are not in the same subnet.", NULL
);
241 return EFI_INVALID_PARAMETER
; }
244 NicInfo
->Source
= IP4_CONFIG_SOURCE_STATIC
;
245 NicInfo
->Ip4Info
.RouteTableSize
= 2;
247 CopyMem (&NicInfo
->Ip4Info
.StationAddress
, &HostIp
.v4
, sizeof (EFI_IPv4_ADDRESS
));
248 CopyMem (&NicInfo
->Ip4Info
.SubnetMask
, &SubnetMask
.v4
, sizeof (EFI_IPv4_ADDRESS
));
250 Ip
.Addr
[0] = HostIp
.Addr
[0] & SubnetMask
.Addr
[0];
252 CopyMem (&NicInfo
->Ip4Info
.RouteTable
[0].SubnetAddress
, &Ip
.v4
, sizeof (EFI_IPv4_ADDRESS
));
253 CopyMem (&NicInfo
->Ip4Info
.RouteTable
[0].SubnetMask
, &SubnetMask
.v4
, sizeof (EFI_IPv4_ADDRESS
));
254 CopyMem (&NicInfo
->Ip4Info
.RouteTable
[1].GatewayAddress
, &Gateway
.v4
, sizeof (EFI_IPv4_ADDRESS
));
257 NicInfo
->Source
= IP4_CONFIG_SOURCE_DHCP
;
258 ZeroMem (&Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.LocalIp
, sizeof (EFI_IPv4_ADDRESS
));
259 ZeroMem (&Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.SubnetMask
, sizeof (EFI_IPv4_ADDRESS
));
260 ZeroMem (&Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.Gateway
, sizeof (EFI_IPv4_ADDRESS
));
263 NicInfo
->Perment
= TRUE
;
264 CopyMem (&NicInfo
->NicAddr
, &Ip4ConfigInstance
->NicAddr
, sizeof (NIC_ADDR
));
266 return EfiNicIp4ConfigSetInfo (Ip4ConfigInstance
, NicInfo
, TRUE
);
270 This function allows the caller to request the current
271 configuration for one or more named elements. The resulting
272 string is in <ConfigAltResp> format. Any and all alternative
273 configuration strings shall also be appended to the end of the
274 current configuration string. If they are, they must appear
275 after the current configuration. They must contain the same
276 routing (GUID, NAME, PATH) as the current configuration string.
277 They must have an additional description indicating the type of
278 alternative configuration the string represents,
279 "ALTCFG=<StringToken>". That <StringToken> (when
280 converted from Hex UNICODE to binary) is a reference to a
281 string in the associated string pack.
283 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
284 @param[in] Request A null-terminated Unicode string in
285 <ConfigRequest> format. Note that this
286 includes the routing information as well as
287 the configurable name / value pairs. It is
288 invalid for this string to be in
289 <MultiConfigRequest> format.
290 @param[out] Progress On return, points to a character in the
291 Request string. Points to the string's null
292 terminator if request was successful. Points
293 to the most recent "&" before the first
294 failing name / value pair (or the beginning
295 of the string if the failure is in the first
296 name / value pair) if the request was not
298 @param[out] Results A null-terminated Unicode string in
299 <ConfigAltResp> format which has all values
300 filled in for the names in the Request string.
301 String to be allocated by the called function.
303 @retval EFI_SUCCESS The Results string is filled with the
304 values corresponding to all requested
306 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
307 parts of the results that must be
308 stored awaiting possible future
310 @retval EFI_INVALID_PARAMETER For example, passing in a NULL
311 for the Request parameter
312 would result in this type of
313 error. In this case, the
314 Progress parameter would be
316 @retval EFI_NOT_FOUND Routing data doesn't match any
317 known driver. Progress set to the
318 first character in the routing header.
319 Note: There is no requirement that the
320 driver validate the routing data. It
321 must skip the <ConfigHdr> in order to
323 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
324 to most recent & before the
325 error or the beginning of the
327 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
328 to the & before the name in
329 question.Currently not implemented.
333 Ip4DeviceExtractConfig (
334 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
335 IN CONST EFI_STRING Request
,
336 OUT EFI_STRING
*Progress
,
337 OUT EFI_STRING
*Results
342 NIC_IP4_CONFIG_INFO
*IfrDeviceNvData
;
343 IP4_CONFIG_INSTANCE
*Ip4ConfigInstance
;
344 IP4_CONFIG_IFR_NVDATA
*IfrFormNvData
;
345 EFI_STRING ConfigRequestHdr
;
346 EFI_STRING ConfigRequest
;
347 EFI_STRING DeviceResult
;
348 EFI_STRING FormResult
;
350 BOOLEAN AllocatedRequest
;
354 if (Progress
== NULL
|| Results
== NULL
) {
355 return EFI_INVALID_PARAMETER
;
362 ConfigRequest
= NULL
;
363 Status
= EFI_SUCCESS
;
364 AllocatedRequest
= FALSE
;
365 Ip4ConfigInstance
= IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This
);
368 // Check Request data in <ConfigHdr>.
370 if ((Request
== NULL
) || HiiIsConfigHdrMatch (Request
, &gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
)) {
371 IfrDeviceNvData
= AllocateZeroPool (NIC_ITEM_CONFIG_SIZE
);
372 if (IfrDeviceNvData
== NULL
) {
373 return EFI_OUT_OF_RESOURCES
;
376 ConfigLen
= sizeof (NIC_IP4_CONFIG_INFO
) + sizeof (EFI_IP4_ROUTE_TABLE
) * 2;
377 Status
= EfiNicIp4ConfigGetInfo (Ip4ConfigInstance
, &ConfigLen
, IfrDeviceNvData
);
378 if (EFI_ERROR (Status
)) {
379 FreePool (IfrDeviceNvData
);
380 return EFI_NOT_FOUND
;
383 ConfigRequest
= Request
;
384 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
386 // Request has no request element, construct full request string.
387 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
388 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
390 ConfigRequestHdr
= HiiConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, Ip4ConfigInstance
->ChildHandle
);
391 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
392 ConfigRequest
= AllocateZeroPool (Size
);
393 ASSERT (ConfigRequest
!= NULL
);
394 AllocatedRequest
= TRUE
;
395 BufferSize
= NIC_ITEM_CONFIG_SIZE
;
396 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
397 FreePool (ConfigRequestHdr
);
401 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
403 Status
= gHiiConfigRouting
->BlockToConfig (
406 (UINT8
*) IfrDeviceNvData
,
407 NIC_ITEM_CONFIG_SIZE
,
412 FreePool (IfrDeviceNvData
);
414 // Free the allocated config request string.
416 if (AllocatedRequest
) {
417 FreePool (ConfigRequest
);
418 ConfigRequest
= NULL
;
421 if (EFI_ERROR (Status
)) {
426 if ((Request
== NULL
) || HiiIsConfigHdrMatch (Request
, &mNicIp4ConfigNvDataGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
)) {
428 IfrFormNvData
= AllocateZeroPool (NIC_ITEM_CONFIG_SIZE
);
429 if (IfrFormNvData
== NULL
) {
430 return EFI_OUT_OF_RESOURCES
;
433 Ip4ConfigConvertDeviceConfigDataToIfrNvData (Ip4ConfigInstance
, IfrFormNvData
);
435 ConfigRequest
= Request
;
436 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
438 // Request has no request element, construct full request string.
439 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
440 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
442 ConfigRequestHdr
= HiiConstructConfigHdr (&mNicIp4ConfigNvDataGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, Ip4ConfigInstance
->ChildHandle
);
443 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
444 ConfigRequest
= AllocateZeroPool (Size
);
445 ASSERT (ConfigRequest
!= NULL
);
446 AllocatedRequest
= TRUE
;
447 BufferSize
= sizeof (IP4_CONFIG_IFR_NVDATA
);
448 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
449 FreePool (ConfigRequestHdr
);
453 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
455 Status
= gHiiConfigRouting
->BlockToConfig (
458 (UINT8
*) IfrFormNvData
,
459 sizeof (IP4_CONFIG_IFR_NVDATA
),
464 FreePool (IfrFormNvData
);
466 // Free the allocated config request string.
468 if (AllocatedRequest
) {
469 FreePool (ConfigRequest
);
470 ConfigRequest
= NULL
;
473 if (EFI_ERROR (Status
)) {
478 if (Request
== NULL
) {
479 Size
= StrLen (DeviceResult
);
481 Size
= Size
+ StrLen (FormResult
) + 1;
482 *Results
= AllocateZeroPool (Size
* sizeof (CHAR16
));
483 ASSERT (*Results
!= NULL
);
484 StrPointer
= *Results
;
485 StrCpy (StrPointer
, DeviceResult
);
486 StrPointer
= StrPointer
+ StrLen (StrPointer
);
488 StrCpy (StrPointer
+ 1, FormResult
);
489 FreePool (DeviceResult
);
490 FreePool (FormResult
);
491 } else if (HiiIsConfigHdrMatch (ConfigRequest
, &gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
)) {
492 *Results
= DeviceResult
;
493 } else if (HiiIsConfigHdrMatch (ConfigRequest
, &mNicIp4ConfigNvDataGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
)) {
494 *Results
= FormResult
;
496 return EFI_NOT_FOUND
;
501 // Set Progress string to the original request string.
503 if (Request
== NULL
) {
505 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
506 *Progress
= Request
+ StrLen (Request
);
513 This function applies changes in a driver's configuration.
514 Input is a Configuration, which has the routing data for this
515 driver followed by name / value configuration pairs. The driver
516 must apply those pairs to its configurable storage. If the
517 driver's configuration is stored in a linear block of data
518 and the driver's name / value pairs are in <BlockConfig>
519 format, it may use the ConfigToBlock helper function (above) to
520 simplify the job. Currently not implemented.
522 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
523 @param[in] Configuration A null-terminated Unicode string in
524 <ConfigString> format.
525 @param[out] Progress A pointer to a string filled in with the
526 offset of the most recent '&' before the
527 first failing name / value pair (or the
528 beginn ing of the string if the failure
529 is in the first name / value pair) or
530 the terminating NULL if all was
533 @retval EFI_SUCCESS The results have been distributed or are
534 awaiting distribution.
535 @retval EFI_OUT_OF_MEMORY Not enough memory to store the
536 parts of the results that must be
537 stored awaiting possible future
539 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
540 Results parameter would result
541 in this type of error.
542 @retval EFI_NOT_FOUND Target for the specified routing data
547 Ip4DeviceRouteConfig (
548 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
549 IN CONST EFI_STRING Configuration
,
550 OUT EFI_STRING
*Progress
555 NIC_IP4_CONFIG_INFO
*IfrDeviceNvData
;
556 IP4_CONFIG_IFR_NVDATA
*IfrFormNvData
;
557 NIC_IP4_CONFIG_INFO
*NicInfo
;
558 IP4_CONFIG_INSTANCE
*Ip4ConfigInstance
;
559 EFI_MAC_ADDRESS ZeroMac
;
561 if (Configuration
== NULL
|| Progress
== NULL
) {
562 return EFI_INVALID_PARAMETER
;
565 *Progress
= Configuration
;
567 Ip4ConfigInstance
= IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This
);
570 // Check Routing data in <ConfigHdr>.
572 if (HiiIsConfigHdrMatch (Configuration
, &mNicIp4ConfigNvDataGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
)) {
574 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
576 IfrFormNvData
= AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA
));
577 if (IfrFormNvData
== NULL
) {
578 return EFI_OUT_OF_RESOURCES
;
581 BufferSize
= NIC_ITEM_CONFIG_SIZE
;
582 Status
= gHiiConfigRouting
->ConfigToBlock (
585 (UINT8
*) IfrFormNvData
,
589 if (!EFI_ERROR (Status
)) {
590 Status
= Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance
);
593 FreePool (IfrFormNvData
);
595 } else if (HiiIsConfigHdrMatch (Configuration
, &gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
)) {
597 IfrDeviceNvData
= AllocateZeroPool (NIC_ITEM_CONFIG_SIZE
);
598 if (IfrDeviceNvData
== NULL
) {
599 return EFI_OUT_OF_RESOURCES
;
602 BufferSize
= NIC_ITEM_CONFIG_SIZE
;
603 Status
= gHiiConfigRouting
->ConfigToBlock (
606 (UINT8
*) IfrDeviceNvData
,
610 if (!EFI_ERROR (Status
)) {
611 ZeroMem (&ZeroMac
, sizeof (EFI_MAC_ADDRESS
));
612 if (CompareMem (&IfrDeviceNvData
->NicAddr
.MacAddr
, &ZeroMac
, IfrDeviceNvData
->NicAddr
.Len
) != 0) {
613 BufferSize
= sizeof (NIC_IP4_CONFIG_INFO
) + sizeof (EFI_IP4_ROUTE_TABLE
) * IfrDeviceNvData
->Ip4Info
.RouteTableSize
;
614 NicInfo
= AllocateCopyPool (BufferSize
, IfrDeviceNvData
);
615 Status
= EfiNicIp4ConfigSetInfo (Ip4ConfigInstance
, NicInfo
, TRUE
);
617 ZeroMem (&Ip4ConfigInstance
->Ip4ConfigCallbackInfo
, sizeof (IP4_SETTING_INFO
));
618 Status
= EfiNicIp4ConfigSetInfo (Ip4ConfigInstance
, NULL
, TRUE
);
622 FreePool (IfrDeviceNvData
);
626 return EFI_NOT_FOUND
;
634 This function is called to provide results data to the driver.
635 This data consists of a unique key that is used to identify
636 which data is either being passed back or being asked for.
638 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
639 @param[in] Action Specifies the type of action taken by the browser.
640 @param[in] QuestionId A unique value which is sent to the original
641 exporting driver so that it can identify the type
642 of data to expect. The format of the data tends to
643 vary based on the opcode that enerated the callback.
644 @param[in] Type The type of value for the question.
645 @param[in] Value A pointer to the data being sent to the original
647 @param[out] ActionRequest On return, points to the action requested by the
650 @retval EFI_SUCCESS The callback successfully handled the action.
651 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
652 variable and its data.
653 @retval EFI_DEVICE_ERROR The variable could not be saved.
654 @retval EFI_UNSUPPORTED The specified Action is not supported by the
655 callback.Currently not implemented.
656 @retval EFI_INVALID_PARAMETERS Passing in wrong parameter.
657 @retval Others Other errors as indicated.
662 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
663 IN EFI_BROWSER_ACTION Action
,
664 IN EFI_QUESTION_ID QuestionId
,
666 IN EFI_IFR_TYPE_VALUE
*Value
,
667 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
670 IP4_CONFIG_INSTANCE
*Ip4ConfigInstance
;
671 CHAR8 Ip4String
[IP4_STR_MAX_SIZE
];
672 IP4_CONFIG_IFR_NVDATA
*IfrFormNvData
;
673 EFI_IP_ADDRESS HostIp
;
674 EFI_IP_ADDRESS SubnetMask
;
675 EFI_IP_ADDRESS Gateway
;
679 Ip4ConfigInstance
= IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This
);
681 IfrFormNvData
= AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA
));
682 if (IfrFormNvData
== NULL
) {
683 return EFI_OUT_OF_RESOURCES
;
687 // Retrive uncommitted data from Browser
689 if (!HiiGetBrowserData (&mNicIp4ConfigNvDataGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, sizeof (IP4_CONFIG_IFR_NVDATA
), (UINT8
*) IfrFormNvData
)) {
690 FreePool (IfrFormNvData
);
691 return EFI_NOT_FOUND
;
694 Status
= EFI_SUCCESS
;
696 switch (QuestionId
) {
699 if (IfrFormNvData
->Configure
== 0) {
700 Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.Configured
= FALSE
;
702 Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.Configured
= TRUE
;
706 case KEY_DHCP_ENABLE
:
707 if (IfrFormNvData
->DhcpEnable
== 0) {
708 Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.DhcpEnabled
= FALSE
;
710 Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.DhcpEnabled
= TRUE
;
716 UnicodeStrToAsciiStr (IfrFormNvData
->StationAddress
, Ip4String
);
717 Status
= Ip4AsciiStrToIp (Ip4String
, &HostIp
.v4
);
718 if (EFI_ERROR (Status
) || !NetIp4IsUnicast (NTOHL (HostIp
.Addr
[0]), 0)) {
719 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid IP address!", NULL
);
720 Status
= EFI_INVALID_PARAMETER
;
722 CopyMem (&Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.LocalIp
, &HostIp
.v4
, sizeof (HostIp
.v4
));
727 case KEY_SUBNET_MASK
:
728 UnicodeStrToAsciiStr (IfrFormNvData
->SubnetMask
, Ip4String
);
729 Status
= Ip4AsciiStrToIp (Ip4String
, &SubnetMask
.v4
);
730 if (EFI_ERROR (Status
) || ((SubnetMask
.Addr
[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask
.v4
) == 0))) {
731 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid SubnetMask!", NULL
);
732 Status
= EFI_INVALID_PARAMETER
;
734 CopyMem (&Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.SubnetMask
, &SubnetMask
.v4
, sizeof (SubnetMask
.v4
));
740 UnicodeStrToAsciiStr (IfrFormNvData
->GatewayAddress
, Ip4String
);
741 Status
= Ip4AsciiStrToIp (Ip4String
, &Gateway
.v4
);
742 if (EFI_ERROR (Status
) || ((Gateway
.Addr
[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway
.Addr
[0]), 0))) {
743 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, L
"Invalid Gateway!", NULL
);
744 Status
= EFI_INVALID_PARAMETER
;
746 CopyMem (&Ip4ConfigInstance
->Ip4ConfigCallbackInfo
.Gateway
, &Gateway
.v4
, sizeof (Gateway
.v4
));
751 case KEY_SAVE_CHANGES
:
753 Status
= Ip4ConfigConvertIfrNvDataToDeviceConfigData (Ip4ConfigInstance
);
755 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
764 if (!EFI_ERROR (Status
)) {
766 // Pass changed uncommitted data back to Form Browser
768 HiiSetBrowserData (&gEfiNicIp4ConfigVariableGuid
, EFI_NIC_IP4_CONFIG_VARIABLE
, sizeof (IP4_CONFIG_IFR_NVDATA
), (UINT8
*) IfrFormNvData
, NULL
);
771 FreePool (IfrFormNvData
);
777 Install HII Config Access protocol for network device and allocate resource.
779 @param[in] Instance The IP4 Config instance.
781 @retval EFI_SUCCESS The HII Config Access protocol is installed.
782 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
783 @retval Others Other errors as indicated.
786 Ip4ConfigDeviceInit (
787 IN IP4_CONFIG_INSTANCE
*Instance
791 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
792 VENDOR_DEVICE_PATH VendorDeviceNode
;
793 EFI_SERVICE_BINDING_PROTOCOL
*MnpSb
;
795 CHAR16 MenuString
[128];
796 CHAR16 PortString
[128];
797 CHAR16
*OldMenuString
;
799 ConfigAccess
= &Instance
->HiiConfigAccessProtocol
;
800 ConfigAccess
->ExtractConfig
= Ip4DeviceExtractConfig
;
801 ConfigAccess
->RouteConfig
= Ip4DeviceRouteConfig
;
802 ConfigAccess
->Callback
= Ip4FormCallback
;
805 // Construct device path node for EFI HII Config Access protocol,
806 // which consists of controller physical device path and one hardware
809 ZeroMem (&VendorDeviceNode
, sizeof (VENDOR_DEVICE_PATH
));
810 VendorDeviceNode
.Header
.Type
= HARDWARE_DEVICE_PATH
;
811 VendorDeviceNode
.Header
.SubType
= HW_VENDOR_DP
;
813 CopyGuid (&VendorDeviceNode
.Guid
, &gEfiNicIp4ConfigVariableGuid
);
815 SetDevicePathNodeLength (&VendorDeviceNode
.Header
, sizeof (VENDOR_DEVICE_PATH
));
816 Instance
->HiiVendorDevicePath
= AppendDevicePathNode (
817 Instance
->ParentDevicePath
,
818 (EFI_DEVICE_PATH_PROTOCOL
*) &VendorDeviceNode
821 Instance
->ChildHandle
= NULL
;
823 // Install Device Path Protocol and Config Access protocol on new handle
825 Status
= gBS
->InstallMultipleProtocolInterfaces (
826 &Instance
->ChildHandle
,
827 &gEfiDevicePathProtocolGuid
,
828 Instance
->HiiVendorDevicePath
,
829 &gEfiHiiConfigAccessProtocolGuid
,
833 if (!EFI_ERROR (Status
)) {
835 // Open the Parent Handle for the child
837 Status
= gBS
->OpenProtocol (
838 Instance
->Controller
,
839 &gEfiManagedNetworkServiceBindingProtocolGuid
,
842 Instance
->ChildHandle
,
843 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
847 ASSERT_EFI_ERROR (Status
);
850 // Publish our HII data
852 Instance
->RegisteredHandle
= HiiAddPackages (
853 &mNicIp4ConfigNvDataGuid
,
854 Instance
->ChildHandle
,
859 if (Instance
->RegisteredHandle
== NULL
) {
860 return EFI_OUT_OF_RESOURCES
;
864 // Append MAC string in the menu string and tile string
866 Status
= NetLibGetMacString (Instance
->Controller
, Instance
->Image
, &MacString
);
867 if (!EFI_ERROR (Status
)) {
868 OldMenuString
= HiiGetString (Instance
->RegisteredHandle
, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE
), NULL
);
869 UnicodeSPrint (MenuString
, 128, L
"%s (MAC:%s)", OldMenuString
, MacString
);
870 HiiSetString (Instance
->RegisteredHandle
, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE
), MenuString
, NULL
);
872 UnicodeSPrint (PortString
, 128, L
"MAC:%s", MacString
);
873 HiiSetString (Instance
->RegisteredHandle
, STRING_TOKEN (STR_IP4_DEVICE_FORM_TITLE
), PortString
, NULL
);
874 FreePool (MacString
);
881 Uninstall HII Config Access protocol for network device and free resource.
883 @param[in] Instance The IP4 Config instance.
885 @retval EFI_SUCCESS The HII Config Access protocol is uninstalled.
886 @retval Others Other errors as indicated.
889 Ip4ConfigDeviceUnload (
890 IN IP4_CONFIG_INSTANCE
*Instance
894 // Remove HII package list
896 HiiRemovePackages (Instance
->RegisteredHandle
);
899 // Close the child handle
902 Instance
->Controller
,
903 &gEfiManagedNetworkServiceBindingProtocolGuid
,
905 Instance
->ChildHandle
909 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL
911 gBS
->UninstallMultipleProtocolInterfaces (
912 Instance
->ChildHandle
,
913 &gEfiDevicePathProtocolGuid
,
914 Instance
->HiiVendorDevicePath
,
915 &gEfiHiiConfigAccessProtocolGuid
,
916 &Instance
->HiiConfigAccessProtocol
,