iPXE
Usb.h
Go to the documentation of this file.
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 FILE_LICENCE ( BSD3 );
19 
20 //
21 // Subset of Class and Subclass definitions from USB Specs
22 //
23 
24 //
25 // Usb mass storage class code
26 //
27 #define USB_MASS_STORE_CLASS 0x08
28 
29 //
30 // Usb mass storage subclass code, specify the command set used.
31 //
32 #define USB_MASS_STORE_RBC 0x01 ///< Reduced Block Commands
33 #define USB_MASS_STORE_8020I 0x02 ///< SFF-8020i, typically a CD/DVD device
34 #define USB_MASS_STORE_QIC 0x03 ///< Typically a tape device
35 #define USB_MASS_STORE_UFI 0x04 ///< Typically a floppy disk driver device
36 #define USB_MASS_STORE_8070I 0x05 ///< SFF-8070i, typically a floppy disk driver device.
37 #define USB_MASS_STORE_SCSI 0x06 ///< SCSI transparent command set
38 
39 //
40 // Usb mass storage protocol code, specify the transport protocol
41 //
42 #define USB_MASS_STORE_CBI0 0x00 ///< CBI protocol with command completion interrupt
43 #define USB_MASS_STORE_CBI1 0x01 ///< CBI protocol without command completion interrupt
44 #define USB_MASS_STORE_BOT 0x50 ///< Bulk-Only Transport
45 
46 //
47 // Standard device request and request type
48 // USB 2.0 spec, Section 9.4
49 //
50 #define USB_DEV_GET_STATUS 0x00
51 #define USB_DEV_GET_STATUS_REQ_TYPE_D 0x80 // Receiver : Device
52 #define USB_DEV_GET_STATUS_REQ_TYPE_I 0x81 // Receiver : Interface
53 #define USB_DEV_GET_STATUS_REQ_TYPE_E 0x82 // Receiver : Endpoint
54 
55 #define USB_DEV_CLEAR_FEATURE 0x01
56 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device
57 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface
58 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint
59 
60 #define USB_DEV_SET_FEATURE 0x03
61 #define USB_DEV_SET_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device
62 #define USB_DEV_SET_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface
63 #define USB_DEV_SET_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint
64 
65 #define USB_DEV_SET_ADDRESS 0x05
66 #define USB_DEV_SET_ADDRESS_REQ_TYPE 0x00
67 
68 #define USB_DEV_GET_DESCRIPTOR 0x06
69 #define USB_DEV_GET_DESCRIPTOR_REQ_TYPE 0x80
70 
71 #define USB_DEV_SET_DESCRIPTOR 0x07
72 #define USB_DEV_SET_DESCRIPTOR_REQ_TYPE 0x00
73 
74 #define USB_DEV_GET_CONFIGURATION 0x08
75 #define USB_DEV_GET_CONFIGURATION_REQ_TYPE 0x80
76 
77 #define USB_DEV_SET_CONFIGURATION 0x09
78 #define USB_DEV_SET_CONFIGURATION_REQ_TYPE 0x00
79 
80 #define USB_DEV_GET_INTERFACE 0x0A
81 #define USB_DEV_GET_INTERFACE_REQ_TYPE 0x81
82 
83 #define USB_DEV_SET_INTERFACE 0x0B
84 #define USB_DEV_SET_INTERFACE_REQ_TYPE 0x01
85 
86 #define USB_DEV_SYNCH_FRAME 0x0C
87 #define USB_DEV_SYNCH_FRAME_REQ_TYPE 0x82
88 
89 
90 //
91 // USB standard descriptors and reqeust
92 //
93 #pragma pack(1)
94 
95 ///
96 /// Format of Setup Data for USB Device Requests
97 /// USB 2.0 spec, Section 9.3
98 ///
99 typedef struct {
106 
107 ///
108 /// Standard Device Descriptor
109 /// USB 2.0 spec, Section 9.6.1
110 ///
111 typedef struct {
127 
128 ///
129 /// Standard Configuration Descriptor
130 /// USB 2.0 spec, Section 9.6.3
131 ///
132 typedef struct {
142 
143 ///
144 /// Standard Interface Descriptor
145 /// USB 2.0 spec, Section 9.6.5
146 ///
147 typedef struct {
158 
159 ///
160 /// Standard Endpoint Descriptor
161 /// USB 2.0 spec, Section 9.6.6
162 ///
163 typedef struct {
171 
172 ///
173 /// UNICODE String Descriptor
174 /// USB 2.0 spec, Section 9.6.7
175 ///
176 typedef struct {
179  CHAR16 String[1];
181 
182 #pragma pack()
183 
184 
185 typedef enum {
186  //
187  // USB request type
188  //
189  USB_REQ_TYPE_STANDARD = (0x00 << 5),
190  USB_REQ_TYPE_CLASS = (0x01 << 5),
191  USB_REQ_TYPE_VENDOR = (0x02 << 5),
192 
193  //
194  // Standard control transfer request type, or the value
195  // to fill in EFI_USB_DEVICE_REQUEST.Request
196  //
208 
209  //
210  // Usb control transfer target
211  //
216 
217  //
218  // USB Descriptor types
219  //
227 
228  //
229  // Features to be cleared by CLEAR_FEATURE requests
230  //
232 
233  //
234  // USB endpoint types: 00: control, 01: isochronous, 10: bulk, 11: interrupt
235  //
240 
243 
244  //
245  //Use 200 ms to increase the error handling response time
246  //
249 
250 
251 //
252 // HID constants definition, see Device Class Definition
253 // for Human Interface Devices (HID) rev1.11
254 //
255 
256 //
257 // HID standard GET_DESCRIPTOR request.
258 //
259 #define USB_HID_GET_DESCRIPTOR_REQ_TYPE 0x81
260 
261 //
262 // HID specific requests.
263 //
264 #define USB_HID_CLASS_GET_REQ_TYPE 0xa1
265 #define USB_HID_CLASS_SET_REQ_TYPE 0x21
266 
267 //
268 // HID report item format
269 //
270 #define HID_ITEM_FORMAT_SHORT 0
271 #define HID_ITEM_FORMAT_LONG 1
272 
273 //
274 // Special tag indicating long items
275 //
276 #define HID_ITEM_TAG_LONG 15
277 
278 //
279 // HID report descriptor item type (prefix bit 2,3)
280 //
281 #define HID_ITEM_TYPE_MAIN 0
282 #define HID_ITEM_TYPE_GLOBAL 1
283 #define HID_ITEM_TYPE_LOCAL 2
284 #define HID_ITEM_TYPE_RESERVED 3
285 
286 //
287 // HID report descriptor main item tags
288 //
289 #define HID_MAIN_ITEM_TAG_INPUT 8
290 #define HID_MAIN_ITEM_TAG_OUTPUT 9
291 #define HID_MAIN_ITEM_TAG_FEATURE 11
292 #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10
293 #define HID_MAIN_ITEM_TAG_END_COLLECTION 12
294 
295 //
296 // HID report descriptor main item contents
297 //
298 #define HID_MAIN_ITEM_CONSTANT 0x001
299 #define HID_MAIN_ITEM_VARIABLE 0x002
300 #define HID_MAIN_ITEM_RELATIVE 0x004
301 #define HID_MAIN_ITEM_WRAP 0x008
302 #define HID_MAIN_ITEM_NONLINEAR 0x010
303 #define HID_MAIN_ITEM_NO_PREFERRED 0x020
304 #define HID_MAIN_ITEM_NULL_STATE 0x040
305 #define HID_MAIN_ITEM_VOLATILE 0x080
306 #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
307 
308 //
309 // HID report descriptor collection item types
310 //
311 #define HID_COLLECTION_PHYSICAL 0
312 #define HID_COLLECTION_APPLICATION 1
313 #define HID_COLLECTION_LOGICAL 2
314 
315 //
316 // HID report descriptor global item tags
317 //
318 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0
319 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1
320 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2
321 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3
322 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4
323 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5
324 #define HID_GLOBAL_ITEM_TAG_UNIT 6
325 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7
326 #define HID_GLOBAL_ITEM_TAG_REPORT_ID 8
327 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9
328 #define HID_GLOBAL_ITEM_TAG_PUSH 10
329 #define HID_GLOBAL_ITEM_TAG_POP 11
330 
331 //
332 // HID report descriptor local item tags
333 //
334 #define HID_LOCAL_ITEM_TAG_USAGE 0
335 #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1
336 #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2
337 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3
338 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
339 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
340 #define HID_LOCAL_ITEM_TAG_STRING_INDEX 7
341 #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8
342 #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9
343 #define HID_LOCAL_ITEM_TAG_DELIMITER 10
344 
345 //
346 // HID report types
347 //
348 #define HID_INPUT_REPORT 1
349 #define HID_OUTPUT_REPORT 2
350 #define HID_FEATURE_REPORT 3
351 
352 //
353 // HID class protocol request
354 //
355 #define EFI_USB_GET_REPORT_REQUEST 0x01
356 #define EFI_USB_GET_IDLE_REQUEST 0x02
357 #define EFI_USB_GET_PROTOCOL_REQUEST 0x03
358 #define EFI_USB_SET_REPORT_REQUEST 0x09
359 #define EFI_USB_SET_IDLE_REQUEST 0x0a
360 #define EFI_USB_SET_PROTOCOL_REQUEST 0x0b
361 
362 #pragma pack(1)
363 ///
364 /// Descriptor header for Report/Physical Descriptors
365 /// HID 1.1, section 6.2.1
366 ///
367 typedef struct hid_class_descriptor {
371 
372 ///
373 /// The HID descriptor identifies the length and type
374 /// of subordinate descriptors for a device.
375 /// HID 1.1, section 6.2.1
376 ///
377 typedef struct hid_descriptor {
385 
386 #pragma pack()
387 
388 #endif
UINT8 Request
Definition: Usb.h:101
UINT8 StrSerialNumber
Definition: Usb.h:124
UINT8 StrManufacturer
Definition: Usb.h:122
UINT8 DeviceProtocol
Definition: Usb.h:117
UINT8 DescriptorType
Definition: Usb.h:379
UINT8 EndpointAddress
Definition: Usb.h:166
UINT8 Configuration
Definition: Usb.h:138
UINT16 BcdHID
Definition: Usb.h:380
USB_TYPES_DEFINITION
Definition: Usb.h:185
UINT8 DescriptorType
Definition: Usb.h:368
unsigned short CHAR16
Definition: ProcessorBind.h:59
UINT8 InterfaceProtocol
Definition: Usb.h:155
UINT8 StrProduct
Definition: Usb.h:123
UINT8 DescriptorType
Definition: Usb.h:134
#define USB_DEVICE_DESCRIPTOR
A USB device descriptor.
Definition: usb.h:192
UINT8 NumDescriptors
Definition: Usb.h:382
unsigned char UINT8
Definition: ProcessorBind.h:62
EFI_USB_HID_CLASS_DESCRIPTOR HidClassDesc[1]
Definition: Usb.h:383
#define USB_INTERFACE_DESCRIPTOR
A USB interface descriptor.
Definition: usb.h:246
UINT8 DescriptorType
Definition: Usb.h:113
Format of Setup Data for USB Device Requests USB 2.0 spec, Section 9.3.
Definition: Usb.h:99
UINT8 CountryCode
Definition: Usb.h:381
The HID descriptor identifies the length and type of subordinate descriptors for a device.
Definition: Usb.h:377
UINT8 DeviceSubClass
Definition: Usb.h:116
UINT8 RequestType
Definition: Usb.h:100
unsigned short UINT16
Definition: ProcessorBind.h:58
UINT8 MaxPacketSize0
Definition: Usb.h:118
UINT8 Length
Definition: Usb.h:378
struct hid_class_descriptor EFI_USB_HID_CLASS_DESCRIPTOR
Descriptor header for Report/Physical Descriptors HID 1.1, section 6.2.1.
UINT16 Length
Definition: Usb.h:104
UINT8 DeviceClass
Definition: Usb.h:115
UNICODE String Descriptor USB 2.0 spec, Section 9.6.7.
Definition: Usb.h:176
UINT16 IdVendor
Definition: Usb.h:119
UINT16 MaxPacketSize
Definition: Usb.h:168
UINT16 DescriptorLength
Definition: Usb.h:369
UINT16 TotalLength
Definition: Usb.h:135
UINT16 IdProduct
Definition: Usb.h:120
UINT8 NumInterfaces
Definition: Usb.h:136
UINT8 ConfigurationValue
Definition: Usb.h:137
#define USB_ENDPOINT_DESCRIPTOR
A USB endpoint descriptor.
Definition: usb.h:263
Standard Configuration Descriptor USB 2.0 spec, Section 9.6.3.
Definition: Usb.h:132
UINT8 DescriptorType
Definition: Usb.h:165
FILE_LICENCE(BSD3)
UINT8 InterfaceSubClass
Definition: Usb.h:154
struct hid_descriptor EFI_USB_HID_DESCRIPTOR
The HID descriptor identifies the length and type of subordinate descriptors for a device.
UINT8 AlternateSetting
Definition: Usb.h:151
UINT16 BcdDevice
Definition: Usb.h:121
UINT8 Attributes
Definition: Usb.h:139
UINT8 NumConfigurations
Definition: Usb.h:125
UINT16 Value
Definition: Usb.h:102
Descriptor header for Report/Physical Descriptors HID 1.1, section 6.2.1.
Definition: Usb.h:367
UINT16 Index
Definition: Usb.h:103