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