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