158 lines
5.6 KiB
C
158 lines
5.6 KiB
C
|
/*
|
||
|
* Derived from Linux kernel usb.h
|
||
|
*
|
||
|
* GPL-2.0-or-later
|
||
|
*
|
||
|
* Userspace port (C) 2019 Hak5 Inc
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#ifndef __USB_H__
|
||
|
#define __USB_H__
|
||
|
|
||
|
#include "kernel/types.h"
|
||
|
|
||
|
#define USB_DEVICE_ID_MATCH_DEVICE \
|
||
|
(USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
|
||
|
#define USB_DEVICE_ID_MATCH_DEV_RANGE \
|
||
|
(USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI)
|
||
|
#define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
|
||
|
(USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)
|
||
|
#define USB_DEVICE_ID_MATCH_DEV_INFO \
|
||
|
(USB_DEVICE_ID_MATCH_DEV_CLASS | \
|
||
|
USB_DEVICE_ID_MATCH_DEV_SUBCLASS | \
|
||
|
USB_DEVICE_ID_MATCH_DEV_PROTOCOL)
|
||
|
#define USB_DEVICE_ID_MATCH_INT_INFO \
|
||
|
(USB_DEVICE_ID_MATCH_INT_CLASS | \
|
||
|
USB_DEVICE_ID_MATCH_INT_SUBCLASS | \
|
||
|
USB_DEVICE_ID_MATCH_INT_PROTOCOL)
|
||
|
|
||
|
/**
|
||
|
* USB_DEVICE - macro used to describe a specific usb device
|
||
|
* @vend: the 16 bit USB Vendor ID
|
||
|
* @prod: the 16 bit USB Product ID
|
||
|
*
|
||
|
* This macro is used to create a struct usb_device_id that matches a
|
||
|
* specific device.
|
||
|
*/
|
||
|
#define USB_DEVICE(vend, prod) \
|
||
|
.match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
|
||
|
.idVendor = (vend), \
|
||
|
.idProduct = (prod)
|
||
|
|
||
|
/**
|
||
|
* struct usb_device_id - identifies USB devices for probing and hotplugging
|
||
|
* @match_flags: Bit mask controlling which of the other fields are used to
|
||
|
* match against new devices. Any field except for driver_info may be
|
||
|
* used, although some only make sense in conjunction with other fields.
|
||
|
* This is usually set by a USB_DEVICE_*() macro, which sets all
|
||
|
* other fields in this structure except for driver_info.
|
||
|
* @idVendor: USB vendor ID for a device; numbers are assigned
|
||
|
* by the USB forum to its members.
|
||
|
* @idProduct: Vendor-assigned product ID.
|
||
|
* @bcdDevice_lo: Low end of range of vendor-assigned product version numbers.
|
||
|
* This is also used to identify individual product versions, for
|
||
|
* a range consisting of a single device.
|
||
|
* @bcdDevice_hi: High end of version number range. The range of product
|
||
|
* versions is inclusive.
|
||
|
* @bDeviceClass: Class of device; numbers are assigned
|
||
|
* by the USB forum. Products may choose to implement classes,
|
||
|
* or be vendor-specific. Device classes specify behavior of all
|
||
|
* the interfaces on a device.
|
||
|
* @bDeviceSubClass: Subclass of device; associated with bDeviceClass.
|
||
|
* @bDeviceProtocol: Protocol of device; associated with bDeviceClass.
|
||
|
* @bInterfaceClass: Class of interface; numbers are assigned
|
||
|
* by the USB forum. Products may choose to implement classes,
|
||
|
* or be vendor-specific. Interface classes specify behavior only
|
||
|
* of a given interface; other interfaces may support other classes.
|
||
|
* @bInterfaceSubClass: Subclass of interface; associated with bInterfaceClass.
|
||
|
* @bInterfaceProtocol: Protocol of interface; associated with bInterfaceClass.
|
||
|
* @bInterfaceNumber: Number of interface; composite devices may use
|
||
|
* fixed interface numbers to differentiate between vendor-specific
|
||
|
* interfaces.
|
||
|
* @driver_info: Holds information used by the driver. Usually it holds
|
||
|
* a pointer to a descriptor understood by the driver, or perhaps
|
||
|
* device flags.
|
||
|
*
|
||
|
* In most cases, drivers will create a table of device IDs by using
|
||
|
* USB_DEVICE(), or similar macros designed for that purpose.
|
||
|
* They will then export it to userspace using MODULE_DEVICE_TABLE(),
|
||
|
* and provide it to the USB core through their usb_driver structure.
|
||
|
*
|
||
|
* See the usb_match_id() function for information about how matches are
|
||
|
* performed. Briefly, you will normally use one of several macros to help
|
||
|
* construct these entries. Each entry you provide will either identify
|
||
|
* one or more specific products, or will identify a class of products
|
||
|
* which have agreed to behave the same. You should put the more specific
|
||
|
* matches towards the beginning of your table, so that driver_info can
|
||
|
* record quirks of specific products.
|
||
|
*/
|
||
|
struct usb_device_id {
|
||
|
/* which fields to match against? */
|
||
|
__u16 match_flags;
|
||
|
|
||
|
/* Used for product specific matches; range is inclusive */
|
||
|
__u16 idVendor;
|
||
|
__u16 idProduct;
|
||
|
__u16 bcdDevice_lo;
|
||
|
__u16 bcdDevice_hi;
|
||
|
|
||
|
/* Used for device class matches */
|
||
|
__u8 bDeviceClass;
|
||
|
__u8 bDeviceSubClass;
|
||
|
__u8 bDeviceProtocol;
|
||
|
|
||
|
/* Used for interface class matches */
|
||
|
__u8 bInterfaceClass;
|
||
|
__u8 bInterfaceSubClass;
|
||
|
__u8 bInterfaceProtocol;
|
||
|
|
||
|
/* Used for vendor-specific interface matches */
|
||
|
__u8 bInterfaceNumber;
|
||
|
};
|
||
|
|
||
|
/* Some useful macros to use to create struct usb_device_id */
|
||
|
#define USB_DEVICE_ID_MATCH_VENDOR 0x0001
|
||
|
#define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
|
||
|
#define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
|
||
|
#define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
|
||
|
#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
|
||
|
#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
|
||
|
#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
|
||
|
#define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
|
||
|
#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
|
||
|
#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
|
||
|
#define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
|
||
|
|
||
|
/*
|
||
|
* USB directions
|
||
|
*
|
||
|
* This bit flag is used in endpoint descriptors' bEndpointAddress field.
|
||
|
* It's also one of three fields in control requests bRequestType.
|
||
|
*/
|
||
|
#define USB_DIR_OUT 0 /* to device */
|
||
|
#define USB_DIR_IN 0x80 /* to host */
|
||
|
|
||
|
/*
|
||
|
* USB types, the second of three bRequestType fields
|
||
|
*/
|
||
|
#define USB_TYPE_MASK (0x03 << 5)
|
||
|
#define USB_TYPE_STANDARD (0x00 << 5)
|
||
|
#define USB_TYPE_CLASS (0x01 << 5)
|
||
|
#define USB_TYPE_VENDOR (0x02 << 5)
|
||
|
#define USB_TYPE_RESERVED (0x03 << 5)
|
||
|
|
||
|
/*
|
||
|
* USB recipients, the third of three bRequestType fields
|
||
|
*/
|
||
|
#define USB_RECIP_MASK 0x1f
|
||
|
#define USB_RECIP_DEVICE 0x00
|
||
|
#define USB_RECIP_INTERFACE 0x01
|
||
|
#define USB_RECIP_ENDPOINT 0x02
|
||
|
#define USB_RECIP_OTHER 0x03
|
||
|
/* From Wireless USB 1.0 */
|
||
|
#define USB_RECIP_PORT 0x04
|
||
|
#define USB_RECIP_RPIPE 0x05
|
||
|
|
||
|
#endif /* ifndef USB_H */
|