]>
Commit | Line | Data |
---|---|---|
47f51a06 YT |
1 | /** @file\r |
2 | The driver binding and service binding protocol for HttpDxe driver.\r | |
3 | \r | |
f75a7f56 | 4 | Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r |
d8293d31 | 5 | (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r |
47f51a06 YT |
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 "HttpDriver.h"\r | |
18 | \r | |
5ca29abe JW |
19 | EFI_HTTP_UTILITIES_PROTOCOL *mHttpUtilities = NULL;\r |
20 | \r | |
47f51a06 YT |
21 | ///\r |
22 | /// Driver Binding Protocol instance\r | |
23 | ///\r | |
b659408b ZL |
24 | EFI_DRIVER_BINDING_PROTOCOL gHttpDxeIp4DriverBinding = {\r |
25 | HttpDxeIp4DriverBindingSupported,\r | |
26 | HttpDxeIp4DriverBindingStart,\r | |
27 | HttpDxeIp4DriverBindingStop,\r | |
47f51a06 YT |
28 | HTTP_DRIVER_VERSION,\r |
29 | NULL,\r | |
30 | NULL\r | |
31 | };\r | |
32 | \r | |
b659408b ZL |
33 | EFI_DRIVER_BINDING_PROTOCOL gHttpDxeIp6DriverBinding = {\r |
34 | HttpDxeIp6DriverBindingSupported,\r | |
35 | HttpDxeIp6DriverBindingStart,\r | |
36 | HttpDxeIp6DriverBindingStop,\r | |
37 | HTTP_DRIVER_VERSION,\r | |
38 | NULL,\r | |
39 | NULL\r | |
40 | };\r | |
41 | \r | |
42 | \r | |
47f51a06 YT |
43 | /**\r |
44 | Create a HTTP driver service binding private instance.\r | |
45 | \r | |
46 | @param[in] Controller The controller that has TCP4 service binding\r | |
47 | installed.\r | |
47f51a06 YT |
48 | @param[out] ServiceData Point to HTTP driver private instance.\r |
49 | \r | |
50 | @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.\r | |
51 | @retval EFI_SUCCESS A new HTTP driver private instance is created.\r | |
52 | \r | |
53 | **/\r | |
54 | EFI_STATUS\r | |
55 | HttpCreateService (\r | |
56 | IN EFI_HANDLE Controller,\r | |
47f51a06 YT |
57 | OUT HTTP_SERVICE **ServiceData\r |
58 | )\r | |
59 | {\r | |
60 | HTTP_SERVICE *HttpService;\r | |
61 | \r | |
62 | ASSERT (ServiceData != NULL);\r | |
63 | *ServiceData = NULL;\r | |
64 | \r | |
65 | HttpService = AllocateZeroPool (sizeof (HTTP_SERVICE));\r | |
66 | if (HttpService == NULL) {\r | |
67 | return EFI_OUT_OF_RESOURCES;\r | |
68 | }\r | |
69 | \r | |
70 | HttpService->Signature = HTTP_SERVICE_SIGNATURE;\r | |
71 | HttpService->ServiceBinding.CreateChild = HttpServiceBindingCreateChild;\r | |
72 | HttpService->ServiceBinding.DestroyChild = HttpServiceBindingDestroyChild;\r | |
47f51a06 YT |
73 | HttpService->ControllerHandle = Controller;\r |
74 | HttpService->ChildrenNumber = 0;\r | |
75 | InitializeListHead (&HttpService->ChildrenList);\r | |
f75a7f56 | 76 | \r |
47f51a06 YT |
77 | *ServiceData = HttpService;\r |
78 | return EFI_SUCCESS;\r | |
79 | }\r | |
80 | \r | |
81 | /**\r | |
82 | Release all the resource used the HTTP service binding instance.\r | |
83 | \r | |
b659408b ZL |
84 | @param[in] HttpService The HTTP private instance.\r |
85 | @param[in] UsingIpv6 Indicate use TCP4 protocol or TCP6 protocol.\r | |
86 | if TRUE, use Tcp6 protocol.\r | |
87 | if FALSE, use Tcp4 protocl.\r | |
47f51a06 YT |
88 | **/\r |
89 | VOID\r | |
90 | HttpCleanService (\r | |
b659408b ZL |
91 | IN HTTP_SERVICE *HttpService,\r |
92 | IN BOOLEAN UsingIpv6\r | |
47f51a06 | 93 | )\r |
f75a7f56 LG |
94 | {\r |
95 | \r | |
3fd7bd08 | 96 | if (HttpService == NULL) {\r |
47f51a06 YT |
97 | return ;\r |
98 | }\r | |
b659408b ZL |
99 | if (!UsingIpv6) {\r |
100 | if (HttpService->Tcp4ChildHandle != NULL) {\r | |
101 | gBS->CloseProtocol (\r | |
102 | HttpService->Tcp4ChildHandle,\r | |
103 | &gEfiTcp4ProtocolGuid,\r | |
7cf59c85 | 104 | HttpService->Ip4DriverBindingHandle,\r |
b659408b ZL |
105 | HttpService->ControllerHandle\r |
106 | );\r | |
f75a7f56 | 107 | \r |
b659408b ZL |
108 | NetLibDestroyServiceChild (\r |
109 | HttpService->ControllerHandle,\r | |
7cf59c85 | 110 | HttpService->Ip4DriverBindingHandle,\r |
b659408b ZL |
111 | &gEfiTcp4ServiceBindingProtocolGuid,\r |
112 | HttpService->Tcp4ChildHandle\r | |
113 | );\r | |
f75a7f56 | 114 | \r |
b659408b ZL |
115 | HttpService->Tcp4ChildHandle = NULL;\r |
116 | }\r | |
117 | } else {\r | |
118 | if (HttpService->Tcp6ChildHandle != NULL) {\r | |
119 | gBS->CloseProtocol (\r | |
120 | HttpService->Tcp6ChildHandle,\r | |
121 | &gEfiTcp6ProtocolGuid,\r | |
7cf59c85 | 122 | HttpService->Ip6DriverBindingHandle,\r |
b659408b ZL |
123 | HttpService->ControllerHandle\r |
124 | );\r | |
f75a7f56 | 125 | \r |
b659408b ZL |
126 | NetLibDestroyServiceChild (\r |
127 | HttpService->ControllerHandle,\r | |
7cf59c85 | 128 | HttpService->Ip6DriverBindingHandle,\r |
b659408b ZL |
129 | &gEfiTcp6ServiceBindingProtocolGuid,\r |
130 | HttpService->Tcp6ChildHandle\r | |
131 | );\r | |
f75a7f56 | 132 | \r |
b659408b ZL |
133 | HttpService->Tcp6ChildHandle = NULL;\r |
134 | }\r | |
47f51a06 | 135 | }\r |
f75a7f56 | 136 | \r |
47f51a06 YT |
137 | }\r |
138 | \r | |
5ca29abe JW |
139 | /**\r |
140 | The event process routine when the http utilities protocol is installed\r | |
141 | in the system.\r | |
142 | \r | |
143 | @param[in] Event Not used.\r | |
b659408b | 144 | @param[in] Context The pointer to the IP4 config2 instance data or IP6 Config instance data.\r |
5ca29abe JW |
145 | \r |
146 | **/\r | |
147 | VOID\r | |
148 | EFIAPI\r | |
149 | HttpUtilitiesInstalledCallback (\r | |
150 | IN EFI_EVENT Event,\r | |
151 | IN VOID *Context\r | |
152 | )\r | |
153 | {\r | |
154 | gBS->LocateProtocol (\r | |
f75a7f56 LG |
155 | &gEfiHttpUtilitiesProtocolGuid,\r |
156 | NULL,\r | |
5ca29abe JW |
157 | (VOID **) &mHttpUtilities\r |
158 | );\r | |
f75a7f56 | 159 | \r |
5ca29abe JW |
160 | //\r |
161 | // Close the event if Http utilities protocol is loacted.\r | |
162 | //\r | |
163 | if (mHttpUtilities != NULL && Event != NULL) {\r | |
164 | gBS->CloseEvent (Event);\r | |
165 | }\r | |
166 | }\r | |
167 | \r | |
47f51a06 YT |
168 | /**\r |
169 | This is the declaration of an EFI image entry point. This entry point is\r | |
170 | the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r | |
171 | both device drivers and bus drivers.\r | |
172 | \r | |
173 | @param ImageHandle The firmware allocated handle for the UEFI image.\r | |
174 | @param SystemTable A pointer to the EFI System Table.\r | |
175 | \r | |
176 | @retval EFI_SUCCESS The operation completed successfully.\r | |
177 | @retval Others An unexpected error occurred.\r | |
178 | \r | |
179 | **/\r | |
180 | EFI_STATUS\r | |
181 | EFIAPI\r | |
182 | HttpDxeDriverEntryPoint (\r | |
183 | IN EFI_HANDLE ImageHandle,\r | |
184 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
185 | )\r | |
f75a7f56 | 186 | {\r |
b659408b | 187 | EFI_STATUS Status;\r |
5ca29abe JW |
188 | VOID *Registration;\r |
189 | \r | |
190 | gBS->LocateProtocol (\r | |
f75a7f56 LG |
191 | &gEfiHttpUtilitiesProtocolGuid,\r |
192 | NULL,\r | |
5ca29abe JW |
193 | (VOID **) &mHttpUtilities\r |
194 | );\r | |
195 | \r | |
196 | if (mHttpUtilities == NULL) {\r | |
197 | //\r | |
198 | // No Http utilities protocol, register a notify.\r | |
199 | //\r | |
200 | EfiCreateProtocolNotifyEvent (\r | |
201 | &gEfiHttpUtilitiesProtocolGuid,\r | |
202 | TPL_CALLBACK,\r | |
203 | HttpUtilitiesInstalledCallback,\r | |
204 | NULL,\r | |
205 | &Registration\r | |
206 | );\r | |
207 | }\r | |
208 | \r | |
47f51a06 YT |
209 | //\r |
210 | // Install UEFI Driver Model protocol(s).\r | |
211 | //\r | |
b659408b ZL |
212 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
213 | ImageHandle,\r | |
214 | SystemTable,\r | |
215 | &gHttpDxeIp4DriverBinding,\r | |
216 | ImageHandle,\r | |
217 | &gHttpDxeComponentName,\r | |
218 | &gHttpDxeComponentName2\r | |
219 | );\r | |
220 | if (EFI_ERROR (Status)) {\r | |
221 | return Status;\r | |
222 | }\r | |
223 | \r | |
224 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
225 | ImageHandle,\r | |
226 | SystemTable,\r | |
227 | &gHttpDxeIp6DriverBinding,\r | |
228 | NULL,\r | |
229 | &gHttpDxeComponentName,\r | |
230 | &gHttpDxeComponentName2\r | |
231 | );\r | |
232 | if (EFI_ERROR (Status)) {\r | |
22b35e8b AS |
233 | EfiLibUninstallDriverBindingComponentName2 (\r |
234 | &gHttpDxeIp4DriverBinding,\r | |
235 | &gHttpDxeComponentName,\r | |
236 | &gHttpDxeComponentName2\r | |
237 | );\r | |
b659408b ZL |
238 | }\r |
239 | return Status;\r | |
47f51a06 YT |
240 | }\r |
241 | \r | |
242 | /**\r | |
243 | Callback function which provided by user to remove one node in NetDestroyLinkList process.\r | |
f75a7f56 | 244 | \r |
47f51a06 YT |
245 | @param[in] Entry The entry to be removed.\r |
246 | @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.\r | |
247 | \r | |
248 | @retval EFI_INVALID_PARAMETER Any input parameter is NULL.\r | |
249 | @retval EFI_SUCCESS The entry has been removed successfully.\r | |
250 | @retval Others Fail to remove the entry.\r | |
251 | \r | |
252 | **/\r | |
253 | EFI_STATUS\r | |
254 | EFIAPI\r | |
255 | HttpDestroyChildEntryInHandleBuffer (\r | |
256 | IN LIST_ENTRY *Entry,\r | |
257 | IN VOID *Context\r | |
258 | )\r | |
259 | {\r | |
260 | HTTP_PROTOCOL *HttpInstance;\r | |
261 | EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r | |
262 | UINTN NumberOfChildren;\r | |
263 | EFI_HANDLE *ChildHandleBuffer;\r | |
264 | \r | |
265 | if (Entry == NULL || Context == NULL) {\r | |
266 | return EFI_INVALID_PARAMETER;\r | |
267 | }\r | |
268 | \r | |
269 | HttpInstance = NET_LIST_USER_STRUCT_S (Entry, HTTP_PROTOCOL, Link, HTTP_PROTOCOL_SIGNATURE);\r | |
270 | ServiceBinding = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ServiceBinding;\r | |
271 | NumberOfChildren = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->NumberOfChildren;\r | |
272 | ChildHandleBuffer = ((HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT *) Context)->ChildHandleBuffer;\r | |
273 | \r | |
274 | if (!NetIsInHandleBuffer (HttpInstance->Handle, NumberOfChildren, ChildHandleBuffer)) {\r | |
275 | return EFI_SUCCESS;\r | |
276 | }\r | |
277 | \r | |
278 | return ServiceBinding->DestroyChild (ServiceBinding, HttpInstance->Handle);\r | |
279 | }\r | |
280 | \r | |
b659408b ZL |
281 | /**\r |
282 | Test to see if this driver supports ControllerHandle. This is the worker function for\r | |
283 | HttpDxeIp4(6)DriverBindingSupported.\r | |
284 | \r | |
285 | @param[in] This The pointer to the driver binding protocol.\r | |
286 | @param[in] ControllerHandle The handle of device to be tested.\r | |
287 | @param[in] RemainingDevicePath Optional parameter used to pick a specific child\r | |
288 | device to be started.\r | |
289 | @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r | |
f75a7f56 | 290 | \r |
b659408b ZL |
291 | @retval EFI_SUCCESS This driver supports this device.\r |
292 | @retval EFI_UNSUPPORTED This driver does not support this device.\r | |
293 | \r | |
294 | **/\r | |
295 | EFI_STATUS\r | |
296 | EFIAPI\r | |
297 | HttpDxeSupported (\r | |
298 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
299 | IN EFI_HANDLE ControllerHandle,\r | |
300 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,\r | |
301 | IN UINT8 IpVersion\r | |
302 | )\r | |
303 | {\r | |
304 | EFI_STATUS Status;\r | |
305 | EFI_GUID *TcpServiceBindingProtocolGuid;\r | |
306 | \r | |
307 | if (IpVersion == IP_VERSION_4) {\r | |
308 | TcpServiceBindingProtocolGuid = &gEfiTcp4ServiceBindingProtocolGuid;\r | |
309 | } else {\r | |
310 | TcpServiceBindingProtocolGuid = &gEfiTcp6ServiceBindingProtocolGuid;\r | |
311 | }\r | |
312 | \r | |
313 | Status = gBS->OpenProtocol (\r | |
314 | ControllerHandle,\r | |
315 | TcpServiceBindingProtocolGuid,\r | |
316 | NULL,\r | |
317 | This->DriverBindingHandle,\r | |
318 | ControllerHandle,\r | |
319 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
320 | );\r | |
321 | \r | |
322 | if (EFI_ERROR (Status)) {\r | |
323 | return EFI_UNSUPPORTED;\r | |
324 | }\r | |
325 | \r | |
326 | return EFI_SUCCESS;\r | |
327 | }\r | |
328 | \r | |
329 | /**\r | |
330 | Start this driver on ControllerHandle. This is the worker function for\r | |
331 | HttpDxeIp4(6)DriverBindingStart.\r | |
332 | \r | |
333 | @param[in] This The pointer to the driver binding protocol.\r | |
334 | @param[in] ControllerHandle The handle of device to be started.\r | |
335 | @param[in] RemainingDevicePath Optional parameter used to pick a specific child\r | |
336 | device to be started.\r | |
337 | @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r | |
338 | \r | |
339 | \r | |
340 | @retval EFI_SUCCESS This driver is installed to ControllerHandle.\r | |
341 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.\r | |
342 | @retval other This driver does not support this device.\r | |
343 | \r | |
344 | **/\r | |
345 | EFI_STATUS\r | |
346 | EFIAPI\r | |
347 | HttpDxeStart (\r | |
348 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
349 | IN EFI_HANDLE ControllerHandle,\r | |
350 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,\r | |
351 | IN UINT8 IpVersion\r | |
352 | )\r | |
353 | {\r | |
354 | EFI_STATUS Status;\r | |
355 | EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r | |
356 | HTTP_SERVICE *HttpService;\r | |
357 | VOID *Interface;\r | |
358 | BOOLEAN UsingIpv6;\r | |
359 | \r | |
360 | UsingIpv6 = FALSE;\r | |
361 | \r | |
362 | //\r | |
363 | // Test for the Http service binding protocol\r | |
364 | //\r | |
365 | Status = gBS->OpenProtocol (\r | |
366 | ControllerHandle,\r | |
367 | &gEfiHttpServiceBindingProtocolGuid,\r | |
368 | (VOID **) &ServiceBinding,\r | |
369 | This->DriverBindingHandle,\r | |
370 | ControllerHandle,\r | |
371 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
372 | );\r | |
373 | \r | |
374 | if (!EFI_ERROR (Status)) {\r | |
375 | HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);\r | |
376 | } else {\r | |
7cf59c85 | 377 | Status = HttpCreateService (ControllerHandle, &HttpService);\r |
b659408b ZL |
378 | if (EFI_ERROR (Status)) {\r |
379 | return Status;\r | |
380 | }\r | |
f75a7f56 | 381 | \r |
b659408b | 382 | ASSERT (HttpService != NULL);\r |
f75a7f56 | 383 | \r |
b659408b ZL |
384 | //\r |
385 | // Install the HttpServiceBinding Protocol onto Controller\r | |
386 | //\r | |
387 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
388 | &ControllerHandle,\r | |
389 | &gEfiHttpServiceBindingProtocolGuid,\r | |
390 | &HttpService->ServiceBinding,\r | |
391 | NULL\r | |
392 | );\r | |
f75a7f56 | 393 | \r |
b659408b ZL |
394 | if (EFI_ERROR (Status)) {\r |
395 | goto ON_ERROR;\r | |
396 | }\r | |
397 | }\r | |
398 | \r | |
399 | if (IpVersion == IP_VERSION_4) {\r | |
7cf59c85 ZL |
400 | HttpService->Ip4DriverBindingHandle = This->DriverBindingHandle;\r |
401 | \r | |
b659408b ZL |
402 | if (HttpService->Tcp4ChildHandle == NULL) {\r |
403 | //\r | |
404 | // Create a TCP4 child instance, but do not configure it. This will establish the parent-child relationship.\r | |
405 | //\r | |
406 | Status = NetLibCreateServiceChild (\r | |
407 | ControllerHandle,\r | |
408 | This->DriverBindingHandle,\r | |
409 | &gEfiTcp4ServiceBindingProtocolGuid,\r | |
410 | &HttpService->Tcp4ChildHandle\r | |
411 | );\r | |
f75a7f56 | 412 | \r |
b659408b ZL |
413 | if (EFI_ERROR (Status)) {\r |
414 | goto ON_ERROR;\r | |
415 | }\r | |
f75a7f56 | 416 | \r |
b659408b ZL |
417 | Status = gBS->OpenProtocol (\r |
418 | HttpService->Tcp4ChildHandle,\r | |
419 | &gEfiTcp4ProtocolGuid,\r | |
420 | &Interface,\r | |
421 | This->DriverBindingHandle,\r | |
422 | ControllerHandle,\r | |
423 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
424 | );\r | |
f75a7f56 | 425 | \r |
b659408b ZL |
426 | if (EFI_ERROR (Status)) {\r |
427 | goto ON_ERROR;\r | |
428 | }\r | |
f75a7f56 | 429 | \r |
b659408b ZL |
430 | } else {\r |
431 | return EFI_ALREADY_STARTED;\r | |
432 | }\r | |
433 | \r | |
434 | } else {\r | |
435 | UsingIpv6 = TRUE;\r | |
7cf59c85 ZL |
436 | HttpService->Ip6DriverBindingHandle = This->DriverBindingHandle;\r |
437 | \r | |
b659408b ZL |
438 | if (HttpService->Tcp6ChildHandle == NULL) {\r |
439 | //\r | |
440 | // Create a TCP6 child instance, but do not configure it. This will establish the parent-child relationship.\r | |
441 | //\r | |
442 | Status = NetLibCreateServiceChild (\r | |
443 | ControllerHandle,\r | |
444 | This->DriverBindingHandle,\r | |
445 | &gEfiTcp6ServiceBindingProtocolGuid,\r | |
446 | &HttpService->Tcp6ChildHandle\r | |
447 | );\r | |
f75a7f56 | 448 | \r |
b659408b ZL |
449 | if (EFI_ERROR (Status)) {\r |
450 | goto ON_ERROR;\r | |
451 | }\r | |
f75a7f56 | 452 | \r |
b659408b ZL |
453 | Status = gBS->OpenProtocol (\r |
454 | HttpService->Tcp6ChildHandle,\r | |
455 | &gEfiTcp6ProtocolGuid,\r | |
456 | &Interface,\r | |
457 | This->DriverBindingHandle,\r | |
458 | ControllerHandle,\r | |
459 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
460 | );\r | |
f75a7f56 | 461 | \r |
b659408b ZL |
462 | if (EFI_ERROR (Status)) {\r |
463 | goto ON_ERROR;\r | |
464 | }\r | |
f75a7f56 | 465 | \r |
b659408b ZL |
466 | } else {\r |
467 | return EFI_ALREADY_STARTED;\r | |
468 | }\r | |
469 | \r | |
470 | }\r | |
471 | \r | |
472 | return EFI_SUCCESS;\r | |
f75a7f56 | 473 | \r |
b659408b | 474 | ON_ERROR:\r |
f75a7f56 | 475 | \r |
b659408b ZL |
476 | if (HttpService != NULL) {\r |
477 | HttpCleanService (HttpService, UsingIpv6);\r | |
478 | if (HttpService->Tcp4ChildHandle == NULL && HttpService->Tcp6ChildHandle == NULL) {\r | |
479 | FreePool (HttpService);\r | |
480 | }\r | |
481 | }\r | |
f75a7f56 | 482 | \r |
b659408b ZL |
483 | return Status;\r |
484 | \r | |
485 | \r | |
486 | }\r | |
487 | \r | |
488 | /**\r | |
489 | Stop this driver on ControllerHandle. This is the worker function for\r | |
490 | HttpDxeIp4(6)DriverBindingStop.\r | |
491 | \r | |
492 | @param[in] This Protocol instance pointer.\r | |
493 | @param[in] ControllerHandle Handle of device to stop driver on.\r | |
494 | @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
495 | children is zero stop the entire bus driver.\r | |
496 | @param[in] ChildHandleBuffer List of Child Handles to Stop.\r | |
497 | @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.\r | |
498 | \r | |
499 | @retval EFI_SUCCESS This driver was removed ControllerHandle.\r | |
500 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
501 | @retval Others This driver was not removed from this device\r | |
502 | \r | |
503 | **/\r | |
504 | EFI_STATUS\r | |
505 | EFIAPI\r | |
506 | HttpDxeStop (\r | |
507 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
508 | IN EFI_HANDLE ControllerHandle,\r | |
509 | IN UINTN NumberOfChildren,\r | |
510 | IN EFI_HANDLE *ChildHandleBuffer,\r | |
511 | IN UINT8 IpVersion\r | |
512 | )\r | |
513 | {\r | |
514 | EFI_HANDLE NicHandle;\r | |
515 | EFI_STATUS Status;\r | |
516 | EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r | |
517 | HTTP_SERVICE *HttpService;\r | |
518 | LIST_ENTRY *List;\r | |
519 | HTTP_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT Context;\r | |
520 | BOOLEAN UsingIpv6;\r | |
521 | \r | |
522 | //\r | |
523 | // HTTP driver opens TCP4(6) child, So, Controller is a TCP4(6)\r | |
524 | // child handle. Locate the Nic handle first. Then get the\r | |
525 | // HTTP private data back.\r | |
526 | //\r | |
527 | if (IpVersion == IP_VERSION_4) {\r | |
528 | UsingIpv6 = FALSE;\r | |
529 | NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r | |
530 | } else {\r | |
531 | UsingIpv6 = TRUE;\r | |
532 | NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);\r | |
533 | }\r | |
534 | \r | |
535 | if (NicHandle == NULL) {\r | |
536 | return EFI_SUCCESS;\r | |
537 | }\r | |
538 | \r | |
539 | Status = gBS->OpenProtocol (\r | |
540 | NicHandle,\r | |
541 | &gEfiHttpServiceBindingProtocolGuid,\r | |
542 | (VOID **) &ServiceBinding,\r | |
543 | This->DriverBindingHandle,\r | |
544 | NicHandle,\r | |
545 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
546 | );\r | |
547 | \r | |
548 | if (!EFI_ERROR (Status)) {\r | |
f75a7f56 | 549 | \r |
b659408b | 550 | HttpService = HTTP_SERVICE_FROM_PROTOCOL (ServiceBinding);\r |
f75a7f56 | 551 | \r |
b659408b ZL |
552 | if (NumberOfChildren != 0) {\r |
553 | //\r | |
554 | // Destroy the HTTP child instance in ChildHandleBuffer.\r | |
555 | //\r | |
556 | List = &HttpService->ChildrenList;\r | |
557 | Context.ServiceBinding = ServiceBinding;\r | |
558 | Context.NumberOfChildren = NumberOfChildren;\r | |
559 | Context.ChildHandleBuffer = ChildHandleBuffer;\r | |
560 | Status = NetDestroyLinkList (\r | |
561 | List,\r | |
562 | HttpDestroyChildEntryInHandleBuffer,\r | |
563 | &Context,\r | |
564 | NULL\r | |
565 | );\r | |
566 | } else {\r | |
f75a7f56 | 567 | \r |
b659408b | 568 | HttpCleanService (HttpService, UsingIpv6);\r |
f75a7f56 | 569 | \r |
b659408b ZL |
570 | if (HttpService->Tcp4ChildHandle == NULL && HttpService->Tcp6ChildHandle == NULL) {\r |
571 | gBS->UninstallProtocolInterface (\r | |
572 | NicHandle,\r | |
573 | &gEfiHttpServiceBindingProtocolGuid,\r | |
574 | ServiceBinding\r | |
575 | );\r | |
576 | FreePool (HttpService);\r | |
577 | }\r | |
578 | Status = EFI_SUCCESS;\r | |
f75a7f56 | 579 | }\r |
b659408b | 580 | }\r |
f75a7f56 | 581 | \r |
b659408b ZL |
582 | return Status;\r |
583 | \r | |
584 | }\r | |
585 | \r | |
47f51a06 | 586 | /**\r |
f75a7f56 | 587 | Tests to see if this driver supports a given controller. If a child device is provided,\r |
47f51a06 YT |
588 | it further tests to see if this driver supports creating a handle for the specified child device.\r |
589 | \r | |
f75a7f56 LG |
590 | This function checks to see if the driver specified by This supports the device specified by\r |
591 | ControllerHandle. Drivers will typically use the device path attached to\r | |
592 | ControllerHandle and/or the services from the bus I/O abstraction attached to\r | |
593 | ControllerHandle to determine if the driver supports ControllerHandle. This function\r | |
594 | may be called many times during platform initialization. In order to reduce boot times, the tests\r | |
595 | performed by this function must be very small, and take as little time as possible to execute. This\r | |
596 | function must not change the state of any hardware devices, and this function must be aware that the\r | |
597 | device specified by ControllerHandle may already be managed by the same driver or a\r | |
598 | different driver. This function must match its calls to AllocatePages() with FreePages(),\r | |
599 | AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r | |
600 | Because ControllerHandle may have been previously started by the same driver, if a protocol is\r | |
601 | already in the opened state, then it must not be closed with CloseProtocol(). This is required\r | |
47f51a06 YT |
602 | to guarantee the state of ControllerHandle is not modified by this function.\r |
603 | \r | |
604 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
f75a7f56 LG |
605 | @param[in] ControllerHandle The handle of the controller to test. This handle\r |
606 | must support a protocol interface that supplies\r | |
47f51a06 | 607 | an I/O abstraction to the driver.\r |
f75a7f56 LG |
608 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r |
609 | parameter is ignored by device drivers, and is optional for bus\r | |
610 | drivers. For bus drivers, if this parameter is not NULL, then\r | |
611 | the bus driver must determine if the bus controller specified\r | |
612 | by ControllerHandle and the child controller specified\r | |
613 | by RemainingDevicePath are both supported by this\r | |
47f51a06 YT |
614 | bus driver.\r |
615 | \r | |
616 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r | |
617 | RemainingDevicePath is supported by the driver specified by This.\r | |
618 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
619 | RemainingDevicePath is already being managed by the driver\r | |
620 | specified by This.\r | |
621 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
622 | RemainingDevicePath is already being managed by a different\r | |
623 | driver or an application that requires exclusive access.\r | |
624 | Currently not implemented.\r | |
625 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
626 | RemainingDevicePath is not supported by the driver specified by This.\r | |
627 | **/\r | |
628 | EFI_STATUS\r | |
629 | EFIAPI\r | |
b659408b | 630 | HttpDxeIp4DriverBindingSupported (\r |
47f51a06 YT |
631 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
632 | IN EFI_HANDLE ControllerHandle,\r | |
633 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
634 | )\r | |
635 | {\r | |
b659408b ZL |
636 | return HttpDxeSupported (\r |
637 | This,\r | |
638 | ControllerHandle,\r | |
639 | RemainingDevicePath,\r | |
640 | IP_VERSION_4\r | |
641 | );\r | |
47f51a06 YT |
642 | }\r |
643 | \r | |
644 | /**\r | |
645 | Starts a device controller or a bus controller.\r | |
646 | \r | |
647 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r | |
f75a7f56 LG |
648 | As a result, much of the error checking on the parameters to Start() has been moved into this\r |
649 | common boot service. It is legal to call Start() from other locations,\r | |
47f51a06 YT |
650 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r |
651 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
652 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
653 | EFI_DEVICE_PATH_PROTOCOL.\r | |
654 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
f75a7f56 | 655 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r |
47f51a06 YT |
656 | \r |
657 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
f75a7f56 LG |
658 | @param[in] ControllerHandle The handle of the controller to start. This handle\r |
659 | must support a protocol interface that supplies\r | |
47f51a06 | 660 | an I/O abstraction to the driver.\r |
f75a7f56 LG |
661 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r |
662 | parameter is ignored by device drivers, and is optional for bus\r | |
663 | drivers. For a bus driver, if this parameter is NULL, then handles\r | |
664 | for all the children of Controller are created by this driver.\r | |
665 | If this parameter is not NULL and the first Device Path Node is\r | |
666 | not the End of Device Path Node, then only the handle for the\r | |
667 | child device specified by the first Device Path Node of\r | |
47f51a06 | 668 | RemainingDevicePath is created by this driver.\r |
f75a7f56 | 669 | If the first Device Path Node of RemainingDevicePath is\r |
47f51a06 YT |
670 | the End of Device Path Node, no child handle is created by this\r |
671 | driver.\r | |
672 | \r | |
673 | @retval EFI_SUCCESS The device was started.\r | |
674 | @retval EFI_ALREADY_STARTED This device is already running on ControllerHandle.\r | |
675 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
676 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
677 | @retval Others The driver failded to start the device.\r | |
678 | \r | |
679 | **/\r | |
680 | EFI_STATUS\r | |
681 | EFIAPI\r | |
b659408b | 682 | HttpDxeIp4DriverBindingStart (\r |
47f51a06 YT |
683 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
684 | IN EFI_HANDLE ControllerHandle,\r | |
685 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
686 | )\r | |
687 | {\r | |
b659408b ZL |
688 | return HttpDxeStart (\r |
689 | This,\r | |
690 | ControllerHandle,\r | |
691 | RemainingDevicePath,\r | |
692 | IP_VERSION_4\r | |
693 | );\r | |
694 | }\r | |
695 | \r | |
696 | /**\r | |
697 | Stops a device controller or a bus controller.\r | |
f75a7f56 LG |
698 | \r |
699 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r | |
700 | As a result, much of the error checking on the parameters to Stop() has been moved\r | |
701 | into this common boot service. It is legal to call Stop() from other locations,\r | |
b659408b ZL |
702 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r |
703 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
704 | same driver's Start() function.\r | |
705 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
706 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
707 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
708 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
f75a7f56 | 709 | \r |
b659408b | 710 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
f75a7f56 LG |
711 | @param[in] ControllerHandle A handle to the device being stopped. The handle must\r |
712 | support a bus specific I/O protocol for the driver\r | |
b659408b ZL |
713 | to use to stop the device.\r |
714 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
f75a7f56 | 715 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r |
b659408b | 716 | if NumberOfChildren is 0.\r |
47f51a06 | 717 | \r |
b659408b ZL |
718 | @retval EFI_SUCCESS The device was stopped.\r |
719 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
47f51a06 | 720 | \r |
b659408b ZL |
721 | **/\r |
722 | EFI_STATUS\r | |
723 | EFIAPI\r | |
724 | HttpDxeIp4DriverBindingStop (\r | |
725 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
726 | IN EFI_HANDLE ControllerHandle,\r | |
727 | IN UINTN NumberOfChildren,\r | |
728 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r | |
729 | )\r | |
730 | {\r | |
731 | return HttpDxeStop (\r | |
732 | This,\r | |
733 | ControllerHandle,\r | |
734 | NumberOfChildren,\r | |
735 | ChildHandleBuffer,\r | |
736 | IP_VERSION_4\r | |
737 | );\r | |
738 | }\r | |
47f51a06 | 739 | \r |
b659408b | 740 | /**\r |
f75a7f56 | 741 | Tests to see if this driver supports a given controller. If a child device is provided,\r |
b659408b | 742 | it further tests to see if this driver supports creating a handle for the specified child device.\r |
47f51a06 | 743 | \r |
f75a7f56 LG |
744 | This function checks to see if the driver specified by This supports the device specified by\r |
745 | ControllerHandle. Drivers will typically use the device path attached to\r | |
746 | ControllerHandle and/or the services from the bus I/O abstraction attached to\r | |
747 | ControllerHandle to determine if the driver supports ControllerHandle. This function\r | |
748 | may be called many times during platform initialization. In order to reduce boot times, the tests\r | |
749 | performed by this function must be very small, and take as little time as possible to execute. This\r | |
750 | function must not change the state of any hardware devices, and this function must be aware that the\r | |
751 | device specified by ControllerHandle may already be managed by the same driver or a\r | |
752 | different driver. This function must match its calls to AllocatePages() with FreePages(),\r | |
753 | AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r | |
754 | Because ControllerHandle may have been previously started by the same driver, if a protocol is\r | |
755 | already in the opened state, then it must not be closed with CloseProtocol(). This is required\r | |
b659408b | 756 | to guarantee the state of ControllerHandle is not modified by this function.\r |
47f51a06 | 757 | \r |
b659408b | 758 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
f75a7f56 LG |
759 | @param[in] ControllerHandle The handle of the controller to test. This handle\r |
760 | must support a protocol interface that supplies\r | |
b659408b | 761 | an I/O abstraction to the driver.\r |
f75a7f56 LG |
762 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r |
763 | parameter is ignored by device drivers, and is optional for bus\r | |
764 | drivers. For bus drivers, if this parameter is not NULL, then\r | |
765 | the bus driver must determine if the bus controller specified\r | |
766 | by ControllerHandle and the child controller specified\r | |
767 | by RemainingDevicePath are both supported by this\r | |
b659408b | 768 | bus driver.\r |
47f51a06 | 769 | \r |
b659408b ZL |
770 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r |
771 | RemainingDevicePath is supported by the driver specified by This.\r | |
772 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
773 | RemainingDevicePath is already being managed by the driver\r | |
774 | specified by This.\r | |
775 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
776 | RemainingDevicePath is already being managed by a different\r | |
777 | driver or an application that requires exclusive access.\r | |
778 | Currently not implemented.\r | |
779 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
780 | RemainingDevicePath is not supported by the driver specified by This.\r | |
781 | **/\r | |
782 | EFI_STATUS\r | |
783 | EFIAPI\r | |
784 | HttpDxeIp6DriverBindingSupported (\r | |
785 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
786 | IN EFI_HANDLE ControllerHandle,\r | |
787 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
788 | )\r | |
f75a7f56 | 789 | {\r |
b659408b ZL |
790 | return HttpDxeSupported (\r |
791 | This,\r | |
792 | ControllerHandle,\r | |
793 | RemainingDevicePath,\r | |
794 | IP_VERSION_6\r | |
795 | );\r | |
47f51a06 | 796 | \r |
b659408b | 797 | }\r |
47f51a06 | 798 | \r |
b659408b ZL |
799 | /**\r |
800 | Starts a device controller or a bus controller.\r | |
47f51a06 | 801 | \r |
b659408b | 802 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r |
f75a7f56 LG |
803 | As a result, much of the error checking on the parameters to Start() has been moved into this\r |
804 | common boot service. It is legal to call Start() from other locations,\r | |
b659408b ZL |
805 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r |
806 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
807 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
808 | EFI_DEVICE_PATH_PROTOCOL.\r | |
809 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
f75a7f56 | 810 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r |
47f51a06 | 811 | \r |
b659408b | 812 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
f75a7f56 LG |
813 | @param[in] ControllerHandle The handle of the controller to start. This handle\r |
814 | must support a protocol interface that supplies\r | |
b659408b | 815 | an I/O abstraction to the driver.\r |
f75a7f56 LG |
816 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r |
817 | parameter is ignored by device drivers, and is optional for bus\r | |
818 | drivers. For a bus driver, if this parameter is NULL, then handles\r | |
819 | for all the children of Controller are created by this driver.\r | |
820 | If this parameter is not NULL and the first Device Path Node is\r | |
821 | not the End of Device Path Node, then only the handle for the\r | |
822 | child device specified by the first Device Path Node of\r | |
b659408b | 823 | RemainingDevicePath is created by this driver.\r |
f75a7f56 | 824 | If the first Device Path Node of RemainingDevicePath is\r |
b659408b ZL |
825 | the End of Device Path Node, no child handle is created by this\r |
826 | driver.\r | |
47f51a06 | 827 | \r |
b659408b ZL |
828 | @retval EFI_SUCCESS The device was started.\r |
829 | @retval EFI_ALREADY_STARTED This device is already running on ControllerHandle.\r | |
830 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
831 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
832 | @retval Others The driver failded to start the device.\r | |
833 | \r | |
834 | **/\r | |
835 | EFI_STATUS\r | |
836 | EFIAPI\r | |
837 | HttpDxeIp6DriverBindingStart (\r | |
838 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
839 | IN EFI_HANDLE ControllerHandle,\r | |
840 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
841 | )\r | |
842 | {\r | |
843 | return HttpDxeStart (\r | |
844 | This,\r | |
845 | ControllerHandle,\r | |
846 | RemainingDevicePath,\r | |
847 | IP_VERSION_6\r | |
848 | );\r | |
47f51a06 YT |
849 | }\r |
850 | \r | |
851 | /**\r | |
852 | Stops a device controller or a bus controller.\r | |
f75a7f56 LG |
853 | \r |
854 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r | |
855 | As a result, much of the error checking on the parameters to Stop() has been moved\r | |
856 | into this common boot service. It is legal to call Stop() from other locations,\r | |
47f51a06 YT |
857 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r |
858 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
859 | same driver's Start() function.\r | |
860 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
861 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
862 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
863 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
f75a7f56 | 864 | \r |
47f51a06 | 865 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
f75a7f56 LG |
866 | @param[in] ControllerHandle A handle to the device being stopped. The handle must\r |
867 | support a bus specific I/O protocol for the driver\r | |
47f51a06 YT |
868 | to use to stop the device.\r |
869 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
f75a7f56 | 870 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r |
47f51a06 YT |
871 | if NumberOfChildren is 0.\r |
872 | \r | |
873 | @retval EFI_SUCCESS The device was stopped.\r | |
874 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
875 | \r | |
876 | **/\r | |
877 | EFI_STATUS\r | |
878 | EFIAPI\r | |
b659408b | 879 | HttpDxeIp6DriverBindingStop (\r |
47f51a06 YT |
880 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
881 | IN EFI_HANDLE ControllerHandle,\r | |
882 | IN UINTN NumberOfChildren,\r | |
883 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r | |
884 | )\r | |
885 | {\r | |
b659408b ZL |
886 | return HttpDxeStop (\r |
887 | This,\r | |
888 | ControllerHandle,\r | |
889 | NumberOfChildren,\r | |
890 | ChildHandleBuffer,\r | |
891 | IP_VERSION_6\r | |
47f51a06 | 892 | );\r |
47f51a06 | 893 | }\r |
47f51a06 YT |
894 | /**\r |
895 | Creates a child handle and installs a protocol.\r | |
896 | \r | |
897 | The CreateChild() function installs a protocol on ChildHandle.\r | |
898 | If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.\r | |
899 | If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.\r | |
900 | \r | |
901 | @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r | |
902 | @param ChildHandle Pointer to the handle of the child to create. If it is NULL,\r | |
903 | then a new handle is created. If it is a pointer to an existing UEFI handle,\r | |
904 | then the protocol is added to the existing UEFI handle.\r | |
905 | \r | |
906 | @retval EFI_SUCCES The protocol was added to ChildHandle.\r | |
907 | @retval EFI_INVALID_PARAMETER This is NULL, or ChildHandle is NULL.\r | |
c2adf51f | 908 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create\r |
47f51a06 YT |
909 | the child.\r |
910 | @retval other The child handle was not created.\r | |
911 | \r | |
912 | **/\r | |
913 | EFI_STATUS\r | |
914 | EFIAPI\r | |
915 | HttpServiceBindingCreateChild (\r | |
916 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r | |
917 | IN OUT EFI_HANDLE *ChildHandle\r | |
918 | )\r | |
919 | {\r | |
920 | HTTP_SERVICE *HttpService;\r | |
921 | HTTP_PROTOCOL *HttpInstance;\r | |
922 | EFI_STATUS Status;\r | |
47f51a06 YT |
923 | EFI_TPL OldTpl;\r |
924 | \r | |
925 | if ((This == NULL) || (ChildHandle == NULL)) {\r | |
926 | return EFI_INVALID_PARAMETER;\r | |
927 | }\r | |
928 | \r | |
929 | HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);\r | |
930 | HttpInstance = AllocateZeroPool (sizeof (HTTP_PROTOCOL));\r | |
931 | if (HttpInstance == NULL) {\r | |
932 | return EFI_OUT_OF_RESOURCES;\r | |
933 | }\r | |
f75a7f56 | 934 | \r |
b659408b ZL |
935 | HttpInstance->Signature = HTTP_PROTOCOL_SIGNATURE;\r |
936 | HttpInstance->Service = HttpService;\r | |
d8293d31 NH |
937 | HttpInstance->Method = HttpMethodMax;\r |
938 | \r | |
b659408b ZL |
939 | CopyMem (&HttpInstance->Http, &mEfiHttpTemplate, sizeof (HttpInstance->Http));\r |
940 | NetMapInit (&HttpInstance->TxTokens);\r | |
941 | NetMapInit (&HttpInstance->RxTokens);\r | |
47f51a06 YT |
942 | \r |
943 | //\r | |
944 | // Install HTTP protocol onto ChildHandle\r | |
945 | //\r | |
946 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
947 | ChildHandle,\r | |
948 | &gEfiHttpProtocolGuid,\r | |
949 | &HttpInstance->Http,\r | |
950 | NULL\r | |
951 | );\r | |
952 | \r | |
953 | if (EFI_ERROR (Status)) {\r | |
954 | goto ON_ERROR;\r | |
955 | }\r | |
956 | \r | |
b659408b | 957 | HttpInstance->Handle = *ChildHandle;\r |
47f51a06 YT |
958 | \r |
959 | //\r | |
960 | // Add it to the HTTP service's child list.\r | |
961 | //\r | |
962 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
963 | \r | |
964 | InsertTailList (&HttpService->ChildrenList, &HttpInstance->Link);\r | |
965 | HttpService->ChildrenNumber++;\r | |
966 | \r | |
967 | gBS->RestoreTPL (OldTpl);\r | |
968 | \r | |
969 | return EFI_SUCCESS;\r | |
f75a7f56 | 970 | \r |
47f51a06 | 971 | ON_ERROR:\r |
f75a7f56 | 972 | \r |
b659408b ZL |
973 | NetMapClean (&HttpInstance->TxTokens);\r |
974 | NetMapClean (&HttpInstance->RxTokens);\r | |
47f51a06 YT |
975 | FreePool (HttpInstance);\r |
976 | \r | |
977 | return Status;\r | |
978 | }\r | |
979 | \r | |
980 | /**\r | |
981 | Destroys a child handle with a protocol installed on it.\r | |
982 | \r | |
983 | The DestroyChild() function does the opposite of CreateChild(). It removes a protocol\r | |
984 | that was installed by CreateChild() from ChildHandle. If the removed protocol is the\r | |
985 | last protocol on ChildHandle, then ChildHandle is destroyed.\r | |
986 | \r | |
987 | @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r | |
988 | @param ChildHandle Handle of the child to destroy\r | |
989 | \r | |
990 | @retval EFI_SUCCES The protocol was removed from ChildHandle.\r | |
991 | @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r | |
992 | @retval EFI_INVALID_PARAMETER Child handle is NULL.\r | |
993 | @retval other The child handle was not destroyed\r | |
994 | \r | |
995 | **/\r | |
996 | EFI_STATUS\r | |
997 | EFIAPI\r | |
998 | HttpServiceBindingDestroyChild (\r | |
999 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r | |
1000 | IN EFI_HANDLE ChildHandle\r | |
1001 | )\r | |
1002 | {\r | |
1003 | HTTP_SERVICE *HttpService;\r | |
1004 | HTTP_PROTOCOL *HttpInstance;\r | |
1005 | EFI_HTTP_PROTOCOL *Http;\r | |
1006 | EFI_STATUS Status;\r | |
1007 | EFI_TPL OldTpl;\r | |
f75a7f56 | 1008 | \r |
47f51a06 YT |
1009 | if ((This == NULL) || (ChildHandle == NULL)) {\r |
1010 | return EFI_INVALID_PARAMETER;\r | |
1011 | }\r | |
1012 | \r | |
1013 | HttpService = HTTP_SERVICE_FROM_PROTOCOL (This);\r | |
1014 | Status = gBS->OpenProtocol (\r | |
1015 | ChildHandle,\r | |
1016 | &gEfiHttpProtocolGuid,\r | |
1017 | (VOID **) &Http,\r | |
b659408b ZL |
1018 | NULL,\r |
1019 | NULL,\r | |
47f51a06 YT |
1020 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r |
1021 | );\r | |
1022 | if (EFI_ERROR (Status)) {\r | |
1023 | return EFI_UNSUPPORTED;\r | |
1024 | }\r | |
f75a7f56 | 1025 | \r |
47f51a06 YT |
1026 | HttpInstance = HTTP_INSTANCE_FROM_PROTOCOL (Http);\r |
1027 | if (HttpInstance->Service != HttpService) {\r | |
1028 | return EFI_INVALID_PARAMETER;\r | |
1029 | }\r | |
1030 | \r | |
1031 | if (HttpInstance->InDestroy) {\r | |
1032 | return EFI_SUCCESS;\r | |
1033 | }\r | |
1034 | \r | |
47f51a06 YT |
1035 | HttpInstance->InDestroy = TRUE;\r |
1036 | \r | |
1037 | //\r | |
1038 | // Uninstall the HTTP protocol.\r | |
1039 | //\r | |
1040 | Status = gBS->UninstallProtocolInterface (\r | |
1041 | ChildHandle,\r | |
1042 | &gEfiHttpProtocolGuid,\r | |
1043 | Http\r | |
1044 | );\r | |
1045 | \r | |
1046 | if (EFI_ERROR (Status)) {\r | |
1047 | HttpInstance->InDestroy = FALSE;\r | |
1048 | return Status;\r | |
1049 | }\r | |
f75a7f56 | 1050 | \r |
47f51a06 | 1051 | HttpCleanProtocol (HttpInstance);\r |
f75a7f56 | 1052 | \r |
b659408b | 1053 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
f75a7f56 | 1054 | \r |
47f51a06 YT |
1055 | RemoveEntryList (&HttpInstance->Link);\r |
1056 | HttpService->ChildrenNumber--;\r | |
1057 | \r | |
1058 | gBS->RestoreTPL (OldTpl);\r | |
f75a7f56 | 1059 | \r |
47f51a06 YT |
1060 | FreePool (HttpInstance);\r |
1061 | return EFI_SUCCESS;\r | |
1062 | }\r |