14eaae44dSAndrew Thompson.\" 2a5118bdfSAndrew Thompson.\" Copyright (c) 2009 Sylvestre Gallon 34eaae44dSAndrew Thompson.\" 44eaae44dSAndrew Thompson.\" All rights reserved. 54eaae44dSAndrew Thompson.\" 64eaae44dSAndrew Thompson.\" Redistribution and use in source and binary forms, with or without 74eaae44dSAndrew Thompson.\" modification, are permitted provided that the following conditions 84eaae44dSAndrew Thompson.\" are met: 94eaae44dSAndrew Thompson.\" 1. Redistributions of source code must retain the above copyright 104eaae44dSAndrew Thompson.\" notice, this list of conditions and the following disclaimer. 114eaae44dSAndrew Thompson.\" 2. Redistributions in binary form must reproduce the above copyright 124eaae44dSAndrew Thompson.\" notice, this list of conditions and the following disclaimer in the 134eaae44dSAndrew Thompson.\" documentation and/or other materials provided with the distribution. 144eaae44dSAndrew Thompson.\" 154eaae44dSAndrew Thompson.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 164eaae44dSAndrew Thompson.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 174eaae44dSAndrew Thompson.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 184eaae44dSAndrew Thompson.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 194eaae44dSAndrew Thompson.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 204eaae44dSAndrew Thompson.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 214eaae44dSAndrew Thompson.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 224eaae44dSAndrew Thompson.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 234eaae44dSAndrew Thompson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 244eaae44dSAndrew Thompson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 254eaae44dSAndrew Thompson.\" SUCH DAMAGE. 264eaae44dSAndrew Thompson.\" 274eaae44dSAndrew Thompson.\" $FreeBSD$ 284eaae44dSAndrew Thompson.\" 29ca96e26aSHans Petter Selasky.Dd August 16, 2011 304eaae44dSAndrew Thompson.Dt LIBUSB 3 314eaae44dSAndrew Thompson.Os 324eaae44dSAndrew Thompson.Sh NAME 334eaae44dSAndrew Thompson.Nm libusb 344eaae44dSAndrew Thompson.Nd "USB access library" 354eaae44dSAndrew Thompson.Sh LIBRARY 36*11867070SHans Petter SelaskyUSB access library 37*11867070SHans 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 464eaae44dSAndrew Thompson.Pp 47a5118bdfSAndrew Thompson.Ft int 48a5118bdfSAndrew Thompson.Fn libusb_init libusb_context **ctx 49c8c1f2ecSHans Petter SelaskyThis function initialises libusb. 50*11867070SHans Petter SelaskyIt must be called at the beginning 51*11867070SHans Petter Selaskyof the program, before other libusb routines are used. 52c8c1f2ecSHans Petter SelaskyThis function returns 0 on success or LIBUSB_ERROR on 53a5118bdfSAndrew Thompsonfailure. 544eaae44dSAndrew Thompson.Pp 55a5118bdfSAndrew Thompson.Ft void 56a5118bdfSAndrew Thompson.Fn libusb_exit "libusb_context *ctx" 57c8c1f2ecSHans Petter SelaskyDeinitialise libusb. 58c8c1f2ecSHans Petter SelaskyMust be called at the end of the application. 59*11867070SHans Petter SelaskyOther libusb routines may not be called after this function. 60a5118bdfSAndrew Thompson.Pp 61698e791aSHans Petter Selasky.Ft const char * 62698e791aSHans Petter Selasky.Fn libusb_strerror "int code" 63*11867070SHans Petter SelaskyGet the ASCII representation of the error given by the 64698e791aSHans Petter Selasky.Fa code 65698e791aSHans Petter Selaskyargument. 66698e791aSHans Petter Selasky.Pp 67a5118bdfSAndrew Thompson.Ft void 68a5118bdfSAndrew Thompson.Fn libusb_set_debug "libusb_context *ctx" "int level" 69*11867070SHans Petter SelaskySet the debug level to 70*11867070SHans Petter Selasky.Fa level . 71a5118bdfSAndrew Thompson.Pp 72a5118bdfSAndrew Thompson.Ft ssize_t 73a5118bdfSAndrew Thompson.Fn libusb_get_device_list "libusb_context *ctx" "libusb_device ***list" 74*11867070SHans Petter SelaskyPopulate 75a5118bdfSAndrew Thompson.Fa list 76*11867070SHans Petter Selaskywith the list of usb devices available, adding a reference to each 77*11867070SHans Petter Selaskydevice in the list. 78*11867070SHans Petter SelaskyAll the list entries created by this 79*11867070SHans Petter Selaskyfunction must have their reference counter 80*11867070SHans Petter Selaskydecremented when you are done with them, 81*11867070SHans Petter Selaskyand the list itself must be freed. 82c8c1f2ecSHans Petter SelaskyThis 83*11867070SHans Petter Selaskyfunction returns the number of devices in the list or a LIBUSB_ERROR code. 84a5118bdfSAndrew Thompson.Pp 85a5118bdfSAndrew Thompson.Ft void 86a5118bdfSAndrew Thompson.Fn libusb_free_device_list "libusb_device **list" "int unref_devices" 87c8c1f2ecSHans Petter SelaskyFree the list of devices discovered by libusb_get_device_list. 88c8c1f2ecSHans Petter SelaskyIf 89a5118bdfSAndrew Thompson.Fa unref_device 90*11867070SHans Petter Selaskyis set to 1 all devices in the list have their reference 91*11867070SHans Petter Selaskycounter decremented once. 92a5118bdfSAndrew Thompson.Pp 93a5118bdfSAndrew Thompson.Ft uint8_t 94a5118bdfSAndrew Thompson.Fn libusb_get_bus_number "libusb_device *dev" 95a5118bdfSAndrew ThompsonReturns the number of the bus contained by the device 96a5118bdfSAndrew Thompson.Fa dev. 97a5118bdfSAndrew Thompson.Pp 98a5118bdfSAndrew Thompson.Ft uint8_t 99a5118bdfSAndrew Thompson.Fn libusb_get_device_address "libusb_device *dev" 100ca96e26aSHans Petter SelaskyReturns the device_address contained by the device 101a5118bdfSAndrew Thompson.Fa dev. 102a5118bdfSAndrew Thompson.Pp 103ca96e26aSHans Petter Selasky.Ft enum libusb_speed 104ca96e26aSHans Petter Selasky.Fn libusb_get_device_speed "libusb_device *dev" 105ca96e26aSHans Petter SelaskyReturns the wire speed at which the device is connected. 106ca96e26aSHans Petter SelaskySee the LIBUSB_SPEED_XXX enums for more information. 107ca96e26aSHans Petter SelaskyLIBUSB_SPEED_UNKNOWN is returned in case of unknown wire speed. 108ca96e26aSHans Petter Selasky.Pp 109a5118bdfSAndrew Thompson.Ft int 110a5118bdfSAndrew Thompson.Fn libusb_get_max_packet_size "libusb_device *dev" "unsigned char endpoint" 111ca96e26aSHans Petter SelaskyReturns the wMaxPacketSize value on success, LIBUSB_ERROR_NOT_FOUND if the 112a5118bdfSAndrew Thompsonendpoint does not exist and LIBUSB_ERROR_OTHERS on other failure. 113a5118bdfSAndrew Thompson.Pp 114a5118bdfSAndrew Thompson.Ft libusb_device * 115a5118bdfSAndrew Thompson.Fn libusb_ref_device "libusb_device *dev" 116a5118bdfSAndrew ThompsonIncrement the reference counter of the device 117a5118bdfSAndrew Thompson.Fa dev. 118a5118bdfSAndrew Thompson.Pp 119a5118bdfSAndrew Thompson.Ft void 120a5118bdfSAndrew Thompson.Fn libusb_unref_device "libusb_device *dev" 121a5118bdfSAndrew ThompsonDecrement the reference counter of the device 122a5118bdfSAndrew Thompson.Fa dev. 123a5118bdfSAndrew Thompson.Pp 124a5118bdfSAndrew Thompson.Ft int 125a5118bdfSAndrew Thompson.Fn libusb_open "libusb_device *dev" "libusb_device_handle **devh" 126c8c1f2ecSHans Petter SelaskyOpen a device and obtain a device_handle. 127c8c1f2ecSHans Petter SelaskyReturns 0 on success, 128*11867070SHans Petter SelaskyLIBUSB_ERROR_NO_MEM on memory allocation problems, LIBUSB_ERROR_ACCESS 129*11867070SHans Petter Selaskyon permissions problems, LIBUSB_ERROR_NO_DEVICE if the device has been 130*11867070SHans Petter Selaskydisconnected and a LIBUSB_ERROR code on other errors. 131a5118bdfSAndrew Thompson.Pp 132a5118bdfSAndrew Thompson.Ft libusb_device_handle * 133a5118bdfSAndrew Thompson.Fn libusb_open_device_with_vid_pid "libusb_context *ctx" "uint16_t vid" "uint16_t pid" 134*11867070SHans Petter SelaskyA convenience function to open a device by vendor and product IDs 135a5118bdfSAndrew Thompson.Fa vid 1364eaae44dSAndrew Thompsonand 137a5118bdfSAndrew Thompson.Fa pid. 138ca96e26aSHans Petter SelaskyReturns NULL on error. 1394eaae44dSAndrew Thompson.Pp 140a5118bdfSAndrew Thompson.Ft void 141a5118bdfSAndrew Thompson.Fn libusb_close "libusb_device_handle *devh" 142a5118bdfSAndrew ThompsonClose a device handle. 1434eaae44dSAndrew Thompson.Pp 144a5118bdfSAndrew Thompson.Ft libusb_device * 145ca96e26aSHans Petter Selasky.Fn libusb_get_device "libusb_device_handle *devh" 146ca96e26aSHans Petter SelaskyGet the device contained by devh. 147ca96e26aSHans Petter SelaskyReturns NULL on error. 1484eaae44dSAndrew Thompson.Pp 149a5118bdfSAndrew Thompson.Ft int 150a5118bdfSAndrew Thompson.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config" 151c8c1f2ecSHans Petter SelaskyReturns the bConfiguration value of the current configuration. 152c8c1f2ecSHans Petter SelaskyReturns 0 153a5118bdfSAndrew Thompsonon success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected 154a5118bdfSAndrew Thompsonand a LIBUSB_ERROR code on error. 1554eaae44dSAndrew Thompson.Pp 156a5118bdfSAndrew Thompson.Ft int 157a5118bdfSAndrew Thompson.Fn libusb_set_configuration "libusb_device_handle *devh" "int config" 158*11867070SHans Petter SelaskySet the active configuration to 159a5118bdfSAndrew Thompson.Fa config 160a5118bdfSAndrew Thompsonfor the device contained by 161a5118bdfSAndrew Thompson.Fa devh. 162ca96e26aSHans Petter SelaskyThis function returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested 163a5118bdfSAndrew Thompsonconfiguration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently 164a5118bdfSAndrew Thompsonclaimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a 165a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 1664eaae44dSAndrew Thompson.Pp 167a5118bdfSAndrew Thompson.Ft int 168a5118bdfSAndrew Thompson.Fn libusb_claim_interface "libusb_device_handle *devh" "int interface_number" 169a5118bdfSAndrew ThompsonClaim an interface in a given libusb_handle 170a5118bdfSAndrew Thompson.Fa devh. 171c8c1f2ecSHans Petter SelaskyThis is a non-blocking function. 172*11867070SHans Petter SelaskyIt returns 0 on success, LIBUSB_ERROR_NOT_FOUND 173a5118bdfSAndrew Thompsonif the requested interface does not exist, LIBUSB_ERROR_BUSY if a program or 174a5118bdfSAndrew Thompsondriver has claimed the interface, LIBUSB_ERROR_NO_DEVICE if the device has 175a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure. 1764eaae44dSAndrew Thompson.Pp 177a5118bdfSAndrew Thompson.Ft int 178a5118bdfSAndrew Thompson.Fn libusb_release_interface "libusb_device_handle *devh" "int interface_number" 179*11867070SHans Petter SelaskyThis function releases an interface. 180*11867070SHans Petter SelaskyAll the claimed interfaces on a device must be released 181*11867070SHans Petter Selaskybefore closing the device. 182c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the 183799162a6SJoel Dahlinterface was not claimed, LIBUSB_ERROR_NO_DEVICE if the device has been 184a5118bdfSAndrew Thompsondisconnected and LIBUSB_ERROR on failure. 1854eaae44dSAndrew Thompson.Pp 186a5118bdfSAndrew Thompson.Ft int 187a5118bdfSAndrew Thompson.Fn libusb_set_interface_alt_setting "libusb_device_handle *dev" "int interface_number" "int alternate_setting" 188c8c1f2ecSHans Petter SelaskyActivate an alternate setting for an interface. 189c8c1f2ecSHans Petter SelaskyReturns 0 on success, 190a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if the interface was not claimed or the requested 191a5118bdfSAndrew Thompsonsetting does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been 192*11867070SHans Petter Selaskydisconnected and a LIBUSB_ERROR code on failure. 1934eaae44dSAndrew Thompson.Pp 194a5118bdfSAndrew Thompson.Ft int 195a5118bdfSAndrew Thompson.Fn libusb_clear_halt "libusb_device_handle *devh" "unsigned char endpoint" 196c8c1f2ecSHans Petter SelaskyClear an halt/stall for a endpoint. 197c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND 198a5118bdfSAndrew Thompsonif the endpoint does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been 199a5118bdfSAndrew Thompsondisconnected and a LIBUSB_ERROR code on failure. 2004eaae44dSAndrew Thompson.Pp 201a5118bdfSAndrew Thompson.Ft int 202a5118bdfSAndrew Thompson.Fn libusb_reset_device "libusb_device_handle *devh" 203c8c1f2ecSHans Petter SelaskyPerform an USB port reset for an usb device. 204c8c1f2ecSHans Petter SelaskyReturns 0 on success, 205a5118bdfSAndrew ThompsonLIBUSB_ERROR_NOT_FOUND if re-enumeration is required or if the device has 206a5118bdfSAndrew Thompsonbeen disconnected and a LIBUSB_ERROR code on failure. 2074eaae44dSAndrew Thompson.Pp 208a5118bdfSAndrew Thompson.Ft int 209f1b5fa6eSHans Petter Selasky.Fn libusb_check_connected "libusb_device_handle *devh" 210*11867070SHans Petter SelaskyTest if the USB device is still connected. 211c8c1f2ecSHans Petter SelaskyReturns 0 on success, 212*11867070SHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if it has been disconnected and a LIBUSB_ERROR 213f1b5fa6eSHans Petter Selaskycode on failure. 214f1b5fa6eSHans Petter Selasky.Pp 215f1b5fa6eSHans Petter Selasky.Ft int 216a5118bdfSAndrew Thompson.Fn libusb_kernel_driver_active "libusb_device_handle *devh" "int interface" 217c8c1f2ecSHans Petter SelaskyDetermine if a driver is active on a interface. 218c8c1f2ecSHans Petter SelaskyReturns 0 if no kernel driver 219*11867070SHans Petter Selaskyis active, 1 if a kernel driver is active, LIBUSB_ERROR_NO_DEVICE 220*11867070SHans Petter Selaskyif the device has been disconnected and a LIBUSB_ERROR code on failure. 2214eaae44dSAndrew Thompson.Pp 222a5118bdfSAndrew Thompson.Ft int 223698e791aSHans Petter Selasky.Fn libusb_get_driver "libusb_device_handle *devh" "int interface" "char *name" "int namelen" 224698e791aSHans Petter Selaskyor 225698e791aSHans Petter Selasky.Ft int 226698e791aSHans Petter Selasky.Fn libusb_get_driver_np "libusb_device_handle *devh" "int interface" "char *name" "int namelen" 227*11867070SHans Petter SelaskyCopy the name of the driver attached to the given 228698e791aSHans Petter Selasky.Fa device 229698e791aSHans Petter Selaskyand 230698e791aSHans Petter Selasky.Fa interface 231*11867070SHans Petter Selaskyinto the buffer 232698e791aSHans Petter Selasky.Fa name 233*11867070SHans Petter Selaskyof length 234698e791aSHans Petter Selasky.Fa namelen . 235698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver is attached 236698e791aSHans Petter Selaskyto the given interface and LIBUSB_ERROR_INVALID_PARAM if the interface does 237698e791aSHans Petter Selaskynot exist. 238698e791aSHans Petter SelaskyThis function is non-portable. 239698e791aSHans Petter SelaskyThe buffer pointed to by 240698e791aSHans Petter Selasky.Fa name 241698e791aSHans Petter Selaskyis only zero terminated on success. 242698e791aSHans Petter Selasky.Pp 243698e791aSHans Petter Selasky.Ft int 244a5118bdfSAndrew Thompson.Fn libusb_detach_kernel_driver "libusb_device_handle *devh" "int interface" 245698e791aSHans Petter Selaskyor 246698e791aSHans Petter Selasky.Ft int 247698e791aSHans Petter Selasky.Fn libusb_detach_kernel_driver_np "libusb_device_handle *devh" "int interface" 248698e791aSHans Petter SelaskyDetach a kernel driver from an interface. 249*11867070SHans Petter SelaskyThis is needed to claim an interface already claimed by a kernel driver. 250698e791aSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if no kernel driver was active, 251c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, 252c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE if the device has been disconnected 253c8c1f2ecSHans Petter Selaskyand a LIBUSB_ERROR code on failure. 254c8c1f2ecSHans Petter SelaskyThis function is non-portable. 2554eaae44dSAndrew Thompson.Pp 256a5118bdfSAndrew Thompson.Ft int 257a5118bdfSAndrew Thompson.Fn libusb_attach_kernel_driver "libusb_device_handle *devh" "int interface" 258*11867070SHans Petter SelaskyRe-attach an interface kernel driver that was previously detached. 259c8c1f2ecSHans Petter SelaskyReturns 0 on success, 260c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_INVALID_PARAM if the interface does not exist, 261c8c1f2ecSHans Petter SelaskyLIBUSB_ERROR_NO_DEVICE 262*11867070SHans Petter Selaskyif the device has been disconnected, LIBUSB_ERROR_BUSY if the driver cannot be 263a5118bdfSAndrew Thompsonattached because the interface is claimed by a program or driver and a 264a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 2654eaae44dSAndrew Thompson.Pp 266a5118bdfSAndrew Thompson.Sh USB DESCRIPTORS 2674eaae44dSAndrew Thompson.Pp 268a5118bdfSAndrew Thompson.Ft int 269a5118bdfSAndrew Thompson.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc" 270a5118bdfSAndrew ThompsonGet the USB device descriptor for the device 271a5118bdfSAndrew Thompson.Fa dev. 272c8c1f2ecSHans Petter SelaskyThis is a non-blocking function. 273c8c1f2ecSHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on 274a5118bdfSAndrew Thompsonfailure. 2754eaae44dSAndrew Thompson.Pp 276a5118bdfSAndrew Thompson.Ft int 277698e791aSHans Petter Selasky.Fn libsub_get_active_config_descriptor "libusb_device *dev" "struct libusb_config_descriptor **config" 278c8c1f2ecSHans Petter SelaskyGet the USB configuration descriptor for the active configuration. 279c8c1f2ecSHans Petter SelaskyReturns 0 on 280*11867070SHans Petter Selaskysuccess, LIBUSB_ERROR_NOT_FOUND if the device is in 281*11867070SHans Petter Selaskyan unconfigured state 282*11867070SHans Petter Selaskyand a LIBUSB_ERROR code on error. 2834eaae44dSAndrew Thompson.Pp 284a5118bdfSAndrew Thompson.Ft int 285a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor "libusb_device *dev" "uint8_t config_index" "libusb_config_descriptor **config" 286*11867070SHans Petter SelaskyGet a USB configuration descriptor based on its index 287a5118bdfSAndrew Thompson.Fa idx. 288a5118bdfSAndrew ThompsonReturns 0 on success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist 289*11867070SHans Petter Selaskyand a LIBUSB_ERROR code on error. 290545b01adSAndrew Thompson.Pp 291a5118bdfSAndrew Thompson.Ft int 292a5118bdfSAndrew Thompson.Fn libusb_get_config_descriptor_by_value "libusb_device *dev" "uint8 bConfigurationValue" "libusb_config_descriptor **config" 293c8c1f2ecSHans Petter SelaskyGet a USB configuration descriptor with a specific bConfigurationValue. 294c8c1f2ecSHans Petter SelaskyThis is 295*11867070SHans Petter Selaskya non-blocking function which does not send a request through the device. 296c8c1f2ecSHans Petter SelaskyReturns 0 297c8c1f2ecSHans Petter Selaskyon success, LIBUSB_ERROR_NOT_FOUND if the configuration 298*11867070SHans Petter Selaskydoes not exist and a 299a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 3004eaae44dSAndrew Thompson.Pp 301a5118bdfSAndrew Thompson.Ft void 302390065b1SAlfred Perlstein.Fn libusb_free_config_descriptor "libusb_config_descriptor *config" 303a5118bdfSAndrew ThompsonFree a configuration descriptor. 3044eaae44dSAndrew Thompson.Pp 305a5118bdfSAndrew Thompson.Ft int 306a5118bdfSAndrew Thompson.Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length" 307*11867070SHans Petter SelaskyRetrieve a string descriptor in C style ASCII. 308*11867070SHans Petter SelaskyReturns the positive number of bytes in the resulting ASCII string 309c8c1f2ecSHans Petter Selaskyon success and a LIBUSB_ERROR code on failure. 3104eaae44dSAndrew Thompson.Pp 311a5118bdfSAndrew Thompson.Sh USB ASYNCHRONOUS I/O 3124eaae44dSAndrew Thompson.Pp 313a5118bdfSAndrew Thompson.Ft struct libusb_transfer * 314a5118bdfSAndrew Thompson.Fn libusb_alloc_transfer "int iso_packets" 315*11867070SHans Petter SelaskyAllocate a transfer with the number of isochronous packet descriptors 316*11867070SHans Petter Selaskyspecified by 317*11867070SHans Petter Selasky.Fa iso_packets . 318ca96e26aSHans Petter SelaskyReturns NULL on error. 3194eaae44dSAndrew Thompson.Pp 320a5118bdfSAndrew Thompson.Ft void 321a5118bdfSAndrew Thompson.Fn libusb_free_transfer "struct libusb_transfer *tr" 322a5118bdfSAndrew ThompsonFree a transfer. 3234eaae44dSAndrew Thompson.Pp 324a5118bdfSAndrew Thompson.Ft int 325a5118bdfSAndrew Thompson.Fn libusb_submit_transfer "struct libusb_transfer *tr" 326ca96e26aSHans Petter SelaskyThis function will submit a transfer and returns immediately. 327c8c1f2ecSHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_NO_DEVICE if 328*11867070SHans Petter Selaskythe device has been disconnected and a 329a5118bdfSAndrew ThompsonLIBUSB_ERROR code on other failure. 3304eaae44dSAndrew Thompson.Pp 331a5118bdfSAndrew Thompson.Ft int 332a5118bdfSAndrew Thompson.Fn libusb_cancel_transfer "struct libusb_transfer *tr" 333*11867070SHans Petter SelaskyThis function asynchronously cancels a transfer. 334*11867070SHans Petter SelaskyReturns 0 on success and a LIBUSB_ERROR code on failure. 3354eaae44dSAndrew Thompson.Pp 336a5118bdfSAndrew Thompson.Sh USB SYNCHRONOUS I/O 3374eaae44dSAndrew Thompson.Pp 338a5118bdfSAndrew Thompson.Ft int 339698e791aSHans 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" 340ca96e26aSHans Petter SelaskyPerform a USB control transfer. 341ca96e26aSHans Petter SelaskyReturns the actual number of bytes 342*11867070SHans Petter Selaskytransferred on success, in the range from and including zero up to and 343c865d740SHans Petter Selaskyincluding 344892f4806SHans Petter Selasky.Fa wLength . 345*11867070SHans Petter SelaskyOn error a LIBUSB_ERROR code is returned, for example 346*11867070SHans Petter SelaskyLIBUSB_ERROR_TIMEOUT if the transfer timed out, LIBUSB_ERROR_PIPE if the 347c865d740SHans Petter Selaskycontrol request was not supported, LIBUSB_ERROR_NO_DEVICE if the 348*11867070SHans Petter Selaskydevice has been disconnected and another LIBUSB_ERROR code on other failures. 349*11867070SHans Petter SelaskyThe LIBUSB_ERROR codes are all negative. 3504eaae44dSAndrew Thompson.Pp 351a5118bdfSAndrew Thompson.Ft int 352a5118bdfSAndrew Thompson.Fn libusb_bulk_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout" 353892f4806SHans Petter SelaskyPerform an USB bulk transfer. 354892f4806SHans Petter SelaskyA timeout value of zero means no timeout. 355892f4806SHans Petter SelaskyThe timeout value is given in milliseconds. 356892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT 357*11867070SHans Petter Selaskyif the transfer timed out, LIBUSB_ERROR_PIPE if the control request was not 358a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data, 359a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 360*11867070SHans Petter Selaskya LIBUSB_ERROR code on other failure. 3614eaae44dSAndrew Thompson.Pp 362a5118bdfSAndrew Thompson.Ft int 363a5118bdfSAndrew Thompson.Fn libusb_interrupt_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout" 364892f4806SHans Petter SelaskyPerform an USB Interrupt transfer. 365892f4806SHans Petter SelaskyA timeout value of zero means no timeout. 366892f4806SHans Petter SelaskyThe timeout value is given in milliseconds. 367892f4806SHans Petter SelaskyReturns 0 on success, LIBUSB_ERROR_TIMEOUT 368*11867070SHans Petter Selaskyif the transfer timed out, LIBUSB_ERROR_PIPE if the control request was not 369a5118bdfSAndrew Thompsonsupported, LIBUSB_ERROR_OVERFLOW if the device offered more data, 370a5118bdfSAndrew ThompsonLIBUSB_ERROR_NO_DEVICE if the device has been disconnected and 371*11867070SHans Petter Selaskya LIBUSB_ERROR code on other failure. 3724eaae44dSAndrew Thompson.Pp 373a5118bdfSAndrew Thompson.Sh USB EVENTS 3744eaae44dSAndrew Thompson.Pp 375a5118bdfSAndrew Thompson.Ft int 376a5118bdfSAndrew Thompson.Fn libusb_try_lock_events "libusb_context *ctx" 377ca96e26aSHans Petter SelaskyTry to acquire the event handling lock. 378ca96e26aSHans Petter SelaskyReturns 0 if the lock was obtained and 1 if not. 3794eaae44dSAndrew Thompson.Pp 380a5118bdfSAndrew Thompson.Ft void 381a5118bdfSAndrew Thompson.Fn libusb_lock_events "libusb_context *ctx" 382c8c1f2ecSHans Petter SelaskyAcquire the event handling lock. 383c8c1f2ecSHans Petter SelaskyThis function is blocking. 3844eaae44dSAndrew Thompson.Pp 385a5118bdfSAndrew Thompson.Ft void 386a5118bdfSAndrew Thompson.Fn libusb_unlock_events "libusb_context *ctx" 387c8c1f2ecSHans Petter SelaskyRelease the event handling lock. 388c8c1f2ecSHans Petter SelaskyThis will wake up any thread blocked 389*11867070SHans Petter Selaskyon 390*11867070SHans Petter Selasky.B libusb_wait_for_event() . 3914eaae44dSAndrew Thompson.Pp 392a5118bdfSAndrew Thompson.Ft int 393a5118bdfSAndrew Thompson.Fn libusb_event_handling_ok "libusb_context *ctx" 394c8c1f2ecSHans Petter SelaskyDetermine if it still OK for this thread to be doing event handling. 395c8c1f2ecSHans Petter SelaskyReturns 1 396c8c1f2ecSHans Petter Selaskyif event handling can start or continue. 397c8c1f2ecSHans Petter SelaskyReturns 0 if this thread must give up 398a5118bdfSAndrew Thompsonthe events lock. 3994eaae44dSAndrew Thompson.Pp 400a5118bdfSAndrew Thompson.Ft int 401a5118bdfSAndrew Thompson.Fn libusb_event_handler_active "libusb_context *ctx" 402c8c1f2ecSHans Petter SelaskyDetermine if an active thread is handling events. 403*11867070SHans Petter SelaskyReturns 1 if there is a thread handling events and 0 if there 404a5118bdfSAndrew Thompsonare no threads currently handling events. 4054eaae44dSAndrew Thompson.Pp 406a5118bdfSAndrew Thompson.Ft void 407a5118bdfSAndrew Thompson.Fn libusb_lock_event_waiters "libusb_context *ctx" 408c8c1f2ecSHans Petter SelaskyAcquire the event_waiters lock. 409*11867070SHans Petter SelaskyThis lock is designed to be obtained in the 410a5118bdfSAndrew Thompsonsituation where you want to be aware when events are completed, but some other 411a5118bdfSAndrew Thompsonthread is event handling so calling libusb_handle_events() is not allowed. 412545b01adSAndrew Thompson.Pp 413a5118bdfSAndrew Thompson.Ft void 414a5118bdfSAndrew Thompson.Fn libusb_unlock_event_waiters "libusb_context *ctx" 415a5118bdfSAndrew ThompsonRelease the event_waiters lock. 4164eaae44dSAndrew Thompson.Pp 417a5118bdfSAndrew Thompson.Ft int 418a5118bdfSAndrew Thompson.Fn libusb_wait_for_event "libusb_context *ctx" "struct timeval *tv" 419c8c1f2ecSHans Petter SelaskyWait for another thread to signal completion of an event. 420c8c1f2ecSHans Petter SelaskyMust be called 421c8c1f2ecSHans Petter Selaskywith the event waiters lock held, see libusb_lock_event_waiters(). 422c8c1f2ecSHans Petter SelaskyThis will 423a5118bdfSAndrew Thompsonblock until the timeout expires or a transfer completes or a thread releases 424c8c1f2ecSHans Petter Selaskythe event handling lock through libusb_unlock_events(). 425c8c1f2ecSHans Petter SelaskyReturns 0 after a 426*11867070SHans Petter Selaskytransfer completes or another thread stops event handling, and 1 if the 427a5118bdfSAndrew Thompsontimeout expired. 4284eaae44dSAndrew Thompson.Pp 429a5118bdfSAndrew Thompson.Ft int 430a5118bdfSAndrew Thompson.Fn libusb_handle_events_timeout "libusb_context *ctx" "struct timeval *tv" 431a5118bdfSAndrew ThompsonHandle any pending events by checking if timeouts have expired and by 432c8c1f2ecSHans Petter Selaskychecking the set of file descriptors for activity. 433c8c1f2ecSHans Petter SelaskyReturns 0 on success, or a 434a5118bdfSAndrew ThompsonLIBUSB_ERROR code on failure. 4354eaae44dSAndrew Thompson.Pp 436a5118bdfSAndrew Thompson.Ft int 437a5118bdfSAndrew Thompson.Fn libusb_handle_events "libusb_context *ctx" 438c8c1f2ecSHans Petter SelaskyHandle any pending events in blocking mode with a sensible timeout. 439c8c1f2ecSHans Petter SelaskyReturns 0 440*11867070SHans Petter Selaskyon success and a LIBUSB_ERROR code on failure. 4414eaae44dSAndrew Thompson.Pp 442a5118bdfSAndrew Thompson.Ft int 443a5118bdfSAndrew Thompson.Fn libusb_handle_events_locked "libusb_context *ctx" "struct timeval *tv" 444a5118bdfSAndrew ThompsonHandle any pending events by polling file desciptors, without checking if 445*11867070SHans Petter Selaskyanother thread is already doing so. 446c8c1f2ecSHans Petter SelaskyMust be called with the event lock held. 4474eaae44dSAndrew Thompson.Pp 448a5118bdfSAndrew Thompson.Ft int 449a5118bdfSAndrew Thompson.Fn libusb_get_next_timeout "libusb_context *ctx" "struct timeval *tv" 450c8c1f2ecSHans Petter SelaskyDetermine the next internal timeout that libusb needs to handle. 451c8c1f2ecSHans Petter SelaskyReturns 0 452*11867070SHans Petter Selaskyif there are no pending timeouts, 1 if a timeout was returned, or a LIBUSB_ERROR 453a5118bdfSAndrew Thompsoncode on failure. 4544eaae44dSAndrew Thompson.Pp 455a5118bdfSAndrew Thompson.Ft void 456a5118bdfSAndrew Thompson.Fn libusb_set_pollfd_notifiers "libusb_context *ctx" "libusb_pollfd_added_cb added_cb" "libusb_pollfd_removed_cb remove_cb" "void *user_data" 457a5118bdfSAndrew ThompsonRegister notification functions for file descriptor additions/removals. 458a5118bdfSAndrew ThompsonThese functions will be invoked for every new or removed file descriptor 459a5118bdfSAndrew Thompsonthat libusb uses as an event source. 4604eaae44dSAndrew Thompson.Pp 461a5118bdfSAndrew Thompson.Ft const struct libusb_pollfd ** 462a5118bdfSAndrew Thompson.Fn libusb_get_pollfds "libusb_context *ctx" 463a5118bdfSAndrew ThompsonRetrive a list of file descriptors that should be polled by your main loop as 464c8c1f2ecSHans Petter Selaskylibusb event sources. 465c8c1f2ecSHans Petter SelaskyReturns a NULL-terminated list on success or NULL on failure. 4664eaae44dSAndrew Thompson.Sh LIBUSB VERSION 0.1 COMPATIBILITY 467a5118bdfSAndrew Thompson.Pp 468a5118bdfSAndrew ThompsonThe library is also compliant with LibUSB version 0.1.12. 469a5118bdfSAndrew Thompson.Pp 4704eaae44dSAndrew Thompson.Fn usb_open 4714eaae44dSAndrew Thompson.Fn usb_close 4724eaae44dSAndrew Thompson.Fn usb_get_string 4734eaae44dSAndrew Thompson.Fn usb_get_string_simple 4744eaae44dSAndrew Thompson.Fn usb_get_descriptor_by_endpoint 4754eaae44dSAndrew Thompson.Fn usb_get_descriptor 4764eaae44dSAndrew Thompson.Fn usb_parse_descriptor 4774eaae44dSAndrew Thompson.Fn usb_parse_configuration 4784eaae44dSAndrew Thompson.Fn usb_destroy_configuration 4794eaae44dSAndrew Thompson.Fn usb_fetch_and_parse_descriptors 4804eaae44dSAndrew Thompson.Fn usb_bulk_write 4814eaae44dSAndrew Thompson.Fn usb_bulk_read 4824eaae44dSAndrew Thompson.Fn usb_interrupt_write 4834eaae44dSAndrew Thompson.Fn usb_interrupt_read 4844eaae44dSAndrew Thompson.Fn usb_control_msg 4854eaae44dSAndrew Thompson.Fn usb_set_configuration 4864eaae44dSAndrew Thompson.Fn usb_claim_interface 4874eaae44dSAndrew Thompson.Fn usb_release_interface 4884eaae44dSAndrew Thompson.Fn usb_set_altinterface 4894eaae44dSAndrew Thompson.Fn usb_resetep 4904eaae44dSAndrew Thompson.Fn usb_clear_halt 4914eaae44dSAndrew Thompson.Fn usb_reset 4924eaae44dSAndrew Thompson.Fn usb_strerror 4934eaae44dSAndrew Thompson.Fn usb_init 4944eaae44dSAndrew Thompson.Fn usb_set_debug 4954eaae44dSAndrew Thompson.Fn usb_find_busses 4964eaae44dSAndrew Thompson.Fn usb_find_devices 4974eaae44dSAndrew Thompson.Fn usb_device 4984eaae44dSAndrew Thompson.Fn usb_get_busses 499f1b5fa6eSHans Petter Selasky.Fn usb_check_connected 5004eb5923dSHans Petter Selasky.Fn usb_get_driver_np 5014eb5923dSHans Petter Selasky.Fn usb_detach_kernel_driver_np 5024eaae44dSAndrew Thompson.Sh SEE ALSO 503a5118bdfSAndrew Thompson.Xr libusb20 3 , 504c54c1f7cSAndrew Thompson.Xr usb 4 , 5054eaae44dSAndrew Thompson.Xr usbconfig 8 506a5118bdfSAndrew Thompson.Pp 507a5118bdfSAndrew Thompson.Pa http://libusb.sourceforge.net/ 5084eaae44dSAndrew Thompson.Sh HISTORY 5094eaae44dSAndrew Thompson.Nm 510a5118bdfSAndrew Thompsonsupport first appeared in 511a5118bdfSAndrew Thompson.Fx 8.0 . 512