• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Support for USB 2.0 standard.
3 
4   Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
5   This program and the accompanying materials
6   are licensed and made available under the terms and conditions of the BSD License
7   which accompanies this distribution.  The full text of the license may be found at
8   http://opensource.org/licenses/bsd-license.php
9 
10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #ifndef __USB_H__
16 #define __USB_H__
17 
18 //
19 // Subset of Class and Subclass definitions from USB Specs
20 //
21 
22 //
23 // Usb mass storage class code
24 //
25 #define USB_MASS_STORE_CLASS    0x08
26 
27 //
28 // Usb mass storage subclass code, specify the command set used.
29 //
30 #define USB_MASS_STORE_RBC      0x01 ///< Reduced Block Commands
31 #define USB_MASS_STORE_8020I    0x02 ///< SFF-8020i, typically a CD/DVD device
32 #define USB_MASS_STORE_QIC      0x03 ///< Typically a tape device
33 #define USB_MASS_STORE_UFI      0x04 ///< Typically a floppy disk driver device
34 #define USB_MASS_STORE_8070I    0x05 ///< SFF-8070i, typically a floppy disk driver device.
35 #define USB_MASS_STORE_SCSI     0x06 ///< SCSI transparent command set
36 
37 //
38 // Usb mass storage protocol code, specify the transport protocol
39 //
40 #define USB_MASS_STORE_CBI0     0x00 ///< CBI protocol with command completion interrupt
41 #define USB_MASS_STORE_CBI1     0x01 ///< CBI protocol without command completion interrupt
42 #define USB_MASS_STORE_BOT      0x50 ///< Bulk-Only Transport
43 
44 //
45 // Standard device request and request type
46 // USB 2.0 spec, Section 9.4
47 //
48 #define USB_DEV_GET_STATUS                  0x00
49 #define USB_DEV_GET_STATUS_REQ_TYPE_D       0x80 // Receiver : Device
50 #define USB_DEV_GET_STATUS_REQ_TYPE_I       0x81 // Receiver : Interface
51 #define USB_DEV_GET_STATUS_REQ_TYPE_E       0x82 // Receiver : Endpoint
52 
53 #define USB_DEV_CLEAR_FEATURE               0x01
54 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D    0x00 // Receiver : Device
55 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I    0x01 // Receiver : Interface
56 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E    0x02 // Receiver : Endpoint
57 
58 #define USB_DEV_SET_FEATURE                 0x03
59 #define USB_DEV_SET_FEATURE_REQ_TYPE_D      0x00 // Receiver : Device
60 #define USB_DEV_SET_FEATURE_REQ_TYPE_I      0x01 // Receiver : Interface
61 #define USB_DEV_SET_FEATURE_REQ_TYPE_E      0x02 // Receiver : Endpoint
62 
63 #define USB_DEV_SET_ADDRESS                 0x05
64 #define USB_DEV_SET_ADDRESS_REQ_TYPE        0x00
65 
66 #define USB_DEV_GET_DESCRIPTOR              0x06
67 #define USB_DEV_GET_DESCRIPTOR_REQ_TYPE     0x80
68 
69 #define USB_DEV_SET_DESCRIPTOR              0x07
70 #define USB_DEV_SET_DESCRIPTOR_REQ_TYPE     0x00
71 
72 #define USB_DEV_GET_CONFIGURATION           0x08
73 #define USB_DEV_GET_CONFIGURATION_REQ_TYPE  0x80
74 
75 #define USB_DEV_SET_CONFIGURATION           0x09
76 #define USB_DEV_SET_CONFIGURATION_REQ_TYPE  0x00
77 
78 #define USB_DEV_GET_INTERFACE               0x0A
79 #define USB_DEV_GET_INTERFACE_REQ_TYPE      0x81
80 
81 #define USB_DEV_SET_INTERFACE               0x0B
82 #define USB_DEV_SET_INTERFACE_REQ_TYPE      0x01
83 
84 #define USB_DEV_SYNCH_FRAME                 0x0C
85 #define USB_DEV_SYNCH_FRAME_REQ_TYPE        0x82
86 
87 
88 //
89 // USB standard descriptors and reqeust
90 //
91 #pragma pack(1)
92 
93 ///
94 /// Format of Setup Data for USB Device Requests
95 /// USB 2.0 spec, Section 9.3
96 ///
97 typedef struct {
98   UINT8           RequestType;
99   UINT8           Request;
100   UINT16          Value;
101   UINT16          Index;
102   UINT16          Length;
103 } USB_DEVICE_REQUEST;
104 
105 ///
106 /// Standard Device Descriptor
107 /// USB 2.0 spec, Section 9.6.1
108 ///
109 typedef struct {
110   UINT8           Length;
111   UINT8           DescriptorType;
112   UINT16          BcdUSB;
113   UINT8           DeviceClass;
114   UINT8           DeviceSubClass;
115   UINT8           DeviceProtocol;
116   UINT8           MaxPacketSize0;
117   UINT16          IdVendor;
118   UINT16          IdProduct;
119   UINT16          BcdDevice;
120   UINT8           StrManufacturer;
121   UINT8           StrProduct;
122   UINT8           StrSerialNumber;
123   UINT8           NumConfigurations;
124 } USB_DEVICE_DESCRIPTOR;
125 
126 ///
127 /// Standard Configuration Descriptor
128 /// USB 2.0 spec, Section 9.6.3
129 ///
130 typedef struct {
131   UINT8           Length;
132   UINT8           DescriptorType;
133   UINT16          TotalLength;
134   UINT8           NumInterfaces;
135   UINT8           ConfigurationValue;
136   UINT8           Configuration;
137   UINT8           Attributes;
138   UINT8           MaxPower;
139 } USB_CONFIG_DESCRIPTOR;
140 
141 ///
142 /// Standard Interface Descriptor
143 /// USB 2.0 spec, Section 9.6.5
144 ///
145 typedef struct {
146   UINT8           Length;
147   UINT8           DescriptorType;
148   UINT8           InterfaceNumber;
149   UINT8           AlternateSetting;
150   UINT8           NumEndpoints;
151   UINT8           InterfaceClass;
152   UINT8           InterfaceSubClass;
153   UINT8           InterfaceProtocol;
154   UINT8           Interface;
155 } USB_INTERFACE_DESCRIPTOR;
156 
157 ///
158 /// Standard Endpoint Descriptor
159 /// USB 2.0 spec, Section 9.6.6
160 ///
161 typedef struct {
162   UINT8           Length;
163   UINT8           DescriptorType;
164   UINT8           EndpointAddress;
165   UINT8           Attributes;
166   UINT16          MaxPacketSize;
167   UINT8           Interval;
168 } USB_ENDPOINT_DESCRIPTOR;
169 
170 ///
171 /// UNICODE String Descriptor
172 /// USB 2.0 spec, Section 9.6.7
173 ///
174 typedef struct {
175   UINT8           Length;
176   UINT8           DescriptorType;
177   CHAR16          String[1];
178 } EFI_USB_STRING_DESCRIPTOR;
179 
180 #pragma pack()
181 
182 
183 typedef enum {
184   //
185   // USB request type
186   //
187   USB_REQ_TYPE_STANDARD   = (0x00 << 5),
188   USB_REQ_TYPE_CLASS      = (0x01 << 5),
189   USB_REQ_TYPE_VENDOR     = (0x02 << 5),
190 
191   //
192   // Standard control transfer request type, or the value
193   // to fill in EFI_USB_DEVICE_REQUEST.Request
194   //
195   USB_REQ_GET_STATUS      = 0x00,
196   USB_REQ_CLEAR_FEATURE   = 0x01,
197   USB_REQ_SET_FEATURE     = 0x03,
198   USB_REQ_SET_ADDRESS     = 0x05,
199   USB_REQ_GET_DESCRIPTOR  = 0x06,
200   USB_REQ_SET_DESCRIPTOR  = 0x07,
201   USB_REQ_GET_CONFIG      = 0x08,
202   USB_REQ_SET_CONFIG      = 0x09,
203   USB_REQ_GET_INTERFACE   = 0x0A,
204   USB_REQ_SET_INTERFACE   = 0x0B,
205   USB_REQ_SYNCH_FRAME     = 0x0C,
206 
207   //
208   // Usb control transfer target
209   //
210   USB_TARGET_DEVICE       = 0,
211   USB_TARGET_INTERFACE    = 0x01,
212   USB_TARGET_ENDPOINT     = 0x02,
213   USB_TARGET_OTHER        = 0x03,
214 
215   //
216   // USB Descriptor types
217   //
218   USB_DESC_TYPE_DEVICE    = 0x01,
219   USB_DESC_TYPE_CONFIG    = 0x02,
220   USB_DESC_TYPE_STRING    = 0x03,
221   USB_DESC_TYPE_INTERFACE = 0x04,
222   USB_DESC_TYPE_ENDPOINT  = 0x05,
223   USB_DESC_TYPE_HID       = 0x21,
224   USB_DESC_TYPE_REPORT    = 0x22,
225 
226   //
227   // Features to be cleared by CLEAR_FEATURE requests
228   //
229   USB_FEATURE_ENDPOINT_HALT = 0,
230 
231   //
232   // USB endpoint types: 00: control, 01: isochronous, 10: bulk, 11: interrupt
233   //
234   USB_ENDPOINT_CONTROL    = 0x00,
235   USB_ENDPOINT_ISO        = 0x01,
236   USB_ENDPOINT_BULK       = 0x02,
237   USB_ENDPOINT_INTERRUPT  = 0x03,
238 
239   USB_ENDPOINT_TYPE_MASK  = 0x03,
240   USB_ENDPOINT_DIR_IN     = 0x80,
241 
242   //
243   //Use 200 ms to increase the error handling response time
244   //
245   EFI_USB_INTERRUPT_DELAY = 2000000
246 } USB_TYPES_DEFINITION;
247 
248 
249 //
250 // HID constants definition, see Device Class Definition
251 // for Human Interface Devices (HID) rev1.11
252 //
253 
254 //
255 // HID standard GET_DESCRIPTOR request.
256 //
257 #define USB_HID_GET_DESCRIPTOR_REQ_TYPE  0x81
258 
259 //
260 // HID specific requests.
261 //
262 #define USB_HID_CLASS_GET_REQ_TYPE       0xa1
263 #define USB_HID_CLASS_SET_REQ_TYPE       0x21
264 
265 //
266 // HID report item format
267 //
268 #define HID_ITEM_FORMAT_SHORT 0
269 #define HID_ITEM_FORMAT_LONG  1
270 
271 //
272 // Special tag indicating long items
273 //
274 #define HID_ITEM_TAG_LONG 15
275 
276 //
277 // HID report descriptor item type (prefix bit 2,3)
278 //
279 #define HID_ITEM_TYPE_MAIN      0
280 #define HID_ITEM_TYPE_GLOBAL    1
281 #define HID_ITEM_TYPE_LOCAL     2
282 #define HID_ITEM_TYPE_RESERVED  3
283 
284 //
285 // HID report descriptor main item tags
286 //
287 #define HID_MAIN_ITEM_TAG_INPUT             8
288 #define HID_MAIN_ITEM_TAG_OUTPUT            9
289 #define HID_MAIN_ITEM_TAG_FEATURE           11
290 #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION  10
291 #define HID_MAIN_ITEM_TAG_END_COLLECTION    12
292 
293 //
294 // HID report descriptor main item contents
295 //
296 #define HID_MAIN_ITEM_CONSTANT      0x001
297 #define HID_MAIN_ITEM_VARIABLE      0x002
298 #define HID_MAIN_ITEM_RELATIVE      0x004
299 #define HID_MAIN_ITEM_WRAP          0x008
300 #define HID_MAIN_ITEM_NONLINEAR     0x010
301 #define HID_MAIN_ITEM_NO_PREFERRED  0x020
302 #define HID_MAIN_ITEM_NULL_STATE    0x040
303 #define HID_MAIN_ITEM_VOLATILE      0x080
304 #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
305 
306 //
307 // HID report descriptor collection item types
308 //
309 #define HID_COLLECTION_PHYSICAL     0
310 #define HID_COLLECTION_APPLICATION  1
311 #define HID_COLLECTION_LOGICAL      2
312 
313 //
314 // HID report descriptor global item tags
315 //
316 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE        0
317 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM   1
318 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM   2
319 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM  3
320 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM  4
321 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT     5
322 #define HID_GLOBAL_ITEM_TAG_UNIT              6
323 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE       7
324 #define HID_GLOBAL_ITEM_TAG_REPORT_ID         8
325 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT      9
326 #define HID_GLOBAL_ITEM_TAG_PUSH              10
327 #define HID_GLOBAL_ITEM_TAG_POP               11
328 
329 //
330 // HID report descriptor local item tags
331 //
332 #define HID_LOCAL_ITEM_TAG_USAGE              0
333 #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM      1
334 #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM      2
335 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX   3
336 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
337 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
338 #define HID_LOCAL_ITEM_TAG_STRING_INDEX       7
339 #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM     8
340 #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM     9
341 #define HID_LOCAL_ITEM_TAG_DELIMITER          10
342 
343 //
344 // HID report types
345 //
346 #define HID_INPUT_REPORT    1
347 #define HID_OUTPUT_REPORT   2
348 #define HID_FEATURE_REPORT  3
349 
350 //
351 // HID class protocol request
352 //
353 #define EFI_USB_GET_REPORT_REQUEST    0x01
354 #define EFI_USB_GET_IDLE_REQUEST      0x02
355 #define EFI_USB_GET_PROTOCOL_REQUEST  0x03
356 #define EFI_USB_SET_REPORT_REQUEST    0x09
357 #define EFI_USB_SET_IDLE_REQUEST      0x0a
358 #define EFI_USB_SET_PROTOCOL_REQUEST  0x0b
359 
360 #pragma pack(1)
361 ///
362 /// Descriptor header for Report/Physical Descriptors
363 /// HID 1.1, section 6.2.1
364 ///
365 typedef struct hid_class_descriptor {
366   UINT8   DescriptorType;
367   UINT16  DescriptorLength;
368 } EFI_USB_HID_CLASS_DESCRIPTOR;
369 
370 ///
371 /// The HID descriptor identifies the length and type
372 /// of subordinate descriptors for a device.
373 /// HID 1.1, section 6.2.1
374 ///
375 typedef struct hid_descriptor {
376   UINT8                         Length;
377   UINT8                         DescriptorType;
378   UINT16                        BcdHID;
379   UINT8                         CountryCode;
380   UINT8                         NumDescriptors;
381   EFI_USB_HID_CLASS_DESCRIPTOR  HidClassDesc[1];
382 } EFI_USB_HID_DESCRIPTOR;
383 
384 #pragma pack()
385 
386 #endif
387