Author Topic: Change "alternate setting" for HID device on Windows  (Read 18539 times)

raul

  • Member
  • ***
  • Posts: 6
Change "alternate setting" for HID device on Windows
« on: February 26, 2014, 10:14:11 am »
Hi,

I am developing a USB HID device, and have following situation to resolve.

The USB HID device has (for the purpose of this discusion) two functions
          - one is a HID interface (say, a mouse)
          - the other is debug information

Requirements
- when plugging to _any_ vanilla PC (Windows,Linux,Mac)
           - the HID should work without any extra drivers
           - the PC should not ask for any extra software to be installed, nor report any errors.

- when a particular application is installed on the PC - Windows only - (Mac and Linux a bonus)
           - the debug channel should work and provide as much bandwidth as possible.


Based on that,we implemented the "debug channel" also as a HID device, with a big maxpacketsize for bandwidth.

Alas, we've come to realize than to fulfill USB standard, maxPacketSize on the HID IN interrupt endpoint must be set to 64 bytes (as reported by USB 2.0 CV tests); otherwise, as I understand, we risk the device being silently ignored if there is not enough bandwidth on the bus.
This has the side effect of reducing the available bandwidth on the "debug channel", to the point of making it almost unusable for our application.

What are my options here ?

Here the ones I discarded:

* Use bulk endpoint for debug channel
       Discarded because a vanilla Windows installation will ask for a driver (violates one of the above requirements)
* Set maxpacketsize on the debug channel HID interface to a bigger number
       Discarded because it may not enumerate if there is not enough bandwidth on the USB bus.
       QUESTION: would it not enumerate the whole composite device or each interface independently ?
             In other words, would this approach just mean that I violate the standard, and that my "debug channel" may not work sometimes ?

Here others I am considering:
* provide multiple alternate settings with higher maxpacketsize.
    BUT, how do I change the setting if the device is a HID device, owned by the HID driver ?
    Is WinUSB the way to do it ?
         But, in WinUSB, can I just "attach" to a particular interface of a composite device ? (IE: I want the original HID function to work normally thru the standard HID path)

* Special command and re-enumerate with bulk endpoint
    Here the PC app, would send a special command and the USB device, would disconnect and connect again with for example a Bulk Endpoint.
    This is a bit undesirable, as it is cumbersome to achieve on the firmware of the USB.



Any comments, thoughts and answers much appreciated.

Regards,
Raul

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Change "alternate setting" for HID device on Windows
« Reply #1 on: February 26, 2014, 10:34:46 am »
To comply with the USB spec, the default HID interface should request no more than 64 bytes/millisec per interrupt endpoint. It's up to the host whether or not to enforce that. Even if you can get away with it on current OSes, that situation might change in the future, so best not to violate the spec.

To use an alternate HID interface that uses more bandwidth, you would need to provide a HID filter driver on the PC, probably digitally signed.

An alternative is a WinUSB interface using bulk endpoints. With the correct firmware, you no longer need to provide an INF file so it should install without the user having to provide anything. I don't think Macs support WinUSB. Linux can use libusb to access the device. You can have both WinUSB and HID interfaces in a device.

http://www.janaxelson.com/winusb.htm
« Last Edit: July 13, 2014, 10:06:18 pm by Jan Axelson »

raul

  • Member
  • ***
  • Posts: 6
Re: Change "alternate setting" for HID device on Windows
« Reply #2 on: February 26, 2014, 10:49:52 am »
Jan,
thanks for the prompt reply.

Re: WinUSB "you no longer need to provide an INF file"
This is a Win8 feature, isn't it ?  I need the driverless/complainless behaviour from WinXP onwards.

So,I will have a look at the HID filter driver approach. Do you have any good references (other than googl'ing for it) ? In particular, to see if it is viable to do it on UMDF.


Thanks,
Raul.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Change "alternate setting" for HID device on Windows
« Reply #3 on: February 26, 2014, 11:17:28 am »
WinUSB will work on earlier versions with automatic update:

http://blogs.msdn.com/b/usbcoreblog/archive/2012/09/26/how-to-install-winusb-sys-without-a-custom-inf.aspx

I would recommend the WinUSB route - will likely be easier and doesn't require installing a driver.

Otherwise, WinUSB has support for selecting alternate interfaces so you might find something useful there.

Barry Twycross

  • Frequent Contributor
  • ****
  • Posts: 263
Re: Change "alternate setting" for HID device on Windows
« Reply #4 on: February 26, 2014, 02:27:50 pm »
We had the exact same problem with one of our products. In the end we went with a custom driver for Windows, which we needed for other reasons. It made life a lot simpler (once the driver was written). In order for the device to not cause an alert on Windows when plugged in without a driver installed, its default configuration just had a PTP interface, which didn't do much. (It didn't do much without the driver, but at least it didn't annoy the user.)

Working with a Mac is trivial. No device causes an alert when plugged in, and any unknown device can be accessed via the user client interface from userspace.

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: Change "alternate setting" for HID device on Windows
« Reply #5 on: February 28, 2014, 01:09:33 pm »
Quote
WinUSB will work on earlier versions with automatic update:

http://blogs.msdn.com/b/usbcoreblog/archive/2012/09/26/how-to-install-winusb-sys-without-a-custom-inf.aspx
Surely, these Microsoft web pages tell that winusbcompat.inf/.cat, which provides "WinUSB compatible ID support", should be supplied from "Windows update"
Quote
http://msdn.microsoft.com/en-us/library/windows/hardware/hh450799(v=vs.85).aspx
For versions of Windows earlier than Windows 8, the updated Winusb.inf is available through Windows Update. If your computer is configured to get driver update automatically, WinUSB driver will get installed without any user intervention by using the new INF package.

http://blogs.msdn.com/b/usbcoreblog/archive/2012/09/26/how-to-install-winusb-sys-without-a-custom-inf.aspx
WinUSB compatible ID support on earlier versions of Windows
As stated earlier, the ability to provide compatible and sub-compatible IDs through Microsoft OS Descriptors has existed since Windows XP SP3, and has been widely used by other classes of devices such as MTP, RNDIS, and Bluetooth. To enable the use of compatible ID for WinUSB devices, a new certified INF is now available on Windows update for down-level operating systems. If your computer is configured to get driver update automatically, the WinUSB driver will get installed without any user intervention by using the new INF package.

But even if we include "Windows update" for the search at device installation, we often fail to get the INF/CAT files.

In such case, we have to manually download the files from
http://catalog.update.microsoft.com

The detailed download instruction is described in this KB,

"Windows Phone 8 is not detected by your computer"
http://support.microsoft.com/kb/2749484/en-us
- Things to Try
- - 3. Update your Windows Phone 8 driver
- - - To manually download and install the Windows Phone driver:
- - - - a. Go to http://catalog.update.microsoft.com
- - - - b. Search for "windows phone winusb"

Ah, yes. The support files are distributed as "Windows Phone driver"

The direct link is (works just on IE),
http://catalog.update.microsoft.com/v7/site/ScopedViewInline.aspx?updateid=90462af8-f533-4522-9ad1-dcc969d94832

This cab file, which contains winusbcompat.inf/.cat, is downloaded.
AMD64_X86-en-20484220_5f2718fc6d44c5ae61d4275d679bbf1ededf58e5.cab

Extract these INF/CAT files into a folder, and specify this folder at device installation (or driver update).

It works on Windows XP-SP3, Vista x86/x64 and 7 x86/x64.
On the Device Manager of Windows XP SP3, the INF files gives "WinUsb Device (NULL)" instance under "Universal Serial Bus devices". On other platforms, the Device Manager shows the correct device name, given by the Product string descriptor (indexed by iProduct field of the device descriptor).

Tsuneo