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