W2K's BulkUsb example causes an error when disconnect a device

Hi Guru,

I have a USB device which transfers data in BULK mode.

I use W2K DDK’s “bulkusb” example.

The problem is
when I disconnect the device, following error message always occurrs.

“You removed a device without stopping. You should stop the device
before remove.”

So I haven’t seen PnP for this device.

I didn’t modify the source.
I’m wondering if the “bulkusb” example has bugs.

If you know why, please let me know.
Any help would be appreciated!

Regards,
HyungJune Kim

When you get the query device capabilities irp in your PNP dispatch routine, set the SurpriseRemovalOK field to TRUE. This indicates that the device need not be stopped before hot removing it.

D

This posting is provided “AS IS” with no warranties, and confers no rights.

-----Original Message-----
From: HyungJune Kim [mailto:xxxxx@hynix.com]
Sent: Tuesday, July 09, 2002 2:58 AM
To: NT Developers Interest List
Subject: [ntdev] W2K’s BulkUsb example causes an error when disconnect a device

Hi Guru,

I have a USB device which transfers data in BULK mode.

I use W2K DDK’s “bulkusb” example.

The problem is
when I disconnect the device, following error message always occurrs.

“You removed a device without stopping. You should stop the device
before remove.”

So I haven’t seen PnP for this device.

I didn’t modify the source.
I’m wondering if the “bulkusb” example has bugs.

If you know why, please let me know.
Any help would be appreciated!

Regards,
HyungJune Kim

b???v?j?£??r???i?j??u???

Do NOT bother setting the SurpriseRemovalOK field to TRUE in your dispatch
routine, as this will do nothing. Rather, stick a completion routine in the
IRP, and in your completion routine set the SurpriseRemovalOK field to TRUE.
This is a bug in the USB stack in that the USB bus drivers do not check this
field to see what is set by higher drivers in the stack.

Also, this sample could be better. One thing you should definitely consider
is using a lookaside list for the URBs you allocate memory for in your
driver. This list will minimize fragmention of NonPagedPool memory caused
by your driver.


Bill McKenzie

“Doron Holan” wrote in message
news:xxxxx@ntdev…

When you get the query device capabilities irp in your PNP dispatch routine,
set the SurpriseRemovalOK field to TRUE. This indicates that the device
need not be stopped before hot removing it.

D

This posting is provided “AS IS” with no warranties, and confers no rights.

-----Original Message-----
From: HyungJune Kim [mailto:xxxxx@hynix.com]
Sent: Tuesday, July 09, 2002 2:58 AM
To: NT Developers Interest List
Subject: [ntdev] W2K’s BulkUsb example causes an error when disconnect a
device

Hi Guru,

I have a USB device which transfers data in BULK mode.

I use W2K DDK’s “bulkusb” example.

The problem is
when I disconnect the device, following error message always occurrs.

“You removed a device without stopping. You should stop the device
before remove.”

So I haven’t seen PnP for this device.

I didn’t modify the source.
I’m wondering if the “bulkusb” example has bugs.

If you know why, please let me know.
Any help would be appreciated!

Regards,
HyungJune Kim

b­®¶¹®vµj®Â£‰²r¢¹®±ižj¢½u÷–²

Thanks for answers!

I modified the code as your instruction.

In the W2k’s BulkUsb example, the driver checks the DeviceCapabilities in AddDevice routine.
I modify the completion routine as follow.

{
PDEVICE_EXTENSION dx = context;
dx->DeviceCapabilities.SurpriseRemovalOK = TRUE;
KeSetEvent(&dx->EventDevCap, 1, FALSE);
return STATUS_MORE_PROCESSING_REQUIRED;
}

The flag is set correctly, but when I disconnect the device Windows2000 still
tells the warning message “the device removal is not safe. You should stop the device before
removing”.

Also, as disconneting, pnp routine is called in the order of IRP_MN_SURPRISE_REMOVAL -> IRP_MN_REMOVE, but isn’t called IRP_MN_QUERY_REMOVE. Is this right?
When does IRP_MN_QUERY_REMOVE? Is this related to above warning message?

Thanks in advance!

Best Regards,
HyungJune Kim

----- Original Message -----
From: “Bill McKenzie”
Newsgroups: ntdev
To: “NT Developers Interest List”
Sent: Wednesday, July 10, 2002 2:13 PM
Subject: [ntdev] Re: W2K’s BulkUsb example causes an error when disconnect a device

> Do NOT bother setting the SurpriseRemovalOK field to TRUE in your dispatch
> routine, as this will do nothing. Rather, stick a completion routine in the
> IRP, and in your completion routine set the SurpriseRemovalOK field to TRUE.
> This is a bug in the USB stack in that the USB bus drivers do not check this
> field to see what is set by higher drivers in the stack.
>
> Also, this sample could be better. One thing you should definitely consider
> is using a lookaside list for the URBs you allocate memory for in your
> driver. This list will minimize fragmention of NonPagedPool memory caused
> by your driver.
>
> –
> Bill McKenzie
>
>
>
> “Doron Holan” wrote in message
> news:xxxxx@ntdev…
>
> When you get the query device capabilities irp in your PNP dispatch routine,
> set the SurpriseRemovalOK field to TRUE. This indicates that the device
> need not be stopped before hot removing it.
>
> D
>
> This posting is provided “AS IS” with no warranties, and confers no rights.
>
> -----Original Message-----
> From: HyungJune Kim [mailto:xxxxx@hynix.com]
> Sent: Tuesday, July 09, 2002 2:58 AM
> To: NT Developers Interest List
> Subject: [ntdev] W2K’s BulkUsb example causes an error when disconnect a
> device
>
> Hi Guru,
>
> I have a USB device which transfers data in BULK mode.
>
> I use W2K DDK’s “bulkusb” example.
>
> The problem is
> when I disconnect the device, following error message always occurrs.
>
> “You removed a device without stopping. You should stop the device
> before remove.”
>
> So I haven’t seen PnP for this device.
>
> I didn’t modify the source.
> I’m wondering if the “bulkusb” example has bugs.
>
> If you know why, please let me know.
> Any help would be appreciated!
>
> Regards,
> HyungJune Kim
>
>
>
>
>
> b???v?j???r???i?j??u??
>
>
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@hynix.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

As I understand it, QueryRemove can only be called when there is the
possibility of a CancelRemove. Since the device has been physically taken
away there is no way to cancel the remove, all there is…is remove.
SurpriseRemove is there so you can do anything special you may need to do in
the case of a remove without access to hardware.

Hopefully I got it right.
Chris

----- Original Message -----
From: “HyungJune Kim”
To: “NT Developers Interest List”
Sent: Wednesday, July 10, 2002 6:43 AM
Subject: [ntdev] Re: W2K’s BulkUsb example causes an error when disconnect a
device

> Thanks for answers!
>
> I modified the code as your instruction.
>
> In the W2k’s BulkUsb example, the driver checks the DeviceCapabilities in
AddDevice routine.
> I modify the completion routine as follow.
>
> {
> PDEVICE_EXTENSION dx = context;
> dx->DeviceCapabilities.SurpriseRemovalOK = TRUE;
> KeSetEvent(&dx->EventDevCap, 1, FALSE);
> return STATUS_MORE_PROCESSING_REQUIRED;
> }
>
> The flag is set correctly, but when I disconnect the device Windows2000
still
> tells the warning message “the device removal is not safe. You should stop
the device before
> removing”.
>
> Also, as disconneting, pnp routine is called in the order of
IRP_MN_SURPRISE_REMOVAL -> IRP_MN_REMOVE, but isn’t called
IRP_MN_QUERY_REMOVE. Is this right?
> When does IRP_MN_QUERY_REMOVE? Is this related to above warning message?
>
> Thanks in advance!
>
> Best Regards,
> HyungJune Kim
>
>
>
>
>
> ----- Original Message -----
> From: “Bill McKenzie”
> Newsgroups: ntdev
> To: “NT Developers Interest List”
> Sent: Wednesday, July 10, 2002 2:13 PM
> Subject: [ntdev] Re: W2K’s BulkUsb example causes an error when disconnect
a device
>
>
> > Do NOT bother setting the SurpriseRemovalOK field to TRUE in your
dispatch
> > routine, as this will do nothing. Rather, stick a completion routine in
the
> > IRP, and in your completion routine set the SurpriseRemovalOK field to
TRUE.
> > This is a bug in the USB stack in that the USB bus drivers do not check
this
> > field to see what is set by higher drivers in the stack.
> >
> > Also, this sample could be better. One thing you should definitely
consider
> > is using a lookaside list for the URBs you allocate memory for in your
> > driver. This list will minimize fragmention of NonPagedPool memory
caused
> > by your driver.
> >
> > –
> > Bill McKenzie
> >
> >
> >
> > “Doron Holan” wrote in message
> > news:xxxxx@ntdev…
> >
> > When you get the query device capabilities irp in your PNP dispatch
routine,
> > set the SurpriseRemovalOK field to TRUE. This indicates that the device
> > need not be stopped before hot removing it.
> >
> > D
> >
> > This posting is provided “AS IS” with no warranties, and confers no
rights.
> >
> > -----Original Message-----
> > From: HyungJune Kim [mailto:xxxxx@hynix.com]
> > Sent: Tuesday, July 09, 2002 2:58 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] W2K’s BulkUsb example causes an error when disconnect a
> > device
> >
> > Hi Guru,
> >
> > I have a USB device which transfers data in BULK mode.
> >
> > I use W2K DDK’s “bulkusb” example.
> >
> > The problem is
> > when I disconnect the device, following error message always occurrs.
> >
> > “You removed a device without stopping. You should stop the device
> > before remove.”
> >
> > So I haven’t seen PnP for this device.
> >
> > I didn’t modify the source.
> > I’m wondering if the “bulkusb” example has bugs.
> >
> > If you know why, please let me know.
> > Any help would be appreciated!
> >
> > Regards,
> > HyungJune Kim
> >
> >
> >
> >
> >
> > b?떴췾탂?즷쾟▷?i엏♡u??
> >
> >
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@hynix.com
> > To unsubscribe send a blank email to %%email.unsub%%
> >
> >
> b?떴췾탂⇔rr?.왢쎉喝m?앒썢⒳zf쥤?yマ왰^왁밗)b꾼(껭(

If you are setting an event like this from your completion routine, you can
handle the DEVICE_CAPABILITIES in your dispatch routine after a successful
wait for the event. In fact, what is your dispatch routine doing, could it
be resetting this field? If not, I am unclear as to why you would still see
the unsafe removal pop-up. Try setting the Removable field to TRUE as well,
but I don’t think this is necessary.

Also, as disconneting, pnp routine is called in the order of
IRP_MN_SURPRISE_REMOVAL -> IRP_MN_REMOVE, but isn’t called
IRP_MN_QUERY_REMOVE. Is this right?
When does IRP_MN_QUERY_REMOVE? Is this related to above warning message?

If its a surprise, the system can’t ask you if its okay, hence the name
surprise. Queries are only for normal non-surprise removes. There is no
way you could reject a surprise, so this is correct. If you click on the
arrow icon in the system tray for this device and let the system know you
are going to remove it, you will get a query before the remove. This arrow
icon won’t be there if you set the SurpriseRemovalOK field in the
DEVICE_CAPABILITIES however.

Bill M.

“HyungJune Kim” wrote in message
news:xxxxx@ntdev…
> Thanks for answers!
>
> I modified the code as your instruction.
>
> In the W2k’s BulkUsb example, the driver checks the DeviceCapabilities in
AddDevice routine.
> I modify the completion routine as follow.
>
> {
> PDEVICE_EXTENSION dx = context;
> dx->DeviceCapabilities.SurpriseRemovalOK = TRUE;
> KeSetEvent(&dx->EventDevCap, 1, FALSE);
> return STATUS_MORE_PROCESSING_REQUIRED;
> }
>
> The flag is set correctly, but when I disconnect the device Windows2000
still
> tells the warning message “the device removal is not safe. You should stop
the device before
> removing”.
>
> Also, as disconneting, pnp routine is called in the order of
IRP_MN_SURPRISE_REMOVAL -> IRP_MN_REMOVE, but isn’t called
IRP_MN_QUERY_REMOVE. Is this right?
> When does IRP_MN_QUERY_REMOVE? Is this related to above warning message?
>
> Thanks in advance!
>
> Best Regards,
> HyungJune Kim
>
>
>
>
>
> ----- Original Message -----
> From: “Bill McKenzie”
> Newsgroups: ntdev
> To: “NT Developers Interest List”
> Sent: Wednesday, July 10, 2002 2:13 PM
> Subject: [ntdev] Re: W2K’s BulkUsb example causes an error when disconnect
a device
>
>
> > Do NOT bother setting the SurpriseRemovalOK field to TRUE in your
dispatch
> > routine, as this will do nothing. Rather, stick a completion routine in
the
> > IRP, and in your completion routine set the SurpriseRemovalOK field to
TRUE.
> > This is a bug in the USB stack in that the USB bus drivers do not check
this
> > field to see what is set by higher drivers in the stack.
> >
> > Also, this sample could be better. One thing you should definitely
consider
> > is using a lookaside list for the URBs you allocate memory for in your
> > driver. This list will minimize fragmention of NonPagedPool memory
caused
> > by your driver.
> >
> > –
> > Bill McKenzie
> >
> >
> >
> > “Doron Holan” wrote in message
> > news:xxxxx@ntdev…
> >
> > When you get the query device capabilities irp in your PNP dispatch
routine,
> > set the SurpriseRemovalOK field to TRUE. This indicates that the device
> > need not be stopped before hot removing it.
> >
> > D
> >
> > This posting is provided “AS IS” with no warranties, and confers no
rights.
> >
> > -----Original Message-----
> > From: HyungJune Kim [mailto:xxxxx@hynix.com]
> > Sent: Tuesday, July 09, 2002 2:58 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] W2K’s BulkUsb example causes an error when disconnect a
> > device
> >
> > Hi Guru,
> >
> > I have a USB device which transfers data in BULK mode.
> >
> > I use W2K DDK’s “bulkusb” example.
> >
> > The problem is
> > when I disconnect the device, following error message always occurrs.
> >
> > “You removed a device without stopping. You should stop the device
> > before remove.”
> >
> > So I haven’t seen PnP for this device.
> >
> > I didn’t modify the source.
> > I’m wondering if the “bulkusb” example has bugs.
> >
> > If you know why, please let me know.
> > Any help would be appreciated!
> >
> > Regards,
> > HyungJune Kim
> >
> >
> >
> >
> >
> > b?¶¹®vµj?£‰²r¢¹?ižj¢½u??
> >
> >
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@hynix.com
> > To unsubscribe send a blank email to %%email.unsub%%
> >
> >
>

While the sample might check for the dev caps in the add device routine, that means that it is sending its on IRP w/its own dev caps to the PDO. For this to work, you must do this for a query capabilities that the PNP subsystem sends you (ie set the completion routine when you receive the appropriate PNP irp from above and then set the value in the completion routine then).

As for the query remove, you will get a query remove when you disable or uninstall the device from device manager. Furthermore, if you are not surprise removalable, you will also get a query remove from the hot unplug applet if you bring it up and try to manually “stop” a device (which is different then a PNP query stop / stop which is a resource rebalance).

You don’t get the remove device until all outstanding create files have been closed, you can register for pnp notifications and do this properly in your app via the same API you used to register for device interface notifications.

d

-----Original Message-----
From: HyungJune Kim [mailto:xxxxx@hynix.com]
Sent: Wednesday, July 10, 2002 3:44 AM
To: NT Developers Interest List
Subject: [ntdev] Re: W2K’s BulkUsb example causes an error when disconnect a device

Thanks for answers!

I modified the code as your instruction.

In the W2k’s BulkUsb example, the driver checks the DeviceCapabilities in AddDevice routine.
I modify the completion routine as follow.

{
PDEVICE_EXTENSION dx = context;
dx->DeviceCapabilities.SurpriseRemovalOK = TRUE;
KeSetEvent(&dx->EventDevCap, 1, FALSE);
return STATUS_MORE_PROCESSING_REQUIRED;
}

The flag is set correctly, but when I disconnect the device Windows2000 still
tells the warning message “the device removal is not safe. You should stop the device before
removing”.

Also, as disconneting, pnp routine is called in the order of IRP_MN_SURPRISE_REMOVAL -> IRP_MN_REMOVE, but isn’t called IRP_MN_QUERY_REMOVE. Is this right?
When does IRP_MN_QUERY_REMOVE? Is this related to above warning message?

Thanks in advance!

Best Regards,
HyungJune Kim

----- Original Message -----
From: “Bill McKenzie”
Newsgroups: ntdev
To: “NT Developers Interest List”
Sent: Wednesday, July 10, 2002 2:13 PM
Subject: [ntdev] Re: W2K’s BulkUsb example causes an error when disconnect a device

> Do NOT bother setting the SurpriseRemovalOK field to TRUE in your dispatch
> routine, as this will do nothing. Rather, stick a completion routine in the
> IRP, and in your completion routine set the SurpriseRemovalOK field to TRUE.
> This is a bug in the USB stack in that the USB bus drivers do not check this
> field to see what is set by higher drivers in the stack.
>
> Also, this sample could be better. One thing you should definitely consider
> is using a lookaside list for the URBs you allocate memory for in your
> driver. This list will minimize fragmention of NonPagedPool memory caused
> by your driver.
>
> –
> Bill McKenzie
>
>
>
> “Doron Holan” wrote in message
> news:xxxxx@ntdev…
>
> When you get the query device capabilities irp in your PNP dispatch routine,
> set the SurpriseRemovalOK field to TRUE. This indicates that the device
> need not be stopped before hot removing it.
>
> D
>
> This posting is provided “AS IS” with no warranties, and confers no rights.
>
> -----Original Message-----
> From: HyungJune Kim [mailto:xxxxx@hynix.com]
> Sent: Tuesday, July 09, 2002 2:58 AM
> To: NT Developers Interest List
> Subject: [ntdev] W2K’s BulkUsb example causes an error when disconnect a
> device
>
> Hi Guru,
>
> I have a USB device which transfers data in BULK mode.
>
> I use W2K DDK’s “bulkusb” example.
>
> The problem is
> when I disconnect the device, following error message always occurrs.
>
> “You removed a device without stopping. You should stop the device
> before remove.”
>
> So I haven’t seen PnP for this device.
>
> I didn’t modify the source.
> I’m wondering if the “bulkusb” example has bugs.
>
> If you know why, please let me know.
> Any help would be appreciated!
>
> Regards,
> HyungJune Kim
>
>
>
>
>
> b???v?j???r???i?j??u??
>
>
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@hynix.com
> To unsubscribe send a blank email to %%email.unsub%%
>
>
b???v?j???r???i?j??u?