libusb.3 (1829d5da5355930d5cfa8ec8add8ff47dc0bebab) libusb.3 (dc8f21bc49c13bae38994679d0388170b28be719)
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:

--- 12 unchanged lines hidden (view full) ---

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.\"
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:

--- 12 unchanged lines hidden (view full) ---

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 Feb 14, 2009
29.Dd April 5, 2009
30.Dt LIBUSB 3
31.Os
32.Sh NAME
33.Nm libusb
34.
35.Nd "USB access library"
36.
37.
38.Sh LIBRARY
39.
40.
41USB access library (libusb -lusb)
42.
43.
44.
45.Sh SYNOPSIS
30.Dt LIBUSB 3
31.Os
32.Sh NAME
33.Nm libusb
34.
35.Nd "USB access library"
36.
37.
38.Sh LIBRARY
39.
40.
41USB access library (libusb -lusb)
42.
43.
44.
45.Sh SYNOPSIS
46.
47.
48.In libusb20.h
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 void
82.Fn libusb20_tr_set_length "struct libusb20_transfer *xfer" "uint32_t length" "uint16_t fr_index"
83.Ft void
84.Fn libusb20_tr_set_priv_sc0 "struct libusb20_transfer *xfer" "void *sc0"
85.Ft void
86.Fn libusb20_tr_set_priv_sc1 "struct libusb20_transfer *xfer" "void *sc1"
87.Ft void
88.Fn libusb20_tr_set_timeout "struct libusb20_transfer *xfer" "uint32_t timeout"
89.Ft void
90.Fn libusb20_tr_set_total_frames "struct libusb20_transfer *xfer" "uint32_t nframes"
91.Ft void
92.Fn libusb20_tr_setup_bulk "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint32_t timeout"
93.Ft void
94.Fn libusb20_tr_setup_control "struct libusb20_transfer *xfer" "void *psetup" "void *pbuf" "uint32_t timeout"
95.Ft void
96.Fn libusb20_tr_setup_intr "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint32_t timeout"
97.Ft void
98.Fn libusb20_tr_setup_isoc "struct libusb20_transfer *xfer" "void *pbuf" "uint32_t length" "uint61_t fr_index"
99.Ft void
100.Fn libusb20_tr_start "struct libusb20_transfer *xfer"
101.Ft void
102.Fn libusb20_tr_stop "struct libusb20_transfer *xfer"
103.Ft void
104.Fn libusb20_tr_submit "struct libusb20_transfer *xfer"
105.Ft void *
106.Fn libusb20_tr_get_priv_sc0 "struct libusb20_transfer *xfer"
107.Ft void *
108.Fn libusb20_tr_get_priv_sc1 "struct libusb20_transfer *xfer"
109.Ft const char *
110.Fn libusb20_dev_get_backend_name "struct libusb20_device *"
111.Ft int
112.Fn libusb20_dev_get_info "struct libusb20_device *pdev" "struct usb2_device_info *pinfo"
113.Ft int
114.Fn libusb20_dev_get_iface_desc "struct libusb20_device *pdev" "uint8_t iface_index" "char *buf" "uint8_t len"
115.Ft const char *
116.Fn libusb20_dev_get_desc "struct libusb20_device *pdev"
117.Ft int
118.Fn libusb20_dev_claim_interface "struct libusb20_device *pdev" "uint8_t iface_index"
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_release_interface "struct libusb20_device *pdev" "uint8_t iface_index"
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 int
152.Fn libusb20_dev_get_device_desc "struct libusb20_device *pdev" "uint8_t iface_indexr", "char *buf" "uint8_t len"
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_linux "void"
187.Ft struct libusb20_device *
188.Fn libusb20_be_device_foreach "struct libusb20_backend *pbe" "struct libusb20_device *pdev"
189.Ft void
190.Fn libusb20_be_dequeue_device "struct libusb20_backend *pbe" "struct libusb20_device *pdev"
191.Ft void
192.Fn libusb20_be_enqueue_device "struct libusb20_backend *pbe" "struct libusb20_device *pdev"
193.Ft void
194.Fn libusb20_be_free "struct libusb20_backend *pbe"
195.Ft uint8_t
196.Fn libusb20_me_get_1 "const struct libusb20_me_struct *me" "uint16_t off"
197.Ft uint16_t
198.Fn libusb20_me_get_2 "const struct libusb20_me_struct *me" "uint16_t off"
199.Ft uint16_t
200.Fn libusb20_me_encode "void *pdata" "uint16_t len" "const void *pdecoded"
201.Ft uint16_t
202.Fn libusb20_me_decode "const void *pdata" "uint16_t len" "void *pdecoded"
203.Ft "const uint8_t *"
204.Fn libusb20_desc_foreach "const struct libusb20_me_struct *me" "const uint8_t *pdesc"
49.
50.
51.Sh DESCRIPTION
52.
53The
54.Nm
55library implements functions to be able to easily access and control
56USB through the USB file system interface.
57.
58.
59.Sh USB TRANSFER OPERATIONS
60.
61.Pp
62.
205.
206.
207.Sh DESCRIPTION
208.
209The
210.Nm
211library implements functions to be able to easily access and control
212USB through the USB file system interface.
213.
214.
215.Sh USB TRANSFER OPERATIONS
216.
217.Pp
218.
63.Fn libusb20_tr_close pxfer
64This function will release all kernel resources associated with an USB
65.Fa pxfer .
219.Fn libusb20_tr_close
220will release all kernel resources associated with an USB
221.Fa xfer .
66.
67This function returns zero upon success.
68.
69Non-zero return values indicate a LIBUSB20_ERROR value.
70.
71.Pp
72.
222.
223This function returns zero upon success.
224.
225Non-zero return values indicate a LIBUSB20_ERROR value.
226.
227.Pp
228.
73.Fn libusb20_tr_open pxfer max_buf_size max_frame_count ep_no
74This function will allocate kernel resources like
229.Fn libusb20_tr_open
230will allocate kernel resources like
75.Fa max_buf_size
76and
77.Fa max_frame_count
78associated with an USB
79.Fa pxfer
80and bind the transfer to the specified
81.Fa ep_no .
82.
83This function returns zero upon success.
84.
85Non-zero return values indicate a LIBUSB20_ERROR value.
86.
87.Pp
88.
231.Fa max_buf_size
232and
233.Fa max_frame_count
234associated with an USB
235.Fa pxfer
236and bind the transfer to the specified
237.Fa ep_no .
238.
239This function returns zero upon success.
240.
241Non-zero return values indicate a LIBUSB20_ERROR value.
242.
243.Pp
244.
89.Fn libusb20_tr_get_pointer pdev tr_index
90This function will return a pointer to the allocated USB transfer according to the
245.Fn libusb20_tr_get_pointer
246will return a pointer to the allocated USB transfer according to the
91.Fa pdev
92and
93.Fa tr_index
94arguments.
95.
96This function returns NULL in case of failure.
97.
98.Pp
99.
247.Fa pdev
248and
249.Fa tr_index
250arguments.
251.
252This function returns NULL in case of failure.
253.
254.Pp
255.
100.Fn libusb20_tr_get_time_complete pxfer
101This function will return the completion time of an USB transfer in
256.Fn libusb20_tr_get_time_complete
257will return the completion time of an USB transfer in
102millisecond units. This function is most useful for isochronous USB
103transfers when doing echo cancelling.
104.
105.Pp
106.
258millisecond units. This function is most useful for isochronous USB
259transfers when doing echo cancelling.
260.
261.Pp
262.
107.Fn libusb20_tr_get_actual_frames pxfer
108This function will return the actual number of USB frames after an USB
263.Fn libusb20_tr_get_actual_frames
264will return the actual number of USB frames after an USB
109transfer completed. A value of zero means that no data was transferred.
110.
111.Pp
112.
265transfer completed. A value of zero means that no data was transferred.
266.
267.Pp
268.
113.Fn libusb20_tr_get_actual_length pxfer
114This function will return the sum of the actual length for all
269.Fn libusb20_tr_get_actual_length
270will return the sum of the actual length for all
115transferred USB frames for the given USB transfer.
116.
117.Pp
118.
271transferred USB frames for the given USB transfer.
272.
273.Pp
274.
119.Fn libusb20_tr_get_max_frames pxfer
120This function will return the maximum number of USB frames that were
275.Fn libusb20_tr_get_max_frames
276will return the maximum number of USB frames that were
121allocated when an USB transfer was setup for the given USB transfer.
122.
123.Pp
124.
277allocated when an USB transfer was setup for the given USB transfer.
278.
279.Pp
280.
125.Fn libusb20_tr_get_max_packet_length pxfer
126This function will return the maximum packet length in bytes
281.Fn libusb20_tr_get_max_packet_length
282will return the maximum packet length in bytes
127associated with the given USB transfer.
128.
129The packet length can be used round up buffer sizes so that short USB
130packets are avoided for proxy buffers.
131.
132.
133.Pp
134.
283associated with the given USB transfer.
284.
285The packet length can be used round up buffer sizes so that short USB
286packets are avoided for proxy buffers.
287.
288.
289.Pp
290.
135.Fn libusb20_tr_get_max_total_length pxfer
136This function will return the maximum value for the length sum of all
291.Fn libusb20_tr_get_max_total_length
292function will return the maximum value for the length sum of all
137USB frames associated with an USB transfer.
138.
139.Pp
140.
293USB frames associated with an USB transfer.
294.
295.Pp
296.
141.Fn libusb20_tr_get_status pxfer
142This function will return the status of an USB transfer.
297.Fn libusb20_tr_get_status
298will return the status of an USB transfer.
143.
144Status values are defined by a set of LIBUSB20_TRANSFER_XXX enums.
145.
146.Pp
147.
299.
300Status values are defined by a set of LIBUSB20_TRANSFER_XXX enums.
301.
302.Pp
303.
148.Fn libusb20_tr_pending pxfer
149This function will return non-zero if the given USB transfer is
304.Fn libusb20_tr_pending
305will return non-zero if the given USB transfer is
150pending for completion.
151.
152Else this function returns zero.
153.
154.Pp
155.
306pending for completion.
307.
308Else this function returns zero.
309.
310.Pp
311.
156.Fn libusb20_tr_callback_wrapper pxfer
312.Fn libusb20_tr_callback_wrapper
157This is an internal function used to wrap asynchronous USB callbacks.
158.
159.Pp
160.
313This is an internal function used to wrap asynchronous USB callbacks.
314.
315.Pp
316.
161.Fn libusb20_tr_clear_stall_sync pxfer
317.Fn libusb20_tr_clear_stall_sync
162This is an internal function used to synchronously clear the stall on
163the given USB transfer.
164.
165Please see the USB specification for more information on stall
166clearing.
167.
168If the given USB transfer is pending when this function is called, the
169USB transfer will complete with an error after that this function has
170been called.
171.
172.Pp
173.
318This is an internal function used to synchronously clear the stall on
319the given USB transfer.
320.
321Please see the USB specification for more information on stall
322clearing.
323.
324If the given USB transfer is pending when this function is called, the
325USB transfer will complete with an error after that this function has
326been called.
327.
328.Pp
329.
174.Fn libusb20_tr_drain pxfer
175This function will stop the given USB transfer and will not return
330.Fn libusb20_tr_drain
331will stop the given USB transfer and will not return
176until the USB transfer has been stopped in hardware.
177.
178.Pp
179.
332until the USB transfer has been stopped in hardware.
333.
334.Pp
335.
180.Fn libusb20_tr_set_buffer pxfer pbuf fr_index
181This function is used to set the
336.Fn libusb20_tr_set_buffer
337is used to set the
182.Fa buffer
183pointer for the given USB transfer and
184.Fa fr_index .
185.
186Typically the frame index is zero.
187.
188.
189.Pp
190.
338.Fa buffer
339pointer for the given USB transfer and
340.Fa fr_index .
341.
342Typically the frame index is zero.
343.
344.
345.Pp
346.
191.Fn libusb20_tr_set_callback pxfer pcallback
192This function is used to set the USB callback for asynchronous USB
347.Fn libusb20_tr_set_callback
348is used to set the USB callback for asynchronous USB
193transfers.
194.
195The callback type is defined by libusb20_tr_callback_t.
196.
197.Pp
198.
349transfers.
350.
351The callback type is defined by libusb20_tr_callback_t.
352.
353.Pp
354.
199.Fn libusb20_tr_set_flags pxfer flags
200This function is used to set various USB flags for the given USB transfer.
355.Fn libusb20_tr_set_flags
356is used to set various USB flags for the given USB transfer.
201.Bl -tag
202.It LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK
203Report a short frame as error.
204.It LIBUSB20_TRANSFER_MULTI_SHORT_NOT_OK
205Multiple short frames are not allowed.
206.It LIBUSB20_TRANSFER_FORCE_SHORT
207All transmitted frames are short terminated.
208.It LIBUSB20_TRANSFER_DO_CLEAR_STALL
209Will do a clear-stall before starting the transfer.
210.El
211.
212.Pp
213.
357.Bl -tag
358.It LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK
359Report a short frame as error.
360.It LIBUSB20_TRANSFER_MULTI_SHORT_NOT_OK
361Multiple short frames are not allowed.
362.It LIBUSB20_TRANSFER_FORCE_SHORT
363All transmitted frames are short terminated.
364.It LIBUSB20_TRANSFER_DO_CLEAR_STALL
365Will do a clear-stall before starting the transfer.
366.El
367.
368.Pp
369.
214.Fn libusb20_tr_set_length pxfer length fr_index
215This function sets the length of a given USB transfer and frame index.
370.Fn libusb20_tr_set_length
371sets the length of a given USB transfer and frame index.
216.
217.Pp
218.
372.
373.Pp
374.
219.Fn libusb20_tr_set_priv_sc0 pxfer psc0
220This function sets private driver pointer number zero.
375.Fn libusb20_tr_set_priv_sc0
376sets private driver pointer number zero.
221.
222.Pp
223.
377.
378.Pp
379.
224.Fn libusb20_tr_set_priv_sc1 pxfer psc1
225This function sets private driver pointer number one.
380.Fn libusb20_tr_set_priv_sc1
381sets private driver pointer number one.
226.
227.Pp
228.
382.
383.Pp
384.
229.Fn libusb20_tr_set_timeout pxfer timeout
230This function sets the timeout for the given USB transfer.
385.Fn libusb20_tr_set_timeout
386sets the timeout for the given USB transfer.
231.
232A timeout value of zero means no timeout.
233.
234The timeout is given in milliseconds.
235.
236.Pp
237.
387.
388A timeout value of zero means no timeout.
389.
390The timeout is given in milliseconds.
391.
392.Pp
393.
238.Fn libusb20_tr_set_total_frames pxfer nframes
239This function sets the total number of frames that should be executed when the USB transfer is submitted.
394.Fn libusb20_tr_set_total_frames
395sets the total number of frames that should be executed when the USB transfer is submitted.
240.
241The total number of USB frames must be less than the maximum number of USB frames associated with the given USB transfer.
242.
243.Pp
244.
396.
397The total number of USB frames must be less than the maximum number of USB frames associated with the given USB transfer.
398.
399.Pp
400.
245.Fn libusb20_tr_setup_bulk pxfer pbuf length timeout
246This function is a helper function for setting up a single frame USB BULK transfer.
401.Fn libusb20_tr_setup_bulk
402is a helper function for setting up a single frame USB BULK transfer.
247.
248.Pp
249.
403.
404.Pp
405.
250.Fn libusb20_tr_setup_control pxfer psetup pbuf timeout
251This function is a helper function for setting up a single or dual
406.Fn libusb20_tr_setup_control
407is a helper function for setting up a single or dual
252frame USB CONTROL transfer depending on the control transfer length.
253.
254.Pp
255.
408frame USB CONTROL transfer depending on the control transfer length.
409.
410.Pp
411.
256.Fn libusb20_tr_setup_intr pxfer pbuf length timeout
257This function is a helper function for setting up a single frame USB INTERRUPT transfer.
412.Fn libusb20_tr_setup_intr
413is a helper function for setting up a single frame USB INTERRUPT transfer.
258.
259.Pp
260.
414.
415.Pp
416.
261.Fn libusb20_tr_setup_isoc pxfer pbuf length fr_index
262This function is a helper function for setting up a multi frame USB ISOCHRONOUS transfer.
417.Fn libusb20_tr_setup_isoc
418is a helper function for setting up a multi frame USB ISOCHRONOUS transfer.
263.
264.Pp
265.
419.
420.Pp
421.
266.Fn libusb20_tr_start pxfer
267This function will get the USB transfer started, if not already
422.Fn libusb20_tr_start
423will get the USB transfer started, if not already
268started.
269.
270This function will not get the transfer queued in hardware.
271.
272This function is non-blocking.
273.
274.Pp
275.
424started.
425.
426This function will not get the transfer queued in hardware.
427.
428This function is non-blocking.
429.
430.Pp
431.
276.Fn libusb20_tr_stop pxfer
277This function will get the USB transfer stopped, if not already stopped.
432.Fn libusb20_tr_stop
433will get the USB transfer stopped, if not already stopped.
278.
279This function is non-blocking, which means that the actual stop can
280happen after the return of this function.
281.
282.Pp
283.
434.
435This function is non-blocking, which means that the actual stop can
436happen after the return of this function.
437.
438.Pp
439.
284.Fn libusb20_tr_submit pxfer
285This function will get the USB transfer queued in hardware.
440.Fn libusb20_tr_submit
441will get the USB transfer queued in hardware.
286.
287.
288.Pp
289.
442.
443.
444.Pp
445.
290.Fn libusb20_tr_get_priv_sc0 pxfer
291This function returns private driver pointer number zero associated
446.Fn libusb20_tr_get_priv_sc0
447returns private driver pointer number zero associated
292with an USB transfer.
293.
294.
295.Pp
296.
448with an USB transfer.
449.
450.
451.Pp
452.
297.Fn libusb20_tr_get_priv_sc1 pxfer
298This function returns private driver pointer number one associated
453.Fn libusb20_tr_get_priv_sc1
454returns private driver pointer number one associated
299with an USB transfer.
300.
301.
302.Sh USB DEVICE OPERATIONS
303.
304.Pp
305.
455with an USB transfer.
456.
457.
458.Sh USB DEVICE OPERATIONS
459.
460.Pp
461.
306.Fn libusb20_dev_get_backend_name pdev
307This function returns a zero terminated string describing the backend used.
462.Fn libusb20_dev_get_backend_name
463returns a zero terminated string describing the backend used.
308.
309.Pp
310.
464.
465.Pp
466.
311.Fn libusb20_dev_get_info pdev pinfo
312This function retrives the BSD specific usb2_device_info structure into the memory location given by
467.Fn libusb20_dev_get_info
468retrives the BSD specific usb2_device_info structure into the memory location given by
313.Fa pinfo .
314The USB device given by
315.Fa pdev
316must be opened before this function will succeed.
317This function returns zero on success else a LIBUSB20_ERROR value is returned.
318.
319.Pp
320.
469.Fa pinfo .
470The USB device given by
471.Fa pdev
472must be opened before this function will succeed.
473This function returns zero on success else a LIBUSB20_ERROR value is returned.
474.
475.Pp
476.
321.Fn libusb20_dev_get_iface_desc pdev iface_index pbuf len
322This function retrieves the kernel interface description for the given USB
477.Fn libusb20_dev_get_iface_desc
478retrieves the kernel interface description for the given USB
323.Fa iface_index .
324The format of the USB interface description is: "drivername<unit>: <description>"
325The description string is always zero terminated.
326A zero length string is written in case no driver is attached to the given interface.
327The USB device given by
328.Fa pdev
329must be opened before this function will succeed.
330This function returns zero on success else a LIBUSB20_ERROR value is returned.
331.
332.Pp
333.
479.Fa iface_index .
480The format of the USB interface description is: "drivername<unit>: <description>"
481The description string is always zero terminated.
482A zero length string is written in case no driver is attached to the given interface.
483The USB device given by
484.Fa pdev
485must be opened before this function will succeed.
486This function returns zero on success else a LIBUSB20_ERROR value is returned.
487.
488.Pp
489.
334.Fn libusb20_dev_get_desc pdev
335This function returns a zero terminated string describing the given USB device.
490.Fn libusb20_dev_get_desc
491returns a zero terminated string describing the given USB device.
336The format of the string is: "drivername<unit>: <description>"
337.
338.Pp
339.
492The format of the string is: "drivername<unit>: <description>"
493.
494.Pp
495.
340.Fn libusb20_dev_claim_interface pdev iface_index
496.Fn libusb20_dev_claim_interface
341This function will try to claim the given USB interface given by
342.Fa iface_index .
343This function returns zero on success else a LIBUSB20_ERROR value is
344returned.
345.
346.Pp
347.
497This function will try to claim the given USB interface given by
498.Fa iface_index .
499This function returns zero on success else a LIBUSB20_ERROR value is
500returned.
501.
502.Pp
503.
348.Fn libusb20_dev_close pdev
349This function will close the given USB device.
504.Fn libusb20_dev_close
505will close the given USB device.
350.
351This function returns zero on success else a LIBUSB20_ERROR value is
352returned.
353.
354.Pp
355.
506.
507This function returns zero on success else a LIBUSB20_ERROR value is
508returned.
509.
510.Pp
511.
356.Fn libusb20_dev_detach_kernel_driver pdev iface_index
357This function will try to detach the kernel driver for the USB interface given by
512.Fn libusb20_dev_detach_kernel_driver
513will try to detach the kernel driver for the USB interface given by
358.Fa iface_index .
359.
360This function returns zero on success else a LIBUSB20_ERROR value is
361returned.
362.
363.Pp
364.
514.Fa iface_index .
515.
516This function returns zero on success else a LIBUSB20_ERROR value is
517returned.
518.
519.Pp
520.
365.Fn libusb20_dev_set_config_index pdev config_index
366This function will try to set the configuration index on an USB
521.Fn libusb20_dev_set_config_index
522will try to set the configuration index on an USB
367device.
368.
369The first configuration index is zero.
370.
371The un-configure index is 255.
372.
373This function returns zero on success else a LIBUSB20_ERROR value is returned.
374.
375.Pp
376.
523device.
524.
525The first configuration index is zero.
526.
527The un-configure index is 255.
528.
529This function returns zero on success else a LIBUSB20_ERROR value is returned.
530.
531.Pp
532.
377.Fn libusb20_dev_get_debug pdev
378This function returns the debug level of an USB device.
533.Fn libusb20_dev_get_debug
534returns the debug level of an USB device.
379.
380.Pp
381.
535.
536.Pp
537.
382.Fn libusb20_dev_get_fd pdev
383This function returns the file descriptor of the given USB device.
538.Fn libusb20_dev_get_fd
539returns the file descriptor of the given USB device.
384.
385A negative value is returned when no file descriptor is present.
386.
387The file descriptor can be used for polling purposes.
388.
389.Pp
390.
540.
541A negative value is returned when no file descriptor is present.
542.
543The file descriptor can be used for polling purposes.
544.
545.Pp
546.
391.Fn libusb20_dev_kernel_driver_active pdev iface_index
392This function returns a non-zero value if a kernel driver is active on
547.Fn libusb20_dev_kernel_driver_active
548returns a non-zero value if a kernel driver is active on
393the given USB interface.
394.
395Else zero is returned.
396.
397.Pp
398.
549the given USB interface.
550.
551Else zero is returned.
552.
553.Pp
554.
399.Fn libusb20_dev_open pdev transfer_max
400This function opens an USB device so that setting up USB transfers
555.Fn libusb20_dev_open
556opens an USB device so that setting up USB transfers
401becomes possible.
402.
403The number of USB transfers can be zero which means only control
404transfers are allowed.
405.
406This function returns zero on success else a LIBUSB20_ERROR value is
407returned.
408.
409A return value of LIBUSB20_ERROR_BUSY means that the device is already
410opened.
411.
412.Pp
413.
557becomes possible.
558.
559The number of USB transfers can be zero which means only control
560transfers are allowed.
561.
562This function returns zero on success else a LIBUSB20_ERROR value is
563returned.
564.
565A return value of LIBUSB20_ERROR_BUSY means that the device is already
566opened.
567.
568.Pp
569.
414.Fn libusb20_dev_process pdev
415This function is called to sync kernel USB transfers with userland USB
570.Fn libusb20_dev_process
571is called to sync kernel USB transfers with userland USB
416transfers.
417.
418This function returns zero on success else a LIBUSB20_ERROR value is
419returned typically indicating that the given USB device has been
420detached.
421.
422.Pp
423.
572transfers.
573.
574This function returns zero on success else a LIBUSB20_ERROR value is
575returned typically indicating that the given USB device has been
576detached.
577.
578.Pp
579.
424.Fn libusb20_dev_release_interface pdev iface_index
425This function will try to release a claimed USB interface for the specified USB device.
580.Fn libusb20_dev_release_interface
581will try to release a claimed USB interface for the specified USB device.
426.
427This function returns zero on success else a LIBUSB20_ERROR value is
428returned.
429.
430.Pp
431.
582.
583This function returns zero on success else a LIBUSB20_ERROR value is
584returned.
585.
586.Pp
587.
432.Fn libusb20_dev_request_sync pdev psetup pdata pactlen timeout flags
433This function will perform a synchronous control request on the given
588.Fn libusb20_dev_request_sync
589will perform a synchronous control request on the given
434USB device.
435.
436Before this call will succeed the USB device must be opened.
437.
438.Fa setup
439is a pointer to a decoded and host endian SETUP packet.
440.Fa data
441is a pointer to a data transfer buffer associated with the control transaction. This argument can be NULL.

--- 5 unchanged lines hidden (view full) ---

447.Fa flags
448is used to specify transaction flags, for example LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK.
449.
450This function returns zero on success else a LIBUSB20_ERROR value is
451returned.
452.
453.Pp
454.
590USB device.
591.
592Before this call will succeed the USB device must be opened.
593.
594.Fa setup
595is a pointer to a decoded and host endian SETUP packet.
596.Fa data
597is a pointer to a data transfer buffer associated with the control transaction. This argument can be NULL.

--- 5 unchanged lines hidden (view full) ---

603.Fa flags
604is used to specify transaction flags, for example LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK.
605.
606This function returns zero on success else a LIBUSB20_ERROR value is
607returned.
608.
609.Pp
610.
455.Fn libusb20_dev_req_string_sync pdev index lang_id pbuf len
456This function will synchronously request an USB string by language ID
611.Fn libusb20_dev_req_string_sync
612will synchronously request an USB string by language ID
457and string index into the given buffer limited by a maximum length.
458.
459This function returns zero on success else a LIBUSB20_ERROR value is
460returned.
461.
462.Pp
463.
613and string index into the given buffer limited by a maximum length.
614.
615This function returns zero on success else a LIBUSB20_ERROR value is
616returned.
617.
618.Pp
619.
464.Fn libusb20_dev_req_string_simple_sync pdev index pbuf len
465This function will synchronously request an USB string using the
620.Fn libusb20_dev_req_string_simple_sync
621will synchronously request an USB string using the
466default language ID and convert the string into ASCII before storing
467the string into the given buffer limited by a maximum length which
468includes the terminating zero.
469.
470This function returns zero on success else a LIBUSB20_ERROR value is
471returned.
472.
473.
474.Pp
475.
622default language ID and convert the string into ASCII before storing
623the string into the given buffer limited by a maximum length which
624includes the terminating zero.
625.
626This function returns zero on success else a LIBUSB20_ERROR value is
627returned.
628.
629.
630.Pp
631.
476.Fn libusb20_dev_reset pdev
477This function will try to BUS reset the given USB device and restore
632.Fn libusb20_dev_reset
633will try to BUS reset the given USB device and restore
478the last set USB configuration.
479.
480This function returns zero on success else a LIBUSB20_ERROR value is
481returned.
482.
483.Pp
484.
634the last set USB configuration.
635.
636This function returns zero on success else a LIBUSB20_ERROR value is
637returned.
638.
639.Pp
640.
485.Fn libusb20_dev_set_power_mode pdev power_mode
486This function sets the power mode of the USB device.
641.Fn libusb20_dev_set_power_mode
642sets the power mode of the USB device.
487.
488Valid power modes:
489.Bl -tag
490.It LIBUSB20_POWER_OFF
491.It LIBUSB20_POWER_ON
492.It LIBUSB20_POWER_SAVE
493.It LIBUSB20_POWER_SUSPEND
494.It LIBUSB20_POWER_RESUME
495.El
496.
497This function returns zero on success else a LIBUSB20_ERROR value is
498returned.
499.
500.Pp
501.
643.
644Valid power modes:
645.Bl -tag
646.It LIBUSB20_POWER_OFF
647.It LIBUSB20_POWER_ON
648.It LIBUSB20_POWER_SAVE
649.It LIBUSB20_POWER_SUSPEND
650.It LIBUSB20_POWER_RESUME
651.El
652.
653This function returns zero on success else a LIBUSB20_ERROR value is
654returned.
655.
656.Pp
657.
502.Fn libusb20_dev_get_power_mode pdev
503This function returns the currently selected power mode for the given
658.Fn libusb20_dev_get_power_mode
659returns the currently selected power mode for the given
504USB device.
505.
506.Pp
507.
660USB device.
661.
662.Pp
663.
508.Fn libusb20_dev_set_alt_index pdev iface_index alt_index
509This function will try to set the given alternate index for the given
664.Fn libusb20_dev_set_alt_index
665will try to set the given alternate index for the given
510USB interface index.
511.
512This function returns zero on success else a LIBUSB20_ERROR value is
513returned.
514.
515.Pp
516.
666USB interface index.
667.
668This function returns zero on success else a LIBUSB20_ERROR value is
669returned.
670.
671.Pp
672.
517.Fn libusb20_dev_get_device_desc pdev
518This function returns a pointer to the decoded and host endian version
673.Fn libusb20_dev_get_device_desc
674returns a pointer to the decoded and host endian version
519of the device descriptor.
520.
521The USB device need not be opened when calling this function.
522.
523.Pp
524.
675of the device descriptor.
676.
677The USB device need not be opened when calling this function.
678.
679.Pp
680.
525.Fn libusb20_dev_alloc_config pdev config_index
526This function will read out and decode the USB config descriptor for
681.Fn libusb20_dev_alloc_config
682will read out and decode the USB config descriptor for
527the given USB device and config index. This function returns a pointer
528to the decoded configuration which must eventually be passed to
529free(). NULL is returned in case of failure.
530.
531.Pp
532.
683the given USB device and config index. This function returns a pointer
684to the decoded configuration which must eventually be passed to
685free(). NULL is returned in case of failure.
686.
687.Pp
688.
533.Fn libusb20_dev_alloc void
534This is an internal function to allocate a new USB device.
689.Fn libusb20_dev_alloc
690is an internal function to allocate a new USB device.
535.
536.Pp
537.
691.
692.Pp
693.
538.Fn libusb20_dev_get_address pdev
539This function returns the internal and not necessarily the real
694.Fn libusb20_dev_get_address
695returns the internal and not necessarily the real
540hardware address of the given USB device.
541.
542.Pp
543.
696hardware address of the given USB device.
697.
698.Pp
699.
544.Fn libusb20_dev_get_bus_number pdev
545This function return the internal bus number which the given USB
700.Fn libusb20_dev_get_bus_number
701returns the internal bus number which the given USB
546device belongs to.
547.
548.Pp
549.
702device belongs to.
703.
704.Pp
705.
550.Fn libusb20_dev_get_mode pdev
551This function returns the current operation mode of the USB entity.
706.Fn libusb20_dev_get_mode
707returns the current operation mode of the USB entity.
552.
553Valid return values are:
554.Bl -tag
555.It LIBUSB20_MODE_HOST
556.It LIBUSB20_MODE_DEVICE
557.El
558.
559.Pp
560.
708.
709Valid return values are:
710.Bl -tag
711.It LIBUSB20_MODE_HOST
712.It LIBUSB20_MODE_DEVICE
713.El
714.
715.Pp
716.
561.Fn libusb20_dev_get_speed pdev
562This function returns the current speed of the given USB device.
717.Fn libusb20_dev_get_speed
718returns the current speed of the given USB device.
563.
564.Bl -tag
565.It LIBUSB20_SPEED_UNKNOWN
566.It LIBUSB20_SPEED_LOW
567.It LIBUSB20_SPEED_FULL
568.It LIBUSB20_SPEED_HIGH
569.It LIBUSB20_SPEED_VARIABLE
570.It LIBUSB20_SPEED_SUPER
571.El
572.
573.Pp
574.
719.
720.Bl -tag
721.It LIBUSB20_SPEED_UNKNOWN
722.It LIBUSB20_SPEED_LOW
723.It LIBUSB20_SPEED_FULL
724.It LIBUSB20_SPEED_HIGH
725.It LIBUSB20_SPEED_VARIABLE
726.It LIBUSB20_SPEED_SUPER
727.El
728.
729.Pp
730.
575.Fn libusb20_dev_get_config_index pdev
731.Fn libusb20_dev_get_config_index
576This function returns the currently select config index for the given
577USB device.
578.
579.Pp
580.
732This function returns the currently select config index for the given
733USB device.
734.
735.Pp
736.
581.Fn libusb20_dev_free pdev
582This function will free the given USB device and all associated USB
737.Fn libusb20_dev_free
738will free the given USB device and all associated USB
583transfers.
584.
585.Pp
586.
739transfers.
740.
741.Pp
742.
587.Fn libusb20_dev_set_debug pdev debug_level
588This function will set the debug level for the given USB device.
743.Fn libusb20_dev_set_debug
744will set the debug level for the given USB device.
589.
590.Pp
591.
745.
746.Pp
747.
592.Fn libusb20_dev_wait_process pdev timeout
593This function will wait until a pending USB transfer has completed on
748.Fn libusb20_dev_wait_process
749function will wait until a pending USB transfer has completed on
594the given USB device.
595.
596A timeout value can be specified which is passed on to the
597.Xr 2 poll
598function.
599.
600.Sh USB BACKEND OPERATIONS
601.
750the given USB device.
751.
752A timeout value can be specified which is passed on to the
753.Xr 2 poll
754function.
755.
756.Sh USB BACKEND OPERATIONS
757.
602.Fn libusb20_be_get_template pbackend ptemp
603This function will return the currently selected global USB device
758.Fn libusb20_be_get_template
759will return the currently selected global USB device
604side mode template into the integer pointer
605.Fa ptemp .
606This function returns zero on success else a LIBUSB20_ERROR value is
607returned.
608.
609.Pp
610.
760side mode template into the integer pointer
761.Fa ptemp .
762This function returns zero on success else a LIBUSB20_ERROR value is
763returned.
764.
765.Pp
766.
611.Fn libusb20_be_set_template pbackend temp
612This function will set the global USB device side mode template to
767.Fn libusb20_be_set_template
768will set the global USB device side mode template to
613.Fa temp .
614The new template is not activated until after the next USB
615enumeration.
616The template number decides how the USB device will present itself to
617the USB Host, like Mass Storage Device, USB Ethernet Device. Also see
618the
619.Xr usb2_template 4
620module.
621This function returns zero on success else a LIBUSB20_ERROR value is
622returned.
623.
624.Pp
625.
769.Fa temp .
770The new template is not activated until after the next USB
771enumeration.
772The template number decides how the USB device will present itself to
773the USB Host, like Mass Storage Device, USB Ethernet Device. Also see
774the
775.Xr usb2_template 4
776module.
777This function returns zero on success else a LIBUSB20_ERROR value is
778returned.
779.
780.Pp
781.
626.Fn libusb20_be_get_dev_quirk pbackend index pquirk
782.Fn libusb20_be_get_dev_quirk
627This function will return the device quirk according to
628.Fa index
629into the libusb20_quirk structure pointed to by
630.Fa pq .
631This function returns zero on success else a LIBUSB20_ERROR value is
632returned.
633.
634If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
635returned.
636.
637.Pp
638.
783This function will return the device quirk according to
784.Fa index
785into the libusb20_quirk structure pointed to by
786.Fa pq .
787This function returns zero on success else a LIBUSB20_ERROR value is
788returned.
789.
790If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
791returned.
792.
793.Pp
794.
639.Fn libusb20_be_get_quirk_name pbackend index pquirk
640This function will return the quirk name according to
795.Fn libusb20_be_get_quirk_name
796will return the quirk name according to
641.Fa index
642into the libusb20_quirk structure pointed to by
643.Fa pq .
644This function returns zero on success else a LIBUSB20_ERROR value is
645returned.
646.
647If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
648returned.
649.
650.Pp
651.
797.Fa index
798into the libusb20_quirk structure pointed to by
799.Fa pq .
800This function returns zero on success else a LIBUSB20_ERROR value is
801returned.
802.
803If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
804returned.
805.
806.Pp
807.
652.Fn libusb20_be_add_dev_quirk pbackend pquirk
653This function will add the libusb20_quirk structure pointed to by the
808.Fn libusb20_be_add_dev_quirk
809will add the libusb20_quirk structure pointed to by the
654.Fa pq
655argument into the device quirk list.
656.
657This function returns zero on success else a LIBUSB20_ERROR value is
658returned.
659.
660If the given quirk cannot be added LIBUSB20_ERROR_NO_MEM is
661returned.
662.
663.Pp
664.
810.Fa pq
811argument into the device quirk list.
812.
813This function returns zero on success else a LIBUSB20_ERROR value is
814returned.
815.
816If the given quirk cannot be added LIBUSB20_ERROR_NO_MEM is
817returned.
818.
819.Pp
820.
665.Fn libusb20_be_remove_dev_quirk pbackend pquirk
666This function will remove the quirk matching the libusb20_quirk structure pointed to by the
821.Fn libusb20_be_remove_dev_quirk
822will remove the quirk matching the libusb20_quirk structure pointed to by the
667.Fa pq
668argument from the device quirk list.
669.
670This function returns zero on success else a LIBUSB20_ERROR value is
671returned.
672.
673If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
674returned.
675.
823.Fa pq
824argument from the device quirk list.
825.
826This function returns zero on success else a LIBUSB20_ERROR value is
827returned.
828.
829If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
830returned.
831.
676.Fn libusb20_be_alloc_linux void
832.Fn libusb20_be_alloc_linux
677These functions are used to allocate a specific USB backend or the
678operating system default USB backend. Allocating a backend is a way to
679scan for currently present USB devices.
680.
681.Pp
682.
833These functions are used to allocate a specific USB backend or the
834operating system default USB backend. Allocating a backend is a way to
835scan for currently present USB devices.
836.
837.Pp
838.
683.Fn libusb20_be_device_foreach pbackend pdev
684This function is used to iterate USB devices present in a USB backend.
839.Fn libusb20_be_device_foreach
840is used to iterate USB devices present in a USB backend.
685.
686The starting value of
687.Fa pdev
688is NULL.
689.
690This function returns the next USB device in the list.
691.
692If NULL is returned the end of the USB device list has been reached.
693.
694.Pp
695.
841.
842The starting value of
843.Fa pdev
844is NULL.
845.
846This function returns the next USB device in the list.
847.
848If NULL is returned the end of the USB device list has been reached.
849.
850.Pp
851.
696.Fn libusb20_be_dequeue_device pbackend pdev
697This function will dequeue the given USB device pointer from the
852.Fn libusb20_be_dequeue_device
853will dequeue the given USB device pointer from the
698backend USB device list.
699.
700Dequeued USB devices will not be freed when the backend is freed.
701.
702.Pp
703.
854backend USB device list.
855.
856Dequeued USB devices will not be freed when the backend is freed.
857.
858.Pp
859.
704.Fn libusb20_be_enqueue_device pbackend pdev
860.Fn libusb20_be_enqueue_device
705This function will enqueue the given USB device pointer in the backend USB device list.
706.
707Enqueued USB devices will get freed when the backend is freed.
708.
709.Pp
710.
861This function will enqueue the given USB device pointer in the backend USB device list.
862.
863Enqueued USB devices will get freed when the backend is freed.
864.
865.Pp
866.
711.Fn libusb20_be_free pbackend
712This function will free the given backend and all USB devices in its device list.
867.Fn libusb20_be_free
868will free the given backend and all USB devices in its device list.
713.
714.
715.Sh USB DESCRIPTOR PARSING
716.
717.Fn libusb20_me_get_1 pie offset
718This function will return a byte at the given byte offset of a message
719entity.
720.

--- 81 unchanged lines hidden ---
869.
870.
871.Sh USB DESCRIPTOR PARSING
872.
873.Fn libusb20_me_get_1 pie offset
874This function will return a byte at the given byte offset of a message
875entity.
876.

--- 81 unchanged lines hidden ---