libkiconv: Remove unneeded SHLIBDIR in the Makefile.
[dragonfly.git] / lib / libusb / libusb20.3
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: src/lib/libusb/libusb20.3,v 1.17 2012/08/13 18:10:52 hselasky Exp $
28 .\"
29 .Dd October 14, 2012
30 .Dt LIBUSB20 3
31 .Os
32 .Sh NAME
33 .Nm libusb20
34 .
35 .Nd "USB access library"
36 .
37 .
38 .Sh LIBRARY
39 .
40 .
41 USB 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 uint8_t
102 .Fn libusb20_tr_bulk_intr_sync "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint32_t *pactlen" "uint32_t timeout"
103 .Ft void
104 .Fn libusb20_tr_start "struct libusb20_transfer *xfer"
105 .Ft void
106 .Fn libusb20_tr_stop "struct libusb20_transfer *xfer"
107 .Ft void
108 .Fn libusb20_tr_submit "struct libusb20_transfer *xfer"
109 .Ft void *
110 .Fn libusb20_tr_get_priv_sc0 "struct libusb20_transfer *xfer"
111 .Ft void *
112 .Fn libusb20_tr_get_priv_sc1 "struct libusb20_transfer *xfer"
113 .Ft const char *
114 .Fn libusb20_dev_get_backend_name "struct libusb20_device *"
115 .Ft int
116 .Fn libusb20_dev_get_info "struct libusb20_device *pdev" "struct usb_device_info *pinfo"
117 .Ft int
118 .Fn libusb20_dev_get_iface_desc "struct libusb20_device *pdev" "uint8_t iface_index" "char *buf" "uint8_t len"
119 .Ft const char *
120 .Fn libusb20_dev_get_desc "struct libusb20_device *pdev"
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_request_sync "struct libusb20_device *pdev" "struct LIBUSB20_CONTROL_SETUP_DECODED *setup" "void *data" "uint16_t *pactlen" "uint32_t timeout" "uint8_t flags"
139 .Ft int
140 .Fn libusb20_dev_req_string_sync "struct libusb20_device *pdev" "uint8_t index" "uint16_t langid" "void *ptr" "uint16_t len"
141 .Ft int
142 .Fn libusb20_dev_req_string_simple_sync "struct libusb20_device *pdev" "uint8_t index" "void *ptr" "uint16_t len"
143 .Ft int
144 .Fn libusb20_dev_reset "struct libusb20_device *pdev"
145 .Ft int
146 .Fn libusb20_dev_check_connected "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_parent_address "struct libusb20_device *pdev"
163 .Ft uint8_t
164 .Fn libusb20_dev_get_parent_port "struct libusb20_device *pdev"
165 .Ft uint8_t
166 .Fn libusb20_dev_get_bus_number "struct libusb20_device *pdev"
167 .Ft uint8_t
168 .Fn libusb20_dev_get_mode "struct libusb20_device *pdev"
169 .Ft uint8_t
170 .Fn libusb20_dev_get_speed "struct libusb20_device *pdev"
171 .Ft uint8_t
172 .Fn libusb20_dev_get_config_index "struct libusb20_device *pdev"
173 .Ft void
174 .Fn libusb20_dev_free "struct libusb20_device *pdev"
175 .Ft void
176 .Fn libusb20_dev_set_debug "struct libusb20_device *pdev" "int debug"
177 .Ft void
178 .Fn libusb20_dev_wait_process "struct libusb20_device *pdev" "int timeout"
179 .Ft int
180 .Fn libusb20_be_get_template "struct libusb20_backend *pbe" "int *ptemp"
181 .Ft int
182 .Fn libusb20_be_set_template "struct libusb20_backend *pbe" "int temp"
183 .Ft int
184 .Fn libusb20_be_get_dev_quirk "struct libusb20_backend *pber" "uint16_t index" "struct libusb20_quirk *pq"
185 .Ft int
186 .Fn libusb20_be_get_quirk_name "struct libusb20_backend *pbe" "uint16_t index" "struct libusb20_quirk *pq"
187 .Ft int
188 .Fn libusb20_be_add_dev_quirk "struct libusb20_backend *pbe" "struct libusb20_quirk *pq"
189 .Ft int
190 .Fn libusb20_be_remove_dev_quirk "struct libusb20_backend *pbe" "struct libusb20_quirk *pq"
191 .Ft struct libusb20_backend *
192 .Fn libusb20_be_alloc_default "void"
193 .Ft struct libusb20_backend *
194 .Fn libusb20_be_alloc_freebsd "void"
195 .Ft struct libusb20_backend *
196 .Fn libusb20_be_alloc_linux "void"
197 .Ft struct libusb20_device *
198 .Fn libusb20_be_device_foreach  "struct libusb20_backend *pbe" "struct libusb20_device *pdev"
199 .Ft void
200 .Fn libusb20_be_dequeue_device "struct libusb20_backend *pbe" "struct libusb20_device *pdev"
201 .Ft void
202 .Fn libusb20_be_enqueue_device "struct libusb20_backend *pbe" "struct libusb20_device *pdev"
203 .Ft void
204 .Fn libusb20_be_free "struct libusb20_backend *pbe"
205 .Ft uint8_t
206 .Fn libusb20_me_get_1 "const struct libusb20_me_struct *me" "uint16_t off"
207 .Ft uint16_t
208 .Fn libusb20_me_get_2 "const struct libusb20_me_struct *me" "uint16_t off"
209 .Ft uint16_t
210 .Fn libusb20_me_encode "void *pdata" "uint16_t len" "const void *pdecoded"
211 .Ft uint16_t
212 .Fn libusb20_me_decode "const void *pdata" "uint16_t len" "void *pdecoded"
213 .Ft "const uint8_t *"
214 .Fn libusb20_desc_foreach "const struct libusb20_me_struct *me" "const uint8_t *pdesc"
215 .Ft "const char *"
216 .Fn libusb20_strerror "int code"
217 .Ft "const char *"
218 .Fn libusb20_error_name "int code"
219 .
220 .
221 .Sh DESCRIPTION
222 .
223 The
224 .Nm
225 library implements functions to be able to easily access and control
226 USB through the USB file system interface.
227 The
228 .Nm
229 interfaces are specific to the
230 .Fx
231 usb stack and are not available on other operating systems, portable
232 applications should consider using
233 .Xr libusb 3 .
234 .
235 .
236 .Sh USB TRANSFER OPERATIONS
237 .
238 .
239 .Fn libusb20_tr_close
240 will release all kernel resources associated with an USB
241 .Fa xfer .
242 .
243 This function returns zero upon success.
244 .
245 Non-zero return values indicate a LIBUSB20_ERROR value.
246 .
247 .Pp
248 .
249 .Fn libusb20_tr_open
250 will allocate kernel buffer resources according to
251 .Fa max_buf_size
252 and
253 .Fa max_frame_count
254 associated with an USB
255 .Fa pxfer
256 and bind the transfer to the specified
257 .Fa ep_no .
258 .Fa max_buf_size
259 is the minimum buffer size which the data transport layer has to support.
260 If
261 .Fa max_buf_size
262 is zero, the
263 .Nm
264 library will use wMaxPacketSize to compute the buffer size.
265 This can be useful for isochronous transfers.
266 The actual buffer size can be greater than
267 .Fa max_buf_size
268 and is returned by
269 .Fn libusb20_tr_get_max_total_length .
270 .
271 If
272 .Fa max_frame_count
273 is OR'ed with LIBUSB20_MAX_FRAME_PRE_SCALE the remaining part of the
274 argument is converted from milliseconds into the actual number of
275 frames rounded up, when this function returns.
276 This flag is only valid for ISOCHRONOUS transfers and has no effect
277 for other transfer types.
278 The actual number of frames setup is found by calling
279 .Fn libusb20_tr_get_max_frames .
280 .
281 This function returns zero upon success.
282 .
283 Non-zero return values indicate a LIBUSB20_ERROR value.
284 .
285 .Pp
286 .
287 .Fn libusb20_tr_get_pointer
288 will return a pointer to the allocated USB transfer according to the
289 .Fa pdev
290 and
291 .Fa tr_index
292 arguments.
293 .
294 This function returns NULL in case of failure.
295 .
296 .Pp
297 .
298 .Fn libusb20_tr_get_time_complete
299 will return the completion time of an USB transfer in
300 millisecond units. This function is most useful for isochronous USB
301 transfers when doing echo cancelling.
302 .
303 .Pp
304 .
305 .Fn libusb20_tr_get_actual_frames
306 will return the actual number of USB frames after an USB
307 transfer completed. A value of zero means that no data was transferred.
308 .
309 .Pp
310 .
311 .Fn libusb20_tr_get_actual_length
312 will return the sum of the actual length for all
313 transferred USB frames for the given USB transfer.
314 .
315 .Pp
316 .
317 .Fn libusb20_tr_get_max_frames
318 will return the maximum number of USB frames that were
319 allocated when an USB transfer was setup for the given USB transfer.
320 .
321 .Pp
322 .
323 .Fn libusb20_tr_get_max_packet_length
324 will return the maximum packet length in bytes
325 associated with the given USB transfer.
326 .
327 The packet length can be used round up buffer sizes so that short USB
328 packets are avoided for proxy buffers.
329 .
330 .
331 .Pp
332 .
333 .Fn libusb20_tr_get_max_total_length
334 will return the maximum value for the data length sum of all USB
335 frames associated with an USB transfer.
336 In case of control transfers the value returned does not include the
337 length of the SETUP packet, 8 bytes, which is part of frame zero.
338 The returned value of this function is always aligned to the maximum
339 packet size, wMaxPacketSize, of the endpoint which the USB transfer is
340 bound to.
341 .
342 .Pp
343 .
344 .Fn libusb20_tr_get_status
345 will return the status of an USB transfer.
346 .
347 Status values are defined by a set of LIBUSB20_TRANSFER_XXX enums.
348 .
349 .Pp
350 .
351 .Fn libusb20_tr_pending
352 will return non-zero if the given USB transfer is
353 pending for completion.
354 .
355 Else this function returns zero.
356 .
357 .Pp
358 .
359 .Fn libusb20_tr_callback_wrapper
360 This is an internal function used to wrap asynchronous USB callbacks.
361 .
362 .Pp
363 .
364 .Fn libusb20_tr_clear_stall_sync
365 This is an internal function used to synchronously clear the stall on
366 the given USB transfer.
367 .
368 Please see the USB specification for more information on stall
369 clearing.
370 .
371 If the given USB transfer is pending when this function is called, the
372 USB transfer will complete with an error after that this function has
373 been called.
374 .
375 .Pp
376 .
377 .Fn libusb20_tr_drain
378 will stop the given USB transfer and will not return
379 until the USB transfer has been stopped in hardware.
380 .
381 .Pp
382 .
383 .Fn libusb20_tr_set_buffer
384 is used to set the
385 .Fa buffer
386 pointer for the given USB transfer and
387 .Fa fr_index .
388 .
389 Typically the frame index is zero.
390 .
391 .
392 .Pp
393 .
394 .Fn libusb20_tr_set_callback
395 is used to set the USB callback for asynchronous USB
396 transfers.
397 .
398 The callback type is defined by libusb20_tr_callback_t.
399 .
400 .Pp
401 .
402 .Fn libusb20_tr_set_flags
403 is used to set various USB flags for the given USB transfer.
404 .Bl -tag -width "LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK"
405 .It LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK
406 Report a short frame as error.
407 .It LIBUSB20_TRANSFER_MULTI_SHORT_NOT_OK
408 Multiple short frames are not allowed.
409 .It LIBUSB20_TRANSFER_FORCE_SHORT
410 All transmitted frames are short terminated.
411 .It LIBUSB20_TRANSFER_DO_CLEAR_STALL
412 Will do a clear-stall before starting the transfer.
413 .El
414 .
415 .Pp
416 .
417 .Fn libusb20_tr_get_length
418 returns the length of the given USB frame by index.
419 After an USB transfer is complete the USB frame length will get updated to the actual transferred length.
420 .
421 .Pp
422 .
423 .Fn libusb20_tr_set_length
424 sets the length of the given USB frame by index.
425 .
426 .Pp
427 .
428 .Fn libusb20_tr_set_priv_sc0
429 sets private driver pointer number zero.
430 .
431 .Pp
432 .
433 .Fn libusb20_tr_set_priv_sc1
434 sets private driver pointer number one.
435 .
436 .Pp
437 .
438 .Fn libusb20_tr_set_timeout
439 sets the timeout for the given USB transfer.
440 .
441 A timeout value of zero means no timeout.
442 .
443 The timeout is given in milliseconds.
444 .
445 .Pp
446 .
447 .Fn libusb20_tr_set_total_frames
448 sets the total number of frames that should be executed when the USB transfer is submitted.
449 .
450 The total number of USB frames must be less than the maximum number of USB frames associated with the given USB transfer.
451 .
452 .Pp
453 .
454 .Fn libusb20_tr_setup_bulk
455 is a helper function for setting up a single frame USB BULK transfer.
456 .
457 .Pp
458 .
459 .Fn libusb20_tr_setup_control
460 is a helper function for setting up a single or dual
461 frame USB CONTROL transfer depending on the control transfer length.
462 .
463 .Pp
464 .
465 .Fn libusb20_tr_setup_intr
466 is a helper function for setting up a single frame USB INTERRUPT transfer.
467 .
468 .Pp
469 .
470 .Fn libusb20_tr_setup_isoc
471 is a helper function for setting up a multi frame USB ISOCHRONOUS transfer.
472 .
473 .Pp
474 .
475 .Fn libusb20_tr_bulk_intr_sync
476 will perform a synchronous BULK or INTERRUPT transfer having length given by the
477 .Fa length
478 argument and buffer pointer given by the
479 .Fa pbuf
480 argument on the USB transfer given by the
481 .Fa xfer
482 argument.
483 .
484 If the
485 .Fa pactlen
486 argument is non-NULL the actual transfer length will be stored at the given pointer destination.
487 .
488 If the
489 .Fa timeout
490 argument is non-zero the transfer will timeout after the given value in milliseconds.
491 .
492 This function does not change the transfer flags, like short packet not ok.
493 .
494 This function returns zero on success else a LIBUSB20_TRANSFER_XXX value is returned.
495 .
496 .Pp
497 .
498 .Fn libusb20_tr_start
499 will get the USB transfer started, if not already
500 started.
501 .
502 This function will not get the transfer queued in hardware.
503 .
504 This function is non-blocking.
505 .
506 .Pp
507 .
508 .Fn libusb20_tr_stop
509 will get the USB transfer stopped, if not already stopped.
510 .
511 This function is non-blocking, which means that the actual stop can
512 happen after the return of this function.
513 .
514 .Pp
515 .
516 .Fn libusb20_tr_submit
517 will get the USB transfer queued in hardware.
518 .
519 .
520 .Pp
521 .
522 .Fn libusb20_tr_get_priv_sc0
523 returns private driver pointer number zero associated
524 with an USB transfer.
525 .
526 .
527 .Pp
528 .
529 .Fn libusb20_tr_get_priv_sc1
530 returns private driver pointer number one associated
531 with an USB transfer.
532 .
533 .
534 .Sh USB DEVICE OPERATIONS
535 .
536 .
537 .Fn libusb20_dev_get_backend_name
538 returns a zero terminated string describing the backend used.
539 .
540 .Pp
541 .
542 .Fn libusb20_dev_get_info
543 retrieves the BSD specific usb_device_info structure into the memory location given by
544 .Fa pinfo .
545 The USB device given by
546 .Fa pdev
547 must be opened before this function will succeed.
548 This function returns zero on success else a LIBUSB20_ERROR value is returned.
549 .
550 .Pp
551 .
552 .Fn libusb20_dev_get_iface_desc
553 retrieves the kernel interface description for the given USB
554 .Fa iface_index .
555 The format of the USB interface description is: "drivername<unit>: <description>"
556 The description string is always zero terminated.
557 A zero length string is written in case no driver is attached to the given interface.
558 The USB device given by
559 .Fa pdev
560 must be opened before this function will succeed.
561 This function returns zero on success else a LIBUSB20_ERROR value is returned.
562 .
563 .Pp
564 .
565 .Fn libusb20_dev_get_desc
566 returns a zero terminated string describing the given USB device.
567 The format of the string is: "drivername<unit>: <description>"
568 .
569 .Pp
570 .
571 .Fn libusb20_dev_close
572 will close the given USB device.
573 .
574 This function returns zero on success else a LIBUSB20_ERROR value is
575 returned.
576 .
577 .Pp
578 .
579 .Fn libusb20_dev_detach_kernel_driver
580 will try to detach the kernel driver for the USB interface given by
581 .Fa iface_index .
582 .
583 This function returns zero on success else a LIBUSB20_ERROR value is
584 returned.
585 .
586 .Pp
587 .
588 .Fn libusb20_dev_set_config_index
589 will try to set the configuration index on an USB
590 device.
591 .
592 The first configuration index is zero.
593 .
594 The un-configure index is 255.
595 .
596 This function returns zero on success else a LIBUSB20_ERROR value is returned.
597 .
598 .Pp
599 .
600 .Fn libusb20_dev_get_debug
601 returns the debug level of an USB device.
602 .
603 .Pp
604 .
605 .Fn libusb20_dev_get_fd
606 returns the file descriptor of the given USB device.
607 .
608 A negative value is returned when no file descriptor is present.
609 .
610 The file descriptor can be used for polling purposes.
611 .
612 .Pp
613 .
614 .Fn libusb20_dev_kernel_driver_active
615 returns zero if a kernel driver is active on the given USB interface.
616 .
617 Else a LIBUSB20_ERROR value is returned.
618 .
619 .Pp
620 .
621 .Fn libusb20_dev_open
622 opens an USB device so that setting up USB transfers
623 becomes possible.
624 .
625 The number of USB transfers can be zero which means only control
626 transfers are allowed.
627 .
628 This function returns zero on success else a LIBUSB20_ERROR value is
629 returned.
630 .
631 A return value of LIBUSB20_ERROR_BUSY means that the device is already
632 opened.
633 .
634 .Pp
635 .
636 .Fn libusb20_dev_process
637 is called to sync kernel USB transfers with userland USB
638 transfers.
639 .
640 This function returns zero on success else a LIBUSB20_ERROR value is
641 returned typically indicating that the given USB device has been
642 detached.
643 .
644 .Pp
645 .
646 .Fn libusb20_dev_request_sync
647 will perform a synchronous control request on the given
648 USB device.
649 .
650 Before this call will succeed the USB device must be opened.
651 .
652 .Fa setup
653 is a pointer to a decoded and host endian SETUP packet.
654 .Fa data
655 is a pointer to a data transfer buffer associated with the control transaction. This argument can be NULL.
656 .Fa pactlen
657 is a pointer to a variable that will hold the actual transfer length after the control transaction is complete.
658 .Fa timeout
659 is the transaction timeout given in milliseconds.
660 A timeout of zero means no timeout.
661 .Fa flags
662 is used to specify transaction flags, for example LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK.
663 .
664 This function returns zero on success else a LIBUSB20_ERROR value is
665 returned.
666 .
667 .Pp
668 .
669 .Fn libusb20_dev_req_string_sync
670 will synchronously request an USB string by language ID
671 and string index into the given buffer limited by a maximum length.
672 .
673 This function returns zero on success else a LIBUSB20_ERROR value is
674 returned.
675 .
676 .Pp
677 .
678 .Fn libusb20_dev_req_string_simple_sync
679 will synchronously request an USB string using the
680 default language ID and convert the string into ASCII before storing
681 the string into the given buffer limited by a maximum length which
682 includes the terminating zero.
683 .
684 This function returns zero on success else a LIBUSB20_ERROR value is
685 returned.
686 .
687 .
688 .Pp
689 .
690 .Fn libusb20_dev_reset
691 will try to BUS reset the given USB device and restore
692 the last set USB configuration.
693 .
694 This function returns zero on success else a LIBUSB20_ERROR value is
695 returned.
696 .
697 .
698 .Pp
699 .
700 .Fn libusb20_dev_check_connected
701 will check if an opened USB device is still connected.
702 .
703 This function returns zero if the device is still connected else a LIBUSB20_ERROR value is returned.
704 .
705 .
706 .Pp
707 .
708 .Fn libusb20_dev_set_power_mode
709 sets the power mode of the USB device.
710 .
711 Valid power modes:
712 .Bl -tag -width "LIBUSB20_POWER_OFF"
713 .It LIBUSB20_POWER_OFF
714 .It LIBUSB20_POWER_ON
715 .It LIBUSB20_POWER_SAVE
716 .It LIBUSB20_POWER_SUSPEND
717 .It LIBUSB20_POWER_RESUME
718 .El
719 .Pp
720 .
721 This function returns zero on success else a LIBUSB20_ERROR value is
722 returned.
723 .
724 .Pp
725 .
726 .Fn libusb20_dev_get_power_mode
727 returns the currently selected power mode for the given
728 USB device.
729 .
730 .Pp
731 .
732 .Fn libusb20_dev_set_alt_index
733 will try to set the given alternate index for the given
734 USB interface index.
735 .
736 This function returns zero on success else a LIBUSB20_ERROR value is
737 returned.
738 .
739 .Pp
740 .
741 .Fn libusb20_dev_get_device_desc
742 returns a pointer to the decoded and host endian version
743 of the device descriptor.
744 .
745 The USB device need not be opened when calling this function.
746 .
747 .Pp
748 .
749 .Fn libusb20_dev_alloc_config
750 will read out and decode the USB config descriptor for
751 the given USB device and config index. This function returns a pointer
752 to the decoded configuration which must eventually be passed to
753 free(). NULL is returned in case of failure.
754 .
755 .Pp
756 .
757 .Fn libusb20_dev_alloc
758 is an internal function to allocate a new USB device.
759 .
760 .Pp
761 .
762 .Fn libusb20_dev_get_address
763 returns the internal and not necessarily the real
764 hardware address of the given USB device.
765 Valid addresses start at one.
766 .
767 .Pp
768 .
769 .Fn libusb20_dev_get_parent_address
770 returns the internal and not necessarily the real hardware address of
771 the given parent USB HUB device.
772 This value is zero for the root HUB which usually has a device address
773 equal to one.
774 Valid addresses start at one.
775 .
776 .Pp
777 .
778 .Fn libusb20_dev_get_parent_port
779 returns the port number on the parent USB HUB device.
780 This value is zero for the root HUB which usually has a device address
781 equal to one.
782 Valid port numbers start at one.
783 .
784 .Pp
785 .
786 .Fn libusb20_dev_get_bus_number
787 returns the internal bus number which the given USB
788 device belongs to.
789 Valid bus numbers start at zero.
790 .
791 .Pp
792 .
793 .Fn libusb20_dev_get_mode
794 returns the current operation mode of the USB entity.
795 .
796 Valid return values are:
797 .Bl -tag -width "LIBUSB20_MODE_DEVICE"
798 .It LIBUSB20_MODE_HOST
799 .It LIBUSB20_MODE_DEVICE
800 .El
801 .
802 .Pp
803 .
804 .Fn libusb20_dev_get_speed
805 returns the current speed of the given USB device.
806 .
807 .Bl -tag -width "LIBUSB20_SPEED_VARIABLE"
808 .It LIBUSB20_SPEED_UNKNOWN
809 .It LIBUSB20_SPEED_LOW
810 .It LIBUSB20_SPEED_FULL
811 .It LIBUSB20_SPEED_HIGH
812 .It LIBUSB20_SPEED_VARIABLE
813 .It LIBUSB20_SPEED_SUPER
814 .El
815 .
816 .Pp
817 .
818 .Fn libusb20_dev_get_config_index
819 returns the currently selected config index for the given
820 USB device.
821 .
822 .Pp
823 .
824 .Fn libusb20_dev_free
825 will free the given USB device and all associated USB
826 transfers.
827 .
828 .Pp
829 .
830 .Fn libusb20_dev_set_debug
831 will set the debug level for the given USB device.
832 .
833 .Pp
834 .
835 .Fn libusb20_dev_wait_process
836 will wait until a pending USB transfer has completed on
837 the given USB device.
838 .
839 A timeout value can be specified which is passed on to the
840 .Xr poll 2
841 function.
842 .
843 .Sh USB BACKEND OPERATIONS
844 .
845 .Fn libusb20_be_get_template
846 will return the currently selected global USB device
847 side mode template into the integer pointer
848 .Fa ptemp .
849 This function returns zero on success else a LIBUSB20_ERROR value is
850 returned.
851 .
852 .Pp
853 .
854 .Fn libusb20_be_set_template
855 will set the global USB device side mode template to
856 .Fa temp .
857 The new template is not activated until after the next USB
858 enumeration.
859 The template number decides how the USB device will present itself to
860 the USB Host, like Mass Storage Device, USB Ethernet Device. Also see
861 the
862 .Xr usb2_template 4
863 module.
864 This function returns zero on success else a LIBUSB20_ERROR value is
865 returned.
866 .
867 .Pp
868 .
869 .Fn libusb20_be_get_dev_quirk
870 will return the device quirk according to
871 .Fa index
872 into the libusb20_quirk structure pointed to by
873 .Fa pq .
874 This function returns zero on success else a LIBUSB20_ERROR value is
875 returned.
876 .
877 If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
878 returned.
879 .
880 .Pp
881 .
882 .Fn libusb20_be_get_quirk_name
883 will return the quirk name according to
884 .Fa index
885 into the libusb20_quirk structure pointed to by
886 .Fa pq .
887 This function returns zero on success else a LIBUSB20_ERROR value is
888 returned.
889 .
890 If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
891 returned.
892 .
893 .Pp
894 .
895 .Fn libusb20_be_add_dev_quirk
896 will add the libusb20_quirk structure pointed to by the
897 .Fa pq
898 argument into the device quirk list.
899 .
900 This function returns zero on success else a LIBUSB20_ERROR value is
901 returned.
902 .
903 If the given quirk cannot be added LIBUSB20_ERROR_NO_MEM is
904 returned.
905 .
906 .Pp
907 .
908 .Fn libusb20_be_remove_dev_quirk
909 will remove the quirk matching the libusb20_quirk structure pointed to by the
910 .Fa pq
911 argument from the device quirk list.
912 .
913 This function returns zero on success else a LIBUSB20_ERROR value is
914 returned.
915 .
916 If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
917 returned.
918 .
919 .Pp
920 .
921 .Fn libusb20_be_alloc_default
922 .Fn libusb20_be_alloc_freebsd
923 .Fn libusb20_be_alloc_linux
924 These functions are used to allocate a specific USB backend or the
925 operating system default USB backend. Allocating a backend is a way to
926 scan for currently present USB devices.
927 .
928 .Pp
929 .
930 .Fn libusb20_be_device_foreach
931 is used to iterate USB devices present in a USB backend.
932 .
933 The starting value of
934 .Fa pdev
935 is NULL.
936 .
937 This function returns the next USB device in the list.
938 .
939 If NULL is returned the end of the USB device list has been reached.
940 .
941 .Pp
942 .
943 .Fn libusb20_be_dequeue_device
944 will dequeue the given USB device pointer from the
945 backend USB device list.
946 .
947 Dequeued USB devices will not be freed when the backend is freed.
948 .
949 .Pp
950 .
951 .Fn libusb20_be_enqueue_device
952 will enqueue the given USB device pointer in the backend USB device list.
953 .
954 Enqueued USB devices will get freed when the backend is freed.
955 .
956 .Pp
957 .
958 .Fn libusb20_be_free
959 will free the given backend and all USB devices in its device list.
960 .
961 .
962 .Sh USB DESCRIPTOR PARSING
963 .
964 .Fn libusb20_me_get_1 pie offset
965 This function will return a byte at the given byte offset of a message
966 entity.
967 .
968 This function is safe against invalid offsets.
969 .
970 .Pp
971 .
972 .Fn libusb20_me_get_2 pie offset
973 This function will return a little endian 16-bit value at the given byte offset of a message
974 entity.
975 .
976 This function is safe against invalid offsets.
977 .
978 .Pp
979 .
980 .Fn libusb20_me_encode pbuf len pdecoded
981 This function will encode a so-called *DECODED structure into binary
982 format.
983 .
984 The total encoded length that will fit in the given buffer is
985 returned.
986 .
987 If the buffer pointer is NULL no data will be written to the buffer
988 location.
989 .
990 .Pp
991 .
992 .Fn libusb20_me_decode pbuf len pdecoded
993 This function will decode a binary structure into a so-called *DECODED
994 structure.
995 .
996 The total decoded length is returned.
997 .
998 The buffer pointer cannot be NULL.
999 .
1000 .
1001 .Sh USB DEBUGGING
1002 .Ft const char *
1003 .Fn libusb20_strerror "int code"
1004 Get the ASCII representation of the error given by the
1005 .Fa code
1006 argument.
1007 This function does not return NULL.
1008 .Pp
1009 .Ft const char *
1010 .Fn libusb20_error_name "int code"
1011 Get the ASCII representation of the error enum given by the
1012 .Fa code
1013 argument.
1014 This function does not return NULL.
1015 .
1016 .Sh FILES
1017 .
1018 .
1019 /dev/usb
1020 .Sh SEE ALSO
1021 .Xr usb 4 ,
1022 .Xr libusb 3 ,
1023 .Xr usbconfig 8 ,
1024 .Xr usbdump 8
1025 .
1026 .
1027 .Sh HISTORY
1028 .
1029 .
1030 Some parts of the
1031 .Nm
1032 API derives from the libusb project at sourceforge.