Post by Xiaofan ChenThe code is the same in libusb 0.1.
http://libusb.svn.sourceforge.net/viewvc/libusb/trunk/libusb/linux.c?revision=658&view=markup
Similar question: what does IOCTL_USBFS_RELEASEINTF do?
That ioctl will send a Set-Interface request to switch the interface
back to altsetting 0 if it isn't in altsetting 0 already. Otherwise it
is similar to CLAIMINTF.
Do you think this is Set-Interface request is necessary?
Yes. Drivers and programs expect that an interface will be in
altsetting 0 when they first encounter it, so the kernel should arrange
for this to be true.
Also, if a device uses isochronous transfers then the bandwidth
allocated for those transfers might not get released until the
altsetting is changed. (The USB spec helps us there, because
interfaces aren't allowed to use any isochronous bandwidth in
altsetting 0.)
(Actually this isn't quite true. Under Linux, bandwidth currently is
allocated only while a transfer is in progress; however there's a good
chance that in the future we will switch over to allocating bandwidth
as soon as an altsetting is installed. In any case, it's probably best
to put the device in a state where it won't be expecting any
time-critical transfers to take place; this may help reduce power
consumption.)
Post by Xiaofan ChenThe documentation for libusb-1.0 is not quite the same as what
you say.
++++++++++++
http://libusb.sourceforge.net/api-1.0/group__dev.html#gaf0d053dd23420c4daec89c06da04abe4
int libusb_release_interface ( libusb_device_handle * dev,
int interface_number
)
Release an interface previously claimed with libusb_claim_interface().
You should release all claimed interfaces before closing a device handle.
This is a blocking function. A SET_INTERFACE control request will
be sent to the device, resetting interface state to the first alternate setting.
++++++++++++
I'm afraid the libusb documentation is out of date. The Linux kernel
used to behave that way, but it caused problems with too many devices
(their firmwares didn't support multiple altsettings and would crash
upon receiving Set-Interface). So the kernel was changed, a little
under two years ago, to send the Set-Interface request only when it was
needed, that is, only when the interface wasn't already in the first
alternate setting.
Post by Xiaofan ChenWhere are these IOCTL documented for usbfs under Linux?
Those ioctls are implemented in drivers/usb/core/devio.c, using
subroutines from drivers/usb/core/driver.c. I don't think they are
_explained_ anywhere. :-)
http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.34.y.git;a=blob;f=drivers/usb/core/driver.c;hb=HEAD
http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.34.y.git;a=blob;f=drivers/usb/core/devio.c;hb=HEAD
I see. Thanks. Interestingly devio.c is quite similar to libusb. ;-)
Naturally, since it does much the same thing: provide a user interface
for controlling USB devices.
Alan Stern