Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137901535
D46992.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D46992.diff
View Options
diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h
--- a/lib/libusb/libusb.h
+++ b/lib/libusb/libusb.h
@@ -503,6 +503,7 @@
libusb_device_handle *libusb_open_device_with_vid_pid(libusb_context * ctx, uint16_t vendor_id, uint16_t product_id);
void libusb_close(libusb_device_handle * devh);
libusb_device *libusb_get_device(libusb_device_handle * devh);
+libusb_device *libusb_get_parent(libusb_device * dev);
int libusb_get_configuration(libusb_device_handle * devh, int *config);
int libusb_set_configuration(libusb_device_handle * devh, int configuration);
int libusb_claim_interface(libusb_device_handle * devh, int interface_number);
diff --git a/lib/libusb/libusb.3 b/lib/libusb/libusb.3
--- a/lib/libusb/libusb.3
+++ b/lib/libusb/libusb.3
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd May 16, 2025
+.Dd June 12, 2025
.Dt LIBUSB 3
.Os
.Sh NAME
@@ -117,7 +117,7 @@
.Fn libusb_set_debug "libusb_context *ctx" "int level"
Set the debug level to
.Fa level .
-.Pp
+.Sh DEVICE HANDLING AND ENUMERATION
.Ft ssize_t
.Fn libusb_get_device_list "libusb_context *ctx" "libusb_device ***list"
Populate
@@ -220,6 +220,11 @@
Get the device contained by devh.
Returns NULL on error.
.Pp
+.Ft libusb_device *
+.Fn libusb_get_parent "libusb_device *dev"
+Get dev's parent device.
+Returns NULL if the device has no parent (i.e. is a root device).
+.Pp
.Ft int
.Fn libusb_get_configuration "libusb_device_handle *devh" "int *config"
Returns the value of the current configuration.
diff --git a/lib/libusb/libusb10.h b/lib/libusb/libusb10.h
--- a/lib/libusb/libusb10.h
+++ b/lib/libusb/libusb10.h
@@ -142,6 +142,7 @@
struct libusb_super_pollfd dev_poll;
struct libusb_context *ctx;
+ struct libusb_device *parent_dev;
TAILQ_ENTRY(libusb_device) hotplug_entry;
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -3,6 +3,7 @@
*
* Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
* Copyright (c) 2009-2023 Hans Petter Selasky
+ * Copyright (c) 2024 Aymeric Wibo
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -311,9 +312,9 @@
libusb_get_device_list(libusb_context *ctx, libusb_device ***list)
{
struct libusb20_backend *usb_backend;
- struct libusb20_device *pdev;
+ struct libusb20_device *pdev, *parent_dev;
struct libusb_device *dev;
- int i;
+ int i, j, k;
ctx = GET_CONTEXT(ctx);
@@ -365,6 +366,9 @@
/* set context we belong to */
dev->ctx = ctx;
+ /* assume we have no parent by default */
+ dev->parent_dev = NULL;
+
/* link together the two structures */
dev->os_priv = pdev;
pdev->privLuData = dev;
@@ -374,6 +378,25 @@
}
(*list)[i] = NULL;
+ /* for each device, find its parent */
+ for (j = 0; j < i; j++) {
+ pdev = (*list)[j]->os_priv;
+
+ for (k = 0; k < i; k++) {
+ if (k == j)
+ continue;
+
+ parent_dev = (*list)[k]->os_priv;
+
+ if (parent_dev->bus_number != pdev->bus_number)
+ continue;
+ if (parent_dev->device_address == pdev->parent_address) {
+ (*list)[j]->parent_dev = libusb_ref_device((*list)[k]);
+ break;
+ }
+ }
+ }
+
libusb20_be_free(usb_backend);
return (i);
}
@@ -540,6 +563,7 @@
CTX_UNLOCK(dev->ctx);
if (dev->refcnt == 0) {
+ libusb_unref_device(dev->parent_dev);
libusb20_dev_free(dev->os_priv);
free(dev);
}
@@ -816,6 +840,12 @@
return (err ? LIBUSB_ERROR_OTHER : 0);
}
+libusb_device *
+libusb_get_parent(libusb_device *dev)
+{
+ return (dev->parent_dev);
+}
+
static struct libusb20_transfer *
libusb10_get_transfer(struct libusb20_device *pdev,
uint8_t endpoint, uint8_t xfer_index)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 28, 1:08 AM (3 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26269683
Default Alt Text
D46992.diff (3 KB)
Attached To
Mode
D46992: libusb: implement `libusb_get_parent`
Attached
Detach File
Event Timeline
Log In to Comment