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