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