USB error 9: Unable to submit control message: Pipe error

505 Views Asked by At

I'm trying to mimic a software that is sending usb commands to a device. But I'm getting an error when sending the control command towards the device.

public static void main(String[] args) throws UsbException {
    UsbController usb = new UsbController();
    UsbDevice device = usb.findDevice(UsbHostManager.getUsbServices().getRootUsbHub(), hexToShort("046d"), hexToShort("c31c"));

    UsbConfiguration configuration = device.getUsbConfiguration((byte) 1);
    UsbInterface iface = configuration.getUsbInterface((byte) 0);
    iface.claim(usbInterface -> true);

    byte bmRequestType = (byte) 0xb6;
    byte bRequest = (byte) 0x01;
    short wValue = twoBytesToShort((byte) 0x02, (byte) 0x00);

    UsbControlIrp irp = device.createUsbControlIrp (
        bmRequestType,
        bRequest,
        wValue,
        (short) 0
    );

    irp.setData(new byte[1]);
    device.syncSubmit(irp);
}

private static short hexToShort(String hex) {
    int decimal = Integer.parseInt(hex, 16);
    return new Integer(decimal).shortValue();
}

private static short twoBytesToShort(byte firstByte, byte secondByte) {
    ByteBuffer bb = ByteBuffer.allocate(2);
    bb.order(ByteOrder.BIG_ENDIAN);
    bb.put(firstByte);
    bb.put(secondByte);
    return bb.getShort(0);
}

When I try to send the command towards my USB keyboard, then I lose control of my keyboard, so claiming the interface works I guess, but not the command part. I have used USBCap to capture the control command and it seems similar - b6 01 02 00 in the end.

enter image description here

It seems fine to me, so what could be the reason for the error?

0

There are 0 best solutions below