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