xref: /freebsd/lib/libusb/libusb20_dev_open.3 (revision 32cd3ee5901ea33d41ff550e5f40ce743c8d4165)
1.\"
2.\" Copyright (c) 2025 Rick Parrish <unitrunker@unitrunker.net>
3.\"
4.\" SPDX-License-Identifier: BSD-2-Clause
5.\"
6.Dd December 14, 2025
7.Dt LIBUSB20 3
8.Os
9.Sh NAME
10.Nm libusb20_dev_open
11.Nd open a USB device to retrieve descriptors and initiate transfers
12.Sh SYNOPSIS
13.Lb libusb
14.In libusb20.h
15.Ft int
16.Fn libusb20_dev_open "struct libusb20_device *pdev" "uin16_t transfer_max"
17.Sh DESCRIPTION
18The
19.Nm
20function opens a USB device to retrieve descriptors and initiate transfers.
21.Nm
22accepts a pointer as
23.Fa pdev
24to a libusb20_device obtained from
25.Nm libusb20_be_device_foreach .
26A zero for
27.Fa transfer_max
28limits the device to only control transfers.
29Call
30.Xr libusb20_dev_close 3
31to free resources taken by the open device handle.
32.Sh RETURN VALUES
33.Nm
34returns one of the following to report success or failure:
35.Pp
36.Bl -tag -width "LIBUSB20_ERROR_NO_DEVICE," -compact
37.It Er LIBUSB20_SUCCESS ,
38The operation succeeds.
39.It Er LIBUSB20_ERROR_BUSY ,
40The device is in use elsewhere.
41.It Er LIBUSB20_ERROR_ACCESS ,
42A permissions issue.
43.It Er LIBUSB20_ERROR_NO_DEVICE ,
44The device detached.
45.It Er LIBUSB20_ERROR_NO_MEM
46The library couldn't allocate memory.
47.El
48.Pp
49Errors not listed here may be found in
50.Xr libusb20 3
51and
52.In libusb20.h .
53.Sh EXAMPLES
54.Bd -literal
55    #include <libusb20.h>
56    struct libusb20_backend *be = libusb20_be_alloc_default();
57    struct libusb20_device *device = NULL;
58    while ( (device = libusb20_be_device_foreach(be, device)) != NULL ) {
59        if (libusb20_dev_open(device, 0) == LIBUSB20_SUCCESS) {
60            /* do something */
61            libusb20_dev_close(device);
62        }
63    }
64    libusb20_be_free(be);
65.Ed
66.Sh SEE ALSO
67.Xr libusb20 3 ,
68.Xr libusb20_be_device_foreach 3 ,
69.Xr libusb20_dev_close 3
70