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_OUT 0x03 20 #define USB_REQTYPE_OTHER_IN 0x83 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 1 44 #define USB_DESCRIPTOR_CONFIGURATION 2 45 #define USB_DESCRIPTOR_STRING 3 46 #define USB_DESCRIPTOR_INTERFACE 4 47 #define USB_DESCRIPTOR_ENDPOINT 5 48 49 /* Used by {set|clear}_feature() */ 50 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 51 #define USB_FEATURE_ENDPOINT_HALT 0 52 53 #define USB_ENDPOINT_ATTR_CONTROL 0x00 54 #define USB_ENDPOINT_ATTR_ISOCHRONOUS 0x01 55 #define USB_ENDPOINT_ATTR_BULK 0x02 56 #define USB_ENDPOINT_ATTR_INTERRUPT 0x03 57 #define USB_ENDPOINT_ATTR_MASK 0x03 58 59 #define USB_ENDPOINT_ADDR_DIR_IN 0x80 60 #define USB_ENDPOINT_ADDR_DIR_OUT 0x00 61 62 63 typedef struct usb_device_descriptor { 64 uint8 length; 65 uint8 descriptor_type; 66 uint16 usb_version; 67 uint8 device_class; 68 uint8 device_subclass; 69 uint8 device_protocol; 70 uint8 max_packet_size_0; 71 uint16 vendor_id; 72 uint16 product_id; 73 uint16 device_version; 74 uint8 manufacturer; 75 uint8 product; 76 uint8 serial_number; 77 uint8 num_configurations; 78 } _PACKED usb_device_descriptor; 79 80 typedef struct usb_configuration_descriptor { 81 uint8 length; 82 uint8 descriptor_type; 83 uint16 total_length; 84 uint8 number_interfaces; 85 uint8 configuration_value; 86 uint8 configuration; 87 uint8 attributes; 88 uint8 max_power; 89 } _PACKED usb_configuration_descriptor; 90 91 typedef struct usb_interface_descriptor { 92 uint8 length; 93 uint8 descriptor_type; 94 uint8 interface_number; 95 uint8 alternate_setting; 96 uint8 num_endpoints; 97 uint8 interface_class; 98 uint8 interface_subclass; 99 uint8 interface_protocol; 100 uint8 interface; 101 } _PACKED usb_interface_descriptor; 102 103 typedef struct usb_endpoint_descriptor { 104 uint8 length; 105 uint8 descriptor_type; 106 uint8 endpoint_address; 107 uint8 attributes; 108 uint16 max_packet_size; 109 uint8 interval; 110 } _PACKED usb_endpoint_descriptor; 111 112 typedef struct usb_string_descriptor { 113 uint8 length; 114 uint8 descriptor_type; 115 uchar string[1]; 116 } _PACKED usb_string_descriptor; 117 118 typedef struct usb_generic_descriptor { 119 uint8 length; 120 uint8 descriptor_type; 121 uint8 data[1]; 122 } _PACKED usb_generic_descriptor; 123 124 typedef union usb_descriptor { 125 usb_generic_descriptor generic; 126 usb_device_descriptor device; 127 usb_interface_descriptor interface; 128 usb_endpoint_descriptor endpoint; 129 usb_configuration_descriptor configuration; 130 usb_string_descriptor string; 131 } usb_descriptor; 132 133 134 #endif /* _USB_SPEC_H */ 135