14eaae44dSAndrew Thompson.\" 2a5118bdfSAndrew Thompson.\" Copyright (c) 2009 Sylvestre Gallon 34eaae44dSAndrew Thompson.\" 44eaae44dSAndrew Thompson.\" All rights reserved. 54eaae44dSAndrew Thompson.\" 64eaae44dSAndrew Thompson.\" Redistribution and use in source and binary forms, with or without 74eaae44dSAndrew Thompson.\" modification, are permitted provided that the following conditions 84eaae44dSAndrew Thompson.\" are met: 94eaae44dSAndrew Thompson.\" 1. Redistributions of source code must retain the above copyright 104eaae44dSAndrew Thompson.\" notice, this list of conditions and the following disclaimer. 114eaae44dSAndrew Thompson.\" 2. Redistributions in binary form must reproduce the above copyright 124eaae44dSAndrew Thompson.\" notice, this list of conditions and the following disclaimer in the 134eaae44dSAndrew Thompson.\" documentation and/or other materials provided with the distribution. 144eaae44dSAndrew Thompson.\" 154eaae44dSAndrew Thompson.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 164eaae44dSAndrew Thompson.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 174eaae44dSAndrew Thompson.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 184eaae44dSAndrew Thompson.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 194eaae44dSAndrew Thompson.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 204eaae44dSAndrew Thompson.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 214eaae44dSAndrew Thompson.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 224eaae44dSAndrew Thompson.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 234eaae44dSAndrew Thompson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 244eaae44dSAndrew Thompson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 254eaae44dSAndrew Thompson.\" SUCH DAMAGE. 264eaae44dSAndrew Thompson.\" 274eaae44dSAndrew Thompson.\" $FreeBSD$ 284eaae44dSAndrew Thompson.\" 29*03205428SHans Petter Selasky.Dd January 5, 2014 304eaae44dSAndrew Thompson.Dt LIBUSB 3 314eaae44dSAndrew Thompson.Os 324eaae44dSAndrew Thompson.Sh NAME 334eaae44dSAndrew Thompson.Nm libusb 344eaae44dSAndrew Thompson.Nd "USB access library" 354eaae44dSAndrew Thompson.Sh LIBRARY 3611867070SHans Petter SelaskyUSB access library 3711867070SHans Petter Selasky.Pq libusb, -lusb 384eaae44dSAndrew Thompson.Sh SYNOPSIS 39a5118bdfSAndrew Thompson.In libusb.h 404eaae44dSAndrew Thompson.Sh DESCRIPTION 414eaae44dSAndrew ThompsonThe 424eaae44dSAndrew Thompson.Nm 43a5118bdfSAndrew Thompsonlibrary contains interfaces for directly managing a usb device. 44a5118bdfSAndrew ThompsonThe current implementation supports v1.0 of the libusb API. 45a5118bdfSAndrew Thompson.Sh LIBRARY INITIALISATION / DEINITIALISATION 46a5118bdfSAndrew Thompson.Ft int 47a5118bdfSAndrew Thompson.Fn libusb_init libusb_context **ctx 48c8c1f2ecSHans Petter SelaskyThis function initialises libusb. 4911867070SHans Petter SelaskyIt must be called at the beginning 5011867070SHans Petter Selaskyof the program, before other libusb routines are used. 51c8c1f2ecSHans Petter SelaskyThis function returns 0 on success or LIBUSB_ERROR on 52a5118bdfSAndrew Thompsonfailure. 534eaae44dSAndrew Thompson.Pp 54a5118bdfSAndrew Thompson.Ft void 55a5118bdfSAndrew Thompson.Fn libusb_exit "libusb_context *ctx" 56c8c1f2ecSHans Petter SelaskyDeinitialise libusb. 57c8c1f2ecSHans Petter SelaskyMust be called at the end of the application. 5811867070SHans Petter SelaskyOther libusb routines may not be called after this function. 59a5118bdfSAndrew Thompson.Pp 60698e791aSHans Petter Selasky.Ft const char * 61698e791aSHans Petter Selasky.Fn libusb_strerror "int code" 6211867070SHans Petter SelaskyGet the ASCII representation of the error given by the 63698e791aSHans Petter Selasky.Fa code 64698e791aSHans Petter Selaskyargument. 65c61f2561SHans Petter SelaskyThis function does not return NULL. 66c61f2561SHans Petter Selasky.Pp 67c61f2561SHans Petter Selasky.Ft const char * 68c61f2561SHans Petter Selasky.Fn libusb_error_name "int code" 69c61f2561SHans Petter SelaskyGet the ASCII representation of the error enum given by the 70c61f2561SHans Petter Selasky.Fa code 71c61f2561SHans Petter Selaskyargument. 72c61f2561SHans Petter SelaskyThis function does not return NULL. 73698e791aSHans Petter Selasky.Pp 74a5118bdfSAndrew Thompson.Ft void 75a5118bdfSAndrew Thompson.Fn libusb_set_debug "libusb_context *ctx" "int level" 7611867070SHans Petter SelaskySet the debug level to 7711867070SHans Petter Selasky.Fa level . 78a5118bdfSAndrew Thompson.Pp 79a5118bdfSAndrew Thompson.Ft ssize_t 80a5118bdfSAndrew Thompson.Fn libusb_get_device_list "libusb_context *ctx" "libusb_device ***list" 8111867070SHans Petter SelaskyPopulate 82a5118bdfSAndrew Thompson.Fa list 8311867070SHans Petter Selaskywith the list of usb devices available, adding a reference to each 8411867070SHans Petter Selaskydevice in the list. 8511867070SHans Petter SelaskyAll the list entries created by this 8611867070SHans Petter Selaskyfunction must have their reference counter 8711867070SHans Petter Selaskydecremented when you are done with them, 8811867070SHans Petter Selaskyand the list itself must be freed. 89c8c1f2ecSHans Petter SelaskyThis 9011867070SHans Petter Selaskyfunction returns the number of devices in the list or a LIBUSB_ERROR code. 91a5118bdfSAndrew Thompson.Pp 92a5118bdfSAndrew Thompson.Ft void 93a5118bdfSAndrew Thompson.Fn libusb_free_device_list "libusb_device **list" "int unref_devices" 94c8c1f2ecSHans Petter SelaskyFree the list of devices discovered by libusb_get_device_list. 95c8c1f2ecSHans Petter SelaskyIf 96a5118bdfSAndrew Thompson.Fa unref_device 9711867070SHans Petter Selaskyis set to 1 all devices in the list have their reference 9811867070SHans Petter Selaskycounter decremented once. 99a5118bdfSAndrew Thompson.Pp 100a5118bdfSAndrew Thompson.Ft uint8_t 101a5118bdfSAndrew Thompson.Fn libusb_get_bus_number "libusb_device *dev" 102a5118bdfSAndrew ThompsonReturns the number of the bus contained by the device 103a5118bdfSAndrew Thompson.Fa dev . 104a5118bdfSAndrew Thompson.Pp 1055906bf49SEd Maste.Ft int 106a9205626SEd Maste.Fn libusb_get_port_numbers "libusb_device *dev" "uint8_t *buf" "uint8_t bufsize" 1075906bf49SEd MasteStores, in the buffer 1085906bf49SEd Maste.Fa buf 1095906bf49SEd Masteof size 1105906bf49SEd Maste.Fa bufsize , 1115906bf49SEd Mastethe list of all port numbers from root for the device 1125906bf49SEd Maste.Fa dev . 1135906bf49SEd Maste.Pp 114a9205626SEd Maste.Ft int 115a9205626SEd Maste.Fn libusb_get_port_path "libusb_context *ctx" "libusb_device *dev" "uint8_t *buf" "uint8_t bufsize" 116a9205626SEd MasteDeprecated function equivalent to libusb_get_port_numbers. 117a9205626SEd Maste.Pp 118a5118bdfSAndrew Thompson.Ft uint8_t 119a5118bdfSAndrew Thompson.Fn libusb_get_device_address "libusb_device *dev" 120ca96e26aSHans Petter SelaskyReturns the device_address contained by the device 121a5118bdfSAndrew Thompson.Fa dev . 122a5118bdfSAndrew Thompson.Pp 123ca96e26aSHans Petter Selasky.Ft enum libusb_speed 124ca96e26aSHans Petter Selasky.Fn libusb_get_device_speed "libusb_device *dev" 125ca96e26aSHans Petter SelaskyReturns the wire speed at which the device is connected. 126ca96e26aSHans Petter SelaskySee the LIBUSB_SPEED_XXX enums for more information. 127ca96e26aSHans Petter SelaskyLIBUSB_SPEED_UNKNOWN is returned in case of unknown wire speed. 128ca96e26aSHans Petter Selasky.Pp 129a5118bdfSAndrew Thompson.Ft int 130a5118bdfSAndrew Thompson.Fn libusb_get_max_packet_size "libusb_device *dev" "unsigned char endpoint" 131ca96e26aSHans Petter SelaskyReturns the wMaxPacketSize value on success, LIBUSB_ERROR_NOT_FOUND if the 132a5118bdfSAndrew Thompsonendpoint does not exist and LIBUSB_ERROR_OTHERS on other failure. 133a5118bdfSAndrew Thompson.Pp 134748205a3SHans Petter Selasky.Ft int 135748205a3SHans Petter Selasky.Fn libusb_get_max_iso_packet_size "libusb_device *dev" "unsigned char endpoint" 136748205a3SHans Petter SelaskyReturns the packet size multiplied by the packet multiplier on success, 137748205a3SHans Petter SelaskyLIBUSB_ERROR_NOT_FOUND if the endpoint does not exist and 138748205a3SHans Petter SelaskyLIBUSB_ERROR_OTHERS on other failure. 139748205a3SHans Petter Selasky.Pp 140a5118bdfSAndrew Thompson.Ft libusb_device * 141a5118bdfSAndrew Thompson.Fn libusb_ref_device "libusb_device *dev" 142a5118bdfSAndrew ThompsonIncrement the reference counter of the device 143a5118bdfSAndrew Thompson.Fa dev . 144a5118bdfSAndrew Thompson.Pp 145a5118bdfSAndrew Thompson.Ft void 146a5118bdfSAndrew Thompson.Fn libusb_unref_device "libusb_device *dev" 147a5118bdfSAndrew ThompsonDecrement the reference counter of the device 148a5118bdfSAndrew Thompson.Fa dev . 149a5118bdfSAndrew Thompson.Pp 150a5118bdfSAndrew Thompson.Ft int 151a5118bdfSAndrew Thompson.Fn libusb_open "libusb_device *dev" "libusb_device_handle **devh" 152c8c1f2ecSHans Petter SelaskyOpen a device and obtain a device_handle. 153c8c1f2ecSHans Petter SelaskyReturns 0 on success, 15411867070SHans Petter SelaskyLIBUSB_ERROR_NO_MEM on memory allocation problems, LIBUSB_ERROR_ACCESS 15511867070SHans Petter Selaskyon permissions problems, LIBUSB_ERROR_NO_DEVICE if the device has been 15611867070SHans Petter Selaskydisconnected and a LIBUSB_ERROR code on other errors. 157a5118bdfSAndrew Thompson.Pp 158a5118bdfSAndrew Thompson.Ft libusb_device_handle * 159a5118bdfSAndrew Thompson.Fn libusb_open_device_with_vid_pid "libusb_context *ctx" "uint16_t vid" "uint16_t pid" 16011867070SHans Petter SelaskyA convenience function to open a device by vendor and product IDs 161a5118bdfSAndrew Thompson.Fa vid 1624eaae44dSAndrew Thompsonand 163a5118bdfSAndrew Thompson.Fa pid . 164ca96e26aSHans Petter SelaskyReturns NULL on error. 1654eaae44dSAndrew Thompson.Pp 166a5118bdfSAndrew Thompson.Ft void 167a5118bdfSAndrew Thompson.Fn libusb_close "libusb_device_handle *devh" 168a5118bdfSAndrew ThompsonClose a device handle. 1694eaae44dSAndrew Thompson.Pp 170a5118bdfSAndrew Thompson.Ft libusb_device * 171ca96e26aSHans Petter Selasky.Fn libusb_get_device "libusb_device_handle *devh" 172ca96e26aSHans Petter SelaskyGet the device contained by devh. 173ca96e26aSHans Petter SelaskyReturns NULL on error. 1744eaae44dSAndrew Thompson.Pp 175a5118bdfSAndrew Thompson.Ft int 176a5118bdfSAndrew Thompson.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config" 177a3fb6da9SGlen BarberReturns the value of the current configuration. 178c8c1f2ecSHans Petter SelaskyReturns 0 179a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected 180a5118bdfSAndrew Thompsonand a LIBUSB_ERROR code on error. 1814eaae44dSAndrew Thompson.Pp 182a5118bdfSAndrew Thompson.Ft int 183a5118bdfSAndrew Thompson.Fn libusb_set_configuration "libusb_device_handle *devh" "int config" 18411867070SHans Petter SelaskySet the active configuration to 185a5118bdfSAndrew Thompson.Fa config 186a5118bdfSAndrew Thompsonfor the device contained by 187a5118bdfSAndrew Thompson.Fa devh . 188ca96e26aSHans Petter SelaskyThis function returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested 189a5118bdfSAndrew Thompsonconfiguration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently 190a5118bdfSAndrew Thompsonclaimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a 191a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 1924eaae44dSAndrew Thompson.Pp 193a5118bdfSAndrew Thompson.Ft int 194a5118bdfSAndrew Thompson.Fn libusb_claim_interface "libusb_device_handle *devh" "int interface_number" 195a5118bdfSAndrew ThompsonClaim an interface in a given libusb_handle 196a5118bdfSAndrew Thompson.Fa devh . 197c8c1f2ecSHans Petter SelaskyThis is a non-blocking function. 19811867070SHans Petter SelaskyIt returns 0 on success, LIBUSB_ERROR_NOT_FOUND 199a5118bdfSAndrew Thompsonif the requested interface does not exist, LIBUSB_ERROR_BUSY if a program or 200a5118bdfSAndrew Thompsondriver has claimed the interface, LIBUSB_ERROR_NO_DEVICE if the device has 201a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure. 2024eaae44dSAndrew Thompson.Pp 203a5118bdfSAndrew Thompson.Ft int 204a5118bdfSAndrew Thompson.Fn libusb_release_interface "libusb_device_handle *devh" "int interface_number" 20511867070SHans Petter SelaskyThis function releases an interface. 20611867070SHans Petter SelaskyAll the claimed interfaces on a device must be released 20711867070SHans Petter Selaskybefore closing the device. 208c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the 209799162a6SJoel Dahlinterface was not claimed, LIBUSB_ERROR_NO_DEVICE if the device has been 210a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR on failure. 2114eaae44dSAndrew Thompson.Pp 212a5118bdfSAndrew Thompson.Ft int 213a5118bdfSAndrew Thompson.Fn libusb_set_interface_alt_setting "libusb_device_handle *dev" "int interface_number" "int alternate_setting" 214c8c1f2ecSHans Petter SelaskyActivate an alternate setting for an interface. 215c8c1f2ecSHans Petter SelaskyReturns 0 on success, 216a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if the interface was not claimed or the requested 217a5118bdfSAndrew Thompsonsetting does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been 21811867070SHans Petter Selaskydisconnected and a LIBUSB_ERROR code on failure. 2194eaae44dSAndrew Thompson.Pp 220a5118bdfSAndrew Thompson.Ft int 221a5118bdfSAndrew Thompson.Fn libusb_clear_halt "libusb_device_handle *devh" "unsigned char endpoint" 222c8c1f2ecSHans Petter SelaskyClear an halt/stall for a endpoint. 223c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND 224a5118bdfSAndrew Thompsonif the endpoint does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been 225a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on failure. 2264eaae44dSAndrew Thompson.Pp 227a5118bdfSAndrew Thompson.Ft int 228a5118bdfSAndrew Thompson.Fn libusb_reset_device "libusb_device_handle *devh" 229c8c1f2ecSHans Petter SelaskyPerform an USB port reset for an usb device. 230c8c1f2ecSHans Petter SelaskyReturns 0 on success, 231a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if re-enumeration is required or if the device has 232a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure. 2334eaae44dSAndrew Thompson.Pp 234a5118bdfSAndrew Thompson.Ft int 235f1b5fa6eSHans Petter Selasky.Fn libusb_check_connected "libusb_device_handle *devh" 23611867070SHans Petter SelaskyTest if the USB device is still connected. 237c8c1f2ecSHans Petter SelaskyReturns 0 on success, 23811867070SHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if it has been disconnected and a LIBUSB_ERROR 239f1b5fa6eSHans Petter Selaskycode on failure. 240f1b5fa6eSHans Petter Selasky.Pp 241f1b5fa6eSHans Petter Selasky.Ft int 242a5118bdfSAndrew Thompson.Fn libusb_kernel_driver_active "libusb_device_handle *devh" "int interface" 243c8c1f2ecSHans Petter SelaskyDetermine if a driver is active on a interface. 2444d2472aaSHans Petter SelaskyReturns 0 if no kernel driver is active 2454d2472aaSHans Petter Selaskyand 1 if a kernel driver is active, LIBUSB_ERROR_NO_DEVICE 24611867070SHans Petter Selaskyif the device has been disconnected and a LIBUSB_ERROR code on failure. 2474eaae44dSAndrew Thompson.Pp 248a5118bdfSAndrew Thompson.Ft int 249698e791aSHans Petter Selasky.Fn libusb_get_driver "libusb_device_handle *devh" "int interface" "char *name" "int namelen" 250698e791aSHans Petter Selaskyor 251698e791aSHans Petter Selasky.Ft int 252698e791aSHans Petter Selasky.Fn libusb_get_driver_np "libusb_device_handle *devh" "int interface" "char *name" "int namelen" 25311867070SHans Petter SelaskyCopy the name of the driver attached to the given 254698e791aSHans Petter Selasky.Fa device 255698e791aSHans Petter Selaskyand 256698e791aSHans Petter Selasky.Fa interface 25711867070SHans Petter Selaskyinto the buffer 258698e791aSHans Petter Selasky.Fa name 25911867070SHans Petter Selaskyof length 260698e791aSHans Petter Selasky.Fa namelen . 261698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver is attached 262698e791aSHans Petter Selaskyto the given interface and LIBUSB_ERROR_INVALID_PARAM if the interface does 263698e791aSHans Petter Selaskynot exist. 264698e791aSHans Petter SelaskyThis function is non-portable. 265698e791aSHans Petter SelaskyThe buffer pointed to by 266698e791aSHans Petter Selasky.Fa name 267698e791aSHans Petter Selaskyis only zero terminated on success. 268698e791aSHans Petter Selasky.Pp 269698e791aSHans Petter Selasky.Ft int 270a5118bdfSAndrew Thompson.Fn libusb_detach_kernel_driver "libusb_device_handle *devh" "int interface" 271698e791aSHans Petter Selaskyor 272698e791aSHans Petter Selasky.Ft int 273698e791aSHans Petter Selasky.Fn libusb_detach_kernel_driver_np "libusb_device_handle *devh" "int interface" 274698e791aSHans Petter SelaskyDetach a kernel driver from an interface. 27511867070SHans Petter SelaskyThis is needed to claim an interface already claimed by a kernel driver. 276698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver was active, 277c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, 278c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if the device has been disconnected 279c8c1f2ecSHans Petter Selaskyand a LIBUSB_ERROR code on failure. 280c8c1f2ecSHans Petter SelaskyThis function is non-portable. 2814eaae44dSAndrew Thompson.Pp 282a5118bdfSAndrew Thompson.Ft int 283a5118bdfSAndrew Thompson.Fn libusb_attach_kernel_driver "libusb_device_handle *devh" "int interface" 28411867070SHans Petter SelaskyRe-attach an interface kernel driver that was previously detached. 285c8c1f2ecSHans Petter SelaskyReturns 0 on success, 286c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, 287c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE 28811867070SHans Petter Selaskyif the device has been disconnected, LIBUSB_ERROR_BUSY if the driver cannot be 289a5118bdfSAndrew Thompsonattached because the interface is claimed by a program or driver and a 290a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 291a5118bdfSAndrew Thompson.Sh USB DESCRIPTORS 292a5118bdfSAndrew Thompson.Ft int 293a5118bdfSAndrew Thompson.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc" 294a5118bdfSAndrew ThompsonGet the USB device descriptor for the device 295a5118bdfSAndrew Thompson.Fa dev . 296c8c1f2ecSHans Petter SelaskyThis is a non-blocking function. 297c8c1f2ecSHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on 298a5118bdfSAndrew Thompsonfailure. 2994eaae44dSAndrew Thompson.Pp 300a5118bdfSAndrew Thompson.Ft int 301cb0df9e8SHans Petter Selasky.Fn libusb_get_active_config_descriptor "libusb_device *dev" "struct libusb_config_descriptor **config" 302c8c1f2ecSHans Petter SelaskyGet the USB configuration descriptor for the active configuration. 303c8c1f2ecSHans Petter SelaskyReturns 0 on 30411867070SHans Petter Selaskysuccess, LIBUSB_ERROR_NOT_FOUND if the device is in 30511867070SHans Petter Selaskyan unconfigured state 30611867070SHans Petter Selaskyand a LIBUSB_ERROR code on error. 3074eaae44dSAndrew Thompson.Pp 308a5118bdfSAndrew Thompson.Ft int 309a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor "libusb_device *dev" "uint8_t config_index" "libusb_config_descriptor **config" 31011867070SHans Petter SelaskyGet a USB configuration descriptor based on its index 311a5118bdfSAndrew Thompson.Fa idx. 312a5118bdfSAndrew ThompsonReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist 31311867070SHans Petter Selaskyand a LIBUSB_ERROR code on error. 314545b01adSAndrew Thompson.Pp 315a5118bdfSAndrew Thompson.Ft int 316a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor_by_value "libusb_device *dev" "uint8 bConfigurationValue" "libusb_config_descriptor **config" 317c8c1f2ecSHans Petter SelaskyGet a USB configuration descriptor with a specific bConfigurationValue. 318c8c1f2ecSHans Petter SelaskyThis is 31911867070SHans Petter Selaskya non-blocking function which does not send a request through the device. 320c8c1f2ecSHans Petter SelaskyReturns 0 321c8c1f2ecSHans Petter Selaskyon success, LIBUSB_ERROR_NOT_FOUND if the configuration 32211867070SHans Petter Selaskydoes not exist and a 323a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 3244eaae44dSAndrew Thompson.Pp 325a5118bdfSAndrew Thompson.Ft void 326390065b1SAlfred Perlstein.Fn libusb_free_config_descriptor "libusb_config_descriptor *config" 327a5118bdfSAndrew ThompsonFree a configuration descriptor. 3284eaae44dSAndrew Thompson.Pp 329a5118bdfSAndrew Thompson.Ft int 33078ed0e49SHans Petter Selasky.Fn libusb_get_string_descriptor "libusb_device_handle *devh" "uint8_t desc_idx" "uint16_t langid" "unsigned char *data" "int length" 33178ed0e49SHans Petter SelaskyRetrieve a string descriptor in raw format. 33278ed0e49SHans Petter SelaskyReturns the number of bytes actually transferred on success 33378ed0e49SHans Petter Selaskyor a negative LIBUSB_ERROR code on failure. 33478ed0e49SHans Petter Selasky.Pp 33578ed0e49SHans Petter Selasky.Ft int 336a5118bdfSAndrew Thompson.Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length" 33711867070SHans Petter SelaskyRetrieve a string descriptor in C style ASCII. 33811867070SHans Petter SelaskyReturns the positive number of bytes in the resulting ASCII string 339c8c1f2ecSHans Petter Selaskyon success and a LIBUSB_ERROR code on failure. 3404eaae44dSAndrew Thompson.Pp 3414c0392e6SHans Petter Selasky.Ft int 3424c0392e6SHans Petter Selasky.Fn libusb_parse_ss_endpoint_comp "const void *buf" "int len" "libusb_ss_endpoint_companion_descriptor **ep_comp" 3434c0392e6SHans Petter SelaskyThis function parses the USB 3.0 endpoint companion descriptor in host endian format pointed to by 3444c0392e6SHans Petter Selasky.Fa buf 3454c0392e6SHans Petter Selaskyand having a length of 3464c0392e6SHans Petter Selasky.Fa len . 3474c0392e6SHans Petter SelaskyTypically these arguments are the extra and extra_length fields of the 3484c0392e6SHans Petter Selaskyendpoint descriptor. 3494c0392e6SHans Petter SelaskyOn success the pointer to resulting descriptor is stored at the location given by 3504c0392e6SHans Petter Selasky.Fa ep_comp . 3514c0392e6SHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 3524c0392e6SHans Petter SelaskyOn success the parsed USB 3.0 endpoint companion descriptor must be 3534c0392e6SHans Petter Selaskyfreed using the libusb_free_ss_endpoint_comp function. 3544c0392e6SHans Petter Selasky.Pp 3554c0392e6SHans Petter Selasky.Ft void 3564c0392e6SHans Petter Selasky.Fn libusb_free_ss_endpoint_comp "libusb_ss_endpoint_companion_descriptor *ep_comp" 3574c0392e6SHans Petter SelaskyThis function is NULL safe and frees a parsed USB 3.0 endpoint companion descriptor. 3584c0392e6SHans Petter Selasky.Pp 3594c0392e6SHans Petter Selasky.Ft int 3604c0392e6SHans Petter Selasky.Fn libusb_parse_bos_descriptor "const void *buf" "int len" "libusb_bos_descriptor **bos" 3614c0392e6SHans Petter SelaskyThis function parses a Binary Object Store, BOS, descriptor into host endian format pointed to by 3624c0392e6SHans Petter Selasky.Fa buf 3634c0392e6SHans Petter Selaskyand having a length of 3644c0392e6SHans Petter Selasky.Fa len . 3654c0392e6SHans Petter SelaskyOn success the pointer to resulting descriptor is stored at the location given by 3664c0392e6SHans Petter Selasky.Fa bos . 3674c0392e6SHans Petter SelaskyReturns zero on success and a LIBUSB_ERROR code on failure. 3684c0392e6SHans Petter SelaskyOn success the parsed BOS descriptor must be freed using the 3694c0392e6SHans Petter Selaskylibusb_free_bos_descriptor function. 3704c0392e6SHans Petter Selasky.Pp 3714c0392e6SHans Petter Selasky.Ft void 3724c0392e6SHans Petter Selasky.Fn libusb_free_bos_descriptor "libusb_bos_descriptor *bos" 3734c0392e6SHans Petter SelaskyThis function is NULL safe and frees a parsed BOS descriptor. 374a5118bdfSAndrew Thompson.Sh USB ASYNCHRONOUS I/O 375a5118bdfSAndrew Thompson.Ft struct libusb_transfer * 376a5118bdfSAndrew Thompson.Fn libusb_alloc_transfer "int iso_packets" 37711867070SHans Petter SelaskyAllocate a transfer with the number of isochronous packet descriptors 37811867070SHans Petter Selaskyspecified by 37911867070SHans Petter Selasky.Fa iso_packets . 380ca96e26aSHans Petter SelaskyReturns NULL on error. 3814eaae44dSAndrew Thompson.Pp 382a5118bdfSAndrew Thompson.Ft void 383a5118bdfSAndrew Thompson.Fn libusb_free_transfer "struct libusb_transfer *tr" 384a5118bdfSAndrew ThompsonFree a transfer. 3854eaae44dSAndrew Thompson.Pp 386a5118bdfSAndrew Thompson.Ft int 387a5118bdfSAndrew Thompson.Fn libusb_submit_transfer "struct libusb_transfer *tr" 388ca96e26aSHans Petter SelaskyThis function will submit a transfer and returns immediately. 389c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NO_DEVICE if 39011867070SHans Petter Selaskythe device has been disconnected and a 391a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure. 3924eaae44dSAndrew Thompson.Pp 393a5118bdfSAndrew Thompson.Ft int 394a5118bdfSAndrew Thompson.Fn libusb_cancel_transfer "struct libusb_transfer *tr" 39511867070SHans Petter SelaskyThis function asynchronously cancels a transfer. 39611867070SHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on failure. 397a5118bdfSAndrew Thompson.Sh USB SYNCHRONOUS I/O 398a5118bdfSAndrew Thompson.Ft int 399698e791aSHans 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" 400ca96e26aSHans Petter SelaskyPerform a USB control transfer. 401ca96e26aSHans Petter SelaskyReturns the actual number of bytes 40211867070SHans Petter Selaskytransferred on success, in the range from and including zero up to and 403c865d740SHans Petter Selaskyincluding 404892f4806SHans Petter Selasky.Fa wLength . 40511867070SHans Petter SelaskyOn error a LIBUSB_ERROR code is returned, for example 40611867070SHans Petter SelaskyLIBUSB_ERROR_TIMEOUT if the transfer timed out, LIBUSB_ERROR_PIPE if the 407c865d740SHans Petter Selaskycontrol request was not supported, LIBUSB_ERROR_NO_DEVICE if the 40811867070SHans Petter Selaskydevice has been disconnected and another LIBUSB_ERROR code on other failures. 40911867070SHans Petter SelaskyThe LIBUSB_ERROR codes are all negative. 4104eaae44dSAndrew Thompson.Pp 411a5118bdfSAndrew Thompson.Ft int 412a5118bdfSAndrew Thompson.Fn libusb_bulk_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout" 413892f4806SHans Petter SelaskyPerform an USB bulk transfer. 414892f4806SHans Petter SelaskyA timeout value of zero means no timeout. 415892f4806SHans Petter SelaskyThe timeout value is given in milliseconds. 416892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT 41711867070SHans Petter Selaskyif the transfer timed out, LIBUSB_ERROR_PIPE if the control request was not 418a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data, 419a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 42011867070SHans Petter Selaskya LIBUSB_ERROR code on other failure. 4214eaae44dSAndrew Thompson.Pp 422a5118bdfSAndrew Thompson.Ft int 423a5118bdfSAndrew Thompson.Fn libusb_interrupt_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout" 424892f4806SHans Petter SelaskyPerform an USB Interrupt transfer. 425892f4806SHans Petter SelaskyA timeout value of zero means no timeout. 426892f4806SHans Petter SelaskyThe timeout value is given in milliseconds. 427892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT 42811867070SHans Petter Selaskyif the transfer timed out, LIBUSB_ERROR_PIPE if the control request was not 429a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data, 430a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 43111867070SHans Petter Selaskya LIBUSB_ERROR code on other failure. 432a5118bdfSAndrew Thompson.Sh USB EVENTS 433a5118bdfSAndrew Thompson.Ft int 434a5118bdfSAndrew Thompson.Fn libusb_try_lock_events "libusb_context *ctx" 435ca96e26aSHans Petter SelaskyTry to acquire the event handling lock. 436ca96e26aSHans Petter SelaskyReturns 0 if the lock was obtained and 1 if not. 4374eaae44dSAndrew Thompson.Pp 438a5118bdfSAndrew Thompson.Ft void 439a5118bdfSAndrew Thompson.Fn libusb_lock_events "libusb_context *ctx" 440c8c1f2ecSHans Petter SelaskyAcquire the event handling lock. 441c8c1f2ecSHans Petter SelaskyThis function is blocking. 4424eaae44dSAndrew Thompson.Pp 443a5118bdfSAndrew Thompson.Ft void 444a5118bdfSAndrew Thompson.Fn libusb_unlock_events "libusb_context *ctx" 445c8c1f2ecSHans Petter SelaskyRelease the event handling lock. 446c8c1f2ecSHans Petter SelaskyThis will wake up any thread blocked 44711867070SHans Petter Selaskyon 448d284271aSJoel Dahl.Fn libusb_wait_for_event . 4494eaae44dSAndrew Thompson.Pp 450a5118bdfSAndrew Thompson.Ft int 451a5118bdfSAndrew Thompson.Fn libusb_event_handling_ok "libusb_context *ctx" 452c8c1f2ecSHans Petter SelaskyDetermine if it still OK for this thread to be doing event handling. 453c8c1f2ecSHans Petter SelaskyReturns 1 454c8c1f2ecSHans Petter Selaskyif event handling can start or continue. 455c8c1f2ecSHans Petter SelaskyReturns 0 if this thread must give up 456a5118bdfSAndrew Thompsonthe events lock. 4574eaae44dSAndrew Thompson.Pp 458a5118bdfSAndrew Thompson.Ft int 459a5118bdfSAndrew Thompson.Fn libusb_event_handler_active "libusb_context *ctx" 460c8c1f2ecSHans Petter SelaskyDetermine if an active thread is handling events. 46111867070SHans Petter SelaskyReturns 1 if there is a thread handling events and 0 if there 462a5118bdfSAndrew Thompsonare no threads currently handling events. 4634eaae44dSAndrew Thompson.Pp 464a5118bdfSAndrew Thompson.Ft void 465a5118bdfSAndrew Thompson.Fn libusb_lock_event_waiters "libusb_context *ctx" 466c8c1f2ecSHans Petter SelaskyAcquire the event_waiters lock. 46711867070SHans Petter SelaskyThis lock is designed to be obtained in the 468a5118bdfSAndrew Thompsonsituation where you want to be aware when events are completed, but some other 469a5118bdfSAndrew Thompsonthread is event handling so calling libusb_handle_events() is not allowed. 470545b01adSAndrew Thompson.Pp 471a5118bdfSAndrew Thompson.Ft void 472a5118bdfSAndrew Thompson.Fn libusb_unlock_event_waiters "libusb_context *ctx" 473a5118bdfSAndrew ThompsonRelease the event_waiters lock. 4744eaae44dSAndrew Thompson.Pp 475a5118bdfSAndrew Thompson.Ft int 476a5118bdfSAndrew Thompson.Fn libusb_wait_for_event "libusb_context *ctx" "struct timeval *tv" 477c8c1f2ecSHans Petter SelaskyWait for another thread to signal completion of an event. 478c8c1f2ecSHans Petter SelaskyMust be called 479c8c1f2ecSHans Petter Selaskywith the event waiters lock held, see libusb_lock_event_waiters(). 480c8c1f2ecSHans Petter SelaskyThis will 481a5118bdfSAndrew Thompsonblock until the timeout expires or a transfer completes or a thread releases 482c8c1f2ecSHans Petter Selaskythe event handling lock through libusb_unlock_events(). 483c8c1f2ecSHans Petter SelaskyReturns 0 after a 48411867070SHans Petter Selaskytransfer completes or another thread stops event handling, and 1 if the 485a5118bdfSAndrew Thompsontimeout expired. 4864eaae44dSAndrew Thompson.Pp 487a5118bdfSAndrew Thompson.Ft int 488*03205428SHans Petter Selasky.Fn libusb_handle_events_timeout_completed "libusb_context *ctx" "struct timeval *tv" "int *completed" 489*03205428SHans Petter SelaskyHandle any pending events by checking if timeouts have expired and by 490*03205428SHans Petter Selaskychecking the set of file descriptors for activity. 491*03205428SHans Petter SelaskyIf the 492*03205428SHans Petter Selasky.Fa completed 493*03205428SHans Petter Selaskyargument is not equal to NULL, this function will 494*03205428SHans Petter Selaskyloop until a transfer completion callback sets the variable pointed to 495*03205428SHans Petter Selaskyby the 496*03205428SHans Petter Selasky.Fa completed 497*03205428SHans Petter Selaskyargument to non-zero. 498*03205428SHans Petter SelaskyIf the 499*03205428SHans Petter Selasky.Fa tv 500*03205428SHans Petter Selaskyargument is not equal to NULL, this function will return 501*03205428SHans Petter SelaskyLIBUSB_ERROR_TIMEOUT after the given timeout. 502*03205428SHans Petter SelaskyReturns 0 on success, or a LIBUSB_ERROR code on failure or timeout. 503*03205428SHans Petter Selasky.Pp 504*03205428SHans Petter Selasky.Ft int 505*03205428SHans Petter Selasky.Fn libusb_handle_events_completed "libusb_context *ctx" "int *completed" 506*03205428SHans Petter SelaskyHandle any pending events by checking the set of file descriptors for activity. 507*03205428SHans Petter SelaskyIf the 508*03205428SHans Petter Selasky.Fa completed 509*03205428SHans Petter Selaskyargument is not equal to NULL, this function will 510*03205428SHans Petter Selaskyloop until a transfer completion callback sets the variable pointed to 511*03205428SHans Petter Selaskyby the 512*03205428SHans Petter Selasky.Fa completed 513*03205428SHans Petter Selaskyargument to non-zero. 514*03205428SHans Petter SelaskyReturns 0 on success, or a LIBUSB_ERROR code on failure. 515*03205428SHans Petter Selasky.Pp 516*03205428SHans Petter Selasky.Ft int 517a5118bdfSAndrew Thompson.Fn libusb_handle_events_timeout "libusb_context *ctx" "struct timeval *tv" 518a5118bdfSAndrew ThompsonHandle any pending events by checking if timeouts have expired and by 519c8c1f2ecSHans Petter Selaskychecking the set of file descriptors for activity. 520c8c1f2ecSHans Petter SelaskyReturns 0 on success, or a 521*03205428SHans Petter SelaskyLIBUSB_ERROR code on failure or timeout. 5224eaae44dSAndrew Thompson.Pp 523a5118bdfSAndrew Thompson.Ft int 524a5118bdfSAndrew Thompson.Fn libusb_handle_events "libusb_context *ctx" 525c8c1f2ecSHans Petter SelaskyHandle any pending events in blocking mode with a sensible timeout. 526c8c1f2ecSHans Petter SelaskyReturns 0 52711867070SHans Petter Selaskyon success and a LIBUSB_ERROR code on failure. 5284eaae44dSAndrew Thompson.Pp 529a5118bdfSAndrew Thompson.Ft int 530a5118bdfSAndrew Thompson.Fn libusb_handle_events_locked "libusb_context *ctx" "struct timeval *tv" 5313102cfe2SGlen BarberHandle any pending events by polling file descriptors, without checking if 53211867070SHans Petter Selaskyanother thread is already doing so. 533c8c1f2ecSHans Petter SelaskyMust be called with the event lock held. 5344eaae44dSAndrew Thompson.Pp 535a5118bdfSAndrew Thompson.Ft int 536a5118bdfSAndrew Thompson.Fn libusb_get_next_timeout "libusb_context *ctx" "struct timeval *tv" 537c8c1f2ecSHans Petter SelaskyDetermine the next internal timeout that libusb needs to handle. 538c8c1f2ecSHans Petter SelaskyReturns 0 53911867070SHans Petter Selaskyif there are no pending timeouts, 1 if a timeout was returned, or a LIBUSB_ERROR 540*03205428SHans Petter Selaskycode on failure or timeout. 5414eaae44dSAndrew Thompson.Pp 542a5118bdfSAndrew Thompson.Ft void 543a5118bdfSAndrew Thompson.Fn libusb_set_pollfd_notifiers "libusb_context *ctx" "libusb_pollfd_added_cb added_cb" "libusb_pollfd_removed_cb remove_cb" "void *user_data" 544a5118bdfSAndrew ThompsonRegister notification functions for file descriptor additions/removals. 545a5118bdfSAndrew ThompsonThese functions will be invoked for every new or removed file descriptor 546a5118bdfSAndrew Thompsonthat libusb uses as an event source. 5474eaae44dSAndrew Thompson.Pp 548a5118bdfSAndrew Thompson.Ft const struct libusb_pollfd ** 549a5118bdfSAndrew Thompson.Fn libusb_get_pollfds "libusb_context *ctx" 550a5118bdfSAndrew ThompsonRetrive a list of file descriptors that should be polled by your main loop as 551c8c1f2ecSHans Petter Selaskylibusb event sources. 552c8c1f2ecSHans Petter SelaskyReturns a NULL-terminated list on success or NULL on failure. 5534eaae44dSAndrew Thompson.Sh LIBUSB VERSION 0.1 COMPATIBILITY 554a5118bdfSAndrew ThompsonThe library is also compliant with LibUSB version 0.1.12. 555a5118bdfSAndrew Thompson.Pp 5564eaae44dSAndrew Thompson.Fn usb_open 5574eaae44dSAndrew Thompson.Fn usb_close 5584eaae44dSAndrew Thompson.Fn usb_get_string 5594eaae44dSAndrew Thompson.Fn usb_get_string_simple 5604eaae44dSAndrew Thompson.Fn usb_get_descriptor_by_endpoint 5614eaae44dSAndrew Thompson.Fn usb_get_descriptor 5624eaae44dSAndrew Thompson.Fn usb_parse_descriptor 5634eaae44dSAndrew Thompson.Fn usb_parse_configuration 5644eaae44dSAndrew Thompson.Fn usb_destroy_configuration 5654eaae44dSAndrew Thompson.Fn usb_fetch_and_parse_descriptors 5664eaae44dSAndrew Thompson.Fn usb_bulk_write 5674eaae44dSAndrew Thompson.Fn usb_bulk_read 5684eaae44dSAndrew Thompson.Fn usb_interrupt_write 5694eaae44dSAndrew Thompson.Fn usb_interrupt_read 5704eaae44dSAndrew Thompson.Fn usb_control_msg 5714eaae44dSAndrew Thompson.Fn usb_set_configuration 5724eaae44dSAndrew Thompson.Fn usb_claim_interface 5734eaae44dSAndrew Thompson.Fn usb_release_interface 5744eaae44dSAndrew Thompson.Fn usb_set_altinterface 5754eaae44dSAndrew Thompson.Fn usb_resetep 5764eaae44dSAndrew Thompson.Fn usb_clear_halt 5774eaae44dSAndrew Thompson.Fn usb_reset 5784eaae44dSAndrew Thompson.Fn usb_strerror 5794eaae44dSAndrew Thompson.Fn usb_init 5804eaae44dSAndrew Thompson.Fn usb_set_debug 5814eaae44dSAndrew Thompson.Fn usb_find_busses 5824eaae44dSAndrew Thompson.Fn usb_find_devices 5834eaae44dSAndrew Thompson.Fn usb_device 5844eaae44dSAndrew Thompson.Fn usb_get_busses 585f1b5fa6eSHans Petter Selasky.Fn usb_check_connected 5864eb5923dSHans Petter Selasky.Fn usb_get_driver_np 5874eb5923dSHans Petter Selasky.Fn usb_detach_kernel_driver_np 5884eaae44dSAndrew Thompson.Sh SEE ALSO 589a5118bdfSAndrew Thompson.Xr libusb20 3 , 590c54c1f7cSAndrew Thompson.Xr usb 4 , 591c61f2561SHans Petter Selasky.Xr usbconfig 8 , 592c61f2561SHans Petter Selasky.Xr usbdump 8 593a5118bdfSAndrew Thompson.Pp 594a5118bdfSAndrew Thompson.Pa http://libusb.sourceforge.net/ 5954eaae44dSAndrew Thompson.Sh HISTORY 5964eaae44dSAndrew Thompson.Nm 597a5118bdfSAndrew Thompsonsupport first appeared in 598a5118bdfSAndrew Thompson.Fx 8.0 . 599