Id vendor usb linux

lsusb Command in Linux (Display USB device Details)

The `lsusb` command is a utility in Linux that allows users to list the USB (Universal Serial Bus) devices connected to the system. This utility is the part of “usbutils” package, which provides utilities to display information about USB buses in the system and the devices connected to them.

A USB (Universal Serial Bus) is a widely used standard for connecting devices to computers. It allows users to connect a many of devices such as keyboards, mice, printers, and external storage devices to their computers with ease. The `lsusb` command can be used to display information about these devices, including their vendor and product ID, device name, device driver, and others.

In this article, we will discuss the syntax and options of the lsusb command, and provide examples of how to use it to list and display information about USB devices in Linux.

Syntax

The basic syntax of the lsusb command is:

Options

Some common options used with the lsusb command are:

  • -v : Display detailed information about the USB devices.
  • -t : Display a tree-like view of the USB devices.
  • -s : Display information about a specific USB device, specified by its bus and device number.
  • -d : Display information about a specific USB device, specified by its vendor and product ID.
  • -D : Selects which device will be examined.

Examples

Output
Bus 002 Device 004: ID 046d:0a37 Logitech, Inc. USB Headset H540 Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 004: ID 413c:301a Dell Computer Corp. Bus 001 Device 003: ID c0f4:05e0 Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Output
/: Bus 02.Port 1: Dev 1, Driver=ehci-pci/2p, 480M |__ Port 1: Dev 2, If 0, Driver=hub/6p, 480M |__ Port 1: Dev 4, If 0, Driver=snd-usb-audio, 12M |__ Port 1: Dev 4, If 1, Driver=snd-usb-audio, 12M |__ Port 1: Dev 4, If 2, Driver=snd-usb-audio, 12M |__ Port 1: Dev 4, If 3, Interface Device, Driver=usbhid, 12M /: Bus 01.Port 1: Dev 1, Driver=ehci-pci/2p, 480M |__ Port 1: Dev 2, If 0, Driver=hub/4p, 480M |__ Port 1: Dev 3, If 0, Interface Device, Driver=usbhid, 1.5M |__ Port 1: Dev 3, If 1, Interface Device, Driver=usbhid, 1.5M |__ Port 2: Dev 4, If 0, Interface Device, Driver=usbhid, 1.5M
Output
Bus 002 Device 004: ID 046d:0a37 Logitech, Inc. USB Headset H540 Couldn't open device, some information will be missing Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 0 bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x046d Logitech, Inc. idProduct 0x0a37 USB Headset H540 bcdDevice 1.22 iManufacturer 1 iProduct 2 iSerial 3 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 0x011c
Output
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Couldn't open device, some information will be missing Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 9 Hub bDeviceSubClass 0 bDeviceProtocol 0 Full speed (or root) hub bMaxPacketSize0 64 idVendor 0x1d6b Linux Foundation idProduct 0x0002 2.0 root hub bcdDevice 5.15 iManufacturer 3 iProduct 2 iSerial 1

Using the lsusb Command with Other Utilities

The lsusb command can be used in combination with other utilities to perform a variety of tasks.

Читайте также:  Установить видеодрайвер amd линукс

To find the vendor and product ID of a USB device, use the lsusb command with the -v option and grep for the idVendor and idProduct fields:

lsusb -v | grep -E 'idVendor|idProduct' 
Output
idVendor 0x046d Logitech, Inc. idProduct 0x0a37 USB Headset H540 idVendor 0x8087 Intel Corp. idProduct 0x0024 Integrated Rate Matching Hub idVendor 0x8087 Intel Corp. idProduct 0x0024 Integrated Rate Matching Hub idVendor 0x1d6b Linux Foundation idProduct 0x0002 2.0 root hub

To find the device name of a USB device, use the lsusb command with the -v option and grep for the iProduct field:

Output
iProduct 2 Logitech USB Headset H540 iProduct 2 EHCI Host Controller iProduct 2 Dell MS116 USB Optical Mouse iProduct 2 usb keyboard

To find the device driver of a USB device, use the lsusb command with the -t option and grep for the device name:

Output
|__ Port 2: Dev 4, If 0, Interface Device, Driver=usbhid, 1.5M

To find the device node of a USB device, use the lsusb command with the -t option and look for the device name in the /dev directory:

Output
by-id event0 event10 event2 event4 event6 event8 mice by-path event1 event11 event3 event5 event7 event9 mouse0

Conclusion

In this article, you have learned about the `lsusb` command line utility and how to use it to list and display information about USB devices connected to a Linux system. We also saw how to use the lsusb command with other utilities to perform various tasks related to USB devices.

Источник

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

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?

Читайте также:  Cisco anyconnect linux openconnect

Here’s the most recent version: linux-usb.org/usb.ids and the interface for submitting them: linux-usb.org/usb-ids.html

On Android, my C program uses libusbhost which provides callbacks for device insertion/removal. All device descriptors are made available by the lib.

5 Answers 5

lsusb command queries information about currently plugged USB devices. You can use its -d option to query a certain vendor/product (but it seems to work only for currently plugged devices):

$ lsusb -d 0e21:0750 Bus 001 Device 005: ID 0e21:0750 Cowon Systems, Inc. 

You can show information for all devices:

$ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 004: ID 0421:01c7 Nokia Mobile Phones Bus 001 Device 003: ID 0bda:8187 Realtek Semiconductor Corp. RTL8187 Wireless Adapter Bus 001 Device 005: ID 0e21:0750 Cowon Systems, Inc. Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 006 Device 002: ID 046d:c01b Logitech, Inc. MX310 Optical Mouse Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub 

You can also make it be verbose ( lsusb -v ) and printing a lot of stuff.

Note that when accessing information about the system in Linux OS, it’s much preferred to do it via shell commands (such as lsusb ) than to directly parse the system files these commands access.

@Stacked, yes (for C), but that depends on a language you develop in. But either way you’ll be reading something from a stream, and calling lsusb -d . via popen seems to require less keystrokes than parsing the whole file with descriptions.

Haven’t tried this myself, but libudev’s udev_device_get_property_value should be it; it is used in pulseaudio’s udev-util.c as udev_device_get_property_value(card, «ID_VENDOR_FROM_DATABASE»)) .

Here is a small example I just put together, based on udev-util.c — note that I’ve used an Arduino Duemillanove with FTDI FT232 chip, whose udev path I find using udevadm (see comments in code below), and then I hardcoded it in the below program, udevl.c :

// sudo apt-get install libudev-dev // build with: gcc -o udevl -ludev -Wall -g udevl.c #include #include int main( int argc, char **argv ) < const char *v; char t[256]; struct udev *udev; struct udev_device *card = NULL; if (!(udev = udev_new())) < fprintf(stderr, "Failed to allocate udev context.\n"); return -1; >// $ lsusb | grep FT232 // Bus 002 Device 002: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC // $ udevadm info --name=/dev/ttyUSB0 --attribute-walk | grep "looking at device" // looking at device '/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/ttyUSB0/tty/ttyUSB0' // (that one is under /sys) // hardcode that path below: // udev_get_sys_path(udev) for me: '/sys' sprintf(t, "%s/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/ttyUSB0/tty/ttyUSB0", udev_get_sys_path(udev)); fprintf(stdout, " path: %s\n", t); card = udev_device_new_from_syspath(udev, t); fprintf(stdout, " udev_device: 0x%08X\n", (unsigned int)card); if ((v = udev_device_get_property_value(card, "ID_MODEL_FROM_DATABASE")) ) fprintf(stdout, "got ID_MODEL_FROM_DATABASE: %s\n", v); else fprintf(stdout, "failed getting ID_MODEL_FROM_DATABASE: %s\n", v); fprintf(stdout, "Done.\n"); if (card) udev_device_unref(card); if (udev) udev_unref(udev); return 0; > 

This program (with the Arduino attached) outputs:

$ ./udevl path: /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/ttyUSB0/tty/ttyUSB0 udev_device: 0x09FBF080 got ID_MODEL_FROM_DATABASE: FT232 USB-Serial (UART) IC Done. 

. and «FT232 USB-Serial (UART) IC» is the right entry for VID:PID 0403:6001 in usb.ids.

Читайте также:  Install ros linux mint

Источник

Programmatically obtaining the vendor ID, product ID of a USB device on a Linux platform

I have been trying to write a simple device driver, in which I am suppossed to get the Vendor ID and Product ID programmatically. Having gone through almost all the necessary header files, I have come to a conclusion that I can access the vendor ID, product ID, and manufacturer details of the USB device through a structure: struct usb_device<> which has a member struct usb_device_descriptor<> . This nested structure has idVendor, idProduct and iManufacturer and some other members. But somehow, for some reason I am unable to access these members, so when I do a dmesg after inserting my module, it prints some garbage values. I would be glad to receive help or hints or any response. Following is the code that I have written so far: P.S.: Necessary inclusions have been made. Having gone through almost all the necessary header files, I know that I can access the vendor ID, product ID, and manufacturer details of the USB device through a structure: struct usb_device<> which has a member struct usb_device_descriptor<> . This nested structure has idVendor, idProduct and iManufacturer and some other members.

//******************************************* struct usb_device udev; struct usb_bus *bus; ssize_t ret; static int __init usb_fun_init(void) < int result; __le16 idVendor = 0; __le16 idProduct = 0; __u8 iManufacturer = 0; printk(KERN_INFO "\n************************************ in init\n"); list_for_each_entry(bus, &usb_bus_list, bus_list)< printk(KERN_INFO "***************** Begins ****************"); printk(KERN_INFO "\nVendor udev.descriptor.idVendor); printk(KERN_INFO "\nProduct udev.descriptor.idProduct); printk(KERN_INFO "\nManufacturer = %s", udev.descriptor.iManufacturer); return 0; >static int __exit usb_fun_exit(void) < printk(KERN_INFO "\n************************************ in exit\n"); >module_init(usb_fun_init); module_exit(usb_fun_exit); MODULE_LICENSE("GPL"); 

Are you sure you need kernel module? Maybe this would be simpler to work with that device in userspace?

@peterSmith : Thank you for kind reply. But Sir, I have to implement this in kernel-space only. I have tried doing it in user-space using libusb. And, It works absolutely fine over there. Where I am getting issues is in kernel-space.

Источник

Оцените статью
Adblock
detector