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