+\r
+/**\r
+ Tests whether a controller handle is being managed by IScsi driver.\r
+\r
+ This function tests whether the driver specified by DriverBindingHandle is\r
+ currently managing the controller specified by ControllerHandle. This test\r
+ is performed by evaluating if the the protocol specified by ProtocolGuid is\r
+ present on ControllerHandle and is was opened by DriverBindingHandle and Nic\r
+ Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r
+ If ProtocolGuid is NULL, then ASSERT().\r
+\r
+ @param ControllerHandle A handle for a controller to test.\r
+ @param DriverBindingHandle Specifies the driver binding handle for the\r
+ driver.\r
+ @param ProtocolGuid Specifies the protocol that the driver specified\r
+ by DriverBindingHandle opens in its Start()\r
+ function.\r
+\r
+ @retval EFI_SUCCESS ControllerHandle is managed by the driver\r
+ specified by DriverBindingHandle.\r
+ @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver\r
+ specified by DriverBindingHandle.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IScsiTestManagedDevice (\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN EFI_HANDLE DriverBindingHandle,\r
+ IN EFI_GUID *ProtocolGuid\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ VOID *ManagedInterface;\r
+ EFI_HANDLE NicControllerHandle;\r
+\r
+ ASSERT (ProtocolGuid != NULL);\r
+\r
+ NicControllerHandle = NetLibGetNicHandle (ControllerHandle, ProtocolGuid);\r
+ if (NicControllerHandle == NULL) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ Status = gBS->OpenProtocol (\r
+ ControllerHandle,\r
+ (EFI_GUID *) ProtocolGuid,\r
+ &ManagedInterface,\r
+ DriverBindingHandle,\r
+ NicControllerHandle,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ gBS->CloseProtocol (\r
+ ControllerHandle,\r
+ (EFI_GUID *) ProtocolGuid,\r
+ DriverBindingHandle,\r
+ NicControllerHandle\r
+ );\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ if (Status != EFI_ALREADY_STARTED) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r