IOCTL_INTERNAL_USB_CYCLE_PORT has no effect on Windows 7

Hi, everybody

I am developing a usb device sharing solution for windows, and use IOCTL_INTERNAL_USB_CYCLE_PORT to ask usb bus driver to simulate a unplug-n-replug operation, the code works on XP and Windows 2003, but on Windows 7 RC, eventhough the usb bus driver complete the IRP with success, but PnP not happens. A Kingstong DataTraverller USB Disk is attached to the USB port, and the IRP target is that PDO attached by USBSTOR.

does anybody can give me some advice?

Did you try this with win7 rtm?

d

Sent from my phone with no t9, all spilling mistakes are not intentional.

-----Original Message-----
From: xxxxx@hotmail.com
Sent: Tuesday, September 15, 2009 8:59 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] IOCTL_INTERNAL_USB_CYCLE_PORT has no effect on Windows 7

Hi, everybody

I am developing a usb device sharing solution for windows, and use IOCTL_INTERNAL_USB_CYCLE_PORT to ask usb bus driver to simulate a unplug-n-replug operation, the code works on XP and Windows 2003, but on Windows 7 RC, eventhough the usb bus driver complete the IRP with success, but PnP not happens. A Kingstong DataTraverller USB Disk is attached to the USB port, and the IRP target is that PDO attached by USBSTOR.

does anybody can give me some advice?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Yes, I do. It is the same as RC in RTM.

Just to make sure, you are sending it to the pdo enumerated by either usbccgp or usbhub, not the pdo enumerated by usbstor (!devstack pdo will tell you this)

d

Sent from my phone with no t9, all spilling mistakes are not intentional.

-----Original Message-----
From: xxxxx@hotmail.com
Sent: Tuesday, September 15, 2009 9:41 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] IOCTL_INTERNAL_USB_CYCLE_PORT has no effect on Windows 7

Yes, I do. It is the same as RC in RTM.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

The PDO is enumerated by usb root hub, here is the snapshot of DeviceTree (thanks to osronline for providing the great tool for Windows 7)

PDO \Device\NTPNP_PCI0033 - [PCI\VEN_15AD&DEV_0770&USBSYS_077015AD&REV_00]
±-FDO Attached: (unnamed) - \Driver\ACPI
±-FDO \Device\USBFDO-1
±-PDO \Device\USBPDO-1 - [USB\ROOT_HUB20] <— Driver is \Driver\usbehci
±-FDO Attached: (unnamed) - \Driver\usbfilter <— This is my usb filter device object
±-PDO \Device\USBPDO-3 - [USB\VID_090C&PID_1000] <==== DeviceObject 0x86243030
±-FDO \Device\00000067
±-PDO \Device\00000068 - [USBSTOR\Disk\Ven_Kingston&Pod_DataTraceler_2.0&Rev_1100]
±-FDO \Device\Harddisk1\DR1
±-FDO Attached: (unnamed) - \Driver\partmgr

and devobj and drvobj output follows
0: kd> !devobj 0x86243030
Device object (86243030) is for:
USBPDO-3 \Driver\usbhub DriverObject 863c1bb8
Current Irp 00000000 RefCount 0 Type 00000022 Flags 00003040
Dacl 88a56c00 DevExt 862430e8 DevObjExt 86243948 DevNode 86452b00
ExtensionFlags (0x00000800)
Unknown flags 0x00000800
AttachedDevice (Upper) 86a6e748 \Driver\USBSTOR
Device queue is not busy.
0: kd> !devnode 0x86452b00
DevNode 0x86452b00 for PDO 0x86243030
Parent 0x85f90ab0 Sibling 0000000000 Child 0x86977108
InstancePath is “USB\VID_090C&PID_1000\AA04012700007522”
ServiceName is “USBSTOR”
State = DeviceNodeStarted (0x308)
Previous State = DeviceNodeEnumerateCompletion (0x30d)
StateHistory[09] = DeviceNodeEnumerateCompletion (0x30d)
StateHistory[08] = DeviceNodeEnumeratePending (0x30c)
StateHistory[07] = DeviceNodeStarted (0x308)
StateHistory[06] = DeviceNodeStartPostWork (0x307)
StateHistory[05] = DeviceNodeStartCompletion (0x306)
StateHistory[04] = DeviceNodeStartPending (0x305)
StateHistory[03] = DeviceNodeResourcesAssigned (0x304)
StateHistory[02] = DeviceNodeDriversAdded (0x303)
StateHistory[01] = DeviceNodeInitialized (0x302)
StateHistory[00] = DeviceNodeUninitialized (0x301)
StateHistory[19] = Unknown State (0x0)
StateHistory[18] = Unknown State (0x0)
StateHistory[17] = Unknown State (0x0)
StateHistory[16] = Unknown State (0x0)
StateHistory[15] = Unknown State (0x0)
StateHistory[14] = Unknown State (0x0)
StateHistory[13] = Unknown State (0x0)
StateHistory[12] = Unknown State (0x0)
StateHistory[11] = Unknown State (0x0)
StateHistory[10] = Unknown State (0x0)
Flags (0x6c000130) DNF_ENUMERATED, DNF_IDS_QUERIED,
DNF_NO_RESOURCE_REQUIRED, DNF_NO_LOWER_DEVICE_FILTERS,
DNF_NO_LOWER_CLASS_FILTERS, DNF_NO_UPPER_DEVICE_FILTERS,
DNF_NO_UPPER_CLASS_FILTERS
CapabilityFlags (0x00000750) Removable, UniqueID,
RawDeviceOK, SurpriseRemovalOK,
WakeFromD0
0: kd> !drvobj 0x863c1bb8
Driver object (863c1bb8) is for:
\Driver\usbhub
Driver Extension List: (id , addr)

Device Object list:
8692c028 85267030 86243030 86887030
85f8a028 86413028

My code is

NTSTATUS FDO_CycleUsbPort(PDEVICE_OBJECT DeviceObject) // usb port PDO
{
NTSTATUS status;
KEVENT Event;
IO_STATUS_BLOCK iostatus;
PIRP Irp;
PIO_STACK_LOCATION stack;

KeInitializeEvent(&Event, NotificationEvent, FALSE);
Irp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_CYCLE_PORT, DeviceObject, NULL, 0, NULL, 0, TRUE, &Event, &iostatus);
KdPrint((“FDO_CycleUsbPort: IoBuildDeviceIoControlRequest, Irp %X \n”, Irp));

stack = IoGetNextIrpStackLocation(Irp);
stack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
stack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_CYCLE_PORT;

KdPrint((“FDO_CycleUsbPort: IoCallDriver(IOCTL_INTERNAL_USB_CYCLE_PORT, DeviceObject 0x%p)\n”, DeviceObject));
status = IoCallDriver(DeviceObject, Irp);

if ( status == STATUS_PENDING )
{
KdPrint((“FDO_CycleUsbPort: wait IoCallDriver complete …\n”));
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
status = iostatus.Status;
}

KdPrint((“FDO_CycleUsbPort: IoCallDriver return status 0x%x, iostatus.Status 0x%x\n”, status, iostatus.Status));
if (!NT_SUCCESS(status))
{
DbgPrint(“FDO_CycleUsbPort: Error %X trying to reset device\n”, status);
}

KdPrint((“FDO_CycleUsbPort: Leave, status 0x%x\n”, status));
return status;
}

and the output is

Connected to Windows 7 7600 x86 compatible target at (Wed Sep 16 13:10:43.671 2009 (GMT+8)), ptr64 FALSE
Kernel Debugger connection established.
Symbol search path is: srv*DownstreamStore*http://msdl.microsoft.com/download/symbols
Executable search path is:
Windows 7 Kernel Version 7600 MP (1 procs) Free x86 compatible
Built by: 7600.16385.x86fre.win7_rtm.090713-1255

FDO_ChangeBusRelations: FDO_CycleUsbPort(usbDevice->DeviceObject 0x86243030)
FDO_CycleUsbPort: IoBuildDeviceIoControlRequest, Irp 86C4BD98
FDO_CycleUsbPort: IoCallDriver(IOCTL_INTERNAL_USB_CYCLE_PORT, DeviceObject 0x86243030)
FDO_CycleUsbPort: IoCallDriver return status 0x0, iostatus.Status 0x0
FDO_CycleUsbPort: Leave, status 0x0

Are you sure you sending it at passive?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Tuesday, September 15, 2009 11:01 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] IOCTL_INTERNAL_USB_CYCLE_PORT has no effect on Windows 7

The PDO is enumerated by usb root hub, here is the snapshot of DeviceTree (thanks to osronline for providing the great tool for Windows 7)

PDO \Device\NTPNP_PCI0033 - [PCI\VEN_15AD&DEV_0770&USBSYS_077015AD&REV_00]
±-FDO Attached: (unnamed) - \Driver\ACPI
±-FDO \Device\USBFDO-1
±-PDO \Device\USBPDO-1 - [USB\ROOT_HUB20] <— Driver is \Driver\usbehci
±-FDO Attached: (unnamed) - \Driver\usbfilter <— This is my usb filter device object
±-PDO \Device\USBPDO-3 - [USB\VID_090C&PID_1000] <==== DeviceObject 0x86243030
±-FDO \Device\00000067
±-PDO \Device\00000068 - [USBSTOR\Disk\Ven_Kingston&Pod_DataTraceler_2.0&Rev_1100]
±-FDO \Device\Harddisk1\DR1
±-FDO Attached: (unnamed) - \Driver\partmgr

and devobj and drvobj output follows
0: kd> !devobj 0x86243030
Device object (86243030) is for:
USBPDO-3 \Driver\usbhub DriverObject 863c1bb8
Current Irp 00000000 RefCount 0 Type 00000022 Flags 00003040
Dacl 88a56c00 DevExt 862430e8 DevObjExt 86243948 DevNode 86452b00
ExtensionFlags (0x00000800)
Unknown flags 0x00000800
AttachedDevice (Upper) 86a6e748 \Driver\USBSTOR
Device queue is not busy.
0: kd> !devnode 0x86452b00
DevNode 0x86452b00 for PDO 0x86243030
Parent 0x85f90ab0 Sibling 0000000000 Child 0x86977108
InstancePath is “USB\VID_090C&PID_1000\AA04012700007522”
ServiceName is “USBSTOR”
State = DeviceNodeStarted (0x308)
Previous State = DeviceNodeEnumerateCompletion (0x30d)
StateHistory[09] = DeviceNodeEnumerateCompletion (0x30d)
StateHistory[08] = DeviceNodeEnumeratePending (0x30c)
StateHistory[07] = DeviceNodeStarted (0x308)
StateHistory[06] = DeviceNodeStartPostWork (0x307)
StateHistory[05] = DeviceNodeStartCompletion (0x306)
StateHistory[04] = DeviceNodeStartPending (0x305)
StateHistory[03] = DeviceNodeResourcesAssigned (0x304)
StateHistory[02] = DeviceNodeDriversAdded (0x303)
StateHistory[01] = DeviceNodeInitialized (0x302)
StateHistory[00] = DeviceNodeUninitialized (0x301)
StateHistory[19] = Unknown State (0x0)
StateHistory[18] = Unknown State (0x0)
StateHistory[17] = Unknown State (0x0)
StateHistory[16] = Unknown State (0x0)
StateHistory[15] = Unknown State (0x0)
StateHistory[14] = Unknown State (0x0)
StateHistory[13] = Unknown State (0x0)
StateHistory[12] = Unknown State (0x0)
StateHistory[11] = Unknown State (0x0)
StateHistory[10] = Unknown State (0x0)
Flags (0x6c000130) DNF_ENUMERATED, DNF_IDS_QUERIED,
DNF_NO_RESOURCE_REQUIRED, DNF_NO_LOWER_DEVICE_FILTERS,
DNF_NO_LOWER_CLASS_FILTERS, DNF_NO_UPPER_DEVICE_FILTERS,
DNF_NO_UPPER_CLASS_FILTERS
CapabilityFlags (0x00000750) Removable, UniqueID,
RawDeviceOK, SurpriseRemovalOK,
WakeFromD0
0: kd> !drvobj 0x863c1bb8
Driver object (863c1bb8) is for:
\Driver\usbhub
Driver Extension List: (id , addr)

Device Object list:
8692c028 85267030 86243030 86887030
85f8a028 86413028

My code is

NTSTATUS FDO_CycleUsbPort(PDEVICE_OBJECT DeviceObject) // usb port PDO
{
NTSTATUS status;
KEVENT Event;
IO_STATUS_BLOCK iostatus;
PIRP Irp;
PIO_STACK_LOCATION stack;

KeInitializeEvent(&Event, NotificationEvent, FALSE);
Irp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_CYCLE_PORT, DeviceObject, NULL, 0, NULL, 0, TRUE, &Event, &iostatus);
KdPrint((“FDO_CycleUsbPort: IoBuildDeviceIoControlRequest, Irp %X \n”, Irp));

stack = IoGetNextIrpStackLocation(Irp);
stack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
stack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_CYCLE_PORT;

KdPrint((“FDO_CycleUsbPort: IoCallDriver(IOCTL_INTERNAL_USB_CYCLE_PORT, DeviceObject 0x%p)\n”, DeviceObject));
status = IoCallDriver(DeviceObject, Irp);

if ( status == STATUS_PENDING )
{
KdPrint((“FDO_CycleUsbPort: wait IoCallDriver complete …\n”));
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
status = iostatus.Status;
}

KdPrint((“FDO_CycleUsbPort: IoCallDriver return status 0x%x, iostatus.Status 0x%x\n”, status, iostatus.Status));
if (!NT_SUCCESS(status))
{
DbgPrint(“FDO_CycleUsbPort: Error %X trying to reset device\n”, status);
}

KdPrint((“FDO_CycleUsbPort: Leave, status 0x%x\n”, status));
return status;
}

and the output is

Connected to Windows 7 7600 x86 compatible target at (Wed Sep 16 13:10:43.671 2009 (GMT+8)), ptr64 FALSE
Kernel Debugger connection established.
Symbol search path is: srv*DownstreamStore*http://msdl.microsoft.com/download/symbols
Executable search path is:
Windows 7 Kernel Version 7600 MP (1 procs) Free x86 compatible
Built by: 7600.16385.x86fre.win7_rtm.090713-1255

FDO_ChangeBusRelations: FDO_CycleUsbPort(usbDevice->DeviceObject 0x86243030)
FDO_CycleUsbPort: IoBuildDeviceIoControlRequest, Irp 86C4BD98
FDO_CycleUsbPort: IoCallDriver(IOCTL_INTERNAL_USB_CYCLE_PORT, DeviceObject 0x86243030)
FDO_CycleUsbPort: IoCallDriver return status 0x0, iostatus.Status 0x0
FDO_CycleUsbPort: Leave, status 0x0


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Yes, it is, I queue a work item, and the function is called by the work routine, so it is at PASSIVE_LEVEL, and no any locks were acquired.

If I plugin anoth type USB device, like SafeNet Genius Dog UGA V3, then the function can trigger the unplug-and-replug process, old PDO is removed, and a new PDO is created, but not works for USB Storage Device.

Maybe we can find the problem via ETW traces. I’ll start an e-mail
thread with you.

xxxxx@hotmail.com wrote:

If I plugin anoth type USB device, like SafeNet Genius Dog UGA V3, then the function can trigger the unplug-and-replug process, old PDO is removed, and a new PDO is created, but not works for USB Storage Device.

Thanks everybody for helping me resolve the issue, especially Philip help me investigate in usb ETW trace, and point out it is potentially a hardware issue, totay I follow his instruction and test every thing on a new machine, it works fine, so I do know it is hardware issue.