4

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.

Mahmoud Anwer
  • 164
  • 1
  • 2
  • 12
  • Wrong site. You're looking for [su] instead. This site is for programming related questions. With that being said: When you plug in the device, the OS queries it for what it is, and the device tells it. It's just like when you walk into a restaurant and the waiter comes over. They ask you what you'd like to eat and you tell them. How else do you think it would be done? – Ken White Jan 27 '17 at 13:29
  • thanks for response, i was just wondering how this is happening. you helped me and i got the answer, thanks. – Mahmoud Anwer Feb 02 '17 at 10:48

1 Answers1

2

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...

ralf htp
  • 9,149
  • 4
  • 22
  • 34