1 /**
2  * Converted/butchered LIBUSB header to a D-Language interface
3  *
4  * Authors: Ross Lonstein <lonstein@brightboxcharge.com>
5  * License: LGPL
6  * Copyright: 2015, Brightbox, Inc.
7  * See_Also: http://www.libusb.org
8  * Notes: Libusb itself is Copyright
9  * $(UL
10  *   $(LI 2001 Johannes Erdfelt <johannes@erdfelt.com>)
11  *   $(LI 2007-2008 Daniel Drake <dsd@gentoo.org>)
12  *   $(LI 2012 Pete Batard <pete@akeo.ie>)
13  *   $(LI 2012 Nathan Hjelm <hjelmn@cs.unm.edu>) )
14  *
15  */
16 
17 module enums;
18 
19 alias libusb_hotplug_flag = LIBUSB_HOTPLUG_ENUM;
20 alias libusb_hotplug_event = LIBUSB_HOTPLUG_EVENTS;
21 
22 extern (C):
23 
24 /**
25  * Device and/or Interface Class codes
26  */
27 enum libusb_class_code : ubyte {
28   LIBUSB_CLASS_PER_INTERFACE       = 0,
29   LIBUSB_CLASS_AUDIO               = 1,     /** Audio class */
30   LIBUSB_CLASS_COMM                = 2,     /** Communications class */
31   LIBUSB_CLASS_HID                 = 3,     /** Human Interface Device class */
32   LIBUSB_CLASS_PHYSICAL            = 5,     /** Physical */
33   LIBUSB_CLASS_PRINTER             = 7,     /** Printer class */
34   LIBUSB_CLASS_PTP                 = 6,     /** legacy name from libusb-0.1 usb.h */
35   LIBUSB_CLASS_IMAGE               = 6,     /** Image class */
36   LIBUSB_CLASS_MASS_STORAGE        = 8,     /** Mass storage class */
37   LIBUSB_CLASS_HUB                 = 9,     /** Hub class */
38   LIBUSB_CLASS_DATA                = 10,    /** Data class */
39   LIBUSB_CLASS_SMART_CARD          = 0x0b,  /** Smart Card */
40   LIBUSB_CLASS_CONTENT_SECURITY    = 0x0d,  /** Content Security */
41   LIBUSB_CLASS_VIDEO               = 0x0e,  /** Video */
42   LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,  /** Personal Healthcare */
43   LIBUSB_CLASS_DIAGNOSTIC_DEVICE   = 0xdc,  /** Diagnostic Device */
44   LIBUSB_CLASS_WIRELESS            = 0xe0,  /** Wireless class */
45   LIBUSB_CLASS_APPLICATION         = 0xfe,  /** Application class */
46   LIBUSB_CLASS_VENDOR_SPEC         = 0xff   /** Class is vendor-specific */
47 };
48 
49 
50 /**
51  * Descriptor types as defined by the USB specification.
52  */
53 enum libusb_descriptor_type : ubyte {
54   LIBUSB_DT_DEVICE                = 0x01, /** Device descriptor. See libusb_device_descriptor. */
55   LIBUSB_DT_CONFIG                = 0x02, /** Configuration descriptor. See libusb_config_descriptor. */
56   LIBUSB_DT_STRING                = 0x03, /** String descriptor  */
57   LIBUSB_DT_INTERFACE             = 0x04, /** Interface descriptor. See libusb_interface_descriptor. */
58   LIBUSB_DT_ENDPOINT              = 0x05, /** Endpoint descriptor. See libusb_endpoint_descriptor. */
59   LIBUSB_DT_BOS                   = 0x0f, /** BOS descriptor  */
60   LIBUSB_DT_DEVICE_CAPABILITY     = 0x10, /** Device Capability descriptor */
61   LIBUSB_DT_HID                   = 0x21, /** HID descriptor */
62   LIBUSB_DT_REPORT                = 0x22, /** HID report descriptor */
63   LIBUSB_DT_PHYSICAL              = 0x23, /** Physical descriptor */
64   LIBUSB_DT_HUB                   = 0x29, /** Hub descriptor */
65   LIBUSB_DT_SUPERSPEED_HUB        = 0x2a, /** SuperSpeed Hub descriptor */
66   LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30  /** SuperSpeed Endpoint Companion descriptor */
67 };
68 
69 
70 /**
71  * Endpoint direction. Values for bit 7 of the
72  * libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
73  */
74 enum libusb_endpoint_direction : ubyte {
75   LIBUSB_ENDPOINT_IN  = 0x80,    /** In:  device-to-host */
76   LIBUSB_ENDPOINT_OUT = 0x00     /** Out: host-to-device */
77 };
78 
79 
80 /**
81  * Endpoint transfer type. Values for bits 0:1 of the
82  * libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
83  */
84 enum libusb_transfer_type : ubyte {
85   LIBUSB_TRANSFER_TYPE_CONTROL     = 0,   /** Control endpoint */
86   LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,   /** Isochronous endpoint */
87   LIBUSB_TRANSFER_TYPE_BULK        = 2,   /** Bulk endpoint */
88   LIBUSB_TRANSFER_TYPE_INTERRUPT   = 3    /** Interrupt endpoint */
89 };
90 
91 
92 /**
93  * Standard requests, as defined in table 9-5 of the USB 3.0 specifications
94  */
95 enum libusb_standard_request {
96   LIBUSB_REQUEST_GET_STATUS        = 0x00, /** Request status of the specific recipient */
97   LIBUSB_REQUEST_CLEAR_FEATURE     = 0x01, /** Clear or disable a specific feature */
98   /* 0x02 is reserved */
99   LIBUSB_REQUEST_SET_FEATURE       = 0x03, /** Set or enable a specific feature */
100   /* 0x04 is reserved */
101   LIBUSB_REQUEST_SET_ADDRESS       = 0x05, /** Set device address for all future accesses */
102   LIBUSB_REQUEST_GET_DESCRIPTOR    = 0x06, /** Get the specified descriptor */
103   LIBUSB_REQUEST_SET_DESCRIPTOR    = 0x07, /** Used to update existing descriptors or add new descriptors */
104   LIBUSB_REQUEST_GET_CONFIGURATION = 0x08, /** Get the current device configuration value */
105   LIBUSB_REQUEST_SET_CONFIGURATION = 0x09, /** Set device configuration */
106   LIBUSB_REQUEST_GET_INTERFACE     = 0x0A, /** Return the selected alternate setting for the specified interface */
107   LIBUSB_REQUEST_SET_INTERFACE     = 0x0B, /** Select an alternate interface for the specified interface */
108   LIBUSB_REQUEST_SYNCH_FRAME       = 0x0C, /** Set then report an endpoint's synchronization frame */
109   LIBUSB_REQUEST_SET_SEL           = 0x30, /** Sets both the U1 and U2 Exit Latency */
110   LIBUSB_SET_ISOCH_DELAY           = 0x31, /** Delay from the time a host transmits a packet to the time it is received by the device. */
111 };
112 
113 
114 /**
115  * Request type bits of the libusb_control_setup::bmRequestType
116  * "bmRequestType" field in control transfers. 
117  */
118 enum libusb_request_type : ubyte {
119   LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),   /** Standard */
120   LIBUSB_REQUEST_TYPE_CLASS    = (0x01 << 5),   /** Class */
121   LIBUSB_REQUEST_TYPE_VENDOR   = (0x02 << 5),   /** Vendor */
122   LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)    /** Reserved */
123 };
124 
125 
126 /**
127  * Recipient bits of the
128  * libusb_control_setup::bmRequestType "bmRequestType" field in control
129  * transfers. Values 4 through 31 are reserved. */
130 enum libusb_request_recipient {
131   LIBUSB_RECIPIENT_DEVICE    = 0x00,  /** Device */
132   LIBUSB_RECIPIENT_INTERFACE = 0x01,  /** Interface */
133   LIBUSB_RECIPIENT_ENDPOINT  = 0x02,  /** Endpoint */
134   LIBUSB_RECIPIENT_OTHER     = 0x03,  /** Other */
135 };
136 
137 
138 /**
139  * Synchronization type for isochronous endpoints. Values for bits 2:3 of the
140  * libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
141  * libusb_endpoint_descriptor.
142  */
143 enum libusb_iso_sync_type {
144   LIBUSB_ISO_SYNC_TYPE_NONE     = 0,  /** No synchronization */
145   LIBUSB_ISO_SYNC_TYPE_ASYNC    = 1,  /** Asynchronous */
146   LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,  /** Adaptive */
147   LIBUSB_ISO_SYNC_TYPE_SYNC     = 3   /** Synchronous */
148 };
149 
150 
151 /**
152  * Usage type for isochronous endpoints. Values for bits 4:5 of the
153  * libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
154  * libusb_endpoint_descriptor.
155  */
156 enum libusb_iso_usage_type {
157     LIBUSB_ISO_USAGE_TYPE_DATA     = 0,  /** Data endpoint */
158     LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,  /** Feedback endpoint */
159     LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,  /** Implicit feedback Data endpoint */
160 };
161 
162 
163 /**
164  * Speed codes. Indicates the speed at which the device is operating.
165  */
166 enum libusb_speed {
167     LIBUSB_SPEED_UNKNOWN = 0,
168     LIBUSB_SPEED_LOW     = 1,  /** low speed (1.5MBit/s). */
169     LIBUSB_SPEED_FULL    = 2,  /** full speed (12MBit/s). */
170     LIBUSB_SPEED_HIGH    = 3,  /** high speed (480MBit/s). */
171     LIBUSB_SPEED_SUPER   = 4,  /** super speed (5000MBit/s). */
172 };
173 
174 
175 /**
176  * Supported speeds (wSpeedSupported) bitfield. Indicates what
177  * speeds the device supports.
178  */
179 enum libusb_supported_speed {
180     LIBUSB_LOW_SPEED_OPERATION   = 1,  /** Low speed  supported (1.5MBit/s). */
181     LIBUSB_FULL_SPEED_OPERATION  = 2,  /** Full speed supported (12MBit/s). */
182     LIBUSB_HIGH_SPEED_OPERATION  = 4,  /** High speed supported (480MBit/s). */
183     LIBUSB_SUPER_SPEED_OPERATION = 8,  /** Superspeed supported (5000MBit/s). */
184 };
185 
186 
187 /**
188  * Masks for the bits of the
189  * libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field
190  * of the USB 2.0 Extension descriptor.
191  */
192 enum libusb_usb_2_0_extension_attributes {
193     LIBUSB_BM_LPM_SUPPORT = 2,    /** Supports Link Power Management (LPM) */
194 };
195 
196 
197 /**
198  * Masks for the bits of the
199  * libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field
200  * field of the SuperSpeed USB Device Capability descriptor.
201  */
202 enum libusb_ss_usb_device_capability_attributes {
203     LIBUSB_BM_LTM_SUPPORT = 2,    /** Supports Latency Tolerance Messages (LTM) */
204 };
205 
206 
207 /**
208  * USB capability types
209  */
210 enum libusb_bos_type {
211     LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1,    /** Wireless USB device capability */
212     LIBUSB_BT_USB_2_0_EXTENSION              = 2,    /** USB 2.0 extensions */
213     LIBUSB_BT_SS_USB_DEVICE_CAPABILITY       = 3,    /** SuperSpeed USB device capability */
214     LIBUSB_BT_CONTAINER_ID                   = 4,    /** Container ID type */
215 };
216 
217 
218 /**
219  * Error codes. Most libusbx functions return 0 on success or one of these
220  * codes on failure.
221  *
222  * You can call libusb_error_name() to retrieve a string representation of an
223  * error code or libusb_strerror() to get an end-user suitable description of
224  * an error code.
225  */
226 enum libusb_error : int {
227   LIBUSB_SUCCESS             =  0,  /** Success (no error) */
228   LIBUSB_ERROR_IO            = -1,  /** Input/output error */
229   LIBUSB_ERROR_INVALID_PARAM = -2,  /** Invalid parameter */
230   LIBUSB_ERROR_ACCESS        = -3,  /** Access denied (insufficient permissions) */
231   LIBUSB_ERROR_NO_DEVICE     = -4,  /** No such device (it may have been disconnected) */
232   LIBUSB_ERROR_NOT_FOUND     = -5,  /** Entity not found */
233   LIBUSB_ERROR_BUSY          = -6,  /** Resource busy */
234   LIBUSB_ERROR_TIMEOUT       = -7,  /** Operation timed out */
235   LIBUSB_ERROR_OVERFLOW      = -8,  /** Overflow */
236   LIBUSB_ERROR_PIPE          = -9,  /** Pipe error */
237   LIBUSB_ERROR_INTERRUPTED   = -10, /** System call interrupted */
238   LIBUSB_ERROR_NO_MEM        = -11, /** Insufficient memory */
239   LIBUSB_ERROR_NOT_SUPPORTED = -12, /** Operation not supported or unimplemented on this platform */
240   LIBUSB_ERROR_OTHER         = -99
241 };
242 
243 
244 /**
245  * Transfer status codes */
246 enum libusb_transfer_status {
247     /** Transfer completed without error. Note that this does not indicate
248      * that the entire amount of requested data was transferred. */
249     LIBUSB_TRANSFER_COMPLETED,
250 
251     /** Transfer failed */
252     LIBUSB_TRANSFER_ERROR,
253 
254     /** Transfer timed out */
255     LIBUSB_TRANSFER_TIMED_OUT,
256 
257     /** Transfer was cancelled */
258     LIBUSB_TRANSFER_CANCELLED,
259 
260     /** For bulk/interrupt endpoints: halt condition detected (endpoint
261      * stalled). For control endpoints: control request not supported. */
262     LIBUSB_TRANSFER_STALL,
263 
264     /** Device was disconnected */
265     LIBUSB_TRANSFER_NO_DEVICE,
266 
267     /** Device sent more data than requested */
268     LIBUSB_TRANSFER_OVERFLOW,
269 
270     /* NB! Remember to update libusb_error_name()
271        when adding new status codes here. */
272 };
273 
274 
275 /**
276  * libusb_transfer.flags values */
277 enum libusb_transfer_flags {
278     /** Report short frames as errors */
279     LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
280 
281     /** Automatically free() transfer buffer during libusb_free_transfer() */
282     LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
283 
284     /** Automatically call libusb_free_transfer() after callback returns.
285      * If this flag is set, it is illegal to call libusb_free_transfer()
286      * from your transfer callback, as this will result in a double-free
287      * when this flag is acted upon. */
288     LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
289 
290     /** Terminate transfers that are a multiple of the endpoint's
291      * wMaxPacketSize with an extra zero length packet. This is useful
292      * when a device protocol mandates that each logical request is
293      * terminated by an incomplete packet (i.e. the logical requests are
294      * not separated by other means).
295      *
296      * This flag only affects host-to-device transfers to bulk and interrupt
297      * endpoints. In other situations, it is ignored.
298      *
299      * This flag only affects transfers with a length that is a multiple of
300      * the endpoint's wMaxPacketSize. On transfers of other lengths, this
301      * flag has no effect. Therefore, if you are working with a device that
302      * needs a ZLP whenever the end of the logical request falls on a packet
303      * boundary, then it is sensible to set this flag on <em>every</em>
304      * transfer (you do not have to worry about only setting it on transfers
305      * that end on the boundary).
306      *
307      * This flag is currently only supported on Linux.
308      * On other systems, libusb_submit_transfer() will return
309      * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set.
310      *
311      * Available since libusb-1.0.9.
312      */
313     LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
314 };
315 
316 
317 /**
318  * Capabilities supported by an instance of libusb on the current running
319  * platform. Test if the loaded library supports a given capability by calling
320  * libusb_has_capability().
321  */
322 enum libusb_capability {
323   LIBUSB_CAP_HAS_CAPABILITY = 0x0000, /** The libusb_has_capability() API is available. */
324   LIBUSB_CAP_HAS_HOTPLUG    = 0x0001, /** Hotplug support is available on this platform. */
325   LIBUSB_CAP_HAS_HID_ACCESS = 0x0100, /** The library can access HID devices without requiring user intervention.
326                                        *
327                                        * Note that before being able to actually access an HID device, you may
328                                        * still have to call additional libusbx functions such as
329                                        * libusb_detach_kernel_driver(). */
330   LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101 /** The library supports detaching of the default USB driver, using
331                                                      * libusb_detach_kernel_driver(), if one is set by the OS kernel */
332 };
333 
334 /**
335  *  Log message levels.
336  *
337  * $(UL
338  *  $(LI LIBUSB_LOG_LEVEL_NONE (0)    : no messages ever printed by the library (default))
339  *  $(LI LIBUSB_LOG_LEVEL_ERROR (1)   : error messages are printed to stderr)
340  *  $(LI LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr)
341  *  $(LI LIBUSB_LOG_LEVEL_INFO (3)    : informational messages are printed to stdout, warning
342  *    and error messages are printed to stderr)
343  *  $(LI LIBUSB_LOG_LEVEL_DEBUG (4)   : debug and informational messages are printed to stdout,
344  *    warnings and errors to stderr)
345  * )
346  */
347 enum libusb_log_level {
348     LIBUSB_LOG_LEVEL_NONE = 0,
349     LIBUSB_LOG_LEVEL_ERROR,
350     LIBUSB_LOG_LEVEL_WARNING,
351     LIBUSB_LOG_LEVEL_INFO,
352     LIBUSB_LOG_LEVEL_DEBUG,
353 };
354 
355 
356 /**
357  * Flags for hotplug events
358  *
359  * Since version 1.0.16, LIBUSBX_API_VERSION >= 0x01000102
360  */
361 enum LIBUSB_HOTPLUG_ENUM {
362     /** Arm the callback and fire it for all matching currently attached devices. */
363     LIBUSB_HOTPLUG_ENUMERATE = 1,
364 };
365 
366 
367 /**
368  * Hotplug events
369  *
370  * Since version 1.0.16, LIBUSBX_API_VERSION >= 0x01000102
371  *
372  */
373 enum LIBUSB_HOTPLUG_EVENTS {
374   /** A device has been plugged in and is ready to use */
375   LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01,
376 
377   /** A device has left and is no longer available.
378    * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device.
379    * It is safe to call libusb_get_device_descriptor on a device that has left */
380   LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT    = 0x02,
381 };