User mode WM_DEVICECHANGE doesn't work after calling the ReadFile

Hi,

I have a driver on top of the hidclass enumerated device. The driver creates a raw pdo for the user mode application to read report. The application registers the device change notification for the interface that the raw pdo exposes. When the driver gets the Read request from the application, it formats the request for read with the remote IO target of the hid device and calls the WdfRequestSend to that remote IO target. Everything works fine except the device change notification. Without calling the ReadFile, unplugging the device, the application gets notified with the WM_DEVICECHANGE with DBT_DEVICEREMOVECOMPLETE. However, after calling the ReadFile which means that the driver starts to forward the read request to the remote IO target of the hid device, the application can’t receive that notification anymore. The device node of the hid device still exists on the device manager with the !. It seems that the device node can’t be removed. Can anyone know why? How can I fix it
?

0: kd> !wdfkd.wdflogdump logi_generic_hid_filter
Trace searchpath is:

Trace format prefix is: %7!u!: %!FUNC! -
Trying to extract TMF information from - c:\symstore\Wdf01000.pdb\11E877268FAE7196F0AA5A416B1A36E01\Wdf01000.pdb
Gather log: Please wait, this may take a moment (reading 4024 bytes).
% read so far … 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
There are 73 log entries
— start of log —
27: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering PnP State WdfDevStatePnpHardwareAvailable from WdfDevStatePnpInitStarting
28: FxPkgPnp::NotPowerPolicyOwnerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering not power policy owner state WdfDevStatePwrPolStarting from WdfDevStatePwrPolObjectCreated
29: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerStartingCheckDeviceType from WdfDevStatePowerObjectCreated
30: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerD0Starting from WdfDevStatePowerStartingCheckDeviceType
31: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerD0StartingConnectInterrupt from WdfDevStatePowerD0Starting
32: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerD0StartingDmaEnable from WdfDevStatePowerD0StartingConnectInterrupt
33: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerD0StartingStartSelfManagedIo from WdfDevStatePowerD0StartingDmaEnable
34: FxPkgIo::ResumeProcessingForPower - Power resume all queues of WDFDEVICE 0x00006470054AC988
35: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerDecideD0State from WdfDevStatePowerD0StartingStartSelfManagedIo
36: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerD0 from WdfDevStatePowerDecideD0State
37: FxPkgPnp::NotPowerPolicyOwnerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering not power policy owner state WdfDevStatePwrPolStarted from WdfDevStatePwrPolStarting
38: FxPkgPnp::NotPowerPolicyOwnerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering not power policy owner state WdfDevStatePwrPolStartingSucceeded from WdfDevStatePwrPolStarted
39: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering PnP State WdfDevStatePnpEnableInterfaces from WdfDevStatePnpHardwareAvailable
40: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering PnP State WdfDevStatePnpStarted from WdfDevStatePnpEnableInterfaces
41: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000014(IRP_MN_QUERY_PNP_DEVICE_STATE) IRP 0xFFFF9B8FEDEB78C0
42: FxPkgFdo::HandleQueryPnpDeviceStateCompletion - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 returning PNP_DEVICE_STATE 0x0 IRP 0xFFFF9B8FEDEB78C0
43: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type BusRelations IRP 0xFFFF9B8FEDF6F010
44: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type BusRelations IRP 0xFFFF9B8FEDEC2010
45: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FEDE6A630
46: FxIoTargetRemote::OpenTargetHandle - ZwCreateFile for WDFIOTARGET 000064700823F908 returned status STATUS_SUCCESS, info 0x0
47: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FEDF06010
48: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FEDEB78C0
49: FxIoTargetRemote::ClearTargetPointers - WDFIOTARGET 000064700823F908 cleared pointers FFFFC68088D8D6F0 state WdfIoTargetClosed, open state 1, pdo FFFF9B8FEDF04650, fileobj FFFF9B8FEDE9D540, handle FFFFFFFF80001978
50: FxIoTargetRemote::Close - WDFIOTARGET 000064700823F908 derefing PDO FFFF9B8FEDF04650 on close
51: FxIoTargetRemote::Close - WDFIOTARGET 000064700823F908 derefing FileObj FFFF9B8FEDE9D540 on close
52: FxIoTargetRemote::Close - WDFIOTARGET 000064700823F908 closing handle FFFFFFFF80001978 on close
53: FxIoTargetRemote::ClearTargetPointers - WDFIOTARGET 000064700823F908 cleared pointers FFFFC68088D8D5F0 state WdfIoTargetDeleted, open state 1, pdo 0000000000000000, fileobj 0000000000000000, handle 0000000000000000
54: FxIoTarget::WaitForDisposeEvent - WDFIOTARGET 000064700823F908, Waiting on Dispose event FFFFC68088D8D560
55: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpInit from WdfDevStatePnpObjectCreated
56: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type BusRelations IRP 0xFFFF9B8FEDF2EA60
57: FxChildList::ProcessBusRelations - PDO created successfully, WDFDEVICE 00006470082F5918 !devobj FFFF9B8FFB48B240
58: FxPkgPnp::HandleQueryBusRelations - WDFDEVICE 00006470054AC988 returning 1 devices in relations FFFFD680735269A0
59: FxPkgPdo::_PnpQueryId - WDFDEVICE 00006470082F5918 does not have a string for PnP query IdType BusQueryContainerID, 0xc00000bb(STATUS_NOT_SUPPORTED)
60: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000000(IRP_MN_START_DEVICE) IRP 0xFFFF9B8FEDEE5010
61: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpInitStarting from WdfDevStatePnpInit
62: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpHardwareAvailable from WdfDevStatePnpInitStarting
63: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStarting from WdfDevStatePwrPolObjectCreated
64: FxPowerIdleMachine::ProcessEventLocked - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power idle state FxIdleStarted from FxIdleStopped
65: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerStartingCheckDeviceType from WdfDevStatePowerObjectCreated
66: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerStartingChild from WdfDevStatePowerStartingCheckDeviceType
67: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerD0Starting from WdfDevStatePowerStartingChild
68: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerD0StartingConnectInterrupt from WdfDevStatePowerD0Starting
69: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerD0StartingDmaEnable from WdfDevStatePowerD0StartingConnectInterrupt
70: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerD0StartingStartSelfManagedIo from WdfDevStatePowerD0StartingDmaEnable
71: FxPkgIo::ResumeProcessingForPower - Power resume all queues of WDFDEVICE 0x00006470082F5918
72: FxPowerIdleMachine::ProcessEventLocked - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power idle state FxIdleStartedPowerUp from FxIdleStarted
73: FxPowerIdleMachine::ProcessEventLocked - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power idle state FxIdleDisabled from FxIdleStartedPowerUp
74: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerDecideD0State from WdfDevStatePowerD0StartingStartSelfManagedIo
75: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerD0BusWakeOwner from WdfDevStatePowerDecideD0State
76: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStartingPoweredUp from WdfDevStatePwrPolStarting
77: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStartingSucceeded from WdfDevStatePwrPolStartingPoweredUp
78: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStartingDecideS0Wake from WdfDevStatePwrPolStartingSucceeded
79: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStarted from WdfDevStatePwrPolStartingDecideS0Wake
80: FxPowerIdleMachine::ProcessEventLocked - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power idle state FxIdleDisabled from FxIdleDisabled
81: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpEnableInterfaces from WdfDevStatePnpHardwareAvailable
82: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpStarted from WdfDevStatePnpEnableInterfaces
83: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000014(IRP_MN_QUERY_PNP_DEVICE_STATE) IRP 0xFFFF9B8FF91C42C0
84: FxPkgPdo::_PnpQueryPnpDeviceState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 returning PNP_DEVICE_STATE 0x2 IRP 0xFFFF9B8FF91C42C0
85: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type BusRelations IRP 0xFFFF9B8FF88FC3B0
86: FxIoTargetRemote::OpenTargetHandle - ZwCreateFile for WDFIOTARGET 000064700823F908 returned status STATUS_SUCCESS, info 0x0
87: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FEDE745F0
88: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FEDE6A630
89: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FF7E7F010
90: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type RemovalRelations IRP 0xFFFF9B8FF83823C0
91: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type EjectionRelations IRP 0xFFFF9B8FF83B18E0
92: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type RemovalRelations IRP 0xFFFF9B8FFAB03A60
93: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type EjectionRelations IRP 0xFFFF9B8FEDF53010
94: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000017(IRP_MN_SURPRISE_REMOVAL) IRP 0xFFFF9B8FF896D010
95: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpSurpriseRemoveIoStarted from WdfDevStatePnpStarted
96: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpFailedIoStarting from WdfDevStatePnpSurpriseRemoveIoStarted
97: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStopping from WdfDevStatePwrPolStarted
98: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerGotoD3Stopped from WdfDevStatePowerD0BusWakeOwner
99: FxPkgIo::StopProcessingForPower - Perform FxIoStopProcessingForPowerHold for all queues of WDFDEVICE 0x00006470082F5918

The raw pdo state after I unplug the device:
0: kd> !wdfdevice 0x00006470082f5918 ff
Treating handle as a KMDF handle!

Dumping WDFDEVICE 0x00006470082f5918

WDM PDEVICE_OBJECTs: self ffff9b8ffb48b240

Pnp state: 129 ( WdfDevStatePnpFailedIoStarting )
Power state: 314 ( WdfDevStatePowerGotoD3Stopped )
Power Pol state: 55b ( WdfDevStatePwrPolStopping )

Parent WDFDEVICE 00006470054ac988
Parent states:
Pnp state: 119 ( WdfDevStatePnpStarted )
Power state: 307 ( WdfDevStatePowerD0 )
Power Pol state: 502 ( WdfDevStatePwrPolStartingSucceeded )

Device is the power policy owner for the stack
No pended power, wait-wake irps
Pended pnp(IRP_MN_SURPRISE_REMOVAL) !irp 0xffff9b8ff896d010

owning thread: ffff9b8fdd2497c0
Pnp state history:
[0] WdfDevStatePnpObjectCreated (0x100)
[1] WdfDevStatePnpInit (0x105)
[2] WdfDevStatePnpInitStarting (0x106)
[3] WdfDevStatePnpHardwareAvailable (0x108)
[4] WdfDevStatePnpEnableInterfaces (0x109)
[5] WdfDevStatePnpStarted (0x119)
[6] WdfDevStatePnpSurpriseRemoveIoStarted (0x127)
[7] WdfDevStatePnpFailedIoStarting (0x129)

owning thread: ffff9b8fdd2497c0
Power state history:
[0] WdfDevStatePowerStartingChild (0x317)
[1] WdfDevStatePowerD0Starting (0x30f)
[2] WdfDevStatePowerD0StartingConnectInterrupt (0x310)
[3] WdfDevStatePowerD0StartingDmaEnable (0x311)
[4] WdfDevStatePowerD0StartingStartSelfManagedIo (0x312)
[5] WdfDevStatePowerDecideD0State (0x313)
[6] WdfDevStatePowerD0BusWakeOwner (0x309)
[7] WdfDevStatePowerGotoD3Stopped (0x314)

owning thread: ffff9b8fdd2497c0
Power policy state history:
[0] WdfDevStatePwrPolObjectCreated (0x500)
[1] WdfDevStatePwrPolStarting (0x501)
[2] WdfDevStatePwrPolStartingPoweredUp (0x583)
[3] WdfDevStatePwrPolStartingSucceeded (0x502)
[4] WdfDevStatePwrPolStartingDecideS0Wake (0x504)
[5] WdfDevStatePwrPolStarted (0x565)
[6] WdfDevStatePwrPolStopping (0x55b)

Idle state history:
[0] FxIdleStarted (0x2)
[1] FxIdleStartedPowerUp (0x3)
[2] FxIdleDisabled (0x5)
[3] FxIdleDisabled (0x5)

Power references: 1

S0Idle policy not configured

SxWake policy not configured

Power Capabilities:
DeviceWake[PowerSystemWorking]: DeviceWakeDepthD0
DeviceWake[PowerSystemSleeping1]: DeviceWakeDepthNotWakeable
DeviceWake[PowerSystemSleeping2]: DeviceWakeDepthNotWakeable
DeviceWake[PowerSystemSleeping3]: DeviceWakeDepthNotWakeable
DeviceWake[PowerSystemHibernate]: DeviceWakeDepthNotWakeable
SystemWake: PowerSystemUnspecified
S-D mapping:
S0->PowerDeviceD0
S1->PowerDeviceD2
S2->PowerDeviceD2
S3->PowerDeviceD2
S4->PowerDeviceD2
S5->PowerDeviceD3
IdealDxStateForSx: PowerDeviceUnspecified

No PnP device callbacks assigned.

EvtDeviceFileCreate: logi_generic_hid_filter!LSaiHid_EvtDeviceFileCreate (fffff8038c1dfbd0)
EvtDeviceFileClose: logi_generic_hid_filter!LSaiHid_EvtFileClose (fffff8038c1dfe00)

No in-caller context callbacks assigned

No preprocess callbacks assigned

No dispatch callbacks assigned

Properties:
SynchronizationScope: WdfSynchronizationScopeNone
ExecutionLevel: WdfExecutionLevelDispatch
IoType (Read/Write): WdfDeviceIoDirect
FileObjectClass: WdfFileObjectWdfCannotUseFsContexts
Exclusive: No
AutoForwardCleanupClose: No
DefaultIoPriorityBoost: 0

This means there is still an open file handle that is preventing the remove after surprise remove.

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@hotmail.com xxxxx@lists.osr.com
Sent: Monday, August 7, 2017 1:11:30 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] User mode WM_DEVICECHANGE doesn’t work after calling the ReadFile

Hi,

I have a driver on top of the hidclass enumerated device. The driver creates a raw pdo for the user mode application to read report. The application registers the device change notification for the interface that the raw pdo exposes. When the driver gets the Read request from the application, it formats the request for read with the remote IO target of the hid device and calls the WdfRequestSend to that remote IO target. Everything works fine except the device change notification. Without calling the ReadFile, unplugging the device, the application gets notified with the WM_DEVICECHANGE with DBT_DEVICEREMOVECOMPLETE. However, after calling the ReadFile which means that the driver starts to forward the read request to the remote IO target of the hid device, the application can’t receive that notification anymore. The device node of the hid device still exists on the device manager with the !. It seems that the device node can’t be removed. Can anyone know why? How can I fix it
?

0: kd> !wdfkd.wdflogdump logi_generic_hid_filter
Trace searchpath is:

Trace format prefix is: %7!u!: %!FUNC! -
Trying to extract TMF information from - c:\symstore\Wdf01000.pdb\11E877268FAE7196F0AA5A416B1A36E01\Wdf01000.pdb
Gather log: Please wait, this may take a moment (reading 4024 bytes).
% read so far … 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
There are 73 log entries
— start of log —
27: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering PnP State WdfDevStatePnpHardwareAvailable from WdfDevStatePnpInitStarting
28: FxPkgPnp::NotPowerPolicyOwnerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering not power policy owner state WdfDevStatePwrPolStarting from WdfDevStatePwrPolObjectCreated
29: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerStartingCheckDeviceType from WdfDevStatePowerObjectCreated
30: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerD0Starting from WdfDevStatePowerStartingCheckDeviceType
31: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerD0StartingConnectInterrupt from WdfDevStatePowerD0Starting
32: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerD0StartingDmaEnable from WdfDevStatePowerD0StartingConnectInterrupt
33: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerD0StartingStartSelfManagedIo from WdfDevStatePowerD0StartingDmaEnable
34: FxPkgIo::ResumeProcessingForPower - Power resume all queues of WDFDEVICE 0x00006470054AC988
35: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerDecideD0State from WdfDevStatePowerD0StartingStartSelfManagedIo
36: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering Power State WdfDevStatePowerD0 from WdfDevStatePowerDecideD0State
37: FxPkgPnp::NotPowerPolicyOwnerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering not power policy owner state WdfDevStatePwrPolStarted from WdfDevStatePwrPolStarting
38: FxPkgPnp::NotPowerPolicyOwnerEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering not power policy owner state WdfDevStatePwrPolStartingSucceeded from WdfDevStatePwrPolStarted
39: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering PnP State WdfDevStatePnpEnableInterfaces from WdfDevStatePnpHardwareAvailable
40: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 entering PnP State WdfDevStatePnpStarted from WdfDevStatePnpEnableInterfaces
41: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000014(IRP_MN_QUERY_PNP_DEVICE_STATE) IRP 0xFFFF9B8FEDEB78C0
42: FxPkgFdo::HandleQueryPnpDeviceStateCompletion - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0 returning PNP_DEVICE_STATE 0x0 IRP 0xFFFF9B8FEDEB78C0
43: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type BusRelations IRP 0xFFFF9B8FEDF6F010
44: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type BusRelations IRP 0xFFFF9B8FEDEC2010
45: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FEDE6A630
46: FxIoTargetRemote::OpenTargetHandle - ZwCreateFile for WDFIOTARGET 000064700823F908 returned status STATUS_SUCCESS, info 0x0
47: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FEDF06010
48: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FEDEB78C0
49: FxIoTargetRemote::ClearTargetPointers - WDFIOTARGET 000064700823F908 cleared pointers FFFFC68088D8D6F0 state WdfIoTargetClosed, open state 1, pdo FFFF9B8FEDF04650, fileobj FFFF9B8FEDE9D540, handle FFFFFFFF80001978
50: FxIoTargetRemote::Close - WDFIOTARGET 000064700823F908 derefing PDO FFFF9B8FEDF04650 on close
51: FxIoTargetRemote::Close - WDFIOTARGET 000064700823F908 derefing FileObj FFFF9B8FEDE9D540 on close
52: FxIoTargetRemote::Close - WDFIOTARGET 000064700823F908 closing handle FFFFFFFF80001978 on close
53: FxIoTargetRemote::ClearTargetPointers - WDFIOTARGET 000064700823F908 cleared pointers FFFFC68088D8D5F0 state WdfIoTargetDeleted, open state 1, pdo 0000000000000000, fileobj 0000000000000000, handle 0000000000000000
54: FxIoTarget::WaitForDisposeEvent - WDFIOTARGET 000064700823F908, Waiting on Dispose event FFFFC68088D8D560
55: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpInit from WdfDevStatePnpObjectCreated
56: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type BusRelations IRP 0xFFFF9B8FEDF2EA60
57: FxChildList::ProcessBusRelations - PDO created successfully, WDFDEVICE 00006470082F5918 !devobj FFFF9B8FFB48B240
58: FxPkgPnp::HandleQueryBusRelations - WDFDEVICE 00006470054AC988 returning 1 devices in relations FFFFD680735269A0
59: FxPkgPdo::_PnpQueryId - WDFDEVICE 00006470082F5918 does not have a string for PnP query IdType BusQueryContainerID, 0xc00000bb(STATUS_NOT_SUPPORTED)
60: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000000(IRP_MN_START_DEVICE) IRP 0xFFFF9B8FEDEE5010
61: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpInitStarting from WdfDevStatePnpInit
62: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpHardwareAvailable from WdfDevStatePnpInitStarting
63: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStarting from WdfDevStatePwrPolObjectCreated
64: FxPowerIdleMachine::ProcessEventLocked - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power idle state FxIdleStarted from FxIdleStopped
65: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerStartingCheckDeviceType from WdfDevStatePowerObjectCreated
66: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerStartingChild from WdfDevStatePowerStartingCheckDeviceType
67: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerD0Starting from WdfDevStatePowerStartingChild
68: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerD0StartingConnectInterrupt from WdfDevStatePowerD0Starting
69: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerD0StartingDmaEnable from WdfDevStatePowerD0StartingConnectInterrupt
70: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerD0StartingStartSelfManagedIo from WdfDevStatePowerD0StartingDmaEnable
71: FxPkgIo::ResumeProcessingForPower - Power resume all queues of WDFDEVICE 0x00006470082F5918
72: FxPowerIdleMachine::ProcessEventLocked - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power idle state FxIdleStartedPowerUp from FxIdleStarted
73: FxPowerIdleMachine::ProcessEventLocked - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power idle state FxIdleDisabled from FxIdleStartedPowerUp
74: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerDecideD0State from WdfDevStatePowerD0StartingStartSelfManagedIo
75: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerD0BusWakeOwner from WdfDevStatePowerDecideD0State
76: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStartingPoweredUp from WdfDevStatePwrPolStarting
77: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStartingSucceeded from WdfDevStatePwrPolStartingPoweredUp
78: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStartingDecideS0Wake from WdfDevStatePwrPolStartingSucceeded
79: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStarted from WdfDevStatePwrPolStartingDecideS0Wake
80: FxPowerIdleMachine::ProcessEventLocked - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power idle state FxIdleDisabled from FxIdleDisabled
81: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpEnableInterfaces from WdfDevStatePnpHardwareAvailable
82: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpStarted from WdfDevStatePnpEnableInterfaces
83: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000014(IRP_MN_QUERY_PNP_DEVICE_STATE) IRP 0xFFFF9B8FF91C42C0
84: FxPkgPdo::_PnpQueryPnpDeviceState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 returning PNP_DEVICE_STATE 0x2 IRP 0xFFFF9B8FF91C42C0
85: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type BusRelations IRP 0xFFFF9B8FF88FC3B0
86: FxIoTargetRemote::OpenTargetHandle - ZwCreateFile for WDFIOTARGET 000064700823F908 returned status STATUS_SUCCESS, info 0x0
87: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FEDE745F0
88: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FEDE6A630
89: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type TargetDeviceRelation IRP 0xFFFF9B8FF7E7F010
90: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type RemovalRelations IRP 0xFFFF9B8FF83823C0
91: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type EjectionRelations IRP 0xFFFF9B8FF83B18E0
92: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type RemovalRelations IRP 0xFFFF9B8FFAB03A60
93: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470054AC988 !devobj 0xFFFF9B8FEDF2E7F0, IRP_MJ_PNP, 0x00000007(IRP_MN_QUERY_DEVICE_RELATIONS) type EjectionRelations IRP 0xFFFF9B8FEDF53010
94: FxPkgPnp::Dispatch - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240, IRP_MJ_PNP, 0x00000017(IRP_MN_SURPRISE_REMOVAL) IRP 0xFFFF9B8FF896D010
95: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpSurpriseRemoveIoStarted from WdfDevStatePnpStarted
96: FxPkgPnp::PnpEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering PnP State WdfDevStatePnpFailedIoStarting from WdfDevStatePnpSurpriseRemoveIoStarted
97: FxPkgPnp::PowerPolicyEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering power policy state WdfDevStatePwrPolStopping from WdfDevStatePwrPolStarted
98: FxPkgPnp::PowerEnterNewState - WDFDEVICE 0x00006470082F5918 !devobj 0xFFFF9B8FFB48B240 entering Power State WdfDevStatePowerGotoD3Stopped from WdfDevStatePowerD0BusWakeOwner
99: FxPkgIo::StopProcessingForPower - Perform FxIoStopProcessingForPowerHold for all queues of WDFDEVICE 0x00006470082F5918

The raw pdo state after I unplug the device:
0: kd> !wdfdevice 0x00006470082f5918 ff
Treating handle as a KMDF handle!

Dumping WDFDEVICE 0x00006470082f5918
=================================

WDM PDEVICE_OBJECTs: self ffff9b8ffb48b240

Pnp state: 129 ( WdfDevStatePnpFailedIoStarting )
Power state: 314 ( WdfDevStatePowerGotoD3Stopped )
Power Pol state: 55b ( WdfDevStatePwrPolStopping )

Parent WDFDEVICE 00006470054ac988
Parent states:
Pnp state: 119 ( WdfDevStatePnpStarted )
Power state: 307 ( WdfDevStatePowerD0 )
Power Pol state: 502 ( WdfDevStatePwrPolStartingSucceeded )

Device is the power policy owner for the stack
No pended power, wait-wake irps
Pended pnp(IRP_MN_SURPRISE_REMOVAL) !irp 0xffff9b8ff896d010

owning thread: ffff9b8fdd2497c0
Pnp state history:
[0] WdfDevStatePnpObjectCreated (0x100)
[1] WdfDevStatePnpInit (0x105)
[2] WdfDevStatePnpInitStarting (0x106)
[3] WdfDevStatePnpHardwareAvailable (0x108)
[4] WdfDevStatePnpEnableInterfaces (0x109)
[5] WdfDevStatePnpStarted (0x119)
[6] WdfDevStatePnpSurpriseRemoveIoStarted (0x127)
[7] WdfDevStatePnpFailedIoStarting (0x129)

owning thread: ffff9b8fdd2497c0
Power state history:
[0] WdfDevStatePowerStartingChild (0x317)
[1] WdfDevStatePowerD0Starting (0x30f)
[2] WdfDevStatePowerD0StartingConnectInterrupt (0x310)
[3] WdfDevStatePowerD0StartingDmaEnable (0x311)
[4] WdfDevStatePowerD0StartingStartSelfManagedIo (0x312)
[5] WdfDevStatePowerDecideD0State (0x313)
[6] WdfDevStatePowerD0BusWakeOwner (0x309)
[7] WdfDevStatePowerGotoD3Stopped (0x314)

owning thread: ffff9b8fdd2497c0
Power policy state history:
[0] WdfDevStatePwrPolObjectCreated (0x500)
[1] WdfDevStatePwrPolStarting (0x501)
[2] WdfDevStatePwrPolStartingPoweredUp (0x583)
[3] WdfDevStatePwrPolStartingSucceeded (0x502)
[4] WdfDevStatePwrPolStartingDecideS0Wake (0x504)
[5] WdfDevStatePwrPolStarted (0x565)
[6] WdfDevStatePwrPolStopping (0x55b)

Idle state history:
[0] FxIdleStarted (0x2)
[1] FxIdleStartedPowerUp (0x3)
[2] FxIdleDisabled (0x5)
[3] FxIdleDisabled (0x5)

Power references: 1

S0Idle policy not configured

SxWake policy not configured

Power Capabilities:
DeviceWake[PowerSystemWorking]: DeviceWakeDepthD0
DeviceWake[PowerSystemSleeping1]: DeviceWakeDepthNotWakeable
DeviceWake[PowerSystemSleeping2]: DeviceWakeDepthNotWakeable
DeviceWake[PowerSystemSleeping3]: DeviceWakeDepthNotWakeable
DeviceWake[PowerSystemHibernate]: DeviceWakeDepthNotWakeable
SystemWake: PowerSystemUnspecified
S-D mapping:
S0->PowerDeviceD0
S1->PowerDeviceD2
S2->PowerDeviceD2
S3->PowerDeviceD2
S4->PowerDeviceD2
S5->PowerDeviceD3
IdealDxStateForSx: PowerDeviceUnspecified

No PnP device callbacks assigned.

EvtDeviceFileCreate: logi_generic_hid_filter!LSaiHid_EvtDeviceFileCreate (fffff8038c1dfbd0)
EvtDeviceFileClose: logi_generic_hid_filter!LSaiHid_EvtFileClose (fffff8038c1dfe00)

No in-caller context callbacks assigned

No preprocess callbacks assigned

No dispatch callbacks assigned

Properties:
SynchronizationScope: WdfSynchronizationScopeNone
ExecutionLevel: WdfExecutionLevelDispatch
IoType (Read/Write): WdfDeviceIoDirect
FileObjectClass: WdfFileObjectWdfCannotUseFsContexts
Exclusive: No
AutoForwardCleanupClose: No
DefaultIoPriorityBoost: 0


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

Hi Doron,

The issue doesn’t happen if I don’t call ReadFile. In this case, I still call CreateFile to the raw pdo and the notification message can still be received. Debugging into the driver, I don’t see the pending read request gets completed. Any ides?

Regards,
Marshall

Is it in a power managed queue? If not you need to purge the queue yourself. The stuck io will keep the handle open

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@hotmail.com xxxxx@lists.osr.com
Sent: Monday, August 7, 2017 5:35:48 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] User mode WM_DEVICECHANGE doesn’t work after calling the ReadFile

Hi Doron,

The issue doesn’t happen if I don’t call ReadFile. In this case, I still call CreateFile to the raw pdo and the notification message can still be received. Debugging into the driver, I don’t see the pending read request gets completed. Any ides?

Regards,
Marshall


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

Thanks, Doron. Adding the following code, the issue gets fixed.

WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&ioQueueConfig, WdfIoQueueDispatchParallel);
ioQueueConfig.PowerManaged = WdfTrue;
ioQueueConfig.EvtIoStop = LSaiHid_EvtIoStopForRawPdo;

VOID
LSaiHid_EvtIoStopForRawPdo(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN ULONG ActionFlags
)
{
UNREFERENCED_PARAMETER(Queue);

if (ActionFlags & WdfRequestStopActionSuspend)
{
WdfRequestStopAcknowledge(Request, FALSE); // Don’t requeue
}
else if (ActionFlags & WdfRequestStopActionPurge)
{
WdfRequestCancelSentRequest(Request);
}
}