Detecting a connected USB device

I would like to know which part of the system is responsible for detecting a connected device in a USB port

It can be a USB host port, so the connected device will be considered a USB client (therefore, the owner of the port is the host),
or it can be a USB client port, so that the connected device will be considered a USB host (therefore, the owner of the port is a client)

I’m interested in the moment when the system really detects (perhaps by changing the resistance) something was connected and based on which port the signal is coming from (host port or client port), or the host port driver or client port driver
I want to know HOW the system selects one or another driver based on this plug-in event

Where should I look for this? Perhaps in the USB core?

+6
source share
3 answers

The usb subsystem is responsible for detecting and probing newly added / hotplugged USB devices. Look in the kernel logs for a message, for example:

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

The code that handles all this is in the / usb / core drivers

The usb subsystem is under the scsi subsystem, and therefore your new devices will have device names, for example /dev/sdX . Its task is udev to create a new node device corresponding to this USB device in /dev . If you are interested in capturing this event and running a script that makes some notifications, you can read about how to edit udevd rules: http://www.reactivated.net/writing_udev_rules.html#external-run

+1
source

I understand what you are asking, and correctly, when a USB device is connected, the current fluctuation (through the resistors) leads to a notification. Then the host (there may be an agreement on who will be in OTG mode, but this also happens after the listing process).

Enumeration is the main process, which is the most important. USB follows top-level topology, and the entire system is based on the same.

NOTE. . It is very important to note that all packet transactions are initiated by the host. Customer by the grace of the owner. This is very important for understanding usb system.

Link to PLS: http://www.beyondlogic.org/usbnutshell/usb1.shtml

+1
source

Hi, when an Android device is connected, it is in client mode (at least on samsung devices) and when the device is connected, the device address is first set to 0x0, so the default address is known to the host. Then there is the endpoint 0 through which the entire configuration is performed (configuration, interface, endpoints).

enter image description here

The above image will help you understand. This is taken from the USB 2.0 manual. Remember that all settings during initialization are made through the endpoint 0, which is present on each device.

And I do not know how to change it from the client-host mode. (My knowledge is limited to the fact that negotiations are carried out after tuning in OTG mode). Hope I helped.

+1
source

Source: https://habr.com/ru/post/928112/


All Articles