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