Next: Filesystem for USB
Up: Operating System Aspects
Previous: USB Stack
First we will look at what it takes to get a USB device to work under Linux
Consider a typical scenario of a USB device being used in Linux.
Whenever a new device is plugged in, the host controller detects the device and conveys the information
to the operating system. Once the operating system gets this information, the device is
enumerated. Enumeration takes place by way of the operating system issuing commands to the
host controller, more of which is discussed later. Enumeration of devices on the bus also occurs at boot time. Based on the information that the host learns at the time of enumeration, the operating system assigns
a driver to the device. It is possible that none of the drivers known to the OS supports the device.
A device driver for a USB device implements all the functions implemented in a usual device driver,
namely open, read, write, ioctl etc. Among these ioctl() performs a specially important role.
ioctl() is a system call in unix used for I/O functions related to devices. Since unix handles all hardware devices as files, it is necessary to be able to device specific operations on file descriptors corresponding to these devices. ioctl() takes the file descriptor corresponding to the device as the first argument. The second argument is the request type, which is device specific and the third optional argument contains any arguments that need to be passed with the request. Operations concerning the USB device(such as writing) have several attributes associated
with them, such as the transfer-type and specific attributes associated with the transfer type. It would be convenient to implement a write inside an ioctl
so that the necessary attributes may be passed to the ioctl call as parameters.<br>
An example ioctl call may be as follows:
ret = ioctl(dev->fd, IOCTL_USB_BULK, &bulk);
This makes a bulk write by calling ioctl function associated with the file of USB device
dev having a corresponding file-descriptor fd. The second parameter IOCTL_USB_BULK identifies the call as a bulk write,
with the structure bulk containing the actual data to be written.
Next: Filesystem for USB
Up: Operating System Aspects
Previous: USB Stack
Bhanu Nagendra P.
2003-07-28