ArpDriver.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /** @file
  2. ARP driver functions.
  3. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "ArpDriver.h"
  7. #include "ArpImpl.h"
  8. EFI_DRIVER_BINDING_PROTOCOL gArpDriverBinding = {
  9. ArpDriverBindingSupported,
  10. ArpDriverBindingStart,
  11. ArpDriverBindingStop,
  12. 0xa,
  13. NULL,
  14. NULL
  15. };
  16. /**
  17. Create and initialize the arp service context data.
  18. @param[in] ImageHandle The image handle representing the loaded driver
  19. image.
  20. @param[in] ControllerHandle The controller handle the driver binds to.
  21. @param[in, out] ArpService Pointer to the buffer containing the arp service
  22. context data.
  23. @retval EFI_SUCCESS The arp service context is initialized.
  24. @retval EFI_UNSUPPORTED The underlayer Snp mode type is not ethernet.
  25. Failed to initialize the service context.
  26. @retval other Failed to initialize the arp service context.
  27. **/
  28. EFI_STATUS
  29. ArpCreateService (
  30. IN EFI_HANDLE ImageHandle,
  31. IN EFI_HANDLE ControllerHandle,
  32. IN OUT ARP_SERVICE_DATA *ArpService
  33. )
  34. {
  35. EFI_STATUS Status;
  36. ASSERT (ArpService != NULL);
  37. ArpService->Signature = ARP_SERVICE_DATA_SIGNATURE;
  38. //
  39. // Init the lists.
  40. //
  41. InitializeListHead (&ArpService->ChildrenList);
  42. InitializeListHead (&ArpService->PendingRequestTable);
  43. InitializeListHead (&ArpService->DeniedCacheTable);
  44. InitializeListHead (&ArpService->ResolvedCacheTable);
  45. //
  46. // Init the servicebinding protocol members.
  47. //
  48. ArpService->ServiceBinding.CreateChild = ArpServiceBindingCreateChild;
  49. ArpService->ServiceBinding.DestroyChild = ArpServiceBindingDestroyChild;
  50. //
  51. // Save the handles.
  52. //
  53. ArpService->ImageHandle = ImageHandle;
  54. ArpService->ControllerHandle = ControllerHandle;
  55. //
  56. // Create a MNP child instance.
  57. //
  58. Status = NetLibCreateServiceChild (
  59. ControllerHandle,
  60. ImageHandle,
  61. &gEfiManagedNetworkServiceBindingProtocolGuid,
  62. &ArpService->MnpChildHandle
  63. );
  64. if (EFI_ERROR (Status)) {
  65. return Status;
  66. }
  67. //
  68. // Open the MNP protocol.
  69. //
  70. Status = gBS->OpenProtocol (
  71. ArpService->MnpChildHandle,
  72. &gEfiManagedNetworkProtocolGuid,
  73. (VOID **)&ArpService->Mnp,
  74. ImageHandle,
  75. ControllerHandle,
  76. EFI_OPEN_PROTOCOL_BY_DRIVER
  77. );
  78. if (EFI_ERROR (Status)) {
  79. goto ERROR_EXIT;
  80. }
  81. //
  82. // Get the underlayer Snp mode data.
  83. //
  84. Status = ArpService->Mnp->GetModeData (ArpService->Mnp, NULL, &ArpService->SnpMode);
  85. if ((Status != EFI_NOT_STARTED) && EFI_ERROR (Status)) {
  86. goto ERROR_EXIT;
  87. }
  88. if (ArpService->SnpMode.IfType != NET_IFTYPE_ETHERNET) {
  89. //
  90. // Only support the ethernet.
  91. //
  92. Status = EFI_UNSUPPORTED;
  93. goto ERROR_EXIT;
  94. }
  95. //
  96. // Set the Mnp config parameters.
  97. //
  98. ArpService->MnpConfigData.ReceivedQueueTimeoutValue = 0;
  99. ArpService->MnpConfigData.TransmitQueueTimeoutValue = 0;
  100. ArpService->MnpConfigData.ProtocolTypeFilter = ARP_ETHER_PROTO_TYPE;
  101. ArpService->MnpConfigData.EnableUnicastReceive = TRUE;
  102. ArpService->MnpConfigData.EnableMulticastReceive = FALSE;
  103. ArpService->MnpConfigData.EnableBroadcastReceive = TRUE;
  104. ArpService->MnpConfigData.EnablePromiscuousReceive = FALSE;
  105. ArpService->MnpConfigData.FlushQueuesOnReset = TRUE;
  106. ArpService->MnpConfigData.EnableReceiveTimestamps = FALSE;
  107. ArpService->MnpConfigData.DisableBackgroundPolling = FALSE;
  108. //
  109. // Configure the Mnp child.
  110. //
  111. Status = ArpService->Mnp->Configure (ArpService->Mnp, &ArpService->MnpConfigData);
  112. if (EFI_ERROR (Status)) {
  113. goto ERROR_EXIT;
  114. }
  115. //
  116. // Create the event used in the RxToken.
  117. //
  118. Status = gBS->CreateEvent (
  119. EVT_NOTIFY_SIGNAL,
  120. TPL_NOTIFY,
  121. ArpOnFrameRcvd,
  122. ArpService,
  123. &ArpService->RxToken.Event
  124. );
  125. if (EFI_ERROR (Status)) {
  126. goto ERROR_EXIT;
  127. }
  128. //
  129. // Create the Arp heartbeat timer.
  130. //
  131. Status = gBS->CreateEvent (
  132. EVT_NOTIFY_SIGNAL | EVT_TIMER,
  133. TPL_CALLBACK,
  134. ArpTimerHandler,
  135. ArpService,
  136. &ArpService->PeriodicTimer
  137. );
  138. if (EFI_ERROR (Status)) {
  139. goto ERROR_EXIT;
  140. }
  141. //
  142. // Start the heartbeat timer.
  143. //
  144. Status = gBS->SetTimer (
  145. ArpService->PeriodicTimer,
  146. TimerPeriodic,
  147. ARP_PERIODIC_TIMER_INTERVAL
  148. );
  149. ERROR_EXIT:
  150. return Status;
  151. }
  152. /**
  153. Clean the arp service context data.
  154. @param[in, out] ArpService Pointer to the buffer containing the arp service
  155. context data.
  156. @return None.
  157. **/
  158. VOID
  159. ArpCleanService (
  160. IN OUT ARP_SERVICE_DATA *ArpService
  161. )
  162. {
  163. NET_CHECK_SIGNATURE (ArpService, ARP_SERVICE_DATA_SIGNATURE);
  164. if (ArpService->PeriodicTimer != NULL) {
  165. //
  166. // Cancel and close the PeriodicTimer.
  167. //
  168. gBS->SetTimer (ArpService->PeriodicTimer, TimerCancel, 0);
  169. gBS->CloseEvent (ArpService->PeriodicTimer);
  170. }
  171. if (ArpService->RxToken.Event != NULL) {
  172. //
  173. // Cancel the RxToken and close the event in the RxToken.
  174. //
  175. ArpService->Mnp->Cancel (ArpService->Mnp, NULL);
  176. gBS->CloseEvent (ArpService->RxToken.Event);
  177. }
  178. if (ArpService->Mnp != NULL) {
  179. //
  180. // Reset the Mnp child and close the Mnp protocol.
  181. //
  182. ArpService->Mnp->Configure (ArpService->Mnp, NULL);
  183. gBS->CloseProtocol (
  184. ArpService->MnpChildHandle,
  185. &gEfiManagedNetworkProtocolGuid,
  186. ArpService->ImageHandle,
  187. ArpService->ControllerHandle
  188. );
  189. }
  190. if (ArpService->MnpChildHandle != NULL) {
  191. //
  192. // Destroy the mnp child.
  193. //
  194. NetLibDestroyServiceChild (
  195. ArpService->ControllerHandle,
  196. ArpService->ImageHandle,
  197. &gEfiManagedNetworkServiceBindingProtocolGuid,
  198. ArpService->MnpChildHandle
  199. );
  200. }
  201. }
  202. /**
  203. Callback function which provided by user to remove one node in NetDestroyLinkList process.
  204. @param[in] Entry The entry to be removed.
  205. @param[in] Context Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
  206. @retval EFI_SUCCESS The entry has been removed successfully.
  207. @retval Others Fail to remove the entry.
  208. **/
  209. EFI_STATUS
  210. EFIAPI
  211. ArpDestroyChildEntryInHandleBuffer (
  212. IN LIST_ENTRY *Entry,
  213. IN VOID *Context
  214. )
  215. {
  216. ARP_INSTANCE_DATA *Instance;
  217. EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
  218. if ((Entry == NULL) || (Context == NULL)) {
  219. return EFI_INVALID_PARAMETER;
  220. }
  221. Instance = NET_LIST_USER_STRUCT_S (Entry, ARP_INSTANCE_DATA, List, ARP_INSTANCE_DATA_SIGNATURE);
  222. ServiceBinding = (EFI_SERVICE_BINDING_PROTOCOL *)Context;
  223. return ServiceBinding->DestroyChild (ServiceBinding, Instance->Handle);
  224. }
  225. /**
  226. Tests to see if this driver supports a given controller.
  227. If a child device is provided, it further tests to see if this driver supports
  228. creating a handle for the specified child device.
  229. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
  230. @param[in] ControllerHandle The handle of the controller to test. This handle
  231. must support a protocol interface that supplies
  232. an I/O abstraction to the driver.
  233. @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
  234. This parameter is ignored by device drivers,
  235. and is optional for bus drivers.
  236. @retval EFI_SUCCESS The device specified by ControllerHandle and
  237. RemainingDevicePath is supported by the driver
  238. specified by This.
  239. @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
  240. RemainingDevicePath is already being managed
  241. by the driver specified by This.
  242. @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
  243. RemainingDevicePath is already being managed by
  244. a different driver or an application that
  245. requires exclusive access. Currently not implemented.
  246. @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
  247. RemainingDevicePath is not supported by the
  248. driver specified by This.
  249. **/
  250. EFI_STATUS
  251. EFIAPI
  252. ArpDriverBindingSupported (
  253. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  254. IN EFI_HANDLE ControllerHandle,
  255. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
  256. )
  257. {
  258. EFI_STATUS Status;
  259. //
  260. // Test to see if Arp SB is already installed.
  261. //
  262. Status = gBS->OpenProtocol (
  263. ControllerHandle,
  264. &gEfiArpServiceBindingProtocolGuid,
  265. NULL,
  266. This->DriverBindingHandle,
  267. ControllerHandle,
  268. EFI_OPEN_PROTOCOL_TEST_PROTOCOL
  269. );
  270. if (Status == EFI_SUCCESS) {
  271. return EFI_ALREADY_STARTED;
  272. }
  273. //
  274. // Test to see if MNP SB is installed.
  275. //
  276. Status = gBS->OpenProtocol (
  277. ControllerHandle,
  278. &gEfiManagedNetworkServiceBindingProtocolGuid,
  279. NULL,
  280. This->DriverBindingHandle,
  281. ControllerHandle,
  282. EFI_OPEN_PROTOCOL_TEST_PROTOCOL
  283. );
  284. return Status;
  285. }
  286. /**
  287. Start this driver on ControllerHandle.
  288. The Start() function is designed to be invoked from the EFI boot service ConnectController().
  289. As a result, much of the error checking on the parameters to Start() has been
  290. moved into this common boot service. It is legal to call Start() from other locations,
  291. but the following calling restrictions must be followed or the system behavior
  292. will not be deterministic.
  293. 1. ControllerHandle must be a valid EFI_HANDLE.
  294. 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally
  295. aligned EFI_DEVICE_PATH_PROTOCOL.
  296. 3. Prior to calling Start(), the Supported() function for the driver specified
  297. by This must have been called with the same calling parameters, and Supported()
  298. must have returned EFI_SUCCESS.
  299. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
  300. @param[in] ControllerHandle The handle of the controller to start. This handle
  301. must support a protocol interface that supplies
  302. an I/O abstraction to the driver.
  303. @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
  304. This parameter is ignored by device drivers,
  305. and is optional for bus drivers.
  306. @retval EFI_SUCCESS The device was started.
  307. @retval EFI_DEVICE_ERROR The device could not be started due to a device error.
  308. Currently not implemented.
  309. @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of
  310. resources.
  311. @retval Others The driver failed to start the device.
  312. **/
  313. EFI_STATUS
  314. EFIAPI
  315. ArpDriverBindingStart (
  316. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  317. IN EFI_HANDLE ControllerHandle,
  318. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
  319. )
  320. {
  321. EFI_STATUS Status;
  322. ARP_SERVICE_DATA *ArpService;
  323. //
  324. // Allocate a zero pool for ArpService.
  325. //
  326. ArpService = AllocateZeroPool (sizeof (ARP_SERVICE_DATA));
  327. if (ArpService == NULL) {
  328. return EFI_OUT_OF_RESOURCES;
  329. }
  330. //
  331. // Initialize the arp service context data.
  332. //
  333. Status = ArpCreateService (This->DriverBindingHandle, ControllerHandle, ArpService);
  334. if (EFI_ERROR (Status)) {
  335. goto ERROR;
  336. }
  337. //
  338. // Install the ARP service binding protocol.
  339. //
  340. Status = gBS->InstallMultipleProtocolInterfaces (
  341. &ControllerHandle,
  342. &gEfiArpServiceBindingProtocolGuid,
  343. &ArpService->ServiceBinding,
  344. NULL
  345. );
  346. if (EFI_ERROR (Status)) {
  347. goto ERROR;
  348. }
  349. //
  350. // OK, start to receive arp packets from Mnp.
  351. //
  352. Status = ArpService->Mnp->Receive (ArpService->Mnp, &ArpService->RxToken);
  353. if (EFI_ERROR (Status)) {
  354. goto ERROR;
  355. }
  356. return Status;
  357. ERROR:
  358. //
  359. // On error, clean the arp service context data, and free the memory allocated.
  360. //
  361. ArpCleanService (ArpService);
  362. FreePool (ArpService);
  363. return Status;
  364. }
  365. /**
  366. Stop this driver on ControllerHandle.
  367. Release the control of this controller and remove the IScsi functions. The Stop()
  368. function is designed to be invoked from the EFI boot service DisconnectController().
  369. As a result, much of the error checking on the parameters to Stop() has been moved
  370. into this common boot service. It is legal to call Stop() from other locations,
  371. but the following calling restrictions must be followed or the system behavior
  372. will not be deterministic.
  373. 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
  374. same driver's Start() function.
  375. 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
  376. EFI_HANDLE. In addition, all of these handles must have been created in this driver's
  377. Start() function, and the Start() function must have called OpenProtocol() on
  378. ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
  379. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
  380. @param[in] ControllerHandle A handle to the device being stopped. The handle must
  381. support a bus specific I/O protocol for the driver
  382. to use to stop the device.
  383. @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
  384. Not used.
  385. @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
  386. if NumberOfChildren is 0.Not used.
  387. @retval EFI_SUCCESS The device was stopped.
  388. @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
  389. **/
  390. EFI_STATUS
  391. EFIAPI
  392. ArpDriverBindingStop (
  393. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  394. IN EFI_HANDLE ControllerHandle,
  395. IN UINTN NumberOfChildren,
  396. IN EFI_HANDLE *ChildHandleBuffer
  397. )
  398. {
  399. EFI_STATUS Status;
  400. EFI_HANDLE NicHandle;
  401. EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
  402. ARP_SERVICE_DATA *ArpService;
  403. LIST_ENTRY *List;
  404. //
  405. // Get the NicHandle which the arp servicebinding is installed on.
  406. //
  407. NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiManagedNetworkProtocolGuid);
  408. if (NicHandle == NULL) {
  409. return EFI_SUCCESS;
  410. }
  411. //
  412. // Try to get the arp servicebinding protocol on the NicHandle.
  413. //
  414. Status = gBS->OpenProtocol (
  415. NicHandle,
  416. &gEfiArpServiceBindingProtocolGuid,
  417. (VOID **)&ServiceBinding,
  418. This->DriverBindingHandle,
  419. ControllerHandle,
  420. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  421. );
  422. if (EFI_ERROR (Status)) {
  423. DEBUG ((DEBUG_ERROR, "ArpDriverBindingStop: Open ArpSb failed, %r.\n", Status));
  424. return EFI_DEVICE_ERROR;
  425. }
  426. ArpService = ARP_SERVICE_DATA_FROM_THIS (ServiceBinding);
  427. if (NumberOfChildren != 0) {
  428. //
  429. // NumberOfChildren is not zero, destroy all the ARP children instances.
  430. //
  431. List = &ArpService->ChildrenList;
  432. Status = NetDestroyLinkList (
  433. List,
  434. ArpDestroyChildEntryInHandleBuffer,
  435. ServiceBinding,
  436. NULL
  437. );
  438. ASSERT (IsListEmpty (&ArpService->PendingRequestTable));
  439. ASSERT (IsListEmpty (&ArpService->DeniedCacheTable));
  440. ASSERT (IsListEmpty (&ArpService->ResolvedCacheTable));
  441. } else if (IsListEmpty (&ArpService->ChildrenList)) {
  442. //
  443. // Uninstall the ARP ServiceBinding protocol.
  444. //
  445. gBS->UninstallMultipleProtocolInterfaces (
  446. NicHandle,
  447. &gEfiArpServiceBindingProtocolGuid,
  448. &ArpService->ServiceBinding,
  449. NULL
  450. );
  451. //
  452. // Clean the arp servicebinding context data and free the memory allocated.
  453. //
  454. ArpCleanService (ArpService);
  455. FreePool (ArpService);
  456. }
  457. return EFI_SUCCESS;
  458. }
  459. /**
  460. Creates a child handle and installs a protocol.
  461. The CreateChild() function installs a protocol on ChildHandle.
  462. If ChildHandle is a pointer to NULL, then a new handle is created and returned
  463. in ChildHandle. If ChildHandle is not a pointer to NULL, then the protocol
  464. installs on the existing ChildHandle.
  465. @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
  466. @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
  467. then a new handle is created. If it is a pointer to an existing
  468. UEFI handle, then the protocol is added to the existing UEFI handle.
  469. @retval EFI_SUCCESS The protocol was added to ChildHandle.
  470. @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
  471. @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
  472. the child
  473. @retval other The child handle was not created
  474. **/
  475. EFI_STATUS
  476. EFIAPI
  477. ArpServiceBindingCreateChild (
  478. IN EFI_SERVICE_BINDING_PROTOCOL *This,
  479. IN EFI_HANDLE *ChildHandle
  480. )
  481. {
  482. EFI_STATUS Status;
  483. ARP_SERVICE_DATA *ArpService;
  484. ARP_INSTANCE_DATA *Instance;
  485. VOID *Mnp;
  486. EFI_TPL OldTpl;
  487. if ((This == NULL) || (ChildHandle == NULL)) {
  488. return EFI_INVALID_PARAMETER;
  489. }
  490. ArpService = ARP_SERVICE_DATA_FROM_THIS (This);
  491. //
  492. // Allocate memory for the instance context data.
  493. //
  494. Instance = AllocateZeroPool (sizeof (ARP_INSTANCE_DATA));
  495. if (Instance == NULL) {
  496. DEBUG ((DEBUG_ERROR, "ArpSBCreateChild: Failed to allocate memory for Instance.\n"));
  497. return EFI_OUT_OF_RESOURCES;
  498. }
  499. //
  500. // Init the instance context data.
  501. //
  502. ArpInitInstance (ArpService, Instance);
  503. //
  504. // Install the ARP protocol onto the ChildHandle.
  505. //
  506. Status = gBS->InstallMultipleProtocolInterfaces (
  507. ChildHandle,
  508. &gEfiArpProtocolGuid,
  509. (VOID *)&Instance->ArpProto,
  510. NULL
  511. );
  512. if (EFI_ERROR (Status)) {
  513. DEBUG ((DEBUG_ERROR, "ArpSBCreateChild: failed to install ARP protocol, %r.\n", Status));
  514. FreePool (Instance);
  515. return Status;
  516. }
  517. //
  518. // Save the ChildHandle.
  519. //
  520. Instance->Handle = *ChildHandle;
  521. //
  522. // Open the Managed Network protocol BY_CHILD.
  523. //
  524. Status = gBS->OpenProtocol (
  525. ArpService->MnpChildHandle,
  526. &gEfiManagedNetworkProtocolGuid,
  527. (VOID **)&Mnp,
  528. gArpDriverBinding.DriverBindingHandle,
  529. Instance->Handle,
  530. EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
  531. );
  532. if (EFI_ERROR (Status)) {
  533. goto ERROR;
  534. }
  535. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  536. //
  537. // Insert the instance into children list managed by the arp service context data.
  538. //
  539. InsertTailList (&ArpService->ChildrenList, &Instance->List);
  540. ArpService->ChildrenNumber++;
  541. gBS->RestoreTPL (OldTpl);
  542. ERROR:
  543. if (EFI_ERROR (Status)) {
  544. gBS->CloseProtocol (
  545. ArpService->MnpChildHandle,
  546. &gEfiManagedNetworkProtocolGuid,
  547. gArpDriverBinding.DriverBindingHandle,
  548. Instance->Handle
  549. );
  550. gBS->UninstallMultipleProtocolInterfaces (
  551. Instance->Handle,
  552. &gEfiArpProtocolGuid,
  553. &Instance->ArpProto,
  554. NULL
  555. );
  556. //
  557. // Free the allocated memory.
  558. //
  559. FreePool (Instance);
  560. }
  561. return Status;
  562. }
  563. /**
  564. Destroys a child handle with a protocol installed on it.
  565. The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
  566. that was installed by CreateChild() from ChildHandle. If the removed protocol is the
  567. last protocol on ChildHandle, then ChildHandle is destroyed.
  568. @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
  569. @param ChildHandle Handle of the child to destroy
  570. @retval EFI_SUCCESS The protocol was removed from ChildHandle.
  571. @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is
  572. being removed.
  573. @retval EFI_INVALID_PARAMETER Child handle is NULL.
  574. @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
  575. because its services are being used.
  576. @retval other The child handle was not destroyed
  577. **/
  578. EFI_STATUS
  579. EFIAPI
  580. ArpServiceBindingDestroyChild (
  581. IN EFI_SERVICE_BINDING_PROTOCOL *This,
  582. IN EFI_HANDLE ChildHandle
  583. )
  584. {
  585. EFI_STATUS Status;
  586. ARP_SERVICE_DATA *ArpService;
  587. ARP_INSTANCE_DATA *Instance;
  588. EFI_ARP_PROTOCOL *Arp;
  589. EFI_TPL OldTpl;
  590. if ((This == NULL) || (ChildHandle == NULL)) {
  591. return EFI_INVALID_PARAMETER;
  592. }
  593. ArpService = ARP_SERVICE_DATA_FROM_THIS (This);
  594. //
  595. // Get the arp protocol.
  596. //
  597. Status = gBS->OpenProtocol (
  598. ChildHandle,
  599. &gEfiArpProtocolGuid,
  600. (VOID **)&Arp,
  601. ArpService->ImageHandle,
  602. ChildHandle,
  603. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  604. );
  605. if (EFI_ERROR (Status)) {
  606. return EFI_UNSUPPORTED;
  607. }
  608. Instance = ARP_INSTANCE_DATA_FROM_THIS (Arp);
  609. if (Instance->InDestroy) {
  610. return EFI_SUCCESS;
  611. }
  612. //
  613. // Use the InDestroy as a flag to avoid re-entrance.
  614. //
  615. Instance->InDestroy = TRUE;
  616. //
  617. // Close the Managed Network protocol.
  618. //
  619. gBS->CloseProtocol (
  620. ArpService->MnpChildHandle,
  621. &gEfiManagedNetworkProtocolGuid,
  622. gArpDriverBinding.DriverBindingHandle,
  623. ChildHandle
  624. );
  625. //
  626. // Uninstall the ARP protocol.
  627. //
  628. Status = gBS->UninstallMultipleProtocolInterfaces (
  629. ChildHandle,
  630. &gEfiArpProtocolGuid,
  631. &Instance->ArpProto,
  632. NULL
  633. );
  634. if (EFI_ERROR (Status)) {
  635. DEBUG ((
  636. DEBUG_ERROR,
  637. "ArpSBDestroyChild: Failed to uninstall the arp protocol, %r.\n",
  638. Status
  639. ));
  640. Instance->InDestroy = FALSE;
  641. return Status;
  642. }
  643. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  644. if (Instance->Configured) {
  645. //
  646. // Delete the related cache entry.
  647. //
  648. ArpDeleteCacheEntry (Instance, FALSE, NULL, TRUE);
  649. //
  650. // Reset the instance configuration.
  651. //
  652. ArpConfigureInstance (Instance, NULL);
  653. }
  654. //
  655. // Remove this instance from the ChildrenList.
  656. //
  657. RemoveEntryList (&Instance->List);
  658. ArpService->ChildrenNumber--;
  659. gBS->RestoreTPL (OldTpl);
  660. FreePool (Instance);
  661. return Status;
  662. }
  663. /**
  664. The entry point for Arp driver which installs the driver binding and component name
  665. protocol on its ImageHandle.
  666. @param[in] ImageHandle The image handle of the driver.
  667. @param[in] SystemTable The system table.
  668. @retval EFI_SUCCESS if the driver binding and component name protocols
  669. are successfully
  670. @retval Others Failed to install the protocols.
  671. **/
  672. EFI_STATUS
  673. EFIAPI
  674. ArpDriverEntryPoint (
  675. IN EFI_HANDLE ImageHandle,
  676. IN EFI_SYSTEM_TABLE *SystemTable
  677. )
  678. {
  679. return EfiLibInstallDriverBindingComponentName2 (
  680. ImageHandle,
  681. SystemTable,
  682. &gArpDriverBinding,
  683. ImageHandle,
  684. &gArpComponentName,
  685. &gArpComponentName2
  686. );
  687. }