Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1430 lines
42 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. PNP.C
  5. Abstract:
  6. This module contains contains the plugplay calls
  7. PNP / WDM BUS driver.
  8. @@BEGIN_DDKSPLIT
  9. Author:
  10. Jay Senior
  11. @@END_DDKSPLIT
  12. Environment:
  13. kernel mode only
  14. Notes:
  15. @@BEGIN_DDKSPLIT
  16. Revision History:
  17. Louis J. Giliberto, Jr. 22-Mar-1998 Cleanup
  18. Louis J. Giliberto, Jr. 10-Jan-2000 Cleanup
  19. @@END_DDKSPLIT
  20. --*/
  21. #include "pch.h"
  22. #ifdef ALLOC_PRAGMA
  23. #pragma alloc_text (PAGE, Serenum_AddDevice)
  24. #pragma alloc_text (PAGE, Serenum_PnP)
  25. #pragma alloc_text (PAGE, Serenum_FDO_PnP)
  26. #pragma alloc_text (PAGE, Serenum_PDO_PnP)
  27. #pragma alloc_text (PAGE, Serenum_PnPRemove)
  28. //#pragma alloc_text (PAGE, Serenum_Remove)
  29. #endif
  30. NTSTATUS
  31. Serenum_AddDevice(IN PDRIVER_OBJECT DriverObject,
  32. IN PDEVICE_OBJECT BusPhysicalDeviceObject)
  33. /*++
  34. Routine Description.
  35. A bus has been found. Attach our FDO to it.
  36. Allocate any required resources. Set things up. And be prepared for the
  37. first ``start device.''
  38. Arguments:
  39. BusPhysicalDeviceObject - Device object representing the bus. That to which
  40. we attach a new FDO.
  41. DriverObject - This very self referenced driver.
  42. --*/
  43. {
  44. NTSTATUS status;
  45. PDEVICE_OBJECT deviceObject;
  46. PFDO_DEVICE_DATA pDeviceData;
  47. ULONG nameLength;
  48. HANDLE keyHandle;
  49. ULONG actualLength;
  50. PAGED_CODE();
  51. Serenum_KdPrint_Def(SER_DBG_PNP_TRACE, ("Add Device: 0x%x\n",
  52. BusPhysicalDeviceObject));
  53. //
  54. // Create our FDO
  55. //
  56. status = IoCreateDevice(DriverObject, sizeof(FDO_DEVICE_DATA), NULL,
  57. FILE_DEVICE_BUS_EXTENDER, 0, TRUE, &deviceObject);
  58. if (NT_SUCCESS(status)) {
  59. pDeviceData = (PFDO_DEVICE_DATA)deviceObject->DeviceExtension;
  60. RtlFillMemory (pDeviceData, sizeof (FDO_DEVICE_DATA), 0);
  61. pDeviceData->IsFDO = TRUE;
  62. pDeviceData->DebugLevel = SER_DEFAULT_DEBUG_OUTPUT_LEVEL;
  63. pDeviceData->Self = deviceObject;
  64. pDeviceData->AttachedPDO = NULL;
  65. pDeviceData->NumPDOs = 0;
  66. pDeviceData->DeviceState = PowerDeviceD0;
  67. pDeviceData->SystemState = PowerSystemWorking;
  68. pDeviceData->PDOForcedRemove = FALSE;
  69. pDeviceData->SystemWake=PowerSystemUnspecified;
  70. pDeviceData->DeviceWake=PowerDeviceUnspecified;
  71. pDeviceData->Removed = FALSE;
  72. //
  73. // Set the PDO for use with PlugPlay functions
  74. //
  75. pDeviceData->UnderlyingPDO = BusPhysicalDeviceObject;
  76. //
  77. // Attach our filter driver to the device stack.
  78. // the return value of IoAttachDeviceToDeviceStack is the top of the
  79. // attachment chain. This is where all the IRPs should be routed.
  80. //
  81. // Our filter will send IRPs to the top of the stack and use the PDO
  82. // for all PlugPlay functions.
  83. //
  84. pDeviceData->TopOfStack
  85. = IoAttachDeviceToDeviceStack(deviceObject, BusPhysicalDeviceObject);
  86. //
  87. // Set the type of IO we do
  88. //
  89. if (pDeviceData->TopOfStack->Flags & DO_BUFFERED_IO) {
  90. deviceObject->Flags |= DO_BUFFERED_IO;
  91. } else if (pDeviceData->TopOfStack->Flags & DO_DIRECT_IO) {
  92. deviceObject->Flags |= DO_DIRECT_IO;
  93. }
  94. //
  95. // Bias outstanding request to 1 so that we can look for a
  96. // transition to zero when processing the remove device PlugPlay IRP.
  97. //
  98. pDeviceData->OutstandingIO = 1;
  99. KeInitializeEvent(&pDeviceData->RemoveEvent, SynchronizationEvent,
  100. FALSE);
  101. KeInitializeSemaphore(&pDeviceData->CreateSemaphore, 1, 1);
  102. KeInitializeSpinLock(&pDeviceData->EnumerationLock);
  103. //
  104. // Tell the PlugPlay system that this device will need an interface
  105. // device class shingle.
  106. //
  107. // It may be that the driver cannot hang the shingle until it starts
  108. // the device itself, so that it can query some of its properties.
  109. // (Aka the shingles guid (or ref string) is based on the properties
  110. // of the device.)
  111. //
  112. status = IoRegisterDeviceInterface(BusPhysicalDeviceObject,
  113. (LPGUID)&GUID_SERENUM_BUS_ENUMERATOR,
  114. NULL,
  115. &pDeviceData->DevClassAssocName);
  116. if (!NT_SUCCESS(status)) {
  117. Serenum_KdPrint(pDeviceData, SER_DBG_PNP_ERROR,
  118. ("AddDevice: IoRegisterDCA failed (%x)", status));
  119. IoDetachDevice(pDeviceData->TopOfStack);
  120. IoDeleteDevice(deviceObject);
  121. return status;
  122. }
  123. //
  124. // If for any reason you need to save values in a safe location that
  125. // clients of this DeviceClassAssociate might be interested in reading
  126. // here is the time to do so, with the function
  127. // IoOpenDeviceClassRegistryKey
  128. // the symbolic link name used is was returned in
  129. // pDeviceData->DevClassAssocName (the same name which is returned by
  130. // IoGetDeviceClassAssociations and the SetupAPI equivs.
  131. //
  132. #if DBG
  133. {
  134. PWCHAR deviceName = NULL;
  135. status = IoGetDeviceProperty(BusPhysicalDeviceObject,
  136. DevicePropertyPhysicalDeviceObjectName, 0,
  137. NULL, &nameLength);
  138. if ((nameLength != 0) && (status == STATUS_BUFFER_TOO_SMALL)) {
  139. deviceName = ExAllocatePool(NonPagedPool, nameLength);
  140. if (NULL == deviceName) {
  141. goto someDebugStuffExit;
  142. }
  143. IoGetDeviceProperty(BusPhysicalDeviceObject,
  144. DevicePropertyPhysicalDeviceObjectName,
  145. nameLength, deviceName, &nameLength);
  146. Serenum_KdPrint(pDeviceData, SER_DBG_PNP_TRACE,
  147. ("AddDevice: %x to %x->%x (%ws) \n", deviceObject,
  148. pDeviceData->TopOfStack, BusPhysicalDeviceObject,
  149. deviceName));
  150. }
  151. someDebugStuffExit:;
  152. if (deviceName != NULL) {
  153. ExFreePool(deviceName);
  154. }
  155. }
  156. #endif // DBG
  157. //
  158. // Turn on the shingle and point it to the given device object.
  159. //
  160. status = IoSetDeviceInterfaceState(&pDeviceData->DevClassAssocName,
  161. TRUE);
  162. if (!NT_SUCCESS(status)) {
  163. Serenum_KdPrint(pDeviceData, SER_DBG_PNP_ERROR,
  164. ("AddDevice: IoSetDeviceClass failed (%x)", status));
  165. return status;
  166. }
  167. //
  168. // Open the registry and read in our settings
  169. //
  170. status = IoOpenDeviceRegistryKey(pDeviceData->UnderlyingPDO,
  171. PLUGPLAY_REGKEY_DEVICE,
  172. STANDARD_RIGHTS_READ, &keyHandle);
  173. if (status == STATUS_SUCCESS) {
  174. status
  175. = Serenum_GetRegistryKeyValue(keyHandle, L"SkipEnumerations",
  176. sizeof(L"SkipEnumerations"),
  177. &pDeviceData->SkipEnumerations,
  178. sizeof(pDeviceData->SkipEnumerations),
  179. &actualLength);
  180. if ((status != STATUS_SUCCESS)
  181. || (actualLength != sizeof(pDeviceData->SkipEnumerations))) {
  182. pDeviceData->SkipEnumerations = 0;
  183. status = STATUS_SUCCESS;
  184. }
  185. ZwClose(keyHandle);
  186. }
  187. }
  188. if (NT_SUCCESS(status)) {
  189. deviceObject->Flags |= DO_POWER_PAGABLE;
  190. deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
  191. }
  192. return status;
  193. }
  194. NTSTATUS
  195. Serenum_PnP(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
  196. /*++
  197. Routine Description:
  198. Answer the plethora of Irp Major PnP IRPS.
  199. --*/
  200. {
  201. PIO_STACK_LOCATION irpStack;
  202. NTSTATUS status;
  203. PCOMMON_DEVICE_DATA commonData;
  204. KIRQL oldIrq;
  205. PAGED_CODE();
  206. irpStack = IoGetCurrentIrpStackLocation(Irp);
  207. ASSERT(irpStack->MajorFunction == IRP_MJ_PNP);
  208. commonData = (PCOMMON_DEVICE_DATA)DeviceObject->DeviceExtension;
  209. //
  210. // If removed, fail the request and get out
  211. //
  212. if (commonData->Removed) {
  213. Serenum_KdPrint(commonData, SER_DBG_PNP_TRACE,
  214. ("PNP: removed DO: %x got IRP: %x\n", DeviceObject,
  215. Irp));
  216. Irp->IoStatus.Status = status = STATUS_NO_SUCH_DEVICE;
  217. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  218. goto PnPDone;
  219. }
  220. //
  221. // Call either the FDO or PDO Pnp code
  222. //
  223. if (commonData->IsFDO) {
  224. Serenum_KdPrint(commonData, SER_DBG_PNP_TRACE,
  225. ("PNP: Functional DO: %x IRP: %x MJ: %X MIN: %X\n",
  226. DeviceObject, Irp, irpStack->MajorFunction,
  227. irpStack->MinorFunction));
  228. status = Serenum_FDO_PnP(DeviceObject, Irp, irpStack,
  229. (PFDO_DEVICE_DATA)commonData);
  230. goto PnPDone;
  231. }
  232. //
  233. // PDO
  234. //
  235. Serenum_KdPrint(commonData, SER_DBG_PNP_TRACE,
  236. ("PNP: Physical DO: %x IRP: %x MJ: %X MIN: %X\n",
  237. DeviceObject, Irp, irpStack->MajorFunction,
  238. irpStack->MinorFunction));
  239. status = Serenum_PDO_PnP(DeviceObject, Irp, irpStack,
  240. (PPDO_DEVICE_DATA)commonData);
  241. PnPDone:;
  242. return status;
  243. }
  244. NTSTATUS
  245. SerenumCheckEnumerations(IN PFDO_DEVICE_DATA PFdoData)
  246. {
  247. KIRQL oldIrql;
  248. NTSTATUS status;
  249. PIRP pIrp;
  250. BOOLEAN sameDevice = TRUE;
  251. Serenum_KdPrint(PFdoData, SER_DBG_PNP_TRACE, ("Checking enumerations"));
  252. //
  253. // If appropriate, check for new devices or if old devices still there.
  254. //
  255. if (PFdoData->SkipEnumerations == 0) {
  256. ULONG enumFlags;
  257. KeAcquireSpinLock(&PFdoData->EnumerationLock, &oldIrql);
  258. if (PFdoData->EnumFlags == SERENUM_ENUMFLAG_CLEAN) {
  259. Serenum_KdPrint(PFdoData, SER_DBG_PNP_TRACE, ("EnumFlag Clean"));
  260. //
  261. // If nothing is going on, kick off an enumeration
  262. //
  263. PFdoData->EnumFlags |= SERENUM_ENUMFLAG_PENDING;
  264. KeReleaseSpinLock(&PFdoData->EnumerationLock, oldIrql);
  265. status = SerenumStartProtocolThread(PFdoData);
  266. } else if ((PFdoData->EnumFlags
  267. & (SERENUM_ENUMFLAG_REMOVED | SERENUM_ENUMFLAG_PENDING))
  268. == SERENUM_ENUMFLAG_REMOVED) {
  269. Serenum_KdPrint(PFdoData, SER_DBG_PNP_TRACE, ("EnumFlag Removed"));
  270. //
  271. // Clear the flag and do it synchronously to make sure we
  272. // get the exact current state
  273. //
  274. PFdoData->EnumFlags &= ~SERENUM_ENUMFLAG_REMOVED;
  275. KeReleaseSpinLock(&PFdoData->EnumerationLock, oldIrql);
  276. pIrp = IoAllocateIrp(PFdoData->TopOfStack->StackSize + 1, FALSE);
  277. if (pIrp == NULL) {
  278. status = STATUS_INSUFFICIENT_RESOURCES;
  279. goto SerenumCheckEnumerationsOut;
  280. }
  281. status = Serenum_ReenumerateDevices(pIrp, PFdoData, &sameDevice);
  282. if (pIrp != NULL) {
  283. IoFreeIrp(pIrp);
  284. }
  285. KeAcquireSpinLock(&PFdoData->EnumerationLock, &oldIrql);
  286. if (status == STATUS_SUCCESS) {
  287. PFdoData->AttachedPDO = PFdoData->NewPDO;
  288. PFdoData->PdoData = PFdoData->NewPdoData;
  289. PFdoData->NumPDOs = PFdoData->NewNumPDOs;
  290. PFdoData->PDOForcedRemove = PFdoData->NewPDOForcedRemove;
  291. }
  292. KeReleaseSpinLock(&PFdoData->EnumerationLock, oldIrql);
  293. } else if (PFdoData->EnumFlags & SERENUM_ENUMFLAG_DIRTY) {
  294. Serenum_KdPrint(PFdoData, SER_DBG_PNP_TRACE, ("EnumFlag Dirty"));
  295. //
  296. // If there is a new value, use the new values
  297. //
  298. PFdoData->AttachedPDO = PFdoData->NewPDO;
  299. PFdoData->PdoData = PFdoData->NewPdoData;
  300. PFdoData->NumPDOs = PFdoData->NewNumPDOs;
  301. PFdoData->PDOForcedRemove = PFdoData->NewPDOForcedRemove;
  302. PFdoData->EnumFlags &= ~SERENUM_ENUMFLAG_DIRTY;
  303. KeReleaseSpinLock(&PFdoData->EnumerationLock, oldIrql);
  304. status = STATUS_SUCCESS;
  305. } else {
  306. Serenum_KdPrint(PFdoData, SER_DBG_PNP_TRACE, ("EnumFlag default"));
  307. //
  308. // Use the current values
  309. //
  310. KeReleaseSpinLock(&PFdoData->EnumerationLock, oldIrql);
  311. status = STATUS_SUCCESS;
  312. }
  313. } else {
  314. status = STATUS_SUCCESS;
  315. if (PFdoData->SkipEnumerations != 0xffffffff) {
  316. PFdoData->SkipEnumerations--;
  317. }
  318. }
  319. SerenumCheckEnumerationsOut:
  320. return status;
  321. }
  322. NTSTATUS
  323. Serenum_FDO_PnP (
  324. IN PDEVICE_OBJECT DeviceObject,
  325. IN PIRP Irp,
  326. IN PIO_STACK_LOCATION IrpStack,
  327. IN PFDO_DEVICE_DATA DeviceData
  328. )
  329. /*++
  330. Routine Description:
  331. Handle requests from the PlugPlay system for the BUS itself
  332. NB: the various Minor functions of the PlugPlay system will not be
  333. overlapped and do not have to be reentrant
  334. --*/
  335. {
  336. NTSTATUS status;
  337. KIRQL oldIrq;
  338. KEVENT event;
  339. ULONG length;
  340. ULONG i;
  341. PLIST_ENTRY entry;
  342. PPDO_DEVICE_DATA pdoData;
  343. PDEVICE_RELATIONS relations;
  344. PIO_STACK_LOCATION stack;
  345. PRTL_QUERY_REGISTRY_TABLE QueryTable = NULL;
  346. ULONG DebugLevelDefault = SER_DEFAULT_DEBUG_OUTPUT_LEVEL;
  347. PVOID threadObj;
  348. PAGED_CODE();
  349. status = Serenum_IncIoCount (DeviceData);
  350. if (!NT_SUCCESS (status)) {
  351. Irp->IoStatus.Status = status;
  352. IoCompleteRequest (Irp, IO_NO_INCREMENT);
  353. return status;
  354. }
  355. stack = IoGetCurrentIrpStackLocation (Irp);
  356. switch (IrpStack->MinorFunction) {
  357. case IRP_MN_START_DEVICE:
  358. //
  359. // BEFORE you are allowed to ``touch'' the device object to which
  360. // the FDO is attached (that send an irp from the bus to the Device
  361. // object to which the bus is attached). You must first pass down
  362. // the start IRP. It might not be powered on, or able to access or
  363. // something.
  364. //
  365. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE, ("Start Device\n"));
  366. if (DeviceData->Started) {
  367. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE,
  368. ("Device already started\n"));
  369. status = STATUS_SUCCESS;
  370. break;
  371. }
  372. KeInitializeEvent (&event, NotificationEvent, FALSE);
  373. IoCopyCurrentIrpStackLocationToNext (Irp);
  374. IoSetCompletionRoutine (Irp,
  375. SerenumSyncCompletion,
  376. &event,
  377. TRUE,
  378. TRUE,
  379. TRUE);
  380. status = IoCallDriver (DeviceData->TopOfStack, Irp);
  381. if (STATUS_PENDING == status) {
  382. // wait for it...
  383. status = KeWaitForSingleObject (&event,
  384. Executive,
  385. KernelMode,
  386. FALSE, // Not allertable
  387. NULL); // No timeout structure
  388. ASSERT (STATUS_SUCCESS == status);
  389. status = Irp->IoStatus.Status;
  390. }
  391. if (NT_SUCCESS(status)) {
  392. //
  393. // Now we can touch the lower device object as it is now started.
  394. //
  395. //
  396. // Get the debug level from the registry
  397. //
  398. if (NULL == (QueryTable = ExAllocatePool(
  399. PagedPool,
  400. sizeof(RTL_QUERY_REGISTRY_TABLE)*2
  401. ))) {
  402. Serenum_KdPrint (DeviceData, SER_DBG_PNP_ERROR,
  403. ("Failed to allocate memory to query registy\n"));
  404. DeviceData->DebugLevel = DebugLevelDefault;
  405. } else {
  406. RtlZeroMemory(
  407. QueryTable,
  408. sizeof(RTL_QUERY_REGISTRY_TABLE)*2
  409. );
  410. QueryTable[0].QueryRoutine = NULL;
  411. QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
  412. QueryTable[0].EntryContext = &DeviceData->DebugLevel;
  413. QueryTable[0].Name = L"DebugLevel";
  414. QueryTable[0].DefaultType = REG_DWORD;
  415. QueryTable[0].DefaultData = &DebugLevelDefault;
  416. QueryTable[0].DefaultLength= sizeof(ULONG);
  417. // CIMEXCIMEX: The rest of the table isn't filled in!
  418. if (!NT_SUCCESS(RtlQueryRegistryValues(
  419. RTL_REGISTRY_SERVICES,
  420. L"Serenum",
  421. QueryTable,
  422. NULL,
  423. NULL))) {
  424. Serenum_KdPrint (DeviceData,SER_DBG_PNP_ERROR,
  425. ("Failed to get debug level from registry. "
  426. "Using default\n"));
  427. DeviceData->DebugLevel = DebugLevelDefault;
  428. }
  429. ExFreePool( QueryTable );
  430. }
  431. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE,
  432. ("Start Device: Device started successfully\n"));
  433. DeviceData->Started = TRUE;
  434. }
  435. //
  436. // We must now complete the IRP, since we stopped it in the
  437. // completetion routine with MORE_PROCESSING_REQUIRED.
  438. //
  439. break;
  440. case IRP_MN_QUERY_STOP_DEVICE:
  441. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE,
  442. ("Query Stop Device\n"));
  443. //
  444. // Test to see if there are any PDO created as children of this FDO
  445. // If there are then conclude the device is busy and fail the
  446. // query stop.
  447. //
  448. // CIMEXCIMEX
  449. // We could do better, by seing if the children PDOs are actually
  450. // currently open. If they are not then we could stop, get new
  451. // resouces, fill in the new resouce values, and then when a new client
  452. // opens the PDO use the new resources. But this works for now.
  453. //
  454. if (DeviceData->AttachedPDO
  455. || (DeviceData->EnumFlags & SERENUM_ENUMFLAG_PENDING)) {
  456. status = STATUS_UNSUCCESSFUL;
  457. } else {
  458. status = STATUS_SUCCESS;
  459. }
  460. Irp->IoStatus.Status = status;
  461. if (NT_SUCCESS(status)) {
  462. IoSkipCurrentIrpStackLocation (Irp);
  463. status = IoCallDriver (DeviceData->TopOfStack, Irp);
  464. } else {
  465. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  466. }
  467. Serenum_DecIoCount (DeviceData);
  468. return status;
  469. case IRP_MN_CANCEL_STOP_DEVICE:
  470. //
  471. // We always succeed a cancel stop
  472. //
  473. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE,
  474. ("Cancel Stop Device\n"));
  475. Irp->IoStatus.Status = STATUS_SUCCESS;
  476. IoSkipCurrentIrpStackLocation(Irp);
  477. status = IoCallDriver(DeviceData->TopOfStack, Irp);
  478. Serenum_DecIoCount (DeviceData);
  479. return status;
  480. case IRP_MN_STOP_DEVICE:
  481. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE, ("Stop Device\n"));
  482. //
  483. // Wait for the enum thread to complete if it's running
  484. //
  485. SerenumWaitForEnumThreadTerminate(DeviceData);
  486. //
  487. // After the start IRP has been sent to the lower driver object, the
  488. // bus may NOT send any more IRPS down ``touch'' until another START
  489. // has occured.
  490. // What ever access is required must be done before the Irp is passed
  491. // on.
  492. //
  493. // Stop device means that the resources given durring Start device
  494. // are no revoked. So we need to stop using them
  495. //
  496. DeviceData->Started = FALSE;
  497. //
  498. // We don't need a completion routine so fire and forget.
  499. //
  500. // Set the current stack location to the next stack location and
  501. // call the next device object.
  502. //
  503. Irp->IoStatus.Status = STATUS_SUCCESS;
  504. IoSkipCurrentIrpStackLocation (Irp);
  505. status = IoCallDriver (DeviceData->TopOfStack, Irp);
  506. Serenum_DecIoCount (DeviceData);
  507. return status;
  508. case IRP_MN_REMOVE_DEVICE:
  509. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE, ("Remove Device\n"));
  510. //
  511. // The PlugPlay system has detected the removal of this device. We
  512. // have no choice but to detach and delete the device object.
  513. // (If we wanted to express and interest in preventing this removal,
  514. // we should have filtered the query remove and query stop routines.)
  515. //
  516. // Note! we might receive a remove WITHOUT first receiving a stop.
  517. // ASSERT (!DeviceData->Removed);
  518. //
  519. // Synchronize with the enum thread if it is running and wait
  520. // for it to finish
  521. //
  522. SerenumWaitForEnumThreadTerminate(DeviceData);
  523. // We will accept no new requests
  524. //
  525. DeviceData->Removed = TRUE;
  526. //
  527. // Complete any outstanding IRPs queued by the driver here.
  528. //
  529. //
  530. // Make the DCA go away. Some drivers may choose to remove the DCA
  531. // when they receive a stop or even a query stop. We just don't care.
  532. //
  533. IoSetDeviceInterfaceState (&DeviceData->DevClassAssocName, FALSE);
  534. //
  535. // Here if we had any outstanding requests in a personal queue we should
  536. // complete them all now.
  537. //
  538. // Note, the device is guarenteed stopped, so we cannot send it any non-
  539. // PNP IRPS.
  540. //
  541. //
  542. // Fire and forget
  543. //
  544. Irp->IoStatus.Status = STATUS_SUCCESS;
  545. IoSkipCurrentIrpStackLocation (Irp);
  546. status = IoCallDriver (DeviceData->TopOfStack, Irp);
  547. //
  548. // Wait for any outstanding threads to complete
  549. //
  550. //
  551. // Wait for all outstanding requests to complete
  552. //
  553. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE,
  554. ("Waiting for outstanding requests\n"));
  555. i = InterlockedDecrement (&DeviceData->OutstandingIO);
  556. ASSERT (0 < i);
  557. if (0 != InterlockedDecrement (&DeviceData->OutstandingIO)) {
  558. Serenum_KdPrint (DeviceData, SER_DBG_PNP_INFO,
  559. ("Remove Device waiting for request to complete\n"));
  560. KeWaitForSingleObject (&DeviceData->RemoveEvent,
  561. Executive,
  562. KernelMode,
  563. FALSE, // Not Alertable
  564. NULL); // No timeout
  565. }
  566. //
  567. // Free the associated resources
  568. //
  569. //
  570. // Detach from the underlying devices.
  571. //
  572. Serenum_KdPrint(DeviceData, SER_DBG_PNP_INFO,
  573. ("IoDetachDevice: 0x%x\n", DeviceData->TopOfStack));
  574. IoDetachDevice (DeviceData->TopOfStack);
  575. //
  576. // Clean up any resources here
  577. //
  578. ExFreePool (DeviceData->DevClassAssocName.Buffer);
  579. Serenum_KdPrint(DeviceData, SER_DBG_PNP_INFO,
  580. ("IoDeleteDevice: 0x%x\n", DeviceObject));
  581. //
  582. // Remove any PDO's we ejected
  583. //
  584. if (DeviceData->AttachedPDO != NULL) {
  585. ASSERT(DeviceData->NumPDOs == 1);
  586. Serenum_PnPRemove(DeviceData->AttachedPDO, DeviceData->PdoData);
  587. DeviceData->PdoData = NULL;
  588. DeviceData->AttachedPDO = NULL;
  589. DeviceData->NumPDOs = 0;
  590. }
  591. IoDeleteDevice(DeviceObject);
  592. return status;
  593. case IRP_MN_QUERY_DEVICE_RELATIONS:
  594. if (BusRelations != IrpStack->Parameters.QueryDeviceRelations.Type) {
  595. //
  596. // We don't support this
  597. //
  598. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE,
  599. ("Query Device Relations - Non bus\n"));
  600. goto SER_FDO_PNP_DEFAULT;
  601. }
  602. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE,
  603. ("Query Bus Relations\n"));
  604. status = SerenumCheckEnumerations(DeviceData);
  605. //
  606. // Tell the plug and play system about all the PDOs.
  607. //
  608. // There might also be device relations below and above this FDO,
  609. // so, be sure to propagate the relations from the upper drivers.
  610. //
  611. // No Completion routine is needed so long as the status is preset
  612. // to success. (PDOs complete plug and play irps with the current
  613. // IoStatus.Status and IoStatus.Information as the default.)
  614. //
  615. //KeAcquireSpinLock (&DeviceData->Spin, &oldIrq);
  616. i = (0 == Irp->IoStatus.Information) ? 0 :
  617. ((PDEVICE_RELATIONS) Irp->IoStatus.Information)->Count;
  618. // The current number of PDOs in the device relations structure
  619. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE,
  620. ("#PDOS = %d + %d\n", i, DeviceData->NumPDOs));
  621. length = sizeof(DEVICE_RELATIONS) +
  622. ((DeviceData->NumPDOs + i) * sizeof (PDEVICE_OBJECT));
  623. relations = (PDEVICE_RELATIONS) ExAllocatePool (NonPagedPool, length);
  624. if (NULL == relations) {
  625. Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
  626. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  627. Serenum_DecIoCount(DeviceData);
  628. return STATUS_INSUFFICIENT_RESOURCES;
  629. }
  630. //
  631. // Copy in the device objects so far
  632. //
  633. if (i) {
  634. RtlCopyMemory (
  635. relations->Objects,
  636. ((PDEVICE_RELATIONS) Irp->IoStatus.Information)->Objects,
  637. i * sizeof (PDEVICE_OBJECT));
  638. }
  639. relations->Count = DeviceData->NumPDOs + i;
  640. //
  641. // For each PDO on this bus add a pointer to the device relations
  642. // buffer, being sure to take out a reference to that object.
  643. // The PlugPlay system will dereference the object when it is done with
  644. // it and free the device relations buffer.
  645. //
  646. if (DeviceData->NumPDOs) {
  647. relations->Objects[relations->Count-1] = DeviceData->AttachedPDO;
  648. ObReferenceObject (DeviceData->AttachedPDO);
  649. }
  650. //
  651. // Set up and pass the IRP further down the stack
  652. //
  653. Irp->IoStatus.Status = STATUS_SUCCESS;
  654. if (0 != Irp->IoStatus.Information) {
  655. ExFreePool ((PVOID) Irp->IoStatus.Information);
  656. }
  657. Irp->IoStatus.Information = (ULONG_PTR)relations;
  658. IoSkipCurrentIrpStackLocation (Irp);
  659. status = IoCallDriver (DeviceData->TopOfStack, Irp);
  660. Serenum_DecIoCount (DeviceData);
  661. return status;
  662. case IRP_MN_QUERY_REMOVE_DEVICE:
  663. //
  664. // If we were to fail this call then we would need to complete the
  665. // IRP here. Since we are not, set the status to SUCCESS and
  666. // call the next driver.
  667. //
  668. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE,
  669. ("Query Remove Device\n"));
  670. Irp->IoStatus.Status = STATUS_SUCCESS;
  671. IoSkipCurrentIrpStackLocation (Irp);
  672. status = IoCallDriver (DeviceData->TopOfStack, Irp);
  673. Serenum_DecIoCount (DeviceData);
  674. return status;
  675. case IRP_MN_QUERY_CAPABILITIES: {
  676. PIO_STACK_LOCATION irpSp;
  677. //
  678. // Send this down to the PDO first
  679. //
  680. KeInitializeEvent (&event, NotificationEvent, FALSE);
  681. IoCopyCurrentIrpStackLocationToNext (Irp);
  682. IoSetCompletionRoutine (Irp,
  683. SerenumSyncCompletion,
  684. &event,
  685. TRUE,
  686. TRUE,
  687. TRUE);
  688. status = IoCallDriver (DeviceData->TopOfStack, Irp);
  689. if (STATUS_PENDING == status) {
  690. // wait for it...
  691. status = KeWaitForSingleObject (&event,
  692. Executive,
  693. KernelMode,
  694. FALSE, // Not allertable
  695. NULL); // No timeout structure
  696. ASSERT (STATUS_SUCCESS == status);
  697. status = Irp->IoStatus.Status;
  698. }
  699. if (NT_SUCCESS(status)) {
  700. irpSp = IoGetCurrentIrpStackLocation(Irp);
  701. DeviceData->SystemWake
  702. = irpSp->Parameters.DeviceCapabilities.Capabilities->SystemWake;
  703. DeviceData->DeviceWake
  704. = irpSp->Parameters.DeviceCapabilities.Capabilities->DeviceWake;
  705. }
  706. break;
  707. }
  708. SER_FDO_PNP_DEFAULT:
  709. default:
  710. //
  711. // In the default case we merely call the next driver since
  712. // we don't know what to do.
  713. //
  714. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE, ("Default Case\n"));
  715. //
  716. // Fire and Forget
  717. //
  718. IoSkipCurrentIrpStackLocation (Irp);
  719. //
  720. // Done, do NOT complete the IRP, it will be processed by the lower
  721. // device object, which will complete the IRP
  722. //
  723. status = IoCallDriver (DeviceData->TopOfStack, Irp);
  724. Serenum_DecIoCount (DeviceData);
  725. return status;
  726. }
  727. Irp->IoStatus.Status = status;
  728. IoCompleteRequest (Irp, IO_NO_INCREMENT);
  729. Serenum_DecIoCount (DeviceData);
  730. return status;
  731. }
  732. VOID
  733. SerenumMarkPdoRemoved(PFDO_DEVICE_DATA PFdoData)
  734. {
  735. KIRQL oldIrql;
  736. KeAcquireSpinLock(&PFdoData->EnumerationLock, &oldIrql);
  737. PFdoData->EnumFlags |= SERENUM_ENUMFLAG_REMOVED;
  738. KeReleaseSpinLock(&PFdoData->EnumerationLock, oldIrql);
  739. }
  740. NTSTATUS
  741. Serenum_PDO_PnP (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
  742. IN PIO_STACK_LOCATION IrpStack, IN PPDO_DEVICE_DATA DeviceData)
  743. /*++
  744. Routine Description:
  745. Handle requests from the PlugPlay system for the devices on the BUS
  746. --*/
  747. {
  748. PDEVICE_CAPABILITIES deviceCapabilities;
  749. ULONG information;
  750. PWCHAR buffer;
  751. ULONG length, i, j;
  752. NTSTATUS status;
  753. KIRQL oldIrq;
  754. HANDLE keyHandle;
  755. UNICODE_STRING keyName;
  756. PWCHAR returnBuffer = NULL;
  757. PFDO_DEVICE_DATA pFdoDeviceData;
  758. PAGED_CODE();
  759. status = Irp->IoStatus.Status;
  760. //
  761. // NB: since we are a bus enumerator, we have no one to whom we could
  762. // defer these irps. Therefore we do not pass them down but merely
  763. // return them.
  764. //
  765. switch (IrpStack->MinorFunction) {
  766. case IRP_MN_QUERY_CAPABILITIES:
  767. Serenum_KdPrint (DeviceData, SER_DBG_PNP_TRACE, ("Query Caps \n"));
  768. //
  769. // Get the packet.
  770. //
  771. deviceCapabilities=IrpStack->Parameters.DeviceCapabilities.Capabilities;
  772. //
  773. // Set the capabilities.
  774. //
  775. deviceCapabilities->Version = 1;
  776. deviceCapabilities->Size = sizeof (DEVICE_CAPABILITIES);
  777. //
  778. // We cannot wake the system.
  779. //
  780. deviceCapabilities->SystemWake
  781. = ((PFDO_DEVICE_DATA)DeviceData->ParentFdo->DeviceExtension)
  782. ->SystemWake;
  783. deviceCapabilities->DeviceWake
  784. = ((PFDO_DEVICE_DATA)DeviceData->ParentFdo->DeviceExtension)
  785. ->DeviceWake;
  786. //
  787. // We have no latencies
  788. //
  789. deviceCapabilities->D1Latency = 0;
  790. deviceCapabilities->D2Latency = 0;
  791. deviceCapabilities->D3Latency = 0;
  792. deviceCapabilities->UniqueID = FALSE;
  793. status = STATUS_SUCCESS;
  794. break;
  795. case IRP_MN_QUERY_DEVICE_TEXT: {
  796. if ((IrpStack->Parameters.QueryDeviceText.DeviceTextType
  797. != DeviceTextDescription) || DeviceData->DevDesc.Buffer == NULL) {
  798. break;
  799. }
  800. returnBuffer = ExAllocatePool(PagedPool, DeviceData->DevDesc.Length);
  801. if (returnBuffer == NULL) {
  802. status = STATUS_INSUFFICIENT_RESOURCES;
  803. break;
  804. }
  805. status = STATUS_SUCCESS;
  806. RtlCopyMemory(returnBuffer, DeviceData->DevDesc.Buffer,
  807. DeviceData->DevDesc.Length);
  808. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE,
  809. ("TextID: buf 0x%x\n", returnBuffer));
  810. Irp->IoStatus.Information = (ULONG_PTR)returnBuffer;
  811. break;
  812. }
  813. case IRP_MN_QUERY_ID:
  814. //
  815. // Query the IDs of the device
  816. //
  817. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE,
  818. ("QueryID: 0x%x\n", IrpStack->Parameters.QueryId.IdType));
  819. switch (IrpStack->Parameters.QueryId.IdType) {
  820. case BusQueryInstanceID:
  821. //
  822. // Build an instance ID. This is what PnP uses to tell if it has
  823. // seen this thing before or not. Build it from the first hardware
  824. // id and the port number.
  825. //
  826. // NB since we do not incorperate the port number
  827. // this method does not produce unique ids;
  828. //
  829. // return 0000 for all devices and have the flag set to not unique
  830. //
  831. status = STATUS_SUCCESS;
  832. length = SERENUM_INSTANCE_IDS_LENGTH * sizeof(WCHAR);
  833. returnBuffer = ExAllocatePool(PagedPool, length);
  834. if (returnBuffer != NULL) {
  835. RtlCopyMemory(returnBuffer, SERENUM_INSTANCE_IDS, length);
  836. } else {
  837. status = STATUS_INSUFFICIENT_RESOURCES;
  838. }
  839. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE,
  840. ("InstanceID: buf 0x%x\n", returnBuffer));
  841. Irp->IoStatus.Information = (ULONG_PTR)returnBuffer;
  842. break;
  843. //
  844. // The other ID's we just copy from the buffers and are done.
  845. //
  846. case BusQueryDeviceID:
  847. case BusQueryHardwareIDs:
  848. case BusQueryCompatibleIDs:
  849. {
  850. PUNICODE_STRING pId;
  851. status = STATUS_SUCCESS;
  852. switch (IrpStack->Parameters.QueryId.IdType) {
  853. case BusQueryDeviceID:
  854. pId = &DeviceData->DeviceIDs;
  855. break;
  856. case BusQueryHardwareIDs:
  857. pId = &DeviceData->HardwareIDs;
  858. break;
  859. case BusQueryCompatibleIDs:
  860. pId = &DeviceData->CompIDs;
  861. break;
  862. }
  863. buffer = pId->Buffer;
  864. if (buffer != NULL) {
  865. length = pId->Length;
  866. returnBuffer = ExAllocatePool(PagedPool, length);
  867. if (returnBuffer != NULL) {
  868. #if DBG
  869. RtlFillMemory(returnBuffer, length, 0xff);
  870. #endif
  871. RtlCopyMemory(returnBuffer, buffer, pId->Length);
  872. } else {
  873. status = STATUS_INSUFFICIENT_RESOURCES;
  874. }
  875. }
  876. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE,
  877. ("ID: Unicode 0x%x\n", pId));
  878. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE,
  879. ("ID: buf 0x%x\n", returnBuffer));
  880. Irp->IoStatus.Information = (ULONG_PTR)returnBuffer;
  881. }
  882. break;
  883. }
  884. break;
  885. case IRP_MN_QUERY_BUS_INFORMATION: {
  886. PPNP_BUS_INFORMATION pBusInfo;
  887. ASSERTMSG("Serenum appears not to be the sole bus?!?",
  888. Irp->IoStatus.Information == (ULONG_PTR)NULL);
  889. pBusInfo = ExAllocatePool(PagedPool, sizeof(PNP_BUS_INFORMATION));
  890. if (pBusInfo == NULL) {
  891. status = STATUS_INSUFFICIENT_RESOURCES;
  892. break;
  893. }
  894. pBusInfo->BusTypeGuid = GUID_BUS_TYPE_SERENUM;
  895. pBusInfo->LegacyBusType = PNPBus;
  896. //
  897. // We really can't track our bus number since we can be torn
  898. // down with our bus
  899. //
  900. pBusInfo->BusNumber = 0;
  901. Irp->IoStatus.Information = (ULONG_PTR)pBusInfo;
  902. status = STATUS_SUCCESS;
  903. break;
  904. }
  905. case IRP_MN_QUERY_DEVICE_RELATIONS:
  906. switch (IrpStack->Parameters.QueryDeviceRelations.Type) {
  907. case TargetDeviceRelation: {
  908. PDEVICE_RELATIONS pDevRel;
  909. //
  910. // No one else should respond to this since we are the PDO
  911. //
  912. ASSERT(Irp->IoStatus.Information == 0);
  913. if (Irp->IoStatus.Information != 0) {
  914. break;
  915. }
  916. pDevRel = ExAllocatePool(PagedPool, sizeof(DEVICE_RELATIONS));
  917. if (pDevRel == NULL) {
  918. status = STATUS_INSUFFICIENT_RESOURCES;
  919. break;
  920. }
  921. pDevRel->Count = 1;
  922. pDevRel->Objects[0] = DeviceObject;
  923. ObReferenceObject(DeviceObject);
  924. status = STATUS_SUCCESS;
  925. Irp->IoStatus.Information = (ULONG_PTR)pDevRel;
  926. break;
  927. }
  928. default:
  929. break;
  930. }
  931. break;
  932. case IRP_MN_START_DEVICE:
  933. //
  934. // Save serial number and PnPRev
  935. //
  936. if(DeviceData->PnPRev.Length || DeviceData->SerialNo.Length) {
  937. UNICODE_STRING keyname;
  938. HANDLE pnpKey;
  939. status = IoOpenDeviceRegistryKey(DeviceObject, PLUGPLAY_REGKEY_DEVICE,
  940. STANDARD_RIGHTS_WRITE, &pnpKey);
  941. if(DeviceData->PnPRev.Length) {
  942. RtlInitUnicodeString(&keyname, NULL);
  943. keyname.MaximumLength = sizeof(L"PnPRev"+sizeof(WCHAR));
  944. keyname.Buffer = ExAllocatePool(PagedPool, keyname.MaximumLength);
  945. if (keyname.Buffer != NULL) {
  946. RtlAppendUnicodeToString(&keyname, L"PnPRev");
  947. status = ZwSetValueKey(pnpKey, &keyname, 0, REG_SZ, DeviceData->PnPRev.Buffer, DeviceData->PnPRev.Length+sizeof(WCHAR));
  948. ExFreePool(keyname.Buffer);
  949. }
  950. }
  951. if(DeviceData->SerialNo.Length) {
  952. RtlInitUnicodeString(&keyname, NULL);
  953. keyname.MaximumLength = sizeof(L"Serial Number"+sizeof(WCHAR));
  954. keyname.Buffer = ExAllocatePool(PagedPool, keyname.MaximumLength);
  955. if (keyname.Buffer != NULL) {
  956. RtlAppendUnicodeToString(&keyname, L"Serial Number");
  957. status = ZwSetValueKey(pnpKey, &keyname, 0, REG_SZ, DeviceData->SerialNo.Buffer, DeviceData->SerialNo.Length+sizeof(WCHAR));
  958. ExFreePool(keyname.Buffer);
  959. }
  960. }
  961. }
  962. DeviceData->Started = TRUE;
  963. status = STATUS_SUCCESS;
  964. break;
  965. case IRP_MN_STOP_DEVICE:
  966. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE, ("Stop Device\n"));
  967. //
  968. // Here we shut down the device. The opposite of start.
  969. //
  970. DeviceData->Started = FALSE;
  971. status = STATUS_SUCCESS;
  972. break;
  973. case IRP_MN_REMOVE_DEVICE:
  974. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE, ("Remove Device\n"));
  975. //
  976. // Mark as removed so we enumerate devices correctly -- this will
  977. // cause the next enumeration request to occur synchronously
  978. //
  979. SerenumMarkPdoRemoved((PFDO_DEVICE_DATA)DeviceData->ParentFdo
  980. ->DeviceExtension);
  981. //
  982. // Attached is only set to FALSE by the enumeration process.
  983. //
  984. if (!DeviceData->Attached) {
  985. status = Serenum_PnPRemove(DeviceObject, DeviceData);
  986. }
  987. else {
  988. //
  989. // Succeed the remove
  990. ///
  991. status = STATUS_SUCCESS;
  992. }
  993. break;
  994. case IRP_MN_QUERY_STOP_DEVICE:
  995. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE, ("Query Stop Device\n"));
  996. //
  997. // No reason here why we can't stop the device.
  998. // If there were a reason we should speak now for answering success
  999. // here may result in a stop device irp.
  1000. //
  1001. status = STATUS_SUCCESS;
  1002. break;
  1003. case IRP_MN_CANCEL_STOP_DEVICE:
  1004. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE, ("Cancel Stop Device\n"));
  1005. //
  1006. // The stop was canceled. Whatever state we set, or resources we put
  1007. // on hold in anticipation of the forcoming STOP device IRP should be
  1008. // put back to normal. Someone, in the long list of concerned parties,
  1009. // has failed the stop device query.
  1010. //
  1011. status = STATUS_SUCCESS;
  1012. break;
  1013. case IRP_MN_QUERY_REMOVE_DEVICE:
  1014. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE, ("Query Remove Device\n"));
  1015. //
  1016. // Just like Query Stop only now the impending doom is the remove irp
  1017. //
  1018. status = STATUS_SUCCESS;
  1019. break;
  1020. case IRP_MN_CANCEL_REMOVE_DEVICE:
  1021. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE, ("Cancel Remove Device"
  1022. "\n"));
  1023. //
  1024. // Clean up a remove that did not go through, just like cancel STOP.
  1025. //
  1026. status = STATUS_SUCCESS;
  1027. break;
  1028. case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
  1029. case IRP_MN_READ_CONFIG:
  1030. case IRP_MN_WRITE_CONFIG: // we have no config space
  1031. case IRP_MN_EJECT:
  1032. case IRP_MN_SET_LOCK:
  1033. case IRP_MN_QUERY_INTERFACE: // We do not have any non IRP based interfaces.
  1034. default:
  1035. Serenum_KdPrint(DeviceData, SER_DBG_PNP_TRACE, ("PNP Not handled 0x%x\n",
  1036. IrpStack->MinorFunction));
  1037. // For PnP requests to the PDO that we do not understand we should
  1038. // return the IRP WITHOUT setting the status or information fields.
  1039. // They may have already been set by a filter (eg acpi).
  1040. break;
  1041. }
  1042. Irp->IoStatus.Status = status;
  1043. IoCompleteRequest (Irp, IO_NO_INCREMENT);
  1044. return status;
  1045. }
  1046. NTSTATUS
  1047. Serenum_PnPRemove (PDEVICE_OBJECT Device, PPDO_DEVICE_DATA PdoData)
  1048. /*++
  1049. Routine Description:
  1050. The PlugPlay subsystem has instructed that this PDO should be removed.
  1051. We should therefore
  1052. - Complete any requests queued in the driver
  1053. - If the device is still attached to the system,
  1054. then complete the request and return.
  1055. - Otherwise, cleanup device specific allocations, memory, events...
  1056. - Call IoDeleteDevice
  1057. - Return from the dispatch routine.
  1058. Note that if the device is still connected to the bus (IE in this case
  1059. the control panel has not yet told us that the serial device has
  1060. disappeared) then the PDO must remain around, and must be returned during
  1061. any query Device relaions IRPS.
  1062. --*/
  1063. {
  1064. Serenum_KdPrint(PdoData, SER_DBG_PNP_TRACE,
  1065. ("Serenum_PnPRemove: 0x%x\n", Device));
  1066. //
  1067. // Complete any outstanding requests with STATUS_DELETE_PENDING.
  1068. //
  1069. // Serenum does not queue any irps at this time so we have nothing to do.
  1070. //
  1071. if (PdoData->Attached || PdoData->Removed) {
  1072. return STATUS_SUCCESS;
  1073. }
  1074. PdoData->Removed = TRUE;
  1075. //
  1076. // Free any resources.
  1077. //
  1078. RtlFreeUnicodeString(&PdoData->HardwareIDs);
  1079. RtlFreeUnicodeString(&PdoData->CompIDs);
  1080. RtlFreeUnicodeString(&PdoData->DeviceIDs);
  1081. Serenum_KdPrint(PdoData, SER_DBG_PNP_INFO,
  1082. ("IoDeleteDevice: 0x%x\n", Device));
  1083. IoDeleteDevice(Device);
  1084. return STATUS_SUCCESS;
  1085. }