]>
Commit | Line | Data |
---|---|---|
63886849 | 1 | /** @file\r |
2 | Helper functions for configuring or getting the parameters relating to Ip4.\r | |
3 | \r | |
e5eed7d3 HT |
4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials\r | |
63886849 | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "Ip4ConfigNv.h"\r | |
74df5026 | 16 | #include "NicIp4Variable.h"\r |
63886849 | 17 | \r |
d80ea739 | 18 | EFI_GUID mNicIp4ConfigNvDataGuid = EFI_NIC_IP4_CONFIG_NVDATA_GUID;\r |
63886849 | 19 | \r |
63886849 | 20 | \r |
21 | /**\r | |
22 | Calculate the prefix length of the IPv4 subnet mask.\r | |
23 | \r | |
24 | @param[in] SubnetMask The IPv4 subnet mask.\r | |
25 | \r | |
26 | @return The prefix length of the subnet mask.\r | |
27 | @retval 0 Other errors as indicated.\r | |
28 | **/\r | |
29 | UINT8\r | |
30 | GetSubnetMaskPrefixLength (\r | |
31 | IN EFI_IPv4_ADDRESS *SubnetMask\r | |
32 | )\r | |
33 | {\r | |
34 | UINT8 Len;\r | |
35 | UINT32 ReverseMask;\r | |
36 | \r | |
37 | //\r | |
38 | // The SubnetMask is in network byte order.\r | |
39 | //\r | |
72ed3d75 | 40 | ReverseMask = SwapBytes32 (*(UINT32 *)&SubnetMask[0]);\r |
63886849 | 41 | \r |
42 | //\r | |
43 | // Reverse it.\r | |
44 | //\r | |
45 | ReverseMask = ~ReverseMask;\r | |
46 | \r | |
47 | if ((ReverseMask & (ReverseMask + 1)) != 0) {\r | |
48 | return 0;\r | |
49 | }\r | |
50 | \r | |
51 | Len = 0;\r | |
52 | \r | |
53 | while (ReverseMask != 0) {\r | |
54 | ReverseMask = ReverseMask >> 1;\r | |
55 | Len++;\r | |
56 | }\r | |
57 | \r | |
58 | return (UINT8) (32 - Len);\r | |
59 | }\r | |
60 | \r | |
61 | /**\r | |
62 | Convert the decimal dotted IPv4 address into the binary IPv4 address.\r | |
63 | \r | |
64 | @param[in] Str The UNICODE string.\r | |
74df5026 | 65 | @param[out] Ip The storage to return the IPv4 address.\r |
63886849 | 66 | \r |
67 | @retval EFI_SUCCESS The binary IP address is returned in Ip.\r | |
68 | @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r | |
69 | **/\r | |
70 | EFI_STATUS\r | |
74df5026 | 71 | Ip4StrToIp (\r |
72 | IN CHAR16 *Str,\r | |
63886849 | 73 | OUT EFI_IPv4_ADDRESS *Ip\r |
74 | )\r | |
75 | {\r | |
76 | UINTN Index;\r | |
77 | UINTN Number;\r | |
78 | \r | |
79 | Index = 0;\r | |
80 | \r | |
74df5026 | 81 | while (*Str != L'\0') {\r |
63886849 | 82 | \r |
83 | if (Index > 3) {\r | |
84 | return EFI_INVALID_PARAMETER;\r | |
85 | }\r | |
86 | \r | |
87 | Number = 0;\r | |
74df5026 | 88 | while ((*Str >= L'0') && (*Str <= L'9')) {\r |
89 | Number = Number * 10 + (*Str - L'0');\r | |
63886849 | 90 | Str++;\r |
91 | }\r | |
92 | \r | |
93 | if (Number > 0xFF) {\r | |
94 | return EFI_INVALID_PARAMETER;\r | |
95 | }\r | |
96 | \r | |
97 | Ip->Addr[Index] = (UINT8) Number;\r | |
98 | \r | |
74df5026 | 99 | if ((*Str != L'\0') && (*Str != L'.')) {\r |
63886849 | 100 | //\r |
101 | // The current character should be either the NULL terminator or\r | |
102 | // the dot delimiter.\r | |
103 | //\r | |
104 | return EFI_INVALID_PARAMETER;\r | |
105 | }\r | |
106 | \r | |
74df5026 | 107 | if (*Str == L'.') {\r |
63886849 | 108 | //\r |
109 | // Skip the delimiter.\r | |
110 | //\r | |
111 | Str++;\r | |
112 | }\r | |
113 | \r | |
114 | Index++;\r | |
115 | }\r | |
116 | \r | |
117 | if (Index != 4) {\r | |
118 | return EFI_INVALID_PARAMETER;\r | |
119 | }\r | |
120 | \r | |
121 | return EFI_SUCCESS;\r | |
122 | }\r | |
123 | \r | |
124 | /**\r | |
125 | Convert the IPv4 address into a dotted string.\r | |
126 | \r | |
127 | @param[in] Ip The IPv4 address.\r | |
128 | @param[out] Str The dotted IP string.\r | |
129 | **/\r | |
130 | VOID\r | |
131 | Ip4ConfigIpToStr (\r | |
132 | IN EFI_IPv4_ADDRESS *Ip,\r | |
133 | OUT CHAR16 *Str\r | |
134 | )\r | |
135 | {\r | |
136 | UnicodeSPrint (Str, 2 * IP4_STR_MAX_SIZE, L"%d.%d.%d.%d", Ip->Addr[0], Ip->Addr[1], Ip->Addr[2], Ip->Addr[3]);\r | |
137 | }\r | |
138 | \r | |
139 | \r | |
140 | /**\r | |
141 | Convert the network configuration data into the IFR data.\r | |
142 | \r | |
f6b7393c | 143 | @param[in] Ip4ConfigInstance The IP4Config instance\r |
144 | @param[out] IfrFormNvData The IFR nv data.\r | |
63886849 | 145 | **/\r |
146 | VOID\r | |
147 | Ip4ConfigConvertDeviceConfigDataToIfrNvData (\r | |
148 | IN IP4_CONFIG_INSTANCE *Ip4ConfigInstance,\r | |
149 | OUT IP4_CONFIG_IFR_NVDATA *IfrFormNvData\r | |
150 | )\r | |
151 | {\r | |
74df5026 | 152 | NIC_IP4_CONFIG_INFO *NicConfig;\r |
153 | \r | |
154 | NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance);\r | |
155 | if (NicConfig != NULL) {\r | |
c22b6cdf | 156 | IfrFormNvData->Configure = 1;\r |
63886849 | 157 | if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {\r |
158 | IfrFormNvData->DhcpEnable = 1;\r | |
159 | } else {\r | |
160 | IfrFormNvData->DhcpEnable = 0;\r | |
161 | Ip4ConfigIpToStr (&NicConfig->Ip4Info.StationAddress, IfrFormNvData->StationAddress);\r | |
162 | Ip4ConfigIpToStr (&NicConfig->Ip4Info.SubnetMask, IfrFormNvData->SubnetMask);\r | |
163 | Ip4ConfigIpToStr (&NicConfig->Ip4Info.RouteTable[1].GatewayAddress, IfrFormNvData->GatewayAddress);\r | |
164 | }\r | |
74df5026 | 165 | \r |
166 | FreePool (NicConfig);\r | |
c22b6cdf | 167 | } else {\r |
168 | IfrFormNvData->Configure = 0;\r | |
63886849 | 169 | }\r |
63886849 | 170 | }\r |
171 | \r | |
172 | /**\r | |
d80ea739 | 173 | Convert the IFR data into the network configuration data and set the IP\r |
174 | configure parameters for the NIC.\r | |
175 | \r | |
74df5026 | 176 | @param[in] IfrFormNvData The IFR NV data.\r |
d80ea739 | 177 | @param[in, out] Ip4ConfigInstance The IP4Config instance.\r |
c22b6cdf | 178 | \r |
179 | @retval EFI_SUCCESS The configure parameter for this NIC was\r | |
d80ea739 | 180 | set successfully.\r |
181 | @retval EFI_ALREADY_STARTED There is a pending auto configuration.\r | |
182 | @retval EFI_NOT_FOUND No auto configure parameter is found.\r | |
c22b6cdf | 183 | \r |
63886849 | 184 | **/\r |
d80ea739 | 185 | EFI_STATUS\r |
186 | Ip4ConfigConvertIfrNvDataToDeviceConfigData (\r | |
74df5026 | 187 | IN IP4_CONFIG_IFR_NVDATA *IfrFormNvData,\r |
d80ea739 | 188 | IN OUT IP4_CONFIG_INSTANCE *Ip4ConfigInstance\r |
63886849 | 189 | )\r |
190 | {\r | |
c22b6cdf | 191 | EFI_STATUS Status;\r |
d80ea739 | 192 | EFI_IP_ADDRESS HostIp;\r |
193 | EFI_IP_ADDRESS SubnetMask;\r | |
194 | EFI_IP_ADDRESS Gateway;\r | |
195 | EFI_INPUT_KEY Key;\r | |
196 | NIC_IP4_CONFIG_INFO *NicInfo;\r | |
197 | EFI_IP_ADDRESS Ip;\r | |
63886849 | 198 | \r |
74df5026 | 199 | ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));\r |
200 | \r | |
201 | Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured = IfrFormNvData->Configure;\r | |
202 | Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled = IfrFormNvData->DhcpEnable;\r | |
203 | Ip4StrToIp (IfrFormNvData->StationAddress, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp);\r | |
204 | Ip4StrToIp (IfrFormNvData->SubnetMask, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask);\r | |
205 | Ip4StrToIp (IfrFormNvData->GatewayAddress, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway);\r | |
206 | \r | |
c22b6cdf | 207 | if (!Ip4ConfigInstance->Ip4ConfigCallbackInfo.Configured) {\r |
208 | //\r | |
209 | // Clear the variable\r | |
210 | //\r | |
211 | ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));\r | |
212 | \r | |
213 | Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE);\r | |
214 | if (Status == EFI_NOT_FOUND) {\r | |
215 | return EFI_SUCCESS;\r | |
216 | }\r | |
217 | \r | |
218 | return Status;\r | |
219 | }\r | |
220 | \r | |
d80ea739 | 221 | NicInfo = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO) + 2 * sizeof (EFI_IP4_ROUTE_TABLE));\r |
222 | ASSERT (NicInfo != NULL);\r | |
63886849 | 223 | \r |
d80ea739 | 224 | NicInfo->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (NicInfo + 1);\r |
225 | \r | |
c22b6cdf | 226 | if (!Ip4ConfigInstance->Ip4ConfigCallbackInfo.DhcpEnabled) {\r |
d80ea739 | 227 | CopyMem (&HostIp.v4, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, sizeof (HostIp.v4));\r |
228 | CopyMem (&SubnetMask.v4, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, sizeof (SubnetMask.v4));\r | |
229 | CopyMem (&Gateway.v4, &Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, sizeof (Gateway.v4));\r | |
230 | \r | |
c22b6cdf | 231 | if (!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r |
232 | CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r | |
233 | return EFI_INVALID_PARAMETER;\r | |
234 | }\r | |
235 | if (EFI_IP4_EQUAL (&SubnetMask, &mZeroIp4Addr)) {\r | |
236 | CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);\r | |
237 | return EFI_INVALID_PARAMETER;\r | |
238 | }\r | |
239 | \r | |
d80ea739 | 240 | if ((Gateway.Addr[0] != 0)) {\r |
241 | if (SubnetMask.Addr[0] == 0) {\r | |
242 | CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Gateway address is set but subnet mask is zero.", NULL);\r | |
243 | return EFI_INVALID_PARAMETER;\r | |
244 | \r | |
245 | } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) {\r | |
246 | CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Local IP and Gateway are not in the same subnet.", NULL);\r | |
247 | return EFI_INVALID_PARAMETER; }\r | |
63886849 | 248 | }\r |
249 | \r | |
d80ea739 | 250 | NicInfo->Source = IP4_CONFIG_SOURCE_STATIC;\r |
251 | NicInfo->Ip4Info.RouteTableSize = 2;\r | |
252 | \r | |
253 | CopyMem (&NicInfo->Ip4Info.StationAddress, &HostIp.v4, sizeof (EFI_IPv4_ADDRESS));\r | |
254 | CopyMem (&NicInfo->Ip4Info.SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS));\r | |
255 | \r | |
256 | Ip.Addr[0] = HostIp.Addr[0] & SubnetMask.Addr[0];\r | |
257 | \r | |
258 | CopyMem (&NicInfo->Ip4Info.RouteTable[0].SubnetAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));\r | |
259 | CopyMem (&NicInfo->Ip4Info.RouteTable[0].SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS));\r | |
260 | CopyMem (&NicInfo->Ip4Info.RouteTable[1].GatewayAddress, &Gateway.v4, sizeof (EFI_IPv4_ADDRESS));\r | |
c22b6cdf | 261 | \r |
d80ea739 | 262 | } else {\r |
263 | NicInfo->Source = IP4_CONFIG_SOURCE_DHCP;\r | |
c22b6cdf | 264 | ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, sizeof (EFI_IPv4_ADDRESS));\r |
265 | ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r | |
266 | ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, sizeof (EFI_IPv4_ADDRESS));\r | |
63886849 | 267 | }\r |
268 | \r | |
d80ea739 | 269 | NicInfo->Perment = TRUE;\r |
270 | CopyMem (&NicInfo->NicAddr, &Ip4ConfigInstance->NicAddr, sizeof (NIC_ADDR));\r | |
271 | \r | |
272 | return EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE);\r | |
63886849 | 273 | }\r |
274 | \r | |
275 | /**\r | |
276 | This function allows the caller to request the current\r | |
277 | configuration for one or more named elements. The resulting\r | |
278 | string is in <ConfigAltResp> format. Any and all alternative\r | |
279 | configuration strings shall also be appended to the end of the\r | |
280 | current configuration string. If they are, they must appear\r | |
281 | after the current configuration. They must contain the same\r | |
282 | routing (GUID, NAME, PATH) as the current configuration string.\r | |
283 | They must have an additional description indicating the type of\r | |
284 | alternative configuration the string represents,\r | |
285 | "ALTCFG=<StringToken>". That <StringToken> (when\r | |
286 | converted from Hex UNICODE to binary) is a reference to a\r | |
287 | string in the associated string pack.\r | |
288 | \r | |
289 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
290 | @param[in] Request A null-terminated Unicode string in\r | |
291 | <ConfigRequest> format. Note that this\r | |
292 | includes the routing information as well as\r | |
293 | the configurable name / value pairs. It is\r | |
294 | invalid for this string to be in\r | |
295 | <MultiConfigRequest> format.\r | |
296 | @param[out] Progress On return, points to a character in the\r | |
297 | Request string. Points to the string's null\r | |
298 | terminator if request was successful. Points\r | |
299 | to the most recent "&" before the first\r | |
300 | failing name / value pair (or the beginning\r | |
301 | of the string if the failure is in the first\r | |
302 | name / value pair) if the request was not\r | |
303 | successful.\r | |
304 | @param[out] Results A null-terminated Unicode string in\r | |
305 | <ConfigAltResp> format which has all values\r | |
306 | filled in for the names in the Request string.\r | |
307 | String to be allocated by the called function.\r | |
308 | \r | |
309 | @retval EFI_SUCCESS The Results string is filled with the\r | |
310 | values corresponding to all requested\r | |
311 | names.\r | |
312 | @retval EFI_OUT_OF_RESOURCES Not enough memory to store the\r | |
313 | parts of the results that must be\r | |
314 | stored awaiting possible future\r | |
315 | protocols.\r | |
63886849 | 316 | @retval EFI_NOT_FOUND Routing data doesn't match any\r |
317 | known driver. Progress set to the\r | |
318 | first character in the routing header.\r | |
319 | Note: There is no requirement that the\r | |
320 | driver validate the routing data. It\r | |
321 | must skip the <ConfigHdr> in order to\r | |
322 | process the names.\r | |
323 | @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set\r | |
324 | to most recent & before the\r | |
325 | error or the beginning of the\r | |
326 | string.\r | |
327 | @retval EFI_INVALID_PARAMETER Unknown name. Progress points\r | |
328 | to the & before the name in\r | |
329 | question.Currently not implemented.\r | |
330 | **/\r | |
331 | EFI_STATUS\r | |
332 | EFIAPI\r | |
333 | Ip4DeviceExtractConfig (\r | |
334 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
335 | IN CONST EFI_STRING Request,\r | |
336 | OUT EFI_STRING *Progress,\r | |
337 | OUT EFI_STRING *Results\r | |
338 | )\r | |
339 | {\r | |
340 | EFI_STATUS Status;\r | |
63886849 | 341 | NIC_IP4_CONFIG_INFO *IfrDeviceNvData;\r |
74df5026 | 342 | NIC_IP4_CONFIG_INFO *NicConfig;\r |
63886849 | 343 | IP4_CONFIG_INSTANCE *Ip4ConfigInstance;\r |
d80ea739 | 344 | IP4_CONFIG_IFR_NVDATA *IfrFormNvData;\r |
59aefb7e LG |
345 | EFI_STRING ConfigRequestHdr;\r |
346 | EFI_STRING ConfigRequest;\r | |
347 | EFI_STRING DeviceResult;\r | |
348 | EFI_STRING FormResult;\r | |
349 | CHAR16 *StrPointer;\r | |
350 | BOOLEAN AllocatedRequest;\r | |
351 | UINTN Size;\r | |
352 | UINTN BufferSize;\r | |
353 | \r | |
354 | if (Progress == NULL || Results == NULL) {\r | |
63886849 | 355 | return EFI_INVALID_PARAMETER;\r |
356 | }\r | |
357 | \r | |
59aefb7e LG |
358 | *Progress = Request;\r |
359 | Size = 0;\r | |
360 | DeviceResult = NULL;\r | |
361 | FormResult = NULL;\r | |
362 | ConfigRequest = NULL;\r | |
363 | Status = EFI_SUCCESS;\r | |
364 | AllocatedRequest = FALSE;\r | |
d80ea739 | 365 | Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);\r |
366 | \r | |
391a0724 | 367 | //\r |
368 | // Check Request data in <ConfigHdr>.\r | |
369 | //\r | |
59aefb7e | 370 | if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r |
d80ea739 | 371 | IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r |
372 | if (IfrDeviceNvData == NULL) {\r | |
373 | return EFI_OUT_OF_RESOURCES;\r | |
374 | }\r | |
391a0724 | 375 | \r |
74df5026 | 376 | NicConfig = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance);\r |
377 | if (NicConfig == NULL) {\r | |
d80ea739 | 378 | return EFI_NOT_FOUND;\r |
379 | }\r | |
74df5026 | 380 | CopyMem (IfrDeviceNvData, NicConfig, SIZEOF_NIC_IP4_CONFIG_INFO (NicConfig));\r |
381 | FreePool (NicConfig);\r | |
c22b6cdf | 382 | \r |
59aefb7e LG |
383 | ConfigRequest = Request;\r |
384 | if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r | |
385 | //\r | |
386 | // Request has no request element, construct full request string.\r | |
387 | // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r | |
388 | // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r | |
389 | //\r | |
390 | ConfigRequestHdr = HiiConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, Ip4ConfigInstance->ChildHandle);\r | |
391 | Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r | |
392 | ConfigRequest = AllocateZeroPool (Size);\r | |
393 | ASSERT (ConfigRequest != NULL);\r | |
394 | AllocatedRequest = TRUE;\r | |
395 | BufferSize = NIC_ITEM_CONFIG_SIZE;\r | |
396 | UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r | |
397 | FreePool (ConfigRequestHdr);\r | |
398 | }\r | |
399 | \r | |
d80ea739 | 400 | //\r |
401 | // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r | |
402 | //\r | |
403 | Status = gHiiConfigRouting->BlockToConfig (\r | |
404 | gHiiConfigRouting,\r | |
59aefb7e | 405 | ConfigRequest,\r |
d80ea739 | 406 | (UINT8 *) IfrDeviceNvData,\r |
407 | NIC_ITEM_CONFIG_SIZE,\r | |
59aefb7e | 408 | &DeviceResult,\r |
d80ea739 | 409 | Progress\r |
410 | );\r | |
c22b6cdf | 411 | \r |
d80ea739 | 412 | FreePool (IfrDeviceNvData);\r |
59aefb7e LG |
413 | //\r |
414 | // Free the allocated config request string.\r | |
415 | //\r | |
416 | if (AllocatedRequest) {\r | |
417 | FreePool (ConfigRequest);\r | |
418 | ConfigRequest = NULL;\r | |
419 | }\r | |
63886849 | 420 | \r |
59aefb7e LG |
421 | if (EFI_ERROR (Status)) {\r |
422 | goto Failure;\r | |
423 | }\r | |
74df5026 | 424 | }\r |
425 | \r | |
59aefb7e | 426 | if ((Request == NULL) || HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r |
63886849 | 427 | \r |
74df5026 | 428 | IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA));\r |
d80ea739 | 429 | if (IfrFormNvData == NULL) {\r |
430 | return EFI_OUT_OF_RESOURCES;\r | |
431 | }\r | |
c22b6cdf | 432 | \r |
d80ea739 | 433 | Ip4ConfigConvertDeviceConfigDataToIfrNvData (Ip4ConfigInstance, IfrFormNvData);\r |
c22b6cdf | 434 | \r |
59aefb7e LG |
435 | ConfigRequest = Request;\r |
436 | if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r | |
437 | //\r | |
438 | // Request has no request element, construct full request string.\r | |
439 | // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r | |
440 | // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r | |
441 | //\r | |
442 | ConfigRequestHdr = HiiConstructConfigHdr (&mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE, Ip4ConfigInstance->ChildHandle);\r | |
443 | Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r | |
444 | ConfigRequest = AllocateZeroPool (Size);\r | |
445 | ASSERT (ConfigRequest != NULL);\r | |
446 | AllocatedRequest = TRUE;\r | |
447 | BufferSize = sizeof (IP4_CONFIG_IFR_NVDATA);\r | |
448 | UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r | |
449 | FreePool (ConfigRequestHdr);\r | |
450 | }\r | |
74df5026 | 451 | \r |
d80ea739 | 452 | //\r |
453 | // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r | |
454 | //\r | |
455 | Status = gHiiConfigRouting->BlockToConfig (\r | |
456 | gHiiConfigRouting,\r | |
59aefb7e | 457 | ConfigRequest,\r |
d80ea739 | 458 | (UINT8 *) IfrFormNvData,\r |
459 | sizeof (IP4_CONFIG_IFR_NVDATA),\r | |
59aefb7e | 460 | &FormResult,\r |
d80ea739 | 461 | Progress\r |
462 | );\r | |
c22b6cdf | 463 | \r |
d80ea739 | 464 | FreePool (IfrFormNvData);\r |
59aefb7e LG |
465 | //\r |
466 | // Free the allocated config request string.\r | |
467 | //\r | |
468 | if (AllocatedRequest) {\r | |
469 | FreePool (ConfigRequest);\r | |
470 | ConfigRequest = NULL;\r | |
471 | }\r | |
472 | \r | |
473 | if (EFI_ERROR (Status)) {\r | |
474 | goto Failure;\r | |
475 | }\r | |
476 | }\r | |
d80ea739 | 477 | \r |
59aefb7e LG |
478 | if (Request == NULL) {\r |
479 | Size = StrLen (DeviceResult);\r | |
480 | Size = Size + 1;\r | |
481 | Size = Size + StrLen (FormResult) + 1;\r | |
482 | *Results = AllocateZeroPool (Size * sizeof (CHAR16));\r | |
483 | ASSERT (*Results != NULL);\r | |
484 | StrPointer = *Results;\r | |
485 | StrCpy (StrPointer, DeviceResult);\r | |
486 | StrPointer = StrPointer + StrLen (StrPointer);\r | |
487 | *StrPointer = L'&';\r | |
488 | StrCpy (StrPointer + 1, FormResult);\r | |
489 | FreePool (DeviceResult);\r | |
490 | FreePool (FormResult);\r | |
b26fc8d8 | 491 | } else if (HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r |
59aefb7e | 492 | *Results = DeviceResult;\r |
b26fc8d8 | 493 | } else if (HiiIsConfigHdrMatch (Request, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r |
59aefb7e | 494 | *Results = FormResult;\r |
d80ea739 | 495 | } else {\r |
63886849 | 496 | return EFI_NOT_FOUND;\r |
497 | }\r | |
498 | \r | |
59aefb7e LG |
499 | Failure:\r |
500 | //\r | |
501 | // Set Progress string to the original request string.\r | |
502 | //\r | |
503 | if (Request == NULL) {\r | |
504 | *Progress = NULL;\r | |
505 | } else if (StrStr (Request, L"OFFSET") == NULL) {\r | |
506 | *Progress = Request + StrLen (Request);\r | |
507 | }\r | |
74df5026 | 508 | \r |
63886849 | 509 | return Status;\r |
510 | }\r | |
511 | \r | |
512 | /**\r | |
513 | This function applies changes in a driver's configuration.\r | |
514 | Input is a Configuration, which has the routing data for this\r | |
515 | driver followed by name / value configuration pairs. The driver\r | |
516 | must apply those pairs to its configurable storage. If the\r | |
517 | driver's configuration is stored in a linear block of data\r | |
518 | and the driver's name / value pairs are in <BlockConfig>\r | |
519 | format, it may use the ConfigToBlock helper function (above) to\r | |
520 | simplify the job. Currently not implemented.\r | |
521 | \r | |
522 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
523 | @param[in] Configuration A null-terminated Unicode string in\r | |
524 | <ConfigString> format.\r | |
525 | @param[out] Progress A pointer to a string filled in with the\r | |
526 | offset of the most recent '&' before the\r | |
527 | first failing name / value pair (or the\r | |
528 | beginn ing of the string if the failure\r | |
529 | is in the first name / value pair) or\r | |
530 | the terminating NULL if all was\r | |
531 | successful.\r | |
532 | \r | |
533 | @retval EFI_SUCCESS The results have been distributed or are\r | |
534 | awaiting distribution.\r | |
535 | @retval EFI_OUT_OF_MEMORY Not enough memory to store the\r | |
536 | parts of the results that must be\r | |
537 | stored awaiting possible future\r | |
538 | protocols.\r | |
539 | @retval EFI_INVALID_PARAMETERS Passing in a NULL for the\r | |
540 | Results parameter would result\r | |
541 | in this type of error.\r | |
542 | @retval EFI_NOT_FOUND Target for the specified routing data\r | |
543 | was not found.\r | |
544 | **/\r | |
545 | EFI_STATUS\r | |
546 | EFIAPI\r | |
547 | Ip4DeviceRouteConfig (\r | |
548 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
549 | IN CONST EFI_STRING Configuration,\r | |
550 | OUT EFI_STRING *Progress\r | |
551 | )\r | |
552 | {\r | |
553 | EFI_STATUS Status;\r | |
554 | UINTN BufferSize;\r | |
555 | NIC_IP4_CONFIG_INFO *IfrDeviceNvData;\r | |
c22b6cdf | 556 | IP4_CONFIG_IFR_NVDATA *IfrFormNvData;\r |
391a0724 | 557 | NIC_IP4_CONFIG_INFO *NicInfo;\r |
63886849 | 558 | IP4_CONFIG_INSTANCE *Ip4ConfigInstance;\r |
559 | EFI_MAC_ADDRESS ZeroMac;\r | |
560 | \r | |
d80ea739 | 561 | if (Configuration == NULL || Progress == NULL) {\r |
63886849 | 562 | return EFI_INVALID_PARAMETER;\r |
563 | }\r | |
564 | \r | |
74df5026 | 565 | //\r |
566 | // Reclaim Ip4Config variable\r | |
567 | //\r | |
568 | Ip4ConfigReclaimVariable ();\r | |
569 | \r | |
63886849 | 570 | *Progress = Configuration;\r |
571 | \r | |
d80ea739 | 572 | Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);\r |
63886849 | 573 | \r |
574 | //\r | |
d80ea739 | 575 | // Check Routing data in <ConfigHdr>.\r |
63886849 | 576 | //\r |
d80ea739 | 577 | if (HiiIsConfigHdrMatch (Configuration, &mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r |
578 | //\r | |
579 | // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r | |
580 | //\r | |
581 | IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA));\r | |
582 | if (IfrFormNvData == NULL) {\r | |
583 | return EFI_OUT_OF_RESOURCES;\r | |
63886849 | 584 | }\r |
63886849 | 585 | \r |
d80ea739 | 586 | BufferSize = NIC_ITEM_CONFIG_SIZE;\r |
587 | Status = gHiiConfigRouting->ConfigToBlock (\r | |
588 | gHiiConfigRouting,\r | |
589 | Configuration,\r | |
590 | (UINT8 *) IfrFormNvData,\r | |
591 | &BufferSize,\r | |
592 | Progress\r | |
593 | );\r | |
594 | if (!EFI_ERROR (Status)) {\r | |
74df5026 | 595 | Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);\r |
d80ea739 | 596 | }\r |
c22b6cdf | 597 | \r |
d80ea739 | 598 | FreePool (IfrFormNvData);\r |
63886849 | 599 | \r |
d80ea739 | 600 | } else if (HiiIsConfigHdrMatch (Configuration, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r |
63886849 | 601 | \r |
d80ea739 | 602 | IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r |
603 | if (IfrDeviceNvData == NULL) {\r | |
604 | return EFI_OUT_OF_RESOURCES;\r | |
605 | }\r | |
63886849 | 606 | \r |
d80ea739 | 607 | BufferSize = NIC_ITEM_CONFIG_SIZE;\r |
608 | Status = gHiiConfigRouting->ConfigToBlock (\r | |
609 | gHiiConfigRouting,\r | |
610 | Configuration,\r | |
611 | (UINT8 *) IfrDeviceNvData,\r | |
612 | &BufferSize,\r | |
613 | Progress\r | |
614 | );\r | |
615 | if (!EFI_ERROR (Status)) {\r | |
616 | ZeroMem (&ZeroMac, sizeof (EFI_MAC_ADDRESS));\r | |
617 | if (CompareMem (&IfrDeviceNvData->NicAddr.MacAddr, &ZeroMac, IfrDeviceNvData->NicAddr.Len) != 0) {\r | |
74df5026 | 618 | BufferSize = SIZEOF_NIC_IP4_CONFIG_INFO (IfrDeviceNvData);\r |
c22b6cdf | 619 | NicInfo = AllocateCopyPool (BufferSize, IfrDeviceNvData);\r |
74df5026 | 620 | if (NicInfo == NULL) {\r |
621 | return EFI_OUT_OF_RESOURCES;\r | |
622 | }\r | |
d80ea739 | 623 | Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE);\r |
74df5026 | 624 | FreePool (NicInfo);\r |
d80ea739 | 625 | } else {\r |
c22b6cdf | 626 | ZeroMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo, sizeof (IP4_SETTING_INFO));\r |
d80ea739 | 627 | Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE);\r |
628 | }\r | |
629 | }\r | |
63886849 | 630 | \r |
d80ea739 | 631 | FreePool (IfrDeviceNvData);\r |
63886849 | 632 | \r |
d80ea739 | 633 | } else {\r |
ae79d2f9 | 634 | \r |
ae79d2f9 LG |
635 | return EFI_NOT_FOUND;\r |
636 | }\r | |
c22b6cdf | 637 | \r |
d80ea739 | 638 | return Status;\r |
ae79d2f9 | 639 | \r |
63886849 | 640 | }\r |
641 | \r | |
642 | /**\r | |
643 | This function is called to provide results data to the driver.\r | |
644 | This data consists of a unique key that is used to identify\r | |
645 | which data is either being passed back or being asked for.\r | |
646 | \r | |
647 | @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r | |
648 | @param[in] Action Specifies the type of action taken by the browser.\r | |
649 | @param[in] QuestionId A unique value which is sent to the original\r | |
650 | exporting driver so that it can identify the type\r | |
651 | of data to expect. The format of the data tends to\r | |
652 | vary based on the opcode that enerated the callback.\r | |
653 | @param[in] Type The type of value for the question.\r | |
654 | @param[in] Value A pointer to the data being sent to the original\r | |
655 | exporting driver.\r | |
656 | @param[out] ActionRequest On return, points to the action requested by the\r | |
657 | callback function.\r | |
658 | \r | |
659 | @retval EFI_SUCCESS The callback successfully handled the action.\r | |
660 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r | |
661 | variable and its data.\r | |
662 | @retval EFI_DEVICE_ERROR The variable could not be saved.\r | |
663 | @retval EFI_UNSUPPORTED The specified Action is not supported by the\r | |
664 | callback.Currently not implemented.\r | |
665 | @retval EFI_INVALID_PARAMETERS Passing in wrong parameter.\r | |
666 | @retval Others Other errors as indicated.\r | |
667 | **/\r | |
668 | EFI_STATUS\r | |
669 | EFIAPI\r | |
670 | Ip4FormCallback (\r | |
671 | IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r | |
672 | IN EFI_BROWSER_ACTION Action,\r | |
673 | IN EFI_QUESTION_ID QuestionId,\r | |
674 | IN UINT8 Type,\r | |
675 | IN EFI_IFR_TYPE_VALUE *Value,\r | |
676 | OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r | |
677 | )\r | |
678 | {\r | |
679 | IP4_CONFIG_INSTANCE *Ip4ConfigInstance;\r | |
63886849 | 680 | IP4_CONFIG_IFR_NVDATA *IfrFormNvData;\r |
63886849 | 681 | EFI_IP_ADDRESS HostIp;\r |
682 | EFI_IP_ADDRESS SubnetMask;\r | |
683 | EFI_IP_ADDRESS Gateway;\r | |
684 | EFI_STATUS Status;\r | |
685 | EFI_INPUT_KEY Key;\r | |
63886849 | 686 | \r |
74df5026 | 687 | if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {\r |
5adb8db7 LG |
688 | //\r |
689 | // Do nothing for UEFI OPEN/CLOSE Action\r | |
690 | //\r | |
74df5026 | 691 | return EFI_SUCCESS;\r |
5adb8db7 LG |
692 | }\r |
693 | \r | |
d80ea739 | 694 | Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_CONFIG_ACCESS (This);\r |
63886849 | 695 | \r |
696 | IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA));\r | |
697 | if (IfrFormNvData == NULL) {\r | |
698 | return EFI_OUT_OF_RESOURCES;\r | |
699 | }\r | |
700 | \r | |
701 | //\r | |
702 | // Retrive uncommitted data from Browser\r | |
703 | //\r | |
d80ea739 | 704 | if (!HiiGetBrowserData (&mNicIp4ConfigNvDataGuid, EFI_NIC_IP4_CONFIG_VARIABLE, sizeof (IP4_CONFIG_IFR_NVDATA), (UINT8 *) IfrFormNvData)) {\r |
63886849 | 705 | FreePool (IfrFormNvData);\r |
706 | return EFI_NOT_FOUND;\r | |
707 | }\r | |
708 | \r | |
709 | Status = EFI_SUCCESS;\r | |
710 | \r | |
711 | switch (QuestionId) {\r | |
63886849 | 712 | case KEY_LOCAL_IP:\r |
74df5026 | 713 | Status = Ip4StrToIp (IfrFormNvData->StationAddress, &HostIp.v4);\r |
f6b7393c | 714 | if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r |
63886849 | 715 | CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r |
716 | Status = EFI_INVALID_PARAMETER;\r | |
717 | } else {\r | |
d80ea739 | 718 | CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.LocalIp, &HostIp.v4, sizeof (HostIp.v4));\r |
63886849 | 719 | }\r |
720 | \r | |
721 | break;\r | |
722 | \r | |
723 | case KEY_SUBNET_MASK:\r | |
74df5026 | 724 | Status = Ip4StrToIp (IfrFormNvData->SubnetMask, &SubnetMask.v4);\r |
63886849 | 725 | if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {\r |
74df5026 | 726 | CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Subnet Mask!", NULL);\r |
63886849 | 727 | Status = EFI_INVALID_PARAMETER;\r |
728 | } else {\r | |
d80ea739 | 729 | CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));\r |
63886849 | 730 | }\r |
731 | \r | |
732 | break;\r | |
733 | \r | |
734 | case KEY_GATE_WAY:\r | |
74df5026 | 735 | Status = Ip4StrToIp (IfrFormNvData->GatewayAddress, &Gateway.v4);\r |
f6b7393c | 736 | if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r |
63886849 | 737 | CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r |
738 | Status = EFI_INVALID_PARAMETER;\r | |
739 | } else {\r | |
d80ea739 | 740 | CopyMem (&Ip4ConfigInstance->Ip4ConfigCallbackInfo.Gateway, &Gateway.v4, sizeof (Gateway.v4));\r |
63886849 | 741 | }\r |
742 | \r | |
743 | break;\r | |
744 | \r | |
745 | case KEY_SAVE_CHANGES:\r | |
74df5026 | 746 | Status = Ip4ConfigConvertIfrNvDataToDeviceConfigData (IfrFormNvData, Ip4ConfigInstance);\r |
63886849 | 747 | *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r |
748 | break;\r | |
749 | \r | |
750 | default:\r | |
63886849 | 751 | break;\r |
752 | }\r | |
753 | \r | |
63886849 | 754 | FreePool (IfrFormNvData);\r |
d80ea739 | 755 | \r |
63886849 | 756 | return Status;\r |
757 | }\r | |
758 | \r | |
759 | /**\r | |
760 | Install HII Config Access protocol for network device and allocate resource.\r | |
761 | \r | |
762 | @param[in] Instance The IP4 Config instance.\r | |
763 | \r | |
764 | @retval EFI_SUCCESS The HII Config Access protocol is installed.\r | |
765 | @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r | |
766 | @retval Others Other errors as indicated.\r | |
767 | **/\r | |
768 | EFI_STATUS\r | |
769 | Ip4ConfigDeviceInit (\r | |
d80ea739 | 770 | IN IP4_CONFIG_INSTANCE *Instance\r |
63886849 | 771 | )\r |
772 | {\r | |
d80ea739 | 773 | EFI_STATUS Status;\r |
774 | EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r | |
775 | VENDOR_DEVICE_PATH VendorDeviceNode;\r | |
776 | EFI_SERVICE_BINDING_PROTOCOL *MnpSb;\r | |
777 | CHAR16 *MacString;\r | |
778 | CHAR16 MenuString[128];\r | |
779 | CHAR16 PortString[128];\r | |
780 | CHAR16 *OldMenuString;\r | |
63886849 | 781 | \r |
d80ea739 | 782 | ConfigAccess = &Instance->HiiConfigAccessProtocol;\r |
783 | ConfigAccess->ExtractConfig = Ip4DeviceExtractConfig;\r | |
784 | ConfigAccess->RouteConfig = Ip4DeviceRouteConfig;\r | |
785 | ConfigAccess->Callback = Ip4FormCallback;\r | |
63886849 | 786 | \r |
d80ea739 | 787 | //\r |
788 | // Construct device path node for EFI HII Config Access protocol,\r | |
789 | // which consists of controller physical device path and one hardware\r | |
790 | // vendor guid node.\r | |
791 | //\r | |
792 | ZeroMem (&VendorDeviceNode, sizeof (VENDOR_DEVICE_PATH));\r | |
793 | VendorDeviceNode.Header.Type = HARDWARE_DEVICE_PATH;\r | |
794 | VendorDeviceNode.Header.SubType = HW_VENDOR_DP;\r | |
63886849 | 795 | \r |
d80ea739 | 796 | CopyGuid (&VendorDeviceNode.Guid, &gEfiNicIp4ConfigVariableGuid);\r |
63886849 | 797 | \r |
d80ea739 | 798 | SetDevicePathNodeLength (&VendorDeviceNode.Header, sizeof (VENDOR_DEVICE_PATH));\r |
799 | Instance->HiiVendorDevicePath = AppendDevicePathNode (\r | |
800 | Instance->ParentDevicePath,\r | |
801 | (EFI_DEVICE_PATH_PROTOCOL *) &VendorDeviceNode\r | |
802 | );\r | |
63886849 | 803 | \r |
d80ea739 | 804 | Instance->ChildHandle = NULL;\r |
63886849 | 805 | //\r |
d80ea739 | 806 | // Install Device Path Protocol and Config Access protocol on new handle\r |
63886849 | 807 | //\r |
808 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
d80ea739 | 809 | &Instance->ChildHandle,\r |
810 | &gEfiDevicePathProtocolGuid,\r | |
c22b6cdf | 811 | Instance->HiiVendorDevicePath,\r |
63886849 | 812 | &gEfiHiiConfigAccessProtocolGuid,\r |
d80ea739 | 813 | ConfigAccess,\r |
63886849 | 814 | NULL\r |
815 | );\r | |
d80ea739 | 816 | if (!EFI_ERROR (Status)) {\r |
817 | //\r | |
818 | // Open the Parent Handle for the child\r | |
819 | //\r | |
820 | Status = gBS->OpenProtocol (\r | |
821 | Instance->Controller,\r | |
822 | &gEfiManagedNetworkServiceBindingProtocolGuid,\r | |
823 | (VOID **) &MnpSb,\r | |
824 | Instance->Image,\r | |
c22b6cdf | 825 | Instance->ChildHandle,\r |
d80ea739 | 826 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r |
827 | );\r | |
828 | }\r | |
829 | \r | |
63886849 | 830 | ASSERT_EFI_ERROR (Status);\r |
c22b6cdf | 831 | \r |
d80ea739 | 832 | //\r |
833 | // Publish our HII data\r | |
834 | //\r | |
835 | Instance->RegisteredHandle = HiiAddPackages (\r | |
836 | &mNicIp4ConfigNvDataGuid,\r | |
837 | Instance->ChildHandle,\r | |
838 | Ip4ConfigDxeStrings,\r | |
839 | Ip4ConfigDxeBin,\r | |
840 | NULL\r | |
841 | );\r | |
842 | if (Instance->RegisteredHandle == NULL) {\r | |
843 | return EFI_OUT_OF_RESOURCES;\r | |
844 | }\r | |
845 | \r | |
846 | //\r | |
847 | // Append MAC string in the menu string and tile string\r | |
848 | //\r | |
849 | Status = NetLibGetMacString (Instance->Controller, Instance->Image, &MacString);\r | |
850 | if (!EFI_ERROR (Status)) {\r | |
851 | OldMenuString = HiiGetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE), NULL);\r | |
852 | UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);\r | |
853 | HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_CONFIG_FORM_TITLE), MenuString, NULL);\r | |
c22b6cdf | 854 | \r |
d80ea739 | 855 | UnicodeSPrint (PortString, 128, L"MAC:%s", MacString);\r |
856 | HiiSetString (Instance->RegisteredHandle, STRING_TOKEN (STR_IP4_DEVICE_FORM_TITLE), PortString, NULL);\r | |
857 | FreePool (MacString);\r | |
858 | }\r | |
63886849 | 859 | \r |
860 | return Status;\r | |
861 | }\r | |
862 | \r | |
863 | /**\r | |
864 | Uninstall HII Config Access protocol for network device and free resource.\r | |
865 | \r | |
866 | @param[in] Instance The IP4 Config instance.\r | |
867 | \r | |
868 | @retval EFI_SUCCESS The HII Config Access protocol is uninstalled.\r | |
869 | @retval Others Other errors as indicated.\r | |
870 | **/\r | |
871 | EFI_STATUS\r | |
872 | Ip4ConfigDeviceUnload (\r | |
873 | IN IP4_CONFIG_INSTANCE *Instance\r | |
874 | )\r | |
875 | {\r | |
63886849 | 876 | //\r |
d80ea739 | 877 | // Remove HII package list\r |
63886849 | 878 | //\r |
d80ea739 | 879 | HiiRemovePackages (Instance->RegisteredHandle);\r |
63886849 | 880 | \r |
881 | //\r | |
d80ea739 | 882 | // Close the child handle\r |
63886849 | 883 | //\r |
d80ea739 | 884 | gBS->CloseProtocol (\r |
885 | Instance->Controller,\r | |
886 | &gEfiManagedNetworkServiceBindingProtocolGuid,\r | |
887 | Instance->Image,\r | |
888 | Instance->ChildHandle\r | |
889 | );\r | |
63886849 | 890 | \r |
891 | //\r | |
892 | // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL\r | |
893 | //\r | |
894 | gBS->UninstallMultipleProtocolInterfaces (\r | |
d80ea739 | 895 | Instance->ChildHandle,\r |
63886849 | 896 | &gEfiDevicePathProtocolGuid,\r |
c22b6cdf | 897 | Instance->HiiVendorDevicePath,\r |
63886849 | 898 | &gEfiHiiConfigAccessProtocolGuid,\r |
d80ea739 | 899 | &Instance->HiiConfigAccessProtocol,\r |
63886849 | 900 | NULL\r |
901 | );\r | |
902 | \r | |
63886849 | 903 | return EFI_SUCCESS;\r |
904 | }\r |