简体   繁体   English

Linux上/ dev目录上的USB设备检测

[英]USB device detection on /dev directory on Linux

Using the lsusb command in Linux I have come to know about bus and device numbers, along with its name of newly attached USB devices. 我在Linux中使用lsusb命令了解总线和设备号,以及新连接的USB设备的名称。

But how can I know on which device directory (/dev/*) USB device get attached in Linux using command lines only? 但是,如何仅使用命令行在Linux中将USB设备连接到哪个设备目录(/ dev / *)上呢?

It's not a rule that every device has to show up directly under /dev/, but some device classes will be nested under sub-directories inside /dev/ 并非每个设备都必须直接显示在/ dev /下,但有些设备类将嵌套在/ dev /中的子目录下。

USB device drivers are a bit different, If you connect a valid USB device, USB HCI would read the VID:PID and will tell the usb-core that the device with VID:PID combination is connected. USB设备驱动程序稍有不同,如果您连接有效的USB设备,则USB HCI会读取VID:PID并告诉USB核连接了具有VID:PID组合的设备。

If the usbcore detects any registered driver for the VID:PID combination, it will couple it with the device, and the device file creation would happen accordingly 如果usbcore检测到任何已注册的VID:PID组合驱动程序,它将与设备耦合,并相应地创建设备文件

The device will show in /dev/bus/usb/.., even if, the corresponding driver is not present, to indicate that the device was detected. 即使没有相应的驱动程序,该设备也将显示在/ dev / bus / usb / ..中,以指示已检测到该设备。

You need to have the device driver to have the device in action/operation. 您需要设备驱动程序才能使设备运行/操作。

You can verify whether a device driver is coupled to the device through 您可以验证设备驱动程序是否通过以下方式耦合到设备:

cat /sys/kernel/debug/usb/devices 猫/ sys /内核/调试/ usb /设备

Each detected USB device will have an entry here, and also shows the "Driver=" field, to show which driver is associated with your device. 每个检测到的USB设备将在此处有一个条目,并显示“ Driver =“字段,以显示与您的设备关联的驱动程序。

Now, IFF there is a driver, that makes an entry in appropriate /dev tree, you will find the device there. 现在,IFF有一个驱动程序,它在适当的/ dev树中创建一个条目,您将在其中找到设备。

NOT every device will show up directly under /dev/ in the first level. 并非所有设备都会直接显示在第一级的/ dev /下。 say, your mouse/keyboard will not show-up directly under /dev, but inside /dev/input/ 例如,您的鼠标/键盘不会直接显示在/ dev下,而是显示在/ dev / input /中

Likewise, IF the connected USB device is a char/block device, it MAY show up there, that too have exceptions. 同样,如果连接的USB设备是char / block设备,则它可能会显示在此处,也有例外。

If your device is and ethernet/wifi device, the interface device will NOT show up under /dev/, cross-check with your existing eth0, wlan0, they will not appear directly under /dev/, but will in /proc/net/devices 如果您的设备是以太网/ wifi设备,则该接口设备将不会显示在/ dev /下,并与您现有的eth0,wlan0进行交叉检查,它们不会直接出现在/ dev /下,而是会显示在/ proc / net /下设备

sda/b/c shows up under /dev directly, because they are block devices and are managed by udev, as such. sda / b / c直接显示在/ dev下,因为它们是块设备,由udev进行管理。

Here is an example of lsusb output on my laptop: 这是我的笔记本电脑上的lsusb输出示例:

Bus 004 Device 123: ID 2001:3c1b D-Link Corp. DWA-127 Wireless N 150 High-Gain Adapter(rev.A1) [Ralink RT3070]

It's the device 123 on the bus 004. /dev/bus/usb/004/123 is just the file for the interested device. 它是在总线004的设备123 /dev/bus/usb/004/123仅仅是有兴趣的设备文件。

The path might vary on different kernels. 该路径可能在不同的内核上有所不同。 The result above holds on kernel 3.15.2 以上结果在内核3.15.2上保持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM