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