1.\" 2.\" Copyright (c) 2008 Hans Petter Selasky 3.\" 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25.\" SUCH DAMAGE. 26.\" 27.\" $FreeBSD$ 28.\" 29.Dd May 28, 2009 30.Dt LIBUSB 3 31.Os 32.Sh NAME 33.Nm libusb 34. 35.Nd "USB access library" 36. 37. 38.Sh LIBRARY 39. 40. 41USB access library (libusb -lusb) 42. 43. 44. 45.Sh SYNOPSIS 46.In libusb20.h 47.Ft int 48.Fn libusb20_tr_close "struct libusb20_transfer *xfer" 49.Ft int 50.Fn libusb20_tr_open "struct libusb20_transfer *xfer" "uint32_t max_buf_size" "uint32_t max_frame_count" "uint8_t ep_no" 51.Ft struct libusb20_transfer* 52.Fn libusb20_tr_get_pointer "struct libusb20_device *pdev" "uint16_t tr_index" 53.Ft uint16_t 54.Fn libusb20_tr_get_time_complete "struct libusb20_transfer *xfer" 55.Ft uint32_t 56.Fn libusb20_tr_get_actual_frames "struct libusb20_transfer *xfer" 57.Ft uint32_t 58.Fn libusb20_tr_get_actual_length "struct libusb20_transfer *xfer" 59.Ft uint32_t 60.Fn libusb20_tr_get_max_frames "struct libusb20_transfer *xfer" 61.Ft uint32_t 62.Fn libusb20_tr_get_max_packet_length "struct libusb20_transfer *xfer" 63.Ft uint32_t 64.Fn libusb20_tr_get_max_total_length "struct libusb20_transfer *xfer" 65.Ft uint8_t 66.Fn libusb20_tr_get_status "struct libusb20_transfer *xfer" 67.Ft uint8_t 68.Fn libusb20_tr_pending "struct libusb20_transfer *xfer" 69.Ft void 70.Fn libusb20_tr_callback_wrapper "struct libusb20_transfer *xfer" 71.Ft void 72.Fn libusb20_tr_clear_stall_sync "struct libusb20_transfer *xfer" 73.Ft void 74.Fn libusb20_tr_drain "struct libusb20_transfer *xfer" 75.Ft void 76.Fn libusb20_tr_set_buffer "struct libusb20_transfer *xfer" "void *buffer" "uint16_t fr_index" 77.Ft void 78.Fn libusb20_tr_set_callback "struct libusb20_transfer *xfer" "libusb20_tr_callback_t *cb" 79.Ft void 80.Fn libusb20_tr_set_flags "struct libusb20_transfer *xfer" "uint8_t flags" 81.Ft uint32_t 82.Fn libusb20_tr_get_length "struct libusb20_transfer *xfer" "uint16_t fr_index" 83.Ft void 84.Fn libusb20_tr_set_length "struct libusb20_transfer *xfer" "uint32_t length" "uint16_t fr_index" 85.Ft void 86.Fn libusb20_tr_set_priv_sc0 "struct libusb20_transfer *xfer" "void *sc0" 87.Ft void 88.Fn libusb20_tr_set_priv_sc1 "struct libusb20_transfer *xfer" "void *sc1" 89.Ft void 90.Fn libusb20_tr_set_timeout "struct libusb20_transfer *xfer" "uint32_t timeout" 91.Ft void 92.Fn libusb20_tr_set_total_frames "struct libusb20_transfer *xfer" "uint32_t nframes" 93.Ft void 94.Fn libusb20_tr_setup_bulk "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint32_t timeout" 95.Ft void 96.Fn libusb20_tr_setup_control "struct libusb20_transfer *xfer" "void *psetup" "void *pbuf" "uint32_t timeout" 97.Ft void 98.Fn libusb20_tr_setup_intr "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint32_t timeout" 99.Ft void 100.Fn libusb20_tr_setup_isoc "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint61_t fr_index" 101.Ft void 102.Fn libusb20_tr_start "struct libusb20_transfer *xfer" 103.Ft void 104.Fn libusb20_tr_stop "struct libusb20_transfer *xfer" 105.Ft void 106.Fn libusb20_tr_submit "struct libusb20_transfer *xfer" 107.Ft void * 108.Fn libusb20_tr_get_priv_sc0 "struct libusb20_transfer *xfer" 109.Ft void * 110.Fn libusb20_tr_get_priv_sc1 "struct libusb20_transfer *xfer" 111.Ft const char * 112.Fn libusb20_dev_get_backend_name "struct libusb20_device *" 113.Ft int 114.Fn libusb20_dev_get_info "struct libusb20_device *pdev" "struct usb_device_info *pinfo" 115.Ft int 116.Fn libusb20_dev_get_iface_desc "struct libusb20_device *pdev" "uint8_t iface_index" "char *buf" "uint8_t len" 117.Ft const char * 118.Fn libusb20_dev_get_desc "struct libusb20_device *pdev" 119.Ft int 120.Fn libusb20_dev_claim_interface "struct libusb20_device *pdev" "uint8_t iface_index" 121.Ft int 122.Fn libusb20_dev_close "struct libusb20_device *pdev" 123.Ft int 124.Fn libusb20_dev_detach_kernel_driver "struct libusb20_device *pdev" "uint8_t iface_index" 125.Ft int 126.Fn libusb20_dev_set_config_index "struct libusb20_device *pdev" "uint8_t configIndex" 127.Ft int 128.Fn libusb20_dev_get_debug "struct libusb20_device *pdev" 129.Ft int 130.Fn libusb20_dev_get_fd "struct libusb20_device *pdev" 131.Ft int 132.Fn libusb20_dev_kernel_driver_active "struct libusb20_device *pdev" "uint8_t iface_index" 133.Ft int 134.Fn libusb20_dev_open "struct libusb20_device *pdev" "uint16_t transfer_max" 135.Ft int 136.Fn libusb20_dev_process "struct libusb20_device *pdev" 137.Ft int 138.Fn libusb20_dev_release_interface "struct libusb20_device *pdev" "uint8_t iface_index" 139.Ft int 140.Fn libusb20_dev_request_sync "struct libusb20_device *pdev" "struct LIBUSB20_CONTROL_SETUP_DECODED *setup" "void *data" "uint16_t *pactlen" "uint32_t timeout" "uint8_t flags" 141.Ft int 142.Fn libusb20_dev_req_string_sync "struct libusb20_device *pdev" "uint8_t index" "uint16_t langid" "void *ptr" "uint16_t len" 143.Ft int 144.Fn libusb20_dev_req_string_simple_sync "struct libusb20_device *pdev" "uint8_t index" "void *ptr" "uint16_t len" 145.Ft int 146.Fn libusb20_dev_reset "struct libusb20_device *pdev" 147.Ft int 148.Fn libusb20_dev_set_power_mode "struct libusb20_device *pdev" "uint8_t power_mode" 149.Ft uint8_t 150.Fn libusb20_dev_get_power_mode "struct libusb20_device *pdev" 151.Ft int 152.Fn libusb20_dev_set_alt_index "struct libusb20_device *pdev" "uint8_t iface_index" "uint8_t alt_index" 153.Ft struct LIBUSB20_DEVICE_DESC_DECODED * 154.Fn libusb20_dev_get_device_desc "struct libusb20_device *pdev" 155.Ft struct libusb20_config * 156.Fn libusb20_dev_alloc_config "struct libusb20_device *pdev" "uint8_t config_index" 157.Ft struct libusb20_device * 158.Fn libusb20_dev_alloc "void" 159.Ft uint8_t 160.Fn libusb20_dev_get_address "struct libusb20_device *pdev" 161.Ft uint8_t 162.Fn libusb20_dev_get_bus_number "struct libusb20_device *pdev" 163.Ft uint8_t 164.Fn libusb20_dev_get_mode "struct libusb20_device *pdev" 165.Ft uint8_t 166.Fn libusb20_dev_get_speed "struct libusb20_device *pdev" 167.Ft uint8_t 168.Fn libusb20_dev_get_config_index "struct libusb20_device *pdev" 169.Ft void 170.Fn libusb20_dev_free "struct libusb20_device *pdev" 171.Ft void 172.Fn libusb20_dev_set_debug "struct libusb20_device *pdev" "int debug" 173.Ft void 174.Fn libusb20_dev_wait_process "struct libusb20_device *pdev" "int timeout" 175.Ft int 176.Fn libusb20_be_get_template "struct libusb20_backend *pbe" "int *ptemp" 177.Ft int 178.Fn libusb20_be_set_template "struct libusb20_backend *pbe" "int temp" 179.Ft int 180.Fn libusb20_be_get_dev_quirk "struct libusb20_backend *pber", "uint16_t index" "struct libusb20_quirk *pq" 181.Ft int 182.Fn libusb20_be_get_quirk_name "struct libusb20_backend *pbe" "uint16_t index" "struct libusb20_quirk *pq" 183.Ft int 184.Fn libusb20_be_add_dev_quirk "struct libusb20_backend *pbe" "struct libusb20_quirk *pq" 185.Ft int 186.Fn libusb20_be_remove_dev_quirk "struct libusb20_backend *pbe" "struct libusb20_quirk *pq" 187.Ft struct libusb20_backend * 188.Fn libusb20_be_alloc_default "void" 189.Ft struct libusb20_backend * 190.Fn libusb20_be_alloc_freebsd "void" 191.Ft struct libusb20_backend * 192.Fn libusb20_be_alloc_linux "void" 193.Ft struct libusb20_device * 194.Fn libusb20_be_device_foreach "struct libusb20_backend *pbe" "struct libusb20_device *pdev" 195.Ft void 196.Fn libusb20_be_dequeue_device "struct libusb20_backend *pbe" "struct libusb20_device *pdev" 197.Ft void 198.Fn libusb20_be_enqueue_device "struct libusb20_backend *pbe" "struct libusb20_device *pdev" 199.Ft void 200.Fn libusb20_be_free "struct libusb20_backend *pbe" 201.Ft uint8_t 202.Fn libusb20_me_get_1 "const struct libusb20_me_struct *me" "uint16_t off" 203.Ft uint16_t 204.Fn libusb20_me_get_2 "const struct libusb20_me_struct *me" "uint16_t off" 205.Ft uint16_t 206.Fn libusb20_me_encode "void *pdata" "uint16_t len" "const void *pdecoded" 207.Ft uint16_t 208.Fn libusb20_me_decode "const void *pdata" "uint16_t len" "void *pdecoded" 209.Ft "const uint8_t *" 210.Fn libusb20_desc_foreach "const struct libusb20_me_struct *me" "const uint8_t *pdesc" 211. 212. 213.Sh DESCRIPTION 214. 215The 216.Nm 217library implements functions to be able to easily access and control 218USB through the USB file system interface. 219. 220. 221.Sh USB TRANSFER OPERATIONS 222. 223.Pp 224. 225.Fn libusb20_tr_close 226will release all kernel resources associated with an USB 227.Fa xfer . 228. 229This function returns zero upon success. 230. 231Non-zero return values indicate a LIBUSB20_ERROR value. 232. 233.Pp 234. 235.Fn libusb20_tr_open 236will allocate kernel buffer resources according to 237.Fa max_buf_size 238and 239.Fa max_frame_count 240associated with an USB 241.Fa pxfer 242and bind the transfer to the specified 243.Fa ep_no . 244.Fa max_buf_size 245is the minimum buffer size which the data transport layer has to support. 246If 247.Fa max_buf_size 248is zero, the 249.Nm 250library will use wMaxPacketSize to compute the buffer size. 251This can be useful for isochronous transfers. 252The actual buffer size can be greater than 253.Fa max_buf_size 254and is returned by 255.Fn libusb20_tr_get_max_total_length . 256. 257This function returns zero upon success. 258. 259Non-zero return values indicate a LIBUSB20_ERROR value. 260. 261.Pp 262. 263.Fn libusb20_tr_get_pointer 264will return a pointer to the allocated USB transfer according to the 265.Fa pdev 266and 267.Fa tr_index 268arguments. 269. 270This function returns NULL in case of failure. 271. 272.Pp 273. 274.Fn libusb20_tr_get_time_complete 275will return the completion time of an USB transfer in 276millisecond units. This function is most useful for isochronous USB 277transfers when doing echo cancelling. 278. 279.Pp 280. 281.Fn libusb20_tr_get_actual_frames 282will return the actual number of USB frames after an USB 283transfer completed. A value of zero means that no data was transferred. 284. 285.Pp 286. 287.Fn libusb20_tr_get_actual_length 288will return the sum of the actual length for all 289transferred USB frames for the given USB transfer. 290. 291.Pp 292. 293.Fn libusb20_tr_get_max_frames 294will return the maximum number of USB frames that were 295allocated when an USB transfer was setup for the given USB transfer. 296. 297.Pp 298. 299.Fn libusb20_tr_get_max_packet_length 300will return the maximum packet length in bytes 301associated with the given USB transfer. 302. 303The packet length can be used round up buffer sizes so that short USB 304packets are avoided for proxy buffers. 305. 306. 307.Pp 308. 309.Fn libusb20_tr_get_max_total_length 310function will return the maximum value for the length sum of all 311USB frames associated with an USB transfer. 312. 313.Pp 314. 315.Fn libusb20_tr_get_status 316will return the status of an USB transfer. 317. 318Status values are defined by a set of LIBUSB20_TRANSFER_XXX enums. 319. 320.Pp 321. 322.Fn libusb20_tr_pending 323will return non-zero if the given USB transfer is 324pending for completion. 325. 326Else this function returns zero. 327. 328.Pp 329. 330.Fn libusb20_tr_callback_wrapper 331This is an internal function used to wrap asynchronous USB callbacks. 332. 333.Pp 334. 335.Fn libusb20_tr_clear_stall_sync 336This is an internal function used to synchronously clear the stall on 337the given USB transfer. 338. 339Please see the USB specification for more information on stall 340clearing. 341. 342If the given USB transfer is pending when this function is called, the 343USB transfer will complete with an error after that this function has 344been called. 345. 346.Pp 347. 348.Fn libusb20_tr_drain 349will stop the given USB transfer and will not return 350until the USB transfer has been stopped in hardware. 351. 352.Pp 353. 354.Fn libusb20_tr_set_buffer 355is used to set the 356.Fa buffer 357pointer for the given USB transfer and 358.Fa fr_index . 359. 360Typically the frame index is zero. 361. 362. 363.Pp 364. 365.Fn libusb20_tr_set_callback 366is used to set the USB callback for asynchronous USB 367transfers. 368. 369The callback type is defined by libusb20_tr_callback_t. 370. 371.Pp 372. 373.Fn libusb20_tr_set_flags 374is used to set various USB flags for the given USB transfer. 375.Bl -tag 376.It LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK 377Report a short frame as error. 378.It LIBUSB20_TRANSFER_MULTI_SHORT_NOT_OK 379Multiple short frames are not allowed. 380.It LIBUSB20_TRANSFER_FORCE_SHORT 381All transmitted frames are short terminated. 382.It LIBUSB20_TRANSFER_DO_CLEAR_STALL 383Will do a clear-stall before starting the transfer. 384.El 385. 386.Pp 387. 388.Fn libusb20_tr_get_length 389returns the length of the given USB frame by index. 390After an USB transfer is complete the USB frame length will get updated to the actual transferred length. 391. 392.Pp 393. 394.Fn libusb20_tr_set_length 395sets the length of the given USB frame by index. 396. 397.Pp 398. 399.Fn libusb20_tr_set_priv_sc0 400sets private driver pointer number zero. 401. 402.Pp 403. 404.Fn libusb20_tr_set_priv_sc1 405sets private driver pointer number one. 406. 407.Pp 408. 409.Fn libusb20_tr_set_timeout 410sets the timeout for the given USB transfer. 411. 412A timeout value of zero means no timeout. 413. 414The timeout is given in milliseconds. 415. 416.Pp 417. 418.Fn libusb20_tr_set_total_frames 419sets the total number of frames that should be executed when the USB transfer is submitted. 420. 421The total number of USB frames must be less than the maximum number of USB frames associated with the given USB transfer. 422. 423.Pp 424. 425.Fn libusb20_tr_setup_bulk 426is a helper function for setting up a single frame USB BULK transfer. 427. 428.Pp 429. 430.Fn libusb20_tr_setup_control 431is a helper function for setting up a single or dual 432frame USB CONTROL transfer depending on the control transfer length. 433. 434.Pp 435. 436.Fn libusb20_tr_setup_intr 437is a helper function for setting up a single frame USB INTERRUPT transfer. 438. 439.Pp 440. 441.Fn libusb20_tr_setup_isoc 442is a helper function for setting up a multi frame USB ISOCHRONOUS transfer. 443. 444.Pp 445. 446.Fn libusb20_tr_start 447will get the USB transfer started, if not already 448started. 449. 450This function will not get the transfer queued in hardware. 451. 452This function is non-blocking. 453. 454.Pp 455. 456.Fn libusb20_tr_stop 457will get the USB transfer stopped, if not already stopped. 458. 459This function is non-blocking, which means that the actual stop can 460happen after the return of this function. 461. 462.Pp 463. 464.Fn libusb20_tr_submit 465will get the USB transfer queued in hardware. 466. 467. 468.Pp 469. 470.Fn libusb20_tr_get_priv_sc0 471returns private driver pointer number zero associated 472with an USB transfer. 473. 474. 475.Pp 476. 477.Fn libusb20_tr_get_priv_sc1 478returns private driver pointer number one associated 479with an USB transfer. 480. 481. 482.Sh USB DEVICE OPERATIONS 483. 484.Pp 485. 486.Fn libusb20_dev_get_backend_name 487returns a zero terminated string describing the backend used. 488. 489.Pp 490. 491.Fn libusb20_dev_get_info 492retrives the BSD specific usb_device_info structure into the memory location given by 493.Fa pinfo . 494The USB device given by 495.Fa pdev 496must be opened before this function will succeed. 497This function returns zero on success else a LIBUSB20_ERROR value is returned. 498. 499.Pp 500. 501.Fn libusb20_dev_get_iface_desc 502retrieves the kernel interface description for the given USB 503.Fa iface_index . 504The format of the USB interface description is: "drivername<unit>: <description>" 505The description string is always zero terminated. 506A zero length string is written in case no driver is attached to the given interface. 507The USB device given by 508.Fa pdev 509must be opened before this function will succeed. 510This function returns zero on success else a LIBUSB20_ERROR value is returned. 511. 512.Pp 513. 514.Fn libusb20_dev_get_desc 515returns a zero terminated string describing the given USB device. 516The format of the string is: "drivername<unit>: <description>" 517. 518.Pp 519. 520.Fn libusb20_dev_claim_interface 521This function will try to claim the given USB interface given by 522.Fa iface_index . 523This function returns zero on success else a LIBUSB20_ERROR value is 524returned. 525. 526.Pp 527. 528.Fn libusb20_dev_close 529will close the given USB device. 530. 531This function returns zero on success else a LIBUSB20_ERROR value is 532returned. 533. 534.Pp 535. 536.Fn libusb20_dev_detach_kernel_driver 537will try to detach the kernel driver for the USB interface given by 538.Fa iface_index . 539. 540This function returns zero on success else a LIBUSB20_ERROR value is 541returned. 542. 543.Pp 544. 545.Fn libusb20_dev_set_config_index 546will try to set the configuration index on an USB 547device. 548. 549The first configuration index is zero. 550. 551The un-configure index is 255. 552. 553This function returns zero on success else a LIBUSB20_ERROR value is returned. 554. 555.Pp 556. 557.Fn libusb20_dev_get_debug 558returns the debug level of an USB device. 559. 560.Pp 561. 562.Fn libusb20_dev_get_fd 563returns the file descriptor of the given USB device. 564. 565A negative value is returned when no file descriptor is present. 566. 567The file descriptor can be used for polling purposes. 568. 569.Pp 570. 571.Fn libusb20_dev_kernel_driver_active 572returns a non-zero value if a kernel driver is active on 573the given USB interface. 574. 575Else zero is returned. 576. 577.Pp 578. 579.Fn libusb20_dev_open 580opens an USB device so that setting up USB transfers 581becomes possible. 582. 583The number of USB transfers can be zero which means only control 584transfers are allowed. 585. 586This function returns zero on success else a LIBUSB20_ERROR value is 587returned. 588. 589A return value of LIBUSB20_ERROR_BUSY means that the device is already 590opened. 591. 592.Pp 593. 594.Fn libusb20_dev_process 595is called to sync kernel USB transfers with userland USB 596transfers. 597. 598This function returns zero on success else a LIBUSB20_ERROR value is 599returned typically indicating that the given USB device has been 600detached. 601. 602.Pp 603. 604.Fn libusb20_dev_release_interface 605will try to release a claimed USB interface for the specified USB device. 606. 607This function returns zero on success else a LIBUSB20_ERROR value is 608returned. 609. 610.Pp 611. 612.Fn libusb20_dev_request_sync 613will perform a synchronous control request on the given 614USB device. 615. 616Before this call will succeed the USB device must be opened. 617. 618.Fa setup 619is a pointer to a decoded and host endian SETUP packet. 620.Fa data 621is a pointer to a data transfer buffer associated with the control transaction. This argument can be NULL. 622.Fa pactlen 623is a pointer to a variable that will hold the actual transfer length after the control transaction is complete. 624.Fa timeout 625is the transaction timeout given in milliseconds. 626A timeout of zero means no timeout. 627.Fa flags 628is used to specify transaction flags, for example LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK. 629. 630This function returns zero on success else a LIBUSB20_ERROR value is 631returned. 632. 633.Pp 634. 635.Fn libusb20_dev_req_string_sync 636will synchronously request an USB string by language ID 637and string index into the given buffer limited by a maximum length. 638. 639This function returns zero on success else a LIBUSB20_ERROR value is 640returned. 641. 642.Pp 643. 644.Fn libusb20_dev_req_string_simple_sync 645will synchronously request an USB string using the 646default language ID and convert the string into ASCII before storing 647the string into the given buffer limited by a maximum length which 648includes the terminating zero. 649. 650This function returns zero on success else a LIBUSB20_ERROR value is 651returned. 652. 653. 654.Pp 655. 656.Fn libusb20_dev_reset 657will try to BUS reset the given USB device and restore 658the last set USB configuration. 659. 660This function returns zero on success else a LIBUSB20_ERROR value is 661returned. 662. 663.Pp 664. 665.Fn libusb20_dev_set_power_mode 666sets the power mode of the USB device. 667. 668Valid power modes: 669.Bl -tag 670.It LIBUSB20_POWER_OFF 671.It LIBUSB20_POWER_ON 672.It LIBUSB20_POWER_SAVE 673.It LIBUSB20_POWER_SUSPEND 674.It LIBUSB20_POWER_RESUME 675.El 676. 677This function returns zero on success else a LIBUSB20_ERROR value is 678returned. 679. 680.Pp 681. 682.Fn libusb20_dev_get_power_mode 683returns the currently selected power mode for the given 684USB device. 685. 686.Pp 687. 688.Fn libusb20_dev_set_alt_index 689will try to set the given alternate index for the given 690USB interface index. 691. 692This function returns zero on success else a LIBUSB20_ERROR value is 693returned. 694. 695.Pp 696. 697.Fn libusb20_dev_get_device_desc 698returns a pointer to the decoded and host endian version 699of the device descriptor. 700. 701The USB device need not be opened when calling this function. 702. 703.Pp 704. 705.Fn libusb20_dev_alloc_config 706will read out and decode the USB config descriptor for 707the given USB device and config index. This function returns a pointer 708to the decoded configuration which must eventually be passed to 709free(). NULL is returned in case of failure. 710. 711.Pp 712. 713.Fn libusb20_dev_alloc 714is an internal function to allocate a new USB device. 715. 716.Pp 717. 718.Fn libusb20_dev_get_address 719returns the internal and not necessarily the real 720hardware address of the given USB device. 721. 722.Pp 723. 724.Fn libusb20_dev_get_bus_number 725returns the internal bus number which the given USB 726device belongs to. 727. 728.Pp 729. 730.Fn libusb20_dev_get_mode 731returns the current operation mode of the USB entity. 732. 733Valid return values are: 734.Bl -tag 735.It LIBUSB20_MODE_HOST 736.It LIBUSB20_MODE_DEVICE 737.El 738. 739.Pp 740. 741.Fn libusb20_dev_get_speed 742returns the current speed of the given USB device. 743. 744.Bl -tag 745.It LIBUSB20_SPEED_UNKNOWN 746.It LIBUSB20_SPEED_LOW 747.It LIBUSB20_SPEED_FULL 748.It LIBUSB20_SPEED_HIGH 749.It LIBUSB20_SPEED_VARIABLE 750.It LIBUSB20_SPEED_SUPER 751.El 752. 753.Pp 754. 755.Fn libusb20_dev_get_config_index 756This function returns the currently select config index for the given 757USB device. 758. 759.Pp 760. 761.Fn libusb20_dev_free 762will free the given USB device and all associated USB 763transfers. 764. 765.Pp 766. 767.Fn libusb20_dev_set_debug 768will set the debug level for the given USB device. 769. 770.Pp 771. 772.Fn libusb20_dev_wait_process 773function will wait until a pending USB transfer has completed on 774the given USB device. 775. 776A timeout value can be specified which is passed on to the 777.Xr poll 2 778function. 779. 780.Sh USB BACKEND OPERATIONS 781. 782.Fn libusb20_be_get_template 783will return the currently selected global USB device 784side mode template into the integer pointer 785.Fa ptemp . 786This function returns zero on success else a LIBUSB20_ERROR value is 787returned. 788. 789.Pp 790. 791.Fn libusb20_be_set_template 792will set the global USB device side mode template to 793.Fa temp . 794The new template is not activated until after the next USB 795enumeration. 796The template number decides how the USB device will present itself to 797the USB Host, like Mass Storage Device, USB Ethernet Device. Also see 798the 799.Xr usb2_template 4 800module. 801This function returns zero on success else a LIBUSB20_ERROR value is 802returned. 803. 804.Pp 805. 806.Fn libusb20_be_get_dev_quirk 807This function will return the device quirk according to 808.Fa index 809into the libusb20_quirk structure pointed to by 810.Fa pq . 811This function returns zero on success else a LIBUSB20_ERROR value is 812returned. 813. 814If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is 815returned. 816. 817.Pp 818. 819.Fn libusb20_be_get_quirk_name 820will return the quirk name according to 821.Fa index 822into the libusb20_quirk structure pointed to by 823.Fa pq . 824This function returns zero on success else a LIBUSB20_ERROR value is 825returned. 826. 827If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is 828returned. 829. 830.Pp 831. 832.Fn libusb20_be_add_dev_quirk 833will add the libusb20_quirk structure pointed to by the 834.Fa pq 835argument into the device quirk list. 836. 837This function returns zero on success else a LIBUSB20_ERROR value is 838returned. 839. 840If the given quirk cannot be added LIBUSB20_ERROR_NO_MEM is 841returned. 842. 843.Pp 844. 845.Fn libusb20_be_remove_dev_quirk 846will remove the quirk matching the libusb20_quirk structure pointed to by the 847.Fa pq 848argument from the device quirk list. 849. 850This function returns zero on success else a LIBUSB20_ERROR value is 851returned. 852. 853If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is 854returned. 855. 856.Pp 857. 858.Fn libusb20_be_alloc_default 859.Fn libusb20_be_alloc_freebsd 860.Fn libusb20_be_alloc_linux 861These functions are used to allocate a specific USB backend or the 862operating system default USB backend. Allocating a backend is a way to 863scan for currently present USB devices. 864. 865.Pp 866. 867.Fn libusb20_be_device_foreach 868is used to iterate USB devices present in a USB backend. 869. 870The starting value of 871.Fa pdev 872is NULL. 873. 874This function returns the next USB device in the list. 875. 876If NULL is returned the end of the USB device list has been reached. 877. 878.Pp 879. 880.Fn libusb20_be_dequeue_device 881will dequeue the given USB device pointer from the 882backend USB device list. 883. 884Dequeued USB devices will not be freed when the backend is freed. 885. 886.Pp 887. 888.Fn libusb20_be_enqueue_device 889This function will enqueue the given USB device pointer in the backend USB device list. 890. 891Enqueued USB devices will get freed when the backend is freed. 892. 893.Pp 894. 895.Fn libusb20_be_free 896will free the given backend and all USB devices in its device list. 897. 898. 899.Sh USB DESCRIPTOR PARSING 900. 901.Fn libusb20_me_get_1 pie offset 902This function will return a byte at the given byte offset of a message 903entity. 904. 905This function is safe against invalid offsets. 906. 907.Pp 908. 909.Fn libusb20_me_get_2 pie offset 910This function will return a little endian 16-bit value at the given byte offset of a message 911entity. 912. 913This function is safe against invalid offsets. 914. 915.Pp 916. 917.Fn libusb20_me_encode pbuf len pdecoded 918This function will encode a so-called *DECODED structure into binary 919format. 920. 921The total encoded length that will fit in the given buffer is 922returned. 923. 924If the buffer pointer is NULL no data will be written to the buffer 925location. 926. 927.Pp 928. 929.Fn libusb20_me_decode pbuf len pdecoded 930This function will decode a binary structure into a so-called *DECODED 931structure. 932. 933The total decoded length is returned. 934. 935The buffer pointer cannot be NULL. 936. 937. 938.Sh LIBUSB VERSION 0.1 COMPATIBILITY 939. 940.Fn usb_open 941.Fn usb_close 942.Fn usb_get_string 943.Fn usb_get_string_simple 944.Fn usb_get_descriptor_by_endpoint 945.Fn usb_get_descriptor 946.Fn usb_parse_descriptor 947.Fn usb_parse_configuration 948.Fn usb_destroy_configuration 949.Fn usb_fetch_and_parse_descriptors 950.Fn usb_bulk_write 951.Fn usb_bulk_read 952.Fn usb_interrupt_write 953.Fn usb_interrupt_read 954.Fn usb_control_msg 955.Fn usb_set_configuration 956.Fn usb_claim_interface 957.Fn usb_release_interface 958.Fn usb_set_altinterface 959.Fn usb_resetep 960.Fn usb_clear_halt 961.Fn usb_reset 962.Fn usb_strerror 963.Fn usb_init 964.Fn usb_set_debug 965.Fn usb_find_busses 966.Fn usb_find_devices 967.Fn usb_device 968.Fn usb_get_busses 969These functions are compliant with LibUSB version 0.1.12. 970. 971.Sh FILES 972. 973. 974/dev/usb 975.Sh SEE ALSO 976.Xr usb 4 , 977.Xr usbconfig 8 978. 979. 980.Sh HISTORY 981. 982. 983Some parts of the 984.Nm 985API derives from the libusb project at sourceforge. 986