In this article I show how to control input/output (I/O) of device drivers. Device I/O control is performed by calling driver functions in the kernel. These functions available vary from device to device. As a result, some investigation of the system header files are required in order understand how to call them and interpret the results they return.
Kernel functions are accessed via system calls, however, instead of introducing new systems calls for each I/O function, ioctl is provided as a generic system call for all device I/O control. Network interface configuration commands, for example, make extensive use of the ioctl system call. Try running strace ifconfig eth0 (for example) and you will see a number of calls to ioctl. This article focuses on network devices (serial port, Ethernet cards and Wireless cards) and gives examples of how to monitor and configure them at the system call level.
The ioctl System Call
A device driver consists of a set of kernel space functions that can be accessed from user space via system calls. These functions are implemented to resemble the file system interface. The file operations struct, defined in include/linux/fs.h under the kernel source tree, gives a list of the functions. A driver not may implement all these functions (unwanted functions are defined as NULL).
However, it is likely that the driver will require a number of extra functions for input/output control. Furthermore, these functions tend to be specific to the particular device. For example, a wireless device needs a…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: