]>
Commit | Line | Data |
---|---|---|
8a67d61d | 1 | /** @file\r |
2 | \r | |
216f7970 | 3 | Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 4 | This program and the accompanying materials\r |
8a67d61d | 5 | are licensed and made available under the terms and conditions of the BSD License\r |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
8a67d61d | 12 | **/\r |
13 | \r | |
14 | \r | |
15 | #include "Udp4Impl.h"\r | |
16 | \r | |
17 | EFI_DRIVER_BINDING_PROTOCOL gUdp4DriverBinding = {\r | |
18 | Udp4DriverBindingSupported,\r | |
19 | Udp4DriverBindingStart,\r | |
20 | Udp4DriverBindingStop,\r | |
21 | 0xa,\r | |
22 | NULL,\r | |
23 | NULL\r | |
24 | };\r | |
25 | \r | |
26 | EFI_SERVICE_BINDING_PROTOCOL mUdp4ServiceBinding = {\r | |
27 | Udp4ServiceBindingCreateChild,\r | |
28 | Udp4ServiceBindingDestroyChild\r | |
29 | };\r | |
30 | \r | |
216f7970 | 31 | /**\r |
32 | Callback function which provided by user to remove one node in NetDestroyLinkList process.\r | |
33 | \r | |
34 | @param[in] Entry The entry to be removed.\r | |
35 | @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.\r | |
36 | \r | |
37 | @retval EFI_SUCCESS The entry has been removed successfully.\r | |
38 | @retval Others Fail to remove the entry.\r | |
39 | \r | |
40 | **/\r | |
41 | EFI_STATUS\r | |
1f7eb561 | 42 | EFIAPI\r |
216f7970 | 43 | Udp4DestroyChildEntryInHandleBuffer (\r |
44 | IN LIST_ENTRY *Entry,\r | |
45 | IN VOID *Context\r | |
1f7eb561 | 46 | )\r |
216f7970 | 47 | {\r |
48 | UDP4_INSTANCE_DATA *Instance;\r | |
49 | EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r | |
50 | UINTN NumberOfChildren;\r | |
51 | EFI_HANDLE *ChildHandleBuffer;\r | |
52 | \r | |
53 | if (Entry == NULL || Context == NULL) {\r | |
54 | return EFI_INVALID_PARAMETER;\r | |
55 | }\r | |
56 | \r | |
57 | Instance = NET_LIST_USER_STRUCT_S (Entry, UDP4_INSTANCE_DATA, Link, UDP4_INSTANCE_DATA_SIGNATURE);\r | |
58 | ServiceBinding = ((UDP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;\r | |
59 | NumberOfChildren = ((UDP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;\r | |
60 | ChildHandleBuffer = ((UDP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;\r | |
61 | \r | |
62 | if (!NetIsInHandleBuffer (Instance->ChildHandle, NumberOfChildren, ChildHandleBuffer)) {\r | |
63 | return EFI_SUCCESS;\r | |
64 | }\r | |
65 | \r | |
66 | return ServiceBinding->DestroyChild (ServiceBinding, Instance->ChildHandle);\r | |
67 | }\r | |
68 | \r | |
8a67d61d | 69 | \r |
70 | /**\r | |
bab52709 | 71 | Test to see if this driver supports ControllerHandle. This service\r |
72 | is called by the EFI boot service ConnectController(). In\r | |
73 | order to make drivers as small as possible, there are a few calling\r | |
74 | restrictions for this service. ConnectController() must\r | |
75 | follow these calling restrictions. If any other agent wishes to call\r | |
76 | Supported() it must also follow these calling restrictions.\r | |
77 | \r | |
3e8c18da | 78 | @param[in] This Protocol instance pointer.\r |
79 | @param[in] ControllerHandle Handle of device to test\r | |
80 | @param[in] RemainingDevicePath Optional parameter use to pick a specific child\r | |
81 | device to start.\r | |
bab52709 | 82 | \r |
83 | @retval EFI_SUCCESS This driver supports this device\r | |
84 | @retval EFI_ALREADY_STARTED This driver is already running on this device\r | |
85 | @retval other This driver does not support this device\r | |
8a67d61d | 86 | \r |
87 | **/\r | |
88 | EFI_STATUS\r | |
89 | EFIAPI\r | |
90 | Udp4DriverBindingSupported (\r | |
91 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
92 | IN EFI_HANDLE ControllerHandle,\r | |
93 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
94 | )\r | |
95 | {\r | |
96 | EFI_STATUS Status;\r | |
97 | \r | |
98 | //\r | |
99 | // Test for the Udp4ServiceBinding Protocol\r | |
100 | //\r | |
101 | Status = gBS->OpenProtocol (\r | |
102 | ControllerHandle,\r | |
103 | &gEfiUdp4ServiceBindingProtocolGuid,\r | |
104 | NULL,\r | |
105 | This->DriverBindingHandle,\r | |
106 | ControllerHandle,\r | |
107 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
108 | );\r | |
109 | if (!EFI_ERROR (Status)) {\r | |
110 | return EFI_ALREADY_STARTED;\r | |
111 | }\r | |
112 | \r | |
113 | //\r | |
114 | // Test for the Ip4 Protocol\r | |
115 | //\r | |
116 | Status = gBS->OpenProtocol (\r | |
117 | ControllerHandle,\r | |
118 | &gEfiIp4ServiceBindingProtocolGuid,\r | |
119 | NULL,\r | |
120 | This->DriverBindingHandle,\r | |
121 | ControllerHandle,\r | |
122 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
123 | );\r | |
124 | \r | |
125 | return Status;\r | |
126 | }\r | |
127 | \r | |
128 | \r | |
129 | /**\r | |
bab52709 | 130 | Start this driver on ControllerHandle. This service is called by the\r |
131 | EFI boot service ConnectController(). In order to make\r | |
132 | drivers as small as possible, there are a few calling restrictions for\r | |
133 | this service. ConnectController() must follow these\r | |
134 | calling restrictions. If any other agent wishes to call Start() it\r | |
135 | must also follow these calling restrictions.\r | |
136 | \r | |
3e8c18da | 137 | @param[in] This Protocol instance pointer.\r |
138 | @param[in] ControllerHandle Handle of device to bind driver to\r | |
139 | @param[in] RemainingDevicePath Optional parameter use to pick a specific child\r | |
140 | device to start.\r | |
bab52709 | 141 | \r |
142 | @retval EFI_SUCCESS This driver is added to ControllerHandle\r | |
143 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r | |
144 | @retval other This driver does not support this device\r | |
8a67d61d | 145 | \r |
146 | **/\r | |
147 | EFI_STATUS\r | |
148 | EFIAPI\r | |
149 | Udp4DriverBindingStart (\r | |
150 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
151 | IN EFI_HANDLE ControllerHandle,\r | |
152 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
153 | )\r | |
154 | {\r | |
155 | EFI_STATUS Status;\r | |
156 | UDP4_SERVICE_DATA *Udp4Service;\r | |
157 | \r | |
158 | //\r | |
159 | // Allocate Private Context Data Structure.\r | |
160 | //\r | |
e48e37fc | 161 | Udp4Service = AllocatePool (sizeof (UDP4_SERVICE_DATA));\r |
8a67d61d | 162 | if (Udp4Service == NULL) {\r |
163 | return EFI_OUT_OF_RESOURCES;\r | |
164 | }\r | |
165 | \r | |
166 | Status = Udp4CreateService (Udp4Service, This->DriverBindingHandle, ControllerHandle);\r | |
167 | if (EFI_ERROR (Status)) {\r | |
766c7483 | 168 | FreePool (Udp4Service);\r |
c4a62a12 | 169 | return Status;\r |
8a67d61d | 170 | }\r |
171 | \r | |
172 | //\r | |
173 | // Install the Udp4ServiceBindingProtocol on the ControllerHandle.\r | |
174 | //\r | |
175 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
176 | &ControllerHandle,\r | |
177 | &gEfiUdp4ServiceBindingProtocolGuid,\r | |
178 | &Udp4Service->ServiceBinding,\r | |
179 | NULL\r | |
180 | );\r | |
181 | if (EFI_ERROR (Status)) {\r | |
c4a62a12 | 182 | Udp4CleanService (Udp4Service);\r |
766c7483 | 183 | FreePool (Udp4Service);\r |
c4a62a12 | 184 | } else {\r |
185 | Udp4SetVariableData (Udp4Service);\r | |
8a67d61d | 186 | }\r |
187 | \r | |
8a67d61d | 188 | return Status;\r |
189 | }\r | |
190 | \r | |
191 | \r | |
192 | /**\r | |
bab52709 | 193 | Stop this driver on ControllerHandle. This service is called by the\r |
194 | EFI boot service DisconnectController(). In order to\r | |
195 | make drivers as small as possible, there are a few calling\r | |
196 | restrictions for this service. DisconnectController()\r | |
197 | must follow these calling restrictions. If any other agent wishes\r | |
198 | to call Stop() it must also follow these calling restrictions.\r | |
199 | \r | |
3e8c18da | 200 | @param[in] This Protocol instance pointer.\r |
201 | @param[in] ControllerHandle Handle of device to stop driver on\r | |
202 | @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
203 | children is zero stop the entire bus driver.\r | |
204 | @param[in] ChildHandleBuffer List of Child Handles to Stop.\r | |
bab52709 | 205 | \r |
206 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r | |
207 | @retval other This driver was not removed from this device\r | |
8a67d61d | 208 | \r |
209 | **/\r | |
210 | EFI_STATUS\r | |
211 | EFIAPI\r | |
212 | Udp4DriverBindingStop (\r | |
213 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
214 | IN EFI_HANDLE ControllerHandle,\r | |
215 | IN UINTN NumberOfChildren,\r | |
216 | IN EFI_HANDLE *ChildHandleBuffer\r | |
217 | )\r | |
218 | {\r | |
216f7970 | 219 | EFI_STATUS Status;\r |
220 | EFI_HANDLE NicHandle;\r | |
221 | EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r | |
222 | UDP4_SERVICE_DATA *Udp4Service;\r | |
223 | UDP4_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;\r | |
224 | LIST_ENTRY *List;\r | |
8a67d61d | 225 | \r |
226 | //\r | |
227 | // Find the NicHandle where UDP4 ServiceBinding Protocol is installed.\r | |
228 | //\r | |
229 | NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiIp4ProtocolGuid);\r | |
230 | if (NicHandle == NULL) {\r | |
216f7970 | 231 | return EFI_SUCCESS;\r |
8a67d61d | 232 | }\r |
233 | \r | |
234 | //\r | |
235 | // Retrieve the UDP4 ServiceBinding Protocol.\r | |
236 | //\r | |
237 | Status = gBS->OpenProtocol (\r | |
238 | NicHandle,\r | |
239 | &gEfiUdp4ServiceBindingProtocolGuid,\r | |
240 | (VOID **) &ServiceBinding,\r | |
241 | This->DriverBindingHandle,\r | |
242 | NicHandle,\r | |
243 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
244 | );\r | |
245 | if (EFI_ERROR (Status)) {\r | |
246 | return EFI_DEVICE_ERROR;\r | |
247 | }\r | |
248 | \r | |
249 | Udp4Service = UDP4_SERVICE_DATA_FROM_THIS (ServiceBinding);\r | |
216f7970 | 250 | if (NumberOfChildren != 0) {\r |
251 | //\r | |
252 | // NumberOfChildren is not zero, destroy the children instances in ChildHandleBuffer.\r | |
253 | //\r | |
254 | List = &Udp4Service->ChildrenList;\r | |
255 | Context.ServiceBinding = ServiceBinding;\r | |
256 | Context.NumberOfChildren = NumberOfChildren;\r | |
257 | Context.ChildHandleBuffer = ChildHandleBuffer;\r | |
258 | Status = NetDestroyLinkList (\r | |
259 | List,\r | |
260 | Udp4DestroyChildEntryInHandleBuffer,\r | |
261 | &Context,\r | |
262 | NULL\r | |
263 | );\r | |
264 | } else {\r | |
c4a62a12 | 265 | gBS->UninstallMultipleProtocolInterfaces (\r |
266 | NicHandle,\r | |
267 | &gEfiUdp4ServiceBindingProtocolGuid,\r | |
268 | &Udp4Service->ServiceBinding,\r | |
269 | NULL\r | |
270 | );\r | |
8a67d61d | 271 | \r |
c4a62a12 | 272 | Udp4ClearVariableData (Udp4Service);\r |
8a67d61d | 273 | \r |
c4a62a12 | 274 | Udp4CleanService (Udp4Service);\r |
8a67d61d | 275 | \r |
216f7970 | 276 | if (gUdpControllerNameTable != NULL) {\r |
277 | FreeUnicodeStringTable (gUdpControllerNameTable);\r | |
278 | gUdpControllerNameTable = NULL;\r | |
c4a62a12 | 279 | }\r |
216f7970 | 280 | FreePool (Udp4Service);\r |
c4a62a12 | 281 | }\r |
282 | \r | |
283 | return Status;\r | |
8a67d61d | 284 | }\r |
285 | \r | |
286 | \r | |
287 | /**\r | |
3e8c18da | 288 | Creates a child handle and installs a protocol.\r |
289 | \r | |
290 | The CreateChild() function installs a protocol on ChildHandle. \r | |
291 | If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle. \r | |
292 | If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.\r | |
8a67d61d | 293 | \r |
47c75f64 | 294 | @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r |
295 | @param[in] ChildHandle Pointer to the handle of the child to create. If it is NULL,\r | |
296 | then a new handle is created. If it is a pointer to an existing UEFI handle, \r | |
297 | then the protocol is added to the existing UEFI handle.\r | |
8a67d61d | 298 | \r |
3e8c18da | 299 | @retval EFI_SUCCES The protocol was added to ChildHandle.\r |
bab52709 | 300 | @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r |
301 | @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create\r | |
302 | the child\r | |
303 | @retval other The child handle was not created\r | |
8a67d61d | 304 | \r |
305 | **/\r | |
306 | EFI_STATUS\r | |
307 | EFIAPI\r | |
308 | Udp4ServiceBindingCreateChild (\r | |
309 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r | |
310 | IN EFI_HANDLE *ChildHandle\r | |
311 | )\r | |
312 | {\r | |
313 | EFI_STATUS Status;\r | |
314 | UDP4_SERVICE_DATA *Udp4Service;\r | |
315 | UDP4_INSTANCE_DATA *Instance;\r | |
316 | EFI_TPL OldTpl;\r | |
317 | VOID *Ip4;\r | |
318 | \r | |
319 | if ((This == NULL) || (ChildHandle == NULL)) {\r | |
320 | return EFI_INVALID_PARAMETER;\r | |
321 | }\r | |
322 | \r | |
323 | Udp4Service = UDP4_SERVICE_DATA_FROM_THIS (This);\r | |
324 | \r | |
325 | //\r | |
326 | // Allocate the instance private data structure.\r | |
327 | //\r | |
e48e37fc | 328 | Instance = AllocateZeroPool (sizeof (UDP4_INSTANCE_DATA));\r |
8a67d61d | 329 | if (Instance == NULL) {\r |
330 | return EFI_OUT_OF_RESOURCES;\r | |
331 | }\r | |
332 | \r | |
333 | Udp4InitInstance (Udp4Service, Instance);\r | |
334 | \r | |
335 | //\r | |
336 | // Add an IpInfo for this instance.\r | |
337 | //\r | |
338 | Instance->IpInfo = IpIoAddIp (Udp4Service->IpIo);\r | |
339 | if (Instance->IpInfo == NULL) {\r | |
340 | Status = EFI_OUT_OF_RESOURCES;\r | |
c4a62a12 | 341 | goto ON_ERROR;\r |
8a67d61d | 342 | }\r |
343 | \r | |
344 | //\r | |
345 | // Install the Udp4Protocol for this instance.\r | |
346 | //\r | |
347 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
348 | ChildHandle,\r | |
349 | &gEfiUdp4ProtocolGuid,\r | |
350 | &Instance->Udp4Proto,\r | |
351 | NULL\r | |
352 | );\r | |
353 | if (EFI_ERROR (Status)) {\r | |
c4a62a12 | 354 | goto ON_ERROR;\r |
8a67d61d | 355 | }\r |
356 | \r | |
357 | Instance->ChildHandle = *ChildHandle;\r | |
358 | \r | |
359 | //\r | |
360 | // Open the default Ip4 protocol in the IP_IO BY_CHILD.\r | |
361 | //\r | |
362 | Status = gBS->OpenProtocol (\r | |
363 | Udp4Service->IpIo->ChildHandle,\r | |
364 | &gEfiIp4ProtocolGuid,\r | |
365 | (VOID **) &Ip4,\r | |
366 | gUdp4DriverBinding.DriverBindingHandle,\r | |
367 | Instance->ChildHandle,\r | |
368 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
369 | );\r | |
370 | if (EFI_ERROR (Status)) {\r | |
c4a62a12 | 371 | goto ON_ERROR;\r |
8a67d61d | 372 | }\r |
373 | \r | |
216f7970 | 374 | //\r |
375 | // Open this instance's Ip4 protocol in the IpInfo BY_CHILD.\r | |
376 | //\r | |
377 | Status = gBS->OpenProtocol (\r | |
378 | Instance->IpInfo->ChildHandle,\r | |
379 | &gEfiIp4ProtocolGuid,\r | |
380 | (VOID **) &Ip4,\r | |
381 | gUdp4DriverBinding.DriverBindingHandle,\r | |
382 | Instance->ChildHandle,\r | |
383 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
384 | );\r | |
385 | if (EFI_ERROR (Status)) {\r | |
386 | goto ON_ERROR;\r | |
387 | }\r | |
388 | \r | |
e48e37fc | 389 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 390 | \r |
391 | //\r | |
392 | // Link this instance into the service context data and increase the ChildrenNumber.\r | |
393 | //\r | |
e48e37fc | 394 | InsertTailList (&Udp4Service->ChildrenList, &Instance->Link);\r |
8a67d61d | 395 | Udp4Service->ChildrenNumber++;\r |
396 | \r | |
e48e37fc | 397 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 398 | \r |
c4a62a12 | 399 | return EFI_SUCCESS;\r |
8a67d61d | 400 | \r |
c4a62a12 | 401 | ON_ERROR:\r |
8a67d61d | 402 | \r |
c4a62a12 | 403 | if (Instance->ChildHandle != NULL) {\r |
404 | gBS->UninstallMultipleProtocolInterfaces (\r | |
405 | Instance->ChildHandle,\r | |
406 | &gEfiUdp4ProtocolGuid,\r | |
407 | &Instance->Udp4Proto,\r | |
408 | NULL\r | |
409 | );\r | |
410 | }\r | |
8a67d61d | 411 | \r |
c4a62a12 | 412 | if (Instance->IpInfo != NULL) {\r |
413 | IpIoRemoveIp (Udp4Service->IpIo, Instance->IpInfo);\r | |
414 | }\r | |
8a67d61d | 415 | \r |
416 | Udp4CleanInstance (Instance);\r | |
417 | \r | |
766c7483 | 418 | FreePool (Instance);\r |
8a67d61d | 419 | \r |
420 | return Status;\r | |
421 | }\r | |
422 | \r | |
423 | \r | |
424 | /**\r | |
3e8c18da | 425 | Destroys a child handle with a protocol installed on it.\r |
426 | \r | |
427 | The DestroyChild() function does the opposite of CreateChild(). It removes a protocol \r | |
428 | that was installed by CreateChild() from ChildHandle. If the removed protocol is the \r | |
429 | last protocol on ChildHandle, then ChildHandle is destroyed.\r | |
8a67d61d | 430 | \r |
47c75f64 | 431 | @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r |
432 | @param[in] ChildHandle Handle of the child to destroy\r | |
8a67d61d | 433 | \r |
3e8c18da | 434 | @retval EFI_SUCCES The protocol was removed from ChildHandle.\r |
435 | @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r | |
284ee2e8 | 436 | @retval EFI_INVALID_PARAMETER Child handle is NULL.\r |
3e8c18da | 437 | @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle\r |
438 | because its services are being used.\r | |
bab52709 | 439 | @retval other The child handle was not destroyed\r |
8a67d61d | 440 | \r |
441 | **/\r | |
442 | EFI_STATUS\r | |
443 | EFIAPI\r | |
444 | Udp4ServiceBindingDestroyChild (\r | |
445 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r | |
446 | IN EFI_HANDLE ChildHandle\r | |
447 | )\r | |
448 | {\r | |
449 | EFI_STATUS Status;\r | |
450 | UDP4_SERVICE_DATA *Udp4Service;\r | |
451 | EFI_UDP4_PROTOCOL *Udp4Proto;\r | |
452 | UDP4_INSTANCE_DATA *Instance;\r | |
453 | EFI_TPL OldTpl;\r | |
454 | \r | |
455 | if ((This == NULL) || (ChildHandle == NULL)) {\r | |
456 | return EFI_INVALID_PARAMETER;\r | |
457 | }\r | |
458 | \r | |
459 | Udp4Service = UDP4_SERVICE_DATA_FROM_THIS (This);\r | |
460 | \r | |
461 | //\r | |
462 | // Try to get the Udp4 protocol from the ChildHandle.\r | |
463 | //\r | |
464 | Status = gBS->OpenProtocol (\r | |
465 | ChildHandle,\r | |
466 | &gEfiUdp4ProtocolGuid,\r | |
467 | (VOID **) &Udp4Proto,\r | |
468 | gUdp4DriverBinding.DriverBindingHandle,\r | |
469 | ChildHandle,\r | |
470 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
471 | );\r | |
472 | if (EFI_ERROR (Status)) {\r | |
473 | return EFI_UNSUPPORTED;\r | |
474 | }\r | |
475 | \r | |
476 | Instance = UDP4_INSTANCE_DATA_FROM_THIS (Udp4Proto);\r | |
477 | \r | |
216f7970 | 478 | if (Instance->InDestroy) {\r |
8a67d61d | 479 | return EFI_SUCCESS;\r |
480 | }\r | |
481 | \r | |
482 | //\r | |
483 | // Use the Destroyed flag to avoid the re-entering of the following code.\r | |
484 | //\r | |
216f7970 | 485 | Instance->InDestroy = TRUE;\r |
8a67d61d | 486 | \r |
487 | //\r | |
488 | // Close the Ip4 protocol.\r | |
489 | //\r | |
490 | gBS->CloseProtocol (\r | |
491 | Udp4Service->IpIo->ChildHandle,\r | |
492 | &gEfiIp4ProtocolGuid,\r | |
493 | gUdp4DriverBinding.DriverBindingHandle,\r | |
494 | Instance->ChildHandle\r | |
495 | );\r | |
216f7970 | 496 | //\r |
497 | // Close the Ip4 protocol on this instance's IpInfo.\r | |
498 | //\r | |
499 | gBS->CloseProtocol (\r | |
500 | Instance->IpInfo->ChildHandle,\r | |
501 | &gEfiIp4ProtocolGuid,\r | |
502 | gUdp4DriverBinding.DriverBindingHandle,\r | |
503 | Instance->ChildHandle\r | |
504 | ); \r | |
8a67d61d | 505 | \r |
506 | //\r | |
507 | // Uninstall the Udp4Protocol previously installed on the ChildHandle.\r | |
508 | //\r | |
509 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
510 | ChildHandle,\r | |
511 | &gEfiUdp4ProtocolGuid,\r | |
512 | (VOID *) &Instance->Udp4Proto,\r | |
513 | NULL\r | |
514 | );\r | |
515 | if (EFI_ERROR (Status)) {\r | |
216f7970 | 516 | Instance->InDestroy = FALSE;\r |
8a67d61d | 517 | return Status;\r |
518 | }\r | |
519 | \r | |
520 | //\r | |
521 | // Reset the configuration in case the instance's consumer forgets to do this.\r | |
522 | //\r | |
523 | Udp4Proto->Configure (Udp4Proto, NULL);\r | |
524 | \r | |
525 | //\r | |
526 | // Remove the IpInfo this instance consumes.\r | |
527 | //\r | |
528 | IpIoRemoveIp (Udp4Service->IpIo, Instance->IpInfo);\r | |
529 | \r | |
e48e37fc | 530 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 531 | \r |
532 | //\r | |
533 | // Remove this instance from the service context data's ChildrenList.\r | |
534 | //\r | |
e48e37fc | 535 | RemoveEntryList (&Instance->Link);\r |
8a67d61d | 536 | Udp4Service->ChildrenNumber--;\r |
537 | \r | |
538 | //\r | |
539 | // Clean the instance.\r | |
540 | //\r | |
541 | Udp4CleanInstance (Instance);\r | |
542 | \r | |
e48e37fc | 543 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 544 | \r |
766c7483 | 545 | FreePool (Instance);\r |
8a67d61d | 546 | \r |
547 | return EFI_SUCCESS;\r | |
548 | }\r | |
549 | \r | |
bab52709 | 550 | /**\r |
551 | This is the declaration of an EFI image entry point. This entry point is\r | |
552 | the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r | |
553 | both device drivers and bus drivers.\r | |
554 | \r | |
555 | The entry point for Udp4 driver which installs the driver binding\r | |
556 | and component name protocol on its ImageHandle.\r | |
557 | \r | |
3e8c18da | 558 | @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r |
559 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
bab52709 | 560 | \r |
561 | @retval EFI_SUCCESS The operation completed successfully.\r | |
562 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
8a67d61d | 563 | \r |
bab52709 | 564 | **/\r |
8a67d61d | 565 | EFI_STATUS\r |
566 | EFIAPI\r | |
567 | Udp4DriverEntryPoint (\r | |
568 | IN EFI_HANDLE ImageHandle,\r | |
569 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
570 | )\r | |
8a67d61d | 571 | {\r |
572 | EFI_STATUS Status;\r | |
573 | \r | |
574 | //\r | |
575 | // Install the Udp4DriverBinding and Udp4ComponentName protocols.\r | |
576 | //\r | |
83cbd279 | 577 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
8a67d61d | 578 | ImageHandle,\r |
579 | SystemTable,\r | |
580 | &gUdp4DriverBinding,\r | |
581 | ImageHandle,\r | |
582 | &gUdp4ComponentName,\r | |
83cbd279 | 583 | &gUdp4ComponentName2\r |
8a67d61d | 584 | );\r |
585 | if (!EFI_ERROR (Status)) {\r | |
586 | //\r | |
587 | // Initialize the UDP random port.\r | |
588 | //\r | |
687a2e5f | 589 | mUdp4RandomPort = (UINT16) (((UINT16) NetRandomInitSeed ()) % UDP4_PORT_KNOWN + UDP4_PORT_KNOWN);\r |
8a67d61d | 590 | }\r |
591 | \r | |
592 | return Status;\r | |
593 | }\r | |
594 | \r |