From: polybear on

When system resume from suspend power status, my USB device must be reset.


Since there are no IRP_MN_WAIT_WAKE .
(I guess that IRP_MN_WAIT_WAKE not been receipted because this device is not
a remote-wakeup supported device.)

I call this cycle port function when the system power chang to working power
status
(in IRP_MN_SET_POWER).

==========================================================================
NTSTATUS ntStatus, status = STATUS_SUCCESS;
PIRP irp;
KEVENT event;
IO_STATUS_BLOCK ioStatus;
// PIO_STACK_LOCATION nextStack;
PDEVICE_EXTENSION deviceExtension;

BULKUSB_KdPrint( DBGLVL_DEFAULT,("enter BulkUsb_CyclePort\n"));

deviceExtension = DeviceObject->DeviceExtension;
KeInitializeEvent(&event, NotificationEvent, FALSE);

irp = IoBuildDeviceIoControlRequest(
IOCTL_INTERNAL_USB_CYCLE_PORT,
deviceExtension->TopOfStackDeviceObject,
NULL,
0,
NULL,
0,
TRUE, // internal ( use IRP_MJ_INTERNAL_DEVICE_CONTROL )
&event,
&ioStatus);


// nextStack = IoGetNextIrpStackLocation(irp);
// nextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
// nextStack->Parameters.DeviceIoControl.IoControlCode =
// IOCTL_INTERNAL_USB_CYCLE_PORT;

// BULKUSB_ASSERT(nextStack != NULL);

BULKUSB_KdPrint( DBGLVL_DEFAULT,("BulkUsb_CyclePort() calling USBD
reset port api\n"));

ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject,
irp);

BULKUSB_KdPrint( DBGLVL_DEFAULT,("BulkUsb_CyclePort() return from
IoCallDriver USBD %x\n", ntStatus));

if (ntStatus == STATUS_PENDING) {

BULKUSB_KdPrint( DBGLVL_DEFAULT,("BulkUsb_CyclePort() Wait for
single object\n"));

status = KeWaitForSingleObject(
&event,
Suspended,
KernelMode,
FALSE,
NULL);

BULKUSB_KdPrint( DBGLVL_DEFAULT,("BulkUsb_CyclePort() Wait for
single object, returned %x\n", status));

} else {
ioStatus.Status = ntStatus;
}

//
// USBD maps the error code for us
//
ntStatus = ioStatus.Status;

BULKUSB_KdPrint( DBGLVL_DEFAULT,("Exit BulkUsb_CyclePort (%x)\n",
ntStatus));

return ntStatus;

==Result====================================================================
==============

enter BulkUsb_CyclePort
BulkUsb:
BulkUsb_CyclePort() calling USBD reset port api
BulkUsb:
BulkUsb_CyclePort() return from IoCallDriver USBD c000000d
BulkUsb:
Exit BulkUsb_CyclePort (c000000d)