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*4c6bcffdSHans Petter Selasky.Dd January, 26, 2023 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" 50*4c6bcffdSHans Petter SelaskyCall this function before any other libusb v1.0 API function, to 51*4c6bcffdSHans Petter Selaskyinitialise a valid libusb v1.0 context. 52*4c6bcffdSHans Petter SelaskyIf the 53*4c6bcffdSHans Petter Selasky.Fa ctx 54*4c6bcffdSHans Petter Selaskyargument is non-NULL, a pointer to the libusb context is stored at 55*4c6bcffdSHans Petter Selaskythe given location. 56*4c6bcffdSHans Petter SelaskyThis function returns 0 upon success or LIBUSB_ERROR on failure. 57*4c6bcffdSHans Petter Selasky.Pp 58*4c6bcffdSHans Petter Selasky.Ft int 59*4c6bcffdSHans Petter Selasky.Fn libusb_init_context "libusb_context **ctx" "const struct libusb_init_option []" "int num_options" 60*4c6bcffdSHans Petter SelaskyCall this function before any other libusb v1.0 API function, to 61*4c6bcffdSHans Petter Selaskyinitialise a valid libusb v1.0 context. 62*4c6bcffdSHans Petter SelaskyIf the 63*4c6bcffdSHans Petter Selasky.Fa ctx 64*4c6bcffdSHans Petter Selaskyargument is non-NULL, a pointer to the libusb context is stored at 65*4c6bcffdSHans Petter Selaskythe given location. 66*4c6bcffdSHans Petter SelaskyAdditional options, like the USB debug level, may be given using the 67*4c6bcffdSHans Petter Selaskysecond and third argument. 68*4c6bcffdSHans Petter SelaskyIf no options are needed, simply use libusb_init(). 69*4c6bcffdSHans Petter SelaskyThis function returns 0 upon success or a LIBUSB_ERROR value on failure. 704eaae44dSAndrew Thompson.Pp 71a5118bdfSAndrew Thompson.Ft void 72a5118bdfSAndrew Thompson.Fn libusb_exit "libusb_context *ctx" 73c8c1f2ecSHans Petter SelaskyDeinitialise libusb. 74c8c1f2ecSHans Petter SelaskyMust be called at the end of the application. 7511867070SHans Petter SelaskyOther libusb routines may not be called after this function. 76a5118bdfSAndrew Thompson.Pp 7704391da3SKyle Evans.Ft int 7804391da3SKyle Evans.Fn libusb_has_capability "uint32_t capability" 7904391da3SKyle EvansThis function checks the runtime capabilities of 8004391da3SKyle Evans.Nm . 8104391da3SKyle EvansThis function will return non-zero if the given 8204391da3SKyle Evans.Fa capability 8304391da3SKyle Evansis supported, 0 if it is not supported. 8404391da3SKyle EvansThe valid values for 8504391da3SKyle Evans.Fa capability 8604391da3SKyle Evansare: 8704391da3SKyle Evans.Bl -tag -width LIBUSB_CAP -offset indent 8804391da3SKyle Evans.It Va LIBUSB_CAP_HAS_CAPABILITY 8904391da3SKyle Evans.Nm 9004391da3SKyle Evanssupports 9104391da3SKyle Evans.Fn libusb_has_capability . 9204391da3SKyle Evans.It Va LIBUSB_CAP_HAS_HOTPLUG 9304391da3SKyle Evans.Nm 9404391da3SKyle Evanssupports hotplug notifications. 9504391da3SKyle Evans.It Va LIBUSB_CAP_HAS_HID_ACCESS 9604391da3SKyle Evans.Nm 9704391da3SKyle Evanscan access HID devices without requiring user intervention. 9804391da3SKyle Evans.It Va LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER 9904391da3SKyle Evans.Nm 10004391da3SKyle Evanssupports detaching of the default USB driver with 10104391da3SKyle Evans.Fn libusb_detach_kernel_driver . 10204391da3SKyle Evans.El 10304391da3SKyle Evans.Pp 104698e791aSHans Petter Selasky.Ft const char * 105698e791aSHans Petter Selasky.Fn libusb_strerror "int code" 10611867070SHans Petter SelaskyGet the ASCII representation of the error given by the 107698e791aSHans Petter Selasky.Fa code 108698e791aSHans Petter Selaskyargument. 109c61f2561SHans Petter SelaskyThis function does not return NULL. 110c61f2561SHans Petter Selasky.Pp 111c61f2561SHans Petter Selasky.Ft const char * 112c61f2561SHans Petter Selasky.Fn libusb_error_name "int code" 113c61f2561SHans Petter SelaskyGet the ASCII representation of the error enum given by the 114c61f2561SHans Petter Selasky.Fa code 115c61f2561SHans Petter Selaskyargument. 116c61f2561SHans Petter SelaskyThis function does not return NULL. 117698e791aSHans Petter Selasky.Pp 118a5118bdfSAndrew Thompson.Ft void 119a5118bdfSAndrew Thompson.Fn libusb_set_debug "libusb_context *ctx" "int level" 12011867070SHans Petter SelaskySet the debug level to 12111867070SHans Petter Selasky.Fa level . 122a5118bdfSAndrew Thompson.Pp 123a5118bdfSAndrew Thompson.Ft ssize_t 124a5118bdfSAndrew Thompson.Fn libusb_get_device_list "libusb_context *ctx" "libusb_device ***list" 12511867070SHans Petter SelaskyPopulate 126a5118bdfSAndrew Thompson.Fa list 12711867070SHans Petter Selaskywith the list of usb devices available, adding a reference to each 12811867070SHans Petter Selaskydevice in the list. 12911867070SHans Petter SelaskyAll the list entries created by this 13011867070SHans Petter Selaskyfunction must have their reference counter 13111867070SHans Petter Selaskydecremented when you are done with them, 13211867070SHans Petter Selaskyand the list itself must be freed. 133c8c1f2ecSHans Petter SelaskyThis 13411867070SHans Petter Selaskyfunction returns the number of devices in the list or a LIBUSB_ERROR code. 135a5118bdfSAndrew Thompson.Pp 136a5118bdfSAndrew Thompson.Ft void 137a5118bdfSAndrew Thompson.Fn libusb_free_device_list "libusb_device **list" "int unref_devices" 138c8c1f2ecSHans Petter SelaskyFree the list of devices discovered by libusb_get_device_list. 139c8c1f2ecSHans Petter SelaskyIf 140a5118bdfSAndrew Thompson.Fa unref_device 14111867070SHans Petter Selaskyis set to 1 all devices in the list have their reference 14211867070SHans Petter Selaskycounter decremented once. 143a5118bdfSAndrew Thompson.Pp 144a5118bdfSAndrew Thompson.Ft uint8_t 145a5118bdfSAndrew Thompson.Fn libusb_get_bus_number "libusb_device *dev" 146a5118bdfSAndrew ThompsonReturns the number of the bus contained by the device 147a5118bdfSAndrew Thompson.Fa dev . 148a5118bdfSAndrew Thompson.Pp 1490f2c7066SHans Petter Selasky.Ft uint8_t 1500f2c7066SHans Petter Selasky.Fn libusb_get_port_number "libusb_device *dev" 1510f2c7066SHans Petter SelaskyReturns the port number which the device given by 1520f2c7066SHans Petter Selasky.Fa dev 1530f2c7066SHans Petter Selaskyis attached to. 1540f2c7066SHans Petter Selasky.Pp 1555906bf49SEd Maste.Ft int 156a9205626SEd Maste.Fn libusb_get_port_numbers "libusb_device *dev" "uint8_t *buf" "uint8_t bufsize" 1575906bf49SEd MasteStores, in the buffer 1585906bf49SEd Maste.Fa buf 1595906bf49SEd Masteof size 1605906bf49SEd Maste.Fa bufsize , 1615906bf49SEd Mastethe list of all port numbers from root for the device 1625906bf49SEd Maste.Fa dev . 1635906bf49SEd Maste.Pp 164a9205626SEd Maste.Ft int 165a9205626SEd Maste.Fn libusb_get_port_path "libusb_context *ctx" "libusb_device *dev" "uint8_t *buf" "uint8_t bufsize" 166a9205626SEd MasteDeprecated function equivalent to libusb_get_port_numbers. 167a9205626SEd Maste.Pp 168a5118bdfSAndrew Thompson.Ft uint8_t 169a5118bdfSAndrew Thompson.Fn libusb_get_device_address "libusb_device *dev" 170ca96e26aSHans Petter SelaskyReturns the device_address contained by the device 171a5118bdfSAndrew Thompson.Fa dev . 172a5118bdfSAndrew Thompson.Pp 173ca96e26aSHans Petter Selasky.Ft enum libusb_speed 174ca96e26aSHans Petter Selasky.Fn libusb_get_device_speed "libusb_device *dev" 175ca96e26aSHans Petter SelaskyReturns the wire speed at which the device is connected. 176ca96e26aSHans Petter SelaskySee the LIBUSB_SPEED_XXX enums for more information. 177ca96e26aSHans Petter SelaskyLIBUSB_SPEED_UNKNOWN is returned in case of unknown wire speed. 178ca96e26aSHans Petter Selasky.Pp 179a5118bdfSAndrew Thompson.Ft int 180a5118bdfSAndrew Thompson.Fn libusb_get_max_packet_size "libusb_device *dev" "unsigned char endpoint" 181ca96e26aSHans Petter SelaskyReturns the wMaxPacketSize value on success, LIBUSB_ERROR_NOT_FOUND if the 182a5118bdfSAndrew Thompsonendpoint does not exist and LIBUSB_ERROR_OTHERS on other failure. 183a5118bdfSAndrew Thompson.Pp 184748205a3SHans Petter Selasky.Ft int 185748205a3SHans Petter Selasky.Fn libusb_get_max_iso_packet_size "libusb_device *dev" "unsigned char endpoint" 186748205a3SHans Petter SelaskyReturns the packet size multiplied by the packet multiplier on success, 187748205a3SHans Petter SelaskyLIBUSB_ERROR_NOT_FOUND if the endpoint does not exist and 188748205a3SHans Petter SelaskyLIBUSB_ERROR_OTHERS on other failure. 189748205a3SHans Petter Selasky.Pp 190a5118bdfSAndrew Thompson.Ft libusb_device * 191a5118bdfSAndrew Thompson.Fn libusb_ref_device "libusb_device *dev" 192a5118bdfSAndrew ThompsonIncrement the reference counter of the device 193a5118bdfSAndrew Thompson.Fa dev . 194a5118bdfSAndrew Thompson.Pp 195a5118bdfSAndrew Thompson.Ft void 196a5118bdfSAndrew Thompson.Fn libusb_unref_device "libusb_device *dev" 197a5118bdfSAndrew ThompsonDecrement the reference counter of the device 198a5118bdfSAndrew Thompson.Fa dev . 199a5118bdfSAndrew Thompson.Pp 200a5118bdfSAndrew Thompson.Ft int 201a5118bdfSAndrew Thompson.Fn libusb_open "libusb_device *dev" "libusb_device_handle **devh" 202c8c1f2ecSHans Petter SelaskyOpen a device and obtain a device_handle. 203c8c1f2ecSHans Petter SelaskyReturns 0 on success, 20411867070SHans Petter SelaskyLIBUSB_ERROR_NO_MEM on memory allocation problems, LIBUSB_ERROR_ACCESS 20511867070SHans Petter Selaskyon permissions problems, LIBUSB_ERROR_NO_DEVICE if the device has been 20611867070SHans Petter Selaskydisconnected and a LIBUSB_ERROR code on other errors. 207a5118bdfSAndrew Thompson.Pp 208a5118bdfSAndrew Thompson.Ft libusb_device_handle * 209a5118bdfSAndrew Thompson.Fn libusb_open_device_with_vid_pid "libusb_context *ctx" "uint16_t vid" "uint16_t pid" 21011867070SHans Petter SelaskyA convenience function to open a device by vendor and product IDs 211a5118bdfSAndrew Thompson.Fa vid 2124eaae44dSAndrew Thompsonand 213a5118bdfSAndrew Thompson.Fa pid . 214ca96e26aSHans Petter SelaskyReturns NULL on error. 2154eaae44dSAndrew Thompson.Pp 216a5118bdfSAndrew Thompson.Ft void 217a5118bdfSAndrew Thompson.Fn libusb_close "libusb_device_handle *devh" 218a5118bdfSAndrew ThompsonClose a device handle. 2194eaae44dSAndrew Thompson.Pp 220a5118bdfSAndrew Thompson.Ft libusb_device * 221ca96e26aSHans Petter Selasky.Fn libusb_get_device "libusb_device_handle *devh" 222ca96e26aSHans Petter SelaskyGet the device contained by devh. 223ca96e26aSHans Petter SelaskyReturns NULL on error. 2244eaae44dSAndrew Thompson.Pp 225a5118bdfSAndrew Thompson.Ft int 226a5118bdfSAndrew Thompson.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config" 227a3fb6da9SGlen BarberReturns the value of the current configuration. 228c8c1f2ecSHans Petter SelaskyReturns 0 229a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected 230a5118bdfSAndrew Thompsonand a LIBUSB_ERROR code on error. 2314eaae44dSAndrew Thompson.Pp 232a5118bdfSAndrew Thompson.Ft int 233a5118bdfSAndrew Thompson.Fn libusb_set_configuration "libusb_device_handle *devh" "int config" 23411867070SHans Petter SelaskySet the active configuration to 235a5118bdfSAndrew Thompson.Fa config 236a5118bdfSAndrew Thompsonfor the device contained by 237a5118bdfSAndrew Thompson.Fa devh . 238ca96e26aSHans Petter SelaskyThis function returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested 239a5118bdfSAndrew Thompsonconfiguration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently 240a5118bdfSAndrew Thompsonclaimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a 241a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 2424eaae44dSAndrew Thompson.Pp 243a5118bdfSAndrew Thompson.Ft int 244a5118bdfSAndrew Thompson.Fn libusb_claim_interface "libusb_device_handle *devh" "int interface_number" 245a5118bdfSAndrew ThompsonClaim an interface in a given libusb_handle 246a5118bdfSAndrew Thompson.Fa devh . 247c8c1f2ecSHans Petter SelaskyThis is a non-blocking function. 24811867070SHans Petter SelaskyIt returns 0 on success, LIBUSB_ERROR_NOT_FOUND 249a5118bdfSAndrew Thompsonif the requested interface does not exist, LIBUSB_ERROR_BUSY if a program or 250a5118bdfSAndrew Thompsondriver has claimed the interface, LIBUSB_ERROR_NO_DEVICE if the device has 251a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure. 2524eaae44dSAndrew Thompson.Pp 253a5118bdfSAndrew Thompson.Ft int 254a5118bdfSAndrew Thompson.Fn libusb_release_interface "libusb_device_handle *devh" "int interface_number" 25511867070SHans Petter SelaskyThis function releases an interface. 25611867070SHans Petter SelaskyAll the claimed interfaces on a device must be released 25711867070SHans Petter Selaskybefore closing the device. 258c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the 259799162a6SJoel Dahlinterface was not claimed, LIBUSB_ERROR_NO_DEVICE if the device has been 260a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR on failure. 2614eaae44dSAndrew Thompson.Pp 262a5118bdfSAndrew Thompson.Ft int 263a5118bdfSAndrew Thompson.Fn libusb_set_interface_alt_setting "libusb_device_handle *dev" "int interface_number" "int alternate_setting" 264c8c1f2ecSHans Petter SelaskyActivate an alternate setting for an interface. 265c8c1f2ecSHans Petter SelaskyReturns 0 on success, 266a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if the interface was not claimed or the requested 267a5118bdfSAndrew Thompsonsetting does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been 26811867070SHans Petter Selaskydisconnected and a LIBUSB_ERROR code on failure. 2694eaae44dSAndrew Thompson.Pp 270a5118bdfSAndrew Thompson.Ft int 271a5118bdfSAndrew Thompson.Fn libusb_clear_halt "libusb_device_handle *devh" "unsigned char endpoint" 272c8c1f2ecSHans Petter SelaskyClear an halt/stall for a endpoint. 273c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND 274a5118bdfSAndrew Thompsonif the endpoint does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been 275a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on failure. 2764eaae44dSAndrew Thompson.Pp 277a5118bdfSAndrew Thompson.Ft int 278a5118bdfSAndrew Thompson.Fn libusb_reset_device "libusb_device_handle *devh" 279c8c1f2ecSHans Petter SelaskyPerform an USB port reset for an usb device. 280c8c1f2ecSHans Petter SelaskyReturns 0 on success, 281a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if re-enumeration is required or if the device has 282a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure. 2834eaae44dSAndrew Thompson.Pp 284a5118bdfSAndrew Thompson.Ft int 285f1b5fa6eSHans Petter Selasky.Fn libusb_check_connected "libusb_device_handle *devh" 28611867070SHans Petter SelaskyTest if the USB device is still connected. 287c8c1f2ecSHans Petter SelaskyReturns 0 on success, 28811867070SHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if it has been disconnected and a LIBUSB_ERROR 289f1b5fa6eSHans Petter Selaskycode on failure. 290f1b5fa6eSHans Petter Selasky.Pp 291f1b5fa6eSHans Petter Selasky.Ft int 292a5118bdfSAndrew Thompson.Fn libusb_kernel_driver_active "libusb_device_handle *devh" "int interface" 293c8c1f2ecSHans Petter SelaskyDetermine if a driver is active on a interface. 2944d2472aaSHans Petter SelaskyReturns 0 if no kernel driver is active 2954d2472aaSHans Petter Selaskyand 1 if a kernel driver is active, LIBUSB_ERROR_NO_DEVICE 29611867070SHans Petter Selaskyif the device has been disconnected and a LIBUSB_ERROR code on failure. 2974eaae44dSAndrew Thompson.Pp 298a5118bdfSAndrew Thompson.Ft int 299698e791aSHans Petter Selasky.Fn libusb_get_driver "libusb_device_handle *devh" "int interface" "char *name" "int namelen" 300698e791aSHans Petter Selaskyor 301698e791aSHans Petter Selasky.Ft int 302698e791aSHans Petter Selasky.Fn libusb_get_driver_np "libusb_device_handle *devh" "int interface" "char *name" "int namelen" 30311867070SHans Petter SelaskyCopy the name of the driver attached to the given 304698e791aSHans Petter Selasky.Fa device 305698e791aSHans Petter Selaskyand 306698e791aSHans Petter Selasky.Fa interface 30711867070SHans Petter Selaskyinto the buffer 308698e791aSHans Petter Selasky.Fa name 30911867070SHans Petter Selaskyof length 310698e791aSHans Petter Selasky.Fa namelen . 311698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver is attached 312698e791aSHans Petter Selaskyto the given interface and LIBUSB_ERROR_INVALID_PARAM if the interface does 313698e791aSHans Petter Selaskynot exist. 314698e791aSHans Petter SelaskyThis function is non-portable. 315698e791aSHans Petter SelaskyThe buffer pointed to by 316698e791aSHans Petter Selasky.Fa name 317698e791aSHans Petter Selaskyis only zero terminated on success. 318698e791aSHans Petter Selasky.Pp 319698e791aSHans Petter Selasky.Ft int 320a5118bdfSAndrew Thompson.Fn libusb_detach_kernel_driver "libusb_device_handle *devh" "int interface" 321698e791aSHans Petter Selaskyor 322698e791aSHans Petter Selasky.Ft int 323698e791aSHans Petter Selasky.Fn libusb_detach_kernel_driver_np "libusb_device_handle *devh" "int interface" 324698e791aSHans Petter SelaskyDetach a kernel driver from an interface. 32511867070SHans Petter SelaskyThis is needed to claim an interface already claimed by a kernel driver. 326698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver was active, 327c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, 328c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if the device has been disconnected 329c8c1f2ecSHans Petter Selaskyand a LIBUSB_ERROR code on failure. 330c8c1f2ecSHans Petter SelaskyThis function is non-portable. 3314eaae44dSAndrew Thompson.Pp 332a5118bdfSAndrew Thompson.Ft int 333a5118bdfSAndrew Thompson.Fn libusb_attach_kernel_driver "libusb_device_handle *devh" "int interface" 33411867070SHans Petter SelaskyRe-attach an interface kernel driver that was previously detached. 335c8c1f2ecSHans Petter SelaskyReturns 0 on success, 336c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, 337c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE 33811867070SHans Petter Selaskyif the device has been disconnected, LIBUSB_ERROR_BUSY if the driver cannot be 339a5118bdfSAndrew Thompsonattached because the interface is claimed by a program or driver and a 340a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 3415b40d960SHans Petter Selasky.Pp 3425b40d960SHans Petter Selasky.Ft int 3435b40d960SHans Petter Selasky.Fn libusb_set_auto_detach_kernel_driver "libusb_device_handle *devh" "int enable" 3445b40d960SHans Petter SelaskyThis function enables automatic kernel interface driver detach when an 3455b40d960SHans Petter Selaskyinterface is claimed. 3465b40d960SHans Petter SelaskyWhen the interface is restored the kernel driver is allowed to be re-attached. 3475b40d960SHans Petter SelaskyIf the 3485b40d960SHans Petter Selasky.Fa enable 3495b40d960SHans Petter Selaskyargument is non-zero the feature is enabled. 3505b40d960SHans Petter SelaskyElse disabled. 3515b40d960SHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on 3525b40d960SHans Petter Selaskyfailure. 353a5118bdfSAndrew Thompson.Sh USB DESCRIPTORS 354a5118bdfSAndrew Thompson.Ft int 355a5118bdfSAndrew Thompson.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc" 356a5118bdfSAndrew ThompsonGet the USB device descriptor for the device 357a5118bdfSAndrew Thompson.Fa dev . 358c8c1f2ecSHans Petter SelaskyThis is a non-blocking function. 359c8c1f2ecSHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on 360a5118bdfSAndrew Thompsonfailure. 3614eaae44dSAndrew Thompson.Pp 362a5118bdfSAndrew Thompson.Ft int 363cb0df9e8SHans Petter Selasky.Fn libusb_get_active_config_descriptor "libusb_device *dev" "struct libusb_config_descriptor **config" 364c8c1f2ecSHans Petter SelaskyGet the USB configuration descriptor for the active configuration. 365c8c1f2ecSHans Petter SelaskyReturns 0 on 36611867070SHans Petter Selaskysuccess, LIBUSB_ERROR_NOT_FOUND if the device is in 36711867070SHans Petter Selaskyan unconfigured state 36811867070SHans Petter Selaskyand a LIBUSB_ERROR code on error. 3694eaae44dSAndrew Thompson.Pp 370a5118bdfSAndrew Thompson.Ft int 371a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor "libusb_device *dev" "uint8_t config_index" "libusb_config_descriptor **config" 37211867070SHans Petter SelaskyGet a USB configuration descriptor based on its index 373a5118bdfSAndrew Thompson.Fa idx . 374a5118bdfSAndrew ThompsonReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist 37511867070SHans Petter Selaskyand a LIBUSB_ERROR code on error. 376545b01adSAndrew Thompson.Pp 377a5118bdfSAndrew Thompson.Ft int 378a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor_by_value "libusb_device *dev" "uint8 bConfigurationValue" "libusb_config_descriptor **config" 379c8c1f2ecSHans Petter SelaskyGet a USB configuration descriptor with a specific bConfigurationValue. 380c8c1f2ecSHans Petter SelaskyThis is 38111867070SHans Petter Selaskya non-blocking function which does not send a request through the device. 382c8c1f2ecSHans Petter SelaskyReturns 0 383c8c1f2ecSHans Petter Selaskyon success, LIBUSB_ERROR_NOT_FOUND if the configuration 38411867070SHans Petter Selaskydoes not exist and a 385a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 3864eaae44dSAndrew Thompson.Pp 387a5118bdfSAndrew Thompson.Ft void 388390065b1SAlfred Perlstein.Fn libusb_free_config_descriptor "libusb_config_descriptor *config" 389a5118bdfSAndrew ThompsonFree a configuration descriptor. 3904eaae44dSAndrew Thompson.Pp 391a5118bdfSAndrew Thompson.Ft int 39278ed0e49SHans Petter Selasky.Fn libusb_get_string_descriptor "libusb_device_handle *devh" "uint8_t desc_idx" "uint16_t langid" "unsigned char *data" "int length" 39378ed0e49SHans Petter SelaskyRetrieve a string descriptor in raw format. 39478ed0e49SHans Petter SelaskyReturns the number of bytes actually transferred on success 39578ed0e49SHans Petter Selaskyor a negative LIBUSB_ERROR code on failure. 39678ed0e49SHans Petter Selasky.Pp 39778ed0e49SHans Petter Selasky.Ft int 398a5118bdfSAndrew Thompson.Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length" 39911867070SHans Petter SelaskyRetrieve a string descriptor in C style ASCII. 40011867070SHans Petter SelaskyReturns the positive number of bytes in the resulting ASCII string 401c8c1f2ecSHans Petter Selaskyon success and a LIBUSB_ERROR code on failure. 4024eaae44dSAndrew Thompson.Pp 4034c0392e6SHans Petter Selasky.Ft int 4044c0392e6SHans Petter Selasky.Fn libusb_parse_ss_endpoint_comp "const void *buf" "int len" "libusb_ss_endpoint_companion_descriptor **ep_comp" 4054c0392e6SHans Petter SelaskyThis function parses the USB 3.0 endpoint companion descriptor in host endian format pointed to by 4064c0392e6SHans Petter Selasky.Fa buf 4074c0392e6SHans Petter Selaskyand having a length of 4084c0392e6SHans Petter Selasky.Fa len . 4094c0392e6SHans Petter SelaskyTypically these arguments are the extra and extra_length fields of the 4104c0392e6SHans Petter Selaskyendpoint descriptor. 4114c0392e6SHans Petter SelaskyOn success the pointer to resulting descriptor is stored at the location given by 4124c0392e6SHans Petter Selasky.Fa ep_comp . 4134c0392e6SHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 4144c0392e6SHans Petter SelaskyOn success the parsed USB 3.0 endpoint companion descriptor must be 4154c0392e6SHans Petter Selaskyfreed using the libusb_free_ss_endpoint_comp function. 4164c0392e6SHans Petter Selasky.Pp 4174c0392e6SHans Petter Selasky.Ft void 4184c0392e6SHans Petter Selasky.Fn libusb_free_ss_endpoint_comp "libusb_ss_endpoint_companion_descriptor *ep_comp" 41937d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed USB 3.0 endpoint companion descriptor given by 42037d0636aSHans Petter Selasky.Fa ep_comp . 42137d0636aSHans Petter Selasky.Pp 42237d0636aSHans Petter Selasky.Ft int 42337d0636aSHans 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" 42437d0636aSHans Petter SelaskyThis function finds and parses the USB 3.0 endpoint companion descriptor given by 42537d0636aSHans Petter Selasky.Fa endpoint . 42637d0636aSHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 42737d0636aSHans Petter SelaskyOn success the parsed USB 3.0 endpoint companion descriptor must be 42837d0636aSHans Petter Selaskyfreed using the libusb_free_ss_endpoint_companion_descriptor function. 42937d0636aSHans Petter Selasky.Pp 43037d0636aSHans Petter Selasky.Ft void 43137d0636aSHans Petter Selasky.Fn libusb_free_ss_endpoint_companion_descriptor "struct libusb_ss_endpoint_companion_descriptor *ep_comp" 43237d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed USB 3.0 endpoint companion descriptor given by 43337d0636aSHans Petter Selasky.Fa ep_comp . 43437d0636aSHans Petter Selasky.Pp 43537d0636aSHans Petter Selasky.Ft int 43637d0636aSHans Petter Selasky.Fn libusb_get_bos_descriptor "libusb_device_handle *handle" "struct libusb_bos_descriptor **bos" 43737d0636aSHans Petter SelaskyThis function queries the USB device given by 43837d0636aSHans Petter Selasky.Fa handle 43937d0636aSHans Petter Selaskyand stores a pointer to a parsed BOS descriptor into 44037d0636aSHans Petter Selasky.Fa bos . 44137d0636aSHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 44237d0636aSHans Petter SelaskyOn success the parsed BOS descriptor must be 44337d0636aSHans Petter Selaskyfreed using the libusb_free_bos_descriptor function. 4444c0392e6SHans Petter Selasky.Pp 4454c0392e6SHans Petter Selasky.Ft int 4464c0392e6SHans Petter Selasky.Fn libusb_parse_bos_descriptor "const void *buf" "int len" "libusb_bos_descriptor **bos" 4474c0392e6SHans Petter SelaskyThis function parses a Binary Object Store, BOS, descriptor into host endian format pointed to by 4484c0392e6SHans Petter Selasky.Fa buf 4494c0392e6SHans Petter Selaskyand having a length of 4504c0392e6SHans Petter Selasky.Fa len . 4514c0392e6SHans Petter SelaskyOn success the pointer to resulting descriptor is stored at the location given by 4524c0392e6SHans Petter Selasky.Fa bos . 4534c0392e6SHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 4544c0392e6SHans Petter SelaskyOn success the parsed BOS descriptor must be freed using the 4554c0392e6SHans Petter Selaskylibusb_free_bos_descriptor function. 4564c0392e6SHans Petter Selasky.Pp 4574c0392e6SHans Petter Selasky.Ft void 4584c0392e6SHans Petter Selasky.Fn libusb_free_bos_descriptor "libusb_bos_descriptor *bos" 45937d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed BOS descriptor given by 46037d0636aSHans Petter Selasky.Fa bos . 46137d0636aSHans Petter Selasky.Pp 46237d0636aSHans Petter Selasky.Ft int 46337d0636aSHans 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" 46437d0636aSHans Petter SelaskyThis function parses the USB 2.0 extension 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 usb_2_0_extension . 46837d0636aSHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 46937d0636aSHans Petter SelaskyOn success the parsed USB 2.0 extension descriptor must be freed using the 47037d0636aSHans Petter Selaskylibusb_free_usb_2_0_extension_descriptor function. 47137d0636aSHans Petter Selasky.Pp 47237d0636aSHans Petter Selasky.Ft void 47337d0636aSHans Petter Selasky.Fn libusb_free_usb_2_0_extension_descriptor "struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension" 47437d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed USB 2.0 extension descriptor given by 47537d0636aSHans Petter Selasky.Fa usb_2_0_extension . 47637d0636aSHans Petter Selasky.Pp 47737d0636aSHans Petter Selasky.Ft int 47837d0636aSHans 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" 47937d0636aSHans Petter SelaskyThis function parses the SuperSpeed device capability 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 ss_usb_device_capability . 48337d0636aSHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 48437d0636aSHans Petter SelaskyOn success the parsed SuperSpeed device capability descriptor must be freed using the 48537d0636aSHans Petter Selaskylibusb_free_ss_usb_device_capability_descriptor function. 48637d0636aSHans Petter Selasky.Pp 48737d0636aSHans Petter Selasky.Ft void 48837d0636aSHans Petter Selasky.Fn libusb_free_ss_usb_device_capability_descriptor "struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_capability" 48937d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed SuperSpeed device capability descriptor given by 49037d0636aSHans Petter Selasky.Fa ss_usb_device_capability . 49137d0636aSHans Petter Selasky.Pp 49237d0636aSHans Petter Selasky.Ft int 49337d0636aSHans 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" 49437d0636aSHans Petter SelaskyThis function parses the container ID descriptor from the descriptor given by 49537d0636aSHans Petter Selasky.Fa dev_cap 49637d0636aSHans Petter Selaskyand stores a pointer to the parsed descriptor into 49737d0636aSHans Petter Selasky.Fa container_id . 49837d0636aSHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 49937d0636aSHans Petter SelaskyOn success the parsed container ID descriptor must be freed using the 50037d0636aSHans Petter Selaskylibusb_free_container_id_descriptor function. 50137d0636aSHans Petter Selasky.Pp 50237d0636aSHans Petter Selasky.Ft void 50337d0636aSHans Petter Selasky.Fn libusb_free_container_id_descriptor "struct libusb_container_id_descriptor *container_id" 50437d0636aSHans Petter SelaskyThis function is NULL safe and frees a parsed container ID descriptor given by 50537d0636aSHans Petter Selasky.Fa container_id . 506a5118bdfSAndrew Thompson.Sh USB ASYNCHRONOUS I/O 507a5118bdfSAndrew Thompson.Ft struct libusb_transfer * 508a5118bdfSAndrew Thompson.Fn libusb_alloc_transfer "int iso_packets" 50911867070SHans Petter SelaskyAllocate a transfer with the number of isochronous packet descriptors 51011867070SHans Petter Selaskyspecified by 51111867070SHans Petter Selasky.Fa iso_packets . 512ca96e26aSHans Petter SelaskyReturns NULL on error. 5134eaae44dSAndrew Thompson.Pp 514a5118bdfSAndrew Thompson.Ft void 515a5118bdfSAndrew Thompson.Fn libusb_free_transfer "struct libusb_transfer *tr" 516a5118bdfSAndrew ThompsonFree a transfer. 5174eaae44dSAndrew Thompson.Pp 518a5118bdfSAndrew Thompson.Ft int 519a5118bdfSAndrew Thompson.Fn libusb_submit_transfer "struct libusb_transfer *tr" 520ca96e26aSHans Petter SelaskyThis function will submit a transfer and returns immediately. 521c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NO_DEVICE if 52211867070SHans Petter Selaskythe device has been disconnected and a 523a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure. 5244eaae44dSAndrew Thompson.Pp 525a5118bdfSAndrew Thompson.Ft int 526a5118bdfSAndrew Thompson.Fn libusb_cancel_transfer "struct libusb_transfer *tr" 52711867070SHans Petter SelaskyThis function asynchronously cancels a transfer. 52811867070SHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on failure. 529a5118bdfSAndrew Thompson.Sh USB SYNCHRONOUS I/O 530a5118bdfSAndrew Thompson.Ft int 531698e791aSHans 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" 532ca96e26aSHans Petter SelaskyPerform a USB control transfer. 533ca96e26aSHans Petter SelaskyReturns the actual number of bytes 53411867070SHans Petter Selaskytransferred on success, in the range from and including zero up to and 535c865d740SHans Petter Selaskyincluding 536892f4806SHans Petter Selasky.Fa wLength . 53711867070SHans Petter SelaskyOn error a LIBUSB_ERROR code is returned, for example 53811867070SHans Petter SelaskyLIBUSB_ERROR_TIMEOUT if the transfer timed out, LIBUSB_ERROR_PIPE if the 539c865d740SHans Petter Selaskycontrol request was not supported, LIBUSB_ERROR_NO_DEVICE if the 54011867070SHans Petter Selaskydevice has been disconnected and another LIBUSB_ERROR code on other failures. 54111867070SHans Petter SelaskyThe LIBUSB_ERROR codes are all negative. 5424eaae44dSAndrew Thompson.Pp 543a5118bdfSAndrew Thompson.Ft int 544a5118bdfSAndrew Thompson.Fn libusb_bulk_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout" 545892f4806SHans Petter SelaskyPerform an USB bulk transfer. 546892f4806SHans Petter SelaskyA timeout value of zero means no timeout. 547892f4806SHans Petter SelaskyThe timeout value is given in milliseconds. 548892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT 54911867070SHans Petter Selaskyif the transfer timed out, LIBUSB_ERROR_PIPE if the control request was not 550a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data, 551a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 55211867070SHans Petter Selaskya LIBUSB_ERROR code on other failure. 5534eaae44dSAndrew Thompson.Pp 554a5118bdfSAndrew Thompson.Ft int 555a5118bdfSAndrew Thompson.Fn libusb_interrupt_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout" 556892f4806SHans Petter SelaskyPerform an USB Interrupt transfer. 557892f4806SHans Petter SelaskyA timeout value of zero means no timeout. 558892f4806SHans Petter SelaskyThe timeout value is given in milliseconds. 559892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT 56011867070SHans Petter Selaskyif the transfer timed out, LIBUSB_ERROR_PIPE if the control request was not 561a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data, 562a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 56311867070SHans Petter Selaskya LIBUSB_ERROR code on other failure. 564a0c93fa3SHans Petter Selasky.Sh USB STREAMS SUPPORT 565a0c93fa3SHans Petter Selasky.Ft int 566a0c93fa3SHans Petter Selasky.Fn libusb_alloc_streams "libusb_device_handle *dev" "uint32_t num_streams" "unsigned char *endpoints" "int num_endpoints" 567a0c93fa3SHans Petter SelaskyThis function verifies that the given number of streams using the 568a0c93fa3SHans Petter Selaskygiven number of endpoints is allowed and allocates the resources 569a0c93fa3SHans Petter Selaskyneeded to use so-called USB streams. 570a0c93fa3SHans Petter SelaskyCurrently only a single stream per endpoint is supported to simplify 571a0c93fa3SHans Petter Selaskythe internals of LibUSB. 572a0c93fa3SHans Petter SelaskyThis function returns 0 on success or a LIBUSB_ERROR code on failure. 573a0c93fa3SHans Petter Selasky.Pp 574a0c93fa3SHans Petter Selasky.Ft int 575a0c93fa3SHans Petter Selasky.Fn libusb_free_streams "libusb_device_handle *dev" "unsigned char *endpoints" "int num_endpoints" 576a0c93fa3SHans Petter SelaskyThis function release resources needed for streams usage. 577a0c93fa3SHans Petter SelaskyReturns 0 on success or a LIBUSB_ERROR code on failure. 578a0c93fa3SHans Petter Selasky.Pp 579a0c93fa3SHans Petter Selasky.Ft void 580a0c93fa3SHans Petter Selasky.Fn libusb_transfer_set_stream_id "struct libusb_transfer *transfer" "uint32_t stream_id" 581a0c93fa3SHans Petter SelaskyThis function sets the stream ID for the given USB transfer. 582a0c93fa3SHans Petter Selasky.Pp 583a0c93fa3SHans Petter Selasky.Ft uint32_t 584a0c93fa3SHans Petter Selasky.Fn libusb_transfer_get_stream_id "struct libusb_transfer *transfer" 585a0c93fa3SHans Petter SelaskyThis function returns the stream ID for the given USB transfer. 586a0c93fa3SHans Petter SelaskyIf no stream ID is used a value of zero is returned. 587a5118bdfSAndrew Thompson.Sh USB EVENTS 588a5118bdfSAndrew Thompson.Ft int 589a5118bdfSAndrew Thompson.Fn libusb_try_lock_events "libusb_context *ctx" 590ca96e26aSHans Petter SelaskyTry to acquire the event handling lock. 591ca96e26aSHans Petter SelaskyReturns 0 if the lock was obtained and 1 if not. 5924eaae44dSAndrew Thompson.Pp 593a5118bdfSAndrew Thompson.Ft void 594a5118bdfSAndrew Thompson.Fn libusb_lock_events "libusb_context *ctx" 595c8c1f2ecSHans Petter SelaskyAcquire the event handling lock. 596c8c1f2ecSHans Petter SelaskyThis function is blocking. 5974eaae44dSAndrew Thompson.Pp 598a5118bdfSAndrew Thompson.Ft void 599a5118bdfSAndrew Thompson.Fn libusb_unlock_events "libusb_context *ctx" 600c8c1f2ecSHans Petter SelaskyRelease the event handling lock. 601c8c1f2ecSHans Petter SelaskyThis will wake up any thread blocked 60211867070SHans Petter Selaskyon 603d284271aSJoel Dahl.Fn libusb_wait_for_event . 6044eaae44dSAndrew Thompson.Pp 605a5118bdfSAndrew Thompson.Ft int 606a5118bdfSAndrew Thompson.Fn libusb_event_handling_ok "libusb_context *ctx" 607c8c1f2ecSHans Petter SelaskyDetermine if it still OK for this thread to be doing event handling. 608c8c1f2ecSHans Petter SelaskyReturns 1 609c8c1f2ecSHans Petter Selaskyif event handling can start or continue. 610c8c1f2ecSHans Petter SelaskyReturns 0 if this thread must give up 611a5118bdfSAndrew Thompsonthe events lock. 6124eaae44dSAndrew Thompson.Pp 613a5118bdfSAndrew Thompson.Ft int 614a5118bdfSAndrew Thompson.Fn libusb_event_handler_active "libusb_context *ctx" 615c8c1f2ecSHans Petter SelaskyDetermine if an active thread is handling events. 61611867070SHans Petter SelaskyReturns 1 if there is a thread handling events and 0 if there 617a5118bdfSAndrew Thompsonare no threads currently handling events. 6184eaae44dSAndrew Thompson.Pp 619a5118bdfSAndrew Thompson.Ft void 620aa87aa52SHans Petter Selasky.Fn libusb_interrupt_event_handler "libusb_context *ctx" 621aa87aa52SHans Petter SelaskyCauses the 622aa87aa52SHans Petter Selasky.Fn libusb_handle_events 623aa87aa52SHans Petter Selaskyfamiliy of functions to return to the caller one time. 624aa87aa52SHans Petter SelaskyThe 625aa87aa52SHans Petter Selasky.Fn libusb_handle_events 626aa87aa52SHans Petter Selaskyfunctions may be called again after calling this function. 627aa87aa52SHans Petter Selasky.Pp 628aa87aa52SHans Petter Selasky.Ft void 629a5118bdfSAndrew Thompson.Fn libusb_lock_event_waiters "libusb_context *ctx" 630c8c1f2ecSHans Petter SelaskyAcquire the event_waiters lock. 63111867070SHans Petter SelaskyThis lock is designed to be obtained in the 632a5118bdfSAndrew Thompsonsituation where you want to be aware when events are completed, but some other 633882764c1SMateusz Piotrowskithread is event handling so calling 634882764c1SMateusz Piotrowski.Fn libusb_handle_events 635882764c1SMateusz Piotrowskiis not allowed. 636545b01adSAndrew Thompson.Pp 637a5118bdfSAndrew Thompson.Ft void 638a5118bdfSAndrew Thompson.Fn libusb_unlock_event_waiters "libusb_context *ctx" 639a5118bdfSAndrew ThompsonRelease the event_waiters lock. 6404eaae44dSAndrew Thompson.Pp 641a5118bdfSAndrew Thompson.Ft int 642a5118bdfSAndrew Thompson.Fn libusb_wait_for_event "libusb_context *ctx" "struct timeval *tv" 643c8c1f2ecSHans Petter SelaskyWait for another thread to signal completion of an event. 644c8c1f2ecSHans Petter SelaskyMust be called 645882764c1SMateusz Piotrowskiwith the event waiters lock held, see 646882764c1SMateusz Piotrowski.Fn libusb_lock_event_waiters . 647c8c1f2ecSHans Petter SelaskyThis will 648a5118bdfSAndrew Thompsonblock until the timeout expires or a transfer completes or a thread releases 649882764c1SMateusz Piotrowskithe event handling lock through 650882764c1SMateusz Piotrowski.Fn libusb_unlock_events . 651c8c1f2ecSHans Petter SelaskyReturns 0 after a 65211867070SHans Petter Selaskytransfer completes or another thread stops event handling, and 1 if the 653a5118bdfSAndrew Thompsontimeout expired. 6544eaae44dSAndrew Thompson.Pp 655a5118bdfSAndrew Thompson.Ft int 65603205428SHans Petter Selasky.Fn libusb_handle_events_timeout_completed "libusb_context *ctx" "struct timeval *tv" "int *completed" 65703205428SHans Petter SelaskyHandle any pending events by checking if timeouts have expired and by 65803205428SHans Petter Selaskychecking the set of file descriptors for activity. 65903205428SHans Petter SelaskyIf the 66003205428SHans Petter Selasky.Fa completed 66103205428SHans Petter Selaskyargument is not equal to NULL, this function will 66203205428SHans Petter Selaskyloop until a transfer completion callback sets the variable pointed to 66303205428SHans Petter Selaskyby the 66403205428SHans Petter Selasky.Fa completed 66503205428SHans Petter Selaskyargument to non-zero. 66603205428SHans Petter SelaskyIf the 66703205428SHans Petter Selasky.Fa tv 66803205428SHans Petter Selaskyargument is not equal to NULL, this function will return 66903205428SHans Petter SelaskyLIBUSB_ERROR_TIMEOUT after the given timeout. 67003205428SHans Petter SelaskyReturns 0 on success, or a LIBUSB_ERROR code on failure or timeout. 67103205428SHans Petter Selasky.Pp 67203205428SHans Petter Selasky.Ft int 67303205428SHans Petter Selasky.Fn libusb_handle_events_completed "libusb_context *ctx" "int *completed" 67403205428SHans Petter SelaskyHandle any pending events by checking the set of file descriptors for activity. 67503205428SHans Petter SelaskyIf the 67603205428SHans Petter Selasky.Fa completed 67703205428SHans Petter Selaskyargument is not equal to NULL, this function will 67803205428SHans Petter Selaskyloop until a transfer completion callback sets the variable pointed to 67903205428SHans Petter Selaskyby the 68003205428SHans Petter Selasky.Fa completed 68103205428SHans Petter Selaskyargument to non-zero. 68203205428SHans Petter SelaskyReturns 0 on success, or a LIBUSB_ERROR code on failure. 68303205428SHans Petter Selasky.Pp 68403205428SHans Petter Selasky.Ft int 685a5118bdfSAndrew Thompson.Fn libusb_handle_events_timeout "libusb_context *ctx" "struct timeval *tv" 686a5118bdfSAndrew ThompsonHandle any pending events by checking if timeouts have expired and by 687c8c1f2ecSHans Petter Selaskychecking the set of file descriptors for activity. 688c8c1f2ecSHans Petter SelaskyReturns 0 on success, or a 68903205428SHans Petter SelaskyLIBUSB_ERROR code on failure or timeout. 6904eaae44dSAndrew Thompson.Pp 691a5118bdfSAndrew Thompson.Ft int 692a5118bdfSAndrew Thompson.Fn libusb_handle_events "libusb_context *ctx" 693c8c1f2ecSHans Petter SelaskyHandle any pending events in blocking mode with a sensible timeout. 694c8c1f2ecSHans Petter SelaskyReturns 0 69511867070SHans Petter Selaskyon success and a LIBUSB_ERROR code on failure. 6964eaae44dSAndrew Thompson.Pp 697a5118bdfSAndrew Thompson.Ft int 698a5118bdfSAndrew Thompson.Fn libusb_handle_events_locked "libusb_context *ctx" "struct timeval *tv" 6993102cfe2SGlen BarberHandle any pending events by polling file descriptors, without checking if 70011867070SHans Petter Selaskyanother thread is already doing so. 701c8c1f2ecSHans Petter SelaskyMust be called with the event lock held. 7024eaae44dSAndrew Thompson.Pp 703a5118bdfSAndrew Thompson.Ft int 704a5118bdfSAndrew Thompson.Fn libusb_get_next_timeout "libusb_context *ctx" "struct timeval *tv" 705c8c1f2ecSHans Petter SelaskyDetermine the next internal timeout that libusb needs to handle. 706c8c1f2ecSHans Petter SelaskyReturns 0 70711867070SHans Petter Selaskyif there are no pending timeouts, 1 if a timeout was returned, or a LIBUSB_ERROR 70803205428SHans Petter Selaskycode on failure or timeout. 7094eaae44dSAndrew Thompson.Pp 710a5118bdfSAndrew Thompson.Ft void 711a5118bdfSAndrew Thompson.Fn libusb_set_pollfd_notifiers "libusb_context *ctx" "libusb_pollfd_added_cb added_cb" "libusb_pollfd_removed_cb remove_cb" "void *user_data" 712a5118bdfSAndrew ThompsonRegister notification functions for file descriptor additions/removals. 713a5118bdfSAndrew ThompsonThese functions will be invoked for every new or removed file descriptor 714a5118bdfSAndrew Thompsonthat libusb uses as an event source. 7154eaae44dSAndrew Thompson.Pp 716a5118bdfSAndrew Thompson.Ft const struct libusb_pollfd ** 717a5118bdfSAndrew Thompson.Fn libusb_get_pollfds "libusb_context *ctx" 718882764c1SMateusz PiotrowskiRetrieve a list of file descriptors that should be polled by your main loop as 719c8c1f2ecSHans Petter Selaskylibusb event sources. 720c8c1f2ecSHans Petter SelaskyReturns a NULL-terminated list on success or NULL on failure. 7217bdc064bSHans Petter Selasky.Pp 7227bdc064bSHans Petter Selasky.Ft int 7237bdc064bSHans 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" 7247bdc064bSHans Petter SelaskyThis function registers a hotplug filter. 7257bdc064bSHans Petter SelaskyThe 7267bdc064bSHans Petter Selasky.Fa events 7277bdc064bSHans Petter Selaskyargument select which events makes the hotplug filter trigger. 7287bdc064bSHans Petter SelaskyAvailable event values are LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED and LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT. 7297bdc064bSHans Petter SelaskyOne or more events must be specified. 7307bdc064bSHans Petter SelaskyThe 7317bdc064bSHans Petter Selasky.Fa vendor_id , 7327bdc064bSHans Petter Selasky.Fa product_id 7337bdc064bSHans Petter Selaskyand 7347bdc064bSHans Petter Selasky.Fa dev_class 7357bdc064bSHans Petter Selaskyarguments can be set to LIBUSB_HOTPLUG_MATCH_ANY to match any value in the USB device descriptor. 7367bdc064bSHans Petter SelaskyElse the specified value is used for matching. 7377bdc064bSHans Petter SelaskyIf the 7387bdc064bSHans Petter Selasky.Fa flags 7397bdc064bSHans 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 7407bdc064bSHans Petter Selasky.Fa cb_fn 7417bdc064bSHans Petter Selaskyargument. 7427bdc064bSHans Petter SelaskyElse the 7437bdc064bSHans Petter Selasky.Fa flags 7447bdc064bSHans Petter Selaskyargument should be set to LIBUSB_HOTPLUG_NO_FLAGS. 7457bdc064bSHans Petter SelaskyThis function returns 0 upon success or a LIBUSB_ERROR code on failure. 7467bdc064bSHans Petter Selasky.Pp 7477bdc064bSHans Petter Selasky.Ft int 7487bdc064bSHans Petter Selasky.Fn libusb_hotplug_callback_fn "libusb_context *ctx" "libusb_device *device" "libusb_hotplug_event event" "void *user_data" 7497bdc064bSHans Petter SelaskyThe hotplug filter function. 7507bdc064bSHans Petter SelaskyIf this function returns non-zero, the filter is removed. 7517bdc064bSHans Petter SelaskyElse the filter is kept and can receive more events. 7527bdc064bSHans Petter SelaskyThe 7537bdc064bSHans Petter Selasky.Fa user_data 7547bdc064bSHans Petter Selaskyargument is the same as given when the filter was registered. 7557bdc064bSHans Petter SelaskyThe 7567bdc064bSHans Petter Selasky.Fa event 7577bdc064bSHans Petter Selaskyargument can be either of LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED or LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT. 7587bdc064bSHans Petter Selasky.Pp 7597bdc064bSHans Petter Selasky.Ft void 7607bdc064bSHans Petter Selasky.Fn libusb_hotplug_deregister_callback "libusb_context *ctx" "libusb_hotplug_callback_handle handle" 7617bdc064bSHans Petter SelaskyThis function unregisters a hotplug filter. 7624eaae44dSAndrew Thompson.Sh LIBUSB VERSION 0.1 COMPATIBILITY 763a5118bdfSAndrew ThompsonThe library is also compliant with LibUSB version 0.1.12. 764a5118bdfSAndrew Thompson.Pp 7654eaae44dSAndrew Thompson.Fn usb_open 7664eaae44dSAndrew Thompson.Fn usb_close 7674eaae44dSAndrew Thompson.Fn usb_get_string 7684eaae44dSAndrew Thompson.Fn usb_get_string_simple 7694eaae44dSAndrew Thompson.Fn usb_get_descriptor_by_endpoint 7704eaae44dSAndrew Thompson.Fn usb_get_descriptor 7714eaae44dSAndrew Thompson.Fn usb_parse_descriptor 7724eaae44dSAndrew Thompson.Fn usb_parse_configuration 7734eaae44dSAndrew Thompson.Fn usb_destroy_configuration 7744eaae44dSAndrew Thompson.Fn usb_fetch_and_parse_descriptors 7754eaae44dSAndrew Thompson.Fn usb_bulk_write 7764eaae44dSAndrew Thompson.Fn usb_bulk_read 7774eaae44dSAndrew Thompson.Fn usb_interrupt_write 7784eaae44dSAndrew Thompson.Fn usb_interrupt_read 7794eaae44dSAndrew Thompson.Fn usb_control_msg 7804eaae44dSAndrew Thompson.Fn usb_set_configuration 7814eaae44dSAndrew Thompson.Fn usb_claim_interface 7824eaae44dSAndrew Thompson.Fn usb_release_interface 7834eaae44dSAndrew Thompson.Fn usb_set_altinterface 7844eaae44dSAndrew Thompson.Fn usb_resetep 7854eaae44dSAndrew Thompson.Fn usb_clear_halt 7864eaae44dSAndrew Thompson.Fn usb_reset 7874eaae44dSAndrew Thompson.Fn usb_strerror 7884eaae44dSAndrew Thompson.Fn usb_init 7894eaae44dSAndrew Thompson.Fn usb_set_debug 7904eaae44dSAndrew Thompson.Fn usb_find_busses 7914eaae44dSAndrew Thompson.Fn usb_find_devices 7924eaae44dSAndrew Thompson.Fn usb_device 7934eaae44dSAndrew Thompson.Fn usb_get_busses 794f1b5fa6eSHans Petter Selasky.Fn usb_check_connected 7954eb5923dSHans Petter Selasky.Fn usb_get_driver_np 7964eb5923dSHans Petter Selasky.Fn usb_detach_kernel_driver_np 7974eaae44dSAndrew Thompson.Sh SEE ALSO 798a5118bdfSAndrew Thompson.Xr libusb20 3 , 799c54c1f7cSAndrew Thompson.Xr usb 4 , 800c61f2561SHans Petter Selasky.Xr usbconfig 8 , 801c61f2561SHans Petter Selasky.Xr usbdump 8 802a5118bdfSAndrew Thompson.Pp 803882764c1SMateusz Piotrowski.Lk https://libusb.info/ 8044eaae44dSAndrew Thompson.Sh HISTORY 8054eaae44dSAndrew Thompson.Nm 806a5118bdfSAndrew Thompsonsupport first appeared in 807a5118bdfSAndrew Thompson.Fx 8.0 . 808