How to get USB vendor and product info programmatically on Linux?

Viewed 70020

Using udev I have been able to get this information for a certain USB device:

idVendor: 13b1
idProduct: 0018
manufacturer:  
product: USB 2.0 Network Adapter ver.2 
serial: 00FFFF

Now I want to get the full strings that are associated with the vendor and product ids. I found that the file /usr/share/misc/usb.ids contains the information that I'm looking for:

13b1  Linksys
        000b  WUSB11 v4.0 802.11b Adapter
        000d  WUSB54G Wireless Adapter
        0011  WUSB54GP v4.0 802.11g Adapter
        0018  USB200M 10/100 Ethernet Adapter
        001a  HU200TS Wireless Adapter
        001e  WUSBF54G 802.11bg
        0020  WUSB54GC 802.11g Adapter [ralink rt73]
        0023  WUSB54GR
        0024  WUSBF54G v1.1 802.11bg

However, it's not clear to me how I should retrieve this data in my application. Is there an API available or should I just parse the file? If I choose to parse it, then is /usr/share/misc/usb.ids always going to be the correct location?

5 Answers
lsusb

you get something like this

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 009: ID 138a:0010 Validity Sensors, Inc. VFS Fingerprint sensor
Bus 001 Device 008: ID 13d3:3491 IMC Networks 

then: ID 1d6b:0003 can be seen as : vendor = 1d6b and product = 0003

Related