need to programatically suspend or disconnect USB device

I am using a fully-embedded USB-based system in a product development.
The product line includes both Windows-XP and Windows-7 hosts and the
embedded USB device is completely inside and not physically accessible.

Most of time the USB device acts as an HD camera using the UVC
protocol. But if the camera firmware needs to be updated then there is
a method by which the camera can be commanded to go into firmware update
mode. When this command is received, the USB (camera) device shuts down
and disconnects and then reconfigures itself as a thumb drive … i.e.
it appears on he same USB port as a USB file storage gadget. When
Windows sees this “new” device it properly assigns a drive letter and
opens Windows Explorer to allow file transfers. All of this works like
a charm.

A problem arises, however, when a Windows-7 based system attempts to
“safely remove” the file storage device. This action (under Win-XP)
causes a USB suspend condition and that condition triggers the USB
device to finalize its firmware update and reboot itself, coming back
again as a UVC camera. Everything works well under Windows-XP. But,
with Windows-7, the “safely remove” action seems to do nothing as far as
the embedded file storage gadget device is concerned. The device
apparently doesn’t see a USB suspend so it just sits there forever
waiting for one. Since the device is completely embedded, it isn’t
possible to unplug its USB connection. That action, if we could do it,
would generate a USB disconnect event and that would work OK as well
… but, alas, we cannot do it.

My question is “How can I programmatically cause a Windows-7 machine to
generate a USB suspend (or a USB disconnect) condition on a USB file
storage gadget?” I’ve tried a few of the public domain programs that
claim to do this (e.g. EjectUSB) and I’ve also tried “devcon” from the
WinDDK package. With devcon it is possible to shutdown the entire host
controller and then do a rescan to put it back together. That scenario
does accomplish what I need but it is very invasive to the overall
system and thus isn’t a good solution.

Any advice, help, or pointers on how to write a program (hopefully at
user level) to generate a USB-suspend or USB-disconnect condition would
be greatly appreciated.

Steve B

I am guessing the difference is that on xp, the usb hub port was powered down as well when you did a safe removal. On win7, the port is not powered down. There is no programmatic interface to power down the port. Disable/enable (via devcon) of the parent hub will also get you a reenumeration

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Steven Butner
Sent: Tuesday, June 26, 2012 7:54 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] need to programatically suspend or disconnect USB device

I am using a fully-embedded USB-based system in a product development.
The product line includes both Windows-XP and Windows-7 hosts and the embedded USB device is completely inside and not physically accessible.

Most of time the USB device acts as an HD camera using the UVC protocol. But if the camera firmware needs to be updated then there is a method by which the camera can be commanded to go into firmware update mode. When this command is received, the USB (camera) device shuts down and disconnects and then reconfigures itself as a thumb drive … i.e.
it appears on he same USB port as a USB file storage gadget. When
Windows sees this “new” device it properly assigns a drive letter and
opens Windows Explorer to allow file transfers. All of this works like
a charm.

A problem arises, however, when a Windows-7 based system attempts to
“safely remove” the file storage device. This action (under Win-XP)
causes a USB suspend condition and that condition triggers the USB device to finalize its firmware update and reboot itself, coming back
again as a UVC camera. Everything works well under Windows-XP. But,
with Windows-7, the “safely remove” action seems to do nothing as far as
the embedded file storage gadget device is concerned. The device
apparently doesn’t see a USB suspend so it just sits there forever
waiting for one. Since the device is completely embedded, it isn’t
possible to unplug its USB connection. That action, if we could do it,
would generate a USB disconnect event and that would work OK as well … but, alas, we cannot do it.

My question is “How can I programmatically cause a Windows-7 machine to generate a USB suspend (or a USB disconnect) condition on a USB file
storage gadget?” I’ve tried a few of the public domain programs that
claim to do this (e.g. EjectUSB) and I’ve also tried “devcon” from the
WinDDK package. With devcon it is possible to shutdown the entire host
controller and then do a rescan to put it back together. That scenario
does accomplish what I need but it is very invasive to the overall system and thus isn’t a good solution.

Any advice, help, or pointers on how to write a program (hopefully at user level) to generate a USB-suspend or USB-disconnect condition would be greatly appreciated.

Steve B


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

Steven Butner wrote:

I am using a fully-embedded USB-based system in a product development.
The product line includes both Windows-XP and Windows-7 hosts and the
embedded USB device is completely inside and not physically accessible.

My question is “How can I programmatically cause a Windows-7 machine to
generate a USB suspend (or a USB disconnect) condition on a USB file
storage gadget?” I’ve tried a few of the public domain programs that
claim to do this (e.g. EjectUSB) and I’ve also tried “devcon” from the
WinDDK package. With devcon it is possible to shutdown the entire host
controller and then do a rescan to put it back together. That scenario
does accomplish what I need but it is very invasive to the overall
system and thus isn’t a good solution.

MSDN claims that disable/enable, using either device manager or devcon,
will reset a USB device [1]. So it seems that you were already close,
only applying devcon at the wrong level.

For a quick test:
devcon find usb*
Identify your mass storage device from the list, then:
devcon restart usb\vid_xyz*

HTH

[1] http://msdn.microsoft.com/en-us/library/windows/hardware/ff537340.aspx

Thanks for the idea … but when I tried it (with full admin privileges)
I got a message that nothing was restarted. It simply says “Restart
failed.”. I can see the device and I typed its id as “usb\vid_0515*”.

Any idea why this doesn’t succeed?

Steve B

On 06/27/2012 03:54 AM, Wilhelm Nöker wrote:

Steven Butner wrote:

> I am using a fully-embedded USB-based system in a product development.
> The product line includes both Windows-XP and Windows-7 hosts and the
> embedded USB device is completely inside and not physically accessible.
>
> My question is “How can I programmatically cause a Windows-7 machine to
> generate a USB suspend (or a USB disconnect) condition on a USB file
> storage gadget?” I’ve tried a few of the public domain programs that
> claim to do this (e.g. EjectUSB) and I’ve also tried “devcon” from the
> WinDDK package. With devcon it is possible to shutdown the entire host
> controller and then do a rescan to put it back together. That scenario
> does accomplish what I need but it is very invasive to the overall
> system and thus isn’t a good solution.

MSDN claims that disable/enable, using either device manager or
devcon, will reset a USB device [1]. So it seems that you were already
close, only applying devcon at the wrong level.

For a quick test:
devcon find usb*
Identify your mass storage device from the list, then:
devcon restart usb\vid_xyz*

HTH

[1]
http://msdn.microsoft.com/en-us/library/windows/hardware/ff537340.aspx


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

Unfortunately, it isn’t very hard to keep a mass storage device from
ejecting or restarting. Some process moving its current directory there
is already enough. For example, if I create a text file on a memory
stick and open it with notepad, “devcon restart” will fail for that
stick, reporting “reboot required”. If I close notepad and try again,
devcon succeeds.

You may have noticed that my first MSDN link [1] is mainly a description
of IOCTL_USB_HUB_CYCLE_PORT. That IOCTL has been declared deprecated
since Vista, but some say that it still works [2]. So if you don’t care
about safe removal and such things, it might be what you need.

[2] Geoff Chappell in
http://social.msdn.microsoft.com/Forums/en-US/wdk/thread/e2ae1ead-d733-41d0-a780-a50ac372822b

Steven Butner wrote:

Thanks for the idea … but when I tried it (with full admin privileges)
I got a message that nothing was restarted. It simply says “Restart
failed.”. I can see the device and I typed its id as “usb\vid_0515*”.

Any idea why this doesn’t succeed?

Steve B

On 06/27/2012 03:54 AM, Wilhelm Nöker wrote:
> Steven Butner wrote:
>
>> I am using a fully-embedded USB-based system in a product development.
>> The product line includes both Windows-XP and Windows-7 hosts and the
>> embedded USB device is completely inside and not physically accessible.
>>
>> My question is “How can I programmatically cause a Windows-7 machine to
>> generate a USB suspend (or a USB disconnect) condition on a USB file
>> storage gadget?” I’ve tried a few of the public domain programs that
>> claim to do this (e.g. EjectUSB) and I’ve also tried “devcon” from the
>> WinDDK package. With devcon it is possible to shutdown the entire host
>> controller and then do a rescan to put it back together. That scenario
>> does accomplish what I need but it is very invasive to the overall
>> system and thus isn’t a good solution.
>
> MSDN claims that disable/enable, using either device manager or
> devcon, will reset a USB device [1]. So it seems that you were already
> close, only applying devcon at the wrong level.
>
> For a quick test:
> devcon find usb*
> Identify your mass storage device from the list, then:
> devcon restart usb\vid_xyz*
>
> HTH
>
> [1]
> http://msdn.microsoft.com/en-us/library/windows/hardware/ff537340.aspx

On 6/26/2012 10:54 AM, Steven Butner wrote:

A problem arises, however, when a Windows-7 based system attempts to
“safely remove” the file storage device. This action (under Win-XP)
causes a USB suspend condition and that condition triggers the USB
device to finalize its firmware update and reboot itself, coming back
again as a UVC camera. Everything works well under Windows-XP. But,
with Windows-7, the “safely remove” action seems to do nothing as far
as the embedded file storage gadget device is concerned. The device
apparently doesn’t see a USB suspend so it just sits there forever
waiting for one. Since the device is completely embedded, it isn’t
possible to unplug its USB connection. That action, if we could do
it, would generate a USB disconnect event and that would work OK as
well … but, alas, we cannot do it.

Do you have any control over the hardware?
If your 1.5kOhm pullup on DP is software controllable, you can use that
to disappear from the USB.
The LPC 1343s I’m using call this “SoftConnect”. Give it a try if you
can… unless your microcontroller
is overly helpful you should be good.

James

You need to set the DisableOnSoftRemove registry flag for the device. Here’s a link to a KnowledgeBase article that describes how to do this:

http://support.microsoft.com/kb/2401954