Search code examples
javascriptwebusbwinusb

Chrome WebUSB controlTransferOut Results in "Transfer failed: A device attached to the system is not functioning. (0x1F)"


I'm developing a consumer USB device that will be configured via a web interface.

The first interface is a HID Gamepad. The second is a vendor interface where configuration will be handled.

Running this WebUSB code, I get the following error:

async () => {
  try {
    let device = await navigator.usb.requestDevice();

    await device.open();
    await device.selectConfiguration(1);
    await device.claimInterface(1);
    await device.controlTransferOut({ // ERROR OCCURS AT THIS LINE!
      requestType: "vendor",
      recipient: "interface",
      request: 0x01,
      value: 0x01,
      index: 0x01,
    });
    const dataToSend = new ArrayBuffer(8);
    dataToSend[0] = 2;
    let result = await device.transferOut(4, dataToSend);

    const decoder = new TextDecoder();
    console.log("Received: " + decoder.decode(result.data));
  } catch (error) {
    console.error(error);
  }

Which outputs DOMException: A transfer error has occurred.

Checking the Chrome device logs, I see this in chrome://device-log/:

[22:21:07] Transfer failed: A device attached to the system is not functioning. (0x1F)

A side note: I'm almost certain this code was working 6 months ago and I recall vaguely that it may have had to do with this next part (specifically the "driver":)

[22:15:57] USB device added: path=\\?\usb#vid_0f0d&pid_00cc#a&33dbaa40&1&1#{a5dcbf10-6530-11d2-901f-00c04fb951ed} vendor=3853 "keyboard.gg", product=204 "Edgeguard", serial="", driver="usbccgp", guid=c240342b-ed28-41aa-a8c9-bc505467059e

Chrome Device Log

First red flag to me is that the device is using driver="usbccgp" - I was expecting to see WinUsb. Using a tool called Zadig, I can see that the first interface is not WCID, but the second is (please note: I did not manually change either of these, this is what they are detected as by Windows.)

Zadig showing a non-WCID first interface Zadig showing a non-WCID second interface

My memory is fuzzy, but I think that this transfer may be failing because Chrome is adding the device with a usbccgp driver. Any advice would be appreciated.


Solution

  • This was due to a misconfiguration of my device's firmware code (didn't initialize or do any setup for the endpoints!)

    That's been fixed and I'm able to send data over properly.