?? usb.h
字號:
#ifndef __LINUX_USB_H#define __LINUX_USB_H/* USB constants *//* * Device and/or Interface Class codes */#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */#define USB_CLASS_AUDIO 1#define USB_CLASS_COMM 2#define USB_CLASS_HID 3#define USB_CLASS_PHYSICAL 5#define USB_CLASS_STILL_IMAGE 6#define USB_CLASS_PRINTER 7#define USB_CLASS_MASS_STORAGE 8#define USB_CLASS_HUB 9#define USB_CLASS_CDC_DATA 0x0a#define USB_CLASS_CSCID 0x0b /* chip+ smart card */#define USB_CLASS_CONTENT_SEC 0x0d /* content security */#define USB_CLASS_APP_SPEC 0xfe#define USB_CLASS_VENDOR_SPEC 0xff/* * USB types */#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 */#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/* * USB directions */#define USB_DIR_OUT 0 /* to device */#define USB_DIR_IN 0x80 /* to host *//* * Descriptor types */#define USB_DT_DEVICE 0x01#define USB_DT_CONFIG 0x02#define USB_DT_STRING 0x03#define USB_DT_INTERFACE 0x04#define USB_DT_ENDPOINT 0x05#define USB_DT_HID (USB_TYPE_CLASS | 0x01)#define USB_DT_REPORT (USB_TYPE_CLASS | 0x02)#define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)#define USB_DT_HUB (USB_TYPE_CLASS | 0x09)/* * Descriptor sizes per descriptor type */#define USB_DT_DEVICE_SIZE 18#define USB_DT_CONFIG_SIZE 9#define USB_DT_INTERFACE_SIZE 9#define USB_DT_ENDPOINT_SIZE 7#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */#define USB_DT_HUB_NONVAR_SIZE 7#define USB_DT_HID_SIZE 9/* * Endpoints */#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */#define USB_ENDPOINT_DIR_MASK 0x80#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */#define USB_ENDPOINT_XFER_CONTROL 0#define USB_ENDPOINT_XFER_ISOC 1#define USB_ENDPOINT_XFER_BULK 2#define USB_ENDPOINT_XFER_INT 3/* * USB Packet IDs (PIDs) */#define USB_PID_UNDEF_0 0xf0#define USB_PID_OUT 0xe1#define USB_PID_ACK 0xd2#define USB_PID_DATA0 0xc3#define USB_PID_PING 0xb4 /* USB 2.0 */#define USB_PID_SOF 0xa5#define USB_PID_NYET 0x96 /* USB 2.0 */#define USB_PID_DATA2 0x87 /* USB 2.0 */#define USB_PID_SPLIT 0x78 /* USB 2.0 */#define USB_PID_IN 0x69#define USB_PID_NAK 0x5a#define USB_PID_DATA1 0x4b#define USB_PID_PREAMBLE 0x3c /* Token mode */#define USB_PID_ERR 0x3c /* USB 2.0: handshake mode */#define USB_PID_SETUP 0x2d#define USB_PID_STALL 0x1e#define USB_PID_MDATA 0x0f /* USB 2.0 *//* * Standard requests */#define USB_REQ_GET_STATUS 0x00#define USB_REQ_CLEAR_FEATURE 0x01#define USB_REQ_SET_FEATURE 0x03#define USB_REQ_SET_ADDRESS 0x05#define USB_REQ_GET_DESCRIPTOR 0x06#define USB_REQ_SET_DESCRIPTOR 0x07#define USB_REQ_GET_CONFIGURATION 0x08#define USB_REQ_SET_CONFIGURATION 0x09#define USB_REQ_GET_INTERFACE 0x0A#define USB_REQ_SET_INTERFACE 0x0B#define USB_REQ_SYNCH_FRAME 0x0C/* * HID requests */#define USB_REQ_GET_REPORT 0x01#define USB_REQ_GET_IDLE 0x02#define USB_REQ_GET_PROTOCOL 0x03#define USB_REQ_SET_REPORT 0x09#define USB_REQ_SET_IDLE 0x0A#define USB_REQ_SET_PROTOCOL 0x0B#ifdef __KERNEL__#include <linux/types.h>#include <linux/ioctl.h>#include <linux/version.h>#include <linux/sched.h>#include <linux/delay.h>#include <linux/interrupt.h> /* for in_interrupt() */#include <linux/config.h>#include <linux/list.h>#define USB_MAJOR 180static __inline__ void wait_ms(unsigned int ms){ if(!in_interrupt()) { current->state = TASK_UNINTERRUPTIBLE; schedule_timeout(1 + ms * HZ / 1000); } else mdelay(ms);}/** * struct usb_ctrlrequest - structure used to make USB device control requests easier to create and decode * @bRequestType: matches the USB bmRequestType field * @bRequest: matches the USB bRequest field * @wValue: matches the USB wValue field * @wIndex: matches the USB wIndex field * @wLength: matches the USB wLength field * * This structure is used to send control requests to a USB device. It matches * the different fields of the USB 2.0 Spec section 9.3, table 9-2. See the * USB spec for a fuller description of the different fields, and what they are * used for. */struct usb_ctrlrequest { __u8 bRequestType; __u8 bRequest; __u16 wValue; __u16 wIndex; __u16 wLength;} __attribute__ ((packed));/* * USB-status codes: * USB_ST* maps to -E* and should go away in the future */#define USB_ST_NOERROR 0#define USB_ST_CRC (-EILSEQ)#define USB_ST_BITSTUFF (-EPROTO)#define USB_ST_NORESPONSE (-ETIMEDOUT) /* device not responding/handshaking */#define USB_ST_DATAOVERRUN (-EOVERFLOW)#define USB_ST_DATAUNDERRUN (-EREMOTEIO)#define USB_ST_BUFFEROVERRUN (-ECOMM)#define USB_ST_BUFFERUNDERRUN (-ENOSR)#define USB_ST_INTERNALERROR (-EPROTO) /* unknown error */#define USB_ST_SHORT_PACKET (-EREMOTEIO)#define USB_ST_PARTIAL_ERROR (-EXDEV) /* ISO transfer only partially completed */#define USB_ST_URB_KILLED (-ENOENT) /* URB canceled by user */#define USB_ST_URB_PENDING (-EINPROGRESS)#define USB_ST_REMOVED (-ENODEV) /* device not existing or removed */#define USB_ST_TIMEOUT (-ETIMEDOUT) /* communication timed out, also in urb->status**/#define USB_ST_NOTSUPPORTED (-ENOSYS) #define USB_ST_BANDWIDTH_ERROR (-ENOSPC) /* too much bandwidth used */#define USB_ST_URB_INVALID_ERROR (-EINVAL) /* invalid value/transfer type */#define USB_ST_URB_REQUEST_ERROR (-ENXIO) /* invalid endpoint */#define USB_ST_STALL (-EPIPE) /* pipe stalled, also in urb->status*//* * USB device number allocation bitmap. There's one bitmap * per USB tree. */struct usb_devmap { unsigned long devicemap[128 / (8*sizeof(unsigned long))];};#define USB_MAXBUS 64struct usb_busmap { unsigned long busmap[USB_MAXBUS / (8*sizeof(unsigned long))];};/* * This is a USB device descriptor. * * USB device information *//* Everything but the endpoint maximums are aribtrary */#define USB_MAXCONFIG 8#define USB_ALTSETTINGALLOC 4#define USB_MAXALTSETTING 128 /* Hard limit */#define USB_MAXINTERFACES 32#define USB_MAXENDPOINTS 32/* All standard descriptors have these 2 fields in common */struct usb_descriptor_header { __u8 bLength; __u8 bDescriptorType;} __attribute__ ((packed));/* Device descriptor */struct usb_device_descriptor { __u8 bLength; __u8 bDescriptorType; __u16 bcdUSB; __u8 bDeviceClass; __u8 bDeviceSubClass; __u8 bDeviceProtocol; __u8 bMaxPacketSize0; __u16 idVendor; __u16 idProduct; __u16 bcdDevice; __u8 iManufacturer; __u8 iProduct; __u8 iSerialNumber; __u8 bNumConfigurations;} __attribute__ ((packed));/* Endpoint descriptor */struct usb_endpoint_descriptor { __u8 bLength __attribute__ ((packed)); __u8 bDescriptorType __attribute__ ((packed)); __u8 bEndpointAddress __attribute__ ((packed)); __u8 bmAttributes __attribute__ ((packed)); __u16 wMaxPacketSize __attribute__ ((packed)); __u8 bInterval __attribute__ ((packed)); __u8 bRefresh __attribute__ ((packed)); __u8 bSynchAddress __attribute__ ((packed)); unsigned char *extra; /* Extra descriptors */ int extralen;};/* Interface descriptor */struct usb_interface_descriptor { __u8 bLength __attribute__ ((packed)); __u8 bDescriptorType __attribute__ ((packed)); __u8 bInterfaceNumber __attribute__ ((packed)); __u8 bAlternateSetting __attribute__ ((packed)); __u8 bNumEndpoints __attribute__ ((packed)); __u8 bInterfaceClass __attribute__ ((packed)); __u8 bInterfaceSubClass __attribute__ ((packed)); __u8 bInterfaceProtocol __attribute__ ((packed)); __u8 iInterface __attribute__ ((packed)); struct usb_endpoint_descriptor *endpoint; unsigned char *extra; /* Extra descriptors */ int extralen;};struct usb_interface { struct usb_interface_descriptor *altsetting; int act_altsetting; /* active alternate setting */ int num_altsetting; /* number of alternate settings */ int max_altsetting; /* total memory allocated */ struct usb_driver *driver; /* driver */ void *private_data;};/* Configuration descriptor information.. */struct usb_config_descriptor { __u8 bLength __attribute__ ((packed)); __u8 bDescriptorType __attribute__ ((packed)); __u16 wTotalLength __attribute__ ((packed)); __u8 bNumInterfaces __attribute__ ((packed)); __u8 bConfigurationValue __attribute__ ((packed)); __u8 iConfiguration __attribute__ ((packed)); __u8 bmAttributes __attribute__ ((packed)); __u8 MaxPower __attribute__ ((packed)); struct usb_interface *interface; unsigned char *extra; /* Extra descriptors */ int extralen;};/* String descriptor */struct usb_string_descriptor { __u8 bLength; __u8 bDescriptorType; __u16 wData[1];} __attribute__ ((packed));struct usb_device;/* * Device table entry for "new style" table-driven USB drivers. * User mode code can read these tables to choose which modules to load. * Declare the table as __devinitdata, and as a MODULE_DEVICE_TABLE. * * With a device table provide bind() instead of probe(). Then the * third bind() parameter will point to a matching entry from this * table. (Null value reserved.) * * Terminate the driver's table with an all-zeroes entry. * Init the fields you care about; zeroes are not used in comparisons. */#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_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)/* Some useful macros */#define USB_DEVICE(vend,prod) \ match_flags: USB_DEVICE_ID_MATCH_DEVICE, idVendor: (vend), idProduct: (prod)#define USB_DEVICE_VER(vend,prod,lo,hi) \ match_flags: USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, idVendor: (vend), idProduct: (prod), bcdDevice_lo: (lo), bcdDevice_hi: (hi)#define USB_DEVICE_INFO(cl,sc,pr) \ match_flags: USB_DEVICE_ID_MATCH_DEV_INFO, bDeviceClass: (cl), bDeviceSubClass: (sc), bDeviceProtocol: (pr)#define USB_INTERFACE_INFO(cl,sc,pr) \ match_flags: USB_DEVICE_ID_MATCH_INT_INFO, bInterfaceClass: (cl), bInterfaceSubClass: (sc), bInterfaceProtocol: (pr)struct usb_device_id { /* This bitmask is used to determine which of the following fields * are to be used for matching. */ __u16 match_flags; /* * vendor/product codes are checked, if vendor is nonzero * Range is for device revision (bcdDevice), inclusive; * zero values here mean range isn't considered */ __u16 idVendor; __u16 idProduct; __u16 bcdDevice_lo, bcdDevice_hi;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -