Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can the computer distinguishes between keyboard USB and mouse USB?

Tags:

usb

usb-drive

Wondering how can the PC distinguish among multiple USBs. For example, when i plug my flash drive USB into my computer how can it know that it is a flash drive USB not a keyboard USB ?

Thanks in advance.

like image 953
Mahmoud Anwer Avatar asked Oct 19 '25 05:10

Mahmoud Anwer


1 Answers

in the USB standard there are USB classes a memory stick is USB mass storage class, keyboard, mouse, joystick are USB HID class (Human Interface Device), cameras implement USB PTP (picture transfer protocol), USB-to-serial (virtual COM ports,...) is USB CDC ACM class ,...

the following link lists all USB classes for that windows has drivers https://msdn.microsoft.com/en-us/library/windows/hardware/ff538820%28v=vs.85%29.aspx

when the USB device is plugged in there is a communication between the MCU on the USB device (firmware) and the PC (USB host) . in this communication the device says which USB class it it and the host loads the fitting driver

you can sniff this communication using wireshark or see dmesg (on linux)

this communication is very low-level and not easily human-readable. there are tools like wireshark or lsusb -v for this

a USB device has to implement a special hierarchy of descriptors in which information of the internal structure of the USB device is contained. the hierachy is:

device descriptor -> configuration descriptor -> interface descriptor -> endpoint descriptor

EP0 is reserved for control transfers, else any transfer has to go to or come from an endpoint (OUT endpoint / IN endpoint)

see http://www.beyondlogic.org/usbnutshell/usb1.shtml

USB is a higly complex standard because it implements a wide functionality for a large number of different devices in one physical interface. i think the most complicated USB class standard is USB audio...

like image 93
ralf htp Avatar answered Oct 22 '25 08:10

ralf htp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!