2005-01-26 12:19:26

by DervishD

[permalink] [raw]
Subject: 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

--
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...


2005-01-26 13:40:41

by Oliver Neukum

[permalink] [raw]
Subject: Re: USB API, ioctl's and libusb

Am Mittwoch, 26. Januar 2005 13:20 schrieb DervishD:
> ? ? 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

2005-01-26 16:39:13

by DervishD

[permalink] [raw]
Subject: Re: USB API, ioctl's and libusb

Hi Oliver :)

* Oliver Neukum <[email protected]> dixit:
> Am Mittwoch, 26. Januar 2005 13:20 schrieb DervishD:
> > ? ? 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

--
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...

2005-01-27 00:25:53

by DervishD

[permalink] [raw]
Subject: Re: [Linux-usb-users] Re: USB API, ioctl's and libusb

Hi Alan :)
* Alan Stern <[email protected]> dixit:
> > 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.

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 ;)

> 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

--
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...

2005-01-27 00:16:50

by Alan Stern

[permalink] [raw]
Subject: Re: [Linux-usb-users] Re: USB API, ioctl's and libusb

On Wed, 26 Jan 2005, DervishD wrote:

> 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.

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

2005-01-27 01:14:54

by Johannes Erdfelt

[permalink] [raw]
Subject: Re: USB API, ioctl's and libusb

On Wed, Jan 26, 2005, DervishD <[email protected]> wrote:
> * Oliver Neukum <[email protected]> dixit:
> > Am Mittwoch, 26. Januar 2005 13:20 schrieb DervishD:
> > > ? ? 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).

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.

> 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

2005-01-27 11:22:42

by DervishD

[permalink] [raw]
Subject: Re: USB API, ioctl's and libusb

Hi Johannes :)

* Johannes Erdfelt <[email protected]> dixit:
> On Wed, Jan 26, 2005, DervishD <[email protected]> wrote:
> > * Oliver Neukum <[email protected]> dixit:
> > > 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.

> 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.

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

--
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...

2005-01-27 22:08:59

by Johannes Erdfelt

[permalink] [raw]
Subject: Re: USB API, ioctl's and libusb

On Thu, Jan 27, 2005, DervishD <[email protected]> wrote:
> 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

2005-01-28 10:21:53

by DervishD

[permalink] [raw]
Subject: Re: USB API, ioctl's and libusb

Hi Johannes :)

* Johannes Erdfelt <[email protected]> dixit:
> On Thu, Jan 27, 2005, DervishD <[email protected]> wrote:
> > 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

--
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...