xref: /freebsd/lib/libusb/libusb.3 (revision f6ac23919b16d00845b5e8b3b66662b90b7cb2e6)
14eaae44dSAndrew Thompson.\"
2a5118bdfSAndrew Thompson.\" Copyright (c) 2009 Sylvestre Gallon
34eaae44dSAndrew Thompson.\"
44eaae44dSAndrew Thompson.\" All rights reserved.
54eaae44dSAndrew Thompson.\"
64eaae44dSAndrew Thompson.\" Redistribution and use in source and binary forms, with or without
74eaae44dSAndrew Thompson.\" modification, are permitted provided that the following conditions
84eaae44dSAndrew Thompson.\" are met:
94eaae44dSAndrew Thompson.\" 1. Redistributions of source code must retain the above copyright
104eaae44dSAndrew Thompson.\"    notice, this list of conditions and the following disclaimer.
114eaae44dSAndrew Thompson.\" 2. Redistributions in binary form must reproduce the above copyright
124eaae44dSAndrew Thompson.\"    notice, this list of conditions and the following disclaimer in the
134eaae44dSAndrew Thompson.\"    documentation and/or other materials provided with the distribution.
144eaae44dSAndrew Thompson.\"
154eaae44dSAndrew Thompson.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
164eaae44dSAndrew Thompson.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
174eaae44dSAndrew Thompson.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
184eaae44dSAndrew Thompson.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
194eaae44dSAndrew Thompson.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
204eaae44dSAndrew Thompson.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
214eaae44dSAndrew Thompson.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
224eaae44dSAndrew Thompson.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
234eaae44dSAndrew Thompson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
244eaae44dSAndrew Thompson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
254eaae44dSAndrew Thompson.\" SUCH DAMAGE.
264eaae44dSAndrew Thompson.\"
274eaae44dSAndrew Thompson.\" $FreeBSD$
284eaae44dSAndrew Thompson.\"
29a5118bdfSAndrew Thompson.Dd June 22, 2009
304eaae44dSAndrew Thompson.Dt LIBUSB 3
314eaae44dSAndrew Thompson.Os
324eaae44dSAndrew Thompson.Sh NAME
334eaae44dSAndrew Thompson.Nm libusb
344eaae44dSAndrew Thompson.
354eaae44dSAndrew Thompson.Nd "USB access library"
364eaae44dSAndrew Thompson.
374eaae44dSAndrew Thompson.
384eaae44dSAndrew Thompson.Sh LIBRARY
394eaae44dSAndrew Thompson.
404eaae44dSAndrew Thompson.
414eaae44dSAndrew ThompsonUSB access library (libusb -lusb)
424eaae44dSAndrew Thompson.
434eaae44dSAndrew Thompson.
444eaae44dSAndrew Thompson.Sh SYNOPSIS
45a5118bdfSAndrew Thompson.
46a5118bdfSAndrew Thompson.
47a5118bdfSAndrew Thompson.In libusb.h
484eaae44dSAndrew Thompson.
494eaae44dSAndrew Thompson.
504eaae44dSAndrew Thompson.Sh DESCRIPTION
514eaae44dSAndrew ThompsonThe
524eaae44dSAndrew Thompson.Nm
53a5118bdfSAndrew Thompsonlibrary contains interfaces for directly managing a usb device.
54a5118bdfSAndrew ThompsonThe current implementation supports v1.0 of the libusb API.
554eaae44dSAndrew Thompson.
564eaae44dSAndrew Thompson.
57a5118bdfSAndrew Thompson.Sh LIBRARY INITIALISATION / DEINITIALISATION
584eaae44dSAndrew Thompson.
594eaae44dSAndrew Thompson.Pp
604eaae44dSAndrew Thompson.
61a5118bdfSAndrew Thompson.Ft int
62a5118bdfSAndrew Thompson.Fn libusb_init libusb_context **ctx
63a5118bdfSAndrew ThompsonThis function initialises libusb. Must be called at the beginning
64a5118bdfSAndrew Thompsonof the program. This function returns 0 on success or LIBUSB_ERROR on
65a5118bdfSAndrew Thompsonfailure.
664eaae44dSAndrew Thompson.
674eaae44dSAndrew Thompson.Pp
684eaae44dSAndrew Thompson.
69a5118bdfSAndrew Thompson.Ft void
70a5118bdfSAndrew Thompson.Fn libusb_exit "libusb_context *ctx"
71a5118bdfSAndrew ThompsonDeinitialise libusb. Must be called at the end of the application.
72a5118bdfSAndrew Thompson.
73a5118bdfSAndrew Thompson.Pp
74a5118bdfSAndrew Thompson.
75a5118bdfSAndrew Thompson.Ft void
76a5118bdfSAndrew Thompson.Fn libusb_set_debug "libusb_context *ctx" "int level"
77a5118bdfSAndrew ThompsonSet debug to the
78a5118bdfSAndrew Thompson.Fa level
79a5118bdfSAndrew Thompsonlevel.
80a5118bdfSAndrew Thompson.
81a5118bdfSAndrew Thompson.Pp
82a5118bdfSAndrew Thompson.
83a5118bdfSAndrew Thompson.Ft ssize_t
84a5118bdfSAndrew Thompson.Fn libusb_get_device_list "libusb_context *ctx" "libusb_device ***list"
85a5118bdfSAndrew ThompsonFill into
86a5118bdfSAndrew Thompson.Fa list
87a5118bdfSAndrew Thompsonthe list of usb device available. All the device created by this
88a5118bdfSAndrew Thompsonfunction must be unref and free when you are done with them. This
89a5118bdfSAndrew Thompsonfunction returns the number of devices in list or a LIBUSB_ERROR code.
90a5118bdfSAndrew Thompson.
91a5118bdfSAndrew Thompson.Pp
92a5118bdfSAndrew Thompson.
93a5118bdfSAndrew Thompson.Ft void
94a5118bdfSAndrew Thompson.Fn libusb_free_device_list "libusb_device **list" "int unref_devices"
95a5118bdfSAndrew ThompsonFree the list of devices discovered by libusb_get_device_list. If
96a5118bdfSAndrew Thompson.Fa unref_device
97a5118bdfSAndrew Thompsonis set to 1 all devices are unref one time.
98a5118bdfSAndrew Thompson.
99a5118bdfSAndrew Thompson.Pp
100a5118bdfSAndrew Thompson.
101a5118bdfSAndrew Thompson.Ft uint8_t
102a5118bdfSAndrew Thompson.Fn libusb_get_bus_number "libusb_device *dev"
103a5118bdfSAndrew ThompsonReturns the number of the bus contained by the device
104a5118bdfSAndrew Thompson.Fa dev.
105a5118bdfSAndrew Thompson.
106a5118bdfSAndrew Thompson.Pp
107a5118bdfSAndrew Thompson.
108a5118bdfSAndrew Thompson.Ft uint8_t
109a5118bdfSAndrew Thompson.Fn libusb_get_device_address "libusb_device *dev"
110a5118bdfSAndrew ThompsonReturn the device_address contained by the device
111a5118bdfSAndrew Thompson.Fa dev.
112a5118bdfSAndrew Thompson.
113a5118bdfSAndrew Thompson.Pp
114a5118bdfSAndrew Thompson.
115a5118bdfSAndrew Thompson.Ft int
116a5118bdfSAndrew Thompson.Fn libusb_get_max_packet_size "libusb_device *dev" "unsigned char endpoint"
117a5118bdfSAndrew ThompsonReturn the wMaxPacketSize value on success, LIBUSB_ERROR_NOT_FOUND if the
118a5118bdfSAndrew Thompsonendpoint does not exist and LIBUSB_ERROR_OTHERS on other failure.
119a5118bdfSAndrew Thompson.
120a5118bdfSAndrew Thompson.Pp
121a5118bdfSAndrew Thompson.
122a5118bdfSAndrew Thompson.Ft libusb_device *
123a5118bdfSAndrew Thompson.Fn libusb_ref_device "libusb_device *dev"
124a5118bdfSAndrew ThompsonIncrement the reference counter of the device
125a5118bdfSAndrew Thompson.Fa dev.
126a5118bdfSAndrew Thompson.
127a5118bdfSAndrew Thompson.Pp
128a5118bdfSAndrew Thompson.
129a5118bdfSAndrew Thompson.Ft void
130a5118bdfSAndrew Thompson.Fn libusb_unref_device "libusb_device *dev"
131a5118bdfSAndrew ThompsonDecrement the reference counter of the device
132a5118bdfSAndrew Thompson.Fa dev.
133a5118bdfSAndrew Thompson.
134a5118bdfSAndrew Thompson.Pp
135a5118bdfSAndrew Thompson.
136a5118bdfSAndrew Thompson.Ft int
137a5118bdfSAndrew Thompson.Fn libusb_open "libusb_device *dev" "libusb_device_handle **devh"
138a5118bdfSAndrew ThompsonOpen a device and obtain a device_handle. Return 0 on success,
139a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_MEM on memory allocation problem, LIBUSB_ERROR_ACCESS
140a5118bdfSAndrew Thompsonon permission problem, LIBUSB_ERROR_NO_DEVICE if the device has been
141a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on error.
142a5118bdfSAndrew Thompson.
143a5118bdfSAndrew Thompson.Pp
144a5118bdfSAndrew Thompson.
145a5118bdfSAndrew Thompson.Ft libusb_device_handle *
146a5118bdfSAndrew Thompson.Fn libusb_open_device_with_vid_pid "libusb_context *ctx" "uint16_t vid" "uint16_t pid"
147*f6ac2391SJoel DahlConvenience function to open a device with is
148a5118bdfSAndrew Thompson.Fa vid
1494eaae44dSAndrew Thompsonand
150a5118bdfSAndrew Thompson.Fa pid.
151a5118bdfSAndrew ThompsonReturn NULL on error.
1524eaae44dSAndrew Thompson.
1534eaae44dSAndrew Thompson.Pp
1544eaae44dSAndrew Thompson.
155a5118bdfSAndrew Thompson.Ft void
156a5118bdfSAndrew Thompson.Fn libusb_close "libusb_device_handle *devh"
157a5118bdfSAndrew ThompsonClose a device handle.
1584eaae44dSAndrew Thompson.
1594eaae44dSAndrew Thompson.Pp
1604eaae44dSAndrew Thompson.
161a5118bdfSAndrew Thompson.Ft libusb_device *
162a5118bdfSAndrew Thompson.Fn libusb_get_device(libusb_device_handle *devh)
163a5118bdfSAndrew ThompsonGet the device contained by devh. Return NULL on error.
1644eaae44dSAndrew Thompson.
1654eaae44dSAndrew Thompson.Pp
1664eaae44dSAndrew Thompson.
167a5118bdfSAndrew Thompson.Ft int
168a5118bdfSAndrew Thompson.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config"
169a5118bdfSAndrew ThompsonReturn the bConfiguration value of the current configuration. return 0
170a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
171a5118bdfSAndrew Thompsonand a LIBUSB_ERROR code on error.
1724eaae44dSAndrew Thompson.
1734eaae44dSAndrew Thompson.Pp
1744eaae44dSAndrew Thompson.
175a5118bdfSAndrew Thompson.Ft int
176a5118bdfSAndrew Thompson.Fn libusb_set_configuration "libusb_device_handle *devh" "int config"
177a5118bdfSAndrew ThompsonSet the active configuration
178a5118bdfSAndrew Thompson.Fa config
179a5118bdfSAndrew Thompsonfor the device contained by
180a5118bdfSAndrew Thompson.Fa devh.
181a5118bdfSAndrew ThompsonThis function return 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested
182a5118bdfSAndrew Thompsonconfiguration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently
183a5118bdfSAndrew Thompsonclaimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a
184a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
1854eaae44dSAndrew Thompson.
1864eaae44dSAndrew Thompson.Pp
1874eaae44dSAndrew Thompson.
188a5118bdfSAndrew Thompson.Ft int
189a5118bdfSAndrew Thompson.Fn libusb_claim_interface "libusb_device_handle *devh" "int interface_number"
190a5118bdfSAndrew ThompsonClaim an interface in a given libusb_handle
191a5118bdfSAndrew Thompson.Fa devh.
192a5118bdfSAndrew ThompsonThis is a non-blocking function. It return 0 success, LIBUSB_ERROR_NOT_FOUND
193a5118bdfSAndrew Thompsonif the requested interface does not exist, LIBUSB_ERROR_BUSY if a program or
194a5118bdfSAndrew Thompsondriver has claimed the interface, LIBUSB_ERROR_NO_DEVICE if the device has
195a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure.
1964eaae44dSAndrew Thompson.
1974eaae44dSAndrew Thompson.Pp
1984eaae44dSAndrew Thompson.
199a5118bdfSAndrew Thompson.Ft int
200a5118bdfSAndrew Thompson.Fn libusb_release_interface "libusb_device_handle *devh" "int interface_number"
201a5118bdfSAndrew ThompsonThis function release an interface. All the claimed interface must be released
202a5118bdfSAndrew Thompsonbefore closing a device. Returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the
203799162a6SJoel Dahlinterface was not claimed, LIBUSB_ERROR_NO_DEVICE if the device has been
204a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR on failure.
2054eaae44dSAndrew Thompson.
2064eaae44dSAndrew Thompson.Pp
2074eaae44dSAndrew Thompson.
208a5118bdfSAndrew Thompson.Ft int
209a5118bdfSAndrew Thompson.Fn libusb_set_interface_alt_setting "libusb_device_handle *dev" "int interface_number" "int alternate_setting"
210a5118bdfSAndrew ThompsonActivate an alternate setting for an interface. Returns 0 on success,
211a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if the interface was not claimed or the requested
212a5118bdfSAndrew Thompsonsetting does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been
213a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR code on failure.
2144eaae44dSAndrew Thompson.
2154eaae44dSAndrew Thompson.Pp
2164eaae44dSAndrew Thompson.
217a5118bdfSAndrew Thompson.Ft int
218a5118bdfSAndrew Thompson.Fn libusb_clear_halt "libusb_device_handle *devh" "unsigned char endpoint"
219a5118bdfSAndrew ThompsonClear an halt/stall for a endpoint. Returns 0 on success, LIBUSB_ERROR_NOT_FOUND
220a5118bdfSAndrew Thompsonif the endpoint does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been
221a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on failure.
2224eaae44dSAndrew Thompson.
2234eaae44dSAndrew Thompson.Pp
2244eaae44dSAndrew Thompson.
225a5118bdfSAndrew Thompson.Ft int
226a5118bdfSAndrew Thompson.Fn libusb_reset_device "libusb_device_handle *devh"
227a5118bdfSAndrew ThompsonPerform an USB port reset for an usb device. Returns 0 on success,
228a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if re-enumeration is required or if the device has
229a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure.
2304eaae44dSAndrew Thompson.
2314eaae44dSAndrew Thompson.Pp
2324eaae44dSAndrew Thompson.
233a5118bdfSAndrew Thompson.Ft int
234a5118bdfSAndrew Thompson.Fn libusb_kernel_driver_active "libusb_device_handle *devh" "int interface"
235a5118bdfSAndrew ThompsonDetermine if a driver is active on a interface. Returns 0 if no kernel driver
236a5118bdfSAndrew Thompsonis active, returns 1 if a kernel driver is active, returns LIBUSB_ERROR_NO_DEVICE
237a5118bdfSAndrew Thompsonif the device has been disconnected and return a LIBUSB_ERROR code on failure.
2384eaae44dSAndrew Thompson.
2394eaae44dSAndrew Thompson.Pp
2404eaae44dSAndrew Thompson.
241a5118bdfSAndrew Thompson.Ft int
242a5118bdfSAndrew Thompson.Fn libusb_detach_kernel_driver "libusb_device_handle *devh" "int interface"
243a5118bdfSAndrew ThompsonDetach a kernel driver from an interface. This is needed to claim an interface
244a5118bdfSAndrew Thompsonrequired by a kernel driver. Returns 0 on success, LIBUSB_ERROR_NOT_FOUND if
245a5118bdfSAndrew Thompsonno kernel driver was active, LIBUSB_ERROR_INVALID_PARAM if the interface does not
246a5118bdfSAndrew Thompsonexist, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a
247a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
2484eaae44dSAndrew Thompson.
2494eaae44dSAndrew Thompson.Pp
2504eaae44dSAndrew Thompson.
251a5118bdfSAndrew Thompson.Ft int
252a5118bdfSAndrew Thompson.Fn libusb_attach_kernel_driver "libusb_device_handle *devh" "int interface"
253a5118bdfSAndrew ThompsonRe-attach an interface kernel driver previously detached. Returns 0 on success,
254a5118bdfSAndrew ThompsonLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, LIBUSB_ERROR_NO_DEVICE
255a5118bdfSAndrew Thompsonif the device has been disconnect, LIBUSB_ERROR_BUSY if the driver cannot be
256a5118bdfSAndrew Thompsonattached because the interface is claimed by a program or driver and a
257a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
2584eaae44dSAndrew Thompson.
2594eaae44dSAndrew Thompson.Pp
2604eaae44dSAndrew Thompson.
261a5118bdfSAndrew Thompson.Sh USB DESCRIPTORS
2624eaae44dSAndrew Thompson.
2634eaae44dSAndrew Thompson.Pp
2644eaae44dSAndrew Thompson.
265a5118bdfSAndrew Thompson.Ft int
266a5118bdfSAndrew Thompson.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc"
267a5118bdfSAndrew ThompsonGet the USB device descriptor for the device
268a5118bdfSAndrew Thompson.Fa dev.
269a5118bdfSAndrew ThompsonThis is a non-blocking function. Returns 0 on success and a LIBUSB_ERROR code on
270a5118bdfSAndrew Thompsonfailure.
2714eaae44dSAndrew Thompson.
2724eaae44dSAndrew Thompson.Pp
273a5118bdfSAndrew Thompson.Ft int
274a5118bdfSAndrew Thompson.Fn libsub_get_active_config_descriptor "libusb_device *dev" "libusb_device_descriptor **config"
275a5118bdfSAndrew ThompsonGet the USB configuration descriptor for the active configuration. Returns 0 on
276a5118bdfSAndrew Thompsonsuccess, returns LIBUSB_ERROR_NOT_FOUND if the device is in unconfigured state
277a5118bdfSAndrew Thompsonand return another LIBUSB_ERROR code on error.
2784eaae44dSAndrew Thompson.
2794eaae44dSAndrew Thompson.Pp
280a5118bdfSAndrew Thompson.Ft int
281a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor "libusb_device *dev" "uint8_t config_index" "libusb_config_descriptor **config"
282a5118bdfSAndrew ThompsonGet USB configuration descriptor based on its index
283a5118bdfSAndrew Thompson.Fa idx.
284a5118bdfSAndrew ThompsonReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
285a5118bdfSAndrew Thompsonand returns another LIBUSB_ERROR code on error.
286545b01adSAndrew Thompson.
287545b01adSAndrew Thompson.Pp
288a5118bdfSAndrew Thompson.Ft int
289a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor_by_value "libusb_device *dev" "uint8 bConfigurationValue" "libusb_config_descriptor **config"
290a5118bdfSAndrew ThompsonGet a USB configuration descriptor with a specific bConfigurationValue. This is
291a5118bdfSAndrew Thompsona non-blocking function which does not send request through the device. Returns 0
292a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist and another
293a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
2944eaae44dSAndrew Thompson.
2954eaae44dSAndrew Thompson.Pp
296a5118bdfSAndrew Thompson.Ft void
297390065b1SAlfred Perlstein.Fn libusb_free_config_descriptor "libusb_config_descriptor *config"
298a5118bdfSAndrew ThompsonFree a configuration descriptor.
2994eaae44dSAndrew Thompson.
3004eaae44dSAndrew Thompson.Pp
301a5118bdfSAndrew Thompson.Ft int
302a5118bdfSAndrew Thompson.Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length"
303a5118bdfSAndrew ThompsonRetrieve a string descriptor in C style ascii. Returns a number of byte on success
304a5118bdfSAndrew Thompsonand a LIBUSB_ERROR code on failure.
3054eaae44dSAndrew Thompson.
3064eaae44dSAndrew Thompson.Pp
3074eaae44dSAndrew Thompson.
308a5118bdfSAndrew Thompson.Sh USB ASYNCHRONOUS I/O
3094eaae44dSAndrew Thompson.
3104eaae44dSAndrew Thompson.Pp
311a5118bdfSAndrew Thompson.Ft struct libusb_transfer *
312a5118bdfSAndrew Thompson.Fn libusb_alloc_transfer "int iso_packets"
313a5118bdfSAndrew ThompsonAllocate a transfer with
314a5118bdfSAndrew Thompson.Fa iso_packets
315a5118bdfSAndrew Thompsonnumbers of isochronous packet descriptors. Returns NULL on error.
3164eaae44dSAndrew Thompson.
3174eaae44dSAndrew Thompson.Pp
318a5118bdfSAndrew Thompson.Ft void
319a5118bdfSAndrew Thompson.Fn libusb_free_transfer "struct libusb_transfer *tr"
320a5118bdfSAndrew ThompsonFree a transfer.
3214eaae44dSAndrew Thompson.
3224eaae44dSAndrew Thompson.Pp
323a5118bdfSAndrew Thompson.Ft int
324a5118bdfSAndrew Thompson.Fn libusb_submit_transfer "struct libusb_transfer *tr"
325a5118bdfSAndrew ThompsonThis function will submit a transfer and returns immediately. Returns 0 on
326a5118bdfSAndrew Thompsonsuccess, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
327a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure.
3284eaae44dSAndrew Thompson.
3294eaae44dSAndrew Thompson.Pp
330a5118bdfSAndrew Thompson.Ft int
331a5118bdfSAndrew Thompson.Fn libusb_cancel_transfer "struct libusb_transfer *tr"
332a5118bdfSAndrew ThompsonThis function asynchronously cancel a transfer. Returns 0 on success and
333a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
3344eaae44dSAndrew Thompson.
3354eaae44dSAndrew Thompson.Pp
336a5118bdfSAndrew Thompson.Sh USB SYNCHRONOUS I/O
3374eaae44dSAndrew Thompson.
3384eaae44dSAndrew Thompson.Pp
339a5118bdfSAndrew Thompson.Ft int
340a5118bdfSAndrew Thompson.Fn libusb_control_transfer "libusb_device_handle *devh" "uint8_t bmRequestType" "uint16_t wIndex" "unsigned char *data" "uint16_t wLength" "unsigned int timeout"
341a5118bdfSAndrew ThompsonPerform a USB control transfer. Returns 0 on success, LIBUSB_ERROR_TIMEOUT
342a5118bdfSAndrew Thompsonif the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not
343a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
344a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure.
3454eaae44dSAndrew Thompson.
3464eaae44dSAndrew Thompson.Pp
347a5118bdfSAndrew Thompson.Ft int
348a5118bdfSAndrew Thompson.Fn libusb_bulk_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout"
349a5118bdfSAndrew ThompsonPerform an USB bulk transfer. Returns 0 on success, LIBUSB_ERROR_TIMEOUT
350a5118bdfSAndrew Thompsonif the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not
351a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data,
352a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
353a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure.
3544eaae44dSAndrew Thompson.
3554eaae44dSAndrew Thompson.Pp
356a5118bdfSAndrew Thompson.Ft int
357a5118bdfSAndrew Thompson.Fn libusb_interrupt_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout"
358a5118bdfSAndrew ThompsonPerform an USB Interrupt transfer. Returns 0 on success, LIBUSB_ERROR_TIMEOUT
359a5118bdfSAndrew Thompsonif the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not
360a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data,
361a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
362a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure.
3634eaae44dSAndrew Thompson.
3644eaae44dSAndrew Thompson.Pp
365a5118bdfSAndrew Thompson.Sh USB EVENTS
3664eaae44dSAndrew Thompson.
3674eaae44dSAndrew Thompson.Pp
368a5118bdfSAndrew Thompson.Ft int
369a5118bdfSAndrew Thompson.Fn libusb_try_lock_events "libusb_context *ctx"
370a5118bdfSAndrew ThompsonTry to acquire the event handling lock. Returns 0 if the lock was obtained and 1
371a5118bdfSAndrew Thompsonif not.
3724eaae44dSAndrew Thompson.
3734eaae44dSAndrew Thompson.Pp
374a5118bdfSAndrew Thompson.Ft void
375a5118bdfSAndrew Thompson.Fn libusb_lock_events "libusb_context *ctx"
376a5118bdfSAndrew ThompsonAcquire the event handling lock. This function is blocking.
3774eaae44dSAndrew Thompson.
3784eaae44dSAndrew Thompson.Pp
379a5118bdfSAndrew Thompson.Ft void
380a5118bdfSAndrew Thompson.Fn libusb_unlock_events "libusb_context *ctx"
381a5118bdfSAndrew ThompsonRelease the event handling lock. This will wake up any thread blocked
382a5118bdfSAndrew Thompsonon libusb_wait_for_event().
3834eaae44dSAndrew Thompson.
3844eaae44dSAndrew Thompson.Pp
385a5118bdfSAndrew Thompson.Ft int
386a5118bdfSAndrew Thompson.Fn libusb_event_handling_ok "libusb_context *ctx"
387a5118bdfSAndrew ThompsonDetermine if it still OK for this thread to be doing event handling. Returns 1
388a5118bdfSAndrew Thompsonif event handling can start or continue. Returns 0 if this thread must give up
389a5118bdfSAndrew Thompsonthe events lock.
3904eaae44dSAndrew Thompson.
3914eaae44dSAndrew Thompson.Pp
392a5118bdfSAndrew Thompson.Ft int
393a5118bdfSAndrew Thompson.Fn libusb_event_handler_active "libusb_context *ctx"
394a5118bdfSAndrew ThompsonDetermine if an active thread is handling events. Returns 1 if yes and 0 if there
395a5118bdfSAndrew Thompsonare no threads currently handling events.
3964eaae44dSAndrew Thompson.
3974eaae44dSAndrew Thompson.Pp
398a5118bdfSAndrew Thompson.Ft void
399a5118bdfSAndrew Thompson.Fn libusb_lock_event_waiters "libusb_context *ctx"
400a5118bdfSAndrew ThompsonAcquire the event_waiters lock. This lock is designed to be obtained under the
401a5118bdfSAndrew Thompsonsituation where you want to be aware when events are completed, but some other
402a5118bdfSAndrew Thompsonthread is event handling so calling libusb_handle_events() is not allowed.
4034eaae44dSAndrew Thompson.
404545b01adSAndrew Thompson.Pp
405a5118bdfSAndrew Thompson.Ft void
406a5118bdfSAndrew Thompson.Fn libusb_unlock_event_waiters "libusb_context *ctx"
407a5118bdfSAndrew ThompsonRelease the event_waiters lock.
4084eaae44dSAndrew Thompson.
4094eaae44dSAndrew Thompson.Pp
410a5118bdfSAndrew Thompson.Ft int
411a5118bdfSAndrew Thompson.Fn libusb_wait_for_event "libusb_context *ctx" "struct timeval *tv"
412a5118bdfSAndrew ThompsonWait for another thread to signal completion of an event. Must be called
413a5118bdfSAndrew Thompsonwith the event waiters lock held, see libusb_lock_event_waiters(). This will
414a5118bdfSAndrew Thompsonblock until the timeout expires or a transfer completes or a thread releases
415a5118bdfSAndrew Thompsonthe event handling lock through libusb_unlock_events(). Returns 0 after a
416a5118bdfSAndrew Thompsontransfer completes or another thread stops event handling, returns 1 if the
417a5118bdfSAndrew Thompsontimeout expired.
4184eaae44dSAndrew Thompson.
4194eaae44dSAndrew Thompson.Pp
420a5118bdfSAndrew Thompson.Ft int
421a5118bdfSAndrew Thompson.Fn libusb_handle_events_timeout "libusb_context *ctx" "struct timeval *tv"
422a5118bdfSAndrew ThompsonHandle any pending events by checking if timeouts have expired and by
423a5118bdfSAndrew Thompsonchecking the set of file descriptors for activity. Returns 0 on success, or a
424a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
4254eaae44dSAndrew Thompson.
4264eaae44dSAndrew Thompson.Pp
427a5118bdfSAndrew Thompson.Ft int
428a5118bdfSAndrew Thompson.Fn libusb_handle_events "libusb_context *ctx"
429a5118bdfSAndrew ThompsonHandle any pending events in blocking mode with a sensible timeout. Returns 0
430a5118bdfSAndrew Thompsonon success, returns a LIBUSB_ERROR code on failure.
4314eaae44dSAndrew Thompson.
4324eaae44dSAndrew Thompson.Pp
433a5118bdfSAndrew Thompson.Ft int
434a5118bdfSAndrew Thompson.Fn libusb_handle_events_locked "libusb_context *ctx" "struct timeval *tv"
435a5118bdfSAndrew ThompsonHandle any pending events by polling file desciptors, without checking if
436a5118bdfSAndrew Thompsonanother threads are already doing so. Must be called with the event lock held.
4374eaae44dSAndrew Thompson.
4384eaae44dSAndrew Thompson.Pp
439a5118bdfSAndrew Thompson.Ft int
440a5118bdfSAndrew Thompson.Fn libusb_get_next_timeout "libusb_context *ctx" "struct timeval *tv"
441a5118bdfSAndrew ThompsonDetermine the next internal timeout that libusb needs to handle. Returns 0
442a5118bdfSAndrew Thompsonif there are no pending timeouts, 1 if a timeout was returned, or LIBUSB_ERROR
443a5118bdfSAndrew Thompsoncode on failure.
4444eaae44dSAndrew Thompson.
4454eaae44dSAndrew Thompson.Pp
446a5118bdfSAndrew Thompson.Ft void
447a5118bdfSAndrew Thompson.Fn libusb_set_pollfd_notifiers "libusb_context *ctx" "libusb_pollfd_added_cb added_cb" "libusb_pollfd_removed_cb remove_cb" "void *user_data"
448a5118bdfSAndrew ThompsonRegister notification functions for file descriptor additions/removals.
449a5118bdfSAndrew ThompsonThese functions will be invoked for every new or removed file descriptor
450a5118bdfSAndrew Thompsonthat libusb uses as an event source.
4514eaae44dSAndrew Thompson.
4524eaae44dSAndrew Thompson.Pp
453a5118bdfSAndrew Thompson.Ft const struct libusb_pollfd **
454a5118bdfSAndrew Thompson.Fn libusb_get_pollfds "libusb_context *ctx"
455a5118bdfSAndrew ThompsonRetrive a list of file descriptors that should be polled by your main loop as
456a5118bdfSAndrew Thompsonlibusb event sources. Returns a NULL-terminated list on success or NULL on failure.
4574eaae44dSAndrew Thompson.
4584eaae44dSAndrew Thompson.Sh LIBUSB VERSION 0.1 COMPATIBILITY
459a5118bdfSAndrew Thompson.Pp
460a5118bdfSAndrew ThompsonThe library is also compliant with LibUSB version 0.1.12.
461a5118bdfSAndrew Thompson.Pp
4624eaae44dSAndrew Thompson.Fn usb_open
4634eaae44dSAndrew Thompson.Fn usb_close
4644eaae44dSAndrew Thompson.Fn usb_get_string
4654eaae44dSAndrew Thompson.Fn usb_get_string_simple
4664eaae44dSAndrew Thompson.Fn usb_get_descriptor_by_endpoint
4674eaae44dSAndrew Thompson.Fn usb_get_descriptor
4684eaae44dSAndrew Thompson.Fn usb_parse_descriptor
4694eaae44dSAndrew Thompson.Fn usb_parse_configuration
4704eaae44dSAndrew Thompson.Fn usb_destroy_configuration
4714eaae44dSAndrew Thompson.Fn usb_fetch_and_parse_descriptors
4724eaae44dSAndrew Thompson.Fn usb_bulk_write
4734eaae44dSAndrew Thompson.Fn usb_bulk_read
4744eaae44dSAndrew Thompson.Fn usb_interrupt_write
4754eaae44dSAndrew Thompson.Fn usb_interrupt_read
4764eaae44dSAndrew Thompson.Fn usb_control_msg
4774eaae44dSAndrew Thompson.Fn usb_set_configuration
4784eaae44dSAndrew Thompson.Fn usb_claim_interface
4794eaae44dSAndrew Thompson.Fn usb_release_interface
4804eaae44dSAndrew Thompson.Fn usb_set_altinterface
4814eaae44dSAndrew Thompson.Fn usb_resetep
4824eaae44dSAndrew Thompson.Fn usb_clear_halt
4834eaae44dSAndrew Thompson.Fn usb_reset
4844eaae44dSAndrew Thompson.Fn usb_strerror
4854eaae44dSAndrew Thompson.Fn usb_init
4864eaae44dSAndrew Thompson.Fn usb_set_debug
4874eaae44dSAndrew Thompson.Fn usb_find_busses
4884eaae44dSAndrew Thompson.Fn usb_find_devices
4894eaae44dSAndrew Thompson.Fn usb_device
4904eaae44dSAndrew Thompson.Fn usb_get_busses
4914eaae44dSAndrew Thompson.
4924eaae44dSAndrew Thompson.Sh SEE ALSO
493a5118bdfSAndrew Thompson.Xr libusb20 3 ,
494c54c1f7cSAndrew Thompson.Xr usb 4 ,
4954eaae44dSAndrew Thompson.Xr usbconfig 8
496a5118bdfSAndrew Thompson.Pp
497a5118bdfSAndrew Thompson.Pa http://libusb.sourceforge.net/
4984eaae44dSAndrew Thompson.
4994eaae44dSAndrew Thompson.Sh HISTORY
5004eaae44dSAndrew Thompson.
5014eaae44dSAndrew Thompson.Nm
502a5118bdfSAndrew Thompsonsupport first appeared in
503a5118bdfSAndrew Thompson.Fx 8.0 .
504