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