The Universal Serial Bus (USB) was designed by a consortium of hardware and software vendors Compaq, Intel, Microsoft and NEC beginning in 1994. It was conceived to provide a standardized way of connecting a wide range of peripheral devices to a computer (read "personal computer") and to correct some of the limitations of traditional serial and parallel lines.
USB has the following advantages:
USB cables contain only four wires: power, ground, send, and receive. Communication is handled in a hierarchical manner, under the control of a master; attached devices all function as slaves, thereby eliminating issues such as avoiding collisions. USB cable connectors are illustrated on the far left in Figure 12-2, and Figure 12-5 illustrates their corresponding pinouts.
Figure 12-5. USB connectors
B-type connectors are used for the USB port on the device, and A-type connectors are used for the port on the hub or computer system.
FreeBSD, HP-UX, Linux, Solaris, and Tru64 all support USB devices to some extent, although the support under HP-UX and Tru64 is limited to the USB keyboards and mice that come with the system (and are accordingly preconfigured by the operating system).
We will consider configuring three sample USB devices a mouse, a Zip drive, and a printer on the other three systems in the remainder of this section.
Table 12-6 summarizes the device files used for some USB devices on these systems.
12.8.1 FreeBSD USB Support
FreeBSD provides good support for USB devices, although some of it is in the experimental stage. See the FreeBSD USB project's home page, http://www.etal.net/~n_hibma/usb/, for details on the current status.
Before you can use USB devices, you must configure support in the kernel. The following kernel configuration file lines relate to USB support:
device uhci General USB support modules. device usb device ugen device ohic Alternate USB chipset support. device uhid device ukbd Keyboard. device ulpt Printer. device umass Mass storage: Zip drive. device umodem Modem. device ums Mouse. device uscanner Scanner.
You should always include the first four items. Include uhid also if you are using a mouse or keyboard. Include as many of the other items as makes sense for your configuration (or include all of them to allow for flexibility in the future).
You can determine if your kernel includes USB support that is compatible with the USB controller on the system by examining the output of dmesg:
# dmesg | grep usb usb0: OHCI version 1.0, legacy support usb0: <OHCI (generic) USB controller> on ohci0 usb0: USB revision 1.0
This kernel is configured for USB support, and it successfully detected the controller.
You can load the USB kernel module manually via the kldload usb command. Alternatively, you can set the appropriate modules to load automatically in the /boot/loader.conf file. Here we load general USB support and the modules for the mouse, keyboard, printer and Zip drive:
usb_load="YES" ums_load="YES" ukdb_load="YES" umass_load="YES" ulpt_load="YES"
See Chapter 16 for information about building FreeBSD kernels and modules.
You can list the current USB devices with the usbdevs command:
# usbdevs addr 1: OHCI root hub, (unknown) addr 2: Genius USB Wheel Mouse, KYE addr 3: TUSB2046 hub, Texas Instruments addr 4: Espon Stylus Photo 1280 addr 5: USB Zip 250, Iomega
This system has a USB mouse in one of the system's USB ports and a USB hub in the other. The secondary hub has a printer and a Zip 250 drive attached to it.
Some USB devices are configured automatically when they are detected, via the usbd daemon; the actions performed are specified in its configuration file, /etc/usbd.conf . This is the case for the printer, the Zip drive, and the USB mouse used in the system console's text mode.
Using the mouse under X as well requires an additional step, however. You must edit the XF86Config file to make X aware of the USB mouse (this file is usually in /etc). Under XFree86 Version 3.3, you modify the Pointer section as follows:
Section "Pointer" Device "/dev/sysmouse" Protocol "MouseSystems" EndSection
A USBprinter is also easy to configure. You can set it up like any other printer within the LPD facility, using the special file /dev/ulpt0 to refer to the printer.
A Zip drive is accessed via the USB mass storage driver. Via sleight of hand, it manages to trick the standard SCSI driver into servicing a USB disk. Accordingly, the kernel must also provide SCSI support in order to use such USB devices, and SCSI disk special files will be used to refer to them.
For example, the following command can be used to mount the disk in a Zip drive at /zip:
# mount -t msdos /dev/da0s4 /zip
The DOS partition on a Zip disk appears as the fourth slice to FreeBSD.
Alternatively, you can create a UFS filesystem on a Zip disk using the usual commands (see Section 10.3):
# disklabel -w -r da0 zip250 # newfs /dev/da0c # mount -t ufs /dev/da0c /somewhere
12.8.2 Linux USB Support
Linux also provides good support forUSB devices. Once again, support for them must be enabled in the kernel. Figure 12-6 illustrates make xconfig's USB menu.
Figure 12-6. Linux USB-related kernel parameters
We show only part of this very long parameter list (the gap indicates omitted selections). The items are divided into sections of related settings, beginning with general USB support and then support for hubs and devices classes, followed later by choices corresponding to specific USB devices. The ones required for our three devices are highlighted. I recommend selecting module-based support whenever possible.
You will also want to install the usbutils package and possibly the usbview package, as well (the latter provides a graphical USB device display command of the same name). We'll use tools from the former in this section.
You can view the currently attached USB devices with lsusb:
# lsusb | grep Bus Bus 001 Device 001: ID 0000:0000 Bus 001 Device 002: ID 0458:0003 KYE Systems Corp.(Mouse Systems) Bus 001 Device 003: ID 0451:2046 Texas Instruments TUSB2046 Hub Bus 001 Device 004: ID 059b:0030 Iomega Corp. Zip 250
USB device attributes are also available within the /proc filesystem, in files named like /proc/bus/usb/bus#/dev#. For example, the usbmodules command can be used to list the device-specific modules used by a USB device:
# usbmodules --device /proc/bus/usb/001/002 usbmouse hid
As with FreeBSD, using a USB mouse in the system console does not require configuration. If you want to use one under X, however, you must edit the XF86Config file, usually found in /etc/X11 (we are assuming Version 4 here). In order to use a USB mouse instead of the usual mouse type, add an InputDevice section like this one:
Section "InputDevice" Identifier "USB Mouse" Driver "mouse" Option "Protocol" "IMPS/2" Option "Device" "/dev/input/mice" EndSection
The special file mentioned in this example, mice, refers to any and all USB mice present on the system. If you want to specify just the first USB mouse, substitute /dev/input/mouse0.
In addition, you must designate the mouse to the X server via an InputDevice directive in the ServerLayout section. For example, these entries allow you to use both a normal and a USB mouse:
Section "ServerLayout" Identifier "Layout[all]" InputDevice "Mouse" "CorePointer" InputDevice "USB Mouse" "SendCoreEvents" ... EndSection
If you want to use only a USB mouse, remove the entry for the usual mouse, and set the second parameter of the USB mouse's entry to CorePointer.
Configuring a USB printer is no different than configuring any other printer. Using the administrative tools to do so is often a quick method. For example, Figure 12-7 illustrates the SuSE Linux YAST2 printer management facility's built-in USB printer support. In it, we see the available USB device choices.
Figure 12-7. Adding a USB printer with YAST2
Alternatively, you can set up a printer manually, using the same device file, /dev/usb/lp0. On SuSE 7 systems, the corresponding device is /dev/usblp0.
As under FreeBSD, accessing a USB Zip drive uses an interface to the SCSI subsystem (which must also be enabled in the kernel). For example, the following command could be used to mount a Zip disk at /zip:
# mount -t vfat /dev/sda4 /zip
The Zip disk's DOS partition is interpreted as partition 4 on the disk. You can also build other filesystem types on Zip disks, if you like.
For more information about the Linux USB project, see http://www.linux-usb.org.
12.8.3 Solaris USB Support
Solaris also provides support for USB devices. In fact, some Sun systems, like my Sun Blade, come with USB keyboards and mice standard, and no additional configuration is required to use them.
You can also use the system's USB ports for other sorts of devices. I tried using the same devices on my Sun as for the other two operating systems. The Zip drive worked fine. I used the following command to mount it:
# mount -F pcfs /dev/dsk/c1t0d0s0:c /zip
Like the other systems, the Solaris USB mass storage driver interfaces to the SCSI drive, and so the Zip drive's special filename is of the usual SCSI form. The DOS partition corresponds to the c slice.
Solaris offers support only for a very few USB printers, accessed via the /dev/usbprn* device files or via the usual /dev/printers/* files.