HttpDriver.c 39 KB

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