Leaked source code of windows server 2003
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.

2573 lines
64 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. sSPnP.c
  5. Abstract:
  6. This file contains code to handle the pnp irps.
  7. This is not USB specific but is essential for
  8. every WDM driver.
  9. Environment:
  10. Kernel mode
  11. Notes:
  12. Copyright (c) 2000 Microsoft Corporation.
  13. All Rights Reserved.
  14. --*/
  15. #include "selSusp.h"
  16. #include "sSPnP.h"
  17. #include "sSPwr.h"
  18. #include "sSDevCtr.h"
  19. #include "sSWmi.h"
  20. #include "sSUsr.h"
  21. NTSTATUS
  22. SS_DispatchPnP(
  23. IN PDEVICE_OBJECT DeviceObject,
  24. IN PIRP Irp
  25. )
  26. /*++
  27. Routine Description:
  28. The plug and play dispatch routines.
  29. Most of these requests the driver will completely ignore.
  30. In all cases it must pass on the IRP to the lower driver.
  31. Arguments:
  32. DeviceObject - pointer to a device object.
  33. Irp - pointer to an I/O Request Packet.
  34. Return Value:
  35. NT status code
  36. --*/
  37. {
  38. PIO_STACK_LOCATION irpStack;
  39. PDEVICE_EXTENSION deviceExtension;
  40. KEVENT startDeviceEvent;
  41. NTSTATUS ntStatus;
  42. //
  43. // initialize variables
  44. //
  45. irpStack = IoGetCurrentIrpStackLocation(Irp);
  46. deviceExtension = DeviceObject->DeviceExtension;
  47. //
  48. // since the device is removed, fail the Irp.
  49. //
  50. if(Removed == deviceExtension->DeviceState) {
  51. ntStatus = STATUS_DELETE_PENDING;
  52. Irp->IoStatus.Status = ntStatus;
  53. Irp->IoStatus.Information = 0;
  54. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  55. return ntStatus;
  56. }
  57. SSDbgPrint(3, ("///////////////////////////////////////////\n"));
  58. SSDbgPrint(3, ("SS_DispatchPnP::"));
  59. SSIoIncrement(deviceExtension);
  60. if(irpStack->MinorFunction == IRP_MN_START_DEVICE) {
  61. ASSERT(deviceExtension->IdleReqPend == 0);
  62. }
  63. else {
  64. if(deviceExtension->SSEnable) {
  65. CancelSelectSuspend(deviceExtension);
  66. }
  67. }
  68. SSDbgPrint(2, (PnPMinorFunctionString(irpStack->MinorFunction)));
  69. switch(irpStack->MinorFunction) {
  70. case IRP_MN_START_DEVICE:
  71. ntStatus = HandleStartDevice(DeviceObject, Irp);
  72. break;
  73. case IRP_MN_QUERY_STOP_DEVICE:
  74. //
  75. // if we cannot stop the device, we fail the query stop irp
  76. //
  77. ntStatus = CanStopDevice(DeviceObject, Irp);
  78. if(NT_SUCCESS(ntStatus)) {
  79. ntStatus = HandleQueryStopDevice(DeviceObject, Irp);
  80. return ntStatus;
  81. }
  82. break;
  83. case IRP_MN_CANCEL_STOP_DEVICE:
  84. ntStatus = HandleCancelStopDevice(DeviceObject, Irp);
  85. break;
  86. case IRP_MN_STOP_DEVICE:
  87. ntStatus = HandleStopDevice(DeviceObject, Irp);
  88. SSDbgPrint(3, ("SS_DispatchPnP::IRP_MN_STOP_DEVICE::"));
  89. SSIoDecrement(deviceExtension);
  90. return ntStatus;
  91. case IRP_MN_QUERY_REMOVE_DEVICE:
  92. //
  93. // if we cannot remove the device, we fail the query remove irp
  94. //
  95. ntStatus = CanRemoveDevice(DeviceObject, Irp);
  96. if(NT_SUCCESS(ntStatus)) {
  97. ntStatus = HandleQueryRemoveDevice(DeviceObject, Irp);
  98. return ntStatus;
  99. }
  100. break;
  101. case IRP_MN_CANCEL_REMOVE_DEVICE:
  102. ntStatus = HandleCancelRemoveDevice(DeviceObject, Irp);
  103. break;
  104. case IRP_MN_SURPRISE_REMOVAL:
  105. ntStatus = HandleSurpriseRemoval(DeviceObject, Irp);
  106. SSDbgPrint(3, ("SS_DispatchPnP::IRP_MN_SURPRISE_REMOVAL::"));
  107. SSIoDecrement(deviceExtension);
  108. return ntStatus;
  109. case IRP_MN_REMOVE_DEVICE:
  110. ntStatus = HandleRemoveDevice(DeviceObject, Irp);
  111. return ntStatus;
  112. case IRP_MN_QUERY_CAPABILITIES:
  113. ntStatus = HandleQueryCapabilities(DeviceObject, Irp);
  114. break;
  115. default:
  116. IoSkipCurrentIrpStackLocation(Irp);
  117. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
  118. SSDbgPrint(3, ("SS_DispatchPnP::default::"));
  119. SSIoDecrement(deviceExtension);
  120. return ntStatus;
  121. } // switch
  122. //
  123. // complete request
  124. //
  125. Irp->IoStatus.Status = ntStatus;
  126. Irp->IoStatus.Information = 0;
  127. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  128. //
  129. // decrement count
  130. //
  131. SSDbgPrint(3, ("SS_DispatchPnP::"));
  132. SSIoDecrement(deviceExtension);
  133. return ntStatus;
  134. }
  135. NTSTATUS
  136. HandleStartDevice(
  137. IN PDEVICE_OBJECT DeviceObject,
  138. IN PIRP Irp
  139. )
  140. /*++
  141. Routine Description:
  142. This is the dispatch routine for IRP_MN_START_DEVICE
  143. Arguments:
  144. DeviceObject - pointer to a device object.
  145. Irp - I/O request packet
  146. Return Value:
  147. NT status value
  148. --*/
  149. {
  150. KIRQL oldIrql;
  151. KEVENT startDeviceEvent;
  152. NTSTATUS ntStatus;
  153. PDEVICE_EXTENSION deviceExtension;
  154. LARGE_INTEGER dueTime;
  155. SSDbgPrint(3, ("HandleStartDevice - begins\n"));
  156. //
  157. // initialize variables
  158. //
  159. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  160. //
  161. // We cannot touch the device (send it any non pnp irps) until a
  162. // start device has been passed down to the lower drivers.
  163. // first pass the Irp down
  164. //
  165. KeInitializeEvent(&startDeviceEvent, NotificationEvent, FALSE);
  166. IoCopyCurrentIrpStackLocationToNext(Irp);
  167. IoSetCompletionRoutine(Irp,
  168. (PIO_COMPLETION_ROUTINE)IrpCompletionRoutine,
  169. (PVOID)&startDeviceEvent,
  170. TRUE,
  171. TRUE,
  172. TRUE);
  173. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
  174. if(ntStatus == STATUS_PENDING) {
  175. KeWaitForSingleObject(&startDeviceEvent,
  176. Executive,
  177. KernelMode,
  178. FALSE,
  179. NULL);
  180. ntStatus = Irp->IoStatus.Status;
  181. }
  182. if(!NT_SUCCESS(ntStatus)) {
  183. SSDbgPrint(1, ("Lower drivers failed IRP_MN_START_DEVICE\n"));
  184. return ntStatus;
  185. }
  186. //
  187. // Read the device descriptor, configuration descriptor
  188. // and select the interface descriptors
  189. //
  190. ntStatus = ReadandSelectDescriptors(DeviceObject);
  191. if(!NT_SUCCESS(ntStatus)) {
  192. SSDbgPrint(1, ("ReadandSelectDescriptors failed\n"));
  193. return ntStatus;
  194. }
  195. //
  196. // enable the symbolic links for system components to open
  197. // handles to the device
  198. //
  199. ntStatus = IoSetDeviceInterfaceState(&deviceExtension->InterfaceName,
  200. TRUE);
  201. if(!NT_SUCCESS(ntStatus)) {
  202. SSDbgPrint(1, ("IoSetDeviceInterfaceState:enable:failed\n"));
  203. return ntStatus;
  204. }
  205. KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
  206. SET_NEW_PNP_STATE(deviceExtension, Working);
  207. deviceExtension->QueueState = AllowRequests;
  208. KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
  209. //
  210. // initialize wait wake variables
  211. // and issue a wait wake.
  212. deviceExtension->WaitWakeIrp = NULL;
  213. deviceExtension->FlagWWCancel = 0;
  214. deviceExtension->FlagWWOutstanding = 0;
  215. if(deviceExtension->WaitWakeEnable) {
  216. IssueWaitWake(deviceExtension);
  217. }
  218. ProcessQueuedRequests(deviceExtension);
  219. if(WinXpOrBetter == deviceExtension->WdmVersion) {
  220. deviceExtension->SSEnable = deviceExtension->SSRegistryEnable;
  221. //
  222. // set timer for selective suspend requests.
  223. //
  224. if(deviceExtension->SSEnable) {
  225. dueTime.QuadPart = -10000 * IDLE_INTERVAL; // 5000 ms
  226. SSDbgPrint(3, ("Setting the timer...\n"));
  227. KeSetTimerEx(&deviceExtension->Timer,
  228. dueTime,
  229. IDLE_INTERVAL, // 5000 ms
  230. &deviceExtension->DeferredProcCall);
  231. deviceExtension->FreeIdleIrpCount = 0;
  232. }
  233. }
  234. SSDbgPrint(3, ("HandleStartDevice - ends\n"));
  235. return ntStatus;
  236. }
  237. NTSTATUS
  238. ReadandSelectDescriptors(
  239. IN PDEVICE_OBJECT DeviceObject
  240. )
  241. /*++
  242. Routine Description:
  243. This routine configures the USB device.
  244. In this routines we get the device descriptor,
  245. the configuration descriptor and select the
  246. configuration descriptor.
  247. Arguments:
  248. DeviceObject - pointer to a device object
  249. Return Value:
  250. NTSTATUS - NT status value.
  251. --*/
  252. {
  253. PURB urb;
  254. ULONG siz;
  255. NTSTATUS ntStatus;
  256. PUSB_DEVICE_DESCRIPTOR deviceDescriptor;
  257. //
  258. // initialize variables
  259. //
  260. urb = NULL;
  261. deviceDescriptor = NULL;
  262. //
  263. // 1. Read the device descriptor
  264. //
  265. urb = ExAllocatePool(NonPagedPool,
  266. sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
  267. if(urb) {
  268. siz = sizeof(USB_DEVICE_DESCRIPTOR);
  269. deviceDescriptor = ExAllocatePool(NonPagedPool, siz);
  270. if(deviceDescriptor) {
  271. UsbBuildGetDescriptorRequest(
  272. urb,
  273. (USHORT) sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
  274. USB_DEVICE_DESCRIPTOR_TYPE,
  275. 0,
  276. 0,
  277. deviceDescriptor,
  278. NULL,
  279. siz,
  280. NULL);
  281. ntStatus = CallUSBD(DeviceObject, urb);
  282. if(NT_SUCCESS(ntStatus)) {
  283. ASSERT(deviceDescriptor->bNumConfigurations);
  284. ntStatus = ConfigureDevice(DeviceObject);
  285. }
  286. ExFreePool(urb);
  287. ExFreePool(deviceDescriptor);
  288. }
  289. else {
  290. SSDbgPrint(1, ("Failed to allocate memory for deviceDescriptor\n"));
  291. ExFreePool(urb);
  292. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  293. }
  294. }
  295. else {
  296. SSDbgPrint(1, ("Failed to allocate memory for urb\n"));
  297. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  298. }
  299. return ntStatus;
  300. }
  301. NTSTATUS
  302. ConfigureDevice(
  303. IN PDEVICE_OBJECT DeviceObject
  304. )
  305. /*++
  306. Routine Description:
  307. This helper routine reads the configuration descriptor
  308. for the device in couple of steps.
  309. Arguments:
  310. DeviceObject - pointer to a device object
  311. Return Value:
  312. NTSTATUS - NT status value
  313. --*/
  314. {
  315. PURB urb;
  316. ULONG siz;
  317. NTSTATUS ntStatus;
  318. PDEVICE_EXTENSION deviceExtension;
  319. PUSB_CONFIGURATION_DESCRIPTOR configurationDescriptor;
  320. //
  321. // initialize the variables
  322. //
  323. urb = NULL;
  324. configurationDescriptor = NULL;
  325. deviceExtension = DeviceObject->DeviceExtension;
  326. //
  327. // Read the first configuration descriptor
  328. // This requires two steps:
  329. // 1. Read the fixed sized configuration desciptor (CD)
  330. // 2. Read the CD with all embedded interface and endpoint descriptors
  331. //
  332. urb = ExAllocatePool(NonPagedPool,
  333. sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
  334. if(urb) {
  335. siz = sizeof(USB_CONFIGURATION_DESCRIPTOR);
  336. configurationDescriptor = ExAllocatePool(NonPagedPool, siz);
  337. if(configurationDescriptor) {
  338. UsbBuildGetDescriptorRequest(
  339. urb,
  340. (USHORT) sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
  341. USB_CONFIGURATION_DESCRIPTOR_TYPE,
  342. 0,
  343. 0,
  344. configurationDescriptor,
  345. NULL,
  346. sizeof(USB_CONFIGURATION_DESCRIPTOR),
  347. NULL);
  348. ntStatus = CallUSBD(DeviceObject, urb);
  349. if(!NT_SUCCESS(ntStatus)) {
  350. SSDbgPrint(1, ("UsbBuildGetDescriptorRequest failed\n"));
  351. goto ConfigureDevice_Exit;
  352. }
  353. }
  354. else {
  355. SSDbgPrint(1, ("Failed to allocate mem for config Descriptor\n"));
  356. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  357. goto ConfigureDevice_Exit;
  358. }
  359. siz = configurationDescriptor->wTotalLength;
  360. ExFreePool(configurationDescriptor);
  361. configurationDescriptor = ExAllocatePool(NonPagedPool, siz);
  362. if(configurationDescriptor) {
  363. UsbBuildGetDescriptorRequest(
  364. urb,
  365. (USHORT)sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
  366. USB_CONFIGURATION_DESCRIPTOR_TYPE,
  367. 0,
  368. 0,
  369. configurationDescriptor,
  370. NULL,
  371. siz,
  372. NULL);
  373. ntStatus = CallUSBD(DeviceObject, urb);
  374. if(!NT_SUCCESS(ntStatus)) {
  375. SSDbgPrint(1,("Failed to read configuration descriptor\n"));
  376. goto ConfigureDevice_Exit;
  377. }
  378. }
  379. else {
  380. SSDbgPrint(1, ("Failed to alloc mem for config Descriptor\n"));
  381. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  382. goto ConfigureDevice_Exit;
  383. }
  384. }
  385. else {
  386. SSDbgPrint(1, ("Failed to allocate memory for urb\n"));
  387. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  388. goto ConfigureDevice_Exit;
  389. }
  390. if(configurationDescriptor) {
  391. if(configurationDescriptor->bmAttributes & REMOTE_WAKEUP_MASK)
  392. {
  393. //
  394. // this configuration supports remote wakeup
  395. //
  396. deviceExtension->WaitWakeEnable = 1;
  397. }
  398. else
  399. {
  400. deviceExtension->WaitWakeEnable = 0;
  401. }
  402. ntStatus = SelectInterfaces(DeviceObject, configurationDescriptor);
  403. }
  404. ConfigureDevice_Exit:
  405. if(urb) {
  406. ExFreePool(urb);
  407. }
  408. if(configurationDescriptor) {
  409. ExFreePool(configurationDescriptor);
  410. }
  411. return ntStatus;
  412. }
  413. NTSTATUS
  414. SelectInterfaces(
  415. IN PDEVICE_OBJECT DeviceObject,
  416. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
  417. )
  418. /*++
  419. Routine Description:
  420. This helper routine selects the configuration
  421. Arguments:
  422. DeviceObject - pointer to device object
  423. ConfigurationDescriptor - pointer to the configuration
  424. descriptor for the device
  425. Return Value:
  426. NT status value
  427. --*/
  428. {
  429. LONG numberOfInterfaces,
  430. interfaceNumber,
  431. interfaceindex;
  432. ULONG i;
  433. PURB urb;
  434. PUCHAR pInf;
  435. NTSTATUS ntStatus;
  436. PDEVICE_EXTENSION deviceExtension;
  437. PUSB_INTERFACE_DESCRIPTOR interfaceDescriptor;
  438. PUSBD_INTERFACE_LIST_ENTRY interfaceList,
  439. tmp;
  440. PUSBD_INTERFACE_INFORMATION interface;
  441. //
  442. // initialize the variables
  443. //
  444. urb = NULL;
  445. interface = NULL;
  446. interfaceDescriptor = NULL;
  447. deviceExtension = DeviceObject->DeviceExtension;
  448. numberOfInterfaces = ConfigurationDescriptor->bNumInterfaces;
  449. interfaceindex = interfaceNumber = 0;
  450. //
  451. // Parse the configuration descriptor for the interface;
  452. //
  453. tmp = interfaceList =
  454. ExAllocatePool(
  455. NonPagedPool,
  456. sizeof(USBD_INTERFACE_LIST_ENTRY) * (numberOfInterfaces + 1));
  457. if(!tmp) {
  458. SSDbgPrint(1, ("Failed to allocate mem for interfaceList\n"));
  459. return STATUS_INSUFFICIENT_RESOURCES;
  460. }
  461. while(interfaceNumber < numberOfInterfaces) {
  462. interfaceDescriptor = USBD_ParseConfigurationDescriptorEx(
  463. ConfigurationDescriptor,
  464. ConfigurationDescriptor,
  465. interfaceindex,
  466. 0, -1, -1, -1);
  467. if(interfaceDescriptor) {
  468. interfaceList->InterfaceDescriptor = interfaceDescriptor;
  469. interfaceList->Interface = NULL;
  470. interfaceList++;
  471. interfaceNumber++;
  472. }
  473. interfaceindex++;
  474. }
  475. interfaceList->InterfaceDescriptor = NULL;
  476. interfaceList->Interface = NULL;
  477. urb = USBD_CreateConfigurationRequestEx(ConfigurationDescriptor, tmp);
  478. if(urb) {
  479. interface = &urb->UrbSelectConfiguration.Interface;
  480. for(i=0; i<interface->NumberOfPipes; i++) {
  481. //
  482. // perform pipe initialization here
  483. // set the transfer size and any pipe flags we use
  484. // USBD sets the rest of the Interface struct members
  485. //
  486. interface->Pipes[i].MaximumTransferSize =
  487. USBD_DEFAULT_MAXIMUM_TRANSFER_SIZE;
  488. }
  489. ntStatus = CallUSBD(DeviceObject, urb);
  490. if(!NT_SUCCESS(ntStatus)) {
  491. SSDbgPrint(1, ("Failed to select an interface\n"));
  492. }
  493. }
  494. else {
  495. SSDbgPrint(1, ("USBD_CreateConfigurationRequestEx failed\n"));
  496. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  497. }
  498. if(tmp) {
  499. ExFreePool(tmp);
  500. }
  501. if(urb) {
  502. ExFreePool(urb);
  503. }
  504. return ntStatus;
  505. }
  506. NTSTATUS
  507. DeconfigureDevice(
  508. IN PDEVICE_OBJECT DeviceObject
  509. )
  510. /*++
  511. Routine Description:
  512. This routine is invoked when the device is removed or stopped.
  513. This routine de-configures the usb device.
  514. Arguments:
  515. DeviceObject - pointer to device object
  516. Return Value:
  517. NT status value
  518. --*/
  519. {
  520. PURB urb;
  521. ULONG siz;
  522. NTSTATUS ntStatus;
  523. //
  524. // initialize variables
  525. //
  526. siz = sizeof(struct _URB_SELECT_CONFIGURATION);
  527. urb = ExAllocatePool(NonPagedPool, siz);
  528. if(urb) {
  529. UsbBuildSelectConfigurationRequest(urb, (USHORT)siz, NULL);
  530. ntStatus = CallUSBD(DeviceObject, urb);
  531. if(!NT_SUCCESS(ntStatus)) {
  532. SSDbgPrint(3, ("Failed to deconfigure device\n"));
  533. }
  534. ExFreePool(urb);
  535. }
  536. else {
  537. SSDbgPrint(1, ("Failed to allocate urb\n"));
  538. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  539. }
  540. return ntStatus;
  541. }
  542. NTSTATUS
  543. CallUSBD(
  544. IN PDEVICE_OBJECT DeviceObject,
  545. IN PURB Urb
  546. )
  547. /*++
  548. Routine Description:
  549. This routine synchronously submits an urb down the stack.
  550. Arguments:
  551. DeviceObject - pointer to device object
  552. Urb - USB request block
  553. Return Value:
  554. NT status value
  555. --*/
  556. {
  557. PIRP irp;
  558. KEVENT event;
  559. NTSTATUS ntStatus;
  560. IO_STATUS_BLOCK ioStatus;
  561. PIO_STACK_LOCATION nextStack;
  562. PDEVICE_EXTENSION deviceExtension;
  563. //
  564. // initialize the variables
  565. //
  566. irp = NULL;
  567. deviceExtension = DeviceObject->DeviceExtension;
  568. KeInitializeEvent(&event, NotificationEvent, FALSE);
  569. irp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_SUBMIT_URB,
  570. deviceExtension->TopOfStackDeviceObject,
  571. NULL,
  572. 0,
  573. NULL,
  574. 0,
  575. TRUE,
  576. &event,
  577. &ioStatus);
  578. if(!irp) {
  579. SSDbgPrint(1, ("IoBuildDeviceIoControlRequest failed\n"));
  580. return STATUS_INSUFFICIENT_RESOURCES;
  581. }
  582. nextStack = IoGetNextIrpStackLocation(irp);
  583. ASSERT(nextStack != NULL);
  584. nextStack->Parameters.Others.Argument1 = Urb;
  585. SSDbgPrint(3, ("CallUSBD::"));
  586. SSIoIncrement(deviceExtension);
  587. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, irp);
  588. if(ntStatus == STATUS_PENDING) {
  589. KeWaitForSingleObject(&event,
  590. Executive,
  591. KernelMode,
  592. FALSE,
  593. NULL);
  594. ntStatus = ioStatus.Status;
  595. }
  596. SSDbgPrint(3, ("CallUSBD::"));
  597. SSIoDecrement(deviceExtension);
  598. return ntStatus;
  599. }
  600. NTSTATUS
  601. HandleQueryStopDevice(
  602. IN PDEVICE_OBJECT DeviceObject,
  603. IN PIRP Irp
  604. )
  605. /*++
  606. Routine Description:
  607. This routine services the Irps of minor type IRP_MN_QUERY_STOP_DEVICE
  608. Arguments:
  609. DeviceObject - pointer to device object
  610. Irp - I/O request packet sent by the pnp manager.
  611. Return Value:
  612. NT status value
  613. --*/
  614. {
  615. KIRQL oldIrql;
  616. NTSTATUS ntStatus;
  617. PDEVICE_EXTENSION deviceExtension;
  618. SSDbgPrint(3, ("HandleQueryStopDevice - begins\n"));
  619. //
  620. // initialize variables
  621. //
  622. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  623. //
  624. // If we can stop the device, we need to set the QueueState to
  625. // HoldRequests so further requests will be queued.
  626. //
  627. KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
  628. SET_NEW_PNP_STATE(deviceExtension, PendingStop);
  629. deviceExtension->QueueState = HoldRequests;
  630. KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
  631. //
  632. // wait for the existing ones to be finished.
  633. // first, decrement this operation
  634. //
  635. SSDbgPrint(3, ("HandleQueryStopDevice::"));
  636. SSIoDecrement(deviceExtension);
  637. KeWaitForSingleObject(&deviceExtension->StopEvent,
  638. Executive,
  639. KernelMode,
  640. FALSE,
  641. NULL);
  642. //
  643. // We must set Irp->IoStatus.Status to STATUS_SUCCESS before
  644. // passing it down.
  645. //
  646. Irp->IoStatus.Status = STATUS_SUCCESS;
  647. Irp->IoStatus.Information = 0;
  648. IoSkipCurrentIrpStackLocation(Irp);
  649. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
  650. SSDbgPrint(3, ("HandleQueryStopDevice - ends\n"));
  651. return ntStatus;
  652. }
  653. NTSTATUS
  654. HandleCancelStopDevice(
  655. IN PDEVICE_OBJECT DeviceObject,
  656. IN PIRP Irp
  657. )
  658. /*++
  659. Routine Description:
  660. This routine services Irp of minor type IRP_MN_CANCEL_STOP_DEVICE
  661. Arguments:
  662. DeviceObject - pointer to device object
  663. Irp - I/O request packet sent by the pnp manager.
  664. Return Value:
  665. NT value
  666. --*/
  667. {
  668. KIRQL oldIrql;
  669. KEVENT event;
  670. NTSTATUS ntStatus;
  671. PDEVICE_EXTENSION deviceExtension;
  672. SSDbgPrint(3, ("HandleCancelStopDevice - begins\n"));
  673. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  674. //
  675. // Send this IRP down and wait for it to come back.
  676. // Set the QueueState flag to AllowRequests,
  677. // and process all the previously queued up IRPs.
  678. //
  679. // First check to see whether you have received cancel-stop
  680. // without first receiving a query-stop. This could happen if someone
  681. // above us fails a query-stop and passes down the subsequent
  682. // cancel-stop.
  683. //
  684. if(PendingStop == deviceExtension->DeviceState) {
  685. KeInitializeEvent(&event, NotificationEvent, FALSE);
  686. IoCopyCurrentIrpStackLocationToNext(Irp);
  687. IoSetCompletionRoutine(Irp,
  688. (PIO_COMPLETION_ROUTINE)IrpCompletionRoutine,
  689. (PVOID)&event,
  690. TRUE,
  691. TRUE,
  692. TRUE);
  693. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
  694. if(ntStatus == STATUS_PENDING) {
  695. KeWaitForSingleObject(&event,
  696. Executive,
  697. KernelMode,
  698. FALSE,
  699. NULL);
  700. ntStatus = Irp->IoStatus.Status;
  701. }
  702. if(NT_SUCCESS(ntStatus)) {
  703. KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
  704. RESTORE_PREVIOUS_PNP_STATE(deviceExtension);
  705. deviceExtension->QueueState = AllowRequests;
  706. ASSERT(deviceExtension->DeviceState == Working);
  707. KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
  708. ProcessQueuedRequests(deviceExtension);
  709. }
  710. }
  711. else {
  712. // spurious Irp
  713. ntStatus = STATUS_SUCCESS;
  714. }
  715. SSDbgPrint(3, ("HandleCancelStopDevice - ends\n"));
  716. return ntStatus;
  717. }
  718. NTSTATUS
  719. HandleStopDevice(
  720. IN PDEVICE_OBJECT DeviceObject,
  721. IN PIRP Irp
  722. )
  723. /*++
  724. Routine Description:
  725. This routine services Irp of minor type IRP_MN_STOP_DEVICE
  726. Arguments:
  727. DeviceObject - pointer to device object
  728. Irp - I/O request packet sent by the pnp manager.
  729. Return Value:
  730. NT status value
  731. --*/
  732. {
  733. KIRQL oldIrql;
  734. NTSTATUS ntStatus;
  735. PDEVICE_EXTENSION deviceExtension;
  736. SSDbgPrint(3, ("HandleStopDevice - begins\n"));
  737. //
  738. // initialize variables
  739. //
  740. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  741. if(WinXpOrBetter == deviceExtension->WdmVersion) {
  742. if(deviceExtension->SSEnable) {
  743. //
  744. // Cancel the timer so that the DPCs are no longer fired.
  745. // Thus, we are making judicious usage of our resources.
  746. // we do not need DPCs because the device is stopping.
  747. // The timers are re-initialized while handling the start
  748. // device irp.
  749. //
  750. SSDbgPrint(3, ("Cancelling the timer...\n"));
  751. KeCancelTimer(&deviceExtension->Timer);
  752. //
  753. // after the device is stopped, it can be surprise removed.
  754. // we set this to 0, so that we do not attempt to cancel
  755. // the timer while handling surprise remove or remove irps.
  756. // When we get the start device request, this flag will be
  757. // reinitialized.
  758. //
  759. deviceExtension->SSEnable = 0;
  760. //
  761. // make sure that if a DPC was fired before we called cancel timer,
  762. // then the DPC and work-time have run to their completion
  763. //
  764. KeWaitForSingleObject(&deviceExtension->NoDpcWorkItemPendingEvent,
  765. Executive,
  766. KernelMode,
  767. FALSE,
  768. NULL);
  769. //
  770. // make sure that the selective suspend request has been completed.
  771. //
  772. KeWaitForSingleObject(&deviceExtension->NoIdleReqPendEvent,
  773. Executive,
  774. KernelMode,
  775. FALSE,
  776. NULL);
  777. }
  778. }
  779. //
  780. // after the stop Irp is sent to the lower driver object,
  781. // the driver must not send any more Irps down that touch
  782. // the device until another Start has occurred.
  783. //
  784. if(deviceExtension->WaitWakeEnable) {
  785. CancelWaitWake(deviceExtension);
  786. }
  787. KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
  788. SET_NEW_PNP_STATE(deviceExtension, Stopped);
  789. KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
  790. //
  791. // This is the right place to actually give up all the resources used
  792. // This might include calls to IoDisconnectInterrupt, MmUnmapIoSpace,
  793. // etc.
  794. //
  795. ReleaseMemory(DeviceObject);
  796. ntStatus = DeconfigureDevice(DeviceObject);
  797. Irp->IoStatus.Status = ntStatus;
  798. Irp->IoStatus.Information = 0;
  799. IoSkipCurrentIrpStackLocation(Irp);
  800. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
  801. SSDbgPrint(3, ("HandleStopDevice - ends\n"));
  802. return ntStatus;
  803. }
  804. NTSTATUS
  805. HandleQueryRemoveDevice(
  806. IN PDEVICE_OBJECT DeviceObject,
  807. IN PIRP Irp
  808. )
  809. /*++
  810. Routine Description:
  811. This routine services Irp of minor type IRP_MN_QUERY_REMOVE_DEVICE
  812. Arguments:
  813. DeviceObject - pointer to device object
  814. Irp - I/O request packet sent by the pnp manager.
  815. Return Value:
  816. NT status value
  817. --*/
  818. {
  819. KIRQL oldIrql;
  820. NTSTATUS ntStatus;
  821. PDEVICE_EXTENSION deviceExtension;
  822. SSDbgPrint(3, ("HandleQueryRemoveDevice - begins\n"));
  823. //
  824. // initialize variables
  825. //
  826. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  827. //
  828. // If we can allow removal of the device, we should set the QueueState
  829. // to HoldRequests so further requests will be queued. This is required
  830. // so that we can process queued up requests in cancel-remove just in
  831. // case somebody else in the stack fails the query-remove.
  832. //
  833. KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
  834. deviceExtension->QueueState = HoldRequests;
  835. SET_NEW_PNP_STATE(deviceExtension, PendingRemove);
  836. KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
  837. SSDbgPrint(3, ("HandleQueryRemoveDevice::"));
  838. SSIoDecrement(deviceExtension);
  839. //
  840. // wait for all the requests to be completed
  841. //
  842. KeWaitForSingleObject(&deviceExtension->StopEvent,
  843. Executive,
  844. KernelMode,
  845. FALSE,
  846. NULL);
  847. Irp->IoStatus.Status = STATUS_SUCCESS;
  848. Irp->IoStatus.Information = 0;
  849. IoSkipCurrentIrpStackLocation(Irp);
  850. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
  851. SSDbgPrint(3, ("HandleQueryRemoveDevice - ends\n"));
  852. return ntStatus;
  853. }
  854. NTSTATUS
  855. HandleCancelRemoveDevice(
  856. IN PDEVICE_OBJECT DeviceObject,
  857. IN PIRP Irp
  858. )
  859. /*++
  860. Routine Description:
  861. This routine services Irp of minor type IRP_MN_CANCEL_REMOVE_DEVICE
  862. Arguments:
  863. DeviceObject - pointer to device object
  864. Irp - I/O request packet sent by the pnp manager.
  865. Return Value:
  866. NT status value
  867. --*/
  868. {
  869. KIRQL oldIrql;
  870. KEVENT event;
  871. NTSTATUS ntStatus;
  872. PDEVICE_EXTENSION deviceExtension;
  873. SSDbgPrint(3, ("HandleCancelRemoveDevice - begins\n"));
  874. //
  875. // initialize variables
  876. //
  877. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  878. //
  879. // We need to reset the QueueState flag to ProcessRequest,
  880. // since the device resume its normal activities.
  881. //
  882. //
  883. // First check to see whether you have received cancel-remove
  884. // without first receiving a query-remove. This could happen if
  885. // someone above us fails a query-remove and passes down the
  886. // subsequent cancel-remove.
  887. //
  888. if(PendingRemove == deviceExtension->DeviceState) {
  889. KeInitializeEvent(&event, NotificationEvent, FALSE);
  890. IoCopyCurrentIrpStackLocationToNext(Irp);
  891. IoSetCompletionRoutine(Irp,
  892. (PIO_COMPLETION_ROUTINE)IrpCompletionRoutine,
  893. (PVOID)&event,
  894. TRUE,
  895. TRUE,
  896. TRUE);
  897. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
  898. if(ntStatus == STATUS_PENDING) {
  899. KeWaitForSingleObject(&event,
  900. Executive,
  901. KernelMode,
  902. FALSE,
  903. NULL);
  904. ntStatus = Irp->IoStatus.Status;
  905. }
  906. if(NT_SUCCESS(ntStatus)) {
  907. KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
  908. deviceExtension->QueueState = AllowRequests;
  909. RESTORE_PREVIOUS_PNP_STATE(deviceExtension);
  910. KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
  911. //
  912. // process the queued requests that arrive between
  913. // QUERY_REMOVE and CANCEL_REMOVE
  914. //
  915. ProcessQueuedRequests(deviceExtension);
  916. }
  917. }
  918. else {
  919. //
  920. // spurious cancel-remove
  921. //
  922. ntStatus = STATUS_SUCCESS;
  923. }
  924. SSDbgPrint(3, ("HandleCancelRemoveDevice - ends\n"));
  925. return ntStatus;
  926. }
  927. NTSTATUS
  928. HandleSurpriseRemoval(
  929. IN PDEVICE_OBJECT DeviceObject,
  930. IN PIRP Irp
  931. )
  932. /*++
  933. Routine Description:
  934. This routine services Irp of minor type IRP_MN_SURPRISE_REMOVAL
  935. Arguments:
  936. DeviceObject - pointer to device object
  937. Irp - I/O request packet sent by the pnp manager.
  938. Return Value:
  939. NT status value
  940. --*/
  941. {
  942. KIRQL oldIrql;
  943. NTSTATUS ntStatus;
  944. PDEVICE_EXTENSION deviceExtension;
  945. SSDbgPrint(3, ("HandleSurpriseRemoval - begins\n"));
  946. //
  947. // initialize variables
  948. //
  949. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  950. //
  951. // 1. fail pending requests
  952. // 2. return device and memory resources
  953. // 3. disable interfaces
  954. //
  955. if(deviceExtension->WaitWakeEnable) {
  956. CancelWaitWake(deviceExtension);
  957. }
  958. if(WinXpOrBetter == deviceExtension->WdmVersion) {
  959. if(deviceExtension->SSEnable) {
  960. //
  961. // Cancel the timer so that the DPCs are no longer fired.
  962. // we do not need DPCs because the device has been surprise
  963. // removed
  964. //
  965. SSDbgPrint(3, ("Cancelling the timer...\n"));
  966. KeCancelTimer(&deviceExtension->Timer);
  967. deviceExtension->SSEnable = 0;
  968. //
  969. // make sure that if a DPC was fired before we called cancel timer,
  970. // then the DPC and work-time have run to their completion
  971. //
  972. KeWaitForSingleObject(&deviceExtension->NoDpcWorkItemPendingEvent,
  973. Executive,
  974. KernelMode,
  975. FALSE,
  976. NULL);
  977. //
  978. // make sure that the selective suspend request has been completed.
  979. //
  980. KeWaitForSingleObject(&deviceExtension->NoIdleReqPendEvent,
  981. Executive,
  982. KernelMode,
  983. FALSE,
  984. NULL);
  985. }
  986. }
  987. KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
  988. deviceExtension->QueueState = FailRequests;
  989. SET_NEW_PNP_STATE(deviceExtension, SurpriseRemoved);
  990. KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
  991. ProcessQueuedRequests(deviceExtension);
  992. ntStatus = IoSetDeviceInterfaceState(&deviceExtension->InterfaceName,
  993. FALSE);
  994. if(!NT_SUCCESS(ntStatus)) {
  995. SSDbgPrint(1, ("IoSetDeviceInterfaceState::disable:failed\n"));
  996. }
  997. RtlFreeUnicodeString(&deviceExtension->InterfaceName);
  998. Irp->IoStatus.Status = STATUS_SUCCESS;
  999. Irp->IoStatus.Information = 0;
  1000. IoSkipCurrentIrpStackLocation(Irp);
  1001. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
  1002. SSDbgPrint(3, ("HandleSurpriseRemoval - ends\n"));
  1003. return ntStatus;
  1004. }
  1005. NTSTATUS
  1006. HandleRemoveDevice(
  1007. IN PDEVICE_OBJECT DeviceObject,
  1008. IN PIRP Irp
  1009. )
  1010. /*++
  1011. Routine Description:
  1012. This routine services Irp of minor type IRP_MN_REMOVE_DEVICE
  1013. Arguments:
  1014. DeviceObject - pointer to device object
  1015. Irp - I/O request packet sent by the pnp manager.
  1016. Return Value:
  1017. NT status value
  1018. --*/
  1019. {
  1020. KIRQL oldIrql;
  1021. KEVENT event;
  1022. ULONG requestCount;
  1023. NTSTATUS ntStatus;
  1024. PDEVICE_EXTENSION deviceExtension;
  1025. SSDbgPrint(3, ("HandleRemoveDevice - begins\n"));
  1026. //
  1027. // initialize variables
  1028. //
  1029. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  1030. //
  1031. // The Plug & Play system has dictated the removal of this device. We
  1032. // have no choice but to detach and delete the device object.
  1033. // (If we wanted to express an interest in preventing this removal,
  1034. // we should have failed the query remove IRP).
  1035. //
  1036. if(SurpriseRemoved != deviceExtension->DeviceState) {
  1037. //
  1038. // we are here after QUERY_REMOVE
  1039. //
  1040. KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
  1041. deviceExtension->QueueState = FailRequests;
  1042. KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
  1043. if(deviceExtension->WaitWakeEnable) {
  1044. CancelWaitWake(deviceExtension);
  1045. }
  1046. if(WinXpOrBetter == deviceExtension->WdmVersion) {
  1047. if(deviceExtension->SSEnable) {
  1048. //
  1049. // Cancel the timer so that the DPCs are no longer fired.
  1050. // we do not need DPCs because the device has been removed
  1051. //
  1052. SSDbgPrint(3, ("Cancelling the timer...\n"));
  1053. KeCancelTimer(&deviceExtension->Timer);
  1054. deviceExtension->SSEnable = 0;
  1055. //
  1056. // make sure that if a DPC was fired before we called cancel timer,
  1057. // then the DPC and work-time have run to their completion
  1058. //
  1059. KeWaitForSingleObject(&deviceExtension->NoDpcWorkItemPendingEvent,
  1060. Executive,
  1061. KernelMode,
  1062. FALSE,
  1063. NULL);
  1064. //
  1065. // make sure that the selective suspend request has been completed.
  1066. //
  1067. KeWaitForSingleObject(&deviceExtension->NoIdleReqPendEvent,
  1068. Executive,
  1069. KernelMode,
  1070. FALSE,
  1071. NULL);
  1072. }
  1073. }
  1074. ProcessQueuedRequests(deviceExtension);
  1075. ntStatus = IoSetDeviceInterfaceState(&deviceExtension->InterfaceName,
  1076. FALSE);
  1077. if(!NT_SUCCESS(ntStatus)) {
  1078. SSDbgPrint(1, ("IoSetDeviceInterfaceState::disable:failed\n"));
  1079. }
  1080. RtlFreeUnicodeString(&deviceExtension->InterfaceName);
  1081. }
  1082. KeAcquireSpinLock(&deviceExtension->DevStateLock, &oldIrql);
  1083. SET_NEW_PNP_STATE(deviceExtension, Removed);
  1084. KeReleaseSpinLock(&deviceExtension->DevStateLock, oldIrql);
  1085. SSWmiDeRegistration(deviceExtension);
  1086. //
  1087. // need 2 decrements
  1088. //
  1089. SSDbgPrint(3, ("HandleRemoveDevice::"));
  1090. requestCount = SSIoDecrement(deviceExtension);
  1091. ASSERT(requestCount > 0);
  1092. SSDbgPrint(3, ("HandleRemoveDevice::"));
  1093. requestCount = SSIoDecrement(deviceExtension);
  1094. KeWaitForSingleObject(&deviceExtension->RemoveEvent,
  1095. Executive,
  1096. KernelMode,
  1097. FALSE,
  1098. NULL);
  1099. ReleaseMemory(DeviceObject);
  1100. //
  1101. // We need to send the remove down the stack before we detach,
  1102. // but we don't need to wait for the completion of this operation
  1103. // (and to register a completion routine).
  1104. //
  1105. Irp->IoStatus.Status = STATUS_SUCCESS;
  1106. Irp->IoStatus.Information = 0;
  1107. IoSkipCurrentIrpStackLocation(Irp);
  1108. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
  1109. //
  1110. // Detach the FDO from the device stack
  1111. //
  1112. IoDetachDevice(deviceExtension->TopOfStackDeviceObject);
  1113. IoDeleteDevice(DeviceObject);
  1114. SSDbgPrint(3, ("HandleRemoveDevice - ends\n"));
  1115. return ntStatus;
  1116. }
  1117. NTSTATUS
  1118. HandleQueryCapabilities(
  1119. IN PDEVICE_OBJECT DeviceObject,
  1120. IN PIRP Irp
  1121. )
  1122. /*++
  1123. Routine Description:
  1124. This routine services Irp of minor type IRP_MN_QUERY_CAPABILITIES
  1125. Arguments:
  1126. DeviceObject - pointer to device object
  1127. Irp - I/O request packet sent by the pnp manager.
  1128. Return Value:
  1129. NT status value
  1130. --*/
  1131. {
  1132. ULONG i;
  1133. KEVENT event;
  1134. NTSTATUS ntStatus;
  1135. PDEVICE_EXTENSION deviceExtension;
  1136. PDEVICE_CAPABILITIES pdc;
  1137. PIO_STACK_LOCATION irpStack;
  1138. SSDbgPrint(3, ("HandleQueryCapabilities - begins\n"));
  1139. //
  1140. // initialize variables
  1141. //
  1142. irpStack = IoGetCurrentIrpStackLocation(Irp);
  1143. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  1144. pdc = irpStack->Parameters.DeviceCapabilities.Capabilities;
  1145. //
  1146. // We will provide here an example of an IRP that is processed
  1147. // both on its way down and on its way up: there might be no need for
  1148. // a function driver process this Irp (the bus driver will do that).
  1149. // The driver will wait for the lower drivers (the bus driver among
  1150. // them) to process this IRP, then it processes it again.
  1151. //
  1152. if(pdc->Version < 1 || pdc->Size < sizeof(DEVICE_CAPABILITIES)) {
  1153. SSDbgPrint(1, ("HandleQueryCapabilities::request failed\n"));
  1154. ntStatus = STATUS_UNSUCCESSFUL;
  1155. return ntStatus;
  1156. }
  1157. //
  1158. // Set some values in deviceCapabilities here...
  1159. //
  1160. //.............................................
  1161. //
  1162. //
  1163. // Prepare to pass the IRP down
  1164. //
  1165. KeInitializeEvent(&event, NotificationEvent, FALSE);
  1166. IoCopyCurrentIrpStackLocationToNext(Irp);
  1167. IoSetCompletionRoutine(Irp,
  1168. (PIO_COMPLETION_ROUTINE)IrpCompletionRoutine,
  1169. (PVOID)&event,
  1170. TRUE,
  1171. TRUE,
  1172. TRUE);
  1173. ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
  1174. if(ntStatus == STATUS_PENDING) {
  1175. KeWaitForSingleObject(&event,
  1176. Executive,
  1177. KernelMode,
  1178. FALSE,
  1179. NULL);
  1180. ntStatus = Irp->IoStatus.Status;
  1181. }
  1182. //
  1183. // initialize PowerDownLevel to disabled
  1184. //
  1185. deviceExtension->PowerDownLevel = PowerDeviceUnspecified;
  1186. //
  1187. // Lower drivers have finished their operation, so now
  1188. // we can finish ours.
  1189. //
  1190. if(NT_SUCCESS(ntStatus)) {
  1191. deviceExtension->DeviceCapabilities = *pdc;
  1192. for(i = PowerSystemSleeping1; i <= PowerSystemSleeping3; i++) {
  1193. if(deviceExtension->DeviceCapabilities.DeviceState[i] <
  1194. PowerDeviceD3) {
  1195. deviceExtension->PowerDownLevel =
  1196. deviceExtension->DeviceCapabilities.DeviceState[i];
  1197. }
  1198. }
  1199. //
  1200. // since its safe to surprise-remove this device, we shall
  1201. // set the SurpriseRemoveOK flag to supress any dialog to
  1202. // user.
  1203. //
  1204. pdc->SurpriseRemovalOK = 1;
  1205. }
  1206. if(deviceExtension->PowerDownLevel == PowerDeviceUnspecified ||
  1207. deviceExtension->PowerDownLevel <= PowerDeviceD0) {
  1208. deviceExtension->PowerDownLevel = PowerDeviceD2;
  1209. }
  1210. SSDbgPrint(3, ("HandleQueryCapabilities - ends\n"));
  1211. return ntStatus;
  1212. }
  1213. VOID
  1214. DpcRoutine(
  1215. IN PKDPC Dpc,
  1216. IN PVOID DeferredContext,
  1217. IN PVOID SystemArgument1,
  1218. IN PVOID SystemArgument2
  1219. )
  1220. /*++
  1221. Routine Description:
  1222. DPC routine triggered by the timer to check the idle state
  1223. of the device and submit an idle request for the device.
  1224. Arguments:
  1225. DeferredContext - context for the dpc routine.
  1226. DeviceObject in our case.
  1227. Return Value:
  1228. None
  1229. --*/
  1230. {
  1231. NTSTATUS ntStatus;
  1232. PDEVICE_OBJECT deviceObject;
  1233. PDEVICE_EXTENSION deviceExtension;
  1234. PIO_WORKITEM item;
  1235. deviceObject = (PDEVICE_OBJECT)DeferredContext;
  1236. deviceExtension = (PDEVICE_EXTENSION)deviceObject->DeviceExtension;
  1237. SSDbgPrint(3, ("DpcRoutine - begins\n"));
  1238. //
  1239. // Clear this event since a DPC has been fired!
  1240. //
  1241. KeClearEvent(&deviceExtension->NoDpcWorkItemPendingEvent);
  1242. if(CanDeviceSuspend(deviceExtension)) {
  1243. SSDbgPrint(3, ("Device is Idle\n"));
  1244. item = IoAllocateWorkItem(deviceObject);
  1245. if(item) {
  1246. IoQueueWorkItem(item,
  1247. IdleRequestWorkerRoutine,
  1248. DelayedWorkQueue,
  1249. item);
  1250. ntStatus = STATUS_PENDING;
  1251. }
  1252. else {
  1253. SSDbgPrint(3, ("Cannot alloc memory for work item\n"));
  1254. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  1255. //
  1256. // signal the NoDpcWorkItemPendingEvent.
  1257. //
  1258. KeSetEvent(&deviceExtension->NoDpcWorkItemPendingEvent,
  1259. IO_NO_INCREMENT,
  1260. FALSE);
  1261. }
  1262. }
  1263. else {
  1264. SSDbgPrint(3, ("Idle event not signaled\n"));
  1265. //
  1266. // signal the NoDpcWorkItemPendingEvent.
  1267. //
  1268. KeSetEvent(&deviceExtension->NoDpcWorkItemPendingEvent,
  1269. IO_NO_INCREMENT,
  1270. FALSE);
  1271. }
  1272. SSDbgPrint(3, ("DpcRoutine - ends\n"));
  1273. }
  1274. VOID
  1275. IdleRequestWorkerRoutine(
  1276. IN PDEVICE_OBJECT DeviceObject,
  1277. IN PVOID Context
  1278. )
  1279. /*++
  1280. Routine Description:
  1281. This is the work item fired from the DPC.
  1282. This workitem checks the idle state of the device
  1283. and submits an idle request.
  1284. Arguments:
  1285. DeviceObject - pointer to device object
  1286. Context - context for the work item.
  1287. Return Value:
  1288. None
  1289. --*/
  1290. {
  1291. PIRP irp;
  1292. NTSTATUS ntStatus;
  1293. PDEVICE_EXTENSION deviceExtension;
  1294. PIO_WORKITEM workItem;
  1295. SSDbgPrint(3, ("IdleRequestWorkerRoutine - begins\n"));
  1296. //
  1297. // initialize variables
  1298. //
  1299. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  1300. workItem = (PIO_WORKITEM) Context;
  1301. if(CanDeviceSuspend(deviceExtension)) {
  1302. SSDbgPrint(3, ("Device is idle\n"));
  1303. ntStatus = SubmitIdleRequestIrp(deviceExtension);
  1304. if(!NT_SUCCESS(ntStatus)) {
  1305. SSDbgPrint(1, ("SubmitIdleRequestIrp failed\n"));
  1306. }
  1307. }
  1308. else {
  1309. SSDbgPrint(3, ("Device is not idle\n"));
  1310. }
  1311. IoFreeWorkItem(workItem);
  1312. //
  1313. // signal the NoDpcWorkItemPendingEvent.
  1314. //
  1315. KeSetEvent(&deviceExtension->NoDpcWorkItemPendingEvent,
  1316. IO_NO_INCREMENT,
  1317. FALSE);
  1318. SSDbgPrint(3, ("IdleRequestsWorkerRoutine - ends\n"));
  1319. }
  1320. VOID
  1321. ProcessQueuedRequests(
  1322. IN OUT PDEVICE_EXTENSION DeviceExtension
  1323. )
  1324. /*++
  1325. Routine Description:
  1326. Remove and process the entries in the queue. If this routine is called
  1327. when processing IRP_MN_CANCEL_STOP_DEVICE, IRP_MN_CANCEL_REMOVE_DEVICE
  1328. or IRP_MN_START_DEVICE, the requests are passed to the next lower driver.
  1329. If the routine is called when IRP_MN_REMOVE_DEVICE is received, the IRPs
  1330. are complete with STATUS_DELETE_PENDING
  1331. Arguments:
  1332. DeviceExtension - pointer to device extension
  1333. Return Value:
  1334. None
  1335. --*/
  1336. {
  1337. KIRQL oldIrql;
  1338. PIRP nextIrp,
  1339. cancelledIrp;
  1340. PVOID cancelRoutine;
  1341. LIST_ENTRY cancelledIrpList;
  1342. PLIST_ENTRY listEntry;
  1343. SSDbgPrint(3, ("ProcessQueuedRequests - begins\n"));
  1344. //
  1345. // initialize variables
  1346. //
  1347. cancelRoutine = NULL;
  1348. InitializeListHead(&cancelledIrpList);
  1349. //
  1350. // 1. dequeue the entries in the queue
  1351. // 2. reset the cancel routine
  1352. // 3. process them
  1353. // 3a. if the device is active, send them down
  1354. // 3b. else complete with STATUS_DELETE_PENDING
  1355. //
  1356. while(1) {
  1357. KeAcquireSpinLock(&DeviceExtension->QueueLock, &oldIrql);
  1358. if(IsListEmpty(&DeviceExtension->NewRequestsQueue)) {
  1359. KeReleaseSpinLock(&DeviceExtension->QueueLock, oldIrql);
  1360. break;
  1361. }
  1362. //
  1363. // Remove a request from the queue
  1364. //
  1365. listEntry = RemoveHeadList(&DeviceExtension->NewRequestsQueue);
  1366. nextIrp = CONTAINING_RECORD(listEntry, IRP, Tail.Overlay.ListEntry);
  1367. //
  1368. // set the cancel routine to NULL
  1369. //
  1370. cancelRoutine = IoSetCancelRoutine(nextIrp, NULL);
  1371. //
  1372. // check if its already cancelled
  1373. //
  1374. if(nextIrp->Cancel) {
  1375. if(cancelRoutine) {
  1376. //
  1377. // the cancel routine for this IRP hasnt been called yet
  1378. // so queue the IRP in the cancelledIrp list and complete
  1379. // after releasing the lock
  1380. //
  1381. InsertTailList(&cancelledIrpList, listEntry);
  1382. }
  1383. else {
  1384. //
  1385. // the cancel routine has run
  1386. // it must be waiting to hold the queue lock
  1387. // so initialize the IRPs listEntry
  1388. //
  1389. InitializeListHead(listEntry);
  1390. }
  1391. KeReleaseSpinLock(&DeviceExtension->QueueLock, oldIrql);
  1392. }
  1393. else {
  1394. KeReleaseSpinLock(&DeviceExtension->QueueLock, oldIrql);
  1395. if(FailRequests == DeviceExtension->QueueState) {
  1396. nextIrp->IoStatus.Information = 0;
  1397. nextIrp->IoStatus.Status = STATUS_DELETE_PENDING;
  1398. IoCompleteRequest(nextIrp, IO_NO_INCREMENT);
  1399. }
  1400. else {
  1401. PIO_STACK_LOCATION irpStack;
  1402. SSDbgPrint(3, ("ProcessQueuedRequests::"));
  1403. SSIoIncrement(DeviceExtension);
  1404. IoSkipCurrentIrpStackLocation(nextIrp);
  1405. IoCallDriver(DeviceExtension->TopOfStackDeviceObject, nextIrp);
  1406. SSDbgPrint(3, ("ProcessQueuedRequests::"));
  1407. SSIoDecrement(DeviceExtension);
  1408. }
  1409. }
  1410. } // while loop
  1411. //
  1412. // walk through the cancelledIrp list and cancel them
  1413. //
  1414. while(!IsListEmpty(&cancelledIrpList)) {
  1415. PLIST_ENTRY cancelEntry = RemoveHeadList(&cancelledIrpList);
  1416. cancelledIrp = CONTAINING_RECORD(cancelEntry,
  1417. IRP,
  1418. Tail.Overlay.ListEntry);
  1419. cancelledIrp->IoStatus.Status = STATUS_CANCELLED;
  1420. cancelledIrp->IoStatus.Information = 0;
  1421. IoCompleteRequest(cancelledIrp, IO_NO_INCREMENT);
  1422. }
  1423. SSDbgPrint(3, ("ProcessQueuedRequests - ends\n"));
  1424. return;
  1425. }
  1426. NTSTATUS
  1427. SS_DispatchClean(
  1428. IN PDEVICE_OBJECT DeviceObject,
  1429. IN PIRP Irp
  1430. )
  1431. /*++
  1432. Routine Description:
  1433. Dispatch routine for IRP_MJ_CLEANUP
  1434. Arguments:
  1435. DeviceObject - pointer to device object
  1436. Irp - I/O request packet sent by the pnp manager
  1437. Return Value:
  1438. NT status value
  1439. --*/
  1440. {
  1441. PDEVICE_EXTENSION deviceExtension;
  1442. KIRQL oldIrql;
  1443. LIST_ENTRY cleanupList;
  1444. PLIST_ENTRY thisEntry,
  1445. nextEntry,
  1446. listHead;
  1447. PIRP pendingIrp;
  1448. PIO_STACK_LOCATION pendingIrpStack,
  1449. irpStack;
  1450. NTSTATUS ntStatus;
  1451. //
  1452. // initialize variables
  1453. //
  1454. deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
  1455. irpStack = IoGetCurrentIrpStackLocation(Irp);
  1456. InitializeListHead(&cleanupList);
  1457. SSDbgPrint(3, ("SS_DispatchClean::"));
  1458. SSIoIncrement(deviceExtension);
  1459. //
  1460. // acquire queue lock
  1461. //
  1462. KeAcquireSpinLock(&deviceExtension->QueueLock, &oldIrql);
  1463. //
  1464. // remove all Irp's that belong to input Irp's fileobject
  1465. //
  1466. listHead = &deviceExtension->NewRequestsQueue;
  1467. for(thisEntry = listHead->Flink, nextEntry = thisEntry->Flink;
  1468. thisEntry != listHead;
  1469. thisEntry = nextEntry, nextEntry = thisEntry->Flink) {
  1470. pendingIrp = CONTAINING_RECORD(thisEntry, IRP, Tail.Overlay.ListEntry);
  1471. pendingIrpStack = IoGetCurrentIrpStackLocation(pendingIrp);
  1472. if(irpStack->FileObject == pendingIrpStack->FileObject) {
  1473. RemoveEntryList(thisEntry);
  1474. //
  1475. // set the cancel routine to NULL
  1476. //
  1477. if(NULL == IoSetCancelRoutine(pendingIrp, NULL)) {
  1478. InitializeListHead(thisEntry);
  1479. }
  1480. else {
  1481. InsertTailList(&cleanupList, thisEntry);
  1482. }
  1483. }
  1484. }
  1485. //
  1486. // Release the spin lock
  1487. //
  1488. KeReleaseSpinLock(&deviceExtension->QueueLock, oldIrql);
  1489. //
  1490. // walk thru the cleanup list and cancel all the Irps
  1491. //
  1492. while(!IsListEmpty(&cleanupList)) {
  1493. //
  1494. // complete the Irp
  1495. //
  1496. thisEntry = RemoveHeadList(&cleanupList);
  1497. pendingIrp = CONTAINING_RECORD(thisEntry, IRP, Tail.Overlay.ListEntry);
  1498. pendingIrp->IoStatus.Information = 0;
  1499. pendingIrp->IoStatus.Status = STATUS_CANCELLED;
  1500. IoCompleteRequest(pendingIrp, IO_NO_INCREMENT);
  1501. }
  1502. Irp->IoStatus.Information = 0;
  1503. Irp->IoStatus.Status = STATUS_SUCCESS;
  1504. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  1505. SSDbgPrint(3, ("SS_DispatchClean::"));
  1506. SSIoDecrement(deviceExtension);
  1507. return STATUS_SUCCESS;
  1508. }
  1509. NTSTATUS
  1510. SS_GetRegistryDword(
  1511. IN PWCHAR RegPath,
  1512. IN PWCHAR ValueName,
  1513. IN OUT PULONG Value
  1514. )
  1515. /*++
  1516. Routine Description:
  1517. This routine reads the specified reqistry value.
  1518. Arguments:
  1519. RegPath - registry path
  1520. ValueName - property to be fetched from the registry
  1521. Value - corresponding value read from the registry.
  1522. Return Value:
  1523. NT status value
  1524. --*/
  1525. {
  1526. ULONG defaultData;
  1527. WCHAR buffer[MAXIMUM_FILENAME_LENGTH];
  1528. NTSTATUS ntStatus;
  1529. UNICODE_STRING regPath;
  1530. RTL_QUERY_REGISTRY_TABLE paramTable[2];
  1531. SSDbgPrint(3, ("SS_GetRegistryDword - begins\n"));
  1532. regPath.Length = 0;
  1533. regPath.MaximumLength = MAXIMUM_FILENAME_LENGTH * sizeof(WCHAR);
  1534. regPath.Buffer = buffer;
  1535. RtlZeroMemory(regPath.Buffer, regPath.MaximumLength);
  1536. RtlMoveMemory(regPath.Buffer,
  1537. RegPath,
  1538. wcslen(RegPath) * sizeof(WCHAR));
  1539. RtlZeroMemory(paramTable, sizeof(paramTable));
  1540. paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
  1541. paramTable[0].Name = ValueName;
  1542. paramTable[0].EntryContext = Value;
  1543. paramTable[0].DefaultType = REG_DWORD;
  1544. paramTable[0].DefaultData = &defaultData;
  1545. paramTable[0].DefaultLength = sizeof(ULONG);
  1546. ntStatus = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE |
  1547. RTL_REGISTRY_OPTIONAL,
  1548. regPath.Buffer,
  1549. paramTable,
  1550. NULL,
  1551. NULL);
  1552. if(NT_SUCCESS(ntStatus)) {
  1553. SSDbgPrint(3, ("success Value = %X\n", *Value));
  1554. return STATUS_SUCCESS;
  1555. }
  1556. else {
  1557. *Value = 0;
  1558. return STATUS_UNSUCCESSFUL;
  1559. }
  1560. }
  1561. BOOLEAN
  1562. CanDeviceSuspend(
  1563. IN PDEVICE_EXTENSION DeviceExtension
  1564. )
  1565. /*++
  1566. Routine Description:
  1567. This is the routine where we check if the device
  1568. can selectively suspend.
  1569. Arguments:
  1570. DeviceExtension - pointer to device extension
  1571. Return Value:
  1572. TRUE - if the device can suspend
  1573. FALSE - otherwise.
  1574. --*/
  1575. {
  1576. SSDbgPrint(3, ("CanDeviceSuspend\n"));
  1577. if((DeviceExtension->OpenHandleCount == 0) &&
  1578. (DeviceExtension->OutStandingIO == 1)) {
  1579. return TRUE;
  1580. }
  1581. else {
  1582. return FALSE;
  1583. }
  1584. }
  1585. NTSTATUS
  1586. IrpCompletionRoutine(
  1587. IN PDEVICE_OBJECT DeviceObject,
  1588. IN PIRP Irp,
  1589. IN PVOID Context
  1590. )
  1591. /*++
  1592. Routine Description:
  1593. This routine is a completion routine.
  1594. In this routine we set an event.
  1595. Since the completion routine returns
  1596. STATUS_MORE_PROCESSING_REQUIRED, the Irps,
  1597. which set this routine as the completion routine,
  1598. should be marked pending.
  1599. Arguments:
  1600. DeviceObject - pointer to device object
  1601. Irp - I/O request packet
  1602. Context -
  1603. Return Value:
  1604. NT status value
  1605. --*/
  1606. {
  1607. PKEVENT event = Context;
  1608. KeSetEvent(event, 0, FALSE);
  1609. return STATUS_MORE_PROCESSING_REQUIRED;
  1610. }
  1611. LONG
  1612. SSIoIncrement(
  1613. IN OUT PDEVICE_EXTENSION DeviceExtension
  1614. )
  1615. /*++
  1616. Routine Description:
  1617. This routine bumps up the I/O count.
  1618. This routine is typically invoked when any of the
  1619. dispatch routines handle new irps for the driver.
  1620. Arguments:
  1621. DeviceExtension - pointer to device extension
  1622. Return Value:
  1623. new value
  1624. --*/
  1625. {
  1626. LONG result = 0;
  1627. KIRQL oldIrql;
  1628. KeAcquireSpinLock(&DeviceExtension->IOCountLock, &oldIrql);
  1629. result = InterlockedIncrement(&DeviceExtension->OutStandingIO);
  1630. //
  1631. // when OutStandingIO bumps from 1 to 2, clear the StopEvent
  1632. //
  1633. if(result == 2) {
  1634. KeClearEvent(&DeviceExtension->StopEvent);
  1635. }
  1636. KeReleaseSpinLock(&DeviceExtension->IOCountLock, oldIrql);
  1637. SSDbgPrint(3, ("SSIoIncrement::%d\n", result));
  1638. return result;
  1639. }
  1640. LONG
  1641. SSIoDecrement(
  1642. IN OUT PDEVICE_EXTENSION DeviceExtension
  1643. )
  1644. /*++
  1645. Routine Description:
  1646. This routine decrements the outstanding I/O count
  1647. This is typically invoked after the dispatch routine
  1648. has finished processing the irp.
  1649. Arguments:
  1650. DeviceExtension - pointer to device extension
  1651. Return Value:
  1652. new value
  1653. --*/
  1654. {
  1655. LONG result = 0;
  1656. KIRQL oldIrql;
  1657. KeAcquireSpinLock(&DeviceExtension->IOCountLock, &oldIrql);
  1658. result = InterlockedDecrement(&DeviceExtension->OutStandingIO);
  1659. if(result == 1) {
  1660. KeSetEvent(&DeviceExtension->StopEvent, IO_NO_INCREMENT, FALSE);
  1661. }
  1662. if(result == 0) {
  1663. ASSERT(Removed == DeviceExtension->DeviceState);
  1664. KeSetEvent(&DeviceExtension->RemoveEvent, IO_NO_INCREMENT, FALSE);
  1665. }
  1666. KeReleaseSpinLock(&DeviceExtension->IOCountLock, oldIrql);
  1667. SSDbgPrint(3, ("SSIoDecrement::%d\n", result));
  1668. return result;
  1669. }
  1670. NTSTATUS
  1671. CanStopDevice(
  1672. IN PDEVICE_OBJECT DeviceObject,
  1673. IN PIRP Irp
  1674. )
  1675. /*++
  1676. Routine Description:
  1677. This routine determines whether the device can be safely stopped. In our
  1678. particular case, we'll assume we can always stop the device.
  1679. A device might fail the request if it doesn't have a queue for the
  1680. requests it might come or if it was notified that it is in the paging
  1681. path.
  1682. Arguments:
  1683. DeviceObject - pointer to the device object.
  1684. Irp - pointer to the current IRP.
  1685. Return Value:
  1686. STATUS_SUCCESS if the device can be safely stopped, an appropriate
  1687. NT Status if not.
  1688. --*/
  1689. {
  1690. //
  1691. // We assume we can stop the device
  1692. //
  1693. UNREFERENCED_PARAMETER(DeviceObject);
  1694. UNREFERENCED_PARAMETER(Irp);
  1695. return STATUS_SUCCESS;
  1696. }
  1697. NTSTATUS
  1698. CanRemoveDevice(
  1699. IN PDEVICE_OBJECT DeviceObject,
  1700. IN PIRP Irp
  1701. )
  1702. /*++
  1703. Routine Description:
  1704. This routine determines whether the device can be safely removed. In our
  1705. particular case, we'll assume we can always remove the device.
  1706. A device shouldn't be removed if, for example, it has open handles or
  1707. removing the device could result in losing data (plus the reasons
  1708. mentioned at CanStopDevice). The PnP manager on Windows 2000 fails
  1709. on its own any attempt to remove, if there any open handles to the device.
  1710. However on Win9x, the driver must keep count of open handles and fail
  1711. query_remove if there are any open handles.
  1712. Arguments:
  1713. DeviceObject - pointer to the device object.
  1714. Irp - pointer to the current IRP.
  1715. Return Value:
  1716. STATUS_SUCCESS if the device can be safely removed, an appropriate
  1717. NT Status if not.
  1718. --*/
  1719. {
  1720. //
  1721. // We assume we can remove the device
  1722. //
  1723. UNREFERENCED_PARAMETER(DeviceObject);
  1724. UNREFERENCED_PARAMETER(Irp);
  1725. return STATUS_SUCCESS;
  1726. }
  1727. NTSTATUS
  1728. ReleaseMemory(
  1729. IN PDEVICE_OBJECT DeviceObject
  1730. )
  1731. /*++
  1732. Routine Description:
  1733. This routine returns all the memory allocations acquired during
  1734. device startup.
  1735. Arguments:
  1736. DeviceObject - pointer to the device object.
  1737. Return Value:
  1738. STATUS_SUCCESS if the device can be safely removed, an appropriate
  1739. NT Status if not.
  1740. --*/
  1741. {
  1742. //
  1743. // Disconnect from the interrupt and unmap any I/O ports
  1744. //
  1745. UNREFERENCED_PARAMETER(DeviceObject);
  1746. return STATUS_SUCCESS;
  1747. }
  1748. PCHAR
  1749. PnPMinorFunctionString (
  1750. UCHAR MinorFunction
  1751. )
  1752. /*++
  1753. Routine Description:
  1754. Arguments:
  1755. Return Value:
  1756. --*/
  1757. {
  1758. switch (MinorFunction) {
  1759. case IRP_MN_START_DEVICE:
  1760. return "IRP_MN_START_DEVICE\n";
  1761. case IRP_MN_QUERY_REMOVE_DEVICE:
  1762. return "IRP_MN_QUERY_REMOVE_DEVICE\n";
  1763. case IRP_MN_REMOVE_DEVICE:
  1764. return "IRP_MN_REMOVE_DEVICE\n";
  1765. case IRP_MN_CANCEL_REMOVE_DEVICE:
  1766. return "IRP_MN_CANCEL_REMOVE_DEVICE\n";
  1767. case IRP_MN_STOP_DEVICE:
  1768. return "IRP_MN_STOP_DEVICE\n";
  1769. case IRP_MN_QUERY_STOP_DEVICE:
  1770. return "IRP_MN_QUERY_STOP_DEVICE\n";
  1771. case IRP_MN_CANCEL_STOP_DEVICE:
  1772. return "IRP_MN_CANCEL_STOP_DEVICE\n";
  1773. case IRP_MN_QUERY_DEVICE_RELATIONS:
  1774. return "IRP_MN_QUERY_DEVICE_RELATIONS\n";
  1775. case IRP_MN_QUERY_INTERFACE:
  1776. return "IRP_MN_QUERY_INTERFACE\n";
  1777. case IRP_MN_QUERY_CAPABILITIES:
  1778. return "IRP_MN_QUERY_CAPABILITIES\n";
  1779. case IRP_MN_QUERY_RESOURCES:
  1780. return "IRP_MN_QUERY_RESOURCES\n";
  1781. case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
  1782. return "IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n";
  1783. case IRP_MN_QUERY_DEVICE_TEXT:
  1784. return "IRP_MN_QUERY_DEVICE_TEXT\n";
  1785. case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
  1786. return "IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n";
  1787. case IRP_MN_READ_CONFIG:
  1788. return "IRP_MN_READ_CONFIG\n";
  1789. case IRP_MN_WRITE_CONFIG:
  1790. return "IRP_MN_WRITE_CONFIG\n";
  1791. case IRP_MN_EJECT:
  1792. return "IRP_MN_EJECT\n";
  1793. case IRP_MN_SET_LOCK:
  1794. return "IRP_MN_SET_LOCK\n";
  1795. case IRP_MN_QUERY_ID:
  1796. return "IRP_MN_QUERY_ID\n";
  1797. case IRP_MN_QUERY_PNP_DEVICE_STATE:
  1798. return "IRP_MN_QUERY_PNP_DEVICE_STATE\n";
  1799. case IRP_MN_QUERY_BUS_INFORMATION:
  1800. return "IRP_MN_QUERY_BUS_INFORMATION\n";
  1801. case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  1802. return "IRP_MN_DEVICE_USAGE_NOTIFICATION\n";
  1803. case IRP_MN_SURPRISE_REMOVAL:
  1804. return "IRP_MN_SURPRISE_REMOVAL\n";
  1805. default:
  1806. return "IRP_MN_?????\n";
  1807. }
  1808. }