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