Commit | Line | Data |
---|---|---|
1f6729ff | 1 | /** @file\r |
2 | The implementation of EFI IPv4 Configuration II Protocol.\r | |
3 | \r | |
7648748e | 4 | Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r |
4f0f2316 | 5 | (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r |
1f6729ff | 6 | \r |
7 | This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php.\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #include "Ip4Impl.h"\r | |
18 | \r | |
19 | LIST_ENTRY mIp4Config2InstanceList = {&mIp4Config2InstanceList, &mIp4Config2InstanceList};\r | |
20 | \r | |
21 | /**\r | |
22 | The event process routine when the DHCPv4 service binding protocol is installed\r | |
23 | in the system.\r | |
24 | \r | |
25 | @param[in] Event Not used.\r | |
26 | @param[in] Context Pointer to the IP4 config2 instance data.\r | |
27 | \r | |
28 | **/\r | |
29 | VOID\r | |
30 | EFIAPI\r | |
31 | Ip4Config2OnDhcp4SbInstalled (\r | |
32 | IN EFI_EVENT Event,\r | |
33 | IN VOID *Context\r | |
34 | );\r | |
35 | \r | |
36 | /**\r | |
37 | Destroy the Dhcp4 child in IP4_CONFIG2_INSTANCE and release the resources.\r | |
38 | \r | |
39 | @param[in, out] Instance The buffer of IP4 config2 instance to be freed.\r | |
40 | \r | |
41 | @retval EFI_SUCCESS The child was successfully destroyed.\r | |
42 | @retval Others Failed to destroy the child.\r | |
43 | \r | |
44 | **/\r | |
45 | EFI_STATUS\r | |
46 | Ip4Config2DestroyDhcp4 (\r | |
47 | IN OUT IP4_CONFIG2_INSTANCE *Instance\r | |
48 | )\r | |
49 | {\r | |
50 | IP4_SERVICE *IpSb;\r | |
51 | EFI_STATUS Status;\r | |
52 | EFI_DHCP4_PROTOCOL *Dhcp4;\r | |
53 | \r | |
54 | Dhcp4 = Instance->Dhcp4;\r | |
55 | ASSERT (Dhcp4 != NULL);\r | |
56 | \r | |
57 | Dhcp4->Stop (Dhcp4);\r | |
58 | Dhcp4->Configure (Dhcp4, NULL);\r | |
59 | Instance->Dhcp4 = NULL;\r | |
60 | \r | |
61 | IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r | |
62 | \r | |
63 | //\r | |
64 | // Close DHCPv4 protocol and destroy the child.\r | |
65 | //\r | |
66 | Status = gBS->CloseProtocol (\r | |
67 | Instance->Dhcp4Handle,\r | |
68 | &gEfiDhcp4ProtocolGuid,\r | |
69 | IpSb->Image,\r | |
70 | IpSb->Controller\r | |
71 | );\r | |
72 | if (EFI_ERROR (Status)) {\r | |
73 | return Status;\r | |
74 | }\r | |
75 | \r | |
76 | Status = NetLibDestroyServiceChild (\r | |
77 | IpSb->Controller,\r | |
78 | IpSb->Image,\r | |
79 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
80 | Instance->Dhcp4Handle\r | |
81 | );\r | |
82 | \r | |
83 | Instance->Dhcp4Handle = NULL;\r | |
84 | \r | |
85 | return Status; \r | |
86 | }\r | |
87 | \r | |
1f6729ff | 88 | /**\r |
89 | Update the current policy to NewPolicy. During the transition\r | |
90 | period, the default router list\r | |
91 | and address list in all interfaces will be released.\r | |
92 | \r | |
93 | @param[in] IpSb The IP4 service binding instance.\r | |
94 | @param[in] NewPolicy The new policy to be updated to.\r | |
95 | \r | |
96 | **/\r | |
97 | VOID\r | |
98 | Ip4Config2OnPolicyChanged (\r | |
99 | IN IP4_SERVICE *IpSb,\r | |
100 | IN EFI_IP4_CONFIG2_POLICY NewPolicy\r | |
101 | )\r | |
102 | {\r | |
103 | IP4_INTERFACE *IpIf;\r | |
104 | IP4_ROUTE_TABLE *RouteTable;\r | |
105 | \r | |
106 | //\r | |
107 | // Currently there are only two policies: static and dhcp. Regardless of\r | |
108 | // what transition is going on, i.e., static -> dhcp and dhcp ->\r | |
109 | // static, we have to free default router table and all addresses.\r | |
110 | //\r | |
111 | \r | |
112 | if (IpSb->DefaultInterface != NULL) {\r | |
113 | if (IpSb->DefaultRouteTable != NULL) {\r | |
114 | Ip4FreeRouteTable (IpSb->DefaultRouteTable);\r | |
115 | IpSb->DefaultRouteTable = NULL; \r | |
116 | }\r | |
117 | \r | |
118 | Ip4CancelReceive (IpSb->DefaultInterface);\r | |
119 | \r | |
120 | Ip4FreeInterface (IpSb->DefaultInterface, NULL);\r | |
121 | IpSb->DefaultInterface = NULL;\r | |
122 | }\r | |
123 | \r | |
124 | Ip4CleanAssembleTable (&IpSb->Assemble);\r | |
125 | \r | |
126 | //\r | |
127 | // Create new default interface and route table.\r | |
128 | // \r | |
129 | IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image);\r | |
130 | if (IpIf == NULL) {\r | |
131 | return ;\r | |
132 | }\r | |
133 | \r | |
134 | RouteTable = Ip4CreateRouteTable ();\r | |
135 | if (RouteTable == NULL) {\r | |
136 | Ip4FreeInterface (IpIf, NULL);\r | |
137 | return ;\r | |
138 | }\r | |
139 | \r | |
140 | IpSb->DefaultInterface = IpIf;\r | |
141 | InsertHeadList (&IpSb->Interfaces, &IpIf->Link);\r | |
142 | IpSb->DefaultRouteTable = RouteTable;\r | |
143 | Ip4ReceiveFrame (IpIf, NULL, Ip4AccpetFrame, IpSb);\r | |
144 | \r | |
145 | if (IpSb->State == IP4_SERVICE_CONFIGED) {\r | |
146 | IpSb->State = IP4_SERVICE_UNSTARTED;\r | |
147 | }\r | |
148 | \r | |
149 | //\r | |
150 | // Start the dhcp configuration.\r | |
151 | //\r | |
152 | if (NewPolicy == Ip4Config2PolicyDhcp) {\r | |
e371cc14 | 153 | IpSb->Reconfig = TRUE;\r |
1f6729ff | 154 | Ip4StartAutoConfig (&IpSb->Ip4Config2Instance);\r |
155 | }\r | |
156 | \r | |
157 | }\r | |
158 | \r | |
159 | /**\r | |
160 | Signal the registered event. It is the callback routine for NetMapIterate.\r | |
161 | \r | |
162 | @param[in] Map Points to the list of registered event.\r | |
163 | @param[in] Item The registered event.\r | |
164 | @param[in] Arg Not used.\r | |
165 | \r | |
166 | @retval EFI_SUCCESS The event was signaled successfully.\r | |
167 | **/\r | |
168 | EFI_STATUS\r | |
169 | EFIAPI\r | |
170 | Ip4Config2SignalEvent (\r | |
171 | IN NET_MAP *Map,\r | |
172 | IN NET_MAP_ITEM *Item,\r | |
173 | IN VOID *Arg\r | |
174 | )\r | |
175 | {\r | |
176 | gBS->SignalEvent ((EFI_EVENT) Item->Key);\r | |
177 | \r | |
178 | return EFI_SUCCESS;\r | |
179 | }\r | |
180 | \r | |
181 | /**\r | |
182 | Read the configuration data from variable storage according to the VarName and\r | |
183 | gEfiIp4Config2ProtocolGuid. It checks the integrity of variable data. If the\r | |
184 | data is corrupted, it clears the variable data to ZERO. Othewise, it outputs the\r | |
185 | configuration data to IP4_CONFIG2_INSTANCE.\r | |
186 | \r | |
187 | @param[in] VarName The pointer to the variable name\r | |
188 | @param[in, out] Instance The pointer to the IP4 config2 instance data.\r | |
189 | \r | |
190 | @retval EFI_NOT_FOUND The variable can not be found or already corrupted.\r | |
191 | @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.\r | |
192 | @retval EFI_SUCCESS The configuration data was retrieved successfully.\r | |
193 | \r | |
194 | **/\r | |
195 | EFI_STATUS\r | |
196 | Ip4Config2ReadConfigData (\r | |
197 | IN CHAR16 *VarName,\r | |
198 | IN OUT IP4_CONFIG2_INSTANCE *Instance\r | |
199 | )\r | |
200 | {\r | |
201 | EFI_STATUS Status;\r | |
202 | UINTN VarSize;\r | |
203 | IP4_CONFIG2_VARIABLE *Variable;\r | |
204 | IP4_CONFIG2_DATA_ITEM *DataItem;\r | |
205 | UINTN Index;\r | |
206 | IP4_CONFIG2_DATA_RECORD DataRecord;\r | |
207 | CHAR8 *Data;\r | |
208 | \r | |
209 | //\r | |
210 | // Try to read the configuration variable.\r | |
211 | //\r | |
212 | VarSize = 0;\r | |
213 | Status = gRT->GetVariable (\r | |
214 | VarName,\r | |
215 | &gEfiIp4Config2ProtocolGuid,\r | |
216 | NULL,\r | |
217 | &VarSize,\r | |
218 | NULL\r | |
219 | );\r | |
220 | \r | |
221 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
222 | //\r | |
223 | // Allocate buffer and read the config variable.\r | |
224 | //\r | |
225 | Variable = AllocatePool (VarSize);\r | |
226 | if (Variable == NULL) {\r | |
227 | return EFI_OUT_OF_RESOURCES;\r | |
228 | }\r | |
229 | \r | |
230 | Status = gRT->GetVariable (\r | |
231 | VarName,\r | |
232 | &gEfiIp4Config2ProtocolGuid,\r | |
233 | NULL,\r | |
234 | &VarSize,\r | |
235 | Variable\r | |
236 | );\r | |
237 | if (EFI_ERROR (Status) || (UINT16) (~NetblockChecksum ((UINT8 *) Variable, (UINT32) VarSize)) != 0) {\r | |
238 | //\r | |
239 | // GetVariable still error or the variable is corrupted.\r | |
240 | // Fall back to the default value.\r | |
241 | //\r | |
242 | FreePool (Variable);\r | |
243 | \r | |
244 | //\r | |
245 | // Remove the problematic variable and return EFI_NOT_FOUND, a new\r | |
246 | // variable will be set again.\r | |
247 | //\r | |
248 | gRT->SetVariable (\r | |
249 | VarName,\r | |
250 | &gEfiIp4Config2ProtocolGuid,\r | |
251 | IP4_CONFIG2_VARIABLE_ATTRIBUTE,\r | |
252 | 0,\r | |
253 | NULL\r | |
254 | );\r | |
255 | \r | |
256 | return EFI_NOT_FOUND;\r | |
257 | }\r | |
258 | \r | |
259 | \r | |
260 | for (Index = 0; Index < Variable->DataRecordCount; Index++) {\r | |
261 | \r | |
262 | CopyMem (&DataRecord, &Variable->DataRecord[Index], sizeof (DataRecord));\r | |
263 | \r | |
264 | DataItem = &Instance->DataItem[DataRecord.DataType];\r | |
265 | if (DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED) &&\r | |
266 | (DataItem->DataSize != DataRecord.DataSize)\r | |
267 | ) {\r | |
268 | //\r | |
269 | // Perhaps a corrupted data record...\r | |
270 | //\r | |
271 | continue;\r | |
272 | }\r | |
273 | \r | |
274 | if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED)) {\r | |
275 | //\r | |
276 | // This data item has variable length data.\r | |
277 | //\r | |
278 | DataItem->Data.Ptr = AllocatePool (DataRecord.DataSize);\r | |
279 | if (DataItem->Data.Ptr == NULL) {\r | |
280 | //\r | |
281 | // no memory resource\r | |
282 | //\r | |
283 | continue;\r | |
284 | }\r | |
285 | }\r | |
286 | \r | |
287 | Data = (CHAR8 *) Variable + DataRecord.Offset;\r | |
288 | CopyMem (DataItem->Data.Ptr, Data, DataRecord.DataSize);\r | |
289 | \r | |
290 | DataItem->DataSize = DataRecord.DataSize;\r | |
291 | DataItem->Status = EFI_SUCCESS;\r | |
292 | }\r | |
293 | \r | |
294 | FreePool (Variable);\r | |
295 | return EFI_SUCCESS;\r | |
296 | }\r | |
297 | \r | |
298 | return Status;\r | |
299 | }\r | |
300 | \r | |
301 | /**\r | |
302 | Write the configuration data from IP4_CONFIG2_INSTANCE to variable storage.\r | |
303 | \r | |
304 | @param[in] VarName The pointer to the variable name.\r | |
305 | @param[in] Instance The pointer to the IP4 config2 instance data.\r | |
306 | \r | |
307 | @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.\r | |
308 | @retval EFI_SUCCESS The configuration data is written successfully.\r | |
309 | \r | |
310 | **/\r | |
311 | EFI_STATUS\r | |
312 | Ip4Config2WriteConfigData (\r | |
313 | IN CHAR16 *VarName,\r | |
314 | IN IP4_CONFIG2_INSTANCE *Instance\r | |
315 | )\r | |
316 | {\r | |
317 | UINTN Index;\r | |
318 | UINTN VarSize;\r | |
319 | IP4_CONFIG2_DATA_ITEM *DataItem;\r | |
320 | IP4_CONFIG2_VARIABLE *Variable;\r | |
321 | IP4_CONFIG2_DATA_RECORD *DataRecord;\r | |
322 | CHAR8 *Heap;\r | |
323 | EFI_STATUS Status;\r | |
324 | \r | |
325 | VarSize = sizeof (IP4_CONFIG2_VARIABLE) - sizeof (IP4_CONFIG2_DATA_RECORD);\r | |
326 | \r | |
327 | for (Index = 0; Index < Ip4Config2DataTypeMaximum; Index++) {\r | |
328 | \r | |
329 | DataItem = &Instance->DataItem[Index];\r | |
330 | if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_VOLATILE) && !EFI_ERROR (DataItem->Status)) {\r | |
331 | \r | |
332 | VarSize += sizeof (IP4_CONFIG2_DATA_RECORD) + DataItem->DataSize;\r | |
333 | }\r | |
334 | }\r | |
335 | \r | |
336 | Variable = AllocatePool (VarSize);\r | |
337 | if (Variable == NULL) {\r | |
338 | return EFI_OUT_OF_RESOURCES;\r | |
339 | }\r | |
340 | \r | |
341 | Heap = (CHAR8 *) Variable + VarSize;\r | |
342 | Variable->DataRecordCount = 0;\r | |
343 | \r | |
344 | for (Index = 0; Index < Ip4Config2DataTypeMaximum; Index++) {\r | |
345 | \r | |
346 | DataItem = &Instance->DataItem[Index];\r | |
347 | if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_VOLATILE) && !EFI_ERROR (DataItem->Status)) {\r | |
348 | \r | |
349 | Heap -= DataItem->DataSize;\r | |
350 | CopyMem (Heap, DataItem->Data.Ptr, DataItem->DataSize);\r | |
351 | \r | |
352 | DataRecord = &Variable->DataRecord[Variable->DataRecordCount];\r | |
353 | DataRecord->DataType = (EFI_IP4_CONFIG2_DATA_TYPE) Index;\r | |
354 | DataRecord->DataSize = (UINT32) DataItem->DataSize;\r | |
355 | DataRecord->Offset = (UINT16) (Heap - (CHAR8 *) Variable);\r | |
356 | \r | |
357 | Variable->DataRecordCount++;\r | |
358 | }\r | |
359 | }\r | |
360 | \r | |
361 | Variable->Checksum = 0;\r | |
362 | Variable->Checksum = (UINT16) ~NetblockChecksum ((UINT8 *) Variable, (UINT32) VarSize);\r | |
363 | \r | |
364 | Status = gRT->SetVariable (\r | |
365 | VarName,\r | |
366 | &gEfiIp4Config2ProtocolGuid,\r | |
367 | IP4_CONFIG2_VARIABLE_ATTRIBUTE,\r | |
368 | VarSize,\r | |
369 | Variable\r | |
370 | );\r | |
371 | \r | |
372 | FreePool (Variable);\r | |
373 | \r | |
374 | return Status;\r | |
375 | }\r | |
376 | \r | |
377 | \r | |
378 | /**\r | |
379 | Build a EFI_IP4_ROUTE_TABLE to be returned to the caller of GetModeData. \r | |
380 | The EFI_IP4_ROUTE_TABLE is clumsy to use in the internal operation of the \r | |
381 | IP4 driver.\r | |
382 | \r | |
383 | @param[in] IpSb The IP4 service binding instance.\r | |
384 | @param[out] Table The built IP4 route table.\r | |
385 | \r | |
386 | @retval EFI_SUCCESS The route table is successfully build\r | |
387 | @retval EFI_NOT_FOUND Failed to allocate the memory for the rotue table.\r | |
388 | \r | |
389 | **/\r | |
390 | EFI_STATUS\r | |
391 | Ip4Config2BuildDefaultRouteTable (\r | |
392 | IN IP4_SERVICE *IpSb,\r | |
393 | OUT EFI_IP4_ROUTE_TABLE *Table\r | |
394 | )\r | |
395 | {\r | |
396 | LIST_ENTRY *Entry; \r | |
397 | IP4_ROUTE_ENTRY *RtEntry;\r | |
398 | UINT32 Count;\r | |
399 | INT32 Index;\r | |
400 | \r | |
401 | if (IpSb->DefaultRouteTable == NULL) {\r | |
402 | return EFI_NOT_FOUND;\r | |
403 | }\r | |
404 | \r | |
405 | Count = IpSb->DefaultRouteTable->TotalNum;\r | |
406 | \r | |
407 | if (Count == 0) {\r | |
408 | return EFI_NOT_FOUND;\r | |
409 | }\r | |
410 | \r | |
411 | //\r | |
412 | // Copy the route entry to EFI route table. Keep the order of\r | |
413 | // route entry copied from most specific to default route. That\r | |
414 | // is, interlevel the route entry from the instance's route area\r | |
415 | // and those from the default route table's route area.\r | |
416 | //\r | |
417 | Count = 0;\r | |
418 | \r | |
419 | for (Index = IP4_MASK_NUM - 1; Index >= 0; Index--) {\r | |
420 | \r | |
421 | NET_LIST_FOR_EACH (Entry, &(IpSb->DefaultRouteTable->RouteArea[Index])) {\r | |
422 | RtEntry = NET_LIST_USER_STRUCT (Entry, IP4_ROUTE_ENTRY, Link);\r | |
423 | \r | |
424 | EFI_IP4 (Table[Count].SubnetAddress) = HTONL (RtEntry->Dest & RtEntry->Netmask);\r | |
425 | EFI_IP4 (Table[Count].SubnetMask) = HTONL (RtEntry->Netmask);\r | |
426 | EFI_IP4 (Table[Count].GatewayAddress) = HTONL (RtEntry->NextHop);\r | |
427 | \r | |
428 | Count++;\r | |
429 | }\r | |
430 | \r | |
431 | }\r | |
432 | \r | |
433 | return EFI_SUCCESS;\r | |
434 | }\r | |
435 | \r | |
436 | /**\r | |
437 | The event process routine when the DHCPv4 service binding protocol is installed\r | |
438 | in the system.\r | |
439 | \r | |
440 | @param[in] Event Not used.\r | |
441 | @param[in] Context The pointer to the IP4 config2 instance data.\r | |
442 | \r | |
443 | **/\r | |
444 | VOID\r | |
445 | EFIAPI\r | |
446 | Ip4Config2OnDhcp4SbInstalled (\r | |
447 | IN EFI_EVENT Event,\r | |
448 | IN VOID *Context\r | |
449 | )\r | |
450 | {\r | |
451 | IP4_CONFIG2_INSTANCE *Instance;\r | |
452 | \r | |
453 | Instance = (IP4_CONFIG2_INSTANCE *) Context;\r | |
454 | \r | |
455 | if ((Instance->Dhcp4Handle != NULL) || (Instance->Policy != Ip4Config2PolicyDhcp)) {\r | |
456 | //\r | |
457 | // The DHCP4 child is already created or the policy is no longer DHCP.\r | |
458 | //\r | |
459 | return ;\r | |
460 | }\r | |
461 | \r | |
462 | Ip4StartAutoConfig (Instance);\r | |
463 | }\r | |
464 | \r | |
465 | /**\r | |
466 | Set the station address and subnetmask for the default interface.\r | |
467 | \r | |
e371cc14 | 468 | @param[in] IpSb The pointer to the IP4 service binding instance.\r |
1f6729ff | 469 | @param[in] StationAddress Ip address to be set.\r |
470 | @param[in] SubnetMask Subnet to be set.\r | |
471 | \r | |
472 | @retval EFI_SUCCESS Set default address successful. \r | |
473 | @retval Others Some errors occur in setting. \r | |
474 | \r | |
475 | **/\r | |
476 | EFI_STATUS\r | |
477 | Ip4Config2SetDefaultAddr (\r | |
e371cc14 | 478 | IN IP4_SERVICE *IpSb,\r |
1f6729ff | 479 | IN IP4_ADDR StationAddress,\r |
480 | IN IP4_ADDR SubnetMask\r | |
481 | )\r | |
482 | {\r | |
483 | EFI_STATUS Status;\r | |
1f6729ff | 484 | IP4_INTERFACE *IpIf;\r |
485 | IP4_PROTOCOL *Ip4Instance;\r | |
486 | EFI_ARP_PROTOCOL *Arp;\r | |
487 | LIST_ENTRY *Entry;\r | |
488 | IP4_ADDR Subnet;\r | |
489 | IP4_ROUTE_TABLE *RouteTable;\r | |
490 | \r | |
1f6729ff | 491 | IpIf = IpSb->DefaultInterface;\r |
492 | ASSERT (IpIf != NULL);\r | |
493 | \r | |
494 | if ((IpIf->Ip == StationAddress) && (IpIf->SubnetMask == SubnetMask)) {\r | |
2c320007 | 495 | IpSb->State = IP4_SERVICE_CONFIGED;\r |
1f6729ff | 496 | return EFI_SUCCESS;\r |
497 | }\r | |
498 | \r | |
e371cc14 JW |
499 | if (IpSb->Reconfig) {\r |
500 | //\r | |
501 | // The default address is changed, free the previous interface first.\r | |
502 | //\r | |
503 | if (IpSb->DefaultRouteTable != NULL) {\r | |
504 | Ip4FreeRouteTable (IpSb->DefaultRouteTable);\r | |
505 | IpSb->DefaultRouteTable = NULL; \r | |
506 | }\r | |
1f6729ff | 507 | \r |
e371cc14 JW |
508 | Ip4CancelReceive (IpSb->DefaultInterface);\r |
509 | Ip4FreeInterface (IpSb->DefaultInterface, NULL);\r | |
510 | IpSb->DefaultInterface = NULL;\r | |
511 | //\r | |
512 | // Create new default interface and route table.\r | |
513 | // \r | |
514 | IpIf = Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image);\r | |
515 | if (IpIf == NULL) {\r | |
516 | return EFI_OUT_OF_RESOURCES;\r | |
517 | }\r | |
1f6729ff | 518 | \r |
e371cc14 JW |
519 | RouteTable = Ip4CreateRouteTable ();\r |
520 | if (RouteTable == NULL) {\r | |
521 | Ip4FreeInterface (IpIf, NULL);\r | |
522 | return EFI_OUT_OF_RESOURCES;\r | |
523 | }\r | |
524 | \r | |
525 | IpSb->DefaultInterface = IpIf;\r | |
526 | InsertHeadList (&IpSb->Interfaces, &IpIf->Link);\r | |
527 | IpSb->DefaultRouteTable = RouteTable;\r | |
528 | Ip4ReceiveFrame (IpIf, NULL, Ip4AccpetFrame, IpSb);\r | |
1f6729ff | 529 | }\r |
1f6729ff | 530 | \r |
531 | if (IpSb->State == IP4_SERVICE_CONFIGED) {\r | |
532 | IpSb->State = IP4_SERVICE_UNSTARTED;\r | |
533 | }\r | |
534 | \r | |
535 | Status = Ip4SetAddress (IpIf, StationAddress, SubnetMask);\r | |
536 | if (EFI_ERROR (Status)) {\r | |
537 | return Status;\r | |
538 | }\r | |
539 | \r | |
540 | if (IpIf->Arp != NULL) {\r | |
541 | // \r | |
542 | // A non-NULL IpIf->Arp here means a new ARP child is created when setting default address, \r | |
543 | // but some IP children may have referenced the default interface before it is configured,\r | |
544 | // these IP instances also consume this ARP protocol so they need to open it BY_CHILD_CONTROLLER.\r | |
545 | //\r | |
546 | Arp = NULL;\r | |
547 | NET_LIST_FOR_EACH (Entry, &IpIf->IpInstances) {\r | |
548 | Ip4Instance = NET_LIST_USER_STRUCT_S (Entry, IP4_PROTOCOL, AddrLink, IP4_PROTOCOL_SIGNATURE);\r | |
549 | Status = gBS->OpenProtocol (\r | |
550 | IpIf->ArpHandle,\r | |
551 | &gEfiArpProtocolGuid,\r | |
552 | (VOID **) &Arp,\r | |
553 | gIp4DriverBinding.DriverBindingHandle,\r | |
554 | Ip4Instance->Handle,\r | |
555 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
556 | );\r | |
557 | if (EFI_ERROR (Status)) {\r | |
558 | return Status;\r | |
559 | }\r | |
560 | }\r | |
561 | }\r | |
562 | \r | |
563 | Ip4AddRoute (\r | |
564 | IpSb->DefaultRouteTable,\r | |
565 | StationAddress,\r | |
566 | SubnetMask,\r | |
567 | IP4_ALLZERO_ADDRESS\r | |
568 | );\r | |
569 | \r | |
570 | //\r | |
571 | // Add a route for the connected network.\r | |
572 | //\r | |
573 | Subnet = StationAddress & SubnetMask;\r | |
574 | \r | |
575 | Ip4AddRoute (\r | |
576 | IpSb->DefaultRouteTable,\r | |
577 | Subnet,\r | |
578 | SubnetMask,\r | |
579 | IP4_ALLZERO_ADDRESS\r | |
580 | );\r | |
581 | \r | |
582 | IpSb->State = IP4_SERVICE_CONFIGED;\r | |
e371cc14 JW |
583 | IpSb->Reconfig = FALSE;\r |
584 | \r | |
1f6729ff | 585 | return EFI_SUCCESS;\r |
586 | }\r | |
587 | \r | |
588 | /**\r | |
589 | Set the station address, subnetmask and gateway address for the default interface.\r | |
590 | \r | |
591 | @param[in] Instance The pointer to the IP4 config2 instance data. \r | |
592 | @param[in] StationAddress Ip address to be set.\r | |
593 | @param[in] SubnetMask Subnet to be set.\r | |
594 | @param[in] GatewayAddress Gateway to be set.\r | |
595 | \r | |
596 | @retval EFI_SUCCESS Set default If successful. \r | |
597 | @retval Others Errors occur as indicated. \r | |
598 | \r | |
599 | **/\r | |
600 | EFI_STATUS\r | |
601 | Ip4Config2SetDefaultIf (\r | |
602 | IN IP4_CONFIG2_INSTANCE *Instance,\r | |
603 | IN IP4_ADDR StationAddress,\r | |
604 | IN IP4_ADDR SubnetMask,\r | |
605 | IN IP4_ADDR GatewayAddress\r | |
606 | )\r | |
607 | {\r | |
608 | EFI_STATUS Status;\r | |
609 | IP4_SERVICE *IpSb;\r | |
610 | \r | |
e371cc14 JW |
611 | IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r |
612 | \r | |
613 | Status = Ip4Config2SetDefaultAddr (IpSb, StationAddress, SubnetMask);\r | |
1f6729ff | 614 | if (EFI_ERROR (Status)) {\r |
615 | return Status;\r | |
616 | }\r | |
617 | \r | |
618 | //\r | |
619 | // Create a route if there is a default router.\r | |
620 | //\r | |
1f6729ff | 621 | if (GatewayAddress != IP4_ALLZERO_ADDRESS) {\r |
622 | Ip4AddRoute (\r | |
623 | IpSb->DefaultRouteTable,\r | |
624 | IP4_ALLZERO_ADDRESS,\r | |
625 | IP4_ALLZERO_ADDRESS,\r | |
626 | GatewayAddress\r | |
627 | ); \r | |
628 | }\r | |
629 | \r | |
630 | return EFI_SUCCESS;\r | |
631 | }\r | |
632 | \r | |
633 | \r | |
634 | /**\r | |
635 | Release all the DHCP related resources.\r | |
636 | \r | |
637 | @param Instance The IP4 config2 instance.\r | |
638 | \r | |
639 | @return None\r | |
640 | \r | |
641 | **/\r | |
642 | VOID\r | |
643 | Ip4Config2CleanDhcp4 (\r | |
644 | IN IP4_CONFIG2_INSTANCE *Instance\r | |
645 | )\r | |
646 | {\r | |
647 | IP4_SERVICE *IpSb;\r | |
648 | \r | |
649 | IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r | |
650 | \r | |
651 | if (Instance->Dhcp4 != NULL) {\r | |
652 | Instance->Dhcp4->Stop (Instance->Dhcp4);\r | |
653 | \r | |
654 | gBS->CloseProtocol (\r | |
655 | Instance->Dhcp4Handle,\r | |
656 | &gEfiDhcp4ProtocolGuid,\r | |
657 | IpSb->Image,\r | |
658 | IpSb->Controller\r | |
659 | );\r | |
660 | \r | |
661 | Instance->Dhcp4 = NULL;\r | |
662 | }\r | |
663 | \r | |
664 | if (Instance->Dhcp4Handle != NULL) {\r | |
665 | NetLibDestroyServiceChild (\r | |
666 | IpSb->Controller,\r | |
667 | IpSb->Image,\r | |
668 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
669 | Instance->Dhcp4Handle\r | |
670 | );\r | |
671 | \r | |
672 | Instance->Dhcp4Handle = NULL;\r | |
673 | }\r | |
674 | \r | |
675 | if (Instance->Dhcp4Event != NULL) {\r | |
676 | gBS->CloseEvent (Instance->Dhcp4Event);\r | |
677 | Instance->Dhcp4Event = NULL;\r | |
678 | }\r | |
679 | }\r | |
680 | \r | |
9feefde0 SEHM |
681 | /**\r |
682 | This worker function sets the DNS server list for the EFI IPv4 network\r | |
683 | stack running on the communication device that this EFI_IP4_CONFIG2_PROTOCOL\r | |
684 | manages. The DNS server addresses must be unicast IPv4 addresses. \r | |
685 | \r | |
686 | @param[in] Instance The pointer to the IP4 config2 instance data.\r | |
687 | @param[in] DataSize The size of the buffer pointed to by Data in bytes.\r | |
688 | @param[in] Data The data buffer to set, points to an array of\r | |
689 | EFI_IPv4_ADDRESS instances.\r | |
690 | \r | |
691 | @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.\r | |
692 | @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.\r | |
693 | @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.\r | |
694 | @retval EFI_ABORTED The DNS server addresses to be set equal the current\r | |
695 | configuration.\r | |
696 | @retval EFI_SUCCESS The specified configuration data for the EFI IPv4\r | |
697 | network stack was set.\r | |
698 | \r | |
699 | **/\r | |
700 | EFI_STATUS\r | |
701 | Ip4Config2SetDnsServerWorker (\r | |
702 | IN IP4_CONFIG2_INSTANCE *Instance,\r | |
703 | IN UINTN DataSize,\r | |
704 | IN VOID *Data\r | |
705 | )\r | |
706 | {\r | |
707 | UINTN OldIndex;\r | |
708 | UINTN NewIndex;\r | |
709 | UINTN Index1;\r | |
710 | EFI_IPv4_ADDRESS *OldDns;\r | |
711 | EFI_IPv4_ADDRESS *NewDns;\r | |
712 | UINTN OldDnsCount;\r | |
713 | UINTN NewDnsCount;\r | |
714 | IP4_CONFIG2_DATA_ITEM *Item;\r | |
715 | BOOLEAN OneAdded;\r | |
716 | VOID *Tmp;\r | |
717 | IP4_ADDR DnsAddress;\r | |
718 | \r | |
719 | if ((DataSize % sizeof (EFI_IPv4_ADDRESS) != 0) || (DataSize == 0)) {\r | |
720 | return EFI_BAD_BUFFER_SIZE;\r | |
721 | }\r | |
722 | \r | |
723 | Item = &Instance->DataItem[Ip4Config2DataTypeDnsServer];\r | |
724 | NewDns = (EFI_IPv4_ADDRESS *) Data;\r | |
725 | OldDns = Item->Data.DnsServers;\r | |
726 | NewDnsCount = DataSize / sizeof (EFI_IPv4_ADDRESS); \r | |
727 | OldDnsCount = Item->DataSize / sizeof (EFI_IPv4_ADDRESS);\r | |
728 | OneAdded = FALSE;\r | |
729 | \r | |
730 | if (NewDnsCount != OldDnsCount) {\r | |
731 | Tmp = AllocatePool (DataSize);\r | |
732 | if (Tmp == NULL) {\r | |
733 | return EFI_OUT_OF_RESOURCES;\r | |
734 | }\r | |
735 | } else {\r | |
736 | Tmp = NULL;\r | |
737 | }\r | |
738 | \r | |
739 | for (NewIndex = 0; NewIndex < NewDnsCount; NewIndex++) {\r | |
740 | CopyMem (&DnsAddress, NewDns + NewIndex, sizeof (IP4_ADDR));\r | |
741 | \r | |
742 | if (!NetIp4IsUnicast (NTOHL (DnsAddress), 0)) {\r | |
743 | //\r | |
744 | // The dns server address must be unicast.\r | |
745 | //\r | |
746 | FreePool (Tmp);\r | |
747 | return EFI_INVALID_PARAMETER;\r | |
748 | }\r | |
749 | \r | |
750 | for (Index1 = NewIndex + 1; Index1 < NewDnsCount; Index1++) {\r | |
751 | if (EFI_IP4_EQUAL (NewDns + NewIndex, NewDns + Index1)) {\r | |
752 | FreePool (Tmp);\r | |
753 | return EFI_INVALID_PARAMETER;\r | |
754 | }\r | |
755 | }\r | |
756 | \r | |
757 | if (OneAdded) {\r | |
758 | //\r | |
759 | // If any address in the new setting is not in the old settings, skip the\r | |
760 | // comparision below.\r | |
761 | //\r | |
762 | continue;\r | |
763 | }\r | |
764 | \r | |
765 | for (OldIndex = 0; OldIndex < OldDnsCount; OldIndex++) {\r | |
766 | if (EFI_IP4_EQUAL (NewDns + NewIndex, OldDns + OldIndex)) {\r | |
767 | //\r | |
768 | // If found break out.\r | |
769 | //\r | |
770 | break;\r | |
771 | }\r | |
772 | }\r | |
773 | \r | |
774 | if (OldIndex == OldDnsCount) {\r | |
775 | OneAdded = TRUE;\r | |
776 | }\r | |
777 | }\r | |
778 | \r | |
779 | if (!OneAdded && (DataSize == Item->DataSize)) {\r | |
780 | //\r | |
781 | // No new item is added and the size is the same.\r | |
782 | //\r | |
783 | Item->Status = EFI_SUCCESS;\r | |
784 | return EFI_ABORTED;\r | |
785 | } else {\r | |
786 | if (Tmp != NULL) {\r | |
787 | if (Item->Data.Ptr != NULL) {\r | |
788 | FreePool (Item->Data.Ptr);\r | |
789 | } \r | |
790 | Item->Data.Ptr = Tmp;\r | |
791 | }\r | |
792 | \r | |
793 | CopyMem (Item->Data.Ptr, Data, DataSize);\r | |
794 | Item->DataSize = DataSize;\r | |
795 | Item->Status = EFI_SUCCESS;\r | |
796 | return EFI_SUCCESS;\r | |
797 | }\r | |
798 | }\r | |
799 | \r | |
800 | \r | |
1f6729ff | 801 | \r |
802 | /**\r | |
803 | Callback function when DHCP process finished. It will save the\r | |
804 | retrieved IP configure parameter from DHCP to the NVRam.\r | |
805 | \r | |
806 | @param Event The callback event\r | |
807 | @param Context Opaque context to the callback\r | |
808 | \r | |
809 | @return None\r | |
810 | \r | |
811 | **/\r | |
812 | VOID\r | |
813 | EFIAPI\r | |
814 | Ip4Config2OnDhcp4Complete (\r | |
815 | IN EFI_EVENT Event,\r | |
816 | IN VOID *Context\r | |
817 | )\r | |
818 | {\r | |
819 | IP4_CONFIG2_INSTANCE *Instance;\r | |
820 | EFI_DHCP4_MODE_DATA Dhcp4Mode;\r | |
821 | EFI_STATUS Status;\r | |
822 | IP4_ADDR StationAddress;\r | |
823 | IP4_ADDR SubnetMask;\r | |
824 | IP4_ADDR GatewayAddress;\r | |
9feefde0 SEHM |
825 | UINT32 Index;\r |
826 | UINT32 OptionCount;\r | |
827 | EFI_DHCP4_PACKET_OPTION **OptionList;\r | |
1f6729ff | 828 | \r |
829 | Instance = (IP4_CONFIG2_INSTANCE *) Context;\r | |
830 | ASSERT (Instance->Dhcp4 != NULL);\r | |
831 | \r | |
832 | //\r | |
833 | // Get the DHCP retrieved parameters\r | |
834 | //\r | |
835 | Status = Instance->Dhcp4->GetModeData (Instance->Dhcp4, &Dhcp4Mode);\r | |
836 | \r | |
837 | if (EFI_ERROR (Status)) {\r | |
838 | goto Exit;\r | |
839 | }\r | |
840 | \r | |
841 | if (Dhcp4Mode.State == Dhcp4Bound) {\r | |
842 | StationAddress = EFI_NTOHL (Dhcp4Mode.ClientAddress);\r | |
843 | SubnetMask = EFI_NTOHL (Dhcp4Mode.SubnetMask);\r | |
844 | GatewayAddress = EFI_NTOHL (Dhcp4Mode.RouterAddress);\r | |
845 | \r | |
846 | Status = Ip4Config2SetDefaultIf (Instance, StationAddress, SubnetMask, GatewayAddress);\r | |
847 | if (EFI_ERROR (Status)) {\r | |
848 | goto Exit;\r | |
849 | }\r | |
850 | \r | |
9feefde0 SEHM |
851 | //\r |
852 | // Parse the ACK to get required DNS server information.\r | |
853 | //\r | |
854 | OptionCount = 0;\r | |
855 | OptionList = NULL;\r | |
856 | \r | |
857 | Status = Instance->Dhcp4->Parse (Instance->Dhcp4, Dhcp4Mode.ReplyPacket, &OptionCount, OptionList);\r | |
858 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
859 | goto Exit;\r | |
860 | }\r | |
861 | \r | |
862 | OptionList = AllocateZeroPool (OptionCount * sizeof (EFI_DHCP4_PACKET_OPTION *));\r | |
863 | if (OptionList == NULL) {\r | |
864 | goto Exit;\r | |
865 | }\r | |
866 | \r | |
867 | Status = Instance->Dhcp4->Parse (Instance->Dhcp4, Dhcp4Mode.ReplyPacket, &OptionCount, OptionList);\r | |
868 | if (EFI_ERROR (Status)) {\r | |
869 | FreePool (OptionList);\r | |
870 | goto Exit;\r | |
871 | }\r | |
872 | \r | |
873 | for (Index = 0; Index < OptionCount; Index++) {\r | |
874 | //\r | |
875 | // Look for DNS Server opcode (6).\r | |
876 | //\r | |
877 | if (OptionList[Index]->OpCode == DHCP_TAG_DNS_SERVER) {\r | |
878 | if (((OptionList[Index]->Length & 0x3) != 0) || (OptionList[Index]->Length == 0)) {\r | |
879 | break;\r | |
880 | }\r | |
881 | \r | |
882 | Ip4Config2SetDnsServerWorker (Instance, OptionList[Index]->Length, &OptionList[Index]->Data[0]);\r | |
883 | break;\r | |
884 | }\r | |
885 | }\r | |
886 | \r | |
887 | FreePool (OptionList);\r | |
888 | \r | |
1f6729ff | 889 | Instance->DhcpSuccess = TRUE;\r |
890 | }\r | |
891 | \r | |
892 | Exit:\r | |
893 | Ip4Config2CleanDhcp4 (Instance);\r | |
894 | DispatchDpc ();\r | |
895 | }\r | |
896 | \r | |
897 | \r | |
898 | /**\r | |
899 | Start the DHCP configuration for this IP service instance.\r | |
900 | It will locates the EFI_IP4_CONFIG2_PROTOCOL, then start the\r | |
901 | DHCP configuration.\r | |
902 | \r | |
903 | @param[in] Instance The IP4 config2 instance to configure\r | |
904 | \r | |
905 | @retval EFI_SUCCESS The auto configuration is successfull started\r | |
906 | @retval Others Failed to start auto configuration.\r | |
907 | \r | |
908 | **/\r | |
909 | EFI_STATUS\r | |
910 | Ip4StartAutoConfig (\r | |
911 | IN IP4_CONFIG2_INSTANCE *Instance\r | |
912 | )\r | |
913 | {\r | |
914 | IP4_SERVICE *IpSb;\r | |
915 | EFI_DHCP4_PROTOCOL *Dhcp4;\r | |
916 | EFI_DHCP4_MODE_DATA Dhcp4Mode;\r | |
917 | EFI_DHCP4_PACKET_OPTION *OptionList[1];\r | |
918 | IP4_CONFIG2_DHCP4_OPTION ParaList;\r | |
919 | EFI_STATUS Status;\r | |
920 | \r | |
921 | \r | |
922 | IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r | |
923 | \r | |
924 | if (IpSb->State > IP4_SERVICE_UNSTARTED) {\r | |
925 | return EFI_SUCCESS;\r | |
926 | }\r | |
927 | \r | |
928 | //\r | |
929 | // A host must not invoke DHCP configuration if it is already\r | |
930 | // participating in the DHCP configuraiton process.\r | |
931 | //\r | |
932 | if (Instance->Dhcp4Handle != NULL) {\r | |
933 | return EFI_SUCCESS;\r | |
934 | }\r | |
935 | \r | |
936 | Status = NetLibCreateServiceChild (\r | |
937 | IpSb->Controller,\r | |
938 | IpSb->Image,\r | |
939 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
940 | &Instance->Dhcp4Handle\r | |
941 | );\r | |
942 | \r | |
943 | if (Status == EFI_UNSUPPORTED) {\r | |
944 | //\r | |
945 | // No DHCPv4 Service Binding protocol, register a notify.\r | |
946 | //\r | |
947 | if (Instance->Dhcp4SbNotifyEvent == NULL) {\r | |
948 | Instance->Dhcp4SbNotifyEvent = EfiCreateProtocolNotifyEvent (\r | |
949 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
950 | TPL_CALLBACK,\r | |
951 | Ip4Config2OnDhcp4SbInstalled,\r | |
952 | (VOID *) Instance,\r | |
953 | &Instance->Registration\r | |
954 | );\r | |
955 | }\r | |
956 | }\r | |
957 | \r | |
958 | if (EFI_ERROR (Status)) {\r | |
959 | return Status;\r | |
960 | }\r | |
961 | \r | |
962 | if (Instance->Dhcp4SbNotifyEvent != NULL) {\r | |
963 | gBS->CloseEvent (Instance->Dhcp4SbNotifyEvent);\r | |
964 | }\r | |
965 | \r | |
966 | Status = gBS->OpenProtocol (\r | |
967 | Instance->Dhcp4Handle,\r | |
968 | &gEfiDhcp4ProtocolGuid,\r | |
969 | (VOID **) &Instance->Dhcp4,\r | |
970 | IpSb->Image,\r | |
971 | IpSb->Controller,\r | |
972 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
973 | );\r | |
974 | ASSERT_EFI_ERROR (Status);\r | |
975 | \r | |
976 | \r | |
977 | //\r | |
978 | // Check the current DHCP status, if the DHCP process has\r | |
979 | // already finished, return now.\r | |
980 | //\r | |
981 | Dhcp4 = Instance->Dhcp4;\r | |
982 | Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);\r | |
983 | \r | |
984 | if (Dhcp4Mode.State == Dhcp4Bound) {\r | |
985 | Ip4Config2OnDhcp4Complete (NULL, Instance);\r | |
986 | return EFI_SUCCESS;\r | |
987 | \r | |
988 | }\r | |
989 | \r | |
990 | //\r | |
991 | // Try to start the DHCP process. Use most of the current\r | |
992 | // DHCP configuration to avoid problems if some DHCP client\r | |
993 | // yields the control of this DHCP service to us.\r | |
994 | //\r | |
995 | ParaList.Head.OpCode = DHCP_TAG_PARA_LIST;\r | |
9feefde0 | 996 | ParaList.Head.Length = 3;\r |
1f6729ff | 997 | ParaList.Head.Data[0] = DHCP_TAG_NETMASK;\r |
998 | ParaList.Route = DHCP_TAG_ROUTER;\r | |
9feefde0 | 999 | ParaList.Dns = DHCP_TAG_DNS_SERVER;\r |
1f6729ff | 1000 | OptionList[0] = &ParaList.Head;\r |
1001 | Dhcp4Mode.ConfigData.OptionCount = 1;\r | |
1002 | Dhcp4Mode.ConfigData.OptionList = OptionList;\r | |
1003 | \r | |
1004 | Status = Dhcp4->Configure (Dhcp4, &Dhcp4Mode.ConfigData);\r | |
1005 | \r | |
1006 | if (EFI_ERROR (Status)) {\r | |
1007 | return Status;\r | |
1008 | }\r | |
1009 | \r | |
1010 | //\r | |
1011 | // Start the DHCP process\r | |
1012 | //\r | |
1013 | Status = gBS->CreateEvent (\r | |
1014 | EVT_NOTIFY_SIGNAL,\r | |
1015 | TPL_CALLBACK,\r | |
1016 | Ip4Config2OnDhcp4Complete,\r | |
1017 | Instance,\r | |
1018 | &Instance->Dhcp4Event\r | |
1019 | );\r | |
1020 | \r | |
1021 | if (EFI_ERROR (Status)) {\r | |
1022 | return Status;\r | |
1023 | }\r | |
1024 | \r | |
1025 | Status = Dhcp4->Start (Dhcp4, Instance->Dhcp4Event);\r | |
1026 | \r | |
1027 | if (EFI_ERROR (Status)) {\r | |
1028 | return Status;\r | |
1029 | }\r | |
1030 | \r | |
1031 | IpSb->State = IP4_SERVICE_STARTED;\r | |
1032 | DispatchDpc ();\r | |
1033 | return EFI_SUCCESS;\r | |
1034 | \r | |
1035 | }\r | |
1036 | \r | |
1037 | \r | |
1038 | \r | |
1039 | /**\r | |
1040 | The work function is to get the interface information of the communication \r | |
1041 | device this IP4_CONFIG2_INSTANCE manages.\r | |
1042 | \r | |
1043 | @param[in] Instance Pointer to the IP4 config2 instance data.\r | |
1044 | @param[in, out] DataSize On input, in bytes, the size of Data. On output, in\r | |
1045 | bytes, the size of buffer required to store the specified\r | |
1046 | configuration data.\r | |
1047 | @param[in] Data The data buffer in which the configuration data is returned.\r | |
1048 | Ignored if DataSize is ZERO.\r | |
1049 | \r | |
1050 | @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified\r | |
1051 | configuration data, and the required size is\r | |
1052 | returned in DataSize.\r | |
1053 | @retval EFI_SUCCESS The specified configuration data was obtained.\r | |
1054 | \r | |
1055 | **/\r | |
1056 | EFI_STATUS\r | |
1057 | Ip4Config2GetIfInfo (\r | |
1058 | IN IP4_CONFIG2_INSTANCE *Instance,\r | |
1059 | IN OUT UINTN *DataSize,\r | |
1060 | IN VOID *Data OPTIONAL\r | |
1061 | )\r | |
1062 | {\r | |
1063 | \r | |
1064 | IP4_SERVICE *IpSb;\r | |
1065 | UINTN Length;\r | |
1066 | IP4_CONFIG2_DATA_ITEM *Item;\r | |
1067 | EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo;\r | |
1068 | IP4_ADDR Address;\r | |
1069 | \r | |
1070 | IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r | |
1071 | Length = sizeof (EFI_IP4_CONFIG2_INTERFACE_INFO);\r | |
1072 | \r | |
1073 | if (IpSb->DefaultRouteTable != NULL) {\r | |
1074 | Length += IpSb->DefaultRouteTable->TotalNum * sizeof (EFI_IP4_ROUTE_TABLE);\r | |
1075 | }\r | |
1076 | \r | |
1077 | if (*DataSize < Length) {\r | |
1078 | *DataSize = Length;\r | |
1079 | return EFI_BUFFER_TOO_SMALL;\r | |
1080 | }\r | |
1081 | \r | |
1082 | //\r | |
1083 | // Copy the fixed size part of the interface info.\r | |
1084 | //\r | |
1085 | Item = &Instance->DataItem[Ip4Config2DataTypeInterfaceInfo];\r | |
1086 | IfInfo = (EFI_IP4_CONFIG2_INTERFACE_INFO *) Data;\r | |
1087 | CopyMem (IfInfo, Item->Data.Ptr, sizeof (EFI_IP4_CONFIG2_INTERFACE_INFO));\r | |
1088 | \r | |
1089 | //\r | |
1090 | // Update the address info.\r | |
1091 | //\r | |
1092 | if (IpSb->DefaultInterface != NULL) {\r | |
1093 | Address = HTONL (IpSb->DefaultInterface->Ip);\r | |
1094 | CopyMem (&IfInfo->StationAddress, &Address, sizeof (EFI_IPv4_ADDRESS));\r | |
1095 | Address = HTONL (IpSb->DefaultInterface->SubnetMask);\r | |
1096 | CopyMem (&IfInfo->SubnetMask, &Address, sizeof (EFI_IPv4_ADDRESS));\r | |
1097 | }\r | |
1098 | \r | |
1099 | if (IpSb->DefaultRouteTable != NULL) {\r | |
1100 | IfInfo->RouteTableSize = IpSb->DefaultRouteTable->TotalNum;\r | |
1101 | IfInfo->RouteTable = (EFI_IP4_ROUTE_TABLE *) ((UINT8 *) Data + sizeof (EFI_IP4_CONFIG2_INTERFACE_INFO));\r | |
1102 | \r | |
1103 | Ip4Config2BuildDefaultRouteTable (IpSb, IfInfo->RouteTable); \r | |
1104 | }\r | |
1105 | \r | |
1106 | return EFI_SUCCESS;\r | |
1107 | }\r | |
1108 | \r | |
1109 | /**\r | |
1110 | The work function is to set the general configuration policy for the EFI IPv4 network \r | |
1111 | stack that is running on the communication device managed by this IP4_CONFIG2_INSTANCE.\r | |
1112 | The policy will affect other configuration settings.\r | |
1113 | \r | |
1114 | @param[in] Instance Pointer to the IP4 config2 instance data.\r | |
1115 | @param[in] DataSize Size of the buffer pointed to by Data in bytes.\r | |
1116 | @param[in] Data The data buffer to set.\r | |
1117 | \r | |
1118 | @retval EFI_INVALID_PARAMETER The to be set policy is invalid.\r | |
1119 | @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.\r | |
1120 | @retval EFI_ABORTED The new policy equals the current policy.\r | |
1121 | @retval EFI_SUCCESS The specified configuration data for the EFI IPv6\r | |
1122 | network stack was set.\r | |
1123 | \r | |
1124 | **/\r | |
1125 | EFI_STATUS\r | |
1126 | Ip4Config2SetPolicy (\r | |
1127 | IN IP4_CONFIG2_INSTANCE *Instance,\r | |
1128 | IN UINTN DataSize,\r | |
1129 | IN VOID *Data\r | |
1130 | )\r | |
1131 | {\r | |
1132 | EFI_IP4_CONFIG2_POLICY NewPolicy;\r | |
1133 | IP4_CONFIG2_DATA_ITEM *DataItem;\r | |
1134 | IP4_SERVICE *IpSb;\r | |
1135 | \r | |
1136 | if (DataSize != sizeof (EFI_IP4_CONFIG2_POLICY)) {\r | |
1137 | return EFI_BAD_BUFFER_SIZE;\r | |
1138 | }\r | |
1139 | \r | |
1140 | NewPolicy = *((EFI_IP4_CONFIG2_POLICY *) Data);\r | |
1141 | \r | |
1142 | if (NewPolicy >= Ip4Config2PolicyMax) {\r | |
1143 | return EFI_INVALID_PARAMETER;\r | |
1144 | }\r | |
1145 | \r | |
1146 | if (NewPolicy == Instance->Policy) {\r | |
7648748e JW |
1147 | if (NewPolicy != Ip4Config2PolicyDhcp || Instance->DhcpSuccess) {\r |
1148 | return EFI_ABORTED;\r | |
1149 | }\r | |
1f6729ff | 1150 | } else {\r |
1151 | if (NewPolicy == Ip4Config2PolicyDhcp) {\r | |
1152 | //\r | |
1153 | // The policy is changed from static to dhcp:\r | |
1154 | // Clean the ManualAddress, Gateway and DnsServers, shrink the variable\r | |
1155 | // data size, and fire up all the related events.\r | |
1156 | //\r | |
1157 | DataItem = &Instance->DataItem[Ip4Config2DataTypeManualAddress];\r | |
1158 | if (DataItem->Data.Ptr != NULL) {\r | |
1159 | FreePool (DataItem->Data.Ptr);\r | |
1160 | }\r | |
1161 | DataItem->Data.Ptr = NULL;\r | |
1162 | DataItem->DataSize = 0;\r | |
1163 | DataItem->Status = EFI_NOT_FOUND;\r | |
1164 | NetMapIterate (&DataItem->EventMap, Ip4Config2SignalEvent, NULL);\r | |
1165 | \r | |
1166 | DataItem = &Instance->DataItem[Ip4Config2DataTypeGateway];\r | |
1167 | if (DataItem->Data.Ptr != NULL) {\r | |
1168 | FreePool (DataItem->Data.Ptr);\r | |
1169 | }\r | |
1170 | DataItem->Data.Ptr = NULL;\r | |
1171 | DataItem->DataSize = 0;\r | |
1172 | DataItem->Status = EFI_NOT_FOUND;\r | |
1173 | NetMapIterate (&DataItem->EventMap, Ip4Config2SignalEvent, NULL);\r | |
1174 | \r | |
1175 | DataItem = &Instance->DataItem[Ip4Config2DataTypeDnsServer];\r | |
1176 | if (DataItem->Data.Ptr != NULL) {\r | |
1177 | FreePool (DataItem->Data.Ptr);\r | |
1178 | }\r | |
1179 | DataItem->Data.Ptr = NULL;\r | |
1180 | DataItem->DataSize = 0;\r | |
1181 | DataItem->Status = EFI_NOT_FOUND;\r | |
1182 | NetMapIterate (&DataItem->EventMap, Ip4Config2SignalEvent, NULL);\r | |
1183 | } else {\r | |
1184 | //\r | |
1185 | // The policy is changed from dhcp to static. Stop the DHCPv4 process\r | |
1186 | // and destroy the DHCPv4 child.\r | |
1187 | //\r | |
1188 | if (Instance->Dhcp4Handle != NULL) {\r | |
1189 | Ip4Config2DestroyDhcp4 (Instance);\r | |
1190 | }\r | |
1191 | \r | |
1192 | //\r | |
1193 | // Close the event.\r | |
1194 | //\r | |
1195 | if (Instance->Dhcp4Event != NULL) {\r | |
1196 | gBS->CloseEvent (Instance->Dhcp4Event);\r | |
4f0f2316 | 1197 | Instance->Dhcp4Event = NULL;\r |
1f6729ff | 1198 | }\r |
1199 | }\r | |
1200 | }\r | |
1201 | \r | |
1202 | IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r | |
1203 | Ip4Config2OnPolicyChanged (IpSb, NewPolicy);\r | |
1204 | \r | |
1205 | Instance->Policy = NewPolicy;\r | |
1206 | \r | |
1207 | return EFI_SUCCESS;\r | |
1208 | }\r | |
1209 | \r | |
1210 | /**\r | |
1211 | The work function is to set the station addresses manually for the EFI IPv4 \r | |
1212 | network stack. It is only configurable when the policy is Ip4Config2PolicyStatic.\r | |
1213 | \r | |
1214 | @param[in] Instance Pointer to the IP4 config2 instance data.\r | |
1215 | @param[in] DataSize Size of the buffer pointed to by Data in bytes.\r | |
1216 | @param[in] Data The data buffer to set.\r | |
1217 | \r | |
1218 | @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.\r | |
1219 | @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set\r | |
1220 | under the current policy.\r | |
1221 | @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.\r | |
1222 | @retval EFI_OUT_OF_RESOURCES Fail to allocate resource to complete the operation.\r | |
1223 | @retval EFI_NOT_READY An asynchrous process is invoked to set the specified\r | |
1224 | configuration data, and the process is not finished.\r | |
1225 | @retval EFI_ABORTED The manual addresses to be set equal current\r | |
1226 | configuration.\r | |
1227 | @retval EFI_SUCCESS The specified configuration data for the EFI IPv6\r | |
1228 | network stack was set.\r | |
1229 | \r | |
1230 | **/\r | |
1231 | EFI_STATUS\r | |
1232 | Ip4Config2SetMaunualAddress (\r | |
1233 | IN IP4_CONFIG2_INSTANCE *Instance,\r | |
1234 | IN UINTN DataSize,\r | |
1235 | IN VOID *Data\r | |
1236 | )\r | |
1237 | {\r | |
1238 | EFI_IP4_CONFIG2_MANUAL_ADDRESS NewAddress;\r | |
1239 | IP4_CONFIG2_DATA_ITEM *DataItem;\r | |
1240 | EFI_STATUS Status;\r | |
1241 | IP4_ADDR StationAddress;\r | |
1242 | IP4_ADDR SubnetMask;\r | |
1243 | VOID *Ptr;\r | |
e371cc14 JW |
1244 | IP4_SERVICE *IpSb;\r |
1245 | \r | |
1246 | IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r | |
1f6729ff | 1247 | \r |
1248 | ASSERT (Instance->DataItem[Ip4Config2DataTypeManualAddress].Status != EFI_NOT_READY);\r | |
1249 | \r | |
1250 | if (((DataSize % sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS)) != 0) || (DataSize == 0)) {\r | |
1251 | return EFI_BAD_BUFFER_SIZE;\r | |
1252 | }\r | |
1253 | \r | |
1254 | if (Instance->Policy != Ip4Config2PolicyStatic) {\r | |
1255 | return EFI_WRITE_PROTECTED;\r | |
1256 | }\r | |
1257 | \r | |
1258 | NewAddress = *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data);\r | |
1259 | \r | |
1260 | //\r | |
1261 | // Store the new data, and init the DataItem status to EFI_NOT_READY because\r | |
1262 | // we may have an asynchronous configuration process.\r | |
1263 | //\r | |
1264 | Ptr = AllocateCopyPool (DataSize, Data);\r | |
1265 | if (Ptr == NULL) {\r | |
1266 | return EFI_OUT_OF_RESOURCES;\r | |
1267 | }\r | |
1268 | \r | |
1269 | DataItem = &Instance->DataItem[Ip4Config2DataTypeManualAddress];\r | |
1270 | if (DataItem->Data.Ptr != NULL) {\r | |
1271 | FreePool (DataItem->Data.Ptr);\r | |
1272 | }\r | |
1273 | \r | |
1274 | DataItem->Data.Ptr = Ptr;\r | |
1275 | DataItem->DataSize = DataSize;\r | |
1276 | DataItem->Status = EFI_NOT_READY;\r | |
1277 | \r | |
1278 | StationAddress = EFI_NTOHL (NewAddress.Address);\r | |
1279 | SubnetMask = EFI_NTOHL (NewAddress.SubnetMask);\r | |
1280 | \r | |
e371cc14 JW |
1281 | IpSb->Reconfig = TRUE;\r |
1282 | Status = Ip4Config2SetDefaultAddr (IpSb, StationAddress, SubnetMask);\r | |
1f6729ff | 1283 | if (EFI_ERROR (Status)) {\r |
1284 | goto ON_EXIT;\r | |
1285 | } \r | |
1286 | \r | |
1287 | DataItem->Status = EFI_SUCCESS; \r | |
1288 | \r | |
1289 | ON_EXIT:\r | |
1290 | if (EFI_ERROR (DataItem->Status)) {\r | |
1291 | if (Ptr != NULL) {\r | |
1292 | FreePool (Ptr);\r | |
1293 | }\r | |
1294 | DataItem->Data.Ptr = NULL; \r | |
1295 | }\r | |
1296 | \r | |
1297 | return EFI_SUCCESS;\r | |
1298 | }\r | |
1299 | \r | |
1300 | /**\r | |
1301 | The work function is to set the gateway addresses manually for the EFI IPv4 \r | |
1302 | network stack that is running on the communication device that this EFI IPv4 \r | |
1303 | Configuration Protocol manages. It is not configurable when the policy is\r | |
1304 | Ip4Config2PolicyDhcp. The gateway addresses must be unicast IPv4 addresses.\r | |
1305 | \r | |
1306 | @param[in] Instance The pointer to the IP4 config2 instance data.\r | |
1307 | @param[in] DataSize The size of the buffer pointed to by Data in bytes.\r | |
1308 | @param[in] Data The data buffer to set. This points to an array of\r | |
1309 | EFI_IPv6_ADDRESS instances.\r | |
1310 | \r | |
1311 | @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.\r | |
1312 | @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set\r | |
1313 | under the current policy.\r | |
1314 | @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.\r | |
1315 | @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to complete the operation.\r | |
1316 | @retval EFI_ABORTED The manual gateway addresses to be set equal the\r | |
1317 | current configuration.\r | |
1318 | @retval EFI_SUCCESS The specified configuration data for the EFI IPv6\r | |
1319 | network stack was set.\r | |
1320 | \r | |
1321 | **/\r | |
1322 | EFI_STATUS\r | |
1323 | Ip4Config2SetGateway (\r | |
1324 | IN IP4_CONFIG2_INSTANCE *Instance,\r | |
1325 | IN UINTN DataSize,\r | |
1326 | IN VOID *Data\r | |
1327 | )\r | |
1328 | {\r | |
1329 | IP4_SERVICE *IpSb;\r | |
1330 | IP4_CONFIG2_DATA_ITEM *DataItem;\r | |
1331 | IP4_ADDR Gateway;\r | |
1332 | \r | |
1333 | UINTN Index1;\r | |
1334 | UINTN Index2;\r | |
1335 | EFI_IPv4_ADDRESS *OldGateway;\r | |
1336 | EFI_IPv4_ADDRESS *NewGateway;\r | |
1337 | UINTN OldGatewayCount;\r | |
1338 | UINTN NewGatewayCount;\r | |
1339 | BOOLEAN OneRemoved;\r | |
1340 | BOOLEAN OneAdded;\r | |
1341 | VOID *Tmp;\r | |
1342 | \r | |
1343 | if ((DataSize % sizeof (EFI_IPv4_ADDRESS) != 0) || (DataSize == 0)) {\r | |
1344 | return EFI_BAD_BUFFER_SIZE;\r | |
1345 | }\r | |
1346 | \r | |
1347 | if (Instance->Policy != Ip4Config2PolicyStatic) {\r | |
1348 | return EFI_WRITE_PROTECTED;\r | |
1349 | }\r | |
1350 | \r | |
1351 | \r | |
1352 | NewGateway = (EFI_IPv4_ADDRESS *) Data;\r | |
1353 | NewGatewayCount = DataSize / sizeof (EFI_IPv4_ADDRESS);\r | |
1354 | for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {\r | |
1355 | CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR));\r | |
1356 | \r | |
1357 | if (!NetIp4IsUnicast (NTOHL (Gateway), 0)) {\r | |
1358 | \r | |
1359 | return EFI_INVALID_PARAMETER;\r | |
1360 | }\r | |
1361 | \r | |
1362 | for (Index2 = Index1 + 1; Index2 < NewGatewayCount; Index2++) {\r | |
1363 | if (EFI_IP4_EQUAL (NewGateway + Index1, NewGateway + Index2)) {\r | |
1364 | return EFI_INVALID_PARAMETER;\r | |
1365 | }\r | |
1366 | }\r | |
1367 | }\r | |
1368 | \r | |
1369 | IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r | |
1370 | DataItem = &Instance->DataItem[Ip4Config2DataTypeGateway];\r | |
1371 | OldGateway = DataItem->Data.Gateway;\r | |
1372 | OldGatewayCount = DataItem->DataSize / sizeof (EFI_IPv4_ADDRESS);\r | |
1373 | OneRemoved = FALSE;\r | |
1374 | OneAdded = FALSE;\r | |
1375 | \r | |
1376 | if (NewGatewayCount != OldGatewayCount) {\r | |
1377 | Tmp = AllocatePool (DataSize);\r | |
1378 | if (Tmp == NULL) {\r | |
1379 | return EFI_OUT_OF_RESOURCES;\r | |
1380 | }\r | |
1381 | } else {\r | |
1382 | Tmp = NULL;\r | |
1383 | }\r | |
1384 | \r | |
1385 | for (Index1 = 0; Index1 < OldGatewayCount; Index1++) {\r | |
1386 | //\r | |
1387 | // Remove this route entry.\r | |
1388 | //\r | |
1389 | CopyMem (&Gateway, OldGateway + Index1, sizeof (IP4_ADDR));\r | |
1390 | Ip4DelRoute (\r | |
1391 | IpSb->DefaultRouteTable,\r | |
1392 | IP4_ALLZERO_ADDRESS,\r | |
1393 | IP4_ALLZERO_ADDRESS,\r | |
1394 | NTOHL (Gateway)\r | |
1395 | );\r | |
1396 | OneRemoved = TRUE;\r | |
1397 | \r | |
1398 | }\r | |
1399 | \r | |
1400 | for (Index1 = 0; Index1 < NewGatewayCount; Index1++) {\r | |
1401 | CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR));\r | |
1402 | Ip4AddRoute (\r | |
1403 | IpSb->DefaultRouteTable,\r | |
1404 | IP4_ALLZERO_ADDRESS,\r | |
1405 | IP4_ALLZERO_ADDRESS,\r | |
1406 | NTOHL (Gateway)\r | |
1407 | ); \r | |
1408 | \r | |
1409 | OneAdded = TRUE;\r | |
1410 | }\r | |
1411 | \r | |
1412 | \r | |
1413 | if (!OneRemoved && !OneAdded) {\r | |
1414 | DataItem->Status = EFI_SUCCESS;\r | |
1415 | return EFI_ABORTED;\r | |
1416 | } else {\r | |
1417 | \r | |
1418 | if (Tmp != NULL) {\r | |
1419 | if (DataItem->Data.Ptr != NULL) {\r | |
1420 | FreePool (DataItem->Data.Ptr);\r | |
1421 | }\r | |
1422 | DataItem->Data.Ptr = Tmp;\r | |
1423 | }\r | |
1424 | \r | |
1425 | CopyMem (DataItem->Data.Ptr, Data, DataSize);\r | |
1426 | DataItem->DataSize = DataSize;\r | |
1427 | DataItem->Status = EFI_SUCCESS;\r | |
1428 | return EFI_SUCCESS;\r | |
1429 | }\r | |
1430 | \r | |
1431 | }\r | |
1432 | \r | |
1433 | /**\r | |
1434 | The work function is to set the DNS server list for the EFI IPv4 network \r | |
1435 | stack running on the communication device that this EFI_IP4_CONFIG2_PROTOCOL \r | |
1436 | manages. It is not configurable when the policy is Ip4Config2PolicyDhcp. \r | |
1437 | The DNS server addresses must be unicast IPv4 addresses.\r | |
1438 | \r | |
1439 | @param[in] Instance The pointer to the IP4 config2 instance data.\r | |
1440 | @param[in] DataSize The size of the buffer pointed to by Data in bytes.\r | |
1441 | @param[in] Data The data buffer to set, points to an array of\r | |
1442 | EFI_IPv4_ADDRESS instances.\r | |
1443 | \r | |
1444 | @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type.\r | |
1445 | @retval EFI_WRITE_PROTECTED The specified configuration data cannot be set\r | |
1446 | under the current policy.\r | |
1447 | @retval EFI_INVALID_PARAMETER One or more fields in Data is invalid.\r | |
1448 | @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.\r | |
1449 | @retval EFI_ABORTED The DNS server addresses to be set equal the current\r | |
1450 | configuration.\r | |
1451 | @retval EFI_SUCCESS The specified configuration data for the EFI IPv4\r | |
1452 | network stack was set.\r | |
1453 | \r | |
1454 | **/\r | |
1455 | EFI_STATUS\r | |
1456 | Ip4Config2SetDnsServer (\r | |
1457 | IN IP4_CONFIG2_INSTANCE *Instance,\r | |
1458 | IN UINTN DataSize,\r | |
1459 | IN VOID *Data\r | |
1460 | )\r | |
1461 | {\r | |
1f6729ff | 1462 | if (Instance->Policy != Ip4Config2PolicyStatic) {\r |
1463 | return EFI_WRITE_PROTECTED;\r | |
1464 | }\r | |
1465 | \r | |
9feefde0 | 1466 | return Ip4Config2SetDnsServerWorker (Instance, DataSize, Data);\r |
1f6729ff | 1467 | }\r |
1468 | \r | |
1469 | /**\r | |
1470 | Generate the operational state of the interface this IP4 config2 instance manages\r | |
1471 | and output in EFI_IP4_CONFIG2_INTERFACE_INFO.\r | |
1472 | \r | |
1473 | @param[in] IpSb The pointer to the IP4 service binding instance.\r | |
1474 | @param[out] IfInfo The pointer to the IP4 config2 interface information structure.\r | |
1475 | \r | |
1476 | **/\r | |
1477 | VOID\r | |
1478 | Ip4Config2InitIfInfo (\r | |
1479 | IN IP4_SERVICE *IpSb,\r | |
1480 | OUT EFI_IP4_CONFIG2_INTERFACE_INFO *IfInfo\r | |
1481 | )\r | |
1482 | {\r | |
1483 | IfInfo->Name[0] = L'e';\r | |
1484 | IfInfo->Name[1] = L't';\r | |
1485 | IfInfo->Name[2] = L'h';\r | |
1486 | IfInfo->Name[3] = (CHAR16) (L'0' + IpSb->Ip4Config2Instance.IfIndex);\r | |
1487 | IfInfo->Name[4] = 0;\r | |
1488 | \r | |
1489 | IfInfo->IfType = IpSb->SnpMode.IfType;\r | |
1490 | IfInfo->HwAddressSize = IpSb->SnpMode.HwAddressSize;\r | |
1491 | CopyMem (&IfInfo->HwAddress, &IpSb->SnpMode.CurrentAddress, IfInfo->HwAddressSize);\r | |
1492 | }\r | |
1493 | \r | |
1494 | /**\r | |
1495 | The event handle routine when DHCPv4 process is finished or is updated.\r | |
1496 | \r | |
1497 | @param[in] Event Not used.\r | |
1498 | @param[in] Context The pointer to the IP4 configuration instance data.\r | |
1499 | \r | |
1500 | **/\r | |
1501 | VOID\r | |
1502 | EFIAPI\r | |
1503 | Ip4Config2OnDhcp4Event (\r | |
1504 | IN EFI_EVENT Event,\r | |
1505 | IN VOID *Context\r | |
1506 | )\r | |
1507 | {\r | |
1508 | return ;\r | |
1509 | }\r | |
1510 | \r | |
1511 | \r | |
1512 | /**\r | |
1513 | Set the configuration for the EFI IPv4 network stack running on the communication\r | |
1514 | device this EFI_IP4_CONFIG2_PROTOCOL instance manages.\r | |
1515 | \r | |
1516 | This function is used to set the configuration data of type DataType for the EFI\r | |
1517 | IPv4 network stack that is running on the communication device that this EFI IPv4\r | |
1518 | Configuration Protocol instance manages.\r | |
1519 | \r | |
1520 | DataSize is used to calculate the count of structure instances in the Data for\r | |
1521 | a DataType in which multiple structure instances are allowed.\r | |
1522 | \r | |
1523 | This function is always non-blocking. When setting some type of configuration data,\r | |
1524 | an asynchronous process is invoked to check the correctness of the data, such as\r | |
1525 | performing Duplicate Address Detection on the manually set local IPv4 addresses.\r | |
1526 | EFI_NOT_READY is returned immediately to indicate that such an asynchronous process\r | |
1527 | is invoked, and the process is not finished yet. The caller wanting to get the result\r | |
1528 | of the asynchronous process is required to call RegisterDataNotify() to register an\r | |
1529 | event on the specified configuration data. Once the event is signaled, the caller\r | |
1530 | can call GetData() to obtain the configuration data and know the result.\r | |
1531 | For other types of configuration data that do not require an asynchronous configuration\r | |
1532 | process, the result of the operation is immediately returned.\r | |
1533 | \r | |
1534 | @param[in] This The pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.\r | |
1535 | @param[in] DataType The type of data to set.\r | |
1536 | @param[in] DataSize Size of the buffer pointed to by Data in bytes.\r | |
1537 | @param[in] Data The data buffer to set. The type of the data buffer is\r | |
1538 | associated with the DataType.\r | |
1539 | \r | |
1540 | @retval EFI_SUCCESS The specified configuration data for the EFI IPv6\r | |
1541 | network stack was set successfully.\r | |
1542 | @retval EFI_INVALID_PARAMETER One or more of the following are TRUE:\r | |
1543 | - This is NULL.\r | |
1544 | - Data is NULL.\r | |
1545 | - One or more fields in Data do not match the requirement of the\r | |
1546 | data type indicated by DataType.\r | |
1547 | @retval EFI_WRITE_PROTECTED The specified configuration data is read-only or the specified\r | |
1548 | configuration data cannot be set under the current policy.\r | |
1549 | @retval EFI_ACCESS_DENIED Another set operation on the specified configuration\r | |
1550 | data is already in process.\r | |
1551 | @retval EFI_NOT_READY An asynchronous process was invoked to set the specified\r | |
1552 | configuration data, and the process is not finished yet.\r | |
1553 | @retval EFI_BAD_BUFFER_SIZE The DataSize does not match the size of the type\r | |
1554 | indicated by DataType.\r | |
1555 | @retval EFI_UNSUPPORTED This DataType is not supported.\r | |
1556 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r | |
1557 | @retval EFI_DEVICE_ERROR An unexpected system error or network error occurred.\r | |
1558 | \r | |
1559 | **/\r | |
1560 | EFI_STATUS\r | |
1561 | EFIAPI\r | |
1562 | EfiIp4Config2SetData (\r | |
1563 | IN EFI_IP4_CONFIG2_PROTOCOL *This,\r | |
1564 | IN EFI_IP4_CONFIG2_DATA_TYPE DataType,\r | |
1565 | IN UINTN DataSize,\r | |
1566 | IN VOID *Data\r | |
1567 | )\r | |
1568 | {\r | |
1569 | EFI_TPL OldTpl;\r | |
1570 | EFI_STATUS Status;\r | |
1571 | IP4_CONFIG2_INSTANCE *Instance;\r | |
1572 | IP4_SERVICE *IpSb;\r | |
1573 | \r | |
1574 | if ((This == NULL) || (Data == NULL)) {\r | |
1575 | return EFI_INVALID_PARAMETER;\r | |
1576 | }\r | |
1577 | \r | |
1578 | if (DataType >= Ip4Config2DataTypeMaximum) {\r | |
1579 | return EFI_UNSUPPORTED;\r | |
1580 | }\r | |
1581 | \r | |
1582 | Instance = IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This);\r | |
1583 | IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r | |
1584 | NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE);\r | |
1585 | \r | |
1586 | \r | |
1587 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1588 | \r | |
1589 | Status = Instance->DataItem[DataType].Status;\r | |
1590 | if (Status != EFI_NOT_READY) {\r | |
1591 | \r | |
1592 | if (Instance->DataItem[DataType].SetData == NULL) {\r | |
1593 | //\r | |
1594 | // This type of data is readonly.\r | |
1595 | //\r | |
1596 | Status = EFI_WRITE_PROTECTED;\r | |
1597 | } else {\r | |
1598 | \r | |
1599 | Status = Instance->DataItem[DataType].SetData (Instance, DataSize, Data);\r | |
1600 | if (!EFI_ERROR (Status)) {\r | |
1601 | //\r | |
1602 | // Fire up the events registered with this type of data.\r | |
1603 | //\r | |
1604 | NetMapIterate (&Instance->DataItem[DataType].EventMap, Ip4Config2SignalEvent, NULL);\r | |
1605 | Ip4Config2WriteConfigData (IpSb->MacString, Instance);\r | |
1606 | } else if (Status == EFI_ABORTED) {\r | |
1607 | //\r | |
1608 | // The SetData is aborted because the data to set is the same with\r | |
1609 | // the one maintained.\r | |
1610 | //\r | |
1611 | Status = EFI_SUCCESS;\r | |
1612 | NetMapIterate (&Instance->DataItem[DataType].EventMap, Ip4Config2SignalEvent, NULL);\r | |
1613 | }\r | |
1614 | }\r | |
1615 | } else {\r | |
1616 | //\r | |
1617 | // Another asynchornous process is on the way.\r | |
1618 | //\r | |
1619 | Status = EFI_ACCESS_DENIED;\r | |
1620 | }\r | |
1621 | \r | |
1622 | gBS->RestoreTPL (OldTpl);\r | |
1623 | \r | |
1624 | return Status;\r | |
1625 | }\r | |
1626 | \r | |
1627 | /**\r | |
1628 | Get the configuration data for the EFI IPv4 network stack running on the communication\r | |
1629 | device that this EFI_IP4_CONFIG2_PROTOCOL instance manages.\r | |
1630 | \r | |
1631 | This function returns the configuration data of type DataType for the EFI IPv4 network\r | |
1632 | stack running on the communication device that this EFI IPv4 Configuration Protocol instance\r | |
1633 | manages.\r | |
1634 | \r | |
1635 | The caller is responsible for allocating the buffer used to return the specified\r | |
1636 | configuration data. The required size will be returned to the caller if the size of\r | |
1637 | the buffer is too small.\r | |
1638 | \r | |
1639 | EFI_NOT_READY is returned if the specified configuration data is not ready due to an\r | |
1640 | asynchronous configuration process already in progress. The caller can call RegisterDataNotify()\r | |
1641 | to register an event on the specified configuration data. Once the asynchronous configuration\r | |
1642 | process is finished, the event will be signaled, and a subsequent GetData() call will return\r | |
1643 | the specified configuration data.\r | |
1644 | \r | |
1645 | @param[in] This Pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.\r | |
1646 | @param[in] DataType The type of data to get.\r | |
1647 | @param[in, out] DataSize On input, in bytes, the size of Data. On output, in bytes, the\r | |
1648 | size of buffer required to store the specified configuration data.\r | |
1649 | @param[in] Data The data buffer in which the configuration data is returned. The\r | |
1650 | type of the data buffer is associated with the DataType.\r | |
1651 | This is an optional parameter that may be NULL.\r | |
1652 | \r | |
1653 | @retval EFI_SUCCESS The specified configuration data was obtained successfully.\r | |
1654 | @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:\r | |
1655 | - This is NULL.\r | |
1656 | - DataSize is NULL.\r | |
1657 | - Data is NULL if *DataSize is not zero.\r | |
1658 | @retval EFI_BUFFER_TOO_SMALL The size of Data is too small for the specified configuration data,\r | |
1659 | and the required size is returned in DataSize.\r | |
1660 | @retval EFI_NOT_READY The specified configuration data is not ready due to an\r | |
1661 | asynchronous configuration process already in progress.\r | |
1662 | @retval EFI_NOT_FOUND The specified configuration data is not found.\r | |
1663 | \r | |
1664 | **/\r | |
1665 | EFI_STATUS\r | |
1666 | EFIAPI\r | |
1667 | EfiIp4Config2GetData (\r | |
1668 | IN EFI_IP4_CONFIG2_PROTOCOL *This,\r | |
1669 | IN EFI_IP4_CONFIG2_DATA_TYPE DataType,\r | |
1670 | IN OUT UINTN *DataSize,\r | |
1671 | IN VOID *Data OPTIONAL\r | |
1672 | )\r | |
1673 | {\r | |
1674 | EFI_TPL OldTpl;\r | |
1675 | EFI_STATUS Status;\r | |
1676 | IP4_CONFIG2_INSTANCE *Instance;\r | |
1677 | IP4_CONFIG2_DATA_ITEM *DataItem;\r | |
1678 | \r | |
1679 | if ((This == NULL) || (DataSize == NULL) || ((*DataSize != 0) && (Data == NULL))) {\r | |
1680 | return EFI_INVALID_PARAMETER;\r | |
1681 | }\r | |
1682 | \r | |
1683 | if (DataType >= Ip4Config2DataTypeMaximum) {\r | |
1684 | return EFI_NOT_FOUND;\r | |
1685 | }\r | |
1686 | \r | |
1687 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1688 | \r | |
1689 | Instance = IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This);\r | |
1690 | DataItem = &Instance->DataItem[DataType];\r | |
1691 | \r | |
1692 | Status = Instance->DataItem[DataType].Status;\r | |
1693 | if (!EFI_ERROR (Status)) {\r | |
1694 | \r | |
1695 | if (DataItem->GetData != NULL) {\r | |
1696 | \r | |
1697 | Status = DataItem->GetData (Instance, DataSize, Data);\r | |
1698 | } else if (*DataSize < Instance->DataItem[DataType].DataSize) {\r | |
1699 | //\r | |
1700 | // Update the buffer length.\r | |
1701 | //\r | |
1702 | *DataSize = Instance->DataItem[DataType].DataSize;\r | |
1703 | Status = EFI_BUFFER_TOO_SMALL;\r | |
1704 | } else {\r | |
1705 | \r | |
1706 | *DataSize = Instance->DataItem[DataType].DataSize;\r | |
1707 | CopyMem (Data, Instance->DataItem[DataType].Data.Ptr, *DataSize);\r | |
1708 | }\r | |
1709 | }\r | |
1710 | \r | |
1711 | gBS->RestoreTPL (OldTpl);\r | |
1712 | \r | |
1713 | return Status;\r | |
1714 | }\r | |
1715 | \r | |
1716 | /**\r | |
1717 | Register an event that is signaled whenever a configuration process on the specified\r | |
1718 | configuration data is done.\r | |
1719 | \r | |
1720 | This function registers an event that is to be signaled whenever a configuration\r | |
1721 | process on the specified configuration data is performed. An event can be registered\r | |
1722 | for a different DataType simultaneously. The caller is responsible for determining\r | |
1723 | which type of configuration data causes the signaling of the event in such an event.\r | |
1724 | \r | |
1725 | @param[in] This Pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.\r | |
1726 | @param[in] DataType The type of data to unregister the event for.\r | |
1727 | @param[in] Event The event to register.\r | |
1728 | \r | |
1729 | @retval EFI_SUCCESS The notification event for the specified configuration data is\r | |
1730 | registered.\r | |
1731 | @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.\r | |
1732 | @retval EFI_UNSUPPORTED The configuration data type specified by DataType is not\r | |
1733 | supported.\r | |
1734 | @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.\r | |
1735 | @retval EFI_ACCESS_DENIED The Event is already registered for the DataType.\r | |
1736 | \r | |
1737 | **/\r | |
1738 | EFI_STATUS\r | |
1739 | EFIAPI\r | |
1740 | EfiIp4Config2RegisterDataNotify (\r | |
1741 | IN EFI_IP4_CONFIG2_PROTOCOL *This,\r | |
1742 | IN EFI_IP4_CONFIG2_DATA_TYPE DataType,\r | |
1743 | IN EFI_EVENT Event\r | |
1744 | )\r | |
1745 | {\r | |
1746 | EFI_TPL OldTpl;\r | |
1747 | EFI_STATUS Status;\r | |
1748 | IP4_CONFIG2_INSTANCE *Instance;\r | |
1749 | NET_MAP *EventMap;\r | |
1750 | NET_MAP_ITEM *Item;\r | |
1751 | \r | |
1752 | if ((This == NULL) || (Event == NULL)) {\r | |
1753 | return EFI_INVALID_PARAMETER;\r | |
1754 | }\r | |
1755 | \r | |
1756 | if (DataType >= Ip4Config2DataTypeMaximum) {\r | |
1757 | return EFI_UNSUPPORTED;\r | |
1758 | }\r | |
1759 | \r | |
1760 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1761 | \r | |
1762 | Instance = IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This);\r | |
1763 | EventMap = &Instance->DataItem[DataType].EventMap;\r | |
1764 | \r | |
1765 | //\r | |
1766 | // Check whether this event is already registered for this DataType.\r | |
1767 | //\r | |
1768 | Item = NetMapFindKey (EventMap, Event);\r | |
1769 | if (Item == NULL) {\r | |
1770 | \r | |
1771 | Status = NetMapInsertTail (EventMap, Event, NULL);\r | |
1772 | \r | |
1773 | if (EFI_ERROR (Status)) {\r | |
1774 | \r | |
1775 | Status = EFI_OUT_OF_RESOURCES;\r | |
1776 | }\r | |
1777 | \r | |
1778 | } else {\r | |
1779 | \r | |
1780 | Status = EFI_ACCESS_DENIED;\r | |
1781 | }\r | |
1782 | \r | |
1783 | gBS->RestoreTPL (OldTpl);\r | |
1784 | \r | |
1785 | return Status;\r | |
1786 | }\r | |
1787 | \r | |
1788 | /**\r | |
1789 | Remove a previously registered event for the specified configuration data.\r | |
1790 | \r | |
1791 | @param This The pointer to the EFI_IP4_CONFIG2_PROTOCOL instance.\r | |
1792 | @param DataType The type of data to remove from the previously\r | |
1793 | registered event.\r | |
1794 | @param Event The event to be unregistered.\r | |
1795 | \r | |
1796 | @retval EFI_SUCCESS The event registered for the specified\r | |
1797 | configuration data was removed.\r | |
1798 | @retval EFI_INVALID_PARAMETER This is NULL or Event is NULL.\r | |
1799 | @retval EFI_NOT_FOUND The Event has not been registered for the\r | |
1800 | specified DataType.\r | |
1801 | \r | |
1802 | **/\r | |
1803 | EFI_STATUS\r | |
1804 | EFIAPI\r | |
1805 | EfiIp4Config2UnregisterDataNotify (\r | |
1806 | IN EFI_IP4_CONFIG2_PROTOCOL *This,\r | |
1807 | IN EFI_IP4_CONFIG2_DATA_TYPE DataType,\r | |
1808 | IN EFI_EVENT Event\r | |
1809 | )\r | |
1810 | {\r | |
1811 | EFI_TPL OldTpl;\r | |
1812 | EFI_STATUS Status;\r | |
1813 | IP4_CONFIG2_INSTANCE *Instance;\r | |
1814 | NET_MAP_ITEM *Item;\r | |
1815 | \r | |
1816 | if ((This == NULL) || (Event == NULL)) {\r | |
1817 | return EFI_INVALID_PARAMETER;\r | |
1818 | }\r | |
1819 | \r | |
1820 | if (DataType >= Ip4Config2DataTypeMaximum) {\r | |
1821 | return EFI_NOT_FOUND;\r | |
1822 | }\r | |
1823 | \r | |
1824 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1825 | \r | |
1826 | Instance = IP4_CONFIG2_INSTANCE_FROM_PROTOCOL (This);\r | |
1827 | \r | |
1828 | Item = NetMapFindKey (&Instance->DataItem[DataType].EventMap, Event);\r | |
1829 | if (Item != NULL) {\r | |
1830 | \r | |
1831 | NetMapRemoveItem (&Instance->DataItem[DataType].EventMap, Item, NULL);\r | |
1832 | Status = EFI_SUCCESS;\r | |
1833 | } else {\r | |
1834 | \r | |
1835 | Status = EFI_NOT_FOUND;\r | |
1836 | }\r | |
1837 | \r | |
1838 | gBS->RestoreTPL (OldTpl);\r | |
1839 | \r | |
1840 | return Status;\r | |
1841 | }\r | |
1842 | \r | |
1843 | /**\r | |
1844 | Initialize an IP4_CONFIG2_INSTANCE.\r | |
1845 | \r | |
1846 | @param[out] Instance The buffer of IP4_CONFIG2_INSTANCE to be initialized.\r | |
1847 | \r | |
1848 | @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to complete the operation.\r | |
1849 | @retval EFI_SUCCESS The IP4_CONFIG2_INSTANCE initialized successfully.\r | |
1850 | \r | |
1851 | **/\r | |
1852 | EFI_STATUS\r | |
1853 | Ip4Config2InitInstance (\r | |
1854 | OUT IP4_CONFIG2_INSTANCE *Instance\r | |
1855 | )\r | |
1856 | {\r | |
1857 | IP4_SERVICE *IpSb;\r | |
1858 | IP4_CONFIG2_INSTANCE *TmpInstance;\r | |
1859 | LIST_ENTRY *Entry;\r | |
1860 | EFI_STATUS Status;\r | |
1861 | UINTN Index;\r | |
1862 | UINT16 IfIndex;\r | |
1863 | IP4_CONFIG2_DATA_ITEM *DataItem;\r | |
1864 | \r | |
1865 | \r | |
1866 | IpSb = IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance);\r | |
1867 | \r | |
1868 | Instance->Signature = IP4_CONFIG2_INSTANCE_SIGNATURE;\r | |
1869 | \r | |
1870 | \r | |
1871 | //\r | |
1872 | // Determine the index of this interface.\r | |
1873 | //\r | |
1874 | IfIndex = 0;\r | |
1875 | NET_LIST_FOR_EACH (Entry, &mIp4Config2InstanceList) {\r | |
1876 | TmpInstance = NET_LIST_USER_STRUCT_S (Entry, IP4_CONFIG2_INSTANCE, Link, IP4_CONFIG2_INSTANCE_SIGNATURE);\r | |
1877 | \r | |
1878 | if (TmpInstance->IfIndex > IfIndex) {\r | |
1879 | //\r | |
1880 | // There is a sequence hole because some interface is down.\r | |
1881 | //\r | |
1882 | break;\r | |
1883 | }\r | |
1884 | \r | |
1885 | IfIndex++;\r | |
1886 | }\r | |
1887 | \r | |
1888 | Instance->IfIndex = IfIndex;\r | |
1889 | NetListInsertBefore (Entry, &Instance->Link);\r | |
1890 | \r | |
1891 | for (Index = 0; Index < Ip4Config2DataTypeMaximum; Index++) {\r | |
1892 | //\r | |
1893 | // Initialize the event map for each data item.\r | |
1894 | //\r | |
1895 | NetMapInit (&Instance->DataItem[Index].EventMap);\r | |
1896 | }\r | |
1897 | \r | |
1898 | \r | |
1899 | //\r | |
1900 | // Initialize each data type: associate storage and set data size for the\r | |
1901 | // fixed size data types, hook the SetData function, set the data attribute.\r | |
1902 | //\r | |
1903 | DataItem = &Instance->DataItem[Ip4Config2DataTypeInterfaceInfo];\r | |
1904 | DataItem->GetData = Ip4Config2GetIfInfo;\r | |
1905 | DataItem->Data.Ptr = &Instance->InterfaceInfo;\r | |
1906 | DataItem->DataSize = sizeof (Instance->InterfaceInfo);\r | |
1907 | SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED | DATA_ATTRIB_VOLATILE);\r | |
1908 | Ip4Config2InitIfInfo (IpSb, &Instance->InterfaceInfo);\r | |
1909 | \r | |
1910 | DataItem = &Instance->DataItem[Ip4Config2DataTypePolicy];\r | |
1911 | DataItem->SetData = Ip4Config2SetPolicy;\r | |
1912 | DataItem->Data.Ptr = &Instance->Policy;\r | |
1913 | DataItem->DataSize = sizeof (Instance->Policy);\r | |
7648748e | 1914 | Instance->Policy = Ip4Config2PolicyStatic;\r |
1f6729ff | 1915 | SET_DATA_ATTRIB (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED);\r |
1916 | \r | |
1917 | DataItem = &Instance->DataItem[Ip4Config2DataTypeManualAddress];\r | |
1918 | DataItem->SetData = Ip4Config2SetMaunualAddress;\r | |
1919 | DataItem->Status = EFI_NOT_FOUND;\r | |
1920 | \r | |
1921 | DataItem = &Instance->DataItem[Ip4Config2DataTypeGateway];\r | |
1922 | DataItem->SetData = Ip4Config2SetGateway;\r | |
1923 | DataItem->Status = EFI_NOT_FOUND;\r | |
1924 | \r | |
1925 | DataItem = &Instance->DataItem[Ip4Config2DataTypeDnsServer];\r | |
1926 | DataItem->SetData = Ip4Config2SetDnsServer;\r | |
1927 | DataItem->Status = EFI_NOT_FOUND;\r | |
1928 | \r | |
1929 | //\r | |
1930 | // Create the event used for DHCP.\r | |
1931 | //\r | |
1932 | Status = gBS->CreateEvent (\r | |
1933 | EVT_NOTIFY_SIGNAL,\r | |
1934 | TPL_CALLBACK,\r | |
1935 | Ip4Config2OnDhcp4Event,\r | |
1936 | Instance,\r | |
1937 | &Instance->Dhcp4Event\r | |
1938 | );\r | |
1939 | ASSERT_EFI_ERROR (Status);\r | |
1940 | \r | |
1941 | Instance->Configured = TRUE;\r | |
1942 | \r | |
1943 | //\r | |
1944 | // Try to read the config data from NV variable.\r | |
7648748e JW |
1945 | // If not found, write initialized config data into NV variable \r |
1946 | // as a default config data.\r | |
1f6729ff | 1947 | //\r |
1948 | Status = Ip4Config2ReadConfigData (IpSb->MacString, Instance);\r | |
1949 | if (Status == EFI_NOT_FOUND) {\r | |
1950 | Status = Ip4Config2WriteConfigData (IpSb->MacString, Instance);\r | |
1951 | }\r | |
1952 | \r | |
1953 | if (EFI_ERROR (Status)) {\r | |
1954 | return Status;\r | |
1955 | }\r | |
7648748e | 1956 | \r |
1f6729ff | 1957 | Instance->Ip4Config2.SetData = EfiIp4Config2SetData;\r |
1958 | Instance->Ip4Config2.GetData = EfiIp4Config2GetData;\r | |
1959 | Instance->Ip4Config2.RegisterDataNotify = EfiIp4Config2RegisterDataNotify;\r | |
1960 | Instance->Ip4Config2.UnregisterDataNotify = EfiIp4Config2UnregisterDataNotify;\r | |
1961 | \r | |
1962 | //\r | |
1963 | // Publish the IP4 configuration form\r | |
1964 | //\r | |
1965 | return Ip4Config2FormInit (Instance);\r | |
1966 | }\r | |
1967 | \r | |
1968 | \r | |
1969 | /**\r | |
1970 | Release an IP4_CONFIG2_INSTANCE.\r | |
1971 | \r | |
1972 | @param[in, out] Instance The buffer of IP4_CONFIG2_INSTANCE to be freed.\r | |
1973 | \r | |
1974 | **/\r | |
1975 | VOID\r | |
1976 | Ip4Config2CleanInstance (\r | |
1977 | IN OUT IP4_CONFIG2_INSTANCE *Instance\r | |
1978 | )\r | |
1979 | {\r | |
1980 | UINTN Index;\r | |
1981 | IP4_CONFIG2_DATA_ITEM *DataItem;\r | |
1982 | \r | |
1983 | if (Instance->DeclineAddress != NULL) {\r | |
1984 | FreePool (Instance->DeclineAddress);\r | |
1985 | }\r | |
1986 | \r | |
1987 | if (!Instance->Configured) {\r | |
1988 | return ;\r | |
1989 | }\r | |
1990 | \r | |
1991 | if (Instance->Dhcp4Handle != NULL) {\r | |
1992 | \r | |
1993 | Ip4Config2DestroyDhcp4 (Instance);\r | |
1994 | }\r | |
1995 | \r | |
1996 | //\r | |
1997 | // Close the event.\r | |
1998 | //\r | |
1999 | if (Instance->Dhcp4Event != NULL) {\r | |
2000 | gBS->CloseEvent (Instance->Dhcp4Event);\r | |
4f0f2316 | 2001 | Instance->Dhcp4Event = NULL;\r |
1f6729ff | 2002 | }\r |
2003 | \r | |
2004 | for (Index = 0; Index < Ip4Config2DataTypeMaximum; Index++) {\r | |
2005 | \r | |
2006 | DataItem = &Instance->DataItem[Index];\r | |
2007 | \r | |
2008 | if (!DATA_ATTRIB_SET (DataItem->Attribute, DATA_ATTRIB_SIZE_FIXED)) {\r | |
2009 | if (DataItem->Data.Ptr != NULL) {\r | |
2010 | FreePool (DataItem->Data.Ptr);\r | |
2011 | }\r | |
2012 | DataItem->Data.Ptr = NULL;\r | |
2013 | DataItem->DataSize = 0;\r | |
2014 | }\r | |
2015 | \r | |
2016 | NetMapClean (&Instance->DataItem[Index].EventMap);\r | |
2017 | }\r | |
2018 | \r | |
2019 | Ip4Config2FormUnload (Instance);\r | |
2020 | \r | |
2021 | RemoveEntryList (&Instance->Link);\r | |
2022 | }\r | |
2023 | \r | |
7648748e JW |
2024 | /**\r |
2025 | The event handle for IP4 auto reconfiguration. The original default\r | |
2026 | interface and route table will be removed as the default.\r | |
2027 | \r | |
2028 | @param[in] Context The IP4 service binding instance.\r | |
2029 | \r | |
2030 | **/\r | |
2031 | VOID\r | |
2032 | EFIAPI\r | |
2033 | Ip4AutoReconfigCallBackDpc (\r | |
2034 | IN VOID *Context\r | |
2035 | )\r | |
2036 | {\r | |
2037 | IP4_SERVICE *IpSb;\r | |
2038 | \r | |
2039 | IpSb = (IP4_SERVICE *) Context;\r | |
2040 | NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE);\r | |
2041 | \r | |
2042 | if (IpSb->State > IP4_SERVICE_UNSTARTED) {\r | |
2043 | IpSb->State = IP4_SERVICE_UNSTARTED;\r | |
2044 | }\r | |
2045 | \r | |
2046 | IpSb->Reconfig = TRUE;\r | |
2047 | \r | |
2048 | Ip4StartAutoConfig (&IpSb->Ip4Config2Instance);\r | |
2049 | \r | |
2050 | return ;\r | |
2051 | }\r | |
2052 | \r | |
2053 | \r | |
2054 | /**\r | |
2055 | Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK.\r | |
2056 | \r | |
2057 | @param Event The event that is signalled.\r | |
2058 | @param Context The IP4 service binding instance.\r | |
2059 | \r | |
2060 | **/\r | |
2061 | VOID\r | |
2062 | EFIAPI\r | |
2063 | Ip4AutoReconfigCallBack (\r | |
2064 | IN EFI_EVENT Event,\r | |
2065 | IN VOID *Context\r | |
2066 | )\r | |
2067 | {\r | |
2068 | //\r | |
2069 | // Request Ip4AutoReconfigCallBackDpc as a DPC at TPL_CALLBACK\r | |
2070 | //\r | |
2071 | QueueDpc (TPL_CALLBACK, Ip4AutoReconfigCallBackDpc, Context);\r | |
2072 | }\r | |
2073 | \r |