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