]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigNv.c
Define macro for .global/.globl in assembly.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4ConfigDxe / Ip4ConfigNv.c
CommitLineData
63886849 1/** @file\r
2 Helper functions for configuring or getting the parameters relating to Ip4.\r
3\r
4Copyright (c) 2009, Intel Corporation.<BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "Ip4ConfigNv.h"\r
16\r
17GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Ip4HexString[] = "0123456789ABCDEFabcdef";\r
18\r
19UINTN mNumberOfIp4Devices = 0;\r
20\r
21IP4_FORM_CALLBACK_INFO *mCallbackInfo = NULL;\r
22\r
23LIST_ENTRY mIp4ConfigFormList = {\r
24 &mIp4ConfigFormList,\r
25 &mIp4ConfigFormList\r
26};\r
27\r
28HII_VENDOR_DEVICE_PATH mIp4ConifgHiiVendorDevicePath = {\r
29 {\r
30 {\r
31 HARDWARE_DEVICE_PATH,\r
32 HW_VENDOR_DP,\r
33 {\r
34 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
35 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
36 }\r
37 },\r
38 //\r
39 // {6D3FD906-42B9-4220-9E63-9D8C972D58EE}\r
40 //\r
41 { 0x6d3fd906, 0x42b9, 0x4220, { 0x9e, 0x63, 0x9d, 0x8c, 0x97, 0x2d, 0x58, 0xee } }\r
42 },\r
43 {\r
44 END_DEVICE_PATH_TYPE,\r
45 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
46 {\r
47 (UINT8) (END_DEVICE_PATH_LENGTH),\r
48 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
49 }\r
50 }\r
51};\r
52\r
53/**\r
54 Convert the mac address into a hexadecimal encoded "-" seperated string.\r
55\r
56 @param[in] Mac The mac address.\r
57 @param[in] Len Length in bytes of the mac address.\r
58 @param[out] Str The storage to return the mac string.\r
59\r
60**/\r
61VOID\r
62Ip4MacAddrToStr (\r
63 IN EFI_MAC_ADDRESS *Mac,\r
64 IN UINT32 Len,\r
65 OUT CHAR16 *Str\r
66 )\r
67{\r
68 UINT32 Index;\r
69\r
70 for (Index = 0; Index < Len; Index++) {\r
71 Str[3 * Index] = (CHAR16) Ip4HexString[(Mac->Addr[Index] >> 4) & 0x0F];\r
72 Str[3 * Index + 1] = (CHAR16) Ip4HexString[Mac->Addr[Index] & 0x0F];\r
73 Str[3 * Index + 2] = L'-';\r
74 }\r
75\r
76 Str[3 * Index - 1] = L'\0';\r
77}\r
78\r
79/**\r
80 Calculate the prefix length of the IPv4 subnet mask.\r
81\r
82 @param[in] SubnetMask The IPv4 subnet mask.\r
83\r
84 @return The prefix length of the subnet mask.\r
85 @retval 0 Other errors as indicated.\r
86**/\r
87UINT8\r
88GetSubnetMaskPrefixLength (\r
89 IN EFI_IPv4_ADDRESS *SubnetMask\r
90 )\r
91{\r
92 UINT8 Len;\r
93 UINT32 ReverseMask;\r
94\r
95 //\r
96 // The SubnetMask is in network byte order.\r
97 //\r
98 ReverseMask = (SubnetMask->Addr[0] << 24) | (SubnetMask->Addr[1] << 16) | (SubnetMask->Addr[2] << 8) | (SubnetMask->Addr[3]);\r
99\r
100 //\r
101 // Reverse it.\r
102 //\r
103 ReverseMask = ~ReverseMask;\r
104\r
105 if ((ReverseMask & (ReverseMask + 1)) != 0) {\r
106 return 0;\r
107 }\r
108\r
109 Len = 0;\r
110\r
111 while (ReverseMask != 0) {\r
112 ReverseMask = ReverseMask >> 1;\r
113 Len++;\r
114 }\r
115\r
116 return (UINT8) (32 - Len);\r
117}\r
118\r
119/**\r
120 Convert the decimal dotted IPv4 address into the binary IPv4 address.\r
121\r
122 @param[in] Str The UNICODE string.\r
123 @param[out] Ip The storage to return the ASCII string.\r
124\r
125 @retval EFI_SUCCESS The binary IP address is returned in Ip.\r
126 @retval EFI_INVALID_PARAMETER The IP string is malformatted.\r
127**/\r
128EFI_STATUS\r
129Ip4AsciiStrToIp (\r
130 IN CHAR8 *Str,\r
131 OUT EFI_IPv4_ADDRESS *Ip\r
132 )\r
133{\r
134 UINTN Index;\r
135 UINTN Number;\r
136\r
137 Index = 0;\r
138\r
139 while (*Str != 0) {\r
140\r
141 if (Index > 3) {\r
142 return EFI_INVALID_PARAMETER;\r
143 }\r
144\r
145 Number = 0;\r
146 while (NET_IS_DIGIT (*Str)) {\r
147 Number = Number * 10 + (*Str - '0');\r
148 Str++;\r
149 }\r
150\r
151 if (Number > 0xFF) {\r
152 return EFI_INVALID_PARAMETER;\r
153 }\r
154\r
155 Ip->Addr[Index] = (UINT8) Number;\r
156\r
157 if ((*Str != '\0') && (*Str != '.')) {\r
158 //\r
159 // The current character should be either the NULL terminator or\r
160 // the dot delimiter.\r
161 //\r
162 return EFI_INVALID_PARAMETER;\r
163 }\r
164\r
165 if (*Str == '.') {\r
166 //\r
167 // Skip the delimiter.\r
168 //\r
169 Str++;\r
170 }\r
171\r
172 Index++;\r
173 }\r
174\r
175 if (Index != 4) {\r
176 return EFI_INVALID_PARAMETER;\r
177 }\r
178\r
179 return EFI_SUCCESS;\r
180}\r
181\r
182/**\r
183 Convert the IPv4 address into a dotted string.\r
184\r
185 @param[in] Ip The IPv4 address.\r
186 @param[out] Str The dotted IP string.\r
187**/\r
188VOID\r
189Ip4ConfigIpToStr (\r
190 IN EFI_IPv4_ADDRESS *Ip,\r
191 OUT CHAR16 *Str\r
192 )\r
193{\r
194 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
195}\r
196\r
197\r
198/**\r
199 Convert the network configuration data into the IFR data.\r
200\r
201 @param[in] ConfigFormEntry The IP4 configuration form entry.\r
202 @param[out] IfrNvData The IFR nv data.\r
203**/\r
204VOID\r
205Ip4ConfigConvertDeviceConfigDataToIfrNvData (\r
206 IN IP4_CONFIG_INSTANCE *Ip4ConfigInstance,\r
207 OUT IP4_CONFIG_IFR_NVDATA *IfrFormNvData\r
208 )\r
209{\r
210 EFI_STATUS Status;\r
211 NIC_IP4_CONFIG_INFO *NicConfig;\r
212 UINTN ConfigLen;\r
213\r
214 IfrFormNvData->DhcpEnable = 1;\r
215\r
216 ConfigLen = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * 2;\r
217 NicConfig = AllocateZeroPool (ConfigLen);\r
218 ASSERT (NicConfig != NULL);\r
219 Status = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance, &ConfigLen, NicConfig);\r
220 if (!EFI_ERROR (Status)) {\r
221 if (NicConfig->Source == IP4_CONFIG_SOURCE_DHCP) {\r
222 IfrFormNvData->DhcpEnable = 1;\r
223 } else {\r
224 IfrFormNvData->DhcpEnable = 0;\r
225 Ip4ConfigIpToStr (&NicConfig->Ip4Info.StationAddress, IfrFormNvData->StationAddress);\r
226 Ip4ConfigIpToStr (&NicConfig->Ip4Info.SubnetMask, IfrFormNvData->SubnetMask);\r
227 Ip4ConfigIpToStr (&NicConfig->Ip4Info.RouteTable[1].GatewayAddress, IfrFormNvData->GatewayAddress);\r
228 }\r
229 }\r
230 FreePool (NicConfig);\r
231}\r
232\r
233/**\r
234 Get the IP4 configuration form entry by the index of the goto opcode actived.\r
235\r
236 @param[in] Index The 0-based index of the goto opcode actived.\r
237\r
238 @return The IP4 configuration form entry found.\r
239**/\r
240IP4CONFIG_FORM_ENTRY *\r
241Ip4GetConfigFormEntryByIndex (\r
242 IN UINT32 Index\r
243 )\r
244{\r
245 UINT32 CurrentIndex;\r
246 LIST_ENTRY *Entry;\r
247 IP4CONFIG_FORM_ENTRY *ConfigFormEntry;\r
248\r
249 CurrentIndex = 0;\r
250 ConfigFormEntry = NULL;\r
251\r
252 NET_LIST_FOR_EACH (Entry, &mIp4ConfigFormList) {\r
253 if (CurrentIndex == Index) {\r
254 ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, IP4CONFIG_FORM_ENTRY, Link);\r
255 break;\r
256 }\r
257\r
258 CurrentIndex++;\r
259 }\r
260\r
261 return ConfigFormEntry;\r
262}\r
263\r
264/**\r
265 This function allows the caller to request the current\r
266 configuration for one or more named elements. The resulting\r
267 string is in <ConfigAltResp> format. Any and all alternative\r
268 configuration strings shall also be appended to the end of the\r
269 current configuration string. If they are, they must appear\r
270 after the current configuration. They must contain the same\r
271 routing (GUID, NAME, PATH) as the current configuration string.\r
272 They must have an additional description indicating the type of\r
273 alternative configuration the string represents,\r
274 "ALTCFG=<StringToken>". That <StringToken> (when\r
275 converted from Hex UNICODE to binary) is a reference to a\r
276 string in the associated string pack.\r
277\r
278 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
279 @param[in] Request A null-terminated Unicode string in\r
280 <ConfigRequest> format. Note that this\r
281 includes the routing information as well as\r
282 the configurable name / value pairs. It is\r
283 invalid for this string to be in\r
284 <MultiConfigRequest> format.\r
285 @param[out] Progress On return, points to a character in the\r
286 Request string. Points to the string's null\r
287 terminator if request was successful. Points\r
288 to the most recent "&" before the first\r
289 failing name / value pair (or the beginning\r
290 of the string if the failure is in the first\r
291 name / value pair) if the request was not\r
292 successful.\r
293 @param[out] Results A null-terminated Unicode string in\r
294 <ConfigAltResp> format which has all values\r
295 filled in for the names in the Request string.\r
296 String to be allocated by the called function.\r
297\r
298 @retval EFI_SUCCESS The Results string is filled with the\r
299 values corresponding to all requested\r
300 names.\r
301 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the\r
302 parts of the results that must be\r
303 stored awaiting possible future\r
304 protocols.\r
305 @retval EFI_INVALID_PARAMETER For example, passing in a NULL\r
306 for the Request parameter\r
307 would result in this type of\r
308 error. In this case, the\r
309 Progress parameter would be\r
310 set to NULL.\r
311 @retval EFI_NOT_FOUND Routing data doesn't match any\r
312 known driver. Progress set to the\r
313 first character in the routing header.\r
314 Note: There is no requirement that the\r
315 driver validate the routing data. It\r
316 must skip the <ConfigHdr> in order to\r
317 process the names.\r
318 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set\r
319 to most recent & before the\r
320 error or the beginning of the\r
321 string.\r
322 @retval EFI_INVALID_PARAMETER Unknown name. Progress points\r
323 to the & before the name in\r
324 question.Currently not implemented.\r
325**/\r
326EFI_STATUS\r
327EFIAPI\r
328Ip4DeviceExtractConfig (\r
329 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
330 IN CONST EFI_STRING Request,\r
331 OUT EFI_STRING *Progress,\r
332 OUT EFI_STRING *Results\r
333 )\r
334{\r
335 EFI_STATUS Status;\r
336 UINTN ConfigLen;\r
337 NIC_IP4_CONFIG_INFO *IfrDeviceNvData;\r
338 IP4_FORM_CALLBACK_INFO *Private;\r
339 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r
340 IP4_CONFIG_INSTANCE *Ip4ConfigInstance;\r
341\r
342 if (Request == NULL) {\r
343 return EFI_INVALID_PARAMETER;\r
344 }\r
345\r
346 *Progress = Request;\r
347\r
391a0724 348 //\r
349 // Check Request data in <ConfigHdr>.\r
350 //\r
351 if (!HiiIsConfigHdrMatch (Request, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r
352 return EFI_NOT_FOUND;\r
353 }\r
354\r
63886849 355 Private = IP4CONFIG_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);\r
356 Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_IP4FORM_CALLBACK_INFO (Private);\r
357\r
358 IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
359 if (IfrDeviceNvData == NULL) {\r
360 return EFI_OUT_OF_RESOURCES;\r
361 }\r
362\r
363 Status = EfiNicIp4ConfigGetInfo (Ip4ConfigInstance, &ConfigLen, IfrDeviceNvData);\r
364 if (EFI_ERROR (Status)) {\r
365 FreePool (IfrDeviceNvData);\r
366 return EFI_NOT_FOUND;\r
367 }\r
368\r
369 //\r
370 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
371 //\r
372 HiiConfigRouting = Private->ConfigRouting;\r
373 Status = HiiConfigRouting->BlockToConfig (\r
374 HiiConfigRouting,\r
375 Request,\r
376 (UINT8 *) IfrDeviceNvData,\r
377 NIC_ITEM_CONFIG_SIZE,\r
378 Results,\r
379 Progress\r
380 );\r
381\r
63886849 382 FreePool (IfrDeviceNvData);\r
383\r
384 return Status;\r
385}\r
386\r
387/**\r
388 This function applies changes in a driver's configuration.\r
389 Input is a Configuration, which has the routing data for this\r
390 driver followed by name / value configuration pairs. The driver\r
391 must apply those pairs to its configurable storage. If the\r
392 driver's configuration is stored in a linear block of data\r
393 and the driver's name / value pairs are in <BlockConfig>\r
394 format, it may use the ConfigToBlock helper function (above) to\r
395 simplify the job. Currently not implemented.\r
396\r
397 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
398 @param[in] Configuration A null-terminated Unicode string in\r
399 <ConfigString> format.\r
400 @param[out] Progress A pointer to a string filled in with the\r
401 offset of the most recent '&' before the\r
402 first failing name / value pair (or the\r
403 beginn ing of the string if the failure\r
404 is in the first name / value pair) or\r
405 the terminating NULL if all was\r
406 successful.\r
407\r
408 @retval EFI_SUCCESS The results have been distributed or are\r
409 awaiting distribution.\r
410 @retval EFI_OUT_OF_MEMORY Not enough memory to store the\r
411 parts of the results that must be\r
412 stored awaiting possible future\r
413 protocols.\r
414 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the\r
415 Results parameter would result\r
416 in this type of error.\r
417 @retval EFI_NOT_FOUND Target for the specified routing data\r
418 was not found.\r
419**/\r
420EFI_STATUS\r
421EFIAPI\r
422Ip4DeviceRouteConfig (\r
423 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
424 IN CONST EFI_STRING Configuration,\r
425 OUT EFI_STRING *Progress\r
426 )\r
427{\r
428 EFI_STATUS Status;\r
429 UINTN BufferSize;\r
430 NIC_IP4_CONFIG_INFO *IfrDeviceNvData;\r
391a0724 431 NIC_IP4_CONFIG_INFO *NicInfo;\r
63886849 432 IP4_FORM_CALLBACK_INFO *Private;\r
433 EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;\r
434 IP4_CONFIG_INSTANCE *Ip4ConfigInstance;\r
435 EFI_MAC_ADDRESS ZeroMac;\r
436\r
437 if (Configuration == NULL) {\r
438 return EFI_INVALID_PARAMETER;\r
439 }\r
440\r
441 *Progress = Configuration;\r
442\r
391a0724 443 //\r
444 // Check Routing data in <ConfigHdr>.\r
445 //\r
446 if (!HiiIsConfigHdrMatch (Configuration, &gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE)) {\r
447 return EFI_NOT_FOUND;\r
448 }\r
449\r
63886849 450 Private = IP4CONFIG_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);\r
451 Ip4ConfigInstance = IP4_CONFIG_INSTANCE_FROM_IP4FORM_CALLBACK_INFO (Private);\r
452\r
453 IfrDeviceNvData = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
454 if (IfrDeviceNvData == NULL) {\r
455 return EFI_OUT_OF_RESOURCES;\r
456 }\r
457\r
458 //\r
459 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()\r
460 //\r
461 HiiConfigRouting = Private->ConfigRouting;\r
462 BufferSize = NIC_ITEM_CONFIG_SIZE;\r
463 Status = HiiConfigRouting->ConfigToBlock (\r
464 HiiConfigRouting,\r
465 Configuration,\r
466 (UINT8 *) IfrDeviceNvData,\r
467 &BufferSize,\r
468 Progress\r
469 );\r
470 if (!EFI_ERROR (Status)) {\r
471 ZeroMem (&ZeroMac, sizeof (EFI_MAC_ADDRESS));\r
472 if (CompareMem (&IfrDeviceNvData->NicAddr.MacAddr, &ZeroMac, IfrDeviceNvData->NicAddr.Len) != 0) {\r
391a0724 473 BufferSize = sizeof (NIC_IP4_CONFIG_INFO) + sizeof (EFI_IP4_ROUTE_TABLE) * IfrDeviceNvData->Ip4Info.RouteTableSize;\r
474 NicInfo = AllocateCopyPool (BufferSize, IfrDeviceNvData); \r
475 Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE);\r
63886849 476 } else {\r
477 Status = EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NULL, TRUE);\r
478 }\r
479 }\r
480\r
63886849 481 FreePool (IfrDeviceNvData);\r
482 return Status;\r
483\r
484}\r
485\r
486/**\r
487 This function allows the caller to request the current\r
488 configuration for one or more named elements. The resulting\r
489 string is in <ConfigAltResp> format. Any and all alternative\r
490 configuration strings shall also be appended to the end of the\r
491 current configuration string. If they are, they must appear\r
492 after the current configuration. They must contain the same\r
493 routing (GUID, NAME, PATH) as the current configuration string.\r
494 They must have an additional description indicating the type of\r
495 alternative configuration the string represents,\r
496 "ALTCFG=<StringToken>". That <StringToken> (when\r
497 converted from Hex UNICODE to binary) is a reference to a\r
498 string in the associated string pack.\r
499\r
500 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
501 @param[in] Request A null-terminated Unicode string in\r
502 <ConfigRequest> format. Note that this\r
503 includes the routing information as well as\r
504 the configurable name / value pairs. It is\r
505 invalid for this string to be in\r
506 <MultiConfigRequest> format.\r
507 @param[out] Progress On return, points to a character in the\r
508 Request string. Points to the string's null\r
509 terminator if request was successful. Points\r
510 to the most recent "&" before the first\r
511 failing name / value pair (or the beginning\r
512 of the string if the failure is in the first\r
513 name / value pair) if the request was not\r
514 successful.\r
515 @param[out] Results A null-terminated Unicode string in\r
516 <ConfigAltResp> format which has all values\r
517 filled in for the names in the Request string.\r
518 String to be allocated by the called function.\r
519\r
520 @retval EFI_SUCCESS The Results string is filled with the\r
521 values corresponding to all requested\r
522 names.\r
523 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the\r
524 parts of the results that must be\r
525 stored awaiting possible future\r
526 protocols.\r
527 @retval EFI_INVALID_PARAMETER For example, passing in a NULL\r
528 for the Request parameter\r
529 would result in this type of\r
530 error. In this case, the\r
531 Progress parameter would be\r
532 set to NULL.\r
533 @retval EFI_NOT_FOUND Routing data doesn't match any\r
534 known driver. Progress set to the\r
535 first character in the routing header.\r
536 Note: There is no requirement that the\r
537 driver validate the routing data. It\r
538 must skip the <ConfigHdr> in order to\r
539 process the names.\r
540 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set\r
541 to most recent & before the\r
542 error or the beginning of the\r
543 string.\r
544 @retval EFI_INVALID_PARAMETER Unknown name. Progress points\r
545 to the & before the name in\r
546 question.Currently not implemented.\r
547**/\r
548EFI_STATUS\r
549EFIAPI\r
550Ip4FormExtractConfig (\r
551 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
552 IN CONST EFI_STRING Request,\r
553 OUT EFI_STRING *Progress,\r
554 OUT EFI_STRING *Results\r
555 )\r
556{\r
391a0724 557 *Progress = Request;\r
63886849 558 return EFI_NOT_FOUND;\r
559}\r
560\r
561/**\r
562 This function applies changes in a driver's configuration.\r
563 Input is a Configuration, which has the routing data for this\r
564 driver followed by name / value configuration pairs. The driver\r
565 must apply those pairs to its configurable storage. If the\r
566 driver's configuration is stored in a linear block of data\r
567 and the driver's name / value pairs are in <BlockConfig>\r
568 format, it may use the ConfigToBlock helper function (above) to\r
569 simplify the job. Currently not implemented.\r
570\r
571 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
572 @param[in] Configuration A null-terminated Unicode string in\r
573 <ConfigString> format.\r
574 @param[out] Progress A pointer to a string filled in with the\r
575 offset of the most recent '&' before the\r
576 first failing name / value pair (or the\r
577 beginn ing of the string if the failure\r
578 is in the first name / value pair) or\r
579 the terminating NULL if all was\r
580 successful.\r
581\r
582 @retval EFI_SUCCESS The results have been distributed or are\r
583 awaiting distribution.\r
584 @retval EFI_OUT_OF_MEMORY Not enough memory to store the\r
585 parts of the results that must be\r
586 stored awaiting possible future\r
587 protocols.\r
588 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the\r
589 Results parameter would result\r
590 in this type of error.\r
591 @retval EFI_NOT_FOUND Target for the specified routing data\r
592 was not found.\r
593**/\r
594EFI_STATUS\r
595EFIAPI\r
596Ip4FormRouteConfig (\r
597 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
598 IN CONST EFI_STRING Configuration,\r
599 OUT EFI_STRING *Progress\r
600 )\r
601{\r
602 return EFI_NOT_FOUND;\r
603}\r
604\r
605/**\r
606 This function is called to provide results data to the driver.\r
607 This data consists of a unique key that is used to identify\r
608 which data is either being passed back or being asked for.\r
609\r
610 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
611 @param[in] Action Specifies the type of action taken by the browser.\r
612 @param[in] QuestionId A unique value which is sent to the original\r
613 exporting driver so that it can identify the type\r
614 of data to expect. The format of the data tends to\r
615 vary based on the opcode that enerated the callback.\r
616 @param[in] Type The type of value for the question.\r
617 @param[in] Value A pointer to the data being sent to the original\r
618 exporting driver.\r
619 @param[out] ActionRequest On return, points to the action requested by the\r
620 callback function.\r
621\r
622 @retval EFI_SUCCESS The callback successfully handled the action.\r
623 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
624 variable and its data.\r
625 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
626 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
627 callback.Currently not implemented.\r
628 @retval EFI_INVALID_PARAMETERS Passing in wrong parameter.\r
629 @retval Others Other errors as indicated.\r
630**/\r
631EFI_STATUS\r
632EFIAPI\r
633Ip4FormCallback (\r
634 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
635 IN EFI_BROWSER_ACTION Action,\r
636 IN EFI_QUESTION_ID QuestionId,\r
637 IN UINT8 Type,\r
638 IN EFI_IFR_TYPE_VALUE *Value,\r
639 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
640 )\r
641{\r
642 IP4_CONFIG_INSTANCE *Ip4ConfigInstance;\r
643 IP4_FORM_CALLBACK_INFO *Private;\r
644 CHAR8 Ip4String[IP4_STR_MAX_SIZE];\r
645 CHAR16 PortString[128];\r
646 EFI_STRING_ID DeviceFormTitleToken;\r
647 IP4_CONFIG_IFR_NVDATA *IfrFormNvData;\r
648 IP4CONFIG_FORM_ENTRY *ConfigFormEntry;\r
649 EFI_IP_ADDRESS HostIp;\r
650 EFI_IP_ADDRESS SubnetMask;\r
651 EFI_IP_ADDRESS Gateway;\r
652 EFI_STATUS Status;\r
653 EFI_INPUT_KEY Key;\r
654 NIC_IP4_CONFIG_INFO *NicInfo;\r
655 EFI_IP_ADDRESS Ip;\r
656\r
657 ConfigFormEntry = NULL;\r
658\r
659 Private = IP4CONFIG_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);\r
660\r
661 IfrFormNvData = AllocateZeroPool (sizeof (IP4_CONFIG_IFR_NVDATA));\r
662 if (IfrFormNvData == NULL) {\r
663 return EFI_OUT_OF_RESOURCES;\r
664 }\r
665\r
666 //\r
667 // Retrive uncommitted data from Browser\r
668 //\r
669 if (!HiiGetBrowserData (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, sizeof (IP4_CONFIG_IFR_NVDATA), (UINT8 *) IfrFormNvData)) {\r
670 FreePool (IfrFormNvData);\r
671 return EFI_NOT_FOUND;\r
672 }\r
673\r
674 Status = EFI_SUCCESS;\r
675\r
676 switch (QuestionId) {\r
677\r
678 case KEY_DHCP_ENABLE:\r
679 if (IfrFormNvData->DhcpEnable == 0) {\r
680 Private->Current->SessionConfigData.Enabled = FALSE;\r
681 } else {\r
682 Private->Current->SessionConfigData.Enabled = TRUE;\r
683 }\r
684\r
685 break;\r
686\r
687 case KEY_LOCAL_IP:\r
688 UnicodeStrToAsciiStr (IfrFormNvData->StationAddress, Ip4String);\r
689 Status = Ip4AsciiStrToIp (Ip4String, &HostIp.v4);\r
690 if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
691 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
692 Status = EFI_INVALID_PARAMETER;\r
693 } else {\r
694 CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4));\r
695 }\r
696\r
697 break;\r
698\r
699 case KEY_SUBNET_MASK:\r
700 UnicodeStrToAsciiStr (IfrFormNvData->SubnetMask, Ip4String);\r
701 Status = Ip4AsciiStrToIp (Ip4String, &SubnetMask.v4);\r
702 if (EFI_ERROR (Status) || ((SubnetMask.Addr[0] != 0) && (GetSubnetMaskPrefixLength (&SubnetMask.v4) == 0))) {\r
703 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid SubnetMask!", NULL);\r
704 Status = EFI_INVALID_PARAMETER;\r
705 } else {\r
706 CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));\r
707 }\r
708\r
709 break;\r
710\r
711 case KEY_GATE_WAY:\r
712 UnicodeStrToAsciiStr (IfrFormNvData->GatewayAddress, Ip4String);\r
713 Status = Ip4AsciiStrToIp (Ip4String, &Gateway.v4);\r
714 if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
715 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
716 Status = EFI_INVALID_PARAMETER;\r
717 } else {\r
718 CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4));\r
719 }\r
720\r
721 break;\r
722\r
723 case KEY_SAVE_CHANGES:\r
724 Ip4ConfigInstance = Private->Current->Ip4ConfigInstance;\r
725 NicInfo = AllocateZeroPool (sizeof (NIC_IP4_CONFIG_INFO) + 2 * sizeof (EFI_IP4_ROUTE_TABLE));\r
726 NicInfo->Ip4Info.RouteTable = (EFI_IP4_ROUTE_TABLE *) (NicInfo + 1);\r
727\r
728 if (!Private->Current->SessionConfigData.Enabled) {\r
729 CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.LocalIp, sizeof (HostIp.v4));\r
730 CopyMem (&SubnetMask.v4, &Private->Current->SessionConfigData.SubnetMask, sizeof (SubnetMask.v4));\r
731 CopyMem (&Gateway.v4, &Private->Current->SessionConfigData.Gateway, sizeof (Gateway.v4));\r
732\r
733 if ((Gateway.Addr[0] != 0)) {\r
734 if (SubnetMask.Addr[0] == 0) {\r
735 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Gateway address is set but subnet mask is zero.", NULL);\r
736 Status = EFI_INVALID_PARAMETER;\r
737 break;\r
738 } else if (!IP4_NET_EQUAL (HostIp.Addr[0], Gateway.Addr[0], SubnetMask.Addr[0])) {\r
739 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Local IP and Gateway are not in the same subnet.", NULL);\r
740 Status = EFI_INVALID_PARAMETER;\r
741 break;\r
742 }\r
743 }\r
744\r
745 NicInfo->Source = IP4_CONFIG_SOURCE_STATIC;\r
746 NicInfo->Ip4Info.RouteTableSize = 2;\r
747\r
748 CopyMem (&NicInfo->Ip4Info.StationAddress, &HostIp.v4, sizeof (EFI_IPv4_ADDRESS));\r
749 CopyMem (&NicInfo->Ip4Info.SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS));\r
750\r
751 Ip.Addr[0] = HostIp.Addr[0] & SubnetMask.Addr[0];\r
752\r
753 CopyMem (&NicInfo->Ip4Info.RouteTable[0].SubnetAddress, &Ip.v4, sizeof (EFI_IPv4_ADDRESS));\r
754 CopyMem (&NicInfo->Ip4Info.RouteTable[0].SubnetMask, &SubnetMask.v4, sizeof (EFI_IPv4_ADDRESS));\r
755 CopyMem (&NicInfo->Ip4Info.RouteTable[1].GatewayAddress, &Gateway.v4, sizeof (EFI_IPv4_ADDRESS));\r
756 } else {\r
757 NicInfo->Source = IP4_CONFIG_SOURCE_DHCP;\r
758 }\r
759\r
760 NicInfo->Perment = TRUE;\r
761 CopyMem (&NicInfo->NicAddr, &Ip4ConfigInstance->NicAddr, sizeof (NIC_ADDR));\r
762\r
763 EfiNicIp4ConfigSetInfo (Ip4ConfigInstance, NicInfo, TRUE);\r
764\r
765 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
766 break;\r
767\r
768 default:\r
769 if ((QuestionId >= KEY_DEVICE_ENTRY_BASE) && (QuestionId < (mNumberOfIp4Devices + KEY_DEVICE_ENTRY_BASE))) {\r
770 //\r
771 // In case goto the device configuration form, update the device form title.\r
772 //\r
773 ConfigFormEntry = Ip4GetConfigFormEntryByIndex ((UINT32) (QuestionId - KEY_DEVICE_ENTRY_BASE));\r
774 ASSERT (ConfigFormEntry != NULL);\r
775\r
776 Ip4ConfigInstance = ConfigFormEntry->Ip4ConfigInstance;\r
777\r
778 UnicodeSPrint (PortString, (UINTN) 128, L"Port %s", ConfigFormEntry->MacString);\r
779 DeviceFormTitleToken = (EFI_STRING_ID) STR_IP4_DEVICE_FORM_TITLE;\r
780 HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString, NULL);\r
781\r
782 Ip4ConfigConvertDeviceConfigDataToIfrNvData (Ip4ConfigInstance, IfrFormNvData);\r
783\r
784 Private->Current = ConfigFormEntry;\r
785 }\r
786\r
787 break;\r
788 }\r
789\r
790 if (!EFI_ERROR (Status)) {\r
791\r
792 //\r
793 // Pass changed uncommitted data back to Form Browser\r
794 //\r
795 HiiSetBrowserData (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, sizeof (IP4_CONFIG_IFR_NVDATA), (UINT8 *) IfrFormNvData, NULL);\r
796 }\r
797\r
798 FreePool (IfrFormNvData);\r
799 return Status;\r
800}\r
801\r
802/**\r
803 Install HII Config Access protocol for network device and allocate resource.\r
804\r
805 @param[in] Instance The IP4 Config instance.\r
806\r
807 @retval EFI_SUCCESS The HII Config Access protocol is installed.\r
808 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
809 @retval Others Other errors as indicated.\r
810**/\r
811EFI_STATUS\r
812Ip4ConfigDeviceInit (\r
813 IN IP4_CONFIG_INSTANCE *Instance\r
814 )\r
815{\r
816 EFI_STATUS Status;\r
817 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;\r
818 IP4_FORM_CALLBACK_INFO *CallbackInfo;\r
819\r
820 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase);\r
821 if (EFI_ERROR (Status)) {\r
822 return Status;\r
823 }\r
824\r
825 CallbackInfo = &Instance->Ip4FormCallbackInfo;\r
826\r
827 CallbackInfo->Signature = IP4CONFIG_FORM_CALLBACK_INFO_SIGNATURE;\r
828 CallbackInfo->HiiDatabase = HiiDatabase;\r
829\r
830 CallbackInfo->ConfigAccess.ExtractConfig = Ip4DeviceExtractConfig;\r
831 CallbackInfo->ConfigAccess.RouteConfig = Ip4DeviceRouteConfig;\r
832 CallbackInfo->ConfigAccess.Callback = NULL;\r
833\r
834 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&CallbackInfo->ConfigRouting);\r
835 if (EFI_ERROR (Status)) {\r
836 return Status;\r
837 }\r
838\r
839 CallbackInfo->DriverHandle = Instance->Controller;\r
840 //\r
841 // Install Device Path Protocol and Config Access protocol to driver handle\r
842 //\r
843 Status = gBS->InstallMultipleProtocolInterfaces (\r
844 &CallbackInfo->DriverHandle,\r
845 &gEfiHiiConfigAccessProtocolGuid,\r
846 &CallbackInfo->ConfigAccess,\r
847 NULL\r
848 );\r
849 ASSERT_EFI_ERROR (Status);\r
850\r
851 return Status;\r
852}\r
853\r
854/**\r
855 Uninstall HII Config Access protocol for network device and free resource.\r
856\r
857 @param[in] Instance The IP4 Config instance.\r
858\r
859 @retval EFI_SUCCESS The HII Config Access protocol is uninstalled.\r
860 @retval Others Other errors as indicated.\r
861**/\r
862EFI_STATUS\r
863Ip4ConfigDeviceUnload (\r
864 IN IP4_CONFIG_INSTANCE *Instance\r
865 )\r
866{\r
867 IP4_FORM_CALLBACK_INFO *CallbackInfo;\r
868\r
869 CallbackInfo = &Instance->Ip4FormCallbackInfo;\r
870\r
871 Ip4ConfigUpdateForm (Instance, FALSE);\r
872\r
873 //\r
874 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL\r
875 //\r
876 gBS->UninstallMultipleProtocolInterfaces (\r
877 CallbackInfo->DriverHandle,\r
878 &gEfiHiiConfigAccessProtocolGuid,\r
879 &CallbackInfo->ConfigAccess,\r
880 NULL\r
881 );\r
882\r
883 return EFI_SUCCESS;\r
884}\r
885\r
886/**\r
887 Unload the network configuration form, this includes: delete all the network\r
888 device configuration entries, uninstall the form callback protocol and\r
889 free the resources used.\r
890\r
891 @retval EFI_SUCCESS The network configuration form is unloaded.\r
892**/\r
893EFI_STATUS\r
894Ip4ConfigFormUnload (\r
895 VOID\r
896 )\r
897{\r
898 IP4CONFIG_FORM_ENTRY *ConfigFormEntry;\r
899\r
900 while (!IsListEmpty (&mIp4ConfigFormList)) {\r
901 //\r
902 // Uninstall the device forms as the network driver instance may fail to\r
903 // control the controller but still install the device configuration form.\r
904 // In such case, upon driver unloading, the driver instance's driverbinding.\r
905 // stop () won't be called, so we have to take this chance here to uninstall\r
906 // the device form.\r
907 //\r
908 ConfigFormEntry = NET_LIST_USER_STRUCT (mIp4ConfigFormList.ForwardLink, IP4CONFIG_FORM_ENTRY, Link);\r
909 Ip4ConfigUpdateForm (ConfigFormEntry->Ip4ConfigInstance, FALSE);\r
910 }\r
911\r
912 //\r
913 // Remove HII package list\r
914 //\r
915 mCallbackInfo->HiiDatabase->RemovePackageList (\r
916 mCallbackInfo->HiiDatabase,\r
917 mCallbackInfo->RegisteredHandle\r
918 );\r
919\r
920 //\r
921 // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL\r
922 //\r
923 gBS->UninstallMultipleProtocolInterfaces (\r
924 mCallbackInfo->DriverHandle,\r
925 &gEfiDevicePathProtocolGuid,\r
926 &mIp4ConifgHiiVendorDevicePath,\r
927 &gEfiHiiConfigAccessProtocolGuid,\r
928 &mCallbackInfo->ConfigAccess,\r
929 NULL\r
930 );\r
931\r
932 FreePool (mCallbackInfo);\r
933\r
934 return EFI_SUCCESS;\r
935}\r
936\r
937/**\r
938 Updates the network configuration form to add/delete an entry for the network\r
939 device specified by the Instance.\r
940\r
941 @param[in] Instance The IP4 Config instance.\r
942 @param[in] AddForm Whether to add or delete a form entry.\r
943\r
944 @retval EFI_SUCCESS The network configuration form is updated.\r
945 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
946 @retval Others Other errors as indicated.\r
947**/\r
948EFI_STATUS\r
949Ip4ConfigUpdateForm (\r
950 IN IP4_CONFIG_INSTANCE *Instance,\r
951 IN BOOLEAN AddForm\r
952 )\r
953{\r
954 LIST_ENTRY *Entry;\r
955 IP4CONFIG_FORM_ENTRY *ConfigFormEntry;\r
956 BOOLEAN EntryExisted;\r
957 EFI_STATUS Status;\r
958 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
959 CHAR16 PortString[128];\r
960 UINT16 FormIndex;\r
961 VOID *StartOpCodeHandle;\r
962 VOID *EndOpCodeHandle;\r
963 EFI_IFR_GUID_LABEL *StartLabel;\r
964 EFI_IFR_GUID_LABEL *EndLabel;\r
965\r
966 ConfigFormEntry = NULL;\r
967 EntryExisted = FALSE;\r
968\r
969 NET_LIST_FOR_EACH (Entry, &mIp4ConfigFormList) {\r
970 ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, IP4CONFIG_FORM_ENTRY, Link);\r
971\r
972 if (ConfigFormEntry->Controller == Instance->Controller) {\r
973 EntryExisted = TRUE;\r
974 break;\r
975 }\r
976 }\r
977\r
978 if (AddForm) {\r
979 if (EntryExisted) {\r
980 return EFI_SUCCESS;\r
981 } else {\r
982 //\r
983 // Add a new form.\r
984 //\r
985 ConfigFormEntry = (IP4CONFIG_FORM_ENTRY *) AllocateZeroPool (sizeof (IP4CONFIG_FORM_ENTRY));\r
986 if (ConfigFormEntry == NULL) {\r
987 return EFI_OUT_OF_RESOURCES;\r
988 }\r
989\r
990 ConfigFormEntry->Ip4ConfigInstance = Instance;\r
991 InitializeListHead (&ConfigFormEntry->Link);\r
992 ConfigFormEntry->Controller = Instance->Controller;\r
993\r
994 //\r
995 // Get the simple network protocol and convert the MAC address into\r
996 // the formatted string.\r
997 //\r
998 Status = gBS->HandleProtocol (\r
999 Instance->Controller,\r
1000 &gEfiSimpleNetworkProtocolGuid,\r
1001 (VOID **)&Snp\r
1002 );\r
1003 ASSERT (Status == EFI_SUCCESS);\r
1004\r
1005 Ip4MacAddrToStr (&Snp->Mode->PermanentAddress, Snp->Mode->HwAddressSize, ConfigFormEntry->MacString);\r
1006\r
1007 //\r
1008 // Compose the Port string and create a new EFI_STRING_ID.\r
1009 //\r
1010 UnicodeSPrint (PortString, 128, L"%s %s", Instance->NicName, ConfigFormEntry->MacString);\r
1011 ConfigFormEntry->PortTitleToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL);\r
1012\r
1013 //\r
1014 // Compose the help string of this port and create a new EFI_STRING_ID.\r
1015 //\r
1016 UnicodeSPrint (PortString, 128, L"Set the network parameters on eth%d %s", 0, ConfigFormEntry->MacString);\r
1017 ConfigFormEntry->PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL);\r
1018\r
1019 InsertTailList (&mIp4ConfigFormList, &ConfigFormEntry->Link);\r
1020 mNumberOfIp4Devices++;\r
1021 }\r
1022 } else {\r
1023 ASSERT (EntryExisted);\r
1024\r
1025 mNumberOfIp4Devices--;\r
1026 RemoveEntryList (&ConfigFormEntry->Link);\r
1027 gBS->FreePool (ConfigFormEntry);\r
1028 }\r
1029\r
1030 //\r
1031 // Init OpCode Handle\r
1032 //\r
1033 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1034 ASSERT (StartOpCodeHandle != NULL);\r
1035\r
1036 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1037 ASSERT (EndOpCodeHandle != NULL);\r
1038\r
1039 //\r
1040 // Create Hii Extend Label OpCode as the start opcode\r
1041 //\r
1042 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1043 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1044 StartLabel->Number = DEVICE_ENTRY_LABEL;\r
1045\r
1046 //\r
1047 // Create Hii Extend Label OpCode as the end opcode\r
1048 //\r
1049 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
1050 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
1051 EndLabel->Number = LABEL_END;\r
1052\r
1053 FormIndex = 0;\r
1054\r
1055 FormIndex = 0;\r
1056 NET_LIST_FOR_EACH (Entry, &mIp4ConfigFormList) {\r
1057 ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, IP4CONFIG_FORM_ENTRY, Link);\r
1058\r
1059 HiiCreateGotoOpCode (\r
1060 StartOpCodeHandle, // Container for dynamic created opcodes\r
1061 FORMID_DEVICE_FORM, // Target Form ID\r
1062 ConfigFormEntry->PortTitleToken, // Prompt text\r
1063 ConfigFormEntry->PortTitleHelpToken, // Help text\r
1064 EFI_IFR_FLAG_CALLBACK, // Question flag\r
1065 (UINT16)(KEY_DEVICE_ENTRY_BASE + FormIndex) // Question ID\r
1066 );\r
1067\r
1068 FormIndex++;\r
1069 }\r
1070\r
1071 HiiUpdateForm (\r
1072 mCallbackInfo->RegisteredHandle,\r
1073 &gEfiNicIp4ConfigVariableGuid,\r
1074 FORMID_MAIN_FORM,\r
1075 StartOpCodeHandle, // Label DEVICE_ENTRY_LABEL\r
1076 EndOpCodeHandle // LABEL_END\r
1077 );\r
1078\r
1079 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
1080 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
1081\r
1082 return EFI_SUCCESS;\r
1083}\r
1084\r
1085/**\r
1086 Initialize the network configuration form, this includes: delete all the network\r
1087 device configuration entries, install the form callback protocol and\r
1088 allocate the resources used.\r
1089\r
1090 @retval EFI_SUCCESS The network configuration form is unloaded.\r
1091 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
1092**/\r
1093EFI_STATUS\r
1094Ip4ConfigFormInit (\r
1095 VOID\r
1096 )\r
1097{\r
1098 EFI_STATUS Status;\r
1099 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;\r
1100 IP4_FORM_CALLBACK_INFO *CallbackInfo;\r
1101\r
1102 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase);\r
1103 if (EFI_ERROR (Status)) {\r
1104 return Status;\r
1105 }\r
1106\r
1107 CallbackInfo = (IP4_FORM_CALLBACK_INFO *) AllocateZeroPool (sizeof (IP4_FORM_CALLBACK_INFO));\r
1108 if (CallbackInfo == NULL) {\r
1109 return EFI_OUT_OF_RESOURCES;\r
1110 }\r
1111\r
1112 CallbackInfo->Signature = IP4CONFIG_FORM_CALLBACK_INFO_SIGNATURE;\r
1113 CallbackInfo->HiiDatabase = HiiDatabase;\r
1114\r
1115 CallbackInfo->ConfigAccess.ExtractConfig = Ip4FormExtractConfig;\r
1116 CallbackInfo->ConfigAccess.RouteConfig = Ip4FormRouteConfig;\r
1117 CallbackInfo->ConfigAccess.Callback = Ip4FormCallback;\r
1118\r
1119 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **)&CallbackInfo->ConfigRouting);\r
1120 if (EFI_ERROR (Status)) {\r
1121 return Status;\r
1122 }\r
1123\r
1124 CallbackInfo->DriverHandle = NULL;\r
1125 //\r
1126 // Install Device Path Protocol and Config Access protocol to driver handle\r
1127 //\r
1128 Status = gBS->InstallMultipleProtocolInterfaces (\r
1129 &CallbackInfo->DriverHandle,\r
1130 &gEfiDevicePathProtocolGuid,\r
1131 &mIp4ConifgHiiVendorDevicePath,\r
1132 &gEfiHiiConfigAccessProtocolGuid,\r
1133 &CallbackInfo->ConfigAccess,\r
1134 NULL\r
1135 );\r
1136 ASSERT_EFI_ERROR (Status);\r
1137\r
1138 //\r
1139 // Publish our HII data\r
1140 //\r
1141 CallbackInfo->RegisteredHandle = HiiAddPackages (\r
1142 &gEfiNicIp4ConfigVariableGuid,\r
1143 CallbackInfo->DriverHandle,\r
1144 Ip4ConfigDxeStrings,\r
1145 Ip4ConfigDxeBin,\r
1146 NULL\r
1147 );\r
1148 if (CallbackInfo->RegisteredHandle == NULL) {\r
1149 return EFI_OUT_OF_RESOURCES;\r
1150 }\r
1151\r
1152 mCallbackInfo = CallbackInfo;\r
1153\r
1154 return Status;\r
1155}\r