xref: /haiku/headers/os/drivers/USB_spec.h (revision ed6250c95736c0b55da79d6e9dd01369532260c0)
1 /*
2 ** USB_spec.h
3 **
4 ** Copyright 1999, Be Incorporated. All Rights Reserved.
5 **
6 ** This file contains structures and constants based on the USB Specification 1.1
7 **
8 */
9 
10 #ifndef _USB_SPEC_H
11 #define _USB_SPEC_H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /* request types (target & direction) for  send_request() */
18 /* cf USB Spec Rev 1.1, table 9-2, p 183 */
19 #define USB_REQTYPE_DEVICE_IN         0x80
20 #define USB_REQTYPE_DEVICE_OUT        0x00
21 #define USB_REQTYPE_INTERFACE_IN      0x81
22 #define USB_REQTYPE_INTERFACE_OUT     0x01
23 #define USB_REQTYPE_ENDPOINT_IN       0x82
24 #define USB_REQTYPE_ENDPOINT_OUT      0x02
25 #define USB_REQTYPE_OTHER_OUT         0x03
26 #define USB_REQTYPE_OTHER_IN          0x83
27 
28 /* request types for send_request() */
29 /* cf USB Spec Rev 1.1, table 9-2, p 183 */
30 #define USB_REQTYPE_STANDARD          0x00
31 #define USB_REQTYPE_CLASS             0x20
32 #define USB_REQTYPE_VENDOR            0x40
33 #define USB_REQTYPE_RESERVED          0x60
34 #define USB_REQTYPE_MASK              0x9F
35 
36 /* standard request values for send_request() */
37 /* cf USB Spec Rev 1.1, table 9-4, p 187 */
38 #define USB_REQUEST_GET_STATUS           0
39 #define USB_REQUEST_CLEAR_FEATURE        1
40 #define USB_REQUEST_SET_FEATURE          3
41 #define USB_REQUEST_SET_ADDRESS          5
42 #define USB_REQUEST_GET_DESCRIPTOR       6
43 #define USB_REQUEST_SET_DESCRIPTOR       7
44 #define USB_REQUEST_GET_CONFIGURATION    8
45 #define USB_REQUEST_SET_CONFIGURATION    9
46 #define USB_REQUEST_GET_INTERFACE       10
47 #define USB_REQUEST_SET_INTERFACE       11
48 #define USB_REQUEST_SYNCH_FRAME         12
49 
50 /* used by {set,get}_descriptor() */
51 /* cf USB Spec Rev 1.1, table 9-5, p 187 */
52 #define USB_DESCRIPTOR_DEVICE            1
53 #define USB_DESCRIPTOR_CONFIGURATION     2
54 #define USB_DESCRIPTOR_STRING            3
55 #define USB_DESCRIPTOR_INTERFACE         4
56 #define USB_DESCRIPTOR_ENDPOINT          5
57 
58 /* used by {set,clear}_feature() */
59 /* cf USB Spec Rev 1.1, table 9-6, p 188 */
60 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP	1
61 #define USB_FEATURE_ENDPOINT_HALT			0
62 
63 #define USB_ENDPOINT_ATTR_CONTROL		0x00
64 #define USB_ENDPOINT_ATTR_ISOCHRONOUS	0x01
65 #define USB_ENDPOINT_ATTR_BULK			0x02
66 #define USB_ENDPOINT_ATTR_INTERRUPT		0x03
67 #define USB_ENDPOINT_ATTR_MASK			0x03
68 
69 #define USB_ENDPOINT_ADDR_DIR_IN	 	0x80
70 #define USB_ENDPOINT_ADDR_DIR_OUT		0x00
71 
72 
73 typedef struct {
74 	/* cf USB Spec Rev 1.1, table 9-7, p 197 */
75 	uint8 length;
76 	uint8 descriptor_type;          /* USB_DESCRIPTOR_DEVICE */
77 	uint16 usb_version;             /* USB_DESCRIPTOR_DEVICE_LENGTH */
78 	uint8 device_class;
79 	uint8 device_subclass;
80 	uint8 device_protocol;
81 	uint8 max_packet_size_0;
82 	uint16 vendor_id;
83 	uint16 product_id;
84 	uint16 device_version;
85 	uint8 manufacturer;
86 	uint8 product;
87 	uint8 serial_number;
88 	uint8 num_configurations;
89 } _PACKED usb_device_descriptor;
90 
91 typedef struct {
92 	/* cf USB Spec Rev 1.1, table 9-8, p 199 */
93 	uint8 length;
94 	uint8 descriptor_type;          /* USB_DESCRIPTOR_CONFIGURATION */
95 	uint16 total_length;            /* USB_DESCRIPTOR_CONFIGURATION_LENGTH */
96 	uint8 number_interfaces;
97 	uint8 configuration_value;
98 	uint8 configuration;
99 	uint8 attributes;
100 	uint8 max_power;
101 } _PACKED usb_configuration_descriptor;
102 
103 typedef struct {
104 	/* cf USB Spec Rev 1.1, table 9-9, p 202 */
105 	uint8 length;
106 	uint8 descriptor_type;          /* USB_DESCRIPTOR_INTERFACE */
107 	uint8 interface_number;         /* USB_DESCRIPTOR_INTERFACE_LENGTH  */
108 	uint8 alternate_setting;
109 	uint8 num_endpoints;
110 	uint8 interface_class;
111 	uint8 interface_subclass;
112 	uint8 interface_protocol;
113 	uint8 interface;
114 } _PACKED usb_interface_descriptor;
115 
116 typedef struct {
117 	/* cf USB Spec Rev 1.1, table 9-10, p 203 */
118 	uint8 length;
119 	uint8 descriptor_type;          /* USB_DESCRIPTOR_ENDPOINT */
120 	uint8 endpoint_address;         /* USB_DESCRIPTOR_ENDPOINT_LENGTH */
121 	uint8 attributes;
122 	uint16 max_packet_size;
123 	uint8 interval;
124 } _PACKED usb_endpoint_descriptor;
125 
126 typedef struct {
127 	/* cf USB Spec Rev 1.1, table 9-12, p 205 */
128 	uint8 length;                   /* USB_DESCRIPTOR_STRING */
129 	uint8 descriptor_type;
130 	uchar string[1];
131 } _PACKED usb_string_descriptor;
132 
133 typedef struct {
134 	uint8 length;
135 	uint8 descriptor_type;
136 	uint8 data[1];
137 } _PACKED usb_generic_descriptor;
138 
139 typedef union {
140 	usb_generic_descriptor generic;
141 	usb_device_descriptor device;
142 	usb_interface_descriptor interface;
143 	usb_endpoint_descriptor endpoint;
144 	usb_configuration_descriptor configuration;
145 	usb_string_descriptor string;
146 } usb_descriptor;
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 
152 #endif
153