xref: /freebsd/lib/libusb/libusb.h (revision f81cdf24ba5436367377f7c8e8f51f6df2a75ca7)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef __LIBUSB_H__
29 #define	__LIBUSB_H__
30 
31 #ifndef LIBUSB_GLOBAL_INCLUDE_FILE
32 #include <stdint.h>
33 #include <sys/time.h>
34 #include <sys/types.h>
35 #endif
36 
37 #define	LIBUSB_API_VERSION 0x01000102
38 
39 #define	LIBUSB_CALL
40 
41 #ifdef __cplusplus
42 extern	"C" {
43 #endif
44 #if 0
45 }					/* indent fix */
46 
47 #endif
48 
49 /* libusb enums */
50 
51 enum libusb_class_code {
52 	LIBUSB_CLASS_PER_INTERFACE = 0,
53 	LIBUSB_CLASS_AUDIO = 1,
54 	LIBUSB_CLASS_COMM = 2,
55 	LIBUSB_CLASS_HID = 3,
56 	LIBUSB_CLASS_PHYSICAL = 5,
57 	LIBUSB_CLASS_PTP = 6,
58 	LIBUSB_CLASS_IMAGE = 6,
59 	LIBUSB_CLASS_PRINTER = 7,
60 	LIBUSB_CLASS_MASS_STORAGE = 8,
61 	LIBUSB_CLASS_HUB = 9,
62 	LIBUSB_CLASS_DATA = 10,
63 	LIBUSB_CLASS_SMART_CARD = 11,
64 	LIBUSB_CLASS_CONTENT_SECURITY = 13,
65 	LIBUSB_CLASS_VIDEO = 14,
66 	LIBUSB_CLASS_PERSONAL_HEALTHCARE = 15,
67 	LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
68 	LIBUSB_CLASS_WIRELESS = 0xe0,
69 	LIBUSB_CLASS_APPLICATION = 0xfe,
70 	LIBUSB_CLASS_VENDOR_SPEC = 0xff,
71 };
72 
73 enum libusb_descriptor_type {
74 	LIBUSB_DT_DEVICE = 0x01,
75 	LIBUSB_DT_CONFIG = 0x02,
76 	LIBUSB_DT_STRING = 0x03,
77 	LIBUSB_DT_INTERFACE = 0x04,
78 	LIBUSB_DT_ENDPOINT = 0x05,
79 	LIBUSB_DT_HID = 0x21,
80 	LIBUSB_DT_REPORT = 0x22,
81 	LIBUSB_DT_PHYSICAL = 0x23,
82 	LIBUSB_DT_HUB = 0x29,
83 	LIBUSB_DT_BOS = 0x0f,
84 	LIBUSB_DT_DEVICE_CAPABILITY = 0x10,
85 	LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30,
86 };
87 
88 enum libusb_device_capability_type {
89 	LIBUSB_WIRELESS_USB_DEVICE_CAPABILITY = 0x1,
90 	LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY = 0x2,
91 	LIBUSB_SS_USB_DEVICE_CAPABILITY = 0x3,
92 	LIBUSB_CONTAINER_ID_DEVICE_CAPABILITY = 0x4,
93 };
94 
95 #define	LIBUSB_DT_DEVICE_SIZE		18
96 #define	LIBUSB_DT_CONFIG_SIZE		9
97 #define	LIBUSB_DT_INTERFACE_SIZE	9
98 #define	LIBUSB_DT_ENDPOINT_SIZE		7
99 #define	LIBUSB_DT_ENDPOINT_AUDIO_SIZE	9
100 #define	LIBUSB_DT_HUB_NONVAR_SIZE	7
101 #define	LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE	6
102 #define	LIBUSB_DT_BOS_SIZE		5
103 #define	LIBUSB_USB_2_0_EXTENSION_DEVICE_CAPABILITY_SIZE	7
104 #define	LIBUSB_SS_USB_DEVICE_CAPABILITY_SIZE	10
105 
106 #define	LIBUSB_BT_USB_2_0_EXTENSION_SIZE	7
107 #define	LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE	10
108 #define	LIBUSB_BT_CONTAINER_ID_SIZE		20
109 
110 #define	LIBUSB_ENDPOINT_ADDRESS_MASK	0x0f
111 #define	LIBUSB_ENDPOINT_DIR_MASK	0x80
112 
113 enum libusb_endpoint_direction {
114 	LIBUSB_ENDPOINT_IN = 0x80,
115 	LIBUSB_ENDPOINT_OUT = 0x00,
116 };
117 
118 #define	LIBUSB_TRANSFER_TYPE_MASK	0x03
119 
120 enum libusb_transfer_type {
121 	LIBUSB_TRANSFER_TYPE_CONTROL = 0,
122 	LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
123 	LIBUSB_TRANSFER_TYPE_BULK = 2,
124 	LIBUSB_TRANSFER_TYPE_INTERRUPT = 3,
125 };
126 
127 enum libusb_standard_request {
128 	LIBUSB_REQUEST_GET_STATUS = 0x00,
129 	LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
130 	LIBUSB_REQUEST_SET_FEATURE = 0x03,
131 	LIBUSB_REQUEST_SET_ADDRESS = 0x05,
132 	LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
133 	LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
134 	LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
135 	LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
136 	LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
137 	LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
138 	LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
139 	LIBUSB_REQUEST_SET_SEL = 0x30,
140 	LIBUSB_REQUEST_SET_ISOCH_DELAY = 0x31,
141 };
142 
143 enum libusb_request_type {
144 	LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
145 	LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
146 	LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
147 	LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5),
148 };
149 
150 enum libusb_request_recipient {
151 	LIBUSB_RECIPIENT_DEVICE = 0x00,
152 	LIBUSB_RECIPIENT_INTERFACE = 0x01,
153 	LIBUSB_RECIPIENT_ENDPOINT = 0x02,
154 	LIBUSB_RECIPIENT_OTHER = 0x03,
155 };
156 
157 #define	LIBUSB_ISO_SYNC_TYPE_MASK	0x0C
158 
159 enum libusb_iso_sync_type {
160 	LIBUSB_ISO_SYNC_TYPE_NONE = 0,
161 	LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
162 	LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
163 	LIBUSB_ISO_SYNC_TYPE_SYNC = 3,
164 };
165 
166 #define	LIBUSB_ISO_USAGE_TYPE_MASK 0x30
167 
168 enum libusb_iso_usage_type {
169 	LIBUSB_ISO_USAGE_TYPE_DATA = 0,
170 	LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
171 	LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
172 };
173 
174 enum libusb_bos_type {
175 	LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1,
176 	LIBUSB_BT_USB_2_0_EXTENSION = 2,
177 	LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3,
178 	LIBUSB_BT_CONTAINER_ID = 4,
179 };
180 
181 enum libusb_capability {
182 	/* libusb supports libusb_has_capability(). */
183 	LIBUSB_CAP_HAS_CAPABILITY = 0,
184 	/* Hotplug support is available. */
185 	LIBUSB_CAP_HAS_HOTPLUG,
186 	/* Can access HID devices without requiring user intervention. */
187 	LIBUSB_CAP_HAS_HID_ACCESS,
188 
189 	/*
190 	 * Supports detaching of the default USB driver with
191 	 * libusb_detach_kernel_driver().
192 	 */
193 	LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER,
194 };
195 
196 enum libusb_error {
197 	LIBUSB_SUCCESS = 0,
198 	LIBUSB_ERROR_IO = -1,
199 	LIBUSB_ERROR_INVALID_PARAM = -2,
200 	LIBUSB_ERROR_ACCESS = -3,
201 	LIBUSB_ERROR_NO_DEVICE = -4,
202 	LIBUSB_ERROR_NOT_FOUND = -5,
203 	LIBUSB_ERROR_BUSY = -6,
204 	LIBUSB_ERROR_TIMEOUT = -7,
205 	LIBUSB_ERROR_OVERFLOW = -8,
206 	LIBUSB_ERROR_PIPE = -9,
207 	LIBUSB_ERROR_INTERRUPTED = -10,
208 	LIBUSB_ERROR_NO_MEM = -11,
209 	LIBUSB_ERROR_NOT_SUPPORTED = -12,
210 	LIBUSB_ERROR_OTHER = -99,
211 };
212 
213 enum libusb_speed {
214 	LIBUSB_SPEED_UNKNOWN = 0,
215 	LIBUSB_SPEED_LOW = 1,
216 	LIBUSB_SPEED_FULL = 2,
217 	LIBUSB_SPEED_HIGH = 3,
218 	LIBUSB_SPEED_SUPER = 4,
219 };
220 
221 enum libusb_transfer_status {
222 	LIBUSB_TRANSFER_COMPLETED,
223 	LIBUSB_TRANSFER_ERROR,
224 	LIBUSB_TRANSFER_TIMED_OUT,
225 	LIBUSB_TRANSFER_CANCELLED,
226 	LIBUSB_TRANSFER_STALL,
227 	LIBUSB_TRANSFER_NO_DEVICE,
228 	LIBUSB_TRANSFER_OVERFLOW,
229 };
230 
231 enum libusb_transfer_flags {
232 	LIBUSB_TRANSFER_SHORT_NOT_OK = 1 << 0,
233 	LIBUSB_TRANSFER_FREE_BUFFER = 1 << 1,
234 	LIBUSB_TRANSFER_FREE_TRANSFER = 1 << 2,
235 };
236 
237 enum libusb_log_level {
238        LIBUSB_LOG_LEVEL_NONE = 0,
239        LIBUSB_LOG_LEVEL_ERROR,
240        LIBUSB_LOG_LEVEL_WARNING,
241        LIBUSB_LOG_LEVEL_INFO,
242        LIBUSB_LOG_LEVEL_DEBUG
243 };
244 
245 /* XXX */
246 /* libusb_set_debug should take parameters from libusb_log_level
247  * above according to
248  *   https://libusb.sourceforge.io/api-1.0/group__libusb__lib.html
249  */
250 enum libusb_debug_level {
251 	LIBUSB_DEBUG_NO=0,
252 	LIBUSB_DEBUG_FUNCTION=1,
253 	LIBUSB_DEBUG_TRANSFER=2,
254 };
255 
256 #define	LIBUSB_HOTPLUG_MATCH_ANY -1
257 
258 typedef enum {
259 	LIBUSB_HOTPLUG_NO_FLAGS = 0,
260 	LIBUSB_HOTPLUG_ENUMERATE = 1 << 0,
261 } libusb_hotplug_flag;
262 
263 typedef enum {
264 	LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 1,
265 	LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 2,
266 } libusb_hotplug_event;
267 
268 enum libusb_option {
269 	LIBUSB_OPTION_LOG_LEVEL = 0,
270 	LIBUSB_OPTION_USE_USBDK = 1,
271 	LIBUSB_OPTION_NO_DEVICE_DISCOVERY = 2,
272 	LIBUSB_OPTION_WEAK_AUTHORITY = 2,
273 	LIBUSB_OPTION_MAX = 3,
274 };
275 
276 /* libusb structures */
277 
278 struct libusb_context;
279 struct libusb_device;
280 struct libusb_transfer;
281 struct libusb_device_handle;
282 struct libusb_hotplug_callback_handle_struct;
283 
284 struct libusb_pollfd {
285 	int	fd;
286 	short	events;
287 };
288 
289 struct libusb_version {
290 	const uint16_t major;
291 	const uint16_t minor;
292 	const uint16_t micro;
293 	const uint16_t nano;
294 	const char *rc;
295 	const char *describe;
296 };
297 
298 struct libusb_init_option {
299 	enum libusb_option option;
300 	union {
301 		int64_t ival;
302 	} value;
303 };
304 
305 typedef struct libusb_context libusb_context;
306 typedef struct libusb_device libusb_device;
307 typedef struct libusb_device_handle libusb_device_handle;
308 typedef struct libusb_pollfd libusb_pollfd;
309 typedef void (*libusb_pollfd_added_cb) (int fd, short events, void *user_data);
310 typedef void (*libusb_pollfd_removed_cb) (int fd, void *user_data);
311 typedef struct libusb_hotplug_callback_handle_struct *libusb_hotplug_callback_handle;
312 
313 typedef struct libusb_device_descriptor {
314 	uint8_t	bLength;
315 	uint8_t	bDescriptorType;
316 	uint16_t bcdUSB;
317 	uint8_t	bDeviceClass;
318 	uint8_t	bDeviceSubClass;
319 	uint8_t	bDeviceProtocol;
320 	uint8_t	bMaxPacketSize0;
321 	uint16_t idVendor;
322 	uint16_t idProduct;
323 	uint16_t bcdDevice;
324 	uint8_t	iManufacturer;
325 	uint8_t	iProduct;
326 	uint8_t	iSerialNumber;
327 	uint8_t	bNumConfigurations;
328 }	libusb_device_descriptor;
329 
330 typedef struct libusb_endpoint_descriptor {
331 	uint8_t	bLength;
332 	uint8_t	bDescriptorType;
333 	uint8_t	bEndpointAddress;
334 	uint8_t	bmAttributes;
335 	uint16_t wMaxPacketSize;
336 	uint8_t	bInterval;
337 	uint8_t	bRefresh;
338 	uint8_t	bSynchAddress;
339 	uint8_t *extra;
340 	int	extra_length;
341 }	libusb_endpoint_descriptor __aligned(sizeof(void *));
342 
343 typedef struct libusb_ss_endpoint_companion_descriptor {
344 	uint8_t bLength;
345 	uint8_t bDescriptorType;
346 	uint8_t bMaxBurst;
347 	uint8_t bmAttributes;
348 	uint16_t wBytesPerInterval;
349 }	libusb_ss_endpoint_companion_descriptor __aligned(sizeof(void *));
350 
351 typedef struct libusb_interface_descriptor {
352 	uint8_t	bLength;
353 	uint8_t	bDescriptorType;
354 	uint8_t	bInterfaceNumber;
355 	uint8_t	bAlternateSetting;
356 	uint8_t	bNumEndpoints;
357 	uint8_t	bInterfaceClass;
358 	uint8_t	bInterfaceSubClass;
359 	uint8_t	bInterfaceProtocol;
360 	uint8_t	iInterface;
361 	struct libusb_endpoint_descriptor *endpoint;
362 	uint8_t *extra;
363 	int	extra_length;
364 }	libusb_interface_descriptor __aligned(sizeof(void *));
365 
366 typedef struct libusb_interface {
367 	struct libusb_interface_descriptor *altsetting;
368 	int	num_altsetting;
369 }	libusb_interface __aligned(sizeof(void *));
370 
371 typedef struct libusb_config_descriptor {
372 	uint8_t	bLength;
373 	uint8_t	bDescriptorType;
374 	uint16_t wTotalLength;
375 	uint8_t	bNumInterfaces;
376 	uint8_t	bConfigurationValue;
377 	uint8_t	iConfiguration;
378 	uint8_t	bmAttributes;
379 	uint8_t	MaxPower;
380 	struct libusb_interface *interface;
381 	uint8_t *extra;
382 	int	extra_length;
383 }	libusb_config_descriptor __aligned(sizeof(void *));
384 
385 typedef struct libusb_usb_2_0_device_capability_descriptor {
386 	uint8_t bLength;
387 	uint8_t bDescriptorType;
388 	uint8_t bDevCapabilityType;
389 	uint32_t bmAttributes;
390 #define LIBUSB_USB_2_0_CAPABILITY_LPM_SUPPORT  (1 << 1)
391 }	libusb_usb_2_0_device_capability_descriptor __aligned(sizeof(void *));
392 
393 typedef struct libusb_ss_usb_device_capability_descriptor {
394 	uint8_t bLength;
395 	uint8_t bDescriptorType;
396 	uint8_t bDevCapabilityType;
397 	uint8_t bmAttributes;
398 #define LIBUSB_SS_USB_CAPABILITY_LPM_SUPPORT   (1 << 1)
399 	uint16_t wSpeedSupported;
400 #define LIBUSB_CAPABILITY_LOW_SPEED_OPERATION  (1)
401 #define LIBUSB_CAPABILITY_FULL_SPEED_OPERATION (1 << 1)
402 #define LIBUSB_CAPABILITY_HIGH_SPEED_OPERATION (1 << 2)
403 #define LIBUSB_CAPABILITY_5GBPS_OPERATION      (1 << 3)
404 	uint8_t bFunctionalitySupport;
405 	uint8_t bU1DevExitLat;
406 	uint16_t wU2DevExitLat;
407 }	libusb_ss_usb_device_capability_descriptor __aligned(sizeof(void *));
408 
409 typedef struct libusb_bos_dev_capability_descriptor {
410 	uint8_t bLength;
411 	uint8_t bDescriptorType;
412 	uint8_t bDevCapabilityType;
413 	uint8_t dev_capability_data[0];
414 }	libusb_bos_dev_capability_descriptor __aligned(sizeof(void *));
415 
416 typedef struct libusb_bos_descriptor {
417 	uint8_t bLength;
418 	uint8_t bDescriptorType;
419 	uint16_t wTotalLength;
420 	uint8_t bNumDeviceCapabilities;
421 	struct libusb_usb_2_0_device_capability_descriptor *usb_2_0_ext_cap;
422 	struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap;
423 	struct libusb_bos_dev_capability_descriptor **dev_capability;
424 }	libusb_bos_descriptor __aligned(sizeof(void *));
425 
426 typedef struct libusb_usb_2_0_extension_descriptor {
427 	uint8_t bLength;
428 	uint8_t bDescriptorType;
429 	uint8_t bDevCapabilityType;
430 	uint32_t bmAttributes;
431 }	libusb_usb_2_0_extension_descriptor __aligned(sizeof(void *));
432 
433 typedef struct libusb_container_id_descriptor {
434 	uint8_t bLength;
435 	uint8_t bDescriptorType;
436 	uint8_t bDevCapabilityType;
437 	uint8_t	bReserved;
438 	uint8_t ContainerID[16];
439 }	libusb_container_id_descriptor __aligned(sizeof(void *));
440 
441 typedef struct libusb_control_setup {
442 	uint8_t	bmRequestType;
443 	uint8_t	bRequest;
444 	uint16_t wValue;
445 	uint16_t wIndex;
446 	uint16_t wLength;
447 }	libusb_control_setup;
448 
449 #define	LIBUSB_CONTROL_SETUP_SIZE	8	/* bytes */
450 
451 typedef struct libusb_iso_packet_descriptor {
452 	uint32_t length;
453 	uint32_t actual_length;
454 	enum libusb_transfer_status status;
455 }	libusb_iso_packet_descriptor __aligned(sizeof(void *));
456 
457 typedef void (*libusb_transfer_cb_fn) (struct libusb_transfer *transfer);
458 
459 typedef struct libusb_transfer {
460 	libusb_device_handle *dev_handle;
461 	uint8_t	flags;
462 	uint8_t endpoint;
463 	uint8_t type;
464 	uint32_t timeout;
465 	enum libusb_transfer_status status;
466 	int	length;
467 	int	actual_length;
468 	libusb_transfer_cb_fn callback;
469 	void   *user_data;
470 	uint8_t *buffer;
471 	int	num_iso_packets;
472 	struct libusb_iso_packet_descriptor iso_packet_desc[0];
473 }	libusb_transfer __aligned(sizeof(void *));
474 
475 /* Library initialisation */
476 
477 void	libusb_set_debug(libusb_context * ctx, int level);
478 const struct libusb_version *libusb_get_version(void);
479 const char *libusb_strerror(int code);
480 const char *libusb_error_name(int code);
481 int	libusb_init(libusb_context ** context);
482 int	libusb_init_context(libusb_context **, const struct libusb_init_option [], int num_options);
483 void	libusb_exit(struct libusb_context *ctx);
484 int	libusb_has_capability(uint32_t capability);
485 
486 /* Device handling and enumeration */
487 
488 ssize_t libusb_get_device_list(libusb_context * ctx, libusb_device *** list);
489 void	libusb_free_device_list(libusb_device ** list, int unref_devices);
490 uint8_t	libusb_get_bus_number(libusb_device * dev);
491 uint8_t	libusb_get_port_number(libusb_device * dev);
492 int	libusb_get_port_numbers(libusb_device *dev, uint8_t *buf, uint8_t bufsize);
493 int	libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t *buf, uint8_t bufsize);
494 uint8_t	libusb_get_device_address(libusb_device * dev);
495 enum libusb_speed libusb_get_device_speed(libusb_device * dev);
496 int	libusb_clear_halt(libusb_device_handle *devh, uint8_t endpoint);
497 int	libusb_get_max_packet_size(libusb_device * dev, uint8_t endpoint);
498 int	libusb_get_max_iso_packet_size(libusb_device * dev, uint8_t endpoint);
499 libusb_device *libusb_ref_device(libusb_device * dev);
500 void	libusb_unref_device(libusb_device * dev);
501 int	libusb_open(libusb_device * dev, libusb_device_handle ** devh);
502 libusb_device_handle *libusb_open_device_with_vid_pid(libusb_context * ctx, uint16_t vendor_id, uint16_t product_id);
503 void	libusb_close(libusb_device_handle * devh);
504 libusb_device *libusb_get_device(libusb_device_handle * devh);
505 int	libusb_get_configuration(libusb_device_handle * devh, int *config);
506 int	libusb_set_configuration(libusb_device_handle * devh, int configuration);
507 int	libusb_claim_interface(libusb_device_handle * devh, int interface_number);
508 int	libusb_release_interface(libusb_device_handle * devh, int interface_number);
509 int	libusb_reset_device(libusb_device_handle * devh);
510 int	libusb_check_connected(libusb_device_handle * devh);
511 int 	libusb_kernel_driver_active(libusb_device_handle * devh, int interface);
512 int	libusb_get_driver_np(libusb_device_handle * devh, int interface, char *name, int namelen);
513 int	libusb_get_driver(libusb_device_handle * devh, int interface, char *name, int namelen);
514 int 	libusb_detach_kernel_driver_np(libusb_device_handle * devh, int interface);
515 int 	libusb_detach_kernel_driver(libusb_device_handle * devh, int interface);
516 int 	libusb_attach_kernel_driver(libusb_device_handle * devh, int interface);
517 int	libusb_set_auto_detach_kernel_driver(libusb_device_handle *dev, int enable);
518 int	libusb_set_interface_alt_setting(libusb_device_handle * devh, int interface_number, int alternate_setting);
519 
520 /* USB Descriptors */
521 
522 int	libusb_get_device_descriptor(libusb_device * dev, struct libusb_device_descriptor *desc);
523 int	libusb_get_active_config_descriptor(libusb_device * dev, struct libusb_config_descriptor **config);
524 int	libusb_get_config_descriptor(libusb_device * dev, uint8_t config_index, struct libusb_config_descriptor **config);
525 int	libusb_get_config_descriptor_by_value(libusb_device * dev, uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
526 void	libusb_free_config_descriptor(struct libusb_config_descriptor *config);
527 int	libusb_get_ss_endpoint_companion_descriptor(struct libusb_context *ctx, const struct libusb_endpoint_descriptor *endpoint, struct libusb_ss_endpoint_companion_descriptor **ep_comp);
528 void	libusb_free_ss_endpoint_companion_descriptor(struct libusb_ss_endpoint_companion_descriptor *ep_comp);
529 int	libusb_get_string_descriptor(libusb_device_handle * devh, uint8_t desc_index, uint16_t langid, unsigned char *data, int length);
530 int	libusb_get_string_descriptor_ascii(libusb_device_handle * devh, uint8_t desc_index, uint8_t *data, int length);
531 int	libusb_get_descriptor(libusb_device_handle * devh, uint8_t desc_type, uint8_t desc_index, uint8_t *data, int length);
532 int	libusb_parse_ss_endpoint_comp(const void *buf, int len, struct libusb_ss_endpoint_companion_descriptor **ep_comp);
533 void	libusb_free_ss_endpoint_comp(struct libusb_ss_endpoint_companion_descriptor *ep_comp);
534 int	libusb_parse_bos_descriptor(const void *buf, int len, struct libusb_bos_descriptor **bos);
535 void	libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos);
536 int	libusb_get_bos_descriptor(libusb_device_handle *handle, struct libusb_bos_descriptor **bos);
537 int	libusb_get_usb_2_0_extension_descriptor(struct libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension);
538 void	libusb_free_usb_2_0_extension_descriptor(struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension);
539 int	libusb_get_ss_usb_device_capability_descriptor(struct libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_capability);
540 void	libusb_free_ss_usb_device_capability_descriptor(struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_capability);
541 int	libusb_get_container_id_descriptor(struct libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_container_id_descriptor **container_id);
542 void	libusb_free_container_id_descriptor(struct libusb_container_id_descriptor *container_id);
543 
544 /* Asynchronous device I/O */
545 
546 struct libusb_transfer *libusb_alloc_transfer(int iso_packets);
547 void	libusb_free_transfer(struct libusb_transfer *transfer);
548 int	libusb_submit_transfer(struct libusb_transfer *transfer);
549 int	libusb_cancel_transfer(struct libusb_transfer *transfer);
550 uint8_t *libusb_get_iso_packet_buffer(struct libusb_transfer *transfer, uint32_t index);
551 uint8_t *libusb_get_iso_packet_buffer_simple(struct libusb_transfer *transfer, uint32_t index);
552 void	libusb_set_iso_packet_lengths(struct libusb_transfer *transfer, uint32_t length);
553 uint8_t *libusb_control_transfer_get_data(struct libusb_transfer *transfer);
554 struct libusb_control_setup *libusb_control_transfer_get_setup(struct libusb_transfer *transfer);
555 void	libusb_fill_control_setup(uint8_t *buf, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength);
556 void	libusb_fill_control_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t *buf, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout);
557 void	libusb_fill_bulk_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf, int length, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout);
558 void	libusb_fill_interrupt_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf, int length, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout);
559 void	libusb_fill_iso_transfer(struct libusb_transfer *transfer, libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf, int length, int npacket, libusb_transfer_cb_fn callback, void *user_data, uint32_t timeout);
560 
561 /* Polling and timing */
562 
563 int	libusb_try_lock_events(libusb_context * ctx);
564 void	libusb_lock_events(libusb_context * ctx);
565 void	libusb_unlock_events(libusb_context * ctx);
566 int	libusb_event_handling_ok(libusb_context * ctx);
567 int	libusb_event_handler_active(libusb_context * ctx);
568 void	libusb_interrupt_event_handler(libusb_context *ctx);
569 void	libusb_lock_event_waiters(libusb_context * ctx);
570 void	libusb_unlock_event_waiters(libusb_context * ctx);
571 int	libusb_wait_for_event(libusb_context * ctx, struct timeval *tv);
572 int	libusb_handle_events_timeout_completed(libusb_context * ctx, struct timeval *tv, int *completed);
573 int	libusb_handle_events_completed(libusb_context * ctx, int *completed);
574 int	libusb_handle_events_timeout(libusb_context * ctx, struct timeval *tv);
575 int	libusb_handle_events(libusb_context * ctx);
576 int	libusb_handle_events_locked(libusb_context * ctx, struct timeval *tv);
577 int	libusb_get_next_timeout(libusb_context * ctx, struct timeval *tv);
578 void	libusb_set_pollfd_notifiers(libusb_context * ctx, libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, void *user_data);
579 const struct libusb_pollfd **libusb_get_pollfds(libusb_context * ctx);
580 
581 /* Synchronous device I/O */
582 
583 int	libusb_control_transfer(libusb_device_handle * devh, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t *data, uint16_t wLength, uint32_t timeout);
584 int	libusb_bulk_transfer(libusb_device_handle * devh, uint8_t endpoint, uint8_t *data, int length, int *transferred, uint32_t timeout);
585 int	libusb_interrupt_transfer(libusb_device_handle * devh, uint8_t endpoint, uint8_t *data, int length, int *transferred, uint32_t timeout);
586 
587 /* Byte-order */
588 
589 uint16_t libusb_cpu_to_le16(uint16_t x);
590 uint16_t libusb_le16_to_cpu(uint16_t x);
591 
592 /* Hotplug support */
593 
594 typedef int (*libusb_hotplug_callback_fn)(libusb_context *ctx,
595     libusb_device *device, libusb_hotplug_event event, void *user_data);
596 
597 int	libusb_hotplug_register_callback(libusb_context *ctx, libusb_hotplug_event events, libusb_hotplug_flag flags, int vendor_id, int product_id, int dev_class, libusb_hotplug_callback_fn cb_fn, void *user_data, libusb_hotplug_callback_handle *handle);
598 void	libusb_hotplug_deregister_callback(libusb_context *ctx, libusb_hotplug_callback_handle handle);
599 
600 /* Streams support */
601 
602 int	libusb_alloc_streams(libusb_device_handle *dev, uint32_t num_streams, unsigned char *endpoints, int num_endpoints);
603 int	libusb_free_streams(libusb_device_handle *dev, unsigned char *endpoints, int num_endpoints);
604 void	libusb_transfer_set_stream_id(struct libusb_transfer *transfer, uint32_t stream_id);
605 uint32_t libusb_transfer_get_stream_id(struct libusb_transfer *transfer);
606 
607 #if 0
608 {					/* indent fix */
609 #endif
610 #ifdef __cplusplus
611 }
612 
613 #endif
614 
615 #endif					/* __LIBUSB_H__ */
616