USB API, ioctl's and libusb
Hi everybody :)
I've been solving a USB problem related to a digital photo
camera, and I've noticed that 'libusb' uses a ioctl interface to the USB kernel system. In fact it implements 'usb_control_msg()' using ioctl's. On the other hand, the kernel itself (I'm talking about 2.4.29) provides an API in <linux/usb.h> that implements too 'usb_control_msg()' using URB's.
My question is: which interface should be used by user space
applications, <linux/usb.h> or ioctl's? Is the ioctl interface deprecated in any way? In the "Programming guide for Linux USB Device Drivers", located in http://usb.in.tum.de/usbdoc/, I can't find ioctl interface references :?
Thanks a lot in advance :)
Raúl Núñez de Arenas Coronado
Signature · 3 lines
Linux Registered User 88736 http://www.dervishd.net & http://www.pleyades.net/ It's my PC and I'll cry if I want to...
Am Mittwoch, 26. Januar 2005 13:20 schrieb DervishD:
Quoted 5 lines
My question is: which interface should be used by user space applications, <
linux/usb.h> or ioctl's? Is the ioctl interface deprecated in any way? In the "Programming guide for Linux USB Device Drivers", located in http://usb.in.tum.de/usbdoc/, I can't find ioctl interface references :?
You are supposed to use libusb.
Regards
Oliver
Hi Oliver :)
* Oliver Neukum <[email protected]> dixit:
Quoted 7 lines
Am Mittwoch, 26. Januar 2005 13:20 schrieb DervishD:
Quoted 5 lines
My question is: which interface should be used by user space applications, <
linux/usb.h> or ioctl's? Is the ioctl interface deprecated in any way? In the "Programming guide for Linux USB Device Drivers", located in http://usb.in.tum.de/usbdoc/, I can't find ioctl interface references :?You are supposed to use libusb.
That's irrelevant, the program I was trying to fix uses libusb.
My question is about the preferred kernel interface, 'cause I don't know if it's the ioctl one or the URB one (well, I'm calling 'URB' interface the API that is implemented using URB's inside the kernel).
BTW, and judging from the program I've read, there are lots of
operations that must be done using 'usb_control_msg', and libusb implements that function with exactly the same interface as the kernel. The only difference is that libusb uses ioctl and the kernel implements the function using URB's. IMHO libusb doesn't provide a cleaner API, the only advantage of libusb is portability. Anyway, I've not used it enough to judge, I'm more concerned about kernel USB interface, not libusb one.
Thanks anyway :)
Raúl Núñez de Arenas Coronado
Signature · 3 lines
Linux Registered User 88736 http://www.dervishd.net & http://www.pleyades.net/ It's my PC and I'll cry if I want to...
Quoted 5 lines · DervishD
That's irrelevant, the program I was trying to fix uses libusb.
My question is about the preferred kernel interface, 'cause I don't know if it's the ioctl one or the URB one (well, I'm calling 'URB' interface the API that is implemented using URB's inside the kernel).
Quoted 8 lines
BTW, and judging from the program I've read, there are lots of
operations that must be done using 'usb_control_msg', and libusb implements that function with exactly the same interface as the kernel. The only difference is that libusb uses ioctl and the kernel implements the function using URB's. IMHO libusb doesn't provide a cleaner API, the only advantage of libusb is portability. Anyway, I've not used it enough to judge, I'm more concerned about kernel USB interface, not libusb one.
You don't seem to understand the difference between a kernel API and a user API. Only code that is part of the kernel can use a kernel API, so only kernel drivers can use the "URB" interface. By contrast, a user API can be used by regular programs, not part of the kernel. libusb provides a user API.
So there's really no choice. Unless you're writing a kernel module, your program can't use URBs. You can use libusb, or if you don't care about portability you can use ioctl calls directly. But you can't use URBs.
Alan Stern
Hi Alan :)
* Alan Stern <[email protected]> dixit:
Quoted 8 lines
Quoted 8 lines
BTW, and judging from the program I've read, there are lots of
operations that must be done using 'usb_control_msg', and libusb implements that function with exactly the same interface as the kernel. The only difference is that libusb uses ioctl and the kernel implements the function using URB's. IMHO libusb doesn't provide a cleaner API, the only advantage of libusb is portability. Anyway, I've not used it enough to judge, I'm more concerned about kernel USB interface, not libusb one.
Quoted 5 lines
You don't seem to understand the difference between a kernel API and a user API. Only code that is part of the kernel can use a kernel API, so only kernel drivers can use the "URB" interface. By contrast, a user API can be used by regular programs, not part of the kernel. libusb provides a user API.
I thought that <linux/usb.h> provided a user API, not a kernel
one. In fact I thought that the functions provided throught that header were syscalls. They are not, I've checked ;)
Quoted 3 lines
So there's really no choice. Unless you're writing a kernel module, your program can't use URBs. You can use libusb, or if you don't care about portability you can use ioctl calls directly. But you can't use URBs.
OK, that's right. I really thought that there were syscalls
providing USB API for user space programs. That sounded less weird when I first thought of it ;)) Thanks for the help :)))
Raúl Núñez de Arenas Coronado
Signature · 3 lines
Linux Registered User 88736 http://www.dervishd.net & http://www.pleyades.net/ It's my PC and I'll cry if I want to...
Quoted 7 lines · DervishD
* Oliver Neukum <[email protected]> dixit:
Quoted 6 lines
Am Mittwoch, 26. Januar 2005 13:20 schrieb DervishD:
Quoted 5 lines
? ? My question is: which interface should be used by user space applications, <
linux/usb.h> or ioctl's? Is the ioctl interface deprecated in any way? In the "Programming guide for Linux USB Device Drivers", located in http://usb.in.tum.de/usbdoc/, I can't find ioctl interface references :?
Quoted 6 lines
Quoted 1 line
You are supposed to use libusb.
That's irrelevant, the program I was trying to fix uses libusb.
My question is about the preferred kernel interface, 'cause I don't know if it's the ioctl one or the URB one (well, I'm calling 'URB' interface the API that is implemented using URB's inside the kernel).
ioctl() calls are for userspace only.
It just so happens there is an ioctl() call that provides an URB like interface and an ioctl() call that provides a synchronous call to do a control message.
Quoted 8 lines
BTW, and judging from the program I've read, there are lots of
operations that must be done using 'usb_control_msg', and libusb implements that function with exactly the same interface as the kernel. The only difference is that libusb uses ioctl and the kernel implements the function using URB's. IMHO libusb doesn't provide a cleaner API, the only advantage of libusb is portability. Anyway, I've not used it enough to judge, I'm more concerned about kernel USB interface, not libusb one.
I think you're looking at this incorrectly. You use the kernel API for kernel modules. You can use either the ioctl() API or libusb for userspace applications.
JE
Hi Johannes :)
* Johannes Erdfelt <[email protected]> dixit:
Quoted 8 lines · DervishD
Quoted 6 lines
* Oliver Neukum <[email protected]> dixit:
Quoted 1 line
You are supposed to use libusb.
That's irrelevant, the program I was trying to fix uses libusb.
My question is about the preferred kernel interface, 'cause I don't know if it's the ioctl one or the URB one (well, I'm calling 'URB' interface the API that is implemented using URB's inside the kernel).
ioctl()calls are for userspace only.
I was pretty sure of that. My doubt was the other way round. I
was assuming that the functions in <linux/usb.h> were syscalls, that they're not.
Quoted 3 lines
It just so happens there is an
ioctl()call that provides an URB like interface and anioctl()call that provides a synchronous call to do a control message.
Didn't knew about that... Thanks a lot for the info!. Is there
any documentation available for the ioctl USB interface to the kernel? Any API guide or something like that?
Thanks :)
Raúl Núñez de Arenas Coronado
Signature · 3 lines
Linux Registered User 88736 http://www.dervishd.net & http://www.pleyades.net/ It's my PC and I'll cry if I want to...
Quoted 3 lines · DervishD
Didn't knew about that... Thanks a lot for the info!. Is there
any documentation available for the ioctl USB interface to the kernel? Any API guide or something like that?
You can use the kernel sources to see how to use it.
JE
Hi Johannes :)
* Johannes Erdfelt <[email protected]> dixit:
Quoted 5 lines · DervishD
Quoted 3 lines
Didn't knew about that... Thanks a lot for the info!. Is there
any documentation available for the ioctl USB interface to the kernel? Any API guide or something like that?You can use the kernel sources to see how to use it.
Of course, but it's not the better method for learning, IMHO ;))
Thanks anyway, I'll take a look at the kernel sources :) and libusb sources, too.
Raúl Núñez de Arenas Coronado
Signature · 3 lines
Linux Registered User 88736 http://www.dervishd.net & http://www.pleyades.net/ It's my PC and I'll cry if I want to...