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/* Direction */ 79#define USB_ENDPOINT_ADDR_DIR_IN 0x80 80#define USB_ENDPOINT_ADDR_DIR_OUT 0x00 81#define USB_ENDPOINT_ADDR_DIR_MASK 0x80 82 83 84typedef struct usb_device_descriptor { 85 uint8 length; 86 uint8 descriptor_type; 87 uint16 usb_version; 88 uint8 device_class; 89 uint8 device_subclass; 90 uint8 device_protocol; 91 uint8 max_packet_size_0; 92 uint16 vendor_id; 93 uint16 product_id; 94 uint16 device_version; 95 uint8 manufacturer; 96 uint8 product; 97 uint8 serial_number; 98 uint8 num_configurations; 99} _PACKED usb_device_descriptor; 100 101typedef struct usb_configuration_descriptor { 102 uint8 length; 103 uint8 descriptor_type; 104 uint16 total_length; 105 uint8 number_interfaces; 106 uint8 configuration_value; 107 uint8 configuration; 108 uint8 attributes; 109 uint8 max_power; 110} _PACKED usb_configuration_descriptor; 111 112typedef struct usb_interface_descriptor { 113 uint8 length; 114 uint8 descriptor_type; 115 uint8 interface_number; 116 uint8 alternate_setting; 117 uint8 num_endpoints; 118 uint8 interface_class; 119 uint8 interface_subclass; 120 uint8 interface_protocol; 121 uint8 interface; 122} _PACKED usb_interface_descriptor; 123 124typedef struct usb_endpoint_descriptor { 125 uint8 length; 126 uint8 descriptor_type; 127 uint8 endpoint_address; 128 uint8 attributes; 129 uint16 max_packet_size; 130 uint8 interval; 131} _PACKED usb_endpoint_descriptor; 132 133typedef struct usb_string_descriptor { 134 uint8 length; 135 uint8 descriptor_type; 136 uchar string[1]; 137} _PACKED usb_string_descriptor; 138 139typedef struct usb_generic_descriptor { 140 uint8 length; 141 uint8 descriptor_type; 142 uint8 data[1]; 143} _PACKED usb_generic_descriptor; 144 145typedef union usb_descriptor { 146 usb_generic_descriptor generic; 147 usb_device_descriptor device; 148 usb_interface_descriptor interface; 149 usb_endpoint_descriptor endpoint; 150 usb_configuration_descriptor configuration; 151 usb_string_descriptor string; 152} usb_descriptor; 153 154 155#endif /* _USB_SPEC_H */ 156