xref: /freebsd/lib/libusb/libusb.3 (revision c8c1f2ec4d81af30c5d45a2eecfb430f44608fca)
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.\"
29ca96e26aSHans Petter Selasky.Dd August 16, 2011
304eaae44dSAndrew Thompson.Dt LIBUSB 3
314eaae44dSAndrew Thompson.Os
324eaae44dSAndrew Thompson.Sh NAME
334eaae44dSAndrew Thompson.Nm libusb
344eaae44dSAndrew Thompson.Nd "USB access library"
354eaae44dSAndrew Thompson.Sh LIBRARY
364eaae44dSAndrew ThompsonUSB access library (libusb -lusb)
374eaae44dSAndrew Thompson.Sh SYNOPSIS
38a5118bdfSAndrew Thompson.In libusb.h
394eaae44dSAndrew Thompson.Sh DESCRIPTION
404eaae44dSAndrew ThompsonThe
414eaae44dSAndrew Thompson.Nm
42a5118bdfSAndrew Thompsonlibrary contains interfaces for directly managing a usb device.
43a5118bdfSAndrew ThompsonThe current implementation supports v1.0 of the libusb API.
44a5118bdfSAndrew Thompson.Sh LIBRARY INITIALISATION / DEINITIALISATION
454eaae44dSAndrew Thompson.Pp
46a5118bdfSAndrew Thompson.Ft int
47a5118bdfSAndrew Thompson.Fn libusb_init libusb_context **ctx
48*c8c1f2ecSHans Petter SelaskyThis function initialises libusb.
49*c8c1f2ecSHans Petter SelaskyMust be called at the beginning
50*c8c1f2ecSHans Petter Selaskyof the program.
51*c8c1f2ecSHans Petter SelaskyThis function returns 0 on success or LIBUSB_ERROR on
52a5118bdfSAndrew Thompsonfailure.
534eaae44dSAndrew Thompson.Pp
54a5118bdfSAndrew Thompson.Ft void
55a5118bdfSAndrew Thompson.Fn libusb_exit "libusb_context *ctx"
56*c8c1f2ecSHans Petter SelaskyDeinitialise libusb.
57*c8c1f2ecSHans Petter SelaskyMust be called at the end of the application.
58a5118bdfSAndrew Thompson.Pp
59698e791aSHans Petter Selasky.Ft const char *
60698e791aSHans Petter Selasky.Fn libusb_strerror "int code"
61698e791aSHans Petter SelaskyGet ASCII representation of the error given by the
62698e791aSHans Petter Selasky.Fa code
63698e791aSHans Petter Selaskyargument.
64698e791aSHans Petter Selasky.Pp
65a5118bdfSAndrew Thompson.Ft void
66a5118bdfSAndrew Thompson.Fn libusb_set_debug "libusb_context *ctx" "int level"
67a5118bdfSAndrew ThompsonSet debug to the
68a5118bdfSAndrew Thompson.Fa level
69a5118bdfSAndrew Thompsonlevel.
70a5118bdfSAndrew Thompson.Pp
71a5118bdfSAndrew Thompson.Ft ssize_t
72a5118bdfSAndrew Thompson.Fn libusb_get_device_list "libusb_context *ctx" "libusb_device ***list"
73a5118bdfSAndrew ThompsonFill into
74a5118bdfSAndrew Thompson.Fa list
75*c8c1f2ecSHans Petter Selaskythe list of usb device available.
76*c8c1f2ecSHans Petter SelaskyAll the device created by this
77*c8c1f2ecSHans Petter Selaskyfunction must be unref and free when you are done with them.
78*c8c1f2ecSHans Petter SelaskyThis
79a5118bdfSAndrew Thompsonfunction returns the number of devices in list or a LIBUSB_ERROR code.
80a5118bdfSAndrew Thompson.Pp
81a5118bdfSAndrew Thompson.Ft void
82a5118bdfSAndrew Thompson.Fn libusb_free_device_list "libusb_device **list" "int unref_devices"
83*c8c1f2ecSHans Petter SelaskyFree the list of devices discovered by libusb_get_device_list.
84*c8c1f2ecSHans Petter SelaskyIf
85a5118bdfSAndrew Thompson.Fa unref_device
86a5118bdfSAndrew Thompsonis set to 1 all devices are unref one time.
87a5118bdfSAndrew Thompson.Pp
88a5118bdfSAndrew Thompson.Ft uint8_t
89a5118bdfSAndrew Thompson.Fn libusb_get_bus_number "libusb_device *dev"
90a5118bdfSAndrew ThompsonReturns the number of the bus contained by the device
91a5118bdfSAndrew Thompson.Fa dev.
92a5118bdfSAndrew Thompson.Pp
93a5118bdfSAndrew Thompson.Ft uint8_t
94a5118bdfSAndrew Thompson.Fn libusb_get_device_address "libusb_device *dev"
95ca96e26aSHans Petter SelaskyReturns the device_address contained by the device
96a5118bdfSAndrew Thompson.Fa dev.
97a5118bdfSAndrew Thompson.Pp
98ca96e26aSHans Petter Selasky.Ft enum libusb_speed
99ca96e26aSHans Petter Selasky.Fn libusb_get_device_speed "libusb_device *dev"
100ca96e26aSHans Petter SelaskyReturns the wire speed at which the device is connected.
101ca96e26aSHans Petter SelaskySee the LIBUSB_SPEED_XXX enums for more information.
102ca96e26aSHans Petter SelaskyLIBUSB_SPEED_UNKNOWN is returned in case of unknown wire speed.
103ca96e26aSHans Petter Selasky.Pp
104a5118bdfSAndrew Thompson.Ft int
105a5118bdfSAndrew Thompson.Fn libusb_get_max_packet_size "libusb_device *dev" "unsigned char endpoint"
106ca96e26aSHans Petter SelaskyReturns the wMaxPacketSize value on success, LIBUSB_ERROR_NOT_FOUND if the
107a5118bdfSAndrew Thompsonendpoint does not exist and LIBUSB_ERROR_OTHERS on other failure.
108a5118bdfSAndrew Thompson.Pp
109a5118bdfSAndrew Thompson.Ft libusb_device *
110a5118bdfSAndrew Thompson.Fn libusb_ref_device "libusb_device *dev"
111a5118bdfSAndrew ThompsonIncrement the reference counter of the device
112a5118bdfSAndrew Thompson.Fa dev.
113a5118bdfSAndrew Thompson.Pp
114a5118bdfSAndrew Thompson.Ft void
115a5118bdfSAndrew Thompson.Fn libusb_unref_device "libusb_device *dev"
116a5118bdfSAndrew ThompsonDecrement the reference counter of the device
117a5118bdfSAndrew Thompson.Fa dev.
118a5118bdfSAndrew Thompson.Pp
119a5118bdfSAndrew Thompson.Ft int
120a5118bdfSAndrew Thompson.Fn libusb_open "libusb_device *dev" "libusb_device_handle **devh"
121*c8c1f2ecSHans Petter SelaskyOpen a device and obtain a device_handle.
122*c8c1f2ecSHans Petter SelaskyReturns 0 on success,
123a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_MEM on memory allocation problem, LIBUSB_ERROR_ACCESS
124a5118bdfSAndrew Thompsonon permission problem, LIBUSB_ERROR_NO_DEVICE if the device has been
125a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on error.
126a5118bdfSAndrew Thompson.Pp
127a5118bdfSAndrew Thompson.Ft libusb_device_handle *
128a5118bdfSAndrew Thompson.Fn libusb_open_device_with_vid_pid "libusb_context *ctx" "uint16_t vid" "uint16_t pid"
129f6ac2391SJoel DahlConvenience function to open a device with is
130a5118bdfSAndrew Thompson.Fa vid
1314eaae44dSAndrew Thompsonand
132a5118bdfSAndrew Thompson.Fa pid.
133ca96e26aSHans Petter SelaskyReturns NULL on error.
1344eaae44dSAndrew Thompson.Pp
135a5118bdfSAndrew Thompson.Ft void
136a5118bdfSAndrew Thompson.Fn libusb_close "libusb_device_handle *devh"
137a5118bdfSAndrew ThompsonClose a device handle.
1384eaae44dSAndrew Thompson.Pp
139a5118bdfSAndrew Thompson.Ft libusb_device *
140ca96e26aSHans Petter Selasky.Fn libusb_get_device "libusb_device_handle *devh"
141ca96e26aSHans Petter SelaskyGet the device contained by devh.
142ca96e26aSHans Petter SelaskyReturns NULL on error.
1434eaae44dSAndrew Thompson.Pp
144a5118bdfSAndrew Thompson.Ft int
145a5118bdfSAndrew Thompson.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config"
146*c8c1f2ecSHans Petter SelaskyReturns the bConfiguration value of the current configuration.
147*c8c1f2ecSHans Petter SelaskyReturns 0
148a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
149a5118bdfSAndrew Thompsonand a LIBUSB_ERROR code on error.
1504eaae44dSAndrew Thompson.Pp
151a5118bdfSAndrew Thompson.Ft int
152a5118bdfSAndrew Thompson.Fn libusb_set_configuration "libusb_device_handle *devh" "int config"
153a5118bdfSAndrew ThompsonSet the active configuration
154a5118bdfSAndrew Thompson.Fa config
155a5118bdfSAndrew Thompsonfor the device contained by
156a5118bdfSAndrew Thompson.Fa devh.
157ca96e26aSHans Petter SelaskyThis function returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested
158a5118bdfSAndrew Thompsonconfiguration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently
159a5118bdfSAndrew Thompsonclaimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a
160a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
1614eaae44dSAndrew Thompson.Pp
162a5118bdfSAndrew Thompson.Ft int
163a5118bdfSAndrew Thompson.Fn libusb_claim_interface "libusb_device_handle *devh" "int interface_number"
164a5118bdfSAndrew ThompsonClaim an interface in a given libusb_handle
165a5118bdfSAndrew Thompson.Fa devh.
166*c8c1f2ecSHans Petter SelaskyThis is a non-blocking function.
167*c8c1f2ecSHans Petter SelaskyIt returns 0 success, LIBUSB_ERROR_NOT_FOUND
168a5118bdfSAndrew Thompsonif the requested interface does not exist, LIBUSB_ERROR_BUSY if a program or
169a5118bdfSAndrew Thompsondriver has claimed the interface, LIBUSB_ERROR_NO_DEVICE if the device has
170a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure.
1714eaae44dSAndrew Thompson.Pp
172a5118bdfSAndrew Thompson.Ft int
173a5118bdfSAndrew Thompson.Fn libusb_release_interface "libusb_device_handle *devh" "int interface_number"
174*c8c1f2ecSHans Petter SelaskyThis function release an interface.
175*c8c1f2ecSHans Petter SelaskyAll the claimed interface must be released
176*c8c1f2ecSHans Petter Selaskybefore closing a device.
177*c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the
178799162a6SJoel Dahlinterface was not claimed, LIBUSB_ERROR_NO_DEVICE if the device has been
179a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR on failure.
1804eaae44dSAndrew Thompson.Pp
181a5118bdfSAndrew Thompson.Ft int
182a5118bdfSAndrew Thompson.Fn libusb_set_interface_alt_setting "libusb_device_handle *dev" "int interface_number" "int alternate_setting"
183*c8c1f2ecSHans Petter SelaskyActivate an alternate setting for an interface.
184*c8c1f2ecSHans Petter SelaskyReturns 0 on success,
185a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if the interface was not claimed or the requested
186a5118bdfSAndrew Thompsonsetting does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been
187a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR code on failure.
1884eaae44dSAndrew Thompson.Pp
189a5118bdfSAndrew Thompson.Ft int
190a5118bdfSAndrew Thompson.Fn libusb_clear_halt "libusb_device_handle *devh" "unsigned char endpoint"
191*c8c1f2ecSHans Petter SelaskyClear an halt/stall for a endpoint.
192*c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND
193a5118bdfSAndrew Thompsonif the endpoint does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been
194a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on failure.
1954eaae44dSAndrew Thompson.Pp
196a5118bdfSAndrew Thompson.Ft int
197a5118bdfSAndrew Thompson.Fn libusb_reset_device "libusb_device_handle *devh"
198*c8c1f2ecSHans Petter SelaskyPerform an USB port reset for an usb device.
199*c8c1f2ecSHans Petter SelaskyReturns 0 on success,
200a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if re-enumeration is required or if the device has
201a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure.
2024eaae44dSAndrew Thompson.Pp
203a5118bdfSAndrew Thompson.Ft int
204f1b5fa6eSHans Petter Selasky.Fn libusb_check_connected "libusb_device_handle *devh"
205*c8c1f2ecSHans Petter SelaskyTest if USB device is still connected.
206*c8c1f2ecSHans Petter SelaskyReturns 0 on success,
207f1b5fa6eSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if has been disconnected and a LIBUSB_ERROR
208f1b5fa6eSHans Petter Selaskycode on failure.
209f1b5fa6eSHans Petter Selasky.Pp
210f1b5fa6eSHans Petter Selasky.Ft int
211a5118bdfSAndrew Thompson.Fn libusb_kernel_driver_active "libusb_device_handle *devh" "int interface"
212*c8c1f2ecSHans Petter SelaskyDetermine if a driver is active on a interface.
213*c8c1f2ecSHans Petter SelaskyReturns 0 if no kernel driver
214*c8c1f2ecSHans Petter Selaskyis active, returns 1 if a kernel driver is active,
215*c8c1f2ecSHans Petter Selaskyreturns LIBUSB_ERROR_NO_DEVICE
216ca96e26aSHans Petter Selaskyif the device has been disconnected and returns a LIBUSB_ERROR code on failure.
2174eaae44dSAndrew Thompson.Pp
218a5118bdfSAndrew Thompson.Ft int
219698e791aSHans Petter Selasky.Fn libusb_get_driver "libusb_device_handle *devh" "int interface" "char *name" "int namelen"
220698e791aSHans Petter Selaskyor
221698e791aSHans Petter Selasky.Ft int
222698e791aSHans Petter Selasky.Fn libusb_get_driver_np "libusb_device_handle *devh" "int interface" "char *name" "int namelen"
223698e791aSHans Petter SelaskyGets the name of the driver attached to the given
224698e791aSHans Petter Selasky.Fa device
225698e791aSHans Petter Selaskyand
226698e791aSHans Petter Selasky.Fa interface
227698e791aSHans Petter Selaskyinto the buffer given by
228698e791aSHans Petter Selasky.Fa name
229698e791aSHans Petter Selaskyand
230698e791aSHans Petter Selasky.Fa namelen .
231698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver is attached
232698e791aSHans Petter Selaskyto the given interface and LIBUSB_ERROR_INVALID_PARAM if the interface does
233698e791aSHans Petter Selaskynot exist.
234698e791aSHans Petter SelaskyThis function is non-portable.
235698e791aSHans Petter SelaskyThe buffer pointed to by
236698e791aSHans Petter Selasky.Fa name
237698e791aSHans Petter Selaskyis only zero terminated on success.
238698e791aSHans Petter Selasky.Pp
239698e791aSHans Petter Selasky.Ft int
240a5118bdfSAndrew Thompson.Fn libusb_detach_kernel_driver "libusb_device_handle *devh" "int interface"
241698e791aSHans Petter Selaskyor
242698e791aSHans Petter Selasky.Ft int
243698e791aSHans Petter Selasky.Fn libusb_detach_kernel_driver_np "libusb_device_handle *devh" "int interface"
244698e791aSHans Petter SelaskyDetach a kernel driver from an interface.
245698e791aSHans Petter SelaskyThis is needed to claim an interface required by a kernel driver.
246698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver was active,
247*c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist,
248*c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if the device has been disconnected
249*c8c1f2ecSHans Petter Selaskyand a LIBUSB_ERROR code on failure.
250*c8c1f2ecSHans Petter SelaskyThis function is non-portable.
2514eaae44dSAndrew Thompson.Pp
252a5118bdfSAndrew Thompson.Ft int
253a5118bdfSAndrew Thompson.Fn libusb_attach_kernel_driver "libusb_device_handle *devh" "int interface"
254*c8c1f2ecSHans Petter SelaskyRe-attach an interface kernel driver previously detached.
255*c8c1f2ecSHans Petter SelaskyReturns 0 on success,
256*c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist,
257*c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE
258a5118bdfSAndrew Thompsonif the device has been disconnect, LIBUSB_ERROR_BUSY if the driver cannot be
259a5118bdfSAndrew Thompsonattached because the interface is claimed by a program or driver and a
260a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
2614eaae44dSAndrew Thompson.Pp
262a5118bdfSAndrew Thompson.Sh USB DESCRIPTORS
2634eaae44dSAndrew Thompson.Pp
264a5118bdfSAndrew Thompson.Ft int
265a5118bdfSAndrew Thompson.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc"
266a5118bdfSAndrew ThompsonGet the USB device descriptor for the device
267a5118bdfSAndrew Thompson.Fa dev.
268*c8c1f2ecSHans Petter SelaskyThis is a non-blocking function.
269*c8c1f2ecSHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on
270a5118bdfSAndrew Thompsonfailure.
2714eaae44dSAndrew Thompson.Pp
272a5118bdfSAndrew Thompson.Ft int
273698e791aSHans Petter Selasky.Fn libsub_get_active_config_descriptor "libusb_device *dev" "struct libusb_config_descriptor **config"
274*c8c1f2ecSHans Petter SelaskyGet the USB configuration descriptor for the active configuration.
275*c8c1f2ecSHans Petter SelaskyReturns 0 on
276a5118bdfSAndrew Thompsonsuccess, returns LIBUSB_ERROR_NOT_FOUND if the device is in unconfigured state
277ca96e26aSHans Petter Selaskyand returns another LIBUSB_ERROR code on error.
2784eaae44dSAndrew Thompson.Pp
279a5118bdfSAndrew Thompson.Ft int
280a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor "libusb_device *dev" "uint8_t config_index" "libusb_config_descriptor **config"
281a5118bdfSAndrew ThompsonGet USB configuration descriptor based on its index
282a5118bdfSAndrew Thompson.Fa idx.
283a5118bdfSAndrew ThompsonReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
284a5118bdfSAndrew Thompsonand returns another LIBUSB_ERROR code on error.
285545b01adSAndrew Thompson.Pp
286a5118bdfSAndrew Thompson.Ft int
287a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor_by_value "libusb_device *dev" "uint8 bConfigurationValue" "libusb_config_descriptor **config"
288*c8c1f2ecSHans Petter SelaskyGet a USB configuration descriptor with a specific bConfigurationValue.
289*c8c1f2ecSHans Petter SelaskyThis is
290*c8c1f2ecSHans Petter Selaskya non-blocking function which does not send request through the device.
291*c8c1f2ecSHans Petter SelaskyReturns 0
292*c8c1f2ecSHans Petter Selaskyon success, LIBUSB_ERROR_NOT_FOUND if the configuration
293*c8c1f2ecSHans Petter Selaskydoes not exist and another
294a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
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.Pp
300a5118bdfSAndrew Thompson.Ft int
301a5118bdfSAndrew Thompson.Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length"
302ca96e26aSHans Petter SelaskyRetrieve a string descriptor in C style ascii.
303*c8c1f2ecSHans Petter SelaskyReturns a positive number of bytes in the resulting ASCII string
304*c8c1f2ecSHans Petter Selaskyon success and a LIBUSB_ERROR code on failure.
3054eaae44dSAndrew Thompson.Pp
306a5118bdfSAndrew Thompson.Sh USB ASYNCHRONOUS I/O
3074eaae44dSAndrew Thompson.Pp
308a5118bdfSAndrew Thompson.Ft struct libusb_transfer *
309a5118bdfSAndrew Thompson.Fn libusb_alloc_transfer "int iso_packets"
310a5118bdfSAndrew ThompsonAllocate a transfer with
311a5118bdfSAndrew Thompson.Fa iso_packets
312ca96e26aSHans Petter Selaskynumbers of isochronous packet descriptors.
313ca96e26aSHans Petter SelaskyReturns NULL on error.
3144eaae44dSAndrew Thompson.Pp
315a5118bdfSAndrew Thompson.Ft void
316a5118bdfSAndrew Thompson.Fn libusb_free_transfer "struct libusb_transfer *tr"
317a5118bdfSAndrew ThompsonFree a transfer.
3184eaae44dSAndrew Thompson.Pp
319a5118bdfSAndrew Thompson.Ft int
320a5118bdfSAndrew Thompson.Fn libusb_submit_transfer "struct libusb_transfer *tr"
321ca96e26aSHans Petter SelaskyThis function will submit a transfer and returns immediately.
322*c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NO_DEVICE if
323*c8c1f2ecSHans Petter Selaskythe device has been disconnected and
324a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure.
3254eaae44dSAndrew Thompson.Pp
326a5118bdfSAndrew Thompson.Ft int
327a5118bdfSAndrew Thompson.Fn libusb_cancel_transfer "struct libusb_transfer *tr"
328ca96e26aSHans Petter SelaskyThis function asynchronously cancel a transfer.
329ca96e26aSHans Petter SelaskyReturns 0 on success and LIBUSB_ERROR code on failure.
3304eaae44dSAndrew Thompson.Pp
331a5118bdfSAndrew Thompson.Sh USB SYNCHRONOUS I/O
3324eaae44dSAndrew Thompson.Pp
333a5118bdfSAndrew Thompson.Ft int
334698e791aSHans 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"
335ca96e26aSHans Petter SelaskyPerform a USB control transfer.
336ca96e26aSHans Petter SelaskyReturns the actual number of bytes
337c865d740SHans Petter Selaskytransferred on success in the range from and including zero until and
338c865d740SHans Petter Selaskyincluding
339892f4806SHans Petter Selasky.Fa wLength .
340c865d740SHans Petter SelaskyOn error a libusb error code is returned, for example
341c865d740SHans Petter SelaskyLIBUSB_ERROR_TIMEOUT if the transfer timeout, LIBUSB_ERROR_PIPE if the
342c865d740SHans Petter Selaskycontrol request was not supported, LIBUSB_ERROR_NO_DEVICE if the
343c865d740SHans Petter Selaskydevice has been disconnected or another LIBUSB_ERROR code on other failures.
344c865d740SHans Petter SelaskyThe libusb error codes are always negative.
3454eaae44dSAndrew Thompson.Pp
346a5118bdfSAndrew Thompson.Ft int
347a5118bdfSAndrew Thompson.Fn libusb_bulk_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout"
348892f4806SHans Petter SelaskyPerform an USB bulk transfer.
349892f4806SHans Petter SelaskyA timeout value of zero means no timeout.
350892f4806SHans Petter SelaskyThe timeout value is given in milliseconds.
351892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT
352a5118bdfSAndrew Thompsonif the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not
353a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data,
354a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
355a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure.
3564eaae44dSAndrew Thompson.Pp
357a5118bdfSAndrew Thompson.Ft int
358a5118bdfSAndrew Thompson.Fn libusb_interrupt_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout"
359892f4806SHans Petter SelaskyPerform an USB Interrupt transfer.
360892f4806SHans Petter SelaskyA timeout value of zero means no timeout.
361892f4806SHans Petter SelaskyThe timeout value is given in milliseconds.
362892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT
363a5118bdfSAndrew Thompsonif the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not
364a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data,
365a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
366a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure.
3674eaae44dSAndrew Thompson.Pp
368a5118bdfSAndrew Thompson.Sh USB EVENTS
3694eaae44dSAndrew Thompson.Pp
370a5118bdfSAndrew Thompson.Ft int
371a5118bdfSAndrew Thompson.Fn libusb_try_lock_events "libusb_context *ctx"
372ca96e26aSHans Petter SelaskyTry to acquire the event handling lock.
373ca96e26aSHans Petter SelaskyReturns 0 if the lock was obtained and 1 if not.
3744eaae44dSAndrew Thompson.Pp
375a5118bdfSAndrew Thompson.Ft void
376a5118bdfSAndrew Thompson.Fn libusb_lock_events "libusb_context *ctx"
377*c8c1f2ecSHans Petter SelaskyAcquire the event handling lock.
378*c8c1f2ecSHans Petter SelaskyThis function is blocking.
3794eaae44dSAndrew Thompson.Pp
380a5118bdfSAndrew Thompson.Ft void
381a5118bdfSAndrew Thompson.Fn libusb_unlock_events "libusb_context *ctx"
382*c8c1f2ecSHans Petter SelaskyRelease the event handling lock.
383*c8c1f2ecSHans Petter SelaskyThis will wake up any thread blocked
384a5118bdfSAndrew Thompsonon libusb_wait_for_event().
3854eaae44dSAndrew Thompson.Pp
386a5118bdfSAndrew Thompson.Ft int
387a5118bdfSAndrew Thompson.Fn libusb_event_handling_ok "libusb_context *ctx"
388*c8c1f2ecSHans Petter SelaskyDetermine if it still OK for this thread to be doing event handling.
389*c8c1f2ecSHans Petter SelaskyReturns 1
390*c8c1f2ecSHans Petter Selaskyif event handling can start or continue.
391*c8c1f2ecSHans Petter SelaskyReturns 0 if this thread must give up
392a5118bdfSAndrew Thompsonthe events lock.
3934eaae44dSAndrew Thompson.Pp
394a5118bdfSAndrew Thompson.Ft int
395a5118bdfSAndrew Thompson.Fn libusb_event_handler_active "libusb_context *ctx"
396*c8c1f2ecSHans Petter SelaskyDetermine if an active thread is handling events.
397*c8c1f2ecSHans Petter SelaskyReturns 1 if yes and 0 if there
398a5118bdfSAndrew Thompsonare no threads currently handling events.
3994eaae44dSAndrew Thompson.Pp
400a5118bdfSAndrew Thompson.Ft void
401a5118bdfSAndrew Thompson.Fn libusb_lock_event_waiters "libusb_context *ctx"
402*c8c1f2ecSHans Petter SelaskyAcquire the event_waiters lock.
403*c8c1f2ecSHans Petter SelaskyThis lock is designed to be obtained under the
404a5118bdfSAndrew Thompsonsituation where you want to be aware when events are completed, but some other
405a5118bdfSAndrew Thompsonthread is event handling so calling libusb_handle_events() is not allowed.
406545b01adSAndrew Thompson.Pp
407a5118bdfSAndrew Thompson.Ft void
408a5118bdfSAndrew Thompson.Fn libusb_unlock_event_waiters "libusb_context *ctx"
409a5118bdfSAndrew ThompsonRelease the event_waiters lock.
4104eaae44dSAndrew Thompson.Pp
411a5118bdfSAndrew Thompson.Ft int
412a5118bdfSAndrew Thompson.Fn libusb_wait_for_event "libusb_context *ctx" "struct timeval *tv"
413*c8c1f2ecSHans Petter SelaskyWait for another thread to signal completion of an event.
414*c8c1f2ecSHans Petter SelaskyMust be called
415*c8c1f2ecSHans Petter Selaskywith the event waiters lock held, see libusb_lock_event_waiters().
416*c8c1f2ecSHans Petter SelaskyThis will
417a5118bdfSAndrew Thompsonblock until the timeout expires or a transfer completes or a thread releases
418*c8c1f2ecSHans Petter Selaskythe event handling lock through libusb_unlock_events().
419*c8c1f2ecSHans Petter SelaskyReturns 0 after a
420a5118bdfSAndrew Thompsontransfer completes or another thread stops event handling, returns 1 if the
421a5118bdfSAndrew Thompsontimeout expired.
4224eaae44dSAndrew Thompson.Pp
423a5118bdfSAndrew Thompson.Ft int
424a5118bdfSAndrew Thompson.Fn libusb_handle_events_timeout "libusb_context *ctx" "struct timeval *tv"
425a5118bdfSAndrew ThompsonHandle any pending events by checking if timeouts have expired and by
426*c8c1f2ecSHans Petter Selaskychecking the set of file descriptors for activity.
427*c8c1f2ecSHans Petter SelaskyReturns 0 on success, or a
428a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure.
4294eaae44dSAndrew Thompson.Pp
430a5118bdfSAndrew Thompson.Ft int
431a5118bdfSAndrew Thompson.Fn libusb_handle_events "libusb_context *ctx"
432*c8c1f2ecSHans Petter SelaskyHandle any pending events in blocking mode with a sensible timeout.
433*c8c1f2ecSHans Petter SelaskyReturns 0
434a5118bdfSAndrew Thompsonon success, returns a LIBUSB_ERROR code on failure.
4354eaae44dSAndrew Thompson.Pp
436a5118bdfSAndrew Thompson.Ft int
437a5118bdfSAndrew Thompson.Fn libusb_handle_events_locked "libusb_context *ctx" "struct timeval *tv"
438a5118bdfSAndrew ThompsonHandle any pending events by polling file desciptors, without checking if
439*c8c1f2ecSHans Petter Selaskyanother threads are already doing so.
440*c8c1f2ecSHans Petter SelaskyMust be called with the event lock held.
4414eaae44dSAndrew Thompson.Pp
442a5118bdfSAndrew Thompson.Ft int
443a5118bdfSAndrew Thompson.Fn libusb_get_next_timeout "libusb_context *ctx" "struct timeval *tv"
444*c8c1f2ecSHans Petter SelaskyDetermine the next internal timeout that libusb needs to handle.
445*c8c1f2ecSHans Petter SelaskyReturns 0
446a5118bdfSAndrew Thompsonif there are no pending timeouts, 1 if a timeout was returned, or LIBUSB_ERROR
447a5118bdfSAndrew Thompsoncode on failure.
4484eaae44dSAndrew Thompson.Pp
449a5118bdfSAndrew Thompson.Ft void
450a5118bdfSAndrew Thompson.Fn libusb_set_pollfd_notifiers "libusb_context *ctx" "libusb_pollfd_added_cb added_cb" "libusb_pollfd_removed_cb remove_cb" "void *user_data"
451a5118bdfSAndrew ThompsonRegister notification functions for file descriptor additions/removals.
452a5118bdfSAndrew ThompsonThese functions will be invoked for every new or removed file descriptor
453a5118bdfSAndrew Thompsonthat libusb uses as an event source.
4544eaae44dSAndrew Thompson.Pp
455a5118bdfSAndrew Thompson.Ft const struct libusb_pollfd **
456a5118bdfSAndrew Thompson.Fn libusb_get_pollfds "libusb_context *ctx"
457a5118bdfSAndrew ThompsonRetrive a list of file descriptors that should be polled by your main loop as
458*c8c1f2ecSHans Petter Selaskylibusb event sources.
459*c8c1f2ecSHans Petter SelaskyReturns a NULL-terminated list on success or NULL on failure.
4604eaae44dSAndrew Thompson.Sh LIBUSB VERSION 0.1 COMPATIBILITY
461a5118bdfSAndrew Thompson.Pp
462a5118bdfSAndrew ThompsonThe library is also compliant with LibUSB version 0.1.12.
463a5118bdfSAndrew Thompson.Pp
4644eaae44dSAndrew Thompson.Fn usb_open
4654eaae44dSAndrew Thompson.Fn usb_close
4664eaae44dSAndrew Thompson.Fn usb_get_string
4674eaae44dSAndrew Thompson.Fn usb_get_string_simple
4684eaae44dSAndrew Thompson.Fn usb_get_descriptor_by_endpoint
4694eaae44dSAndrew Thompson.Fn usb_get_descriptor
4704eaae44dSAndrew Thompson.Fn usb_parse_descriptor
4714eaae44dSAndrew Thompson.Fn usb_parse_configuration
4724eaae44dSAndrew Thompson.Fn usb_destroy_configuration
4734eaae44dSAndrew Thompson.Fn usb_fetch_and_parse_descriptors
4744eaae44dSAndrew Thompson.Fn usb_bulk_write
4754eaae44dSAndrew Thompson.Fn usb_bulk_read
4764eaae44dSAndrew Thompson.Fn usb_interrupt_write
4774eaae44dSAndrew Thompson.Fn usb_interrupt_read
4784eaae44dSAndrew Thompson.Fn usb_control_msg
4794eaae44dSAndrew Thompson.Fn usb_set_configuration
4804eaae44dSAndrew Thompson.Fn usb_claim_interface
4814eaae44dSAndrew Thompson.Fn usb_release_interface
4824eaae44dSAndrew Thompson.Fn usb_set_altinterface
4834eaae44dSAndrew Thompson.Fn usb_resetep
4844eaae44dSAndrew Thompson.Fn usb_clear_halt
4854eaae44dSAndrew Thompson.Fn usb_reset
4864eaae44dSAndrew Thompson.Fn usb_strerror
4874eaae44dSAndrew Thompson.Fn usb_init
4884eaae44dSAndrew Thompson.Fn usb_set_debug
4894eaae44dSAndrew Thompson.Fn usb_find_busses
4904eaae44dSAndrew Thompson.Fn usb_find_devices
4914eaae44dSAndrew Thompson.Fn usb_device
4924eaae44dSAndrew Thompson.Fn usb_get_busses
493f1b5fa6eSHans Petter Selasky.Fn usb_check_connected
4944eb5923dSHans Petter Selasky.Fn usb_get_driver_np
4954eb5923dSHans Petter Selasky.Fn usb_detach_kernel_driver_np
4964eaae44dSAndrew Thompson.Sh SEE ALSO
497a5118bdfSAndrew Thompson.Xr libusb20 3 ,
498c54c1f7cSAndrew Thompson.Xr usb 4 ,
4994eaae44dSAndrew Thompson.Xr usbconfig 8
500a5118bdfSAndrew Thompson.Pp
501a5118bdfSAndrew Thompson.Pa http://libusb.sourceforge.net/
5024eaae44dSAndrew Thompson.Sh HISTORY
5034eaae44dSAndrew Thompson.Nm
504a5118bdfSAndrew Thompsonsupport first appeared in
505a5118bdfSAndrew Thompson.Fx 8.0 .
506