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