xref: /haiku/headers/os/drivers/USB_spec.h (revision 4cc4f7bb1845789f95d5ebc68cbb0b859e72f6ff)
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 #define USB_ENDPOINT_ADDR_DIR_IN			0x80
66 #define USB_ENDPOINT_ADDR_DIR_OUT			0x00
67 
68 
69 typedef struct usb_device_descriptor {
70 	uint8	length;
71 	uint8	descriptor_type;
72 	uint16	usb_version;
73 	uint8	device_class;
74 	uint8	device_subclass;
75 	uint8	device_protocol;
76 	uint8	max_packet_size_0;
77 	uint16	vendor_id;
78 	uint16	product_id;
79 	uint16	device_version;
80 	uint8	manufacturer;
81 	uint8	product;
82 	uint8	serial_number;
83 	uint8	num_configurations;
84 } _PACKED usb_device_descriptor;
85 
86 typedef struct usb_configuration_descriptor {
87 	uint8	length;
88 	uint8	descriptor_type;
89 	uint16	total_length;
90 	uint8	number_interfaces;
91 	uint8	configuration_value;
92 	uint8	configuration;
93 	uint8	attributes;
94 	uint8	max_power;
95 } _PACKED usb_configuration_descriptor;
96 
97 typedef struct usb_interface_descriptor {
98 	uint8	length;
99 	uint8	descriptor_type;
100 	uint8	interface_number;
101 	uint8	alternate_setting;
102 	uint8	num_endpoints;
103 	uint8	interface_class;
104 	uint8	interface_subclass;
105 	uint8	interface_protocol;
106 	uint8	interface;
107 } _PACKED usb_interface_descriptor;
108 
109 typedef struct usb_endpoint_descriptor {
110 	uint8	length;
111 	uint8	descriptor_type;
112 	uint8	endpoint_address;
113 	uint8	attributes;
114 	uint16	max_packet_size;
115 	uint8	interval;
116 } _PACKED usb_endpoint_descriptor;
117 
118 typedef struct usb_string_descriptor {
119 	uint8	length;
120 	uint8	descriptor_type;
121 	uchar	string[1];
122 } _PACKED usb_string_descriptor;
123 
124 typedef struct usb_generic_descriptor {
125 	uint8	length;
126 	uint8	descriptor_type;
127 	uint8	data[1];
128 } _PACKED usb_generic_descriptor;
129 
130 typedef union usb_descriptor {
131 	usb_generic_descriptor			generic;
132 	usb_device_descriptor			device;
133 	usb_interface_descriptor		interface;
134 	usb_endpoint_descriptor			endpoint;
135 	usb_configuration_descriptor	configuration;
136 	usb_string_descriptor			string;
137 } usb_descriptor;
138 
139 
140 #endif	/* _USB_SPEC_H */
141