USBデバイスをlsしよう


2018年 09月 09日

Unix(Linux,…)では、lsは最もよく使用するコマンドではないだろうか。
ls は、ファイルとか、フォルダ(ディレクトリ)についての情報が分かる。

最近は、周辺機器をUSBで繋ぐのが一般的だ。
そして、何でも繋いでいるので、何がつながっているのか調べるのに困るくらいだ。
そうなると、lsコマンドと同じように、USBについてlsできないかと思うのが自然だろう。

実は、存在する。

lsusb(8)                                          Linux USB Utilities                                          lsusb(8)

NAME
lsusb - list USB devices

SYNOPSIS
lsusb [ options ]

DESCRIPTION
lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.

OPTIONS
-v, --verbose
Tells  lsusb  to be verbose and display detailed information about the devices shown.  This includes con‐
figuration descriptors for the device's current speed.  Class descriptors will be shown, when  available,
for USB device classes including hub, audio, HID, communications, and chipcard.

-s [[bus]:][devnum]
Show only devices in specified bus and/or devnum.  Both ID's are given in decimal and may be omitted.

以下省略
ということで、さっそく使ってみよう。
fuji$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 03f0:134a Hewlett-Packard Optical Mouse
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
fuji$ lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/8p, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/16p, 480M
|__ Port 7: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
fuji$
マウスは見えるが、キーボードが見えない。
実は、キーボードは、USBではなく、PS2でHHK(Happy Hacking Keyboard)をつないでいるからである。
とりあえず、周囲に転がっていた色々なものを挿してみた。

fuji$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 071: ID 04b0:0367 Nikon Corp.
Bus 001 Device 003: ID 03f0:134a Hewlett-Packard Optical Mouse
Bus 001 Device 077: ID 0930:6544 Toshiba Corp. TransMemory-Mini / Kingston DataTraveler 2.0 Stick (2GB)
Bus 001 Device 069: ID 054c:05b8 Sony Corp.
Bus 001 Device 061: ID 0b05:5b0f ASUSTek Computer, Inc.
Bus 001 Device 068: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 001 Device 070: ID 04da:21c1 Panasonic (Matsushita)
Bus 001 Device 060: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
fuji$ lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/8p, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/16p, 480M
|__ Port 6: Dev 77, If 0, Class=Mass Storage, Driver=usb-storage, 480M
|__ Port 7: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 8: Dev 71, If 0, Class=Imaging, Driver=usbfs, 480M
|__ Port 10: Dev 60, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 1: Dev 70, If 0, Class=Communications, Driver=, 480M
|__ Port 1: Dev 70, If 1, Class=CDC Data, Driver=, 480M
|__ Port 1: Dev 70, If 2, Class=Communications, Driver=, 480M
|__ Port 1: Dev 70, If 3, Class=CDC Data, Driver=, 480M
|__ Port 1: Dev 70, If 4, Class=Communications, Driver=, 480M
|__ Port 2: Dev 68, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 4: Dev 61, If 0, Class=Vendor Specific Class, Driver=usbfs, 480M
|__ Port 12: Dev 69, If 0, Class=Mass Storage, Driver=usb-storage, 480M
fuji$
Niconはデジカメ。
ToshibaとSonyはUSBメモリなのだが、表示は非常に違う。なぜ?
ASUSTekはandroid。
マウスはたくさん有る方が便利かもしれないと思って、2つ挿してみた。
Panasonicはガラ系。
Genesys LogicはUSBハブである。

USBバッテリーは挿しても表示されない。

もっと詳しく知りたければ、 -v オプションを使えばよい。
余りにも大量の情報が出てくるので、-s でデバイスを指定しないと困るだろう。
fuji$ lsusb -v -s 077

Bus 001 Device 077: ID 0930:6544 Toshiba Corp. TransMemory-Mini / Kingston DataTraveler 2.0 Stick (2GB)
Couldn't open device, some information will be missing
Device Descriptor:
bLength                18
bDescriptorType         1
bcdUSB               2.00
bDeviceClass            0 (Defined at Interface level)
bDeviceSubClass         0
bDeviceProtocol         0
bMaxPacketSize0        64
idVendor           0x0930 Toshiba Corp.
idProduct          0x6544 TransMemory-Mini / Kingston DataTraveler 2.0 Stick (2GB)
bcdDevice            1.00
iManufacturer           1
iProduct                2
iSerial                 3
bNumConfigurations      1
Configuration Descriptor:
bLength                 9
bDescriptorType         2
wTotalLength           32
bNumInterfaces          1
bConfigurationValue     1
iConfiguration          0
bmAttributes         0x80
(Bus Powered)
MaxPower              200mA
Interface Descriptor:
bLength                 9
bDescriptorType         4
bInterfaceNumber        0
bAlternateSetting       0
bNumEndpoints           2
bInterfaceClass         8 Mass Storage
bInterfaceSubClass      6 SCSI
bInterfaceProtocol     80 Bulk-Only
iInterface              0
Endpoint Descriptor:
bLength                 7
bDescriptorType         5
bEndpointAddress     0x81  EP 1 IN
bmAttributes            2
Transfer Type            Bulk
Synch Type               None
Usage Type               Data
wMaxPacketSize     0x0200  1x 512 bytes
bInterval             255
Endpoint Descriptor:
bLength                 7
bDescriptorType         5
bEndpointAddress     0x02  EP 2 OUT
bmAttributes            2
Transfer Type            Bulk
Synch Type               None
Usage Type               Data
wMaxPacketSize     0x0200  1x 512 bytes
bInterval             255
fuji$
lsusb は、知っていると時には役立つ程度のコマンドだ。
このコマンドの詳細は、各自で調べられたし。