xref: /freebsd/lib/libusb/libusb.3 (revision ca96e26a7165b6267b688a4fb8293c1c22c5771e)
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.\"
29*ca96e26aSHans Petter Selasky.Dd August 16, 2011
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.
75698e791aSHans Petter Selasky.Ft const char *
76698e791aSHans Petter Selasky.Fn libusb_strerror "int code"
77698e791aSHans Petter SelaskyGet ASCII representation of the error given by the
78698e791aSHans Petter Selasky.Fa code
79698e791aSHans Petter Selaskyargument.
80698e791aSHans Petter Selasky.
81698e791aSHans Petter Selasky.
82698e791aSHans Petter Selasky.Pp
83698e791aSHans Petter Selasky.
84a5118bdfSAndrew Thompson.Ft void
85a5118bdfSAndrew Thompson.Fn libusb_set_debug "libusb_context *ctx" "int level"
86a5118bdfSAndrew ThompsonSet debug to the
87a5118bdfSAndrew Thompson.Fa level
88a5118bdfSAndrew Thompsonlevel.
89a5118bdfSAndrew Thompson.
90a5118bdfSAndrew Thompson.Pp
91a5118bdfSAndrew Thompson.
92a5118bdfSAndrew Thompson.Ft ssize_t
93a5118bdfSAndrew Thompson.Fn libusb_get_device_list "libusb_context *ctx" "libusb_device ***list"
94a5118bdfSAndrew ThompsonFill into
95a5118bdfSAndrew Thompson.Fa list
96a5118bdfSAndrew Thompsonthe list of usb device available. All the device created by this
97a5118bdfSAndrew Thompsonfunction must be unref and free when you are done with them. This
98a5118bdfSAndrew Thompsonfunction returns the number of devices in list or a LIBUSB_ERROR code.
99a5118bdfSAndrew Thompson.
100a5118bdfSAndrew Thompson.Pp
101a5118bdfSAndrew Thompson.
102a5118bdfSAndrew Thompson.Ft void
103a5118bdfSAndrew Thompson.Fn libusb_free_device_list "libusb_device **list" "int unref_devices"
104a5118bdfSAndrew ThompsonFree the list of devices discovered by libusb_get_device_list. If
105a5118bdfSAndrew Thompson.Fa unref_device
106a5118bdfSAndrew Thompsonis set to 1 all devices are unref one time.
107a5118bdfSAndrew Thompson.
108a5118bdfSAndrew Thompson.Pp
109a5118bdfSAndrew Thompson.
110a5118bdfSAndrew Thompson.Ft uint8_t
111a5118bdfSAndrew Thompson.Fn libusb_get_bus_number "libusb_device *dev"
112a5118bdfSAndrew ThompsonReturns the number of the bus contained by the device
113a5118bdfSAndrew Thompson.Fa dev.
114a5118bdfSAndrew Thompson.
115a5118bdfSAndrew Thompson.Pp
116a5118bdfSAndrew Thompson.
117a5118bdfSAndrew Thompson.Ft uint8_t
118a5118bdfSAndrew Thompson.Fn libusb_get_device_address "libusb_device *dev"
119*ca96e26aSHans Petter SelaskyReturns the device_address contained by the device
120a5118bdfSAndrew Thompson.Fa dev.
121a5118bdfSAndrew Thompson.
122a5118bdfSAndrew Thompson.Pp
123a5118bdfSAndrew Thompson.
124*ca96e26aSHans Petter Selasky.Ft enum libusb_speed
125*ca96e26aSHans Petter Selasky.Fn libusb_get_device_speed "libusb_device *dev"
126*ca96e26aSHans Petter SelaskyReturns the wire speed at which the device is connected.
127*ca96e26aSHans Petter SelaskySee the LIBUSB_SPEED_XXX enums for more information.
128*ca96e26aSHans Petter SelaskyLIBUSB_SPEED_UNKNOWN is returned in case of unknown wire speed.
129*ca96e26aSHans Petter Selasky.
130*ca96e26aSHans Petter Selasky.Pp
131*ca96e26aSHans Petter Selasky.
132a5118bdfSAndrew Thompson.Ft int
133a5118bdfSAndrew Thompson.Fn libusb_get_max_packet_size "libusb_device *dev" "unsigned char endpoint"
134*ca96e26aSHans Petter SelaskyReturns the wMaxPacketSize value on success, LIBUSB_ERROR_NOT_FOUND if the
135a5118bdfSAndrew Thompsonendpoint does not exist and LIBUSB_ERROR_OTHERS on other failure.
136a5118bdfSAndrew Thompson.
137a5118bdfSAndrew Thompson.Pp
138a5118bdfSAndrew Thompson.
139a5118bdfSAndrew Thompson.Ft libusb_device *
140a5118bdfSAndrew Thompson.Fn libusb_ref_device "libusb_device *dev"
141a5118bdfSAndrew ThompsonIncrement the reference counter of the device
142a5118bdfSAndrew Thompson.Fa dev.
143a5118bdfSAndrew Thompson.
144a5118bdfSAndrew Thompson.Pp
145a5118bdfSAndrew Thompson.
146a5118bdfSAndrew Thompson.Ft void
147a5118bdfSAndrew Thompson.Fn libusb_unref_device "libusb_device *dev"
148a5118bdfSAndrew ThompsonDecrement the reference counter of the device
149a5118bdfSAndrew Thompson.Fa dev.
150a5118bdfSAndrew Thompson.
151a5118bdfSAndrew Thompson.Pp
152a5118bdfSAndrew Thompson.
153a5118bdfSAndrew Thompson.Ft int
154a5118bdfSAndrew Thompson.Fn libusb_open "libusb_device *dev" "libusb_device_handle **devh"
155*ca96e26aSHans Petter SelaskyOpen a device and obtain a device_handle. Returns 0 on success,
156a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_MEM on memory allocation problem, LIBUSB_ERROR_ACCESS
157a5118bdfSAndrew Thompsonon permission problem, LIBUSB_ERROR_NO_DEVICE if the device has been
158a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on error.
159a5118bdfSAndrew Thompson.
160a5118bdfSAndrew Thompson.Pp
161a5118bdfSAndrew Thompson.
162a5118bdfSAndrew Thompson.Ft libusb_device_handle *
163a5118bdfSAndrew Thompson.Fn libusb_open_device_with_vid_pid "libusb_context *ctx" "uint16_t vid" "uint16_t pid"
164f6ac2391SJoel DahlConvenience function to open a device with is
165a5118bdfSAndrew Thompson.Fa vid
1664eaae44dSAndrew Thompsonand
167a5118bdfSAndrew Thompson.Fa pid.
168*ca96e26aSHans Petter SelaskyReturns NULL on error.
1694eaae44dSAndrew Thompson.
1704eaae44dSAndrew Thompson.Pp
1714eaae44dSAndrew Thompson.
172a5118bdfSAndrew Thompson.Ft void
173a5118bdfSAndrew Thompson.Fn libusb_close "libusb_device_handle *devh"
174a5118bdfSAndrew ThompsonClose a device handle.
1754eaae44dSAndrew Thompson.
1764eaae44dSAndrew Thompson.Pp
1774eaae44dSAndrew Thompson.
178a5118bdfSAndrew Thompson.Ft libusb_device *
179*ca96e26aSHans Petter Selasky.Fn libusb_get_device "libusb_device_handle *devh"
180*ca96e26aSHans Petter SelaskyGet the device contained by devh.
181*ca96e26aSHans Petter SelaskyReturns NULL on error.
1824eaae44dSAndrew Thompson.
1834eaae44dSAndrew Thompson.Pp
1844eaae44dSAndrew Thompson.
185a5118bdfSAndrew Thompson.Ft int
186a5118bdfSAndrew Thompson.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config"
187*ca96e26aSHans Petter SelaskyReturns the bConfiguration value of the current configuration. Returns 0
188a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
189a5118bdfSAndrew Thompsonand a LIBUSB_ERROR code on error.
1904eaae44dSAndrew Thompson.
1914eaae44dSAndrew Thompson.Pp
1924eaae44dSAndrew Thompson.
193a5118bdfSAndrew Thompson.Ft int
194a5118bdfSAndrew Thompson.Fn libusb_set_configuration "libusb_device_handle *devh" "int config"
195a5118bdfSAndrew ThompsonSet the active configuration
196a5118bdfSAndrew Thompson.Fa config
197a5118bdfSAndrew Thompsonfor the device contained by
198a5118bdfSAndrew Thompson.Fa devh.
199*ca96e26aSHans Petter SelaskyThis function returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested
200a5118bdfSAndrew Thompsonconfiguration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently
201a5118bdfSAndrew Thompsonclaimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a
202a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
2034eaae44dSAndrew Thompson.
2044eaae44dSAndrew Thompson.Pp
2054eaae44dSAndrew Thompson.
206a5118bdfSAndrew Thompson.Ft int
207a5118bdfSAndrew Thompson.Fn libusb_claim_interface "libusb_device_handle *devh" "int interface_number"
208a5118bdfSAndrew ThompsonClaim an interface in a given libusb_handle
209a5118bdfSAndrew Thompson.Fa devh.
210*ca96e26aSHans Petter SelaskyThis is a non-blocking function. It returns 0 success, LIBUSB_ERROR_NOT_FOUND
211a5118bdfSAndrew Thompsonif the requested interface does not exist, LIBUSB_ERROR_BUSY if a program or
212a5118bdfSAndrew Thompsondriver has claimed the interface, LIBUSB_ERROR_NO_DEVICE if the device has
213a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure.
2144eaae44dSAndrew Thompson.
2154eaae44dSAndrew Thompson.Pp
2164eaae44dSAndrew Thompson.
217a5118bdfSAndrew Thompson.Ft int
218a5118bdfSAndrew Thompson.Fn libusb_release_interface "libusb_device_handle *devh" "int interface_number"
219a5118bdfSAndrew ThompsonThis function release an interface. All the claimed interface must be released
220a5118bdfSAndrew Thompsonbefore closing a device. Returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the
221799162a6SJoel Dahlinterface was not claimed, LIBUSB_ERROR_NO_DEVICE if the device has been
222a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR on failure.
2234eaae44dSAndrew Thompson.
2244eaae44dSAndrew Thompson.Pp
2254eaae44dSAndrew Thompson.
226a5118bdfSAndrew Thompson.Ft int
227a5118bdfSAndrew Thompson.Fn libusb_set_interface_alt_setting "libusb_device_handle *dev" "int interface_number" "int alternate_setting"
228a5118bdfSAndrew ThompsonActivate an alternate setting for an interface. Returns 0 on success,
229a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if the interface was not claimed or the requested
230a5118bdfSAndrew Thompsonsetting does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been
231a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR code on failure.
2324eaae44dSAndrew Thompson.
2334eaae44dSAndrew Thompson.Pp
2344eaae44dSAndrew Thompson.
235a5118bdfSAndrew Thompson.Ft int
236a5118bdfSAndrew Thompson.Fn libusb_clear_halt "libusb_device_handle *devh" "unsigned char endpoint"
237a5118bdfSAndrew ThompsonClear an halt/stall for a endpoint. Returns 0 on success, LIBUSB_ERROR_NOT_FOUND
238a5118bdfSAndrew Thompsonif the endpoint does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been
239a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on failure.
2404eaae44dSAndrew Thompson.
2414eaae44dSAndrew Thompson.Pp
2424eaae44dSAndrew Thompson.
243a5118bdfSAndrew Thompson.Ft int
244a5118bdfSAndrew Thompson.Fn libusb_reset_device "libusb_device_handle *devh"
245a5118bdfSAndrew ThompsonPerform an USB port reset for an usb device. Returns 0 on success,
246a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if re-enumeration is required or if the device has
247a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure.
2484eaae44dSAndrew Thompson.
2494eaae44dSAndrew Thompson.Pp
2504eaae44dSAndrew Thompson.
251a5118bdfSAndrew Thompson.Ft int
252f1b5fa6eSHans Petter Selasky.Fn libusb_check_connected "libusb_device_handle *devh"
253f1b5fa6eSHans Petter SelaskyTest if USB device is still connected. Returns 0 on success,
254f1b5fa6eSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if has been disconnected and a LIBUSB_ERROR
255f1b5fa6eSHans Petter Selaskycode on failure.
256f1b5fa6eSHans Petter Selasky.
257f1b5fa6eSHans Petter Selasky.Pp
258f1b5fa6eSHans Petter Selasky.
259f1b5fa6eSHans Petter Selasky.Ft int
260a5118bdfSAndrew Thompson.Fn libusb_kernel_driver_active "libusb_device_handle *devh" "int interface"
261a5118bdfSAndrew ThompsonDetermine if a driver is active on a interface. Returns 0 if no kernel driver
262a5118bdfSAndrew Thompsonis active, returns 1 if a kernel driver is active, returns LIBUSB_ERROR_NO_DEVICE
263*ca96e26aSHans Petter Selaskyif the device has been disconnected and returns a LIBUSB_ERROR code on failure.
2644eaae44dSAndrew Thompson.
2654eaae44dSAndrew Thompson.Pp
2664eaae44dSAndrew Thompson.
267a5118bdfSAndrew Thompson.Ft int
268698e791aSHans Petter Selasky.Fn libusb_get_driver "libusb_device_handle *devh" "int interface" "char *name" "int namelen"
269698e791aSHans Petter Selaskyor
270698e791aSHans Petter Selasky.Ft int
271698e791aSHans Petter Selasky.Fn libusb_get_driver_np "libusb_device_handle *devh" "int interface" "char *name" "int namelen"
272698e791aSHans Petter SelaskyGets the name of the driver attached to the given
273698e791aSHans Petter Selasky.Fa device
274698e791aSHans Petter Selaskyand
275698e791aSHans Petter Selasky.Fa interface
276698e791aSHans Petter Selaskyinto the buffer given by
277698e791aSHans Petter Selasky.Fa name
278698e791aSHans Petter Selaskyand
279698e791aSHans Petter Selasky.Fa namelen .
280698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver is attached
281698e791aSHans Petter Selaskyto the given interface and LIBUSB_ERROR_INVALID_PARAM if the interface does
282698e791aSHans Petter Selaskynot exist.
283698e791aSHans Petter SelaskyThis function is non-portable.
284698e791aSHans Petter SelaskyThe buffer pointed to by
285698e791aSHans Petter Selasky.Fa name
286698e791aSHans Petter Selaskyis only zero terminated on success.
287698e791aSHans Petter Selasky.
288698e791aSHans Petter Selasky.Pp
289698e791aSHans Petter Selasky.
290698e791aSHans Petter Selasky.Ft int
291a5118bdfSAndrew Thompson.Fn libusb_detach_kernel_driver "libusb_device_handle *devh" "int interface"
292698e791aSHans Petter Selaskyor
293698e791aSHans Petter Selasky.Ft int
294698e791aSHans Petter Selasky.Fn libusb_detach_kernel_driver_np "libusb_device_handle *devh" "int interface"
295698e791aSHans Petter SelaskyDetach a kernel driver from an interface.
296698e791aSHans Petter SelaskyThis is needed to claim an interface required by a kernel driver.
297698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver was active,
298698e791aSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a LIBUSB_ERROR code on failure. This function is non-portable.
2994eaae44dSAndrew Thompson.
3004eaae44dSAndrew Thompson.Pp
3014eaae44dSAndrew Thompson.
302a5118bdfSAndrew Thompson.Ft int
303a5118bdfSAndrew Thompson.Fn libusb_attach_kernel_driver "libusb_device_handle *devh" "int interface"
304a5118bdfSAndrew ThompsonRe-attach an interface kernel driver previously detached. Returns 0 on success,
305a5118bdfSAndrew ThompsonLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, LIBUSB_ERROR_NO_DEVICE
306a5118bdfSAndrew Thompsonif the device has been disconnect, LIBUSB_ERROR_BUSY if the driver cannot be
307a5118bdfSAndrew Thompsonattached because the interface is claimed by a program or driver and a
308a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
3094eaae44dSAndrew Thompson.
3104eaae44dSAndrew Thompson.Pp
3114eaae44dSAndrew Thompson.
312a5118bdfSAndrew Thompson.Sh USB DESCRIPTORS
3134eaae44dSAndrew Thompson.
3144eaae44dSAndrew Thompson.Pp
3154eaae44dSAndrew Thompson.
316a5118bdfSAndrew Thompson.Ft int
317a5118bdfSAndrew Thompson.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc"
318a5118bdfSAndrew ThompsonGet the USB device descriptor for the device
319a5118bdfSAndrew Thompson.Fa dev.
320a5118bdfSAndrew ThompsonThis is a non-blocking function. Returns 0 on success and a LIBUSB_ERROR code on
321a5118bdfSAndrew Thompsonfailure.
3224eaae44dSAndrew Thompson.
3234eaae44dSAndrew Thompson.Pp
324a5118bdfSAndrew Thompson.Ft int
325698e791aSHans Petter Selasky.Fn libsub_get_active_config_descriptor "libusb_device *dev" "struct libusb_config_descriptor **config"
326a5118bdfSAndrew ThompsonGet the USB configuration descriptor for the active configuration. Returns 0 on
327a5118bdfSAndrew Thompsonsuccess, returns LIBUSB_ERROR_NOT_FOUND if the device is in unconfigured state
328*ca96e26aSHans Petter Selaskyand returns another LIBUSB_ERROR code on error.
3294eaae44dSAndrew Thompson.
3304eaae44dSAndrew Thompson.Pp
331a5118bdfSAndrew Thompson.Ft int
332a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor "libusb_device *dev" "uint8_t config_index" "libusb_config_descriptor **config"
333a5118bdfSAndrew ThompsonGet USB configuration descriptor based on its index
334a5118bdfSAndrew Thompson.Fa idx.
335a5118bdfSAndrew ThompsonReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
336a5118bdfSAndrew Thompsonand returns another LIBUSB_ERROR code on error.
337545b01adSAndrew Thompson.
338545b01adSAndrew Thompson.Pp
339a5118bdfSAndrew Thompson.Ft int
340a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor_by_value "libusb_device *dev" "uint8 bConfigurationValue" "libusb_config_descriptor **config"
341a5118bdfSAndrew ThompsonGet a USB configuration descriptor with a specific bConfigurationValue. This is
342a5118bdfSAndrew Thompsona non-blocking function which does not send request through the device. Returns 0
343a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist and another
344a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
3454eaae44dSAndrew Thompson.
3464eaae44dSAndrew Thompson.Pp
347a5118bdfSAndrew Thompson.Ft void
348390065b1SAlfred Perlstein.Fn libusb_free_config_descriptor "libusb_config_descriptor *config"
349a5118bdfSAndrew ThompsonFree a configuration descriptor.
3504eaae44dSAndrew Thompson.
3514eaae44dSAndrew Thompson.Pp
352a5118bdfSAndrew Thompson.Ft int
353a5118bdfSAndrew Thompson.Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length"
354*ca96e26aSHans Petter SelaskyRetrieve a string descriptor in C style ascii.
355*ca96e26aSHans Petter SelaskyReturns a positive number of bytes in the resulting ASCII string on success and a LIBUSB_ERROR code on failure.
3564eaae44dSAndrew Thompson.
3574eaae44dSAndrew Thompson.Pp
3584eaae44dSAndrew Thompson.
359a5118bdfSAndrew Thompson.Sh USB ASYNCHRONOUS I/O
3604eaae44dSAndrew Thompson.
3614eaae44dSAndrew Thompson.Pp
362a5118bdfSAndrew Thompson.Ft struct libusb_transfer *
363a5118bdfSAndrew Thompson.Fn libusb_alloc_transfer "int iso_packets"
364a5118bdfSAndrew ThompsonAllocate a transfer with
365a5118bdfSAndrew Thompson.Fa iso_packets
366*ca96e26aSHans Petter Selaskynumbers of isochronous packet descriptors.
367*ca96e26aSHans Petter SelaskyReturns NULL on error.
3684eaae44dSAndrew Thompson.
3694eaae44dSAndrew Thompson.Pp
370a5118bdfSAndrew Thompson.Ft void
371a5118bdfSAndrew Thompson.Fn libusb_free_transfer "struct libusb_transfer *tr"
372a5118bdfSAndrew ThompsonFree a transfer.
3734eaae44dSAndrew Thompson.
3744eaae44dSAndrew Thompson.Pp
375a5118bdfSAndrew Thompson.Ft int
376a5118bdfSAndrew Thompson.Fn libusb_submit_transfer "struct libusb_transfer *tr"
377*ca96e26aSHans Petter SelaskyThis function will submit a transfer and returns immediately.
378*ca96e26aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
379a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure.
3804eaae44dSAndrew Thompson.
3814eaae44dSAndrew Thompson.Pp
382a5118bdfSAndrew Thompson.Ft int
383a5118bdfSAndrew Thompson.Fn libusb_cancel_transfer "struct libusb_transfer *tr"
384*ca96e26aSHans Petter SelaskyThis function asynchronously cancel a transfer.
385*ca96e26aSHans Petter SelaskyReturns 0 on success and LIBUSB_ERROR code on failure.
3864eaae44dSAndrew Thompson.
3874eaae44dSAndrew Thompson.Pp
388a5118bdfSAndrew Thompson.Sh USB SYNCHRONOUS I/O
3894eaae44dSAndrew Thompson.
3904eaae44dSAndrew Thompson.Pp
391a5118bdfSAndrew Thompson.Ft int
392698e791aSHans Petter Selasky.Fn libusb_control_transfer "libusb_device_handle *devh" "uint8_t bmRequestType" "uint8_t bRequest" "uint16_t wValue" "uint16_t wIndex" "unsigned char *data" "uint16_t wLength" "unsigned int timeout"
393*ca96e26aSHans Petter SelaskyPerform a USB control transfer.
394*ca96e26aSHans Petter SelaskyReturns the actual number of bytes
395c865d740SHans Petter Selaskytransferred on success in the range from and including zero until and
396c865d740SHans Petter Selaskyincluding
397892f4806SHans Petter Selasky.Fa wLength .
398c865d740SHans Petter SelaskyOn error a libusb error code is returned, for example
399c865d740SHans Petter SelaskyLIBUSB_ERROR_TIMEOUT if the transfer timeout, LIBUSB_ERROR_PIPE if the
400c865d740SHans Petter Selaskycontrol request was not supported, LIBUSB_ERROR_NO_DEVICE if the
401c865d740SHans Petter Selaskydevice has been disconnected or another LIBUSB_ERROR code on other failures.
402c865d740SHans Petter SelaskyThe libusb error codes are always negative.
4034eaae44dSAndrew Thompson.
4044eaae44dSAndrew Thompson.Pp
405a5118bdfSAndrew Thompson.Ft int
406a5118bdfSAndrew Thompson.Fn libusb_bulk_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout"
407892f4806SHans Petter SelaskyPerform an USB bulk transfer.
408892f4806SHans Petter SelaskyA timeout value of zero means no timeout.
409892f4806SHans Petter SelaskyThe timeout value is given in milliseconds.
410892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT
411a5118bdfSAndrew Thompsonif the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not
412a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data,
413a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
414a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure.
4154eaae44dSAndrew Thompson.
4164eaae44dSAndrew Thompson.Pp
417a5118bdfSAndrew Thompson.Ft int
418a5118bdfSAndrew Thompson.Fn libusb_interrupt_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout"
419892f4806SHans Petter SelaskyPerform an USB Interrupt transfer.
420892f4806SHans Petter SelaskyA timeout value of zero means no timeout.
421892f4806SHans Petter SelaskyThe timeout value is given in milliseconds.
422892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT
423a5118bdfSAndrew Thompsonif the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not
424a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data,
425a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
426a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure.
4274eaae44dSAndrew Thompson.
4284eaae44dSAndrew Thompson.Pp
429a5118bdfSAndrew Thompson.Sh USB EVENTS
4304eaae44dSAndrew Thompson.
4314eaae44dSAndrew Thompson.Pp
432a5118bdfSAndrew Thompson.Ft int
433a5118bdfSAndrew Thompson.Fn libusb_try_lock_events "libusb_context *ctx"
434*ca96e26aSHans Petter SelaskyTry to acquire the event handling lock.
435*ca96e26aSHans Petter SelaskyReturns 0 if the lock was obtained and 1 if not.
4364eaae44dSAndrew Thompson.
4374eaae44dSAndrew Thompson.Pp
438a5118bdfSAndrew Thompson.Ft void
439a5118bdfSAndrew Thompson.Fn libusb_lock_events "libusb_context *ctx"
440a5118bdfSAndrew ThompsonAcquire the event handling lock. This function is blocking.
4414eaae44dSAndrew Thompson.
4424eaae44dSAndrew Thompson.Pp
443a5118bdfSAndrew Thompson.Ft void
444a5118bdfSAndrew Thompson.Fn libusb_unlock_events "libusb_context *ctx"
445a5118bdfSAndrew ThompsonRelease the event handling lock. This will wake up any thread blocked
446a5118bdfSAndrew Thompsonon libusb_wait_for_event().
4474eaae44dSAndrew Thompson.
4484eaae44dSAndrew Thompson.Pp
449a5118bdfSAndrew Thompson.Ft int
450a5118bdfSAndrew Thompson.Fn libusb_event_handling_ok "libusb_context *ctx"
451a5118bdfSAndrew ThompsonDetermine if it still OK for this thread to be doing event handling. Returns 1
452a5118bdfSAndrew Thompsonif event handling can start or continue. Returns 0 if this thread must give up
453a5118bdfSAndrew Thompsonthe events lock.
4544eaae44dSAndrew Thompson.
4554eaae44dSAndrew Thompson.Pp
456a5118bdfSAndrew Thompson.Ft int
457a5118bdfSAndrew Thompson.Fn libusb_event_handler_active "libusb_context *ctx"
458a5118bdfSAndrew ThompsonDetermine if an active thread is handling events. Returns 1 if yes and 0 if there
459a5118bdfSAndrew Thompsonare no threads currently handling events.
4604eaae44dSAndrew Thompson.
4614eaae44dSAndrew Thompson.Pp
462a5118bdfSAndrew Thompson.Ft void
463a5118bdfSAndrew Thompson.Fn libusb_lock_event_waiters "libusb_context *ctx"
464a5118bdfSAndrew ThompsonAcquire the event_waiters lock. This lock is designed to be obtained under the
465a5118bdfSAndrew Thompsonsituation where you want to be aware when events are completed, but some other
466a5118bdfSAndrew Thompsonthread is event handling so calling libusb_handle_events() is not allowed.
4674eaae44dSAndrew Thompson.
468545b01adSAndrew Thompson.Pp
469a5118bdfSAndrew Thompson.Ft void
470a5118bdfSAndrew Thompson.Fn libusb_unlock_event_waiters "libusb_context *ctx"
471a5118bdfSAndrew ThompsonRelease the event_waiters lock.
4724eaae44dSAndrew Thompson.
4734eaae44dSAndrew Thompson.Pp
474a5118bdfSAndrew Thompson.Ft int
475a5118bdfSAndrew Thompson.Fn libusb_wait_for_event "libusb_context *ctx" "struct timeval *tv"
476a5118bdfSAndrew ThompsonWait for another thread to signal completion of an event. Must be called
477a5118bdfSAndrew Thompsonwith the event waiters lock held, see libusb_lock_event_waiters(). This will
478a5118bdfSAndrew Thompsonblock until the timeout expires or a transfer completes or a thread releases
479a5118bdfSAndrew Thompsonthe event handling lock through libusb_unlock_events(). Returns 0 after a
480a5118bdfSAndrew Thompsontransfer completes or another thread stops event handling, returns 1 if the
481a5118bdfSAndrew Thompsontimeout expired.
4824eaae44dSAndrew Thompson.
4834eaae44dSAndrew Thompson.Pp
484a5118bdfSAndrew Thompson.Ft int
485a5118bdfSAndrew Thompson.Fn libusb_handle_events_timeout "libusb_context *ctx" "struct timeval *tv"
486a5118bdfSAndrew ThompsonHandle any pending events by checking if timeouts have expired and by
487a5118bdfSAndrew Thompsonchecking the set of file descriptors for activity. Returns 0 on success, or a
488a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
4894eaae44dSAndrew Thompson.
4904eaae44dSAndrew Thompson.Pp
491a5118bdfSAndrew Thompson.Ft int
492a5118bdfSAndrew Thompson.Fn libusb_handle_events "libusb_context *ctx"
493a5118bdfSAndrew ThompsonHandle any pending events in blocking mode with a sensible timeout. Returns 0
494a5118bdfSAndrew Thompsonon success, returns a LIBUSB_ERROR code on failure.
4954eaae44dSAndrew Thompson.
4964eaae44dSAndrew Thompson.Pp
497a5118bdfSAndrew Thompson.Ft int
498a5118bdfSAndrew Thompson.Fn libusb_handle_events_locked "libusb_context *ctx" "struct timeval *tv"
499a5118bdfSAndrew ThompsonHandle any pending events by polling file desciptors, without checking if
500a5118bdfSAndrew Thompsonanother threads are already doing so. Must be called with the event lock held.
5014eaae44dSAndrew Thompson.
5024eaae44dSAndrew Thompson.Pp
503a5118bdfSAndrew Thompson.Ft int
504a5118bdfSAndrew Thompson.Fn libusb_get_next_timeout "libusb_context *ctx" "struct timeval *tv"
505a5118bdfSAndrew ThompsonDetermine the next internal timeout that libusb needs to handle. Returns 0
506a5118bdfSAndrew Thompsonif there are no pending timeouts, 1 if a timeout was returned, or LIBUSB_ERROR
507a5118bdfSAndrew Thompsoncode on failure.
5084eaae44dSAndrew Thompson.
5094eaae44dSAndrew Thompson.Pp
510a5118bdfSAndrew Thompson.Ft void
511a5118bdfSAndrew Thompson.Fn libusb_set_pollfd_notifiers "libusb_context *ctx" "libusb_pollfd_added_cb added_cb" "libusb_pollfd_removed_cb remove_cb" "void *user_data"
512a5118bdfSAndrew ThompsonRegister notification functions for file descriptor additions/removals.
513a5118bdfSAndrew ThompsonThese functions will be invoked for every new or removed file descriptor
514a5118bdfSAndrew Thompsonthat libusb uses as an event source.
5154eaae44dSAndrew Thompson.
5164eaae44dSAndrew Thompson.Pp
517a5118bdfSAndrew Thompson.Ft const struct libusb_pollfd **
518a5118bdfSAndrew Thompson.Fn libusb_get_pollfds "libusb_context *ctx"
519a5118bdfSAndrew ThompsonRetrive a list of file descriptors that should be polled by your main loop as
520a5118bdfSAndrew Thompsonlibusb event sources. Returns a NULL-terminated list on success or NULL on failure.
5214eaae44dSAndrew Thompson.
5224eaae44dSAndrew Thompson.Sh LIBUSB VERSION 0.1 COMPATIBILITY
523a5118bdfSAndrew Thompson.Pp
524a5118bdfSAndrew ThompsonThe library is also compliant with LibUSB version 0.1.12.
525a5118bdfSAndrew Thompson.Pp
5264eaae44dSAndrew Thompson.Fn usb_open
5274eaae44dSAndrew Thompson.Fn usb_close
5284eaae44dSAndrew Thompson.Fn usb_get_string
5294eaae44dSAndrew Thompson.Fn usb_get_string_simple
5304eaae44dSAndrew Thompson.Fn usb_get_descriptor_by_endpoint
5314eaae44dSAndrew Thompson.Fn usb_get_descriptor
5324eaae44dSAndrew Thompson.Fn usb_parse_descriptor
5334eaae44dSAndrew Thompson.Fn usb_parse_configuration
5344eaae44dSAndrew Thompson.Fn usb_destroy_configuration
5354eaae44dSAndrew Thompson.Fn usb_fetch_and_parse_descriptors
5364eaae44dSAndrew Thompson.Fn usb_bulk_write
5374eaae44dSAndrew Thompson.Fn usb_bulk_read
5384eaae44dSAndrew Thompson.Fn usb_interrupt_write
5394eaae44dSAndrew Thompson.Fn usb_interrupt_read
5404eaae44dSAndrew Thompson.Fn usb_control_msg
5414eaae44dSAndrew Thompson.Fn usb_set_configuration
5424eaae44dSAndrew Thompson.Fn usb_claim_interface
5434eaae44dSAndrew Thompson.Fn usb_release_interface
5444eaae44dSAndrew Thompson.Fn usb_set_altinterface
5454eaae44dSAndrew Thompson.Fn usb_resetep
5464eaae44dSAndrew Thompson.Fn usb_clear_halt
5474eaae44dSAndrew Thompson.Fn usb_reset
5484eaae44dSAndrew Thompson.Fn usb_strerror
5494eaae44dSAndrew Thompson.Fn usb_init
5504eaae44dSAndrew Thompson.Fn usb_set_debug
5514eaae44dSAndrew Thompson.Fn usb_find_busses
5524eaae44dSAndrew Thompson.Fn usb_find_devices
5534eaae44dSAndrew Thompson.Fn usb_device
5544eaae44dSAndrew Thompson.Fn usb_get_busses
555f1b5fa6eSHans Petter Selasky.Fn usb_check_connected
5564eb5923dSHans Petter Selasky.Fn usb_get_driver_np
5574eb5923dSHans Petter Selasky.Fn usb_detach_kernel_driver_np
5584eaae44dSAndrew Thompson.
5594eaae44dSAndrew Thompson.Sh SEE ALSO
560a5118bdfSAndrew Thompson.Xr libusb20 3 ,
561c54c1f7cSAndrew Thompson.Xr usb 4 ,
5624eaae44dSAndrew Thompson.Xr usbconfig 8
563a5118bdfSAndrew Thompson.Pp
564a5118bdfSAndrew Thompson.Pa http://libusb.sourceforge.net/
5654eaae44dSAndrew Thompson.
5664eaae44dSAndrew Thompson.Sh HISTORY
5674eaae44dSAndrew Thompson.
5684eaae44dSAndrew Thompson.Nm
569a5118bdfSAndrew Thompsonsupport first appeared in
570a5118bdfSAndrew Thompson.Fx 8.0 .
571