📄 usbdef.h
字号:
/* usbdef.h - Nereid USB Monitor / USB Definition * Copyright (C) 2003 Tachibana Eriko * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#ifndef usbdef_h#define usbdef_h/* Setup Packet *//* See: usb11.pdf P.183 ([9.3] USB Device Requests) */typedef struct { unsigned char bmRequestType; /* bit7:Direction bit6-5:Type bit4-0:Recipient */ unsigned char bRequest; /* Specific request */ unsigned short wValue; /* According to request */ unsigned short wIndex; /* Typically used to pass an index or offset */ unsigned short wLength; /* Number of bytes to transfer if there is a Data stage */} SetupData;#define sizeof_SetupData 8#define DATA_TRANSFER_DIRECTION 0x80typedef enum { /* bmRequest */ DIR_HOST2DEVICE = 0x00, DIR_DEVICE2HOST = 0x80,} setupDataTransferDirection;typedef enum { /* bmRequest */ TYPE_STANDARD = 0x00, TYPE_CLASS = 0x20, TYPE_VENDOR = 0x40,} setupType;typedef enum { /* bmRequest */ REC_DEVICE = 0x00, REC_INTERFACE = 0x01, REC_ENDPOINT = 0x02, REC_OTHER = 0x03,} setupRecipient;/* Standard Request Codes (SetupData.bRequest) *//* See: usb11.pdf P.187 ([9.4] Standard Device Requests) *//* P.267 ([11.16.2] Class-specific Requests) *//* usb_20.pdf P.251 ([9.4] Standard Device Requests) */enum setupStandardRequestCode { REQ_GET_STATUS = 0, REQ_CLEAR_FEATURE = 1, /* = 2, */ /* Reserved for future use */ REQ_SET_FEATURE = 3, /* = 4, */ /* Reserved for future use */ REQ_SET_ADDRESS = 5, REQ_GET_DESCRIPTOR = 6, REQ_SET_DESCRIPTOR = 7, REQ_GET_CONFIGURATION = 8, REQ_SET_CONFIGURATION = 9, REQ_GET_INTERFACE = 10, REQ_SET_INTERFACE = 11, REQ_SYNCH_FRAME = 12,};/* Hub Class Request Codes (SetupData.bRequest) *//* See: usb_20.pdf P.420 ([11.24.2] Class-specific Requests) */enum setupHubClassRequestCode { HUB_GET_STATUS = 0, HUB_CLEAR_FEATURE = 1, HUB_GET_STATE = 2, /* USB1.x HUB class only */ HUB_SET_FEATURE = 3, /* = 4, */ /* Reserved for future use */ /* = 5, */ /* Reserved for future use */ HUB_GET_DESCRIPTOR = 6, HUB_SET_DESCRIPTOR = 7, HUB_CLEAR_TT_BUFFER = 8, HUB_RESET_TT = 9, HUB_GET_TT_STATE = 10, HUB_STOP_TT = 11,};/* Descriptor Types (SetupData.wValue) *//* See: usb11.pdf P.187 ([9.4] Standard Device Requests) *//* P.264 ([11.15.2.1 Hub Descriptor) *//* usb_20.pdf P.251 ([9.4] Standard Device Requests) *//* HID1_11.pdf P.49 ([7.1] Standard Requests) *//* USB 僐儞僾儕乕僩 [戞擇斉] P.88, P.242 */typedef enum { /* Standard */ DES_DEVICE = 0x01, DES_CONFIGURATION = 0x02, DES_STRING = 0x03, DES_INTERFACE = 0x04, DES_ENDPOINT = 0x05, /* USB2.0 */ DES_DEVICE_QUALIFIER = 0x06, DES_OTHER_SPEED_CONFIGURATION = 0x07, DES_INTERFACE_POWER = 0x08, /* HID Class */ DES_HID = 0x21, DES_HID_REPORT = 0x22, DES_HID_PHYSICAL = 0x23, /* HUB Class */ DES_HUB = 0x29,} setupDescriptorType;/* Device Class Codes (DevDesc.bDeviceClass) *//* See: http://www.usb.org/developers/defined_class */enum DeviceClassType { DEVCLASS_AT_INTERFACE_LEVEL = 0x00, DEVCLASS_COMMUNICATION = 0x02, DEVCLASS_HUB = 0x09, DEVCLASS_DIAGNOSTIC = 0xdc, DEVCLASS_WIRELESS_CONTROLLER = 0xe0, DEVCLASS_MISCELLANEOUS = 0xef, DEVCLASS_VENDOR_SPECIFIC = 0xff,};/* Interface Class Codes (IntfDesc.bInterfaceClass) *//* See: http://www.usb.org/developers/defined_class */enum InterfaceClassType { CLASS_AUDIO = 0x01, CLASS_CDC_CONTROL = 0x02, CLASS_HID = 0x03, CLASS_PHYSICAL = 0x05, CLASS_IMAGE = 0x06, CLASS_PRINTER = 0x07, CLASS_MASS_STORAGE = 0x08, CLASS_HUB = 0x09, CLASS_CDC_DATA = 0x0a, CLASS_CHIP_SMART_CARD = 0x0b, CLASS_CONTENT_SECURITY = 0x0d, CLASS_VIDEO = 0x0e, CLASS_DIAGNOSTIC = 0xdc, CLASS_WIRELESS_CONTROLLER = 0xe0, CLASS_APPLICATION_SPECIFIC = 0xfe, CLASS_VENDOR_SPECIFIC = 0xff,};/* USB1.0, Standard Device Descriptor *//* See: usb11.pdf P.196 ([9.6.1] Device) */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* DEVICE Descriptor Type */ unsigned short bcdUSB; /* USB Specification Release Number in BCD */ unsigned char bDeviceClass; /* Class code (assigned by the USB) */ unsigned char bDeviceSubClass; /* Subclass code (assigned by the USB) */ unsigned char bDeviceProtocol; /* Protocol code (assigned by the USB) */ unsigned char bMaxPacketSize0; /* Maximum packet size for endpoint zero */ unsigned short idVendor; /* Vendor ID (assigned by the USB) */ unsigned short idProduct; /* Product ID (assigned by the manufacturer) */ unsigned short bcdDevice; /* Device release number in BCD */ unsigned char iManufacturer; /* Index of string descriptor describing manufacturer */ unsigned char iProduct; /* Index of string descriptor describing product */ unsigned char iSerialNumber; /* Index of string descriptor describing the device's serial number */ unsigned char bNumConfigurations; /* Number of possible configurations */} DevDesc;#define sizeof_DevDesc 18/* USB1.0, Standard Configuration Descriptor *//* See: usb11.pdf P.199 ([9.6.2] Configuration) */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* CONFIGURATION Descriptor Type */ unsigned short wTotalLength; /* Total length of data returned for this configuration */ unsigned char bNumInterfaces; /* Number of interfaces supported by this configuration */ unsigned char bConfigurationValue; /* Value to use as an argument to the SetConfiguration() request to select this configuration */ unsigned char iConfiguration; /* Index of string descriptor describing this configuration */ unsigned char bmAttributes; /* bit7:1 bit6:Self-powered bit5:Remote Wakeup */ unsigned char bMaxPower; /* Maximum power consumption of the USB device in this specific configuration */} ConfDesc;#define sizeof_ConfDesc 9/* USB1.0, Standard Interface Descriptor *//* See: usb11.pdf P.201 ([9.6.3] Interface) */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* INTERFACE Descriptor Type */ unsigned char bInterfaceNumber; /* Number of interface */ unsigned char bAlternateSetting; /* Value used to select alternate setting for the interface identified in the prior field */ unsigned char bNumEndpoints; /* Number of endpoints used by this interface */ unsigned char bInterfaceClass; /* Class code (assigned by the USB) */ unsigned char bInterfaceSubClass; /* Subclass code (assigned by the USB) */ unsigned char bInterfaceProtocol; /* Protocol code (assigned by the USB) */ unsigned char iInterface; /* Index of string descriptor describing this interface */} IntfDesc;#define sizeof_IntfDesc 9/* USB2.0, Standard Device Qualifier Descriptor *//* See: usb_20.pdf P.264 ([9.6.2] Device_Qualifier) *//* USB 僐儞僾儕乕僩 [戞擇斉] P.90 */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* DEVICE QUALIFIER Descriptor Type */ unsigned short bcdUSB; /* USB Specification Release Number in BCD */ unsigned char bDeviceClass; /* Class code (assigned by the USB) */ unsigned char bDeviceSubClass; /* Subclass code (assigned by the USB) */ unsigned char bDeviceProtocol; /* Protocol code (assigned by the USB) */ unsigned char bMaxPacketSize0; /* Maximum packet size for endpoint zero */ unsigned char bNumConfigurations; /* Number of possible configurations */ unsigned char bReserved; /* Reserved */} DevQuaDesc;#define sizeof_DevQuaDesc 10/* USB2.0, Standard Other Speed Configuration Descriptor *//* See: usb_20.pdf P.266 ([9.6.4] Other_Speed_Configuration) *//* USB 僐儞僾儕乕僩 [戞擇斉] P.93 */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* OTHER SPEED CONFIGURATION Descriptor Type */ unsigned short wTotalLength; /* Total length of data returned for this configuration */ unsigned char bNumInterfaces; /* Number of interfaces supported by this configuration */ unsigned char bConfigurationValue; /* Value to use as an argument to the SetConfiguration() request to select this configuration */ unsigned char iConfiguration; /* Index of string descriptor describing this configuration */ unsigned char bmAttributes; /* bit7:1 bit6:Self-powered bit5:Remote Wakeup */ unsigned char bMaxPower; /* Maximum power consumption of the USB device in this specific configuration */} OthSpConfDesc;#define sizeof_OthSpConfDesc 9/* USB2.0, Standard Interface Power Descriptor */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* Interface Power Descriptor Type */ unsigned char bmFlags; /* ??? */} IntfPwrDesc;#define sizeof_IntfPwrDesc 3/* USB1.0, HID Class Descriptor *//* See: HID1_11.pdf P.11 ([6.2.1] HID Descriptor) *//* USB 僐儞僾儕乕僩 [戞擇斉] P.242 *//* Notice: struct Report 偼 4 僶僀僩偲側偭偰偟傑偄丄 *//* 捠忢偺曽朄偱偼嶲徠偱偒側偄偺偱拲堄偡傞偙偲. */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* HID CLASS Descriptor Type */ unsigned short bcdHCD; /* HID Specification Release Number in BCD */ unsigned char bCountryCode; /* Country code of the localized hardware */ unsigned char bNumDescriptors; /* Number of class descriptors */ struct { unsigned char bDescriptorType; /* Type of class descriptor */ unsigned short wDescriptorLength __attribute__ ((packed)); } Report[1]; /* Total size of the Report descriptor */} HidDesc;#define sizeof_HidDesc 9 /* +2n *//* USB1.0, HID Class Report Descriptor *//* See: USB 僐儞僾儕乕僩 [戞擇斉] P.243 */typedef struct { /* ---- */} HidRepDesc;/* USB1.0, HID Class Physical Descriptor *//* See: USB 僐儞僾儕乕僩 [戞擇斉] P.269 */typedef struct { /* ---- */} HidPhyDesc;/* USB1.0, HUB Class Descriptor *//* See: usb11.pdf P.264 ([11.15.2.1] Hub Descriptor) *//* USB 僐儞僾儕乕僩 [戞擇斉] P.345 */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* HUB CLASS Descriptor Type */ unsigned char bNbrPorts; /* Number of downstream ports */ unsigned char wHubCharacteristics[2]; unsigned char bPwrOn2PwrGood; /* power-on time (2ms) */ unsigned char bHubContrCurrent; /* Maximum current requirements (mA) */ unsigned char DeviceRemovable[1]; /* Indicates if a port has a removable device attached */ unsigned char PortPowerCtrlMask[1]; /* for compatibility with 1.0 */} HubDesc;#define sizeof_HubDesc 9 /* +2n *//* USB1.0, Standard EndPoint Descriptor *//* See: usb11.pdf P.203 ([9.6.4] Endpoint) */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* ENDPOINT Descriptor Type */ unsigned char bEndpointAddress; /* bit7=0:OUT bit3-0:The endpoint number */ unsigned char bmAttributes; /* 0=Control 1=ISO 2=Bulk 3=Interrupt */ unsigned short wMaxPacketSize; /* Maximum packet size */ unsigned char bInterval; /* Interval for polling endpoint (ms) */} EpDesc;#define sizeof_EpDesc 7/* Codes Representing Languages Supported by the Device *//* See: usb11.pdf P.204 ([9.6.5] String) */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* STRING Descriptor Type */ unsigned short wLANGID[0]; /* LANGID code */} LangDesc;#define sizeof_LangDesc 2 /* +2n *//* USB1.0, UNICODE String Descriptor *//* See: usb11.pdf P.204 ([9.6.5] String) */typedef struct { unsigned char bLength; /* Size of this descriptor in bytes */ unsigned char bDescriptorType; /* STRING Descriptor Type */ unsigned char bString[0]; /* UNICODE encoded string */} UniDesc;#define sizeof_UnDesc 2 /* +2n *//* Packet Identifier *//* See: usb11.pdf P.155 ([9.3.1] Packet Identifier Field) */enum { PID_OUT = 0xe1, PID_IN = 0x69, PID_SOF = 0xa5, PID_SETUP = 0x2d, PID_DATA0 = 0xc3, PID_DATA1 = 0x4b, PID_ACK = 0xd2, PID_NAK = 0x5a, PID_STALL = 0x1e, PID_PRE = 0x3c,};/* 嵟戝抣 */#define DEVADR_MAX 127#define ENDPOINT_MAX 15#define WORD_MAX 0xffff#define LEN_MAX 0xffff#define GET_STATUS_DATA_SIZE 2#define GET_STATE_DATA_SIZE 1#define GET_CONFIGURATION_DATA_SIZE 1#define GET_INTERFACE_DATA_SIZE 1#define SYNCH_FRAME_DATA_SIZE 2#endif /* !usbdef_h *//* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -