aboutsummaryrefslogtreecommitdiff
path: root/lib/libusb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libusb')
-rw-r--r--lib/libusb/Makefile6
-rw-r--r--lib/libusb/libusb10.c18
-rw-r--r--lib/libusb/libusb10_hotplug.c4
-rw-r--r--lib/libusb/libusb20_be_device_foreach.356
-rw-r--r--lib/libusb/libusb20_dev_open.369
5 files changed, 148 insertions, 5 deletions
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile
index 4a0c392f0d8f..b3ef5a061584 100644
--- a/lib/libusb/Makefile
+++ b/lib/libusb/Makefile
@@ -1,5 +1,4 @@
#
-#
# Makefile for the FreeBSD specific LibUSB 2.0
#
@@ -11,7 +10,8 @@ SRCS+= libusb20_desc.c
SRCS+= libusb20_ugen20.c
INCS+= libusb20.h
INCS+= libusb20_desc.h
-MAN= libusb.3 libusb20.3
+MAN= libusb.3 libusb20.3 libusb20_be_device_foreach.3 \
+ libusb20_dev_open.3
MKLINT= no
NOGCCERROR=
PTHREAD_LIBS?= -lpthread
@@ -229,7 +229,6 @@ MLINKS += libusb20.3 libusb20_dev_set_config_index.3
MLINKS += libusb20.3 libusb20_dev_get_debug.3
MLINKS += libusb20.3 libusb20_dev_get_fd.3
MLINKS += libusb20.3 libusb20_dev_kernel_driver_active.3
-MLINKS += libusb20.3 libusb20_dev_open.3
MLINKS += libusb20.3 libusb20_dev_process.3
MLINKS += libusb20.3 libusb20_dev_request_sync.3
MLINKS += libusb20.3 libusb20_dev_req_string_sync.3
@@ -261,7 +260,6 @@ MLINKS += libusb20.3 libusb20_be_get_quirk_name.3
MLINKS += libusb20.3 libusb20_be_add_dev_quirk.3
MLINKS += libusb20.3 libusb20_be_remove_dev_quirk.3
MLINKS += libusb20.3 libusb20_be_alloc_default.3
-MLINKS += libusb20.3 libusb20_be_device_foreach.3
MLINKS += libusb20.3 libusb20_be_dequeue_device.3
MLINKS += libusb20.3 libusb20_be_enqueue_device.3
MLINKS += libusb20.3 libusb20_be_free.3
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
index e226def0b7b6..b3af017ab980 100644
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -1259,6 +1259,9 @@ libusb10_isoc_proxy(struct libusb20_transfer *pxfer)
libusb20_tr_get_length(pxfer, i);
}
libusb10_complete_transfer(pxfer, sxfer, LIBUSB_TRANSFER_COMPLETED);
+
+ /* start next queued transfer, if any */
+ libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint);
break;
case LIBUSB20_TRANSFER_START:
/* setup length(s) */
@@ -1281,6 +1284,9 @@ libusb10_isoc_proxy(struct libusb20_transfer *pxfer)
break;
default:
libusb10_complete_transfer(pxfer, sxfer, libusb10_convert_error(status));
+
+ /* start next queued transfer, if any */
+ libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint);
break;
}
}
@@ -1322,11 +1328,15 @@ libusb10_bulk_intr_proxy(struct libusb20_transfer *pxfer)
} else {
libusb10_complete_transfer(pxfer, sxfer, LIBUSB_TRANSFER_COMPLETED);
}
+ /* start next queued transfer, if any */
+ libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint);
break;
}
/* check for end of data */
if (sxfer->rem_len == 0) {
libusb10_complete_transfer(pxfer, sxfer, LIBUSB_TRANSFER_COMPLETED);
+ /* start next queued transfer, if any */
+ libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint);
break;
}
/* FALLTHROUGH */
@@ -1353,6 +1363,8 @@ libusb10_bulk_intr_proxy(struct libusb20_transfer *pxfer)
default:
libusb10_complete_transfer(pxfer, sxfer, libusb10_convert_error(status));
+ /* start next queued transfer, if any */
+ libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint);
break;
}
}
@@ -1397,11 +1409,15 @@ libusb10_ctrl_proxy(struct libusb20_transfer *pxfer)
} else {
libusb10_complete_transfer(pxfer, sxfer, LIBUSB_TRANSFER_COMPLETED);
}
+ /* start next queued transfer, if any */
+ libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint);
break;
}
/* check for end of data */
if (sxfer->rem_len == 0) {
libusb10_complete_transfer(pxfer, sxfer, LIBUSB_TRANSFER_COMPLETED);
+ /* start next queued transfer, if any */
+ libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint);
break;
}
/* FALLTHROUGH */
@@ -1442,6 +1458,8 @@ libusb10_ctrl_proxy(struct libusb20_transfer *pxfer)
default:
libusb10_complete_transfer(pxfer, sxfer, libusb10_convert_error(status));
+ /* start next queued transfer, if any */
+ libusb10_submit_transfer_sub(libusb20_tr_get_priv_sc0(pxfer), uxfer->endpoint);
break;
}
}
diff --git a/lib/libusb/libusb10_hotplug.c b/lib/libusb/libusb10_hotplug.c
index 9c46d4926bfa..359c818b5720 100644
--- a/lib/libusb/libusb10_hotplug.c
+++ b/lib/libusb/libusb10_hotplug.c
@@ -430,5 +430,7 @@ libusb_hotplug_get_user_data(struct libusb_context *ctx,
}
HOTPLUG_UNLOCK(ctx);
- return (handle);
+ if (handle != NULL)
+ return (handle->user_data);
+ return (NULL);
}
diff --git a/lib/libusb/libusb20_be_device_foreach.3 b/lib/libusb/libusb20_be_device_foreach.3
new file mode 100644
index 000000000000..bc741813ddb0
--- /dev/null
+++ b/lib/libusb/libusb20_be_device_foreach.3
@@ -0,0 +1,56 @@
+.\"
+.\" Copyright (c) 2025 Rick Parrish <unitrunker@unitrunker.net>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd December 14, 2025
+.Dt LIBUSB20 3
+.Os
+.Sh NAME
+.Nm libusb20_be_device_foreach
+.Nd iterate connected USB devices
+.Sh SYNOPSIS
+.Lb libusb
+.In libusb20.h
+.Ft struct libusb20_device *
+.Fn libusb20_be_device_foreach "struct libusb20_backend *pbe" "struct libusb20_device *pdev"
+.Sh DESCRIPTION
+The
+.Nm
+function iterates connected USB devices, one device at a time.
+A backend pointer for
+.Fa pbe
+may be obtained by calling
+.Xr libusb20_be_alloc_default 3 .
+The starting value of
+.Fa pdev
+is NULL.
+Calling
+.Nm libusb20_be_device_foreach
+again with
+.Fa pdev
+set to the return value of the previous call yields the next device.
+To begin interacting with a USB device, pass the pointer in a call to
+.Xr libusb20_dev_open 3 .
+.Sh RETURN VALUES
+.Nm
+returns NULL for end of list.
+Otherwise this is a pointer to the next device.
+.Sh EXAMPLES
+.Bd -literal
+ #include <libusb20.h>
+ struct libusb20_backend *be = libusb20_be_alloc_default();
+ struct libusb20_device *device = NULL;
+ while ( (device = libusb20_be_device_foreach(be, device)) != NULL ) {
+ if (libusb20_dev_open(device, 0) == LIBUSB20_SUCCESS) {
+ /* do something */
+ libusb20_dev_close(device);
+ }
+ }
+ libusb20_be_free(be);
+.Ed
+.Sh SEE ALSO
+.Xr libusb20 3 ,
+.Xr libusb20_be_alloc_default 3 ,
+.Xr libusb20_be_free 3 ,
+.Xr libusb20_dev_open 3
diff --git a/lib/libusb/libusb20_dev_open.3 b/lib/libusb/libusb20_dev_open.3
new file mode 100644
index 000000000000..fa5d1746ff23
--- /dev/null
+++ b/lib/libusb/libusb20_dev_open.3
@@ -0,0 +1,69 @@
+.\"
+.\" Copyright (c) 2025 Rick Parrish <unitrunker@unitrunker.net>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd December 14, 2025
+.Dt LIBUSB20 3
+.Os
+.Sh NAME
+.Nm libusb20_dev_open
+.Nd open a USB device to retrieve descriptors and initiate transfers
+.Sh SYNOPSIS
+.Lb libusb
+.In libusb20.h
+.Ft int
+.Fn libusb20_dev_open "struct libusb20_device *pdev" "uin16_t transfer_max"
+.Sh DESCRIPTION
+The
+.Nm
+function opens a USB device to retrieve descriptors and initiate transfers.
+.Nm
+accepts a pointer as
+.Fa pdev
+to a libusb20_device obtained from
+.Nm libusb20_be_device_foreach .
+A zero for
+.Fa transfer_max
+limits the device to only control transfers.
+Call
+.Xr libusb20_dev_close 3
+to free resources taken by the open device handle.
+.Sh RETURN VALUES
+.Nm
+returns one of the following to report success or failure:
+.Pp
+.Bl -tag -width "LIBUSB20_ERROR_NO_DEVICE," -compact
+.It Er LIBUSB20_SUCCESS ,
+The operation succeeds.
+.It Er LIBUSB20_ERROR_BUSY ,
+The device is in use elsewhere.
+.It Er LIBUSB20_ERROR_ACCESS ,
+A permissions issue.
+.It Er LIBUSB20_ERROR_NO_DEVICE ,
+The device detached.
+.It Er LIBUSB20_ERROR_NO_MEM
+The library couldn't allocate memory.
+.El
+.Pp
+Errors not listed here may be found in
+.Xr libusb20 3
+and
+.In libusb20.h .
+.Sh EXAMPLES
+.Bd -literal
+ #include <libusb20.h>
+ struct libusb20_backend *be = libusb20_be_alloc_default();
+ struct libusb20_device *device = NULL;
+ while ( (device = libusb20_be_device_foreach(be, device)) != NULL ) {
+ if (libusb20_dev_open(device, 0) == LIBUSB20_SUCCESS) {
+ /* do something */
+ libusb20_dev_close(device);
+ }
+ }
+ libusb20_be_free(be);
+.Ed
+.Sh SEE ALSO
+.Xr libusb20 3 ,
+.Xr libusb20_be_device_foreach 3 ,
+.Xr libusb20_dev_close 3