Linux vendor id device id

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?

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.

Читайте также:  Поменять часовой пояс linux ubuntu

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

Источник

PCI-id

На самом деле также есть несколько sub-vendor-id, sub-vendor-id (для определения реализации компьютера/поставщика), функций и классов pci. Для получения дополнительной информации см. дополнительную информацию.

Некоторые из поддерживаемых Debian устройств (device-id) перечислены на странице : DeviceDatabase/PCI.

lspci

lspci [пакет:pciutils] — стандартный инструмент для запроса устройств подключённых к любым pci-совместимым шинам.

Пример вывода (опция «-nn» работает только с новыми версиями Linux):

lspci -nn 00:00.0 Host bridge [0600]: Intel Corporation Mobile 945GM/PM/GMS, 943/940GML and 945GT Express Memory Controller Hub [8086:27a0] (rev 03) 00:02.0 VGA compatible controller [0300]: Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller [8086:27a2] (rev 03) 00:02.1 Display controller [0380]: Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller [8086:27a6] (rev 03) 00:1b.0 Audio device [0403]: Intel Corporation 82801G (ICH7 Family) High Definition Audio Controller [8086:27d8] (rev 02) 00:1c.0 PCI bridge [0604]: Intel Corporation 82801G (ICH7 Family) PCI Express Port 1 [8086:27d0] (rev 02) 00:1c.1 PCI bridge [0604]: Intel Corporation 82801G (ICH7 Family) PCI Express Port 2 [8086:27d2] (rev 02) 00:1c.2 PCI bridge [0604]: Intel Corporation 82801G (ICH7 Family) PCI Express Port 3 [8086:27d4] (rev 02) 00:1c.3 PCI bridge [0604]: Intel Corporation 82801G (ICH7 Family) PCI Express Port 4 [8086:27d6] (rev 02) 00:1d.0 USB Controller [0c03]: Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #1 [8086:27c8] (rev 02) 00:1d.1 USB Controller [0c03]: Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #2 [8086:27c9] (rev 02) 00:1d.2 USB Controller [0c03]: Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #3 [8086:27ca] (rev 02) 00:1d.3 USB Controller [0c03]: Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #4 [8086:27cb] (rev 02) 00:1d.7 USB Controller [0c03]: Intel Corporation 82801G (ICH7 Family) USB2 EHCI Controller [8086:27cc] (rev 02) 00:1e.0 PCI bridge [0604]: Intel Corporation 82801 Mobile PCI Bridge [8086:2448] (rev e2) 00:1f.0 ISA bridge [0601]: Intel Corporation 82801GBM (ICH7-M) LPC Interface Bridge [8086:27b9] (rev 02) 00:1f.2 IDE interface [0101]: Intel Corporation 82801GBM/GHM (ICH7 Family) SATA IDE Controller [8086:27c4] (rev 02) 00:1f.3 SMBus [0c05]: Intel Corporation 82801G (ICH7 Family) SMBus Controller [8086:27da] (rev 02) 02:00.0 Ethernet controller [0200]: Intel Corporation 82573L Gigabit Ethernet Controller [8086:109a] 03:00.0 Network controller [0280]: Intel Corporation PRO/Wireless 3945ABG Network Connection [8086:4227] (rev 02) 15:00.0 CardBus bridge [0607]: Texas Instruments PCI1510 PC card Cardbus Controller [104c:ac56] 16:00.0 Ethernet controller [0200]: ADMtek 21x4x DEC-Tulip compatible 10/100 Ethernet [1317:1985] (rev 11)
  • 104c:ac56 — мост («контроллер») cardbus
  • 1317:1985 — интернет-адаптер PCCard (32-bit Cardbus).
  • если вывод описания устройства: «Unknown device», вы можете обновить локальное определение pci-id, запустив от root update-pciids.
Читайте также:  Mount iso write linux

» width=»16″ height=»16″/> man (8)lspci (8)update-pciids
» width=»16″ height=»16″/> /usr/share/misc/pci.ids — Файл отображающий vendor ID и device ID в текстовом виде.

Чтобы сократить список можно использовать grep:

~$ lspci -nn | grep Network 03:00.0 Network controller [0280]: Intel Corporation PRO/Wireless 3945ABG Network Connection [8086:4227] (rev 02)

В Gnome : hardinfo

Информационная система Gnome (в меню /Приложения/Системные/System Profiler and Benchmark, из пакета:hardinfo) на странице «PCI Devices».

В KDE : KInfocenter

KDE KInfo Center (в K Menu / System / KInfo Center Info Center, из пакета:kcontrol) имеет информационную страницу на «PCI».

Примечание: KInfo Center выводит названия устройств PCI, а не PCI ID.

discover

В пакете discover есть удобная команда:

discover --vendor-id --model-id pci | uniq 8086 27a0 Intel Corporation Mobile 945GM/PM/GMS, 943/940GML and 945GT Express Memory Controller Hub 8086 27a0 Intel Corporation Mobile 945GM/PM/GMS/940GML and 945GT Express Memory Controller Hub 8086 27a2 Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller 8086 27a2 Intel Corporation Mobile 945GM/GMS/940GML Express Integrated Graphics Controller 8086 27a6 Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller 8086 27a6 Intel Corporation Mobile 945GM/GMS/940GML Express Integrated Graphics Controller 8086 27d8 Intel Corporation 82801G (ICH7 Family) High Definition Audio Controller 8086 27d0 Intel Corporation 82801G (ICH7 Family) PCI Express Port 1 8086 27d2 Intel Corporation 82801G (ICH7 Family) PCI Express Port 2 8086 27d4 Intel Corporation 82801G (ICH7 Family) PCI Express Port 3 8086 27d6 Intel Corporation 82801G (ICH7 Family) PCI Express Port 4 8086 27c8 Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #1 8086 27c8 Intel Corporation 82801G (ICH7 Family) USB UHCI #1 8086 27c9 Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #2 8086 27c9 Intel Corporation 82801G (ICH7 Family) USB UHCI #2 8086 27ca Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #3 8086 27ca Intel Corporation 82801G (ICH7 Family) USB UHCI #3 8086 27cb Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #4 8086 27cb Intel Corporation 82801G (ICH7 Family) USB UHCI #4 8086 27cc Intel Corporation 82801G (ICH7 Family) USB2 EHCI Controller 8086 2448 Intel Corporation 82801 Mobile PCI Bridge 8086 27b9 Intel Corporation 82801GBM (ICH7-M) LPC Interface Bridge 8086 27c4 Intel Corporation 82801GBM/GHM (ICH7 Family) SATA IDE Controller 8086 27da Intel Corporation 82801G (ICH7 Family) SMBus Controller 8086 109a Intel Corporation 82573L Gigabit Ethernet Controller8086 4227 Intel Corporation PRO/Wireless 3945ABG Network Connection 104c ac56 Texas Instruments PCI1510 PC card Cardbus Controller

» width=»16″ height=»16″/> man discover(1)
» width=»16″ height=»16″/> Файлы по использованию: /lib/discover/pci-busclass.xml, /lib/discover/pci-device.xml, /lib/discover/pci-vendor.xml

Читайте также:  Команда linux получить права

Подробнее

/proc/bus/pci/devices

Если lspci не доступен (!), вы можно посмотреть содержимое /proc/bus/pci/devices для получения vendor и device ID.

/sys/bus/pci

Если lspci не доступен (!), вы можете посмотреть /sys/bus/pci (предполагается что sysfs смонтирован в /sys).

<i data-lazy-src=

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