1 /* 2 * Copyright 2009, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _USB_SPEC_H 6 #define _USB_SPEC_H 7 8 9 #include <SupportDefs.h> 10 11 12 /* Request types (target/direction) for send_request() */ 13 #define USB_REQTYPE_DEVICE_IN 0x80 14 #define USB_REQTYPE_DEVICE_OUT 0x00 15 #define USB_REQTYPE_INTERFACE_IN 0x81 16 #define USB_REQTYPE_INTERFACE_OUT 0x01 17 #define USB_REQTYPE_ENDPOINT_IN 0x82 18 #define USB_REQTYPE_ENDPOINT_OUT 0x02 19 #define USB_REQTYPE_OTHER_IN 0x83 20 #define USB_REQTYPE_OTHER_OUT 0x03 21 22 /* Request types for send_request() */ 23 #define USB_REQTYPE_STANDARD 0x00 24 #define USB_REQTYPE_CLASS 0x20 25 #define USB_REQTYPE_VENDOR 0x40 26 #define USB_REQTYPE_RESERVED 0x60 27 #define USB_REQTYPE_MASK 0x9f 28 29 /* Standard request values for send_request() */ 30 #define USB_REQUEST_GET_STATUS 0 31 #define USB_REQUEST_CLEAR_FEATURE 1 32 #define USB_REQUEST_SET_FEATURE 3 33 #define USB_REQUEST_SET_ADDRESS 5 34 #define USB_REQUEST_GET_DESCRIPTOR 6 35 #define USB_REQUEST_SET_DESCRIPTOR 7 36 #define USB_REQUEST_GET_CONFIGURATION 8 37 #define USB_REQUEST_SET_CONFIGURATION 9 38 #define USB_REQUEST_GET_INTERFACE 10 39 #define USB_REQUEST_SET_INTERFACE 11 40 #define USB_REQUEST_SYNCH_FRAME 12 41 42 /* Used by {set|get}_descriptor() */ 43 #define USB_DESCRIPTOR_DEVICE 0x01 44 #define USB_DESCRIPTOR_CONFIGURATION 0x02 45 #define USB_DESCRIPTOR_STRING 0x03 46 #define USB_DESCRIPTOR_INTERFACE 0x04 47 #define USB_DESCRIPTOR_ENDPOINT 0x05 48 /* conventional class-specific descriptors */ 49 #define USB_DESCRIPTOR_CS_DEVICE 0x21 50 #define USB_DESCRIPTOR_CS_CONFIGURATION 0x22 51 #define USB_DESCRIPTOR_CS_STRING 0x23 52 #define USB_DESCRIPTOR_CS_INTERFACE 0x24 53 #define USB_DESCRIPTOR_CS_ENDPOINT 0x25 54 55 /* Used by {set|clear}_feature() */ 56 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 57 #define USB_FEATURE_ENDPOINT_HALT 0 58 59 #define USB_ENDPOINT_ATTR_CONTROL 0x00 60 #define USB_ENDPOINT_ATTR_ISOCHRONOUS 0x01 61 #define USB_ENDPOINT_ATTR_BULK 0x02 62 #define USB_ENDPOINT_ATTR_INTERRUPT 0x03 63 #define USB_ENDPOINT_ATTR_MASK 0x03 64 65 /* Synchronization - isochrnous endpoints only */ 66 #define USB_ENDPOINT_ATTR_NO_SYNCHRONIZE 0x00 67 #define USB_ENDPOINT_ATTR_ASYNCRONOUS 0x04 68 #define USB_ENDPOINT_ATTR_ADAPTIVE_SYNCHRO 0x08 69 #define USB_ENDPOINT_ATTR_SYNCHRONOUS 0x0C 70 #define USB_ENDPOINT_ATTR_SYNCHRONIZE_MASK 0x0C 71 72 /* Usage Type - isochrnous endpoints only */ 73 #define USB_ENDPOINT_ATTR_DATA_USAGE 0x00 74 #define USB_ENDPOINT_ATTR_FEEDBACK_USAGE 0x10 75 #define USB_ENDPOINT_ATTR_IMPLICIT_USAGE 0x20 76 #define USB_ENDPOINT_ATTR_USAGE_MASK 0x30 77 78 #define USB_ENDPOINT_ADDR_DIR_IN 0x80 79 #define USB_ENDPOINT_ADDR_DIR_OUT 0x00 80 81 82 typedef struct usb_device_descriptor { 83 uint8 length; 84 uint8 descriptor_type; 85 uint16 usb_version; 86 uint8 device_class; 87 uint8 device_subclass; 88 uint8 device_protocol; 89 uint8 max_packet_size_0; 90 uint16 vendor_id; 91 uint16 product_id; 92 uint16 device_version; 93 uint8 manufacturer; 94 uint8 product; 95 uint8 serial_number; 96 uint8 num_configurations; 97 } _PACKED usb_device_descriptor; 98 99 typedef struct usb_configuration_descriptor { 100 uint8 length; 101 uint8 descriptor_type; 102 uint16 total_length; 103 uint8 number_interfaces; 104 uint8 configuration_value; 105 uint8 configuration; 106 uint8 attributes; 107 uint8 max_power; 108 } _PACKED usb_configuration_descriptor; 109 110 typedef struct usb_interface_descriptor { 111 uint8 length; 112 uint8 descriptor_type; 113 uint8 interface_number; 114 uint8 alternate_setting; 115 uint8 num_endpoints; 116 uint8 interface_class; 117 uint8 interface_subclass; 118 uint8 interface_protocol; 119 uint8 interface; 120 } _PACKED usb_interface_descriptor; 121 122 typedef struct usb_endpoint_descriptor { 123 uint8 length; 124 uint8 descriptor_type; 125 uint8 endpoint_address; 126 uint8 attributes; 127 uint16 max_packet_size; 128 uint8 interval; 129 } _PACKED usb_endpoint_descriptor; 130 131 typedef struct usb_string_descriptor { 132 uint8 length; 133 uint8 descriptor_type; 134 uchar string[1]; 135 } _PACKED usb_string_descriptor; 136 137 typedef struct usb_generic_descriptor { 138 uint8 length; 139 uint8 descriptor_type; 140 uint8 data[1]; 141 } _PACKED usb_generic_descriptor; 142 143 typedef union usb_descriptor { 144 usb_generic_descriptor generic; 145 usb_device_descriptor device; 146 usb_interface_descriptor interface; 147 usb_endpoint_descriptor endpoint; 148 usb_configuration_descriptor configuration; 149 usb_string_descriptor string; 150 } usb_descriptor; 151 152 153 #endif /* _USB_SPEC_H */ 154