14eaae44dSAndrew Thompson.\" 2a5118bdfSAndrew Thompson.\" Copyright (c) 2009 Sylvestre Gallon 34eaae44dSAndrew Thompson.\" 44eaae44dSAndrew Thompson.\" Redistribution and use in source and binary forms, with or without 54eaae44dSAndrew Thompson.\" modification, are permitted provided that the following conditions 64eaae44dSAndrew Thompson.\" are met: 74eaae44dSAndrew Thompson.\" 1. Redistributions of source code must retain the above copyright 84eaae44dSAndrew Thompson.\" notice, this list of conditions and the following disclaimer. 94eaae44dSAndrew Thompson.\" 2. Redistributions in binary form must reproduce the above copyright 104eaae44dSAndrew Thompson.\" notice, this list of conditions and the following disclaimer in the 114eaae44dSAndrew Thompson.\" documentation and/or other materials provided with the distribution. 124eaae44dSAndrew Thompson.\" 134eaae44dSAndrew Thompson.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 144eaae44dSAndrew Thompson.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 154eaae44dSAndrew Thompson.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 164eaae44dSAndrew Thompson.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 174eaae44dSAndrew Thompson.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 184eaae44dSAndrew Thompson.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 194eaae44dSAndrew Thompson.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 204eaae44dSAndrew Thompson.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 214eaae44dSAndrew Thompson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 224eaae44dSAndrew Thompson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 234eaae44dSAndrew Thompson.\" SUCH DAMAGE. 244eaae44dSAndrew Thompson.\" 254eaae44dSAndrew Thompson.\" $FreeBSD$ 264eaae44dSAndrew Thompson.\" 27*aa87aa52SHans Petter Selasky.Dd October, 2, 2022 284eaae44dSAndrew Thompson.Dt LIBUSB 3 294eaae44dSAndrew Thompson.Os 304eaae44dSAndrew Thompson.Sh NAME 314eaae44dSAndrew Thompson.Nm libusb 324eaae44dSAndrew Thompson.Nd "USB access library" 334eaae44dSAndrew Thompson.Sh LIBRARY 3411867070SHans Petter SelaskyUSB access library 3511867070SHans Petter Selasky.Pq libusb, -lusb 364eaae44dSAndrew Thompson.Sh SYNOPSIS 37a5118bdfSAndrew Thompson.In libusb.h 384eaae44dSAndrew Thompson.Sh DESCRIPTION 394eaae44dSAndrew ThompsonThe 404eaae44dSAndrew Thompson.Nm 41a5118bdfSAndrew Thompsonlibrary contains interfaces for directly managing a usb device. 42a5118bdfSAndrew ThompsonThe current implementation supports v1.0 of the libusb API. 43930a4206SHans Petter Selasky.Sh LIBRARY INITIALISATION AND DEINITIALISATION 4414b896ceSHans Petter Selasky.Ft "const struct libusb_version *" 4514b896ceSHans Petter Selasky.Fn libusb_get_version "void" 4614b896ceSHans Petter SelaskyThis function returns version information about LibUSB. 4714b896ceSHans Petter Selasky.Pp 48a5118bdfSAndrew Thompson.Ft int 49930a4206SHans Petter Selasky.Fn libusb_init "libusb_context **ctx" 50c8c1f2ecSHans Petter SelaskyThis function initialises libusb. 5111867070SHans Petter SelaskyIt must be called at the beginning 5211867070SHans Petter Selaskyof the program, before other libusb routines are used. 53c8c1f2ecSHans Petter SelaskyThis function returns 0 on success or LIBUSB_ERROR on 54a5118bdfSAndrew Thompsonfailure. 554eaae44dSAndrew Thompson.Pp 56a5118bdfSAndrew Thompson.Ft void 57a5118bdfSAndrew Thompson.Fn libusb_exit "libusb_context *ctx" 58c8c1f2ecSHans Petter SelaskyDeinitialise libusb. 59c8c1f2ecSHans Petter SelaskyMust be called at the end of the application. 6011867070SHans Petter SelaskyOther libusb routines may not be called after this function. 61a5118bdfSAndrew Thompson.Pp 6204391da3SKyle Evans.Ft int 6304391da3SKyle Evans.Fn libusb_has_capability "uint32_t capability" 6404391da3SKyle EvansThis function checks the runtime capabilities of 6504391da3SKyle Evans.Nm . 6604391da3SKyle EvansThis function will return non-zero if the given 6704391da3SKyle Evans.Fa capability 6804391da3SKyle Evansis supported, 0 if it is not supported. 6904391da3SKyle EvansThe valid values for 7004391da3SKyle Evans.Fa capability 7104391da3SKyle Evansare: 7204391da3SKyle Evans.Bl -tag -width LIBUSB_CAP -offset indent 7304391da3SKyle Evans.It Va LIBUSB_CAP_HAS_CAPABILITY 7404391da3SKyle Evans.Nm 7504391da3SKyle Evanssupports 7604391da3SKyle Evans.Fn libusb_has_capability . 7704391da3SKyle Evans.It Va LIBUSB_CAP_HAS_HOTPLUG 7804391da3SKyle Evans.Nm 7904391da3SKyle Evanssupports hotplug notifications. 8004391da3SKyle Evans.It Va LIBUSB_CAP_HAS_HID_ACCESS 8104391da3SKyle Evans.Nm 8204391da3SKyle Evanscan access HID devices without requiring user intervention. 8304391da3SKyle Evans.It Va LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER 8404391da3SKyle Evans.Nm 8504391da3SKyle Evanssupports detaching of the default USB driver with 8604391da3SKyle Evans.Fn libusb_detach_kernel_driver . 8704391da3SKyle Evans.El 8804391da3SKyle Evans.Pp 89698e791aSHans Petter Selasky.Ft const char * 90698e791aSHans Petter Selasky.Fn libusb_strerror "int code" 9111867070SHans Petter SelaskyGet the ASCII representation of the error given by the 92698e791aSHans Petter Selasky.Fa code 93698e791aSHans Petter Selaskyargument. 94c61f2561SHans Petter SelaskyThis function does not return NULL. 95c61f2561SHans Petter Selasky.Pp 96c61f2561SHans Petter Selasky.Ft const char * 97c61f2561SHans Petter Selasky.Fn libusb_error_name "int code" 98c61f2561SHans Petter SelaskyGet the ASCII representation of the error enum given by the 99c61f2561SHans Petter Selasky.Fa code 100c61f2561SHans Petter Selaskyargument. 101c61f2561SHans Petter SelaskyThis function does not return NULL. 102698e791aSHans Petter Selasky.Pp 103a5118bdfSAndrew Thompson.Ft void 104a5118bdfSAndrew Thompson.Fn libusb_set_debug "libusb_context *ctx" "int level" 10511867070SHans Petter SelaskySet the debug level to 10611867070SHans Petter Selasky.Fa level . 107a5118bdfSAndrew Thompson.Pp 108a5118bdfSAndrew Thompson.Ft ssize_t 109a5118bdfSAndrew Thompson.Fn libusb_get_device_list "libusb_context *ctx" "libusb_device ***list" 11011867070SHans Petter SelaskyPopulate 111a5118bdfSAndrew Thompson.Fa list 11211867070SHans Petter Selaskywith the list of usb devices available, adding a reference to each 11311867070SHans Petter Selaskydevice in the list. 11411867070SHans Petter SelaskyAll the list entries created by this 11511867070SHans Petter Selaskyfunction must have their reference counter 11611867070SHans Petter Selaskydecremented when you are done with them, 11711867070SHans Petter Selaskyand the list itself must be freed. 118c8c1f2ecSHans Petter SelaskyThis 11911867070SHans Petter Selaskyfunction returns the number of devices in the list or a LIBUSB_ERROR code. 120a5118bdfSAndrew Thompson.Pp 121a5118bdfSAndrew Thompson.Ft void 122a5118bdfSAndrew Thompson.Fn libusb_free_device_list "libusb_device **list" "int unref_devices" 123c8c1f2ecSHans Petter SelaskyFree the list of devices discovered by libusb_get_device_list. 124c8c1f2ecSHans Petter SelaskyIf 125a5118bdfSAndrew Thompson.Fa unref_device 12611867070SHans Petter Selaskyis set to 1 all devices in the list have their reference 12711867070SHans Petter Selaskycounter decremented once. 128a5118bdfSAndrew Thompson.Pp 129a5118bdfSAndrew Thompson.Ft uint8_t 130a5118bdfSAndrew Thompson.Fn libusb_get_bus_number "libusb_device *dev" 131a5118bdfSAndrew ThompsonReturns the number of the bus contained by the device 132a5118bdfSAndrew Thompson.Fa dev . 133a5118bdfSAndrew Thompson.Pp 1340f2c7066SHans Petter Selasky.Ft uint8_t 1350f2c7066SHans Petter Selasky.Fn libusb_get_port_number "libusb_device *dev" 1360f2c7066SHans Petter SelaskyReturns the port number which the device given by 1370f2c7066SHans Petter Selasky.Fa dev 1380f2c7066SHans Petter Selaskyis attached to. 1390f2c7066SHans Petter Selasky.Pp 1405906bf49SEd Maste.Ft int 141a9205626SEd Maste.Fn libusb_get_port_numbers "libusb_device *dev" "uint8_t *buf" "uint8_t bufsize" 1425906bf49SEd MasteStores, in the buffer 1435906bf49SEd Maste.Fa buf 1445906bf49SEd Masteof size 1455906bf49SEd Maste.Fa bufsize , 1465906bf49SEd Mastethe list of all port numbers from root for the device 1475906bf49SEd Maste.Fa dev . 1485906bf49SEd Maste.Pp 149a9205626SEd Maste.Ft int 150a9205626SEd Maste.Fn libusb_get_port_path "libusb_context *ctx" "libusb_device *dev" "uint8_t *buf" "uint8_t bufsize" 151a9205626SEd MasteDeprecated function equivalent to libusb_get_port_numbers. 152a9205626SEd Maste.Pp 153a5118bdfSAndrew Thompson.Ft uint8_t 154a5118bdfSAndrew Thompson.Fn libusb_get_device_address "libusb_device *dev" 155ca96e26aSHans Petter SelaskyReturns the device_address contained by the device 156a5118bdfSAndrew Thompson.Fa dev . 157a5118bdfSAndrew Thompson.Pp 158ca96e26aSHans Petter Selasky.Ft enum libusb_speed 159ca96e26aSHans Petter Selasky.Fn libusb_get_device_speed "libusb_device *dev" 160ca96e26aSHans Petter SelaskyReturns the wire speed at which the device is connected. 161ca96e26aSHans Petter SelaskySee the LIBUSB_SPEED_XXX enums for more information. 162ca96e26aSHans Petter SelaskyLIBUSB_SPEED_UNKNOWN is returned in case of unknown wire speed. 163ca96e26aSHans Petter Selasky.Pp 164a5118bdfSAndrew Thompson.Ft int 165a5118bdfSAndrew Thompson.Fn libusb_get_max_packet_size "libusb_device *dev" "unsigned char endpoint" 166ca96e26aSHans Petter SelaskyReturns the wMaxPacketSize value on success, LIBUSB_ERROR_NOT_FOUND if the 167a5118bdfSAndrew Thompsonendpoint does not exist and LIBUSB_ERROR_OTHERS on other failure. 168a5118bdfSAndrew Thompson.Pp 169748205a3SHans Petter Selasky.Ft int 170748205a3SHans Petter Selasky.Fn libusb_get_max_iso_packet_size "libusb_device *dev" "unsigned char endpoint" 171748205a3SHans Petter SelaskyReturns the packet size multiplied by the packet multiplier on success, 172748205a3SHans Petter SelaskyLIBUSB_ERROR_NOT_FOUND if the endpoint does not exist and 173748205a3SHans Petter SelaskyLIBUSB_ERROR_OTHERS on other failure. 174748205a3SHans Petter Selasky.Pp 175a5118bdfSAndrew Thompson.Ft libusb_device * 176a5118bdfSAndrew Thompson.Fn libusb_ref_device "libusb_device *dev" 177a5118bdfSAndrew ThompsonIncrement the reference counter of the device 178a5118bdfSAndrew Thompson.Fa dev . 179a5118bdfSAndrew Thompson.Pp 180a5118bdfSAndrew Thompson.Ft void 181a5118bdfSAndrew Thompson.Fn libusb_unref_device "libusb_device *dev" 182a5118bdfSAndrew ThompsonDecrement the reference counter of the device 183a5118bdfSAndrew Thompson.Fa dev . 184a5118bdfSAndrew Thompson.Pp 185a5118bdfSAndrew Thompson.Ft int 186a5118bdfSAndrew Thompson.Fn libusb_open "libusb_device *dev" "libusb_device_handle **devh" 187c8c1f2ecSHans Petter SelaskyOpen a device and obtain a device_handle. 188c8c1f2ecSHans Petter SelaskyReturns 0 on success, 18911867070SHans Petter SelaskyLIBUSB_ERROR_NO_MEM on memory allocation problems, LIBUSB_ERROR_ACCESS 19011867070SHans Petter Selaskyon permissions problems, LIBUSB_ERROR_NO_DEVICE if the device has been 19111867070SHans Petter Selaskydisconnected and a LIBUSB_ERROR code on other errors. 192a5118bdfSAndrew Thompson.Pp 193a5118bdfSAndrew Thompson.Ft libusb_device_handle * 194a5118bdfSAndrew Thompson.Fn libusb_open_device_with_vid_pid "libusb_context *ctx" "uint16_t vid" "uint16_t pid" 19511867070SHans Petter SelaskyA convenience function to open a device by vendor and product IDs 196a5118bdfSAndrew Thompson.Fa vid 1974eaae44dSAndrew Thompsonand 198a5118bdfSAndrew Thompson.Fa pid . 199ca96e26aSHans Petter SelaskyReturns NULL on error. 2004eaae44dSAndrew Thompson.Pp 201a5118bdfSAndrew Thompson.Ft void 202a5118bdfSAndrew Thompson.Fn libusb_close "libusb_device_handle *devh" 203a5118bdfSAndrew ThompsonClose a device handle. 2044eaae44dSAndrew Thompson.Pp 205a5118bdfSAndrew Thompson.Ft libusb_device * 206ca96e26aSHans Petter Selasky.Fn libusb_get_device "libusb_device_handle *devh" 207ca96e26aSHans Petter SelaskyGet the device contained by devh. 208ca96e26aSHans Petter SelaskyReturns NULL on error. 2094eaae44dSAndrew Thompson.Pp 210a5118bdfSAndrew Thompson.Ft int 211a5118bdfSAndrew Thompson.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config" 212a3fb6da9SGlen BarberReturns the value of the current configuration. 213c8c1f2ecSHans Petter SelaskyReturns 0 214a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected 215a5118bdfSAndrew Thompsonand a LIBUSB_ERROR code on error. 2164eaae44dSAndrew Thompson.Pp 217a5118bdfSAndrew Thompson.Ft int 218a5118bdfSAndrew Thompson.Fn libusb_set_configuration "libusb_device_handle *devh" "int config" 21911867070SHans Petter SelaskySet the active configuration to 220a5118bdfSAndrew Thompson.Fa config 221a5118bdfSAndrew Thompsonfor the device contained by 222a5118bdfSAndrew Thompson.Fa devh . 223ca96e26aSHans Petter SelaskyThis function returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested 224a5118bdfSAndrew Thompsonconfiguration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently 225a5118bdfSAndrew Thompsonclaimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a 226a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 2274eaae44dSAndrew Thompson.Pp 228a5118bdfSAndrew Thompson.Ft int 229a5118bdfSAndrew Thompson.Fn libusb_claim_interface "libusb_device_handle *devh" "int interface_number" 230a5118bdfSAndrew ThompsonClaim an interface in a given libusb_handle 231a5118bdfSAndrew Thompson.Fa devh . 232c8c1f2ecSHans Petter SelaskyThis is a non-blocking function. 23311867070SHans Petter SelaskyIt returns 0 on success, LIBUSB_ERROR_NOT_FOUND 234a5118bdfSAndrew Thompsonif the requested interface does not exist, LIBUSB_ERROR_BUSY if a program or 235a5118bdfSAndrew Thompsondriver has claimed the interface, LIBUSB_ERROR_NO_DEVICE if the device has 236a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure. 2374eaae44dSAndrew Thompson.Pp 238a5118bdfSAndrew Thompson.Ft int 239a5118bdfSAndrew Thompson.Fn libusb_release_interface "libusb_device_handle *devh" "int interface_number" 24011867070SHans Petter SelaskyThis function releases an interface. 24111867070SHans Petter SelaskyAll the claimed interfaces on a device must be released 24211867070SHans Petter Selaskybefore closing the device. 243c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the 244799162a6SJoel Dahlinterface was not claimed, LIBUSB_ERROR_NO_DEVICE if the device has been 245a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR on failure. 2464eaae44dSAndrew Thompson.Pp 247a5118bdfSAndrew Thompson.Ft int 248a5118bdfSAndrew Thompson.Fn libusb_set_interface_alt_setting "libusb_device_handle *dev" "int interface_number" "int alternate_setting" 249c8c1f2ecSHans Petter SelaskyActivate an alternate setting for an interface. 250c8c1f2ecSHans Petter SelaskyReturns 0 on success, 251a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if the interface was not claimed or the requested 252a5118bdfSAndrew Thompsonsetting does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been 25311867070SHans Petter Selaskydisconnected and a LIBUSB_ERROR code on failure. 2544eaae44dSAndrew Thompson.Pp 255a5118bdfSAndrew Thompson.Ft int 256a5118bdfSAndrew Thompson.Fn libusb_clear_halt "libusb_device_handle *devh" "unsigned char endpoint" 257c8c1f2ecSHans Petter SelaskyClear an halt/stall for a endpoint. 258c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND 259a5118bdfSAndrew Thompsonif the endpoint does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been 260a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on failure. 2614eaae44dSAndrew Thompson.Pp 262a5118bdfSAndrew Thompson.Ft int 263a5118bdfSAndrew Thompson.Fn libusb_reset_device "libusb_device_handle *devh" 264c8c1f2ecSHans Petter SelaskyPerform an USB port reset for an usb device. 265c8c1f2ecSHans Petter SelaskyReturns 0 on success, 266a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if re-enumeration is required or if the device has 267a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure. 2684eaae44dSAndrew Thompson.Pp 269a5118bdfSAndrew Thompson.Ft int 270f1b5fa6eSHans Petter Selasky.Fn libusb_check_connected "libusb_device_handle *devh" 27111867070SHans Petter SelaskyTest if the USB device is still connected. 272c8c1f2ecSHans Petter SelaskyReturns 0 on success, 27311867070SHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if it has been disconnected and a LIBUSB_ERROR 274f1b5fa6eSHans Petter Selaskycode on failure. 275f1b5fa6eSHans Petter Selasky.Pp 276f1b5fa6eSHans Petter Selasky.Ft int 277a5118bdfSAndrew Thompson.Fn libusb_kernel_driver_active "libusb_device_handle *devh" "int interface" 278c8c1f2ecSHans Petter SelaskyDetermine if a driver is active on a interface. 2794d2472aaSHans Petter SelaskyReturns 0 if no kernel driver is active 2804d2472aaSHans Petter Selaskyand 1 if a kernel driver is active, LIBUSB_ERROR_NO_DEVICE 28111867070SHans Petter Selaskyif the device has been disconnected and a LIBUSB_ERROR code on failure. 2824eaae44dSAndrew Thompson.Pp 283a5118bdfSAndrew Thompson.Ft int 284698e791aSHans Petter Selasky.Fn libusb_get_driver "libusb_device_handle *devh" "int interface" "char *name" "int namelen" 285698e791aSHans Petter Selaskyor 286698e791aSHans Petter Selasky.Ft int 287698e791aSHans Petter Selasky.Fn libusb_get_driver_np "libusb_device_handle *devh" "int interface" "char *name" "int namelen" 28811867070SHans Petter SelaskyCopy the name of the driver attached to the given 289698e791aSHans Petter Selasky.Fa device 290698e791aSHans Petter Selaskyand 291698e791aSHans Petter Selasky.Fa interface 29211867070SHans Petter Selaskyinto the buffer 293698e791aSHans Petter Selasky.Fa name 29411867070SHans Petter Selaskyof length 295698e791aSHans Petter Selasky.Fa namelen . 296698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver is attached 297698e791aSHans Petter Selaskyto the given interface and LIBUSB_ERROR_INVALID_PARAM if the interface does 298698e791aSHans Petter Selaskynot exist. 299698e791aSHans Petter SelaskyThis function is non-portable. 300698e791aSHans Petter SelaskyThe buffer pointed to by 301698e791aSHans Petter Selasky.Fa name 302698e791aSHans Petter Selaskyis only zero terminated on success. 303698e791aSHans Petter Selasky.Pp 304698e791aSHans Petter Selasky.Ft int 305a5118bdfSAndrew Thompson.Fn libusb_detach_kernel_driver "libusb_device_handle *devh" "int interface" 306698e791aSHans Petter Selaskyor 307698e791aSHans Petter Selasky.Ft int 308698e791aSHans Petter Selasky.Fn libusb_detach_kernel_driver_np "libusb_device_handle *devh" "int interface" 309698e791aSHans Petter SelaskyDetach a kernel driver from an interface. 31011867070SHans Petter SelaskyThis is needed to claim an interface already claimed by a kernel driver. 311698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver was active, 312c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, 313c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if the device has been disconnected 314c8c1f2ecSHans Petter Selaskyand a LIBUSB_ERROR code on failure. 315c8c1f2ecSHans Petter SelaskyThis function is non-portable. 3164eaae44dSAndrew Thompson.Pp 317a5118bdfSAndrew Thompson.Ft int 318a5118bdfSAndrew Thompson.Fn libusb_attach_kernel_driver "libusb_device_handle *devh" "int interface" 31911867070SHans Petter SelaskyRe-attach an interface kernel driver that was previously detached. 320c8c1f2ecSHans Petter SelaskyReturns 0 on success, 321c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, 322c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE 32311867070SHans Petter Selaskyif the device has been disconnected, LIBUSB_ERROR_BUSY if the driver cannot be 324a5118bdfSAndrew Thompsonattached because the interface is claimed by a program or driver and a 325a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 3265b40d960SHans Petter Selasky.Pp 3275b40d960SHans Petter Selasky.Ft int 3285b40d960SHans Petter Selasky.Fn libusb_set_auto_detach_kernel_driver "libusb_device_handle *devh" "int enable" 3295b40d960SHans Petter SelaskyThis function enables automatic kernel interface driver detach when an 3305b40d960SHans Petter Selaskyinterface is claimed. 3315b40d960SHans Petter SelaskyWhen the interface is restored the kernel driver is allowed to be re-attached. 3325b40d960SHans Petter SelaskyIf the 3335b40d960SHans Petter Selasky.Fa enable 3345b40d960SHans Petter Selaskyargument is non-zero the feature is enabled. 3355b40d960SHans Petter SelaskyElse disabled. 3365b40d960SHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on 3375b40d960SHans Petter Selaskyfailure. 338a5118bdfSAndrew Thompson.Sh USB DESCRIPTORS 339a5118bdfSAndrew Thompson.Ft int 340a5118bdfSAndrew Thompson.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc" 341a5118bdfSAndrew ThompsonGet the USB device descriptor for the device 342a5118bdfSAndrew Thompson.Fa dev . 343c8c1f2ecSHans Petter SelaskyThis is a non-blocking function. 344c8c1f2ecSHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on 345a5118bdfSAndrew Thompsonfailure. 3464eaae44dSAndrew Thompson.Pp 347a5118bdfSAndrew Thompson.Ft int 348cb0df9e8SHans Petter Selasky.Fn libusb_get_active_config_descriptor "libusb_device *dev" "struct libusb_config_descriptor **config" 349c8c1f2ecSHans Petter SelaskyGet the USB configuration descriptor for the active configuration. 350c8c1f2ecSHans Petter SelaskyReturns 0 on 35111867070SHans Petter Selaskysuccess, LIBUSB_ERROR_NOT_FOUND if the device is in 35211867070SHans Petter Selaskyan unconfigured state 35311867070SHans Petter Selaskyand a LIBUSB_ERROR code on error. 3544eaae44dSAndrew Thompson.Pp 355a5118bdfSAndrew Thompson.Ft int 356a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor "libusb_device *dev" "uint8_t config_index" "libusb_config_descriptor **config" 35711867070SHans Petter SelaskyGet a USB configuration descriptor based on its index 358a5118bdfSAndrew Thompson.Fa idx . 359a5118bdfSAndrew ThompsonReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist 36011867070SHans Petter Selaskyand a LIBUSB_ERROR code on error. 361545b01adSAndrew Thompson.Pp 362a5118bdfSAndrew Thompson.Ft int 363a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor_by_value "libusb_device *dev" "uint8 bConfigurationValue" "libusb_config_descriptor **config" 364c8c1f2ecSHans Petter SelaskyGet a USB configuration descriptor with a specific bConfigurationValue. 365c8c1f2ecSHans Petter SelaskyThis is 36611867070SHans Petter Selaskya non-blocking function which does not send a request through the device. 367c8c1f2ecSHans Petter SelaskyReturns 0 368c8c1f2ecSHans Petter Selaskyon success, LIBUSB_ERROR_NOT_FOUND if the configuration 36911867070SHans Petter Selaskydoes not exist and a 370a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 3714eaae44dSAndrew Thompson.Pp 372a5118bdfSAndrew Thompson.Ft void 373390065b1SAlfred Perlstein.Fn libusb_free_config_descriptor "libusb_config_descriptor *config" 374a5118bdfSAndrew ThompsonFree a configuration descriptor. 3754eaae44dSAndrew Thompson.Pp 376a5118bdfSAndrew Thompson.Ft int 37778ed0e49SHans Petter Selasky.Fn libusb_get_string_descriptor "libusb_device_handle *devh" "uint8_t desc_idx" "uint16_t langid" "unsigned char *data" "int length" 37878ed0e49SHans Petter SelaskyRetrieve a string descriptor in raw format. 37978ed0e49SHans Petter SelaskyReturns the number of bytes actually transferred on success 38078ed0e49SHans Petter Selaskyor a negative LIBUSB_ERROR code on failure. 38178ed0e49SHans Petter Selasky.Pp 38278ed0e49SHans Petter Selasky.Ft int 383a5118bdfSAndrew Thompson.Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length" 38411867070SHans Petter SelaskyRetrieve a string descriptor in C style ASCII. 38511867070SHans Petter SelaskyReturns the positive number of bytes in the resulting ASCII string 386c8c1f2ecSHans Petter Selaskyon success and a LIBUSB_ERROR code on failure. 3874eaae44dSAndrew Thompson.Pp 3884c0392e6SHans Petter Selasky.Ft int 3894c0392e6SHans Petter Selasky.Fn libusb_parse_ss_endpoint_comp "const void *buf" "int len" "libusb_ss_endpoint_companion_descriptor **ep_comp" 3904c0392e6SHans Petter SelaskyThis function parses the USB 3.0 endpoint companion descriptor in host endian format pointed to by 3914c0392e6SHans Petter Selasky.Fa buf 3924c0392e6SHans Petter Selaskyand having a length of 3934c0392e6SHans Petter Selasky.Fa len . 3944c0392e6SHans Petter SelaskyTypically these arguments are the extra and extra_length fields of the 3954c0392e6SHans Petter Selaskyendpoint descriptor. 3964c0392e6SHans Petter SelaskyOn success the pointer to resulting descriptor is stored at the location given by 3974c0392e6SHans Petter Selasky.Fa ep_comp . 3984c0392e6SHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 3994c0392e6SHans Petter SelaskyOn success the parsed USB 3.0 endpoint companion descriptor must be 4004c0392e6SHans Petter Selaskyfreed using the libusb_free_ss_endpoint_comp function. 4014c0392e6SHans Petter Selasky.Pp 4024c0392e6SHans Petter Selasky.Ft void 4034c0392e6SHans Petter Selasky.Fn libusb_free_ss_endpoint_comp "libusb_ss_endpoint_companion_descriptor *ep_comp" 40437d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed USB 3.0 endpoint companion descriptor given by 40537d0636aSHans Petter Selasky.Fa ep_comp . 40637d0636aSHans Petter Selasky.Pp 40737d0636aSHans Petter Selasky.Ft int 40837d0636aSHans Petter Selasky.Fn libusb_get_ss_endpoint_companion_descriptor "struct libusb_context *ctx" "const struct libusb_endpoint_descriptor *endpoint" "struct libusb_ss_endpoint_companion_descriptor **ep_comp" 40937d0636aSHans Petter SelaskyThis function finds and parses the USB 3.0 endpoint companion descriptor given by 41037d0636aSHans Petter Selasky.Fa endpoint . 41137d0636aSHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 41237d0636aSHans Petter SelaskyOn success the parsed USB 3.0 endpoint companion descriptor must be 41337d0636aSHans Petter Selaskyfreed using the libusb_free_ss_endpoint_companion_descriptor function. 41437d0636aSHans Petter Selasky.Pp 41537d0636aSHans Petter Selasky.Ft void 41637d0636aSHans Petter Selasky.Fn libusb_free_ss_endpoint_companion_descriptor "struct libusb_ss_endpoint_companion_descriptor *ep_comp" 41737d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed USB 3.0 endpoint companion descriptor given by 41837d0636aSHans Petter Selasky.Fa ep_comp . 41937d0636aSHans Petter Selasky.Pp 42037d0636aSHans Petter Selasky.Ft int 42137d0636aSHans Petter Selasky.Fn libusb_get_bos_descriptor "libusb_device_handle *handle" "struct libusb_bos_descriptor **bos" 42237d0636aSHans Petter SelaskyThis function queries the USB device given by 42337d0636aSHans Petter Selasky.Fa handle 42437d0636aSHans Petter Selaskyand stores a pointer to a parsed BOS descriptor into 42537d0636aSHans Petter Selasky.Fa bos . 42637d0636aSHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 42737d0636aSHans Petter SelaskyOn success the parsed BOS descriptor must be 42837d0636aSHans Petter Selaskyfreed using the libusb_free_bos_descriptor function. 4294c0392e6SHans Petter Selasky.Pp 4304c0392e6SHans Petter Selasky.Ft int 4314c0392e6SHans Petter Selasky.Fn libusb_parse_bos_descriptor "const void *buf" "int len" "libusb_bos_descriptor **bos" 4324c0392e6SHans Petter SelaskyThis function parses a Binary Object Store, BOS, descriptor into host endian format pointed to by 4334c0392e6SHans Petter Selasky.Fa buf 4344c0392e6SHans Petter Selaskyand having a length of 4354c0392e6SHans Petter Selasky.Fa len . 4364c0392e6SHans Petter SelaskyOn success the pointer to resulting descriptor is stored at the location given by 4374c0392e6SHans Petter Selasky.Fa bos . 4384c0392e6SHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 4394c0392e6SHans Petter SelaskyOn success the parsed BOS descriptor must be freed using the 4404c0392e6SHans Petter Selaskylibusb_free_bos_descriptor function. 4414c0392e6SHans Petter Selasky.Pp 4424c0392e6SHans Petter Selasky.Ft void 4434c0392e6SHans Petter Selasky.Fn libusb_free_bos_descriptor "libusb_bos_descriptor *bos" 44437d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed BOS descriptor given by 44537d0636aSHans Petter Selasky.Fa bos . 44637d0636aSHans Petter Selasky.Pp 44737d0636aSHans Petter Selasky.Ft int 44837d0636aSHans Petter Selasky.Fn libusb_get_usb_2_0_extension_descriptor "struct libusb_context *ctx" "struct libusb_bos_dev_capability_descriptor *dev_cap" "struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension" 44937d0636aSHans Petter SelaskyThis function parses the USB 2.0 extension descriptor from the descriptor given by 45037d0636aSHans Petter Selasky.Fa dev_cap 45137d0636aSHans Petter Selaskyand stores a pointer to the parsed descriptor into 45237d0636aSHans Petter Selasky.Fa usb_2_0_extension . 45337d0636aSHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 45437d0636aSHans Petter SelaskyOn success the parsed USB 2.0 extension descriptor must be freed using the 45537d0636aSHans Petter Selaskylibusb_free_usb_2_0_extension_descriptor function. 45637d0636aSHans Petter Selasky.Pp 45737d0636aSHans Petter Selasky.Ft void 45837d0636aSHans Petter Selasky.Fn libusb_free_usb_2_0_extension_descriptor "struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension" 45937d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed USB 2.0 extension descriptor given by 46037d0636aSHans Petter Selasky.Fa usb_2_0_extension . 46137d0636aSHans Petter Selasky.Pp 46237d0636aSHans Petter Selasky.Ft int 46337d0636aSHans Petter Selasky.Fn libusb_get_ss_usb_device_capability_descriptor "struct libusb_context *ctx" "struct libusb_bos_dev_capability_descriptor *dev_cap" "struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_capability" 46437d0636aSHans Petter SelaskyThis function parses the SuperSpeed device capability descriptor from the descriptor given by 46537d0636aSHans Petter Selasky.Fa dev_cap 46637d0636aSHans Petter Selaskyand stores a pointer to the parsed descriptor into 46737d0636aSHans Petter Selasky.Fa ss_usb_device_capability . 46837d0636aSHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 46937d0636aSHans Petter SelaskyOn success the parsed SuperSpeed device capability descriptor must be freed using the 47037d0636aSHans Petter Selaskylibusb_free_ss_usb_device_capability_descriptor function. 47137d0636aSHans Petter Selasky.Pp 47237d0636aSHans Petter Selasky.Ft void 47337d0636aSHans Petter Selasky.Fn libusb_free_ss_usb_device_capability_descriptor "struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_capability" 47437d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed SuperSpeed device capability descriptor given by 47537d0636aSHans Petter Selasky.Fa ss_usb_device_capability . 47637d0636aSHans Petter Selasky.Pp 47737d0636aSHans Petter Selasky.Ft int 47837d0636aSHans Petter Selasky.Fn libusb_get_container_id_descriptor "struct libusb_context *ctx" "struct libusb_bos_dev_capability_descriptor *dev_cap" "struct libusb_container_id_descriptor **container_id" 47937d0636aSHans Petter SelaskyThis function parses the container ID descriptor from the descriptor given by 48037d0636aSHans Petter Selasky.Fa dev_cap 48137d0636aSHans Petter Selaskyand stores a pointer to the parsed descriptor into 48237d0636aSHans Petter Selasky.Fa container_id . 48337d0636aSHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 48437d0636aSHans Petter SelaskyOn success the parsed container ID descriptor must be freed using the 48537d0636aSHans Petter Selaskylibusb_free_container_id_descriptor function. 48637d0636aSHans Petter Selasky.Pp 48737d0636aSHans Petter Selasky.Ft void 48837d0636aSHans Petter Selasky.Fn libusb_free_container_id_descriptor "struct libusb_container_id_descriptor *container_id" 48937d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed container ID descriptor given by 49037d0636aSHans Petter Selasky.Fa container_id . 491a5118bdfSAndrew Thompson.Sh USB ASYNCHRONOUS I/O 492a5118bdfSAndrew Thompson.Ft struct libusb_transfer * 493a5118bdfSAndrew Thompson.Fn libusb_alloc_transfer "int iso_packets" 49411867070SHans Petter SelaskyAllocate a transfer with the number of isochronous packet descriptors 49511867070SHans Petter Selaskyspecified by 49611867070SHans Petter Selasky.Fa iso_packets . 497ca96e26aSHans Petter SelaskyReturns NULL on error. 4984eaae44dSAndrew Thompson.Pp 499a5118bdfSAndrew Thompson.Ft void 500a5118bdfSAndrew Thompson.Fn libusb_free_transfer "struct libusb_transfer *tr" 501a5118bdfSAndrew ThompsonFree a transfer. 5024eaae44dSAndrew Thompson.Pp 503a5118bdfSAndrew Thompson.Ft int 504a5118bdfSAndrew Thompson.Fn libusb_submit_transfer "struct libusb_transfer *tr" 505ca96e26aSHans Petter SelaskyThis function will submit a transfer and returns immediately. 506c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NO_DEVICE if 50711867070SHans Petter Selaskythe device has been disconnected and a 508a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure. 5094eaae44dSAndrew Thompson.Pp 510a5118bdfSAndrew Thompson.Ft int 511a5118bdfSAndrew Thompson.Fn libusb_cancel_transfer "struct libusb_transfer *tr" 51211867070SHans Petter SelaskyThis function asynchronously cancels a transfer. 51311867070SHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on failure. 514a5118bdfSAndrew Thompson.Sh USB SYNCHRONOUS I/O 515a5118bdfSAndrew Thompson.Ft int 516698e791aSHans 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" 517ca96e26aSHans Petter SelaskyPerform a USB control transfer. 518ca96e26aSHans Petter SelaskyReturns the actual number of bytes 51911867070SHans Petter Selaskytransferred on success, in the range from and including zero up to and 520c865d740SHans Petter Selaskyincluding 521892f4806SHans Petter Selasky.Fa wLength . 52211867070SHans Petter SelaskyOn error a LIBUSB_ERROR code is returned, for example 52311867070SHans Petter SelaskyLIBUSB_ERROR_TIMEOUT if the transfer timed out, LIBUSB_ERROR_PIPE if the 524c865d740SHans Petter Selaskycontrol request was not supported, LIBUSB_ERROR_NO_DEVICE if the 52511867070SHans Petter Selaskydevice has been disconnected and another LIBUSB_ERROR code on other failures. 52611867070SHans Petter SelaskyThe LIBUSB_ERROR codes are all negative. 5274eaae44dSAndrew Thompson.Pp 528a5118bdfSAndrew Thompson.Ft int 529a5118bdfSAndrew Thompson.Fn libusb_bulk_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout" 530892f4806SHans Petter SelaskyPerform an USB bulk transfer. 531892f4806SHans Petter SelaskyA timeout value of zero means no timeout. 532892f4806SHans Petter SelaskyThe timeout value is given in milliseconds. 533892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT 53411867070SHans Petter Selaskyif the transfer timed out, LIBUSB_ERROR_PIPE if the control request was not 535a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data, 536a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 53711867070SHans Petter Selaskya LIBUSB_ERROR code on other failure. 5384eaae44dSAndrew Thompson.Pp 539a5118bdfSAndrew Thompson.Ft int 540a5118bdfSAndrew Thompson.Fn libusb_interrupt_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout" 541892f4806SHans Petter SelaskyPerform an USB Interrupt transfer. 542892f4806SHans Petter SelaskyA timeout value of zero means no timeout. 543892f4806SHans Petter SelaskyThe timeout value is given in milliseconds. 544892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT 54511867070SHans Petter Selaskyif the transfer timed out, LIBUSB_ERROR_PIPE if the control request was not 546a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data, 547a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 54811867070SHans Petter Selaskya LIBUSB_ERROR code on other failure. 549a0c93fa3SHans Petter Selasky.Sh USB STREAMS SUPPORT 550a0c93fa3SHans Petter Selasky.Ft int 551a0c93fa3SHans Petter Selasky.Fn libusb_alloc_streams "libusb_device_handle *dev" "uint32_t num_streams" "unsigned char *endpoints" "int num_endpoints" 552a0c93fa3SHans Petter SelaskyThis function verifies that the given number of streams using the 553a0c93fa3SHans Petter Selaskygiven number of endpoints is allowed and allocates the resources 554a0c93fa3SHans Petter Selaskyneeded to use so-called USB streams. 555a0c93fa3SHans Petter SelaskyCurrently only a single stream per endpoint is supported to simplify 556a0c93fa3SHans Petter Selaskythe internals of LibUSB. 557a0c93fa3SHans Petter SelaskyThis function returns 0 on success or a LIBUSB_ERROR code on failure. 558a0c93fa3SHans Petter Selasky.Pp 559a0c93fa3SHans Petter Selasky.Ft int 560a0c93fa3SHans Petter Selasky.Fn libusb_free_streams "libusb_device_handle *dev" "unsigned char *endpoints" "int num_endpoints" 561a0c93fa3SHans Petter SelaskyThis function release resources needed for streams usage. 562a0c93fa3SHans Petter SelaskyReturns 0 on success or a LIBUSB_ERROR code on failure. 563a0c93fa3SHans Petter Selasky.Pp 564a0c93fa3SHans Petter Selasky.Ft void 565a0c93fa3SHans Petter Selasky.Fn libusb_transfer_set_stream_id "struct libusb_transfer *transfer" "uint32_t stream_id" 566a0c93fa3SHans Petter SelaskyThis function sets the stream ID for the given USB transfer. 567a0c93fa3SHans Petter Selasky.Pp 568a0c93fa3SHans Petter Selasky.Ft uint32_t 569a0c93fa3SHans Petter Selasky.Fn libusb_transfer_get_stream_id "struct libusb_transfer *transfer" 570a0c93fa3SHans Petter SelaskyThis function returns the stream ID for the given USB transfer. 571a0c93fa3SHans Petter SelaskyIf no stream ID is used a value of zero is returned. 572a5118bdfSAndrew Thompson.Sh USB EVENTS 573a5118bdfSAndrew Thompson.Ft int 574a5118bdfSAndrew Thompson.Fn libusb_try_lock_events "libusb_context *ctx" 575ca96e26aSHans Petter SelaskyTry to acquire the event handling lock. 576ca96e26aSHans Petter SelaskyReturns 0 if the lock was obtained and 1 if not. 5774eaae44dSAndrew Thompson.Pp 578a5118bdfSAndrew Thompson.Ft void 579a5118bdfSAndrew Thompson.Fn libusb_lock_events "libusb_context *ctx" 580c8c1f2ecSHans Petter SelaskyAcquire the event handling lock. 581c8c1f2ecSHans Petter SelaskyThis function is blocking. 5824eaae44dSAndrew Thompson.Pp 583a5118bdfSAndrew Thompson.Ft void 584a5118bdfSAndrew Thompson.Fn libusb_unlock_events "libusb_context *ctx" 585c8c1f2ecSHans Petter SelaskyRelease the event handling lock. 586c8c1f2ecSHans Petter SelaskyThis will wake up any thread blocked 58711867070SHans Petter Selaskyon 588d284271aSJoel Dahl.Fn libusb_wait_for_event . 5894eaae44dSAndrew Thompson.Pp 590a5118bdfSAndrew Thompson.Ft int 591a5118bdfSAndrew Thompson.Fn libusb_event_handling_ok "libusb_context *ctx" 592c8c1f2ecSHans Petter SelaskyDetermine if it still OK for this thread to be doing event handling. 593c8c1f2ecSHans Petter SelaskyReturns 1 594c8c1f2ecSHans Petter Selaskyif event handling can start or continue. 595c8c1f2ecSHans Petter SelaskyReturns 0 if this thread must give up 596a5118bdfSAndrew Thompsonthe events lock. 5974eaae44dSAndrew Thompson.Pp 598a5118bdfSAndrew Thompson.Ft int 599a5118bdfSAndrew Thompson.Fn libusb_event_handler_active "libusb_context *ctx" 600c8c1f2ecSHans Petter SelaskyDetermine if an active thread is handling events. 60111867070SHans Petter SelaskyReturns 1 if there is a thread handling events and 0 if there 602a5118bdfSAndrew Thompsonare no threads currently handling events. 6034eaae44dSAndrew Thompson.Pp 604a5118bdfSAndrew Thompson.Ft void 605*aa87aa52SHans Petter Selasky.Fn libusb_interrupt_event_handler "libusb_context *ctx" 606*aa87aa52SHans Petter SelaskyCauses the 607*aa87aa52SHans Petter Selasky.Fn libusb_handle_events 608*aa87aa52SHans Petter Selaskyfamiliy of functions to return to the caller one time. 609*aa87aa52SHans Petter SelaskyThe 610*aa87aa52SHans Petter Selasky.Fn libusb_handle_events 611*aa87aa52SHans Petter Selaskyfunctions may be called again after calling this function. 612*aa87aa52SHans Petter Selasky.Pp 613*aa87aa52SHans Petter Selasky.Ft void 614a5118bdfSAndrew Thompson.Fn libusb_lock_event_waiters "libusb_context *ctx" 615c8c1f2ecSHans Petter SelaskyAcquire the event_waiters lock. 61611867070SHans Petter SelaskyThis lock is designed to be obtained in the 617a5118bdfSAndrew Thompsonsituation where you want to be aware when events are completed, but some other 618882764c1SMateusz Piotrowskithread is event handling so calling 619882764c1SMateusz Piotrowski.Fn libusb_handle_events 620882764c1SMateusz Piotrowskiis not allowed. 621545b01adSAndrew Thompson.Pp 622a5118bdfSAndrew Thompson.Ft void 623a5118bdfSAndrew Thompson.Fn libusb_unlock_event_waiters "libusb_context *ctx" 624a5118bdfSAndrew ThompsonRelease the event_waiters lock. 6254eaae44dSAndrew Thompson.Pp 626a5118bdfSAndrew Thompson.Ft int 627a5118bdfSAndrew Thompson.Fn libusb_wait_for_event "libusb_context *ctx" "struct timeval *tv" 628c8c1f2ecSHans Petter SelaskyWait for another thread to signal completion of an event. 629c8c1f2ecSHans Petter SelaskyMust be called 630882764c1SMateusz Piotrowskiwith the event waiters lock held, see 631882764c1SMateusz Piotrowski.Fn libusb_lock_event_waiters . 632c8c1f2ecSHans Petter SelaskyThis will 633a5118bdfSAndrew Thompsonblock until the timeout expires or a transfer completes or a thread releases 634882764c1SMateusz Piotrowskithe event handling lock through 635882764c1SMateusz Piotrowski.Fn libusb_unlock_events . 636c8c1f2ecSHans Petter SelaskyReturns 0 after a 63711867070SHans Petter Selaskytransfer completes or another thread stops event handling, and 1 if the 638a5118bdfSAndrew Thompsontimeout expired. 6394eaae44dSAndrew Thompson.Pp 640a5118bdfSAndrew Thompson.Ft int 64103205428SHans Petter Selasky.Fn libusb_handle_events_timeout_completed "libusb_context *ctx" "struct timeval *tv" "int *completed" 64203205428SHans Petter SelaskyHandle any pending events by checking if timeouts have expired and by 64303205428SHans Petter Selaskychecking the set of file descriptors for activity. 64403205428SHans Petter SelaskyIf the 64503205428SHans Petter Selasky.Fa completed 64603205428SHans Petter Selaskyargument is not equal to NULL, this function will 64703205428SHans Petter Selaskyloop until a transfer completion callback sets the variable pointed to 64803205428SHans Petter Selaskyby the 64903205428SHans Petter Selasky.Fa completed 65003205428SHans Petter Selaskyargument to non-zero. 65103205428SHans Petter SelaskyIf the 65203205428SHans Petter Selasky.Fa tv 65303205428SHans Petter Selaskyargument is not equal to NULL, this function will return 65403205428SHans Petter SelaskyLIBUSB_ERROR_TIMEOUT after the given timeout. 65503205428SHans Petter SelaskyReturns 0 on success, or a LIBUSB_ERROR code on failure or timeout. 65603205428SHans Petter Selasky.Pp 65703205428SHans Petter Selasky.Ft int 65803205428SHans Petter Selasky.Fn libusb_handle_events_completed "libusb_context *ctx" "int *completed" 65903205428SHans Petter SelaskyHandle any pending events by checking the set of file descriptors for activity. 66003205428SHans Petter SelaskyIf the 66103205428SHans Petter Selasky.Fa completed 66203205428SHans Petter Selaskyargument is not equal to NULL, this function will 66303205428SHans Petter Selaskyloop until a transfer completion callback sets the variable pointed to 66403205428SHans Petter Selaskyby the 66503205428SHans Petter Selasky.Fa completed 66603205428SHans Petter Selaskyargument to non-zero. 66703205428SHans Petter SelaskyReturns 0 on success, or a LIBUSB_ERROR code on failure. 66803205428SHans Petter Selasky.Pp 66903205428SHans Petter Selasky.Ft int 670a5118bdfSAndrew Thompson.Fn libusb_handle_events_timeout "libusb_context *ctx" "struct timeval *tv" 671a5118bdfSAndrew ThompsonHandle any pending events by checking if timeouts have expired and by 672c8c1f2ecSHans Petter Selaskychecking the set of file descriptors for activity. 673c8c1f2ecSHans Petter SelaskyReturns 0 on success, or a 67403205428SHans Petter SelaskyLIBUSB_ERROR code on failure or timeout. 6754eaae44dSAndrew Thompson.Pp 676a5118bdfSAndrew Thompson.Ft int 677a5118bdfSAndrew Thompson.Fn libusb_handle_events "libusb_context *ctx" 678c8c1f2ecSHans Petter SelaskyHandle any pending events in blocking mode with a sensible timeout. 679c8c1f2ecSHans Petter SelaskyReturns 0 68011867070SHans Petter Selaskyon success and a LIBUSB_ERROR code on failure. 6814eaae44dSAndrew Thompson.Pp 682a5118bdfSAndrew Thompson.Ft int 683a5118bdfSAndrew Thompson.Fn libusb_handle_events_locked "libusb_context *ctx" "struct timeval *tv" 6843102cfe2SGlen BarberHandle any pending events by polling file descriptors, without checking if 68511867070SHans Petter Selaskyanother thread is already doing so. 686c8c1f2ecSHans Petter SelaskyMust be called with the event lock held. 6874eaae44dSAndrew Thompson.Pp 688a5118bdfSAndrew Thompson.Ft int 689a5118bdfSAndrew Thompson.Fn libusb_get_next_timeout "libusb_context *ctx" "struct timeval *tv" 690c8c1f2ecSHans Petter SelaskyDetermine the next internal timeout that libusb needs to handle. 691c8c1f2ecSHans Petter SelaskyReturns 0 69211867070SHans Petter Selaskyif there are no pending timeouts, 1 if a timeout was returned, or a LIBUSB_ERROR 69303205428SHans Petter Selaskycode on failure or timeout. 6944eaae44dSAndrew Thompson.Pp 695a5118bdfSAndrew Thompson.Ft void 696a5118bdfSAndrew Thompson.Fn libusb_set_pollfd_notifiers "libusb_context *ctx" "libusb_pollfd_added_cb added_cb" "libusb_pollfd_removed_cb remove_cb" "void *user_data" 697a5118bdfSAndrew ThompsonRegister notification functions for file descriptor additions/removals. 698a5118bdfSAndrew ThompsonThese functions will be invoked for every new or removed file descriptor 699a5118bdfSAndrew Thompsonthat libusb uses as an event source. 7004eaae44dSAndrew Thompson.Pp 701a5118bdfSAndrew Thompson.Ft const struct libusb_pollfd ** 702a5118bdfSAndrew Thompson.Fn libusb_get_pollfds "libusb_context *ctx" 703882764c1SMateusz PiotrowskiRetrieve a list of file descriptors that should be polled by your main loop as 704c8c1f2ecSHans Petter Selaskylibusb event sources. 705c8c1f2ecSHans Petter SelaskyReturns a NULL-terminated list on success or NULL on failure. 7067bdc064bSHans Petter Selasky.Pp 7077bdc064bSHans Petter Selasky.Ft int 7087bdc064bSHans Petter Selasky.Fn libusb_hotplug_register_callback "libusb_context *ctx" "libusb_hotplug_event events" "libusb_hotplug_flag flags" "int vendor_id" "int product_id" "int dev_class" "libusb_hotplug_callback_fn cb_fn" "void *user_data" "libusb_hotplug_callback_handle *handle" 7097bdc064bSHans Petter SelaskyThis function registers a hotplug filter. 7107bdc064bSHans Petter SelaskyThe 7117bdc064bSHans Petter Selasky.Fa events 7127bdc064bSHans Petter Selaskyargument select which events makes the hotplug filter trigger. 7137bdc064bSHans Petter SelaskyAvailable event values are LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED and LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT. 7147bdc064bSHans Petter SelaskyOne or more events must be specified. 7157bdc064bSHans Petter SelaskyThe 7167bdc064bSHans Petter Selasky.Fa vendor_id , 7177bdc064bSHans Petter Selasky.Fa product_id 7187bdc064bSHans Petter Selaskyand 7197bdc064bSHans Petter Selasky.Fa dev_class 7207bdc064bSHans Petter Selaskyarguments can be set to LIBUSB_HOTPLUG_MATCH_ANY to match any value in the USB device descriptor. 7217bdc064bSHans Petter SelaskyElse the specified value is used for matching. 7227bdc064bSHans Petter SelaskyIf the 7237bdc064bSHans Petter Selasky.Fa flags 7247bdc064bSHans Petter Selaskyargument is set to LIBUSB_HOTPLUG_ENUMERATE, all currently attached and matching USB devices will be passed to the hotplug filter, given by the 7257bdc064bSHans Petter Selasky.Fa cb_fn 7267bdc064bSHans Petter Selaskyargument. 7277bdc064bSHans Petter SelaskyElse the 7287bdc064bSHans Petter Selasky.Fa flags 7297bdc064bSHans Petter Selaskyargument should be set to LIBUSB_HOTPLUG_NO_FLAGS. 7307bdc064bSHans Petter SelaskyThis function returns 0 upon success or a LIBUSB_ERROR code on failure. 7317bdc064bSHans Petter Selasky.Pp 7327bdc064bSHans Petter Selasky.Ft int 7337bdc064bSHans Petter Selasky.Fn libusb_hotplug_callback_fn "libusb_context *ctx" "libusb_device *device" "libusb_hotplug_event event" "void *user_data" 7347bdc064bSHans Petter SelaskyThe hotplug filter function. 7357bdc064bSHans Petter SelaskyIf this function returns non-zero, the filter is removed. 7367bdc064bSHans Petter SelaskyElse the filter is kept and can receive more events. 7377bdc064bSHans Petter SelaskyThe 7387bdc064bSHans Petter Selasky.Fa user_data 7397bdc064bSHans Petter Selaskyargument is the same as given when the filter was registered. 7407bdc064bSHans Petter SelaskyThe 7417bdc064bSHans Petter Selasky.Fa event 7427bdc064bSHans Petter Selaskyargument can be either of LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED or LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT. 7437bdc064bSHans Petter Selasky.Pp 7447bdc064bSHans Petter Selasky.Ft void 7457bdc064bSHans Petter Selasky.Fn libusb_hotplug_deregister_callback "libusb_context *ctx" "libusb_hotplug_callback_handle handle" 7467bdc064bSHans Petter SelaskyThis function unregisters a hotplug filter. 7474eaae44dSAndrew Thompson.Sh LIBUSB VERSION 0.1 COMPATIBILITY 748a5118bdfSAndrew ThompsonThe library is also compliant with LibUSB version 0.1.12. 749a5118bdfSAndrew Thompson.Pp 7504eaae44dSAndrew Thompson.Fn usb_open 7514eaae44dSAndrew Thompson.Fn usb_close 7524eaae44dSAndrew Thompson.Fn usb_get_string 7534eaae44dSAndrew Thompson.Fn usb_get_string_simple 7544eaae44dSAndrew Thompson.Fn usb_get_descriptor_by_endpoint 7554eaae44dSAndrew Thompson.Fn usb_get_descriptor 7564eaae44dSAndrew Thompson.Fn usb_parse_descriptor 7574eaae44dSAndrew Thompson.Fn usb_parse_configuration 7584eaae44dSAndrew Thompson.Fn usb_destroy_configuration 7594eaae44dSAndrew Thompson.Fn usb_fetch_and_parse_descriptors 7604eaae44dSAndrew Thompson.Fn usb_bulk_write 7614eaae44dSAndrew Thompson.Fn usb_bulk_read 7624eaae44dSAndrew Thompson.Fn usb_interrupt_write 7634eaae44dSAndrew Thompson.Fn usb_interrupt_read 7644eaae44dSAndrew Thompson.Fn usb_control_msg 7654eaae44dSAndrew Thompson.Fn usb_set_configuration 7664eaae44dSAndrew Thompson.Fn usb_claim_interface 7674eaae44dSAndrew Thompson.Fn usb_release_interface 7684eaae44dSAndrew Thompson.Fn usb_set_altinterface 7694eaae44dSAndrew Thompson.Fn usb_resetep 7704eaae44dSAndrew Thompson.Fn usb_clear_halt 7714eaae44dSAndrew Thompson.Fn usb_reset 7724eaae44dSAndrew Thompson.Fn usb_strerror 7734eaae44dSAndrew Thompson.Fn usb_init 7744eaae44dSAndrew Thompson.Fn usb_set_debug 7754eaae44dSAndrew Thompson.Fn usb_find_busses 7764eaae44dSAndrew Thompson.Fn usb_find_devices 7774eaae44dSAndrew Thompson.Fn usb_device 7784eaae44dSAndrew Thompson.Fn usb_get_busses 779f1b5fa6eSHans Petter Selasky.Fn usb_check_connected 7804eb5923dSHans Petter Selasky.Fn usb_get_driver_np 7814eb5923dSHans Petter Selasky.Fn usb_detach_kernel_driver_np 7824eaae44dSAndrew Thompson.Sh SEE ALSO 783a5118bdfSAndrew Thompson.Xr libusb20 3 , 784c54c1f7cSAndrew Thompson.Xr usb 4 , 785c61f2561SHans Petter Selasky.Xr usbconfig 8 , 786c61f2561SHans Petter Selasky.Xr usbdump 8 787a5118bdfSAndrew Thompson.Pp 788882764c1SMateusz Piotrowski.Lk https://libusb.info/ 7894eaae44dSAndrew Thompson.Sh HISTORY 7904eaae44dSAndrew Thompson.Nm 791a5118bdfSAndrew Thompsonsupport first appeared in 792a5118bdfSAndrew Thompson.Fx 8.0 . 793