linux / lsusb

零、概述

​USB,是英文 Universal Serial Bus(通用串行总线)的缩写,是一个外部总线标准,早期用于规范电脑与外部设备的连接和通讯。

​USB 连接自从首次推出到现在已经有23年,这种技术在全球电子行业中的扩展速度前所未有。USB 现在已经拥有超过 30 亿端口的年出货量,是迄今为止最常用的接口技术,笔记本电脑、平板电脑、智能手机和其他各种设备都依赖于这种技术来进行功率和数据传输。今天 USB 已经远远超出其最初提供的功能,所支持的数据速率和功率水平都提高了几个数量级。而且,由于这种不断发展的推动,USB 技术已经比任何其他连接解决方案都更加普及。

​ 在Linux上,我们可以使用lsusb来列出USB设备和它的属性。

一、什么是 lsusb

​ 在它的手册上,lsusb 定义成:

显示系统中以及连接到系统的USB总线信息的工具。

二、如何运行 lsusb?

​要运行 lsusb,你可以直接在命令终端里输入 lsusb

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 003: ID 17ef:4811 Lenovo Integrated Webcam [R5U877]
Bus 008 Device 002: ID 0a5c:217f Broadcom Corp. Bluetooth Controller

lsusb 会显示连接到 USB 总线上的设备信息和驱动信息。

下面介绍如何理解输出。我抓取了上面输出的最后一行:

Bus 008 Device 002 : ID 0a5c:217f Broadcom Corp. Bluetooth Controller
  • Bus 008 : 指明设备连接到哪条总线
  • Device 002 : 表明这是连接到总线上的第二台设备
  • ID : 设备的ID
  • Broadcom Corp. Bluetooth Controller :生产商名字和设备名

在插入 USB 设备后, 使用 dmesg 命令可以看到 USB 设备加载时 Linux 内核输出的调试信息。

下面是一个例子, 我们可以看到该设备同时使用了 USB2.0 root hub 驱动和 USB 1.1 root hub 驱动。

dmesg |grep -i usb

结果

[ 0.353138] usbcore: registered new interface driver usbfs
[ 0.353150] usbcore: registered new interface driver hub
[ 0.353182] usbcore: registered new device driver usb
[ 0.730026] ehci_hcd: USB 2.0 ‘Enhanced’ Host Controller (EHCI) Driver
[ 0.730116] ehci_hcd 0000:00:1a.7: new USB bus registered, assigned bus number 1
[ 0.748019] ehci_hcd 0000:00:1a.7: USB 2.0 started, EHCI 1.00
[ 0.748169] hub 1-0:1.0: USB hub found
[ 0.748336] ehci_hcd 0000:00:1d.7: new USB bus registered, assigned bus number 2
[ 0.768019] ehci_hcd 0000:00:1d.7: USB 2.0 started, EHCI 1.00
[ 0.768147] hub 2-0:1.0: USB hub found
[ 0.768236] ohci_hcd: USB 1.1 ‘Open’ Host Controller (OHCI) Driver
[ 0.768251] uhci_hcd: USB Universal Host Controller Interface driver

三、如何列出USB详细信息

使用 -v 选项来开启 USB 设备的详细信息。下面是一个例子。

lsusb -v

结果

Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 5
bNumEndpoints 2
bInterfaceClass 224 Wireless
bInterfaceSubClass 1 Radio Frequency
bInterfaceProtocol 1 Bluetooth
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0×83 EP 3 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0×0040 1x 64 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0×03 EP 3 OUT
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0×0040 1x 64 bytes
bInterval 1

四、找出连接了多少USB设备

find /dev/bus

结果

/dev/bus
/dev/bus/usb
/dev/bus/usb/008
/dev/bus/usb/008/002
/dev/bus/usb/008/001
/dev/bus/usb/007
/dev/bus/usb/007/001
/dev/bus/usb/006
/dev/bus/usb/006/001
/dev/bus/usb/005
/dev/bus/usb/005/001
/dev/bus/usb/004
/dev/bus/usb/004/001
/dev/bus/usb/003
/dev/bus/usb/003/001
/dev/bus/usb/002
/dev/bus/usb/002/004
/dev/bus/usb/002/003
/dev/bus/usb/002/001
/dev/bus/usb/001
/dev/bus/usb/001/001

使用 lsusb 命令 的 -D 选项,你可以打印特定设备的详细信息。下面是一个博通蓝牙设备的示例。

lsusb -D /dev/bus/usb/008/002

结果

Device: ID 0a5c:217f Broadcom Corp. Bluetooth Controller
Couldn’t open device, some information will be missing
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 224 Wireless
bDeviceSubClass 1 Radio Frequency
bDeviceProtocol 1 Bluetooth
bMaxPacketSize0 64
idVendor 0x0a5c Broadcom Corp.
idProduct 0x217f Bluetooth Controller
bcdDevice 3.60
iManufacturer 1
iProduct 2
iSerial 3
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 216
bNumInterfaces 4
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 0mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 224 Wireless
bInterfaceSubClass 1 Radio Frequency
bInterfaceProtocol 1 Bluetooth
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0×81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0×0010 1x 16 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0×82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0×0040 1x 64 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0×02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0×0040 1x 64 bytes
bInterval 1

五、总结

你可以用 lsusb 命令对你的系统上的 USB 设备做一个诊断。想要了解更全面的命令信息, 输入man lsusb 来查看它的手册。

转载:Linux 上USB 调试神器lsusb命令详解 - 知乎

(SAW:Game Over!)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值