libusb.3 (4315b3c95d598b83b39e26259ed4ad539713048f) libusb.3 (a5118bdfe93c01320d1e2c4379871a2ec1b9546f)
1.\"
1.\"
2.\" Copyright (c) 2008 Hans Petter Selasky
2.\" Copyright (c) 2009 Sylvestre Gallon
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.

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

--- 10 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 May 28, 2009
29.Dd June 22, 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.
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
44.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.
45.
46.
209.Sh DESCRIPTION
47.In libusb.h
210.
48.
49.
50.Sh DESCRIPTION
211The
212.Nm
51The
52.Nm
213library implements functions to be able to easily access and control
214USB through the USB file system interface.
53library contains interfaces for directly managing a usb device.
54The current implementation supports v1.0 of the libusb API.
215.
216.
55.
56.
217.Sh USB TRANSFER OPERATIONS
57.Sh LIBRARY INITIALISATION / DEINITIALISATION
218.
219.Pp
220.
58.
59.Pp
60.
221.Fn libusb20_tr_close
222will release all kernel resources associated with an USB
223.Fa xfer .
224.
225This function returns zero upon success.
226.
227Non-zero return values indicate a LIBUSB20_ERROR value.
228.
61.Ft int
62.Fn libusb_init libusb_context **ctx
63This function initialises libusb. Must be called at the beginning
64of the program. This function returns 0 on success or LIBUSB_ERROR on
65failure.
66.
229.Pp
230.
67.Pp
68.
231.Fn libusb20_tr_open
232will allocate kernel buffer resources according to
233.Fa max_buf_size
234and
235.Fa max_frame_count
236associated with an USB
237.Fa pxfer
238and bind the transfer to the specified
239.Fa ep_no .
240.Fa max_buf_size
241is the minimum buffer size which the data transport layer has to support.
242If
243.Fa max_buf_size
244is zero, the
245.Nm
246library will use wMaxPacketSize to compute the buffer size.
247This can be useful for isochronous transfers.
248The actual buffer size can be greater than
249.Fa max_buf_size
250and is returned by
251.Fn libusb20_tr_get_max_total_length .
69.Ft void
70.Fn libusb_exit "libusb_context *ctx"
71Deinitialise libusb. Must be called at the end of the application.
252.
72.
253This function returns zero upon success.
254.
255Non-zero return values indicate a LIBUSB20_ERROR value.
256.
257.Pp
258.
73.Pp
74.
259.Fn libusb20_tr_get_pointer
260will return a pointer to the allocated USB transfer according to the
261.Fa pdev
262and
263.Fa tr_index
264arguments.
75.Ft void
76.Fn libusb_set_debug "libusb_context *ctx" "int level"
77Set debug to the
78.Fa level
79level.
265.
80.
266This function returns NULL in case of failure.
267.
268.Pp
269.
81.Pp
82.
270.Fn libusb20_tr_get_time_complete
271will return the completion time of an USB transfer in
272millisecond units. This function is most useful for isochronous USB
273transfers when doing echo cancelling.
83.Ft ssize_t
84.Fn libusb_get_device_list "libusb_context *ctx" "libusb_device ***list"
85Fill into
86.Fa list
87the list of usb device available. All the device created by this
88function must be unref and free when you are done with them. This
89function returns the number of devices in list or a LIBUSB_ERROR code.
274.
275.Pp
276.
90.
91.Pp
92.
277.Fn libusb20_tr_get_actual_frames
278will return the actual number of USB frames after an USB
279transfer completed. A value of zero means that no data was transferred.
93.Ft void
94.Fn libusb_free_device_list "libusb_device **list" "int unref_devices"
95Free the list of devices discovered by libusb_get_device_list. If
96.Fa unref_device
97is set to 1 all devices are unref one time.
280.
281.Pp
282.
98.
99.Pp
100.
283.Fn libusb20_tr_get_actual_length
284will return the sum of the actual length for all
285transferred USB frames for the given USB transfer.
101.Ft uint8_t
102.Fn libusb_get_bus_number "libusb_device *dev"
103Returns the number of the bus contained by the device
104.Fa dev.
286.
287.Pp
288.
105.
106.Pp
107.
289.Fn libusb20_tr_get_max_frames
290will return the maximum number of USB frames that were
291allocated when an USB transfer was setup for the given USB transfer.
108.Ft uint8_t
109.Fn libusb_get_device_address "libusb_device *dev"
110Return the device_address contained by the device
111.Fa dev.
292.
293.Pp
294.
112.
113.Pp
114.
295.Fn libusb20_tr_get_max_packet_length
296will return the maximum packet length in bytes
297associated with the given USB transfer.
115.Ft int
116.Fn libusb_get_max_packet_size "libusb_device *dev" "unsigned char endpoint"
117Return the wMaxPacketSize value on success, LIBUSB_ERROR_NOT_FOUND if the
118endpoint does not exist and LIBUSB_ERROR_OTHERS on other failure.
298.
119.
299The packet length can be used round up buffer sizes so that short USB
300packets are avoided for proxy buffers.
301.
302.
303.Pp
304.
120.Pp
121.
305.Fn libusb20_tr_get_max_total_length
306function will return the maximum value for the length sum of all
307USB frames associated with an USB transfer.
122.Ft libusb_device *
123.Fn libusb_ref_device "libusb_device *dev"
124Increment the reference counter of the device
125.Fa dev.
308.
309.Pp
310.
126.
127.Pp
128.
311.Fn libusb20_tr_get_status
312will return the status of an USB transfer.
129.Ft void
130.Fn libusb_unref_device "libusb_device *dev"
131Decrement the reference counter of the device
132.Fa dev.
313.
133.
314Status values are defined by a set of LIBUSB20_TRANSFER_XXX enums.
315.
316.Pp
317.
134.Pp
135.
318.Fn libusb20_tr_pending
319will return non-zero if the given USB transfer is
320pending for completion.
136.Ft int
137.Fn libusb_open "libusb_device *dev" "libusb_device_handle **devh"
138Open a device and obtain a device_handle. Return 0 on success,
139LIBUSB_ERROR_NO_MEM on memory allocation problem, LIBUSB_ERROR_ACCESS
140on permission problem, LIBUSB_ERROR_NO_DEVICE if the device has been
141disconnected and a LIBUSB_ERROR code on error.
321.
142.
322Else this function returns zero.
323.
324.Pp
325.
143.Pp
144.
326.Fn libusb20_tr_callback_wrapper
327This is an internal function used to wrap asynchronous USB callbacks.
145.Ft libusb_device_handle *
146.Fn libusb_open_device_with_vid_pid "libusb_context *ctx" "uint16_t vid" "uint16_t pid"
147Conveniance function to open a device with is
148.Fa vid
149and
150.Fa pid.
151Return NULL on error.
328.
329.Pp
330.
152.
153.Pp
154.
331.Fn libusb20_tr_clear_stall_sync
332This is an internal function used to synchronously clear the stall on
333the given USB transfer.
155.Ft void
156.Fn libusb_close "libusb_device_handle *devh"
157Close a device handle.
334.
158.
335Please see the USB specification for more information on stall
336clearing.
337.
338If the given USB transfer is pending when this function is called, the
339USB transfer will complete with an error after that this function has
340been called.
341.
342.Pp
343.
159.Pp
160.
344.Fn libusb20_tr_drain
345will stop the given USB transfer and will not return
346until the USB transfer has been stopped in hardware.
161.Ft libusb_device *
162.Fn libusb_get_device(libusb_device_handle *devh)
163Get the device contained by devh. Return NULL on error.
347.
348.Pp
349.
164.
165.Pp
166.
350.Fn libusb20_tr_set_buffer
351is used to set the
352.Fa buffer
353pointer for the given USB transfer and
354.Fa fr_index .
167.Ft int
168.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config"
169Return the bConfiguration value of the current configuration. return 0
170on success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
171and a LIBUSB_ERROR code on error.
355.
172.
356Typically the frame index is zero.
357.
358.
359.Pp
360.
173.Pp
174.
361.Fn libusb20_tr_set_callback
362is used to set the USB callback for asynchronous USB
363transfers.
175.Ft int
176.Fn libusb_set_configuration "libusb_device_handle *devh" "int config"
177Set the active configuration
178.Fa config
179for the device contained by
180.Fa devh.
181This function return 0 on success, LIBUSB_ERROR_NOT_FOUND if the requested
182configuration does not exist, LIBUSB_ERROR_BUSY if the interfaces are currently
183claimed, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a
184LIBUSB_ERROR code on failure.
364.
185.
365The callback type is defined by libusb20_tr_callback_t.
366.
367.Pp
368.
186.Pp
187.
369.Fn libusb20_tr_set_flags
370is used to set various USB flags for the given USB transfer.
371.Bl -tag
372.It LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK
373Report a short frame as error.
374.It LIBUSB20_TRANSFER_MULTI_SHORT_NOT_OK
375Multiple short frames are not allowed.
376.It LIBUSB20_TRANSFER_FORCE_SHORT
377All transmitted frames are short terminated.
378.It LIBUSB20_TRANSFER_DO_CLEAR_STALL
379Will do a clear-stall before starting the transfer.
380.El
188.Ft int
189.Fn libusb_claim_interface "libusb_device_handle *devh" "int interface_number"
190Claim an interface in a given libusb_handle
191.Fa devh.
192This is a non-blocking function. It return 0 success, LIBUSB_ERROR_NOT_FOUND
193if the requested interface does not exist, LIBUSB_ERROR_BUSY if a program or
194driver has claimed the interface, LIBUSB_ERROR_NO_DEVICE if the device has
195been disconnected and a LIBUSB_ERROR code on failure.
381.
382.Pp
383.
196.
197.Pp
198.
384.Fn libusb20_tr_get_length
385returns the length of the given USB frame by index.
386After an USB transfer is complete the USB frame length will get updated to the actual transferred length.
199.Ft int
200.Fn libusb_release_interface "libusb_device_handle *devh" "int interface_number"
201This function release an interface. All the claimed interface must be released
202before closing a device. Returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the
203interafce was not claimed, LIBUSB_ERROR_NO_DEVICE if the device has been
204disconnected and LIBUSB_ERROR on failure.
387.
388.Pp
389.
205.
206.Pp
207.
390.Fn libusb20_tr_set_length
391sets the length of the given USB frame by index.
208.Ft int
209.Fn libusb_set_interface_alt_setting "libusb_device_handle *dev" "int interface_number" "int alternate_setting"
210Activate an alternate setting for an interface. Returns 0 on success,
211LIBUSB_ERROR_NOT_FOUND if the interface was not claimed or the requested
212setting does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been
213disconnected and LIBUSB_ERROR code on failure.
392.
393.Pp
394.
214.
215.Pp
216.
395.Fn libusb20_tr_set_priv_sc0
396sets private driver pointer number zero.
217.Ft int
218.Fn libusb_clear_halt "libusb_device_handle *devh" "unsigned char endpoint"
219Clear an halt/stall for a endpoint. Returns 0 on success, LIBUSB_ERROR_NOT_FOUND
220if the endpoint does not exist, LIBUSB_ERROR_NO_DEVICE if the device has been
221disconnected and a LIBUSB_ERROR code on failure.
397.
398.Pp
399.
222.
223.Pp
224.
400.Fn libusb20_tr_set_priv_sc1
401sets private driver pointer number one.
225.Ft int
226.Fn libusb_reset_device "libusb_device_handle *devh"
227Perform an USB port reset for an usb device. Returns 0 on success,
228LIBUSB_ERROR_NOT_FOUND if re-enumeration is required or if the device has
229been disconnected and a LIBUSB_ERROR code on failure.
402.
403.Pp
404.
230.
231.Pp
232.
405.Fn libusb20_tr_set_timeout
406sets the timeout for the given USB transfer.
233.Ft int
234.Fn libusb_kernel_driver_active "libusb_device_handle *devh" "int interface"
235Determine if a driver is active on a interface. Returns 0 if no kernel driver
236is active, returns 1 if a kernel driver is active, returns LIBUSB_ERROR_NO_DEVICE
237if the device has been disconnected and return a LIBUSB_ERROR code on failure.
407.
238.
408A timeout value of zero means no timeout.
409.
410The timeout is given in milliseconds.
411.
412.Pp
413.
239.Pp
240.
414.Fn libusb20_tr_set_total_frames
415sets the total number of frames that should be executed when the USB transfer is submitted.
241.Ft int
242.Fn libusb_detach_kernel_driver "libusb_device_handle *devh" "int interface"
243Detach a kernel driver from an interface. This is needed to claim an interface
244required by a kernel driver. Returns 0 on success, LIBUSB_ERROR_NOT_FOUND if
245no kernel driver was active, LIBUSB_ERROR_INVALID_PARAM if the interface does not
246exist, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and a
247LIBUSB_ERROR code on failure.
416.
248.
417The total number of USB frames must be less than the maximum number of USB frames associated with the given USB transfer.
418.
419.Pp
420.
249.Pp
250.
421.Fn libusb20_tr_setup_bulk
422is a helper function for setting up a single frame USB BULK transfer.
251.Ft int
252.Fn libusb_attach_kernel_driver "libusb_device_handle *devh" "int interface"
253Re-attach an interface kernel driver previously detached. Returns 0 on success,
254LIBUSB_ERROR_INVALID_PARAM if the interface does not exist, LIBUSB_ERROR_NO_DEVICE
255if the device has been disconnect, LIBUSB_ERROR_BUSY if the driver cannot be
256attached because the interface is claimed by a program or driver and a
257LIBUSB_ERROR code on failure.
423.
424.Pp
425.
258.
259.Pp
260.
426.Fn libusb20_tr_setup_control
427is a helper function for setting up a single or dual
428frame USB CONTROL transfer depending on the control transfer length.
261.Sh USB DESCRIPTORS
429.
430.Pp
431.
262.
263.Pp
264.
432.Fn libusb20_tr_setup_intr
433is a helper function for setting up a single frame USB INTERRUPT transfer.
265.Ft int
266.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc"
267Get the USB device descriptor for the device
268.Fa dev.
269This is a non-blocking function. Returns 0 on success and a LIBUSB_ERROR code on
270failure.
434.
435.Pp
271.
272.Pp
273.Ft int
274.Fn libsub_get_active_config_descriptor "libusb_device *dev" "libusb_device_descriptor **config"
275Get the USB configuration descriptor for the active configuration. Returns 0 on
276success, returns LIBUSB_ERROR_NOT_FOUND if the device is in unconfigured state
277and return another LIBUSB_ERROR code on error.
436.
278.
437.Fn libusb20_tr_setup_isoc
438is a helper function for setting up a multi frame USB ISOCHRONOUS transfer.
439.
440.Pp
279.Pp
280.Ft int
281.Fn libusb_get_config_descriptor "libusb_device *dev" "uint8_t config_index" "libusb_config_descriptor **config"
282Get USB configuration descriptor based on its index
283.Fa idx.
284Returns 0 on success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
285and returns another LIBUSB_ERROR code on error.
441.
286.
442.Fn libusb20_tr_start
443will get the USB transfer started, if not already
444started.
445.
446This function will not get the transfer queued in hardware.
447.
448This function is non-blocking.
449.
450.Pp
287.Pp
288.Ft int
289.Fn libusb_get_config_descriptor_by_value "libusb_device *dev" "uint8 bConfigurationValue" "libusb_config_descriptor **config"
290Get a USB configuration descriptor with a specific bConfigurationValue. This is
291a non-blocking function which does not send request through the device. Returns 0
292on success, LIBUSB_ERROR_NOT_FOUND if the configuration does not exist and another
293LIBUSB_ERROR code on failure.
451.
294.
452.Fn libusb20_tr_stop
453will get the USB transfer stopped, if not already stopped.
454.
455This function is non-blocking, which means that the actual stop can
456happen after the return of this function.
457.
458.Pp
295.Pp
296.Ft void
297.Fn libusb_free_config_descriptor "libusb_config_descriptor *config`"
298Free a configuration descriptor.
459.
299.
460.Fn libusb20_tr_submit
461will get the USB transfer queued in hardware.
462.
463.
464.Pp
300.Pp
301.Ft int
302.Fn libusb_get_string_descriptor_ascii "libusb_device_handle *devh" "uint8_t desc_idx" "unsigned char *data" "int length"
303Retrieve a string descriptor in C style ascii. Returns a number of byte on success
304and a LIBUSB_ERROR code on failure.
465.
305.
466.Fn libusb20_tr_get_priv_sc0
467returns private driver pointer number zero associated
468with an USB transfer.
469.
470.
471.Pp
472.
306.Pp
307.
473.Fn libusb20_tr_get_priv_sc1
474returns private driver pointer number one associated
475with an USB transfer.
308.Sh USB ASYNCHRONOUS I/O
476.
309.
477.
478.Sh USB DEVICE OPERATIONS
479.
480.Pp
310.Pp
311.Ft struct libusb_transfer *
312.Fn libusb_alloc_transfer "int iso_packets"
313Allocate a transfer with
314.Fa iso_packets
315numbers of isochronous packet descriptors. Returns NULL on error.
481.
316.
482.Fn libusb20_dev_get_backend_name
483returns a zero terminated string describing the backend used.
484.
485.Pp
317.Pp
318.Ft void
319.Fn libusb_free_transfer "struct libusb_transfer *tr"
320Free a transfer.
486.
321.
487.Fn libusb20_dev_get_info
488retrives the BSD specific usb_device_info structure into the memory location given by
489.Fa pinfo .
490The USB device given by
491.Fa pdev
492must be opened before this function will succeed.
493This function returns zero on success else a LIBUSB20_ERROR value is returned.
494.
495.Pp
322.Pp
323.Ft int
324.Fn libusb_submit_transfer "struct libusb_transfer *tr"
325This function will submit a transfer and returns immediately. Returns 0 on
326success, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
327LIBUSB_ERROR code on other failure.
496.
328.
497.Fn libusb20_dev_get_iface_desc
498retrieves the kernel interface description for the given USB
499.Fa iface_index .
500The format of the USB interface description is: "drivername<unit>: <description>"
501The description string is always zero terminated.
502A zero length string is written in case no driver is attached to the given interface.
503The USB device given by
504.Fa pdev
505must be opened before this function will succeed.
506This function returns zero on success else a LIBUSB20_ERROR value is returned.
507.
508.Pp
329.Pp
330.Ft int
331.Fn libusb_cancel_transfer "struct libusb_transfer *tr"
332This function asynchronously cancel a transfer. Returns 0 on success and
333LIBUSB_ERROR code on failure.
509.
334.
510.Fn libusb20_dev_get_desc
511returns a zero terminated string describing the given USB device.
512The format of the string is: "drivername<unit>: <description>"
513.
514.Pp
335.Pp
336.Sh USB SYNCHRONOUS I/O
515.
337.
516.Fn libusb20_dev_close
517will close the given USB device.
518.
519This function returns zero on success else a LIBUSB20_ERROR value is
520returned.
521.
522.Pp
338.Pp
339.Ft int
340.Fn libusb_control_transfer "libusb_device_handle *devh" "uint8_t bmRequestType" "uint16_t wIndex" "unsigned char *data" "uint16_t wLength" "unsigned int timeout"
341Perform a USB control transfer. Returns 0 on success, LIBUSB_ERROR_TIMEOUT
342if the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not
343supported, LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
344LIBUSB_ERROR code on other failure.
523.
345.
524.Fn libusb20_dev_detach_kernel_driver
525will try to detach the kernel driver for the USB interface given by
526.Fa iface_index .
527.
528This function returns zero on success else a LIBUSB20_ERROR value is
529returned.
530.
531.Pp
346.Pp
347.Ft int
348.Fn libusb_bulk_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout"
349Perform an USB bulk transfer. Returns 0 on success, LIBUSB_ERROR_TIMEOUT
350if the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not
351supported, LIBUSB_ERROR_OVERFLOW if the device offered more data,
352LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
353LIBUSB_ERROR code on other failure.
532.
354.
533.Fn libusb20_dev_set_config_index
534will try to set the configuration index on an USB
535device.
536.
537The first configuration index is zero.
538.
539The un-configure index is 255.
540.
541This function returns zero on success else a LIBUSB20_ERROR value is returned.
542.
543.Pp
355.Pp
356.Ft int
357.Fn libusb_interrupt_transfer "struct libusb_device_handle *devh" "unsigned char endpoint" "unsigned char *data" "int length" "int *transferred" "unsigned int timeout"
358Perform an USB Interrupt transfer. Returns 0 on success, LIBUSB_ERROR_TIMEOUT
359if the transfer timeout, LIBUSB_ERROR_PIPE if the control request was not
360supported, LIBUSB_ERROR_OVERFLOW if the device offered more data,
361LIBUSB_ERROR_NO_DEVICE if the device has been disconnected and
362LIBUSB_ERROR code on other failure.
544.
363.
545.Fn libusb20_dev_get_debug
546returns the debug level of an USB device.
547.
548.Pp
364.Pp
365.Sh USB EVENTS
549.
366.
550.Fn libusb20_dev_get_fd
551returns the file descriptor of the given USB device.
552.
553A negative value is returned when no file descriptor is present.
554.
555The file descriptor can be used for polling purposes.
556.
557.Pp
367.Pp
368.Ft int
369.Fn libusb_try_lock_events "libusb_context *ctx"
370Try to acquire the event handling lock. Returns 0 if the lock was obtained and 1
371if not.
558.
372.
559.Fn libusb20_dev_kernel_driver_active
560returns a non-zero value if a kernel driver is active on
561the given USB interface.
562.
563Else zero is returned.
564.
565.Pp
373.Pp
374.Ft void
375.Fn libusb_lock_events "libusb_context *ctx"
376Acquire the event handling lock. This function is blocking.
566.
377.
567.Fn libusb20_dev_open
568opens an USB device so that setting up USB transfers
569becomes possible.
570.
571The number of USB transfers can be zero which means only control
572transfers are allowed.
573.
574This function returns zero on success else a LIBUSB20_ERROR value is
575returned.
576.
577A return value of LIBUSB20_ERROR_BUSY means that the device is already
578opened.
579.
580.Pp
378.Pp
379.Ft void
380.Fn libusb_unlock_events "libusb_context *ctx"
381Release the event handling lock. This will wake up any thread blocked
382on libusb_wait_for_event().
581.
383.
582.Fn libusb20_dev_process
583is called to sync kernel USB transfers with userland USB
584transfers.
585.
586This function returns zero on success else a LIBUSB20_ERROR value is
587returned typically indicating that the given USB device has been
588detached.
589.
590.Pp
384.Pp
385.Ft int
386.Fn libusb_event_handling_ok "libusb_context *ctx"
387Determine if it still OK for this thread to be doing event handling. Returns 1
388if event handling can start or continue. Returns 0 if this thread must give up
389the events lock.
591.
390.
592.Fn libusb20_dev_request_sync
593will perform a synchronous control request on the given
594USB device.
595.
596Before this call will succeed the USB device must be opened.
597.
598.Fa setup
599is a pointer to a decoded and host endian SETUP packet.
600.Fa data
601is a pointer to a data transfer buffer associated with the control transaction. This argument can be NULL.
602.Fa pactlen
603is a pointer to a variable that will hold the actual transfer length after the control transaction is complete.
604.Fa timeout
605is the transaction timeout given in milliseconds.
606A timeout of zero means no timeout.
607.Fa flags
608is used to specify transaction flags, for example LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK.
609.
610This function returns zero on success else a LIBUSB20_ERROR value is
611returned.
612.
613.Pp
391.Pp
392.Ft int
393.Fn libusb_event_handler_active "libusb_context *ctx"
394Determine if an active thread is handling events. Returns 1 if yes and 0 if there
395are no threads currently handling events.
614.
396.
615.Fn libusb20_dev_req_string_sync
616will synchronously request an USB string by language ID
617and string index into the given buffer limited by a maximum length.
618.
619This function returns zero on success else a LIBUSB20_ERROR value is
620returned.
621.
622.Pp
397.Pp
398.Ft void
399.Fn libusb_lock_event_waiters "libusb_context *ctx"
400Acquire the event_waiters lock. This lock is designed to be obtained under the
401situation where you want to be aware when events are completed, but some other
402thread is event handling so calling libusb_handle_events() is not allowed.
623.
403.
624.Fn libusb20_dev_req_string_simple_sync
625will synchronously request an USB string using the
626default language ID and convert the string into ASCII before storing
627the string into the given buffer limited by a maximum length which
628includes the terminating zero.
629.
630This function returns zero on success else a LIBUSB20_ERROR value is
631returned.
632.
633.
634.Pp
404.Pp
405.Ft void
406.Fn libusb_unlock_event_waiters "libusb_context *ctx"
407Release the event_waiters lock.
635.
408.
636.Fn libusb20_dev_reset
637will try to BUS reset the given USB device and restore
638the last set USB configuration.
639.
640This function returns zero on success else a LIBUSB20_ERROR value is
641returned.
642.
643.Pp
409.Pp
410.Ft int
411.Fn libusb_wait_for_event "libusb_context *ctx" "struct timeval *tv"
412Wait for another thread to signal completion of an event. Must be called
413with the event waiters lock held, see libusb_lock_event_waiters(). This will
414block until the timeout expires or a transfer completes or a thread releases
415the event handling lock through libusb_unlock_events(). Returns 0 after a
416transfer completes or another thread stops event handling, returns 1 if the
417timeout expired.
644.
418.
645.Fn libusb20_dev_set_power_mode
646sets the power mode of the USB device.
647.
648Valid power modes:
649.Bl -tag
650.It LIBUSB20_POWER_OFF
651.It LIBUSB20_POWER_ON
652.It LIBUSB20_POWER_SAVE
653.It LIBUSB20_POWER_SUSPEND
654.It LIBUSB20_POWER_RESUME
655.El
656.
657This function returns zero on success else a LIBUSB20_ERROR value is
658returned.
659.
660.Pp
419.Pp
420.Ft int
421.Fn libusb_handle_events_timeout "libusb_context *ctx" "struct timeval *tv"
422Handle any pending events by checking if timeouts have expired and by
423checking the set of file descriptors for activity. Returns 0 on success, or a
424LIBUSB_ERROR code on failure.
661.
425.
662.Fn libusb20_dev_get_power_mode
663returns the currently selected power mode for the given
664USB device.
665.
666.Pp
426.Pp
427.Ft int
428.Fn libusb_handle_events "libusb_context *ctx"
429Handle any pending events in blocking mode with a sensible timeout. Returns 0
430on success, returns a LIBUSB_ERROR code on failure.
667.
431.
668.Fn libusb20_dev_set_alt_index
669will try to set the given alternate index for the given
670USB interface index.
671.
672This function returns zero on success else a LIBUSB20_ERROR value is
673returned.
674.
675.Pp
432.Pp
433.Ft int
434.Fn libusb_handle_events_locked "libusb_context *ctx" "struct timeval *tv"
435Handle any pending events by polling file desciptors, without checking if
436another threads are already doing so. Must be called with the event lock held.
676.
437.
677.Fn libusb20_dev_get_device_desc
678returns a pointer to the decoded and host endian version
679of the device descriptor.
680.
681The USB device need not be opened when calling this function.
682.
683.Pp
438.Pp
439.Ft int
440.Fn libusb_get_next_timeout "libusb_context *ctx" "struct timeval *tv"
441Determine the next internal timeout that libusb needs to handle. Returns 0
442if there are no pending timeouts, 1 if a timeout was returned, or LIBUSB_ERROR
443code on failure.
684.
444.
685.Fn libusb20_dev_alloc_config
686will read out and decode the USB config descriptor for
687the given USB device and config index. This function returns a pointer
688to the decoded configuration which must eventually be passed to
689free(). NULL is returned in case of failure.
690.
691.Pp
445.Pp
446.Ft void
447.Fn libusb_set_pollfd_notifiers "libusb_context *ctx" "libusb_pollfd_added_cb added_cb" "libusb_pollfd_removed_cb remove_cb" "void *user_data"
448Register notification functions for file descriptor additions/removals.
449These functions will be invoked for every new or removed file descriptor
450that libusb uses as an event source.
692.
451.
693.Fn libusb20_dev_alloc
694is an internal function to allocate a new USB device.
695.
696.Pp
452.Pp
453.Ft const struct libusb_pollfd **
454.Fn libusb_get_pollfds "libusb_context *ctx"
455Retrive a list of file descriptors that should be polled by your main loop as
456libusb event sources. Returns a NULL-terminated list on success or NULL on failure.
697.
457.
698.Fn libusb20_dev_get_address
699returns the internal and not necessarily the real
700hardware address of the given USB device.
701.
458.Sh LIBUSB VERSION 0.1 COMPATIBILITY
702.Pp
459.Pp
703.
704.Fn libusb20_dev_get_bus_number
705returns the internal bus number which the given USB
706device belongs to.
707.
460The library is also compliant with LibUSB version 0.1.12.
708.Pp
461.Pp
709.
710.Fn libusb20_dev_get_mode
711returns the current operation mode of the USB entity.
712.
713Valid return values are:
714.Bl -tag
715.It LIBUSB20_MODE_HOST
716.It LIBUSB20_MODE_DEVICE
717.El
718.
719.Pp
720.
721.Fn libusb20_dev_get_speed
722returns the current speed of the given USB device.
723.
724.Bl -tag
725.It LIBUSB20_SPEED_UNKNOWN
726.It LIBUSB20_SPEED_LOW
727.It LIBUSB20_SPEED_FULL
728.It LIBUSB20_SPEED_HIGH
729.It LIBUSB20_SPEED_VARIABLE
730.It LIBUSB20_SPEED_SUPER
731.El
732.
733.Pp
734.
735.Fn libusb20_dev_get_config_index
736This function returns the currently select config index for the given
737USB device.
738.
739.Pp
740.
741.Fn libusb20_dev_free
742will free the given USB device and all associated USB
743transfers.
744.
745.Pp
746.
747.Fn libusb20_dev_set_debug
748will set the debug level for the given USB device.
749.
750.Pp
751.
752.Fn libusb20_dev_wait_process
753function will wait until a pending USB transfer has completed on
754the given USB device.
755.
756A timeout value can be specified which is passed on to the
757.Xr poll 2
758function.
759.
760.Sh USB BACKEND OPERATIONS
761.
762.Fn libusb20_be_get_template
763will return the currently selected global USB device
764side mode template into the integer pointer
765.Fa ptemp .
766This function returns zero on success else a LIBUSB20_ERROR value is
767returned.
768.
769.Pp
770.
771.Fn libusb20_be_set_template
772will set the global USB device side mode template to
773.Fa temp .
774The new template is not activated until after the next USB
775enumeration.
776The template number decides how the USB device will present itself to
777the USB Host, like Mass Storage Device, USB Ethernet Device. Also see
778the
779.Xr usb2_template 4
780module.
781This function returns zero on success else a LIBUSB20_ERROR value is
782returned.
783.
784.Pp
785.
786.Fn libusb20_be_get_dev_quirk
787This function will return the device quirk according to
788.Fa index
789into the libusb20_quirk structure pointed to by
790.Fa pq .
791This function returns zero on success else a LIBUSB20_ERROR value is
792returned.
793.
794If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
795returned.
796.
797.Pp
798.
799.Fn libusb20_be_get_quirk_name
800will return the quirk name according to
801.Fa index
802into the libusb20_quirk structure pointed to by
803.Fa pq .
804This function returns zero on success else a LIBUSB20_ERROR value is
805returned.
806.
807If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
808returned.
809.
810.Pp
811.
812.Fn libusb20_be_add_dev_quirk
813will add the libusb20_quirk structure pointed to by the
814.Fa pq
815argument into the device quirk list.
816.
817This function returns zero on success else a LIBUSB20_ERROR value is
818returned.
819.
820If the given quirk cannot be added LIBUSB20_ERROR_NO_MEM is
821returned.
822.
823.Pp
824.
825.Fn libusb20_be_remove_dev_quirk
826will remove the quirk matching the libusb20_quirk structure pointed to by the
827.Fa pq
828argument from the device quirk list.
829.
830This function returns zero on success else a LIBUSB20_ERROR value is
831returned.
832.
833If the given quirk does not exist LIBUSB20_ERROR_NOT_FOUND is
834returned.
835.
836.Pp
837.
838.Fn libusb20_be_alloc_default
839.Fn libusb20_be_alloc_freebsd
840.Fn libusb20_be_alloc_linux
841These functions are used to allocate a specific USB backend or the
842operating system default USB backend. Allocating a backend is a way to
843scan for currently present USB devices.
844.
845.Pp
846.
847.Fn libusb20_be_device_foreach
848is used to iterate USB devices present in a USB backend.
849.
850The starting value of
851.Fa pdev
852is NULL.
853.
854This function returns the next USB device in the list.
855.
856If NULL is returned the end of the USB device list has been reached.
857.
858.Pp
859.
860.Fn libusb20_be_dequeue_device
861will dequeue the given USB device pointer from the
862backend USB device list.
863.
864Dequeued USB devices will not be freed when the backend is freed.
865.
866.Pp
867.
868.Fn libusb20_be_enqueue_device
869This function will enqueue the given USB device pointer in the backend USB device list.
870.
871Enqueued USB devices will get freed when the backend is freed.
872.
873.Pp
874.
875.Fn libusb20_be_free
876will free the given backend and all USB devices in its device list.
877.
878.
879.Sh USB DESCRIPTOR PARSING
880.
881.Fn libusb20_me_get_1 pie offset
882This function will return a byte at the given byte offset of a message
883entity.
884.
885This function is safe against invalid offsets.
886.
887.Pp
888.
889.Fn libusb20_me_get_2 pie offset
890This function will return a little endian 16-bit value at the given byte offset of a message
891entity.
892.
893This function is safe against invalid offsets.
894.
895.Pp
896.
897.Fn libusb20_me_encode pbuf len pdecoded
898This function will encode a so-called *DECODED structure into binary
899format.
900.
901The total encoded length that will fit in the given buffer is
902returned.
903.
904If the buffer pointer is NULL no data will be written to the buffer
905location.
906.
907.Pp
908.
909.Fn libusb20_me_decode pbuf len pdecoded
910This function will decode a binary structure into a so-called *DECODED
911structure.
912.
913The total decoded length is returned.
914.
915The buffer pointer cannot be NULL.
916.
917.
918.Sh LIBUSB VERSION 0.1 COMPATIBILITY
919.
920.Fn usb_open
921.Fn usb_close
922.Fn usb_get_string
923.Fn usb_get_string_simple
924.Fn usb_get_descriptor_by_endpoint
925.Fn usb_get_descriptor
926.Fn usb_parse_descriptor
927.Fn usb_parse_configuration

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

941.Fn usb_reset
942.Fn usb_strerror
943.Fn usb_init
944.Fn usb_set_debug
945.Fn usb_find_busses
946.Fn usb_find_devices
947.Fn usb_device
948.Fn usb_get_busses
462.Fn usb_open
463.Fn usb_close
464.Fn usb_get_string
465.Fn usb_get_string_simple
466.Fn usb_get_descriptor_by_endpoint
467.Fn usb_get_descriptor
468.Fn usb_parse_descriptor
469.Fn usb_parse_configuration

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

483.Fn usb_reset
484.Fn usb_strerror
485.Fn usb_init
486.Fn usb_set_debug
487.Fn usb_find_busses
488.Fn usb_find_devices
489.Fn usb_device
490.Fn usb_get_busses
949These functions are compliant with LibUSB version 0.1.12.
950.
491.
951.Sh FILES
952.
953.
954/dev/usb
955.Sh SEE ALSO
492.Sh SEE ALSO
493.Xr libusb20 3 ,
956.Xr usb 4 ,
957.Xr usbconfig 8
494.Xr usb 4 ,
495.Xr usbconfig 8
496.Pp
497.Pa http://libusb.sourceforge.net/
958.
498.
959.
960.Sh HISTORY
961.
499.Sh HISTORY
500.
962.
963Some parts of the
964.Nm
501.Nm
965API derives from the libusb project at sourceforge.
502support first appeared in
503.Fx 8.0 .