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 Copyright (c) 2024, American Megatrends International LLC. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#pragma once
12
13FILE_LICENCE ( BSD2_PATENT );
14FILE_SECBOOT ( PERMITTED );
15
16//
17// Subset of Class and Subclass definitions from USB Specs
18//
19
20//
21// Usb mass storage class code
22//
23#define USB_MASS_STORE_CLASS 0x08
24
25//
26// Usb mass storage subclass code, specify the command set used.
27//
28#define USB_MASS_STORE_RBC 0x01 ///< Reduced Block Commands
29#define USB_MASS_STORE_8020I 0x02 ///< SFF-8020i, typically a CD/DVD device
30#define USB_MASS_STORE_QIC 0x03 ///< Typically a tape device
31#define USB_MASS_STORE_UFI 0x04 ///< Typically a floppy disk driver device
32#define USB_MASS_STORE_8070I 0x05 ///< SFF-8070i, typically a floppy disk driver device.
33#define USB_MASS_STORE_SCSI 0x06 ///< SCSI transparent command set
34
35//
36// Usb mass storage protocol code, specify the transport protocol
37//
38#define USB_MASS_STORE_CBI0 0x00 ///< CBI protocol with command completion interrupt
39#define USB_MASS_STORE_CBI1 0x01 ///< CBI protocol without command completion interrupt
40#define USB_MASS_STORE_BOT 0x50 ///< Bulk-Only Transport
41
42//
43// Standard device request and request type
44// USB 2.0 spec, Section 9.4
45//
46#define USB_DEV_GET_STATUS 0x00
47#define USB_DEV_GET_STATUS_REQ_TYPE_D 0x80 // Receiver : Device
48#define USB_DEV_GET_STATUS_REQ_TYPE_I 0x81 // Receiver : Interface
49#define USB_DEV_GET_STATUS_REQ_TYPE_E 0x82 // Receiver : Endpoint
50
51#define USB_DEV_CLEAR_FEATURE 0x01
52#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device
53#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface
54#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint
55
56#define USB_DEV_SET_FEATURE 0x03
57#define USB_DEV_SET_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device
58#define USB_DEV_SET_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface
59#define USB_DEV_SET_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint
60
61#define USB_DEV_SET_ADDRESS 0x05
62#define USB_DEV_SET_ADDRESS_REQ_TYPE 0x00
63
64#define USB_DEV_GET_DESCRIPTOR 0x06
65#define USB_DEV_GET_DESCRIPTOR_REQ_TYPE 0x80
66
67#define USB_DEV_SET_DESCRIPTOR 0x07
68#define USB_DEV_SET_DESCRIPTOR_REQ_TYPE 0x00
69
70#define USB_DEV_GET_CONFIGURATION 0x08
71#define USB_DEV_GET_CONFIGURATION_REQ_TYPE 0x80
72
73#define USB_DEV_SET_CONFIGURATION 0x09
74#define USB_DEV_SET_CONFIGURATION_REQ_TYPE 0x00
75
76#define USB_DEV_GET_INTERFACE 0x0A
77#define USB_DEV_GET_INTERFACE_REQ_TYPE 0x81
78
79#define USB_DEV_SET_INTERFACE 0x0B
80#define USB_DEV_SET_INTERFACE_REQ_TYPE 0x01
81
82#define USB_DEV_SYNCH_FRAME 0x0C
83#define USB_DEV_SYNCH_FRAME_REQ_TYPE 0x82
84
85//
86// USB standard descriptors and reqeust
87//
88#pragma pack(1)
89
90///
91/// Format of Setup Data for USB Device Requests
92/// USB 2.0 spec, Section 9.3
93///
101
102///
103/// Standard Device Descriptor
104/// USB 2.0 spec, Section 9.6.1
105///
122
123///
124/// Standard Configuration Descriptor
125/// USB 2.0 spec, Section 9.6.3
126///
137
138///
139/// Standard Interface Association Descriptor
140/// USB 3.0 spec, Section 9.6.4
141///
152
153///
154/// Standard Interface Descriptor
155/// USB 2.0 spec, Section 9.6.5
156///
168
169///
170/// Standard Endpoint Descriptor
171/// USB 2.0 spec, Section 9.6.6
172///
181
182///
183/// UNICODE String Descriptor
184/// USB 2.0 spec, Section 9.6.7
185///
191
192#pragma pack()
193
194typedef enum {
195 //
196 // USB request type
197 //
199 USB_REQ_TYPE_CLASS = (0x01 << 5),
200 USB_REQ_TYPE_VENDOR = (0x02 << 5),
201
202 //
203 // Standard control transfer request type, or the value
204 // to fill in EFI_USB_DEVICE_REQUEST.Request
205 //
217
218 //
219 // Usb control transfer target
220 //
225
226 //
227 // USB Descriptor types
228 //
239
240 //
241 // Features to be cleared by CLEAR_FEATURE requests
242 //
244
245 //
246 // USB endpoint types: 00: control, 01: isochronous, 10: bulk, 11: interrupt
247 //
252
255
256 //
257 // Use 200 ms to increase the error handling response time
258 //
261
262//
263// HID constants definition, see Device Class Definition
264// for Human Interface Devices (HID) rev1.11
265//
266
267//
268// HID standard GET_DESCRIPTOR request.
269//
270#define USB_HID_GET_DESCRIPTOR_REQ_TYPE 0x81
271
272//
273// HID specific requests.
274//
275#define USB_HID_CLASS_GET_REQ_TYPE 0xa1
276#define USB_HID_CLASS_SET_REQ_TYPE 0x21
277
278//
279// HID report item format
280//
281#define HID_ITEM_FORMAT_SHORT 0
282#define HID_ITEM_FORMAT_LONG 1
283
284//
285// Special tag indicating long items
286//
287#define HID_ITEM_TAG_LONG 15
288
289//
290// HID report descriptor item type (prefix bit 2,3)
291//
292#define HID_ITEM_TYPE_MAIN 0
293#define HID_ITEM_TYPE_GLOBAL 1
294#define HID_ITEM_TYPE_LOCAL 2
295#define HID_ITEM_TYPE_RESERVED 3
296
297//
298// HID report descriptor main item tags
299//
300#define HID_MAIN_ITEM_TAG_INPUT 8
301#define HID_MAIN_ITEM_TAG_OUTPUT 9
302#define HID_MAIN_ITEM_TAG_FEATURE 11
303#define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10
304#define HID_MAIN_ITEM_TAG_END_COLLECTION 12
305
306//
307// HID report descriptor main item contents
308//
309#define HID_MAIN_ITEM_CONSTANT 0x001
310#define HID_MAIN_ITEM_VARIABLE 0x002
311#define HID_MAIN_ITEM_RELATIVE 0x004
312#define HID_MAIN_ITEM_WRAP 0x008
313#define HID_MAIN_ITEM_NONLINEAR 0x010
314#define HID_MAIN_ITEM_NO_PREFERRED 0x020
315#define HID_MAIN_ITEM_NULL_STATE 0x040
316#define HID_MAIN_ITEM_VOLATILE 0x080
317#define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
318
319//
320// HID report descriptor collection item types
321//
322#define HID_COLLECTION_PHYSICAL 0
323#define HID_COLLECTION_APPLICATION 1
324#define HID_COLLECTION_LOGICAL 2
325
326//
327// HID report descriptor global item tags
328//
329#define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0
330#define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1
331#define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2
332#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3
333#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4
334#define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5
335#define HID_GLOBAL_ITEM_TAG_UNIT 6
336#define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7
337#define HID_GLOBAL_ITEM_TAG_REPORT_ID 8
338#define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9
339#define HID_GLOBAL_ITEM_TAG_PUSH 10
340#define HID_GLOBAL_ITEM_TAG_POP 11
341
342//
343// HID report descriptor local item tags
344//
345#define HID_LOCAL_ITEM_TAG_USAGE 0
346#define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1
347#define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2
348#define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3
349#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
350#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
351#define HID_LOCAL_ITEM_TAG_STRING_INDEX 7
352#define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8
353#define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9
354#define HID_LOCAL_ITEM_TAG_DELIMITER 10
355
356//
357// HID report types
358//
359#define HID_INPUT_REPORT 1
360#define HID_OUTPUT_REPORT 2
361#define HID_FEATURE_REPORT 3
362
363//
364// HID class protocol request
365//
366#define EFI_USB_GET_REPORT_REQUEST 0x01
367#define EFI_USB_GET_IDLE_REQUEST 0x02
368#define EFI_USB_GET_PROTOCOL_REQUEST 0x03
369#define EFI_USB_SET_REPORT_REQUEST 0x09
370#define EFI_USB_SET_IDLE_REQUEST 0x0a
371#define EFI_USB_SET_PROTOCOL_REQUEST 0x0b
372
373#pragma pack(1)
374///
375/// Descriptor header for Report/Physical Descriptors
376/// HID 1.1, section 6.2.1
377///
382
383///
384/// The HID descriptor identifies the length and type
385/// of subordinate descriptors for a device.
386/// HID 1.1, section 6.2.1
387///
396
397#pragma pack()
unsigned short UINT16
2-byte unsigned value.
unsigned short CHAR16
2-byte Character.
unsigned char UINT8
1-byte unsigned value.
struct hid_class_descriptor EFI_USB_HID_CLASS_DESCRIPTOR
Descriptor header for Report/Physical Descriptors HID 1.1, section 6.2.1.
struct hid_descriptor EFI_USB_HID_DESCRIPTOR
The HID descriptor identifies the length and type of subordinate descriptors for a device.
USB_TYPES_DEFINITION
Definition Usb.h:194
@ USB_DESC_TYPE_REPORT
Definition Usb.h:236
@ USB_REQ_SYNCH_FRAME
Definition Usb.h:216
@ USB_TARGET_INTERFACE
Definition Usb.h:222
@ USB_DESC_TYPE_ENDPOINT
Definition Usb.h:233
@ USB_REQ_SET_INTERFACE
Definition Usb.h:215
@ USB_REQ_GET_DESCRIPTOR
Definition Usb.h:210
@ USB_REQ_SET_DESCRIPTOR
Definition Usb.h:211
@ USB_ENDPOINT_TYPE_MASK
Definition Usb.h:253
@ USB_ENDPOINT_DIR_IN
Definition Usb.h:254
@ USB_DESC_TYPE_CONFIG
Definition Usb.h:230
@ USB_DESC_TYPE_INTERFACE_ASSOCIATION
Definition Usb.h:234
@ USB_REQ_CLEAR_FEATURE
Definition Usb.h:207
@ USB_DESC_TYPE_HID
Definition Usb.h:235
@ USB_DESC_TYPE_INTERFACE
Definition Usb.h:232
@ USB_DESC_TYPE_DEVICE
Definition Usb.h:229
@ USB_TARGET_ENDPOINT
Definition Usb.h:223
@ USB_DESC_TYPE_CS_INTERFACE
Definition Usb.h:237
@ USB_ENDPOINT_ISO
Definition Usb.h:249
@ USB_REQ_GET_INTERFACE
Definition Usb.h:214
@ USB_REQ_SET_ADDRESS
Definition Usb.h:209
@ USB_ENDPOINT_BULK
Definition Usb.h:250
@ USB_TARGET_DEVICE
Definition Usb.h:221
@ USB_REQ_GET_STATUS
Definition Usb.h:206
@ USB_ENDPOINT_CONTROL
Definition Usb.h:248
@ USB_REQ_TYPE_STANDARD
Definition Usb.h:198
@ USB_TARGET_OTHER
Definition Usb.h:224
@ EFI_USB_INTERRUPT_DELAY
Definition Usb.h:259
@ USB_REQ_GET_CONFIG
Definition Usb.h:212
@ USB_REQ_SET_FEATURE
Definition Usb.h:208
@ USB_REQ_SET_CONFIG
Definition Usb.h:213
@ USB_ENDPOINT_INTERRUPT
Definition Usb.h:251
@ USB_DESC_TYPE_CS_ENDPOINT
Definition Usb.h:238
@ USB_FEATURE_ENDPOINT_HALT
Definition Usb.h:243
@ USB_REQ_TYPE_CLASS
Definition Usb.h:199
@ USB_REQ_TYPE_VENDOR
Definition Usb.h:200
@ USB_DESC_TYPE_STRING
Definition Usb.h:231
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
#define USB_ENDPOINT_DESCRIPTOR
A USB endpoint descriptor.
Definition usb.h:278
#define USB_INTERFACE_DESCRIPTOR
A USB interface descriptor.
Definition usb.h:261
#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR
A USB interface association descriptor.
Definition usb.h:343
#define USB_DEVICE_DESCRIPTOR
A USB device descriptor.
Definition usb.h:207
UNICODE String Descriptor USB 2.0 spec, Section 9.6.7.
Definition Usb.h:186
Standard Configuration Descriptor USB 2.0 spec, Section 9.6.3.
Definition Usb.h:127
UINT8 ConfigurationValue
Definition Usb.h:132
UINT16 TotalLength
Definition Usb.h:130
UINT8 Configuration
Definition Usb.h:133
UINT8 DescriptorType
Definition Usb.h:129
UINT8 NumInterfaces
Definition Usb.h:131
UINT8 DeviceProtocol
Definition Usb.h:112
UINT8 MaxPacketSize0
Definition Usb.h:113
UINT8 NumConfigurations
Definition Usb.h:120
UINT8 DeviceSubClass
Definition Usb.h:111
UINT8 DescriptorType
Definition Usb.h:108
UINT8 StrManufacturer
Definition Usb.h:117
UINT8 StrSerialNumber
Definition Usb.h:119
Format of Setup Data for USB Device Requests USB 2.0 spec, Section 9.3.
Definition Usb.h:94
UINT16 Length
Definition Usb.h:99
UINT8 Request
Definition Usb.h:96
UINT16 Value
Definition Usb.h:97
UINT8 RequestType
Definition Usb.h:95
UINT16 Index
Definition Usb.h:98
Descriptor header for Report/Physical Descriptors HID 1.1, section 6.2.1.
Definition Usb.h:378
UINT16 DescriptorLength
Definition Usb.h:380
UINT8 DescriptorType
Definition Usb.h:379
The HID descriptor identifies the length and type of subordinate descriptors for a device.
Definition Usb.h:388
UINT8 DescriptorType
Definition Usb.h:390
UINT8 NumDescriptors
Definition Usb.h:393
UINT8 Length
Definition Usb.h:389
EFI_USB_HID_CLASS_DESCRIPTOR HidClassDesc[1]
Definition Usb.h:394
UINT8 CountryCode
Definition Usb.h:392
UINT16 BcdHID
Definition Usb.h:391