Throctukes
Throctukes

Reputation: 101

Problem reading from a device with libusb

The situation is this: I have a USB device (a custom device I'm trying to talk to) with two endpoints, one writing to the device, one reading from the device. Both are bulk transfers. Every communication transaction takes the form of (1) Write a command to the device (2) Read the response. I'm using libusb (version 0.1 rather than the 1.0 beta) to actually perform the communications.

On Windows, all is well. I can connect the device, claim the interface and communicate happily. However, in Ubuntu (a standard Hardy desktop install), whilst I can connect to the device and write to it, all read operations fail with the error "error submitting URB: Invalid argument" reported from libusb (error code -22).

If I check /var/log/messages I see a warning message logged for the same time as the read was attempted: "sysfs: duplicate filename 'usbdev4.3_ep81' can not be created" - which tallies with the device (it is indeed on that bus and it's endpoint 81 I'm trying to read from).

So... anyone seen a similar problem using libusb, or have any idea how to fix it?

Upvotes: 4

Views: 7604

Answers (4)

Throctukes
Throctukes

Reputation: 101

Turns out it was a misconfiguration in the descriptors on the device itself. lsusb -v showed an extra interface which was never used, which had a single isochronous endpoint 0x81. Since this was never used (and had never been tested as far as I could see, so quite possibly not even defined correctly) I removed it from the device descriptors completely (in the firmware).

And now I have a fully working device. Why linux refused to read from the device but Windows worked fine I don't know, but it definitely sent me on a wild goose chase.

Upvotes: 2

John Nilsson
John Nilsson

Reputation: 17307

I had to do some hacking to udev rules to get the device created with the right permissions for libusb to work. Like so:

SUBSYSTEM=="usb" ATTRS{idVendor}=="0a81", ATTRS{idProduct}=="0701", \
                MODE="0666" SYMLINK+="missile_launcher"

(This was an usb missile launcher I was writing a driver for.

Also this snippet was required to not clash with the kernel.

if(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
{
    // Detach kernel driver (usbhid) from device interface. (Linux hack)
    usb_detach_kernel_driver_np(launcher, 0);
    usb_detach_kernel_driver_np(launcher, 1);
}

I'm not sure how this relates to your problem, but atleast there are two possible points of failure that might be involved.

Upvotes: 1

Ilya
Ilya

Reputation: 3138

You can try WinDriver it's a commercial tool but have free full function evaluation (somehow time limited). You can check with WinDriver and if problem is reproducible it's might be device or your protocol fault. You did not give enough information to determine or analyze.

Upvotes: 0

Charles Duffy
Charles Duffy

Reputation: 295510

I haven't used libusb in quite some time -- but the sysfs error indicates that this is likely to be a kernel problem rather than a libusb one, so I'd start by trying to track that one down. (Not much point in trying to work with libusb until you're sure your kernel is talking to the device correctly).

Does the patch at http://kerneltrap.org/mailarchive/linux-usb-devel/2007/10/17/345922 apply to your kernel? (If so, does it fix the issue?)

Upvotes: 1

Related Questions