STRUCT USB_DEVICE_ID(9)
π struct usb_device_id β Kernel API Manual, but make it cute
okay so bestie, this is literally the glow-up guide for struct usb_device_id β the little struct that goes "hiii this is my device" when the kernel is probing stuff and hotplugging stuff. it's giving β¨matchmakerβ¨ energy, no cap.
πΈ NAME
struct usb_device_id β identifies USB devices for probing and hotplugging. that's it, that's the whole vibe. it's the little ID card your device waves around so the kernel knows who to hand it to π«Ά
β¨ SYNOPSIS
struct usb_device_id {
__u16 match_flags;
__u16 idVendor;
__u16 idProduct;
__u16 bcdDevice_lo;
__u16 bcdDevice_hi;
__u8 bDeviceClass;
__u8 bDeviceSubClass;
__u8 bDeviceProtocol;
__u8 bInterfaceClass;
__u8 bInterfaceSubClass;
__u8 bInterfaceProtocol;
__u8 bInterfaceNumber;
kernel_ulong_t driver_info;
};
look at her. fourteen fields. main character energy fr fr π
π Members (the whole cast, no one gets cut)
match_flagsβ the bit mask that decides which of the other fields actually get used when matching against new devices. any field exceptdriver_infocan be used, but ngl some of them only make sense when they're paired up with other fields. this one is usually set by aUSB_DEVICE_*()macro, and that macro sets all the other fields in this struct too β exceptdriver_info, which is on its own little journey πidVendorβ the USB vendor ID for a device. these numbers get assigned by the USB forum to its members. it's the family name, basically πidProductβ the product ID, and this one is assigned by the vendor themselves. very "my house, my rules."bcdDevice_loβ the low end of the range of vendor-assigned product version numbers. also used to identify individual product versions, for a range that consists of a single device. so like, a range of one. iconic πbcdDevice_hiβ the high end of the version number range. and heads up, the range of product versions is inclusive β both ends count, no sneaky exclusions π―bDeviceClassβ the class of the device; numbers assigned by the USB forum. products can choose to implement classes or just be vendor-specific, whichever. device classes specify the behavior of all the interfaces on a device β so it's the whole-device mood, not a per-interface one πbDeviceSubClassβ subclass of the device. it's associated withbDeviceClass, they're a package deal π«ΆbDeviceProtocolβ protocol of the device. also associated withbDeviceClass. the trio is complete.bInterfaceClassβ class of an interface; numbers assigned by the USB forum. products may implement classes or be vendor-specific. and this one's different frombDeviceClass, okurrr: interface classes specify behavior only of a given interface β other interfaces on that same device may support other classes. so it's giving per-interface personality πΈbInterfaceSubClassβ subclass of the interface. associated withbInterfaceClass. matching set πbInterfaceProtocolβ protocol of the interface. also associated withbInterfaceClass.bInterfaceNumberβ number of the interface. composite devices may use fixed interface numbers to differentiate between vendor-specific interfaces. lowkey the bouncer at the club checking which door you go through πdriver_infoβ holds information used by the driver. usually it holds a pointer to a descriptor that the driver understands, or maybe device flags. the one field the macros don't touch, remember π
π₯ Description
in most cases, drivers will create a table of device IDs by using USB_DEVICE, or similar macros designed for exactly that purpose. then they export it to userspace using MODULE_DEVICE_TABLE, and hand it over to the USB core through their usb_driver structure. whole pipeline. slay β¨
if you wanna know how the matching actually happens, go see the usb_match_id function β that's the one doing the work. but briefly (because we're being efficient here π
): you'll normally use one of several macros to help construct these entries. each entry you provide will either identify one or more specific products, or identify a class of products that have agreed to behave the same.
and here's the tip that actually matters: put the more specific matches towards the beginning of your table, so that driver_info can record quirks of specific products. order matters bestie, don't come crying to me when the generic entry eats your special one π
π SEE ALSO
- Kernel file
./include/linux/device-id/usb.h
ok so real talk before you go: everything above is exactly what the page says β nothing added, nothing dropped. go forth and match some devices π¦
that's the whole page, mwah π β this was struct usb_device_id(9) from the Kernel API Manual, sourced from ./include/linux/device-id, dated October 2026. ok bye bestie, drink some water π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms