libnx  v4.7.0
usb.h
Go to the documentation of this file.
1 /**
2  * @file usb.h
3  * @brief Common USB (usb:*) service IPC header.
4  * @author SciresM, yellows8
5  * @copyright libnx Authors
6  */
7 #pragma once
8 #include "../types.h"
9 
10 /// Names starting with "libusb" were changed to "usb" to avoid collision with actual libusb if it's ever used.
11 
12 /// Imported from libusb with changed names.
13 /* Descriptor sizes per descriptor type */
14 #define USB_DT_INTERFACE_SIZE 9
15 #define USB_DT_ENDPOINT_SIZE 7
16 #define USB_DT_DEVICE_SIZE 0x12
17 #define USB_DT_SS_ENDPOINT_COMPANION_SIZE 6
18 
19 #define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
20 #define USB_ENDPOINT_DIR_MASK 0x80
21 
22 #define USB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
23 
24 /// Imported from libusb, with some adjustments.
26  uint8_t bLength;
27  uint8_t bDescriptorType; ///< Must match USB_DT_ENDPOINT.
28  uint8_t bEndpointAddress; ///< Should be one of the usb_endpoint_direction values, the endpoint-number is automatically allocated.
29  uint8_t bmAttributes;
30  uint16_t wMaxPacketSize;
31  uint8_t bInterval;
32 } NX_PACKED;
33 
34 /// Imported from libusb, with some adjustments.
36  uint8_t bLength;
37  uint8_t bDescriptorType; ///< Must match USB_DT_INTERFACE.
38  uint8_t bInterfaceNumber; ///< See also USBDS_DEFAULT_InterfaceNumber.
39  uint8_t bAlternateSetting; ///< Must match 0.
40  uint8_t bNumEndpoints;
41  uint8_t bInterfaceClass;
42  uint8_t bInterfaceSubClass;
43  uint8_t bInterfaceProtocol;
44  uint8_t iInterface; ///< Ignored.
45 };
46 
47 /// Imported from libusb, with some adjustments.
49  uint8_t bLength;
50  uint8_t bDescriptorType; ///< Must match USB_DT_Device.
51  uint16_t bcdUSB;
52  uint8_t bDeviceClass;
53  uint8_t bDeviceSubClass;
54  uint8_t bDeviceProtocol;
55  uint8_t bMaxPacketSize0;
56  uint16_t idVendor;
57  uint16_t idProduct;
58  uint16_t bcdDevice;
59  uint8_t iManufacturer;
60  uint8_t iProduct;
61  uint8_t iSerialNumber;
62  uint8_t bNumConfigurations;
63 };
64 
65 /// Imported from libusb, with some adjustments.
67  uint8_t bLength;
68  uint8_t bDescriptorType;
69  uint16_t wTotalLength;
70  uint8_t bNumInterfaces;
71  uint8_t bConfigurationValue;
72  uint8_t iConfiguration;
73  uint8_t bmAttributes;
74  uint8_t MaxPower;
75 } NX_PACKED;
76 
77 /// Imported from libusb, with some adjustments.
79  uint8_t bLength;
80  uint8_t bDescriptorType; ///< Must match USB_DT_SS_ENDPOINT_COMPANION.
81  uint8_t bMaxBurst;
82  uint8_t bmAttributes;
83  uint16_t wBytesPerInterval;
84 };
85 
86 /// Imported from libusb, with some adjustments.
88  uint8_t bLength;
89  uint8_t bDescriptorType; ///< Must match USB_DT_STRING.
90  uint16_t wData[0x40];
91 };
92 
93 /// Imported from libusb, with changed names.
95  USB_CLASS_PER_INTERFACE = 0,
96  USB_CLASS_AUDIO = 1,
97  USB_CLASS_COMM = 2,
98  USB_CLASS_HID = 3,
99  USB_CLASS_PHYSICAL = 5,
100  USB_CLASS_PRINTER = 7,
101  USB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */
102  USB_CLASS_IMAGE = 6,
103  USB_CLASS_MASS_STORAGE = 8,
104  USB_CLASS_HUB = 9,
105  USB_CLASS_DATA = 10,
106  USB_CLASS_SMART_CARD = 0x0b,
107  USB_CLASS_CONTENT_SECURITY = 0x0d,
108  USB_CLASS_VIDEO = 0x0e,
109  USB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
110  USB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
111  USB_CLASS_WIRELESS = 0xe0,
112  USB_CLASS_APPLICATION = 0xfe,
113  USB_CLASS_VENDOR_SPEC = 0xff
114 };
115 
116 /// Imported from libusb, with changed names.
118  USB_DT_DEVICE = 0x01,
119  USB_DT_CONFIG = 0x02,
120  USB_DT_STRING = 0x03,
121  USB_DT_INTERFACE = 0x04,
122  USB_DT_ENDPOINT = 0x05,
123  USB_DT_BOS = 0x0f,
124  USB_DT_DEVICE_CAPABILITY = 0x10,
125  USB_DT_HID = 0x21,
126  USB_DT_REPORT = 0x22,
127  USB_DT_PHYSICAL = 0x23,
128  USB_DT_HUB = 0x29,
129  USB_DT_SUPERSPEED_HUB = 0x2a,
130  USB_DT_SS_ENDPOINT_COMPANION = 0x30
131 };
132 
133 /// Imported from libusb, with changed names.
135  USB_ENDPOINT_IN = 0x80,
136  USB_ENDPOINT_OUT = 0x00
137 };
138 
139 /// Imported from libusb, with changed names.
141  USB_TRANSFER_TYPE_CONTROL = 0,
142  USB_TRANSFER_TYPE_ISOCHRONOUS = 1,
143  USB_TRANSFER_TYPE_BULK = 2,
144  USB_TRANSFER_TYPE_INTERRUPT = 3,
145  USB_TRANSFER_TYPE_BULK_STREAM = 4,
146 };
147 
148 /// Imported from libusb, with changed names.
150  /** Request status of the specific recipient */
152 
153  /** Clear or disable a specific feature */
155 
156  /* 0x02 is reserved */
157 
158  /** Set or enable a specific feature */
160 
161  /* 0x04 is reserved */
162 
163  /** Set device address for all future accesses */
165 
166  /** Get the specified descriptor */
168 
169  /** Used to update existing descriptors or add new descriptors */
171 
172  /** Get the current device configuration value */
174 
175  /** Set device configuration */
177 
178  /** Return the selected alternate setting for the specified interface */
180 
181  /** Select an alternate interface for the specified interface */
183 
184  /** Set then report an endpoint's synchronization frame */
186 
187  /** Sets both the U1 and U2 Exit Latency */
189 
190  /** Delay from the time a host transmits a packet to the time it is
191  * received by the device. */
193 };
194 
195 /// Imported from libusb, with changed names.
197  USB_ISO_SYNC_TYPE_NONE = 0,
198  USB_ISO_SYNC_TYPE_ASYNC = 1,
199  USB_ISO_SYNC_TYPE_ADAPTIVE = 2,
200  USB_ISO_SYNC_TYPE_SYNC = 3
201 };
202 
203 /// Imported from libusb, with changed names.
205  USB_ISO_USAGE_TYPE_DATA = 0,
206  USB_ISO_USAGE_TYPE_FEEDBACK = 1,
207  USB_ISO_USAGE_TYPE_IMPLICIT = 2,
208 };
209 
210 /// USB Device States, per USB 2.0 spec
211 typedef enum {
212  UsbState_Detached = 0, ///< Device is not attached to USB.
213  UsbState_Attached = 1, ///< Device is attached, but is not powered.
214  UsbState_Powered = 2, ///< Device is attached and powered, but has not been reset.
215  UsbState_Default = 3, ///< Device is attached, powered, and has been reset, but does not have an address.
216  UsbState_Address = 4, ///< Device is attached, powered, has been reset, has an address, but is not configured.
217  UsbState_Configured = 5, ///< Device is attached, powered, has been reset, has an address, configured, and may be used.
218  UsbState_Suspended = 6, ///< Device is attached and powered, but has not seen bus activity for 3ms. Device is suspended and cannot be used.
219 } UsbState;
220 
Imported from libusb, with some adjustments.
Definition: usb.h:66
Imported from libusb, with some adjustments.
Definition: usb.h:48
uint8_t bDescriptorType
Must match USB_DT_Device.
Definition: usb.h:50
Imported from libusb, with some adjustments.
Definition: usb.h:25
uint8_t bEndpointAddress
Should be one of the usb_endpoint_direction values, the endpoint-number is automatically allocated.
Definition: usb.h:28
uint8_t bDescriptorType
Must match USB_DT_ENDPOINT.
Definition: usb.h:27
Imported from libusb, with some adjustments.
Definition: usb.h:35
uint8_t iInterface
Ignored.
Definition: usb.h:44
uint8_t bDescriptorType
Must match USB_DT_INTERFACE.
Definition: usb.h:37
uint8_t bAlternateSetting
Must match 0.
Definition: usb.h:39
uint8_t bInterfaceNumber
See also USBDS_DEFAULT_InterfaceNumber.
Definition: usb.h:38
Imported from libusb, with some adjustments.
Definition: usb.h:78
uint8_t bDescriptorType
Must match USB_DT_SS_ENDPOINT_COMPANION.
Definition: usb.h:80
Imported from libusb, with some adjustments.
Definition: usb.h:87
uint8_t bDescriptorType
Must match USB_DT_STRING.
Definition: usb.h:89
#define NX_PACKED
Packs a struct so that it won't include padding bytes.
Definition: types.h:63
usb_class_code
Imported from libusb, with changed names.
Definition: usb.h:94
usb_standard_request
Imported from libusb, with changed names.
Definition: usb.h:149
@ USB_REQUEST_SET_CONFIGURATION
Set device configuration.
Definition: usb.h:176
@ USB_REQUEST_SET_ADDRESS
Set device address for all future accesses.
Definition: usb.h:164
@ USB_REQUEST_SYNCH_FRAME
Set then report an endpoint's synchronization frame.
Definition: usb.h:185
@ USB_REQUEST_CLEAR_FEATURE
Clear or disable a specific feature.
Definition: usb.h:154
@ USB_SET_ISOCH_DELAY
Delay from the time a host transmits a packet to the time it is received by the device.
Definition: usb.h:192
@ USB_REQUEST_GET_INTERFACE
Return the selected alternate setting for the specified interface.
Definition: usb.h:179
@ USB_REQUEST_SET_DESCRIPTOR
Used to update existing descriptors or add new descriptors.
Definition: usb.h:170
@ USB_REQUEST_SET_SEL
Sets both the U1 and U2 Exit Latency.
Definition: usb.h:188
@ USB_REQUEST_GET_STATUS
Request status of the specific recipient.
Definition: usb.h:151
@ USB_REQUEST_SET_FEATURE
Set or enable a specific feature.
Definition: usb.h:159
@ USB_REQUEST_SET_INTERFACE
Select an alternate interface for the specified interface.
Definition: usb.h:182
@ USB_REQUEST_GET_DESCRIPTOR
Get the specified descriptor.
Definition: usb.h:167
@ USB_REQUEST_GET_CONFIGURATION
Get the current device configuration value.
Definition: usb.h:173
UsbState
USB Device States, per USB 2.0 spec.
Definition: usb.h:211
@ UsbState_Default
Device is attached, powered, and has been reset, but does not have an address.
Definition: usb.h:215
@ UsbState_Detached
Device is not attached to USB.
Definition: usb.h:212
@ UsbState_Address
Device is attached, powered, has been reset, has an address, but is not configured.
Definition: usb.h:216
@ UsbState_Powered
Device is attached and powered, but has not been reset.
Definition: usb.h:214
@ UsbState_Suspended
Device is attached and powered, but has not seen bus activity for 3ms. Device is suspended and cannot...
Definition: usb.h:218
@ UsbState_Configured
Device is attached, powered, has been reset, has an address, configured, and may be used.
Definition: usb.h:217
@ UsbState_Attached
Device is attached, but is not powered.
Definition: usb.h:213
usb_descriptor_type
Imported from libusb, with changed names.
Definition: usb.h:117
usb_endpoint_direction
Imported from libusb, with changed names.
Definition: usb.h:134
usb_iso_usage_type
Imported from libusb, with changed names.
Definition: usb.h:204
usb_iso_sync_type
Imported from libusb, with changed names.
Definition: usb.h:196
usb_transfer_type
Imported from libusb, with changed names.
Definition: usb.h:140