2 .\" Copyright (c) 2008-2019 Hans Petter Selasky
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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.
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
35 .Nd "USB access library"
41 USB access library (libusb -lusb)
48 .Fn libusb20_tr_close "struct libusb20_transfer *xfer"
50 .Fn libusb20_tr_open "struct libusb20_transfer *xfer" "uint32_t max_buf_size" "uint32_t max_frame_count" "uint8_t ep_no"
51 .Fn libusb20_tr_open_stream "struct libusb20_transfer *xfer" "uint32_t max_buf_size" "uint32_t max_frame_count" "uint8_t ep_no" "uint16_t stream_id"
52 .Ft struct libusb20_transfer*
53 .Fn libusb20_tr_get_pointer "struct libusb20_device *pdev" "uint16_t tr_index"
55 .Fn libusb20_tr_get_time_complete "struct libusb20_transfer *xfer"
57 .Fn libusb20_tr_get_actual_frames "struct libusb20_transfer *xfer"
59 .Fn libusb20_tr_get_actual_length "struct libusb20_transfer *xfer"
61 .Fn libusb20_tr_get_max_frames "struct libusb20_transfer *xfer"
63 .Fn libusb20_tr_get_max_packet_length "struct libusb20_transfer *xfer"
65 .Fn libusb20_tr_get_max_total_length "struct libusb20_transfer *xfer"
67 .Fn libusb20_tr_get_status "struct libusb20_transfer *xfer"
69 .Fn libusb20_tr_pending "struct libusb20_transfer *xfer"
71 .Fn libusb20_tr_callback_wrapper "struct libusb20_transfer *xfer"
73 .Fn libusb20_tr_clear_stall_sync "struct libusb20_transfer *xfer"
75 .Fn libusb20_tr_drain "struct libusb20_transfer *xfer"
77 .Fn libusb20_tr_set_buffer "struct libusb20_transfer *xfer" "void *buffer" "uint16_t fr_index"
79 .Fn libusb20_tr_set_callback "struct libusb20_transfer *xfer" "libusb20_tr_callback_t *cb"
81 .Fn libusb20_tr_set_flags "struct libusb20_transfer *xfer" "uint8_t flags"
83 .Fn libusb20_tr_get_length "struct libusb20_transfer *xfer" "uint16_t fr_index"
85 .Fn libusb20_tr_set_length "struct libusb20_transfer *xfer" "uint32_t length" "uint16_t fr_index"
87 .Fn libusb20_tr_set_priv_sc0 "struct libusb20_transfer *xfer" "void *sc0"
89 .Fn libusb20_tr_set_priv_sc1 "struct libusb20_transfer *xfer" "void *sc1"
91 .Fn libusb20_tr_set_timeout "struct libusb20_transfer *xfer" "uint32_t timeout"
93 .Fn libusb20_tr_set_total_frames "struct libusb20_transfer *xfer" "uint32_t nframes"
95 .Fn libusb20_tr_setup_bulk "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint32_t timeout"
97 .Fn libusb20_tr_setup_control "struct libusb20_transfer *xfer" "void *psetup" "void *pbuf" "uint32_t timeout"
99 .Fn libusb20_tr_setup_intr "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint32_t timeout"
101 .Fn libusb20_tr_setup_isoc "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint61_t fr_index"
103 .Fn libusb20_tr_bulk_intr_sync "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint32_t *pactlen" "uint32_t timeout"
105 .Fn libusb20_tr_start "struct libusb20_transfer *xfer"
107 .Fn libusb20_tr_stop "struct libusb20_transfer *xfer"
109 .Fn libusb20_tr_submit "struct libusb20_transfer *xfer"
111 .Fn libusb20_tr_get_priv_sc0 "struct libusb20_transfer *xfer"
113 .Fn libusb20_tr_get_priv_sc1 "struct libusb20_transfer *xfer"
115 .Fn libusb20_dev_get_backend_name "struct libusb20_device *"
117 .Fn libusb20_dev_get_port_path "struct libusb20_device *pdev" "uint8_t *buf" "uint8_t bufsize"
119 .Fn libusb20_dev_get_info "struct libusb20_device *pdev" "struct usb_device_info *pinfo"
121 .Fn libusb20_dev_get_iface_desc "struct libusb20_device *pdev" "uint8_t iface_index" "char *buf" "uint8_t len"
123 .Fn libusb20_dev_get_desc "struct libusb20_device *pdev"
125 .Fn libusb20_dev_get_stats "struct libusb20_device *pdev" "struct libusb20_device_stats *pstats"
127 .Fn libusb20_dev_close "struct libusb20_device *pdev"
129 .Fn libusb20_dev_detach_kernel_driver "struct libusb20_device *pdev" "uint8_t iface_index"
131 .Fn libusb20_dev_set_config_index "struct libusb20_device *pdev" "uint8_t configIndex"
133 .Fn libusb20_dev_get_debug "struct libusb20_device *pdev"
135 .Fn libusb20_dev_get_fd "struct libusb20_device *pdev"
137 .Fn libusb20_dev_kernel_driver_active "struct libusb20_device *pdev" "uint8_t iface_index"
139 .Fn libusb20_dev_open "struct libusb20_device *pdev" "uint16_t transfer_max"
141 .Fn libusb20_dev_process "struct libusb20_device *pdev"
143 .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"
145 .Fn libusb20_dev_req_string_sync "struct libusb20_device *pdev" "uint8_t index" "uint16_t langid" "void *ptr" "uint16_t len"
147 .Fn libusb20_dev_req_string_simple_sync "struct libusb20_device *pdev" "uint8_t index" "void *ptr" "uint16_t len"
149 .Fn libusb20_dev_reset "struct libusb20_device *pdev"
151 .Fn libusb20_dev_check_connected "struct libusb20_device *pdev"
153 .Fn libusb20_dev_set_power_mode "struct libusb20_device *pdev" "uint8_t power_mode"
155 .Fn libusb20_dev_get_power_mode "struct libusb20_device *pdev"
157 .Fn libusb20_dev_get_power_usage "struct libusb20_device *pdev"
159 .Fn libusb20_dev_set_alt_index "struct libusb20_device *pdev" "uint8_t iface_index" "uint8_t alt_index"
160 .Ft struct LIBUSB20_DEVICE_DESC_DECODED *
161 .Fn libusb20_dev_get_device_desc "struct libusb20_device *pdev"
162 .Ft struct libusb20_config *
163 .Fn libusb20_dev_alloc_config "struct libusb20_device *pdev" "uint8_t config_index"
164 .Ft struct libusb20_device *
165 .Fn libusb20_dev_alloc "void"
167 .Fn libusb20_dev_get_address "struct libusb20_device *pdev"
169 .Fn libusb20_dev_get_parent_address "struct libusb20_device *pdev"
171 .Fn libusb20_dev_get_parent_port "struct libusb20_device *pdev"
173 .Fn libusb20_dev_get_bus_number "struct libusb20_device *pdev"
175 .Fn libusb20_dev_get_mode "struct libusb20_device *pdev"
177 .Fn libusb20_dev_get_speed "struct libusb20_device *pdev"
179 .Fn libusb20_dev_get_config_index "struct libusb20_device *pdev"
181 .Fn libusb20_dev_free "struct libusb20_device *pdev"
183 .Fn libusb20_dev_set_debug "struct libusb20_device *pdev" "int debug"
185 .Fn libusb20_dev_wait_process "struct libusb20_device *pdev" "int timeout"
187 .Fn libusb20_be_get_template "struct libusb20_backend *pbe" "int *ptemp"
189 .Fn libusb20_be_set_template "struct libusb20_backend *pbe" "int temp"
191 .Fn libusb20_be_get_dev_quirk "struct libusb20_backend *pber" "uint16_t index" "struct libusb20_quirk *pq"
193 .Fn libusb20_be_get_quirk_name "struct libusb20_backend *pbe" "uint16_t index" "struct libusb20_quirk *pq"
195 .Fn libusb20_be_add_dev_quirk "struct libusb20_backend *pbe" "struct libusb20_quirk *pq"
197 .Fn libusb20_be_remove_dev_quirk "struct libusb20_backend *pbe" "struct libusb20_quirk *pq"
198 .Ft struct libusb20_backend *
199 .Fn libusb20_be_alloc_default "void"
200 .Ft struct libusb20_backend *
201 .Fn libusb20_be_alloc_freebsd "void"
202 .Ft struct libusb20_backend *
203 .Fn libusb20_be_alloc_linux "void"
204 .Ft struct libusb20_device *
205 .Fn libusb20_be_device_foreach "struct libusb20_backend *pbe" "struct libusb20_device *pdev"
207 .Fn libusb20_be_dequeue_device "struct libusb20_backend *pbe" "struct libusb20_device *pdev"
209 .Fn libusb20_be_enqueue_device "struct libusb20_backend *pbe" "struct libusb20_device *pdev"
211 .Fn libusb20_be_free "struct libusb20_backend *pbe"
213 .Fn libusb20_me_get_1 "const struct libusb20_me_struct *me" "uint16_t off"
215 .Fn libusb20_me_get_2 "const struct libusb20_me_struct *me" "uint16_t off"
217 .Fn libusb20_me_encode "void *pdata" "uint16_t len" "const void *pdecoded"
219 .Fn libusb20_me_decode "const void *pdata" "uint16_t len" "void *pdecoded"
220 .Ft "const uint8_t *"
221 .Fn libusb20_desc_foreach "const struct libusb20_me_struct *me" "const uint8_t *pdesc"
223 .Fn libusb20_strerror "int code"
225 .Fn libusb20_error_name "int code"
232 library implements functions to be able to easily access and control
233 USB through the USB file system interface.
236 interfaces are specific to the
238 usb stack and are not available on other operating systems, portable
239 applications should consider using
243 .Sh USB TRANSFER OPERATIONS
246 .Fn libusb20_tr_close
247 will release all kernel resources associated with an USB
250 This function returns zero upon success.
252 Non-zero return values indicate a LIBUSB20_ERROR value.
257 will allocate kernel buffer resources according to
261 associated with an USB
263 and bind the transfer to the specified
266 is the minimum buffer size which the data transport layer has to support.
271 library will use wMaxPacketSize to compute the buffer size.
272 This can be useful for isochronous transfers.
273 The actual buffer size can be greater than
276 .Fn libusb20_tr_get_max_total_length .
280 is OR'ed with LIBUSB20_MAX_FRAME_PRE_SCALE the remaining part of the
281 argument is converted from milliseconds into the actual number of
282 frames rounded up, when this function returns.
283 This flag is only valid for ISOCHRONOUS transfers and has no effect
284 for other transfer types.
285 The actual number of frames setup is found by calling
286 .Fn libusb20_tr_get_max_frames .
288 This function returns zero upon success.
290 Non-zero return values indicate a LIBUSB20_ERROR value.
294 .Fn libusb20_tr_open_stream
297 except that a stream ID can be specified for BULK endpoints having
300 can be used to open stream ID zero.
304 .Fn libusb20_tr_get_pointer
305 will return a pointer to the allocated USB transfer according to the
311 This function returns NULL in case of failure.
315 .Fn libusb20_tr_get_time_complete
316 will return the completion time of an USB transfer in
318 This function is most useful for isochronous USB transfers when doing echo
323 .Fn libusb20_tr_get_actual_frames
324 will return the actual number of USB frames after an USB
326 A value of zero means that no data was transferred.
329 .Fn libusb20_tr_get_actual_length
330 will return the sum of the actual length for all
331 transferred USB frames for the given USB transfer.
335 .Fn libusb20_tr_get_max_frames
336 will return the maximum number of USB frames that were
337 allocated when an USB transfer was setup for the given USB transfer.
341 .Fn libusb20_tr_get_max_packet_length
342 will return the maximum packet length in bytes
343 associated with the given USB transfer.
345 The packet length can be used round up buffer sizes so that short USB
346 packets are avoided for proxy buffers.
351 .Fn libusb20_tr_get_max_total_length
352 will return the maximum value for the data length sum of all USB
353 frames associated with an USB transfer.
354 In case of control transfers the value returned does not include the
355 length of the SETUP packet, 8 bytes, which is part of frame zero.
356 The returned value of this function is always aligned to the maximum
357 packet size, wMaxPacketSize, of the endpoint which the USB transfer is
362 .Fn libusb20_tr_get_status
363 will return the status of an USB transfer.
365 Status values are defined by a set of LIBUSB20_TRANSFER_XXX enums.
369 .Fn libusb20_tr_pending
370 will return non-zero if the given USB transfer is
371 pending for completion.
373 Else this function returns zero.
377 .Fn libusb20_tr_callback_wrapper
378 This is an internal function used to wrap asynchronous USB callbacks.
382 .Fn libusb20_tr_clear_stall_sync
383 This is an internal function used to synchronously clear the stall on
384 the given USB transfer.
386 Please see the USB specification for more information on stall
389 If the given USB transfer is pending when this function is called, the
390 USB transfer will complete with an error after that this function has
395 .Fn libusb20_tr_drain
396 will stop the given USB transfer and will not return
397 until the USB transfer has been stopped in hardware.
401 .Fn libusb20_tr_set_buffer
404 pointer for the given USB transfer and
407 Typically the frame index is zero.
412 .Fn libusb20_tr_set_callback
413 is used to set the USB callback for asynchronous USB
416 The callback type is defined by libusb20_tr_callback_t.
420 .Fn libusb20_tr_set_flags
421 is used to set various USB flags for the given USB transfer.
422 .Bl -tag -width "LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK"
423 .It LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK
424 Report a short frame as error.
425 .It LIBUSB20_TRANSFER_MULTI_SHORT_NOT_OK
426 Multiple short frames are not allowed.
427 .It LIBUSB20_TRANSFER_FORCE_SHORT
428 All transmitted frames are short terminated.
429 .It LIBUSB20_TRANSFER_DO_CLEAR_STALL
430 Will do a clear-stall before starting the transfer.
435 .Fn libusb20_tr_get_length
436 returns the length of the given USB frame by index.
437 After an USB transfer is complete the USB frame length will get updated to the actual transferred length.
441 .Fn libusb20_tr_set_length
442 sets the length of the given USB frame by index.
446 .Fn libusb20_tr_set_priv_sc0
447 sets private driver pointer number zero.
451 .Fn libusb20_tr_set_priv_sc1
452 sets private driver pointer number one.
456 .Fn libusb20_tr_set_timeout
457 sets the timeout for the given USB transfer.
459 A timeout value of zero means no timeout.
461 The timeout is given in milliseconds.
465 .Fn libusb20_tr_set_total_frames
466 sets the total number of frames that should be executed when the USB transfer is submitted.
468 The total number of USB frames must be less than the maximum number of USB frames associated with the given USB transfer.
472 .Fn libusb20_tr_setup_bulk
473 is a helper function for setting up a single frame USB BULK transfer.
477 .Fn libusb20_tr_setup_control
478 is a helper function for setting up a single or dual
479 frame USB CONTROL transfer depending on the control transfer length.
483 .Fn libusb20_tr_setup_intr
484 is a helper function for setting up a single frame USB INTERRUPT transfer.
488 .Fn libusb20_tr_setup_isoc
489 is a helper function for setting up a multi frame USB ISOCHRONOUS transfer.
493 .Fn libusb20_tr_bulk_intr_sync
494 will perform a synchronous BULK or INTERRUPT transfer having length given by the
496 argument and buffer pointer given by the
498 argument on the USB transfer given by the
504 argument is non-NULL the actual transfer length will be stored at the given pointer destination.
508 argument is non-zero the transfer will timeout after the given value in milliseconds.
510 This function does not change the transfer flags, like short packet not ok.
512 This function returns zero on success else a LIBUSB20_TRANSFER_XXX value is returned.
516 .Fn libusb20_tr_start
517 will get the USB transfer started, if not already
520 This function will not get the transfer queued in hardware.
522 This function is non-blocking.
527 will get the USB transfer stopped, if not already stopped.
529 This function is non-blocking, which means that the actual stop can
530 happen after the return of this function.
534 .Fn libusb20_tr_submit
535 will get the USB transfer queued in hardware.
540 .Fn libusb20_tr_get_priv_sc0
541 returns private driver pointer number zero associated
542 with an USB transfer.
547 .Fn libusb20_tr_get_priv_sc1
548 returns private driver pointer number one associated
549 with an USB transfer.
552 .Sh USB DEVICE OPERATIONS
555 .Fn libusb20_dev_get_backend_name
556 returns a zero terminated string describing the backend used.
560 .Fn libusb20_dev_get_port_path
561 retrieves the list of USB port numbers which the datastream for a given USB device follows.
562 The first port number is the Root HUB port number.
563 Then children port numbers follow.
564 The Root HUB device itself has a port path length of zero.
565 Valid port numbers start at one and range until and including 255.
566 Typically there should not be more than 16 levels, due to electrical and protocol limitations.
567 This functions returns the number of actual port levels upon success
568 else a LIBUSB20_ERROR value is returned which are always negative.
569 If the actual number of port levels is greater than the maximum
570 specified, a LIBUSB20_ERROR value is returned.
574 .Fn libusb20_dev_get_info
575 retrieves the BSD specific usb_device_info structure into the memory location given by
577 The USB device given by
579 must be opened before this function will succeed.
580 This function returns zero on success else a LIBUSB20_ERROR value is returned.
584 .Fn libusb20_dev_get_iface_desc
585 retrieves the kernel interface description for the given USB
587 The format of the USB interface description is: "drivername<unit>: <description>"
588 The description string is always zero terminated.
589 A zero length string is written in case no driver is attached to the given interface.
590 The USB device given by
592 must be opened before this function will succeed.
593 This function returns zero on success else a LIBUSB20_ERROR value is returned.
597 .Fn libusb20_dev_get_desc
598 returns a zero terminated string describing the given USB device.
599 The format of the string is: "drivername<unit>: <description>"
603 .Fn libusb20_dev_get_stats
604 retrieves the device statistics into the structure pointed to by the
607 This function returns zero on success else a LIBUSB20_ERROR value is returned.
611 .Fn libusb20_dev_close
612 will close the given USB device.
614 This function returns zero on success else a LIBUSB20_ERROR value is
619 .Fn libusb20_dev_detach_kernel_driver
620 will try to detach the kernel driver for the USB interface given by
623 This function returns zero on success else a LIBUSB20_ERROR value is
628 .Fn libusb20_dev_set_config_index
629 will try to set the configuration index on an USB
632 The first configuration index is zero.
634 The un-configure index is 255.
636 This function returns zero on success else a LIBUSB20_ERROR value is returned.
640 .Fn libusb20_dev_get_debug
641 returns the debug level of an USB device.
645 .Fn libusb20_dev_get_fd
646 returns the file descriptor of the given USB device.
648 A negative value is returned when no file descriptor is present.
650 The file descriptor can be used for polling purposes.
654 .Fn libusb20_dev_kernel_driver_active
655 returns zero if a kernel driver is active on the given USB interface.
657 Else a LIBUSB20_ERROR value is returned.
661 .Fn libusb20_dev_open
662 opens an USB device so that setting up USB transfers
665 The number of USB transfers can be zero which means only control
666 transfers are allowed.
668 This function returns zero on success else a LIBUSB20_ERROR value is
671 A return value of LIBUSB20_ERROR_BUSY means that the device is already
676 .Fn libusb20_dev_process
677 is called to sync kernel USB transfers with userland USB
680 This function returns zero on success else a LIBUSB20_ERROR value is
681 returned typically indicating that the given USB device has been
686 .Fn libusb20_dev_request_sync
687 will perform a synchronous control request on the given
690 Before this call will succeed the USB device must be opened.
693 is a pointer to a decoded and host endian SETUP packet.
695 is a pointer to a data transfer buffer associated with the control transaction.
696 This argument can be NULL.
698 is a pointer to a variable that will hold the actual transfer length after the
699 control transaction is complete.
701 is the transaction timeout given in milliseconds.
702 A timeout of zero means no timeout.
704 is used to specify transaction flags, for example LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK.
706 This function returns zero on success else a LIBUSB20_ERROR value is
711 .Fn libusb20_dev_req_string_sync
712 will synchronously request an USB string by language ID
713 and string index into the given buffer limited by a maximum length.
715 This function returns zero on success else a LIBUSB20_ERROR value is
720 .Fn libusb20_dev_req_string_simple_sync
721 will synchronously request an USB string using the
722 default language ID and convert the string into ASCII before storing
723 the string into the given buffer limited by a maximum length which
724 includes the terminating zero.
726 This function returns zero on success else a LIBUSB20_ERROR value is
732 .Fn libusb20_dev_reset
733 will try to BUS reset the given USB device and restore
734 the last set USB configuration.
736 This function returns zero on success else a LIBUSB20_ERROR value is
742 .Fn libusb20_dev_check_connected
743 will check if an opened USB device is still connected.
745 This function returns zero if the device is still connected else a LIBUSB20_ERROR value is returned.
750 .Fn libusb20_dev_set_power_mode
751 sets the power mode of the USB device.
754 .Bl -tag -width "LIBUSB20_POWER_OFF"
755 .It LIBUSB20_POWER_OFF
756 .It LIBUSB20_POWER_ON
757 .It LIBUSB20_POWER_SAVE
758 .It LIBUSB20_POWER_SUSPEND
759 .It LIBUSB20_POWER_RESUME
763 This function returns zero on success else a LIBUSB20_ERROR value is
768 .Fn libusb20_dev_get_power_mode
769 returns the currently selected power mode for the given
774 .Fn libusb20_dev_get_power_usage
775 returns the reported power usage in milliamps for the given USB device.
776 A power usage of zero typically means that the device is self powered.
780 .Fn libusb20_dev_set_alt_index
781 will try to set the given alternate index for the given
784 This function returns zero on success else a LIBUSB20_ERROR value is
789 .Fn libusb20_dev_get_device_desc
790 returns a pointer to the decoded and host endian version
791 of the device descriptor.
793 The USB device need not be opened when calling this function.
797 .Fn libusb20_dev_alloc_config
798 will read out and decode the USB config descriptor for the given USB device
800 This function returns a pointer to the decoded configuration which must eventually
802 NULL is returned in case of failure.
806 .Fn libusb20_dev_alloc
807 is an internal function to allocate a new USB device.
811 .Fn libusb20_dev_get_address
812 returns the internal and not necessarily the real
813 hardware address of the given USB device.
814 Valid addresses start at one.
818 .Fn libusb20_dev_get_parent_address
819 returns the internal and not necessarily the real hardware address of
820 the given parent USB HUB device.
821 This value is zero for the root HUB which usually has a device address
823 Valid addresses start at one.
827 .Fn libusb20_dev_get_parent_port
828 returns the port number on the parent USB HUB device.
829 This value is zero for the root HUB which usually has a device address
831 Valid port numbers start at one.
835 .Fn libusb20_dev_get_bus_number
836 returns the internal bus number which the given USB
838 Valid bus numbers start at zero.
842 .Fn libusb20_dev_get_mode
843 returns the current operation mode of the USB entity.
845 Valid return values are:
846 .Bl -tag -width "LIBUSB20_MODE_DEVICE"
847 .It LIBUSB20_MODE_HOST
848 .It LIBUSB20_MODE_DEVICE
853 .Fn libusb20_dev_get_speed
854 returns the current speed of the given USB device.
856 .Bl -tag -width "LIBUSB20_SPEED_VARIABLE"
857 .It LIBUSB20_SPEED_UNKNOWN
858 .It LIBUSB20_SPEED_LOW
859 .It LIBUSB20_SPEED_FULL
860 .It LIBUSB20_SPEED_HIGH
861 .It LIBUSB20_SPEED_VARIABLE
862 .It LIBUSB20_SPEED_SUPER
867 .Fn libusb20_dev_get_config_index
868 returns the currently selected config index for the given
873 .Fn libusb20_dev_free
874 will free the given USB device and all associated USB
879 .Fn libusb20_dev_set_debug
880 will set the debug level for the given USB device.
884 .Fn libusb20_dev_wait_process
885 will wait until a pending USB transfer has completed on
886 the given USB device.
888 A timeout value can be specified which is passed on to the
892 .Sh USB BACKEND OPERATIONS
894 .Fn libusb20_be_get_template
895 will return the currently selected global USB device
896 side mode template into the integer pointer
898 This function returns zero on success else a LIBUSB20_ERROR value is
903 .Fn libusb20_be_set_template
904 will set the global USB device side mode template to
906 The new template is not activated until after the next USB
908 The template number decides how the USB device will present itself to
909 the USB Host, like Mass Storage Device, USB Ethernet Device.
913 This function returns zero on success else a LIBUSB20_ERROR value is
918 .Fn libusb20_be_get_dev_quirk
919 will return the device quirk according to
921 into the libusb20_quirk structure pointed to by
923 This function returns zero on success else a LIBUSB20_ERROR value is
926 If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
931 .Fn libusb20_be_get_quirk_name
932 will return the quirk name according to
934 into the libusb20_quirk structure pointed to by
936 This function returns zero on success else a LIBUSB20_ERROR value is
939 If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
944 .Fn libusb20_be_add_dev_quirk
945 will add the libusb20_quirk structure pointed to by the
947 argument into the device quirk list.
949 This function returns zero on success else a LIBUSB20_ERROR value is
952 If the given quirk cannot be added LIBUSB20_ERROR_NO_MEM is
957 .Fn libusb20_be_remove_dev_quirk
958 will remove the quirk matching the libusb20_quirk structure pointed to by the
960 argument from the device quirk list.
962 This function returns zero on success else a LIBUSB20_ERROR value is
965 If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
970 .Fn libusb20_be_alloc_default
971 .Fn libusb20_be_alloc_freebsd
972 .Fn libusb20_be_alloc_linux
973 These functions are used to allocate a specific USB backend or the operating system
975 Allocating a backend is a way to scan for currently present USB devices.
978 .Fn libusb20_be_device_foreach
979 is used to iterate USB devices present in a USB backend.
981 The starting value of
985 This function returns the next USB device in the list.
987 If NULL is returned the end of the USB device list has been reached.
991 .Fn libusb20_be_dequeue_device
992 will dequeue the given USB device pointer from the
993 backend USB device list.
995 Dequeued USB devices will not be freed when the backend is freed.
999 .Fn libusb20_be_enqueue_device
1000 will enqueue the given USB device pointer in the backend USB device list.
1002 Enqueued USB devices will get freed when the backend is freed.
1006 .Fn libusb20_be_free
1007 will free the given backend and all USB devices in its device list.
1010 .Sh USB DESCRIPTOR PARSING
1012 .Fn libusb20_me_get_1 pie offset
1013 This function will return a byte at the given byte offset of a message
1016 This function is safe against invalid offsets.
1020 .Fn libusb20_me_get_2 pie offset
1021 This function will return a little endian 16-bit value at the given byte offset of a message
1024 This function is safe against invalid offsets.
1028 .Fn libusb20_me_encode pbuf len pdecoded
1029 This function will encode a so-called *DECODED structure into binary
1032 The total encoded length that will fit in the given buffer is
1035 If the buffer pointer is NULL no data will be written to the buffer
1040 .Fn libusb20_me_decode pbuf len pdecoded
1041 This function will decode a binary structure into a so-called *DECODED
1044 The total decoded length is returned.
1046 The buffer pointer cannot be NULL.
1051 .Fn libusb20_strerror "int code"
1052 Get the ASCII representation of the error given by the
1055 This function does not return NULL.
1058 .Fn libusb20_error_name "int code"
1059 Get the ASCII representation of the error enum given by the
1062 This function does not return NULL.
1080 API derives from the libusb project at sourceforge.