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*c865d740SHans Petter Selasky.Dd November 18, 2010 304eaae44dSAndrew Thompson.Dt LIBUSB 3 314eaae44dSAndrew Thompson.Os 324eaae44dSAndrew Thompson.Sh NAME 334eaae44dSAndrew Thompson.Nm libusb 344eaae44dSAndrew Thompson. 354eaae44dSAndrew Thompson.Nd "USB access library" 364eaae44dSAndrew Thompson. 374eaae44dSAndrew Thompson. 384eaae44dSAndrew Thompson.Sh LIBRARY 394eaae44dSAndrew Thompson. 404eaae44dSAndrew Thompson. 414eaae44dSAndrew ThompsonUSB access library (libusb -lusb) 424eaae44dSAndrew Thompson. 434eaae44dSAndrew Thompson. 444eaae44dSAndrew Thompson.Sh SYNOPSIS 45a5118bdfSAndrew Thompson. 46a5118bdfSAndrew Thompson. 47a5118bdfSAndrew Thompson.In libusb.h 484eaae44dSAndrew Thompson. 494eaae44dSAndrew Thompson. 504eaae44dSAndrew Thompson.Sh DESCRIPTION 514eaae44dSAndrew ThompsonThe 524eaae44dSAndrew Thompson.Nm 53a5118bdfSAndrew Thompsonlibrary contains interfaces for directly managing a usb device. 54a5118bdfSAndrew ThompsonThe current implementation supports v1.0 of the libusb API. 554eaae44dSAndrew Thompson. 564eaae44dSAndrew Thompson. 57a5118bdfSAndrew Thompson.Sh LIBRARY INITIALISATION / DEINITIALISATION 584eaae44dSAndrew Thompson. 594eaae44dSAndrew Thompson.Pp 604eaae44dSAndrew Thompson. 61a5118bdfSAndrew Thompson.Ft int 62a5118bdfSAndrew Thompson.Fn libusb_init libusb_context **ctx 63a5118bdfSAndrew ThompsonThis function initialises libusb. Must be called at the beginning 64a5118bdfSAndrew Thompsonof the program. This function returns 0 on success or LIBUSB_ERROR on 65a5118bdfSAndrew Thompsonfailure. 664eaae44dSAndrew Thompson. 674eaae44dSAndrew Thompson.Pp 684eaae44dSAndrew Thompson. 69a5118bdfSAndrew Thompson.Ft void 70a5118bdfSAndrew Thompson.Fn libusb_exit "libusb_context *ctx" 71a5118bdfSAndrew ThompsonDeinitialise libusb. Must be called at the end of the application. 72a5118bdfSAndrew Thompson. 73a5118bdfSAndrew Thompson.Pp 74a5118bdfSAndrew Thompson. 75698e791aSHans Petter Selasky.Ft const char * 76698e791aSHans Petter Selasky.Fn libusb_strerror "int code" 77698e791aSHans Petter SelaskyGet ASCII representation of the error given by the 78698e791aSHans Petter Selasky.Fa code 79698e791aSHans Petter Selaskyargument. 80698e791aSHans Petter Selasky. 81698e791aSHans Petter Selasky. 82698e791aSHans Petter Selasky.Pp 83698e791aSHans Petter Selasky. 84a5118bdfSAndrew Thompson.Ft void 85a5118bdfSAndrew Thompson.Fn libusb_set_debug "libusb_context *ctx" "int level" 86a5118bdfSAndrew ThompsonSet debug to the 87a5118bdfSAndrew Thompson.Fa level 88a5118bdfSAndrew Thompsonlevel. 89a5118bdfSAndrew Thompson. 90a5118bdfSAndrew Thompson.Pp 91a5118bdfSAndrew Thompson. 92a5118bdfSAndrew Thompson.Ft ssize_t 93a5118bdfSAndrew Thompson.Fn libusb_get_device_list "libusb_context *ctx" "libusb_device ***list" 94a5118bdfSAndrew ThompsonFill into 95a5118bdfSAndrew Thompson.Fa list 96a5118bdfSAndrew Thompsonthe list of usb device available. All the device created by this 97a5118bdfSAndrew Thompsonfunction must be unref and free when you are done with them. This 98a5118bdfSAndrew Thompsonfunction returns the number of devices in list or a LIBUSB_ERROR code. 99a5118bdfSAndrew Thompson. 100a5118bdfSAndrew Thompson.Pp 101a5118bdfSAndrew Thompson. 102a5118bdfSAndrew Thompson.Ft void 103a5118bdfSAndrew Thompson.Fn libusb_free_device_list "libusb_device **list" "int unref_devices" 104a5118bdfSAndrew ThompsonFree the list of devices discovered by libusb_get_device_list. If 105a5118bdfSAndrew Thompson.Fa unref_device 106a5118bdfSAndrew Thompsonis set to 1 all devices are unref one time. 107a5118bdfSAndrew Thompson. 108a5118bdfSAndrew Thompson.Pp 109a5118bdfSAndrew Thompson. 110a5118bdfSAndrew Thompson.Ft uint8_t 111a5118bdfSAndrew Thompson.Fn libusb_get_bus_number "libusb_device *dev" 112a5118bdfSAndrew ThompsonReturns the number of the bus contained by the device 113a5118bdfSAndrew Thompson.Fa dev. 114a5118bdfSAndrew Thompson. 115a5118bdfSAndrew Thompson.Pp 116a5118bdfSAndrew Thompson. 117a5118bdfSAndrew Thompson.Ft uint8_t 118a5118bdfSAndrew Thompson.Fn libusb_get_device_address "libusb_device *dev" 119a5118bdfSAndrew ThompsonReturn the device_address contained by the device 120a5118bdfSAndrew Thompson.Fa dev. 121a5118bdfSAndrew Thompson. 122a5118bdfSAndrew Thompson.Pp 123a5118bdfSAndrew Thompson. 124a5118bdfSAndrew Thompson.Ft int 125a5118bdfSAndrew Thompson.Fn libusb_get_max_packet_size "libusb_device *dev" "unsigned char endpoint" 126a5118bdfSAndrew ThompsonReturn the wMaxPacketSize value on success, LIBUSB_ERROR_NOT_FOUND if the 127a5118bdfSAndrew Thompsonendpoint does not exist and LIBUSB_ERROR_OTHERS on other failure. 128a5118bdfSAndrew Thompson. 129a5118bdfSAndrew Thompson.Pp 130a5118bdfSAndrew Thompson. 131a5118bdfSAndrew Thompson.Ft libusb_device * 132a5118bdfSAndrew Thompson.Fn libusb_ref_device "libusb_device *dev" 133a5118bdfSAndrew ThompsonIncrement the reference counter of the device 134a5118bdfSAndrew Thompson.Fa dev. 135a5118bdfSAndrew Thompson. 136a5118bdfSAndrew Thompson.Pp 137a5118bdfSAndrew Thompson. 138a5118bdfSAndrew Thompson.Ft void 139a5118bdfSAndrew Thompson.Fn libusb_unref_device "libusb_device *dev" 140a5118bdfSAndrew ThompsonDecrement the reference counter of the device 141a5118bdfSAndrew Thompson.Fa dev. 142a5118bdfSAndrew Thompson. 143a5118bdfSAndrew Thompson.Pp 144a5118bdfSAndrew Thompson. 145a5118bdfSAndrew Thompson.Ft int 146a5118bdfSAndrew Thompson.Fn libusb_open "libusb_device *dev" "libusb_device_handle **devh" 147a5118bdfSAndrew ThompsonOpen a device and obtain a device_handle. Return 0 on success, 148a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_MEM on memory allocation problem, LIBUSB_ERROR_ACCESS 149a5118bdfSAndrew Thompsonon permission problem, LIBUSB_ERROR_NO_DEVICE if the device has been 150a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on error. 151a5118bdfSAndrew Thompson. 152a5118bdfSAndrew Thompson.Pp 153a5118bdfSAndrew Thompson. 154a5118bdfSAndrew Thompson.Ft libusb_device_handle * 155a5118bdfSAndrew Thompson.Fn libusb_open_device_with_vid_pid "libusb_context *ctx" "uint16_t vid" "uint16_t pid" 156f6ac2391SJoel DahlConvenience function to open a device with is 157a5118bdfSAndrew Thompson.Fa vid 1584eaae44dSAndrew Thompsonand 159a5118bdfSAndrew Thompson.Fa pid. 160a5118bdfSAndrew ThompsonReturn NULL on error. 1614eaae44dSAndrew Thompson. 1624eaae44dSAndrew Thompson.Pp 1634eaae44dSAndrew Thompson. 164a5118bdfSAndrew Thompson.Ft void 165a5118bdfSAndrew Thompson.Fn libusb_close "libusb_device_handle *devh" 166a5118bdfSAndrew ThompsonClose a device handle. 1674eaae44dSAndrew Thompson. 1684eaae44dSAndrew Thompson.Pp 1694eaae44dSAndrew Thompson. 170a5118bdfSAndrew Thompson.Ft libusb_device * 171a5118bdfSAndrew Thompson.Fn libusb_get_device(libusb_device_handle *devh) 172a5118bdfSAndrew ThompsonGet the device contained by devh. Return NULL on error. 1734eaae44dSAndrew Thompson. 1744eaae44dSAndrew Thompson.Pp 1754eaae44dSAndrew Thompson. 176a5118bdfSAndrew Thompson.Ft int 177a5118bdfSAndrew Thompson.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config" 178a5118bdfSAndrew ThompsonReturn the bConfiguration value of the current configuration. return 0 179a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected 180a5118bdfSAndrew Thompsonand a LIBUSB_ERROR code on error. 1814eaae44dSAndrew Thompson. 1824eaae44dSAndrew Thompson.Pp 1834eaae44dSAndrew Thompson. 184a5118bdfSAndrew Thompson.Ft int 185a5118bdfSAndrew Thompson.Fn libusb_set_configuration "libusb_device_handle *devh" "int config" 186a5118bdfSAndrew ThompsonSet the active configuration 187a5118bdfSAndrew Thompson.Fa config 188a5118bdfSAndrew Thompsonfor the device contained by 189a5118bdfSAndrew Thompson.Fa devh. 190a5118bdfSAndrew ThompsonThis function return 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested 191a5118bdfSAndrew Thompsonconfiguration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently 192a5118bdfSAndrew Thompsonclaimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a 193a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 1944eaae44dSAndrew Thompson. 1954eaae44dSAndrew Thompson.Pp 1964eaae44dSAndrew Thompson. 197a5118bdfSAndrew Thompson.Ft int 198a5118bdfSAndrew Thompson.Fn libusb_claim_interface "libusb_device_handle *devh" "int interface_number" 199a5118bdfSAndrew ThompsonClaim an interface in a given libusb_handle 200a5118bdfSAndrew Thompson.Fa devh. 201a5118bdfSAndrew ThompsonThis is a non-blocking function. It return 0 success, LIBUSB_ERROR_NOT_FOUND 202a5118bdfSAndrew Thompsonif the requested interface does not exist, LIBUSB_ERROR_BUSY if a program or 203a5118bdfSAndrew Thompsondriver has claimed the interface, LIBUSB_ERROR_NO_DEVICE if the device has 204a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure. 2054eaae44dSAndrew Thompson. 2064eaae44dSAndrew Thompson.Pp 2074eaae44dSAndrew Thompson. 208a5118bdfSAndrew Thompson.Ft int 209a5118bdfSAndrew Thompson.Fn libusb_release_interface "libusb_device_handle *devh" "int interface_number" 210a5118bdfSAndrew ThompsonThis function release an interface. All the claimed interface must be released 211a5118bdfSAndrew Thompsonbefore closing a device. Returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the 212799162a6SJoel Dahlinterface was not claimed, LIBUSB_ERROR_NO_DEVICE if the device has been 213a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR on failure. 2144eaae44dSAndrew Thompson. 2154eaae44dSAndrew Thompson.Pp 2164eaae44dSAndrew Thompson. 217a5118bdfSAndrew Thompson.Ft int 218a5118bdfSAndrew Thompson.Fn libusb_set_interface_alt_setting "libusb_device_handle *dev" "int interface_number" "int alternate_setting" 219a5118bdfSAndrew ThompsonActivate an alternate setting for an interface. Returns 0 on success, 220a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if the interface was not claimed or the requested 221a5118bdfSAndrew Thompsonsetting does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been 222a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR code on failure. 2234eaae44dSAndrew Thompson. 2244eaae44dSAndrew Thompson.Pp 2254eaae44dSAndrew Thompson. 226a5118bdfSAndrew Thompson.Ft int 227a5118bdfSAndrew Thompson.Fn libusb_clear_halt "libusb_device_handle *devh" "unsigned char endpoint" 228a5118bdfSAndrew ThompsonClear an halt/stall for a endpoint. Returns 0 on success, LIBUSB_ERROR_NOT_FOUND 229a5118bdfSAndrew Thompsonif the endpoint does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been 230a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on failure. 2314eaae44dSAndrew Thompson. 2324eaae44dSAndrew Thompson.Pp 2334eaae44dSAndrew Thompson. 234a5118bdfSAndrew Thompson.Ft int 235a5118bdfSAndrew Thompson.Fn libusb_reset_device "libusb_device_handle *devh" 236a5118bdfSAndrew ThompsonPerform an USB port reset for an usb device. Returns 0 on success, 237a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if re-enumeration is required or if the device has 238a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure. 2394eaae44dSAndrew Thompson. 2404eaae44dSAndrew Thompson.Pp 2414eaae44dSAndrew Thompson. 242a5118bdfSAndrew Thompson.Ft int 243f1b5fa6eSHans Petter Selasky.Fn libusb_check_connected "libusb_device_handle *devh" 244f1b5fa6eSHans Petter SelaskyTest if USB device is still connected. Returns 0 on success, 245f1b5fa6eSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if has been disconnected and a LIBUSB_ERROR 246f1b5fa6eSHans Petter Selaskycode on failure. 247f1b5fa6eSHans Petter Selasky. 248f1b5fa6eSHans Petter Selasky.Pp 249f1b5fa6eSHans Petter Selasky. 250f1b5fa6eSHans Petter Selasky.Ft int 251a5118bdfSAndrew Thompson.Fn libusb_kernel_driver_active "libusb_device_handle *devh" "int interface" 252a5118bdfSAndrew ThompsonDetermine if a driver is active on a interface. Returns 0 if no kernel driver 253a5118bdfSAndrew Thompsonis active, returns 1 if a kernel driver is active, returns LIBUSB_ERROR_NO_DEVICE 254a5118bdfSAndrew Thompsonif the device has been disconnected and return a LIBUSB_ERROR code on failure. 2554eaae44dSAndrew Thompson. 2564eaae44dSAndrew Thompson.Pp 2574eaae44dSAndrew Thompson. 258a5118bdfSAndrew Thompson.Ft int 259698e791aSHans Petter Selasky.Fn libusb_get_driver "libusb_device_handle *devh" "int interface" "char *name" "int namelen" 260698e791aSHans Petter Selaskyor 261698e791aSHans Petter Selasky.Ft int 262698e791aSHans Petter Selasky.Fn libusb_get_driver_np "libusb_device_handle *devh" "int interface" "char *name" "int namelen" 263698e791aSHans Petter SelaskyGets the name of the driver attached to the given 264698e791aSHans Petter Selasky.Fa device 265698e791aSHans Petter Selaskyand 266698e791aSHans Petter Selasky.Fa interface 267698e791aSHans Petter Selaskyinto the buffer given by 268698e791aSHans Petter Selasky.Fa name 269698e791aSHans Petter Selaskyand 270698e791aSHans Petter Selasky.Fa namelen . 271698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver is attached 272698e791aSHans Petter Selaskyto the given interface and LIBUSB_ERROR_INVALID_PARAM if the interface does 273698e791aSHans Petter Selaskynot exist. 274698e791aSHans Petter SelaskyThis function is non-portable. 275698e791aSHans Petter SelaskyThe buffer pointed to by 276698e791aSHans Petter Selasky.Fa name 277698e791aSHans Petter Selaskyis only zero terminated on success. 278698e791aSHans Petter Selasky. 279698e791aSHans Petter Selasky.Pp 280698e791aSHans Petter Selasky. 281698e791aSHans Petter Selasky.Ft int 282a5118bdfSAndrew Thompson.Fn libusb_detach_kernel_driver "libusb_device_handle *devh" "int interface" 283698e791aSHans Petter Selaskyor 284698e791aSHans Petter Selasky.Ft int 285698e791aSHans Petter Selasky.Fn libusb_detach_kernel_driver_np "libusb_device_handle *devh" "int interface" 286698e791aSHans Petter SelaskyDetach a kernel driver from an interface. 287698e791aSHans Petter SelaskyThis is needed to claim an interface required by a kernel driver. 288698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver was active, 289698e791aSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a LIBUSB_ERROR code on failure. This function is non-portable. 2904eaae44dSAndrew Thompson. 2914eaae44dSAndrew Thompson.Pp 2924eaae44dSAndrew Thompson. 293a5118bdfSAndrew Thompson.Ft int 294a5118bdfSAndrew Thompson.Fn libusb_attach_kernel_driver "libusb_device_handle *devh" "int interface" 295a5118bdfSAndrew ThompsonRe-attach an interface kernel driver previously detached. Returns 0 on success, 296a5118bdfSAndrew ThompsonLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, LIBUSB_ERROR_NO_DEVICE 297a5118bdfSAndrew Thompsonif the device has been disconnect, LIBUSB_ERROR_BUSY if the driver cannot be 298a5118bdfSAndrew Thompsonattached because the interface is claimed by a program or driver and a 299a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 3004eaae44dSAndrew Thompson. 3014eaae44dSAndrew Thompson.Pp 3024eaae44dSAndrew Thompson. 303a5118bdfSAndrew Thompson.Sh USB DESCRIPTORS 3044eaae44dSAndrew Thompson. 3054eaae44dSAndrew Thompson.Pp 3064eaae44dSAndrew Thompson. 307a5118bdfSAndrew Thompson.Ft int 308a5118bdfSAndrew Thompson.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc" 309a5118bdfSAndrew ThompsonGet the USB device descriptor for the device 310a5118bdfSAndrew Thompson.Fa dev. 311a5118bdfSAndrew ThompsonThis is a non-blocking function. Returns 0 on success and a LIBUSB_ERROR code on 312a5118bdfSAndrew Thompsonfailure. 3134eaae44dSAndrew Thompson. 3144eaae44dSAndrew Thompson.Pp 315a5118bdfSAndrew Thompson.Ft int 316698e791aSHans Petter Selasky.Fn libsub_get_active_config_descriptor "libusb_device *dev" "struct libusb_config_descriptor **config" 317a5118bdfSAndrew ThompsonGet the USB configuration descriptor for the active configuration. Returns 0 on 318a5118bdfSAndrew Thompsonsuccess, returns LIBUSB_ERROR_NOT_FOUND if the device is in unconfigured state 319a5118bdfSAndrew Thompsonand return another LIBUSB_ERROR code on error. 3204eaae44dSAndrew Thompson. 3214eaae44dSAndrew Thompson.Pp 322a5118bdfSAndrew Thompson.Ft int 323a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor "libusb_device *dev" "uint8_t config_index" "libusb_config_descriptor **config" 324a5118bdfSAndrew ThompsonGet USB configuration descriptor based on its index 325a5118bdfSAndrew Thompson.Fa idx. 326a5118bdfSAndrew ThompsonReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist 327a5118bdfSAndrew Thompsonand returns another LIBUSB_ERROR code on error. 328545b01adSAndrew Thompson. 329545b01adSAndrew Thompson.Pp 330a5118bdfSAndrew Thompson.Ft int 331a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor_by_value "libusb_device *dev" "uint8 bConfigurationValue" "libusb_config_descriptor **config" 332a5118bdfSAndrew ThompsonGet a USB configuration descriptor with a specific bConfigurationValue. This is 333a5118bdfSAndrew Thompsona non-blocking function which does not send request through the device. Returns 0 334a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist and another 335a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 3364eaae44dSAndrew Thompson. 3374eaae44dSAndrew Thompson.Pp 338a5118bdfSAndrew Thompson.Ft void 339390065b1SAlfred Perlstein.Fn libusb_free_config_descriptor "libusb_config_descriptor *config" 340a5118bdfSAndrew ThompsonFree a configuration descriptor. 3414eaae44dSAndrew Thompson. 3424eaae44dSAndrew Thompson.Pp 343a5118bdfSAndrew Thompson.Ft int 344a5118bdfSAndrew Thompson.Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length" 345a5118bdfSAndrew ThompsonRetrieve a string descriptor in C style ascii. Returns a number of byte on success 346a5118bdfSAndrew Thompsonand a LIBUSB_ERROR code on failure. 3474eaae44dSAndrew Thompson. 3484eaae44dSAndrew Thompson.Pp 3494eaae44dSAndrew Thompson. 350a5118bdfSAndrew Thompson.Sh USB ASYNCHRONOUS I/O 3514eaae44dSAndrew Thompson. 3524eaae44dSAndrew Thompson.Pp 353a5118bdfSAndrew Thompson.Ft struct libusb_transfer * 354a5118bdfSAndrew Thompson.Fn libusb_alloc_transfer "int iso_packets" 355a5118bdfSAndrew ThompsonAllocate a transfer with 356a5118bdfSAndrew Thompson.Fa iso_packets 357a5118bdfSAndrew Thompsonnumbers of isochronous packet descriptors. Returns NULL on error. 3584eaae44dSAndrew Thompson. 3594eaae44dSAndrew Thompson.Pp 360a5118bdfSAndrew Thompson.Ft void 361a5118bdfSAndrew Thompson.Fn libusb_free_transfer "struct libusb_transfer *tr" 362a5118bdfSAndrew ThompsonFree a transfer. 3634eaae44dSAndrew Thompson. 3644eaae44dSAndrew Thompson.Pp 365a5118bdfSAndrew Thompson.Ft int 366a5118bdfSAndrew Thompson.Fn libusb_submit_transfer "struct libusb_transfer *tr" 367a5118bdfSAndrew ThompsonThis function will submit a transfer and returns immediately. Returns 0 on 368a5118bdfSAndrew Thompsonsuccess, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 369a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure. 3704eaae44dSAndrew Thompson. 3714eaae44dSAndrew Thompson.Pp 372a5118bdfSAndrew Thompson.Ft int 373a5118bdfSAndrew Thompson.Fn libusb_cancel_transfer "struct libusb_transfer *tr" 374a5118bdfSAndrew ThompsonThis function asynchronously cancel a transfer. Returns 0 on success and 375a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 3764eaae44dSAndrew Thompson. 3774eaae44dSAndrew Thompson.Pp 378a5118bdfSAndrew Thompson.Sh USB SYNCHRONOUS I/O 3794eaae44dSAndrew Thompson. 3804eaae44dSAndrew Thompson.Pp 381a5118bdfSAndrew Thompson.Ft int 382698e791aSHans 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" 383*c865d740SHans Petter SelaskyPerform a USB control transfer. Returns the actual number of bytes 384*c865d740SHans Petter Selaskytransferred on success in the range from and including zero until and 385*c865d740SHans Petter Selaskyincluding 386*c865d740SHans Petter Selasky.Xa wLength . 387*c865d740SHans Petter SelaskyOn error a libusb error code is returned, for example 388*c865d740SHans Petter SelaskyLIBUSB_ERROR_TIMEOUT if the transfer timeout, LIBUSB_ERROR_PIPE if the 389*c865d740SHans Petter Selaskycontrol request was not supported, LIBUSB_ERROR_NO_DEVICE if the 390*c865d740SHans Petter Selaskydevice has been disconnected or another LIBUSB_ERROR code on other failures. 391*c865d740SHans Petter SelaskyThe libusb error codes are always negative. 3924eaae44dSAndrew Thompson. 3934eaae44dSAndrew Thompson.Pp 394a5118bdfSAndrew Thompson.Ft int 395a5118bdfSAndrew Thompson.Fn libusb_bulk_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout" 396a5118bdfSAndrew ThompsonPerform an USB bulk transfer. Returns 0 on success, LIBUSB_ERROR_TIMEOUT 397a5118bdfSAndrew Thompsonif the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not 398a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data, 399a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 400a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure. 4014eaae44dSAndrew Thompson. 4024eaae44dSAndrew Thompson.Pp 403a5118bdfSAndrew Thompson.Ft int 404a5118bdfSAndrew Thompson.Fn libusb_interrupt_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout" 405a5118bdfSAndrew ThompsonPerform an USB Interrupt transfer. Returns 0 on success, LIBUSB_ERROR_TIMEOUT 406a5118bdfSAndrew Thompsonif the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not 407a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data, 408a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 409a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure. 4104eaae44dSAndrew Thompson. 4114eaae44dSAndrew Thompson.Pp 412a5118bdfSAndrew Thompson.Sh USB EVENTS 4134eaae44dSAndrew Thompson. 4144eaae44dSAndrew Thompson.Pp 415a5118bdfSAndrew Thompson.Ft int 416a5118bdfSAndrew Thompson.Fn libusb_try_lock_events "libusb_context *ctx" 417a5118bdfSAndrew ThompsonTry to acquire the event handling lock. Returns 0 if the lock was obtained and 1 418a5118bdfSAndrew Thompsonif not. 4194eaae44dSAndrew Thompson. 4204eaae44dSAndrew Thompson.Pp 421a5118bdfSAndrew Thompson.Ft void 422a5118bdfSAndrew Thompson.Fn libusb_lock_events "libusb_context *ctx" 423a5118bdfSAndrew ThompsonAcquire the event handling lock. This function is blocking. 4244eaae44dSAndrew Thompson. 4254eaae44dSAndrew Thompson.Pp 426a5118bdfSAndrew Thompson.Ft void 427a5118bdfSAndrew Thompson.Fn libusb_unlock_events "libusb_context *ctx" 428a5118bdfSAndrew ThompsonRelease the event handling lock. This will wake up any thread blocked 429a5118bdfSAndrew Thompsonon libusb_wait_for_event(). 4304eaae44dSAndrew Thompson. 4314eaae44dSAndrew Thompson.Pp 432a5118bdfSAndrew Thompson.Ft int 433a5118bdfSAndrew Thompson.Fn libusb_event_handling_ok "libusb_context *ctx" 434a5118bdfSAndrew ThompsonDetermine if it still OK for this thread to be doing event handling. Returns 1 435a5118bdfSAndrew Thompsonif event handling can start or continue. Returns 0 if this thread must give up 436a5118bdfSAndrew Thompsonthe events lock. 4374eaae44dSAndrew Thompson. 4384eaae44dSAndrew Thompson.Pp 439a5118bdfSAndrew Thompson.Ft int 440a5118bdfSAndrew Thompson.Fn libusb_event_handler_active "libusb_context *ctx" 441a5118bdfSAndrew ThompsonDetermine if an active thread is handling events. Returns 1 if yes and 0 if there 442a5118bdfSAndrew Thompsonare no threads currently handling events. 4434eaae44dSAndrew Thompson. 4444eaae44dSAndrew Thompson.Pp 445a5118bdfSAndrew Thompson.Ft void 446a5118bdfSAndrew Thompson.Fn libusb_lock_event_waiters "libusb_context *ctx" 447a5118bdfSAndrew ThompsonAcquire the event_waiters lock. This lock is designed to be obtained under the 448a5118bdfSAndrew Thompsonsituation where you want to be aware when events are completed, but some other 449a5118bdfSAndrew Thompsonthread is event handling so calling libusb_handle_events() is not allowed. 4504eaae44dSAndrew Thompson. 451545b01adSAndrew Thompson.Pp 452a5118bdfSAndrew Thompson.Ft void 453a5118bdfSAndrew Thompson.Fn libusb_unlock_event_waiters "libusb_context *ctx" 454a5118bdfSAndrew ThompsonRelease the event_waiters lock. 4554eaae44dSAndrew Thompson. 4564eaae44dSAndrew Thompson.Pp 457a5118bdfSAndrew Thompson.Ft int 458a5118bdfSAndrew Thompson.Fn libusb_wait_for_event "libusb_context *ctx" "struct timeval *tv" 459a5118bdfSAndrew ThompsonWait for another thread to signal completion of an event. Must be called 460a5118bdfSAndrew Thompsonwith the event waiters lock held, see libusb_lock_event_waiters(). This will 461a5118bdfSAndrew Thompsonblock until the timeout expires or a transfer completes or a thread releases 462a5118bdfSAndrew Thompsonthe event handling lock through libusb_unlock_events(). Returns 0 after a 463a5118bdfSAndrew Thompsontransfer completes or another thread stops event handling, returns 1 if the 464a5118bdfSAndrew Thompsontimeout expired. 4654eaae44dSAndrew Thompson. 4664eaae44dSAndrew Thompson.Pp 467a5118bdfSAndrew Thompson.Ft int 468a5118bdfSAndrew Thompson.Fn libusb_handle_events_timeout "libusb_context *ctx" "struct timeval *tv" 469a5118bdfSAndrew ThompsonHandle any pending events by checking if timeouts have expired and by 470a5118bdfSAndrew Thompsonchecking the set of file descriptors for activity. Returns 0 on success, or a 471a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 4724eaae44dSAndrew Thompson. 4734eaae44dSAndrew Thompson.Pp 474a5118bdfSAndrew Thompson.Ft int 475a5118bdfSAndrew Thompson.Fn libusb_handle_events "libusb_context *ctx" 476a5118bdfSAndrew ThompsonHandle any pending events in blocking mode with a sensible timeout. Returns 0 477a5118bdfSAndrew Thompsonon success, returns a LIBUSB_ERROR code on failure. 4784eaae44dSAndrew Thompson. 4794eaae44dSAndrew Thompson.Pp 480a5118bdfSAndrew Thompson.Ft int 481a5118bdfSAndrew Thompson.Fn libusb_handle_events_locked "libusb_context *ctx" "struct timeval *tv" 482a5118bdfSAndrew ThompsonHandle any pending events by polling file desciptors, without checking if 483a5118bdfSAndrew Thompsonanother threads are already doing so. Must be called with the event lock held. 4844eaae44dSAndrew Thompson. 4854eaae44dSAndrew Thompson.Pp 486a5118bdfSAndrew Thompson.Ft int 487a5118bdfSAndrew Thompson.Fn libusb_get_next_timeout "libusb_context *ctx" "struct timeval *tv" 488a5118bdfSAndrew ThompsonDetermine the next internal timeout that libusb needs to handle. Returns 0 489a5118bdfSAndrew Thompsonif there are no pending timeouts, 1 if a timeout was returned, or LIBUSB_ERROR 490a5118bdfSAndrew Thompsoncode on failure. 4914eaae44dSAndrew Thompson. 4924eaae44dSAndrew Thompson.Pp 493a5118bdfSAndrew Thompson.Ft void 494a5118bdfSAndrew Thompson.Fn libusb_set_pollfd_notifiers "libusb_context *ctx" "libusb_pollfd_added_cb added_cb" "libusb_pollfd_removed_cb remove_cb" "void *user_data" 495a5118bdfSAndrew ThompsonRegister notification functions for file descriptor additions/removals. 496a5118bdfSAndrew ThompsonThese functions will be invoked for every new or removed file descriptor 497a5118bdfSAndrew Thompsonthat libusb uses as an event source. 4984eaae44dSAndrew Thompson. 4994eaae44dSAndrew Thompson.Pp 500a5118bdfSAndrew Thompson.Ft const struct libusb_pollfd ** 501a5118bdfSAndrew Thompson.Fn libusb_get_pollfds "libusb_context *ctx" 502a5118bdfSAndrew ThompsonRetrive a list of file descriptors that should be polled by your main loop as 503a5118bdfSAndrew Thompsonlibusb event sources. Returns a NULL-terminated list on success or NULL on failure. 5044eaae44dSAndrew Thompson. 5054eaae44dSAndrew Thompson.Sh LIBUSB VERSION 0.1 COMPATIBILITY 506a5118bdfSAndrew Thompson.Pp 507a5118bdfSAndrew ThompsonThe library is also compliant with LibUSB version 0.1.12. 508a5118bdfSAndrew Thompson.Pp 5094eaae44dSAndrew Thompson.Fn usb_open 5104eaae44dSAndrew Thompson.Fn usb_close 5114eaae44dSAndrew Thompson.Fn usb_get_string 5124eaae44dSAndrew Thompson.Fn usb_get_string_simple 5134eaae44dSAndrew Thompson.Fn usb_get_descriptor_by_endpoint 5144eaae44dSAndrew Thompson.Fn usb_get_descriptor 5154eaae44dSAndrew Thompson.Fn usb_parse_descriptor 5164eaae44dSAndrew Thompson.Fn usb_parse_configuration 5174eaae44dSAndrew Thompson.Fn usb_destroy_configuration 5184eaae44dSAndrew Thompson.Fn usb_fetch_and_parse_descriptors 5194eaae44dSAndrew Thompson.Fn usb_bulk_write 5204eaae44dSAndrew Thompson.Fn usb_bulk_read 5214eaae44dSAndrew Thompson.Fn usb_interrupt_write 5224eaae44dSAndrew Thompson.Fn usb_interrupt_read 5234eaae44dSAndrew Thompson.Fn usb_control_msg 5244eaae44dSAndrew Thompson.Fn usb_set_configuration 5254eaae44dSAndrew Thompson.Fn usb_claim_interface 5264eaae44dSAndrew Thompson.Fn usb_release_interface 5274eaae44dSAndrew Thompson.Fn usb_set_altinterface 5284eaae44dSAndrew Thompson.Fn usb_resetep 5294eaae44dSAndrew Thompson.Fn usb_clear_halt 5304eaae44dSAndrew Thompson.Fn usb_reset 5314eaae44dSAndrew Thompson.Fn usb_strerror 5324eaae44dSAndrew Thompson.Fn usb_init 5334eaae44dSAndrew Thompson.Fn usb_set_debug 5344eaae44dSAndrew Thompson.Fn usb_find_busses 5354eaae44dSAndrew Thompson.Fn usb_find_devices 5364eaae44dSAndrew Thompson.Fn usb_device 5374eaae44dSAndrew Thompson.Fn usb_get_busses 538f1b5fa6eSHans Petter Selasky.Fn usb_check_connected 5394eaae44dSAndrew Thompson. 5404eaae44dSAndrew Thompson.Sh SEE ALSO 541a5118bdfSAndrew Thompson.Xr libusb20 3 , 542c54c1f7cSAndrew Thompson.Xr usb 4 , 5434eaae44dSAndrew Thompson.Xr usbconfig 8 544a5118bdfSAndrew Thompson.Pp 545a5118bdfSAndrew Thompson.Pa http://libusb.sourceforge.net/ 5464eaae44dSAndrew Thompson. 5474eaae44dSAndrew Thompson.Sh HISTORY 5484eaae44dSAndrew Thompson. 5494eaae44dSAndrew Thompson.Nm 550a5118bdfSAndrew Thompsonsupport first appeared in 551a5118bdfSAndrew Thompson.Fx 8.0 . 552