检测插入的USB设备

时间:2020-12-09 23:37:31

I'd like to know, which part of the system is responsible for detection of plugged-in device in the USB port

我想知道,系统的哪个部分负责检测USB端口中的插入设备

It may be a USB host port, so that a plugged-in device will be considered a USB client (so port owner is host),
or it may be a USB client port, so that a plugged-in device will be considered a USB host (so port owner is client)

它可能是USB主机端口,因此插入的设备将被视为USB客户端(因此端口所有者是主机),或者它可能是USB客户端端口,因此插入的设备将被视为USB主机(所以端口所有者是客户端)

What I am interested in is a moment WHEN the system actually detects (by change of resistance maybe) that something has been plugged in, and based on from which port the signal is coming (host port or client port), either host port driver or client port driver is deployed
I want to know, HOW system picks up this or that driver, based on that "plugged-in" event

我感兴趣的是系统实际检测到(通过改变电阻)插入某些东西,并根据信号来自哪个端口(主机端口或客户端端口),主机端口驱动程序或部署客户端端口驱动程序我想知道,HOW系统根据“插入”事件获取此驱动程序或该驱动程序

Where should I look for that ? In USB core maybe ?

我应该在哪里寻找?在USB核心可能吗?

3 个解决方案

#1


1  

I understand what you are asking, and rightly when a usb device is connected then the current fluctuation (across resistors) leads to notification. Then the host (there can be negotiation that who will be host in OTG mode but that also happens after enumeration process).

我明白你在问什么,正确地当连接USB设备时,电流波动(跨越电阻器)会导致通知。然后主机(可以协商谁将在OTG模式下主机,但也会在枚举过程后发生)。

Enumeration is main process which is most important. USB follows star tier topology and whole system is based on same.

枚举是最重要的主要过程。 USB遵循星级拓扑,整个系统基于相同。

NOTE: It is very important to note that all the transactions of packets are initiated by host. The client is at mercy of host. This is very important in understanding the usb system.

注意:请务必注意,数据包的所有事务都由主机发起。客户受主人的怜悯。这对于理解usb系统非常重要。

Pls refer: http://www.beyondlogic.org/usbnutshell/usb1.shtml

请参阅:http://www.beyondlogic.org/usbnutshell/usb1.shtml

#2


1  

Hi when android device is connected then it is in client mode (atleast in samsung devices it is) and when the device is connected then at first the address of the device is set to 0x0 so that the default address is known by the host. Then there is endpoint 0 through which all the setup is done (configuration, interface, endpoints).

嗨,当Android设备连接时,它处于客户端模式(至少在三星设备中),当设备连接时,首先设备的地址设置为0x0,以便主机知道默认地址。然后是端点0,通过端点0完成所有设置(配置,接口,端点)。

检测插入的USB设备

The above image will help you to understand. This is taken from USB 2.0 manual. Remember that all the setting during initialization are done through endpoint 0 which is present in every device.

上面的图片将帮助您理解。这取自USB 2.0手册。请记住,初始化期间的所有设置都是通过端点0完成的,端点0存在于每个设备中。

And i dont know how to change it from client to host mode. (My knowledge is limited to that there is negotiation done after setup in OTG mode). I hope i helped.

我不知道如何将其从客户端模式更改为主机模式。 (我的知识仅限于在OTG模式下设置后进行协商)。我希望我帮忙。

#3


1  

The usb subsystem is responsible for detecting and probing newly added/hotplugged USB devices. Look in the kernel logs for messages like:

usb子系统负责检测和探测新添加/热插拔的USB设备。在内核日志中查找以下消息:

usb usb4: New USB device found, idVendor=1d6b, idProduct=0001
usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb4: Product: OHCI Host Controller
usb usb4: Manufacturer: Linux 2.6.32 ohci_hcd
usb usb4: SerialNumber: 0000:00:12.1
usb usb4: configuration #1 chosen from 1 choice

usb usb4:找到新的USB设备,idVendor = 1d6b,idProduct = 0001 usb usb4:新的USB设备字符串:Mfr = 3,Product = 2,SerialNumber = 1 usb usb4:产品:OHCI主机控制器usb usb4:制造商:Linux 2.6。 32 ohci_hcd usb usb4:SerialNumber:0000:00:12.1 usb usb4:从1个选项中选择的配置#1

The code which handles all this is located in drivers/usb/core

处理所有这些的代码位于drivers / usb / core中

The usb subsystem sits below the scsi subsystem and hence your newly allocated devices will have device names like /dev/sdX. Its the job of udev to create a new device node corresponding to this USB device in /dev. If you are interested in capturing this event and running a script that does some notifications you may wanna read up on how to edit udevd rules: http://www.reactivated.net/writing_udev_rules.html#external-run

usb子系统位于scsi子系统下方,因此新分配的设备将具有/ dev / sdX等设备名称。 udev的工作是在/ dev中创建与此USB设备相对应的新设备节点。如果您有兴趣捕获此事件并运行执行某些通知的脚本,您可能想要了解如何编辑udevd规则:http://www.reactivated.net/writing_udev_rules.html#external-run

#1


1  

I understand what you are asking, and rightly when a usb device is connected then the current fluctuation (across resistors) leads to notification. Then the host (there can be negotiation that who will be host in OTG mode but that also happens after enumeration process).

我明白你在问什么,正确地当连接USB设备时,电流波动(跨越电阻器)会导致通知。然后主机(可以协商谁将在OTG模式下主机,但也会在枚举过程后发生)。

Enumeration is main process which is most important. USB follows star tier topology and whole system is based on same.

枚举是最重要的主要过程。 USB遵循星级拓扑,整个系统基于相同。

NOTE: It is very important to note that all the transactions of packets are initiated by host. The client is at mercy of host. This is very important in understanding the usb system.

注意:请务必注意,数据包的所有事务都由主机发起。客户受主人的怜悯。这对于理解usb系统非常重要。

Pls refer: http://www.beyondlogic.org/usbnutshell/usb1.shtml

请参阅:http://www.beyondlogic.org/usbnutshell/usb1.shtml

#2


1  

Hi when android device is connected then it is in client mode (atleast in samsung devices it is) and when the device is connected then at first the address of the device is set to 0x0 so that the default address is known by the host. Then there is endpoint 0 through which all the setup is done (configuration, interface, endpoints).

嗨,当Android设备连接时,它处于客户端模式(至少在三星设备中),当设备连接时,首先设备的地址设置为0x0,以便主机知道默认地址。然后是端点0,通过端点0完成所有设置(配置,接口,端点)。

检测插入的USB设备

The above image will help you to understand. This is taken from USB 2.0 manual. Remember that all the setting during initialization are done through endpoint 0 which is present in every device.

上面的图片将帮助您理解。这取自USB 2.0手册。请记住,初始化期间的所有设置都是通过端点0完成的,端点0存在于每个设备中。

And i dont know how to change it from client to host mode. (My knowledge is limited to that there is negotiation done after setup in OTG mode). I hope i helped.

我不知道如何将其从客户端模式更改为主机模式。 (我的知识仅限于在OTG模式下设置后进行协商)。我希望我帮忙。

#3


1  

The usb subsystem is responsible for detecting and probing newly added/hotplugged USB devices. Look in the kernel logs for messages like:

usb子系统负责检测和探测新添加/热插拔的USB设备。在内核日志中查找以下消息:

usb usb4: New USB device found, idVendor=1d6b, idProduct=0001
usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb4: Product: OHCI Host Controller
usb usb4: Manufacturer: Linux 2.6.32 ohci_hcd
usb usb4: SerialNumber: 0000:00:12.1
usb usb4: configuration #1 chosen from 1 choice

usb usb4:找到新的USB设备,idVendor = 1d6b,idProduct = 0001 usb usb4:新的USB设备字符串:Mfr = 3,Product = 2,SerialNumber = 1 usb usb4:产品:OHCI主机控制器usb usb4:制造商:Linux 2.6。 32 ohci_hcd usb usb4:SerialNumber:0000:00:12.1 usb usb4:从1个选项中选择的配置#1

The code which handles all this is located in drivers/usb/core

处理所有这些的代码位于drivers / usb / core中

The usb subsystem sits below the scsi subsystem and hence your newly allocated devices will have device names like /dev/sdX. Its the job of udev to create a new device node corresponding to this USB device in /dev. If you are interested in capturing this event and running a script that does some notifications you may wanna read up on how to edit udevd rules: http://www.reactivated.net/writing_udev_rules.html#external-run

usb子系统位于scsi子系统下方,因此新分配的设备将具有/ dev / sdX等设备名称。 udev的工作是在/ dev中创建与此USB设备相对应的新设备节点。如果您有兴趣捕获此事件并运行执行某些通知的脚本,您可能想要了解如何编辑udevd规则:http://www.reactivated.net/writing_udev_rules.html#external-run