svn commit: r301966 - head/lib/libusb
Hans Petter Selasky
hselasky at FreeBSD.org
Thu Jun 16 14:26:06 UTC 2016
Author: hselasky
Date: Thu Jun 16 14:26:04 2016
New Revision: 301966
URL: https://svnweb.freebsd.org/changeset/base/301966
Log:
Add support for libusb_set_auto_detach_kernel_driver() to the LibUSB v1.0 API.
Approved by: re (kostikbel)
Requested by: swills
MFC after: 1 week
Modified:
head/lib/libusb/Makefile
head/lib/libusb/libusb.3
head/lib/libusb/libusb.h
head/lib/libusb/libusb10.c
head/lib/libusb/libusb20.c
head/lib/libusb/libusb20_int.h
Modified: head/lib/libusb/Makefile
==============================================================================
--- head/lib/libusb/Makefile Thu Jun 16 13:34:20 2016 (r301965)
+++ head/lib/libusb/Makefile Thu Jun 16 14:26:04 2016 (r301966)
@@ -74,6 +74,7 @@ MLINKS += libusb.3 libusb_set_debug.3
MLINKS += libusb.3 libusb_get_device_list.3
MLINKS += libusb.3 libusb_free_device_list.3
MLINKS += libusb.3 libusb_get_bus_number.3
+MLINKS += libusb.3 libusb_get_port_number.3
MLINKS += libusb.3 libusb_get_device_address.3
MLINKS += libusb.3 libusb_get_device_speed.3
MLINKS += libusb.3 libusb_get_max_packet_size.3
@@ -98,6 +99,7 @@ MLINKS += libusb.3 libusb_get_driver_np.
MLINKS += libusb.3 libusb_detach_kernel_driver.3
MLINKS += libusb.3 libusb_detach_kernel_driver_np.3
MLINKS += libusb.3 libusb_attach_kernel_driver.3
+MLINKS += libusb.3 libusb_set_auto_detach_kernel_driver.3
MLINKS += libusb.3 libusb_get_device_descriptor.3
MLINKS += libusb.3 libusb_get_active_config_descriptor.3
MLINKS += libusb.3 libusb_get_config_descriptor.3
Modified: head/lib/libusb/libusb.3
==============================================================================
--- head/lib/libusb/libusb.3 Thu Jun 16 13:34:20 2016 (r301965)
+++ head/lib/libusb/libusb.3 Thu Jun 16 14:26:04 2016 (r301966)
@@ -298,6 +298,18 @@ LIBUSB_ERROR_NO_DEVICE
if the device has been disconnected, LIBUSB_ERROR_BUSY if the driver cannot be
attached because the interface is claimed by a program or driver and a
LIBUSB_ERROR code on failure.
+.Pp
+.Ft int
+.Fn libusb_set_auto_detach_kernel_driver "libusb_device_handle *devh" "int enable"
+This function enables automatic kernel interface driver detach when an
+interface is claimed.
+When the interface is restored the kernel driver is allowed to be re-attached.
+If the
+.Fa enable
+argument is non-zero the feature is enabled.
+Else disabled.
+Returns 0 on success and a LIBUSB_ERROR code on
+failure.
.Sh USB DESCRIPTORS
.Ft int
.Fn libusb_get_device_descriptor "libusb_device *dev" "libusb_device_descriptor *desc"
Modified: head/lib/libusb/libusb.h
==============================================================================
--- head/lib/libusb/libusb.h Thu Jun 16 13:34:20 2016 (r301965)
+++ head/lib/libusb/libusb.h Thu Jun 16 14:26:04 2016 (r301966)
@@ -432,6 +432,7 @@ int libusb_get_driver(libusb_device_hand
int libusb_detach_kernel_driver_np(libusb_device_handle * devh, int interface);
int libusb_detach_kernel_driver(libusb_device_handle * devh, int interface);
int libusb_attach_kernel_driver(libusb_device_handle * devh, int interface);
+int libusb_set_auto_detach_kernel_driver(libusb_device_handle *dev, int enable);
int libusb_set_interface_alt_setting(libusb_device_handle * devh, int interface_number, int alternate_setting);
/* USB Descriptors */
Modified: head/lib/libusb/libusb10.c
==============================================================================
--- head/lib/libusb/libusb10.c Thu Jun 16 13:34:20 2016 (r301965)
+++ head/lib/libusb/libusb10.c Thu Jun 16 14:26:04 2016 (r301966)
@@ -637,6 +637,7 @@ int
libusb_claim_interface(struct libusb20_device *pdev, int interface_number)
{
libusb_device *dev;
+ int err = 0;
dev = libusb_get_device(pdev);
if (dev == NULL)
@@ -645,11 +646,17 @@ libusb_claim_interface(struct libusb20_d
if (interface_number < 0 || interface_number > 31)
return (LIBUSB_ERROR_INVALID_PARAM);
+ if (pdev->auto_detach != 0) {
+ err = libusb_detach_kernel_driver(pdev, interface_number);
+ if (err != 0)
+ goto done;
+ }
+
CTX_LOCK(dev->ctx);
dev->claimed_interfaces |= (1 << interface_number);
CTX_UNLOCK(dev->ctx);
-
- return (0);
+done:
+ return (err);
}
int
@@ -665,13 +672,19 @@ libusb_release_interface(struct libusb20
if (interface_number < 0 || interface_number > 31)
return (LIBUSB_ERROR_INVALID_PARAM);
+ if (pdev->auto_detach != 0) {
+ err = libusb_attach_kernel_driver(pdev, interface_number);
+ if (err != 0)
+ goto done;
+ }
+
CTX_LOCK(dev->ctx);
if (!(dev->claimed_interfaces & (1 << interface_number)))
err = LIBUSB_ERROR_NOT_FOUND;
-
- if (!err)
+ else
dev->claimed_interfaces &= ~(1 << interface_number);
CTX_UNLOCK(dev->ctx);
+done:
return (err);
}
@@ -873,6 +886,12 @@ libusb_attach_kernel_driver(struct libus
return (0);
}
+int
+libusb_set_auto_detach_kernel_driver(libusb_device_handle *dev, int enable)
+{
+ dev->auto_detach = (enable ? 1 : 0);
+}
+
/* Asynchronous device I/O */
struct libusb_transfer *
Modified: head/lib/libusb/libusb20.c
==============================================================================
--- head/lib/libusb/libusb20.c Thu Jun 16 13:34:20 2016 (r301965)
+++ head/lib/libusb/libusb20.c Thu Jun 16 14:26:04 2016 (r301966)
@@ -601,6 +601,12 @@ libusb20_dev_close(struct libusb20_devic
*/
pdev->claimed_interface = 0;
+ /*
+ * The following variable is only used by the libusb v1.0
+ * compat layer:
+ */
+ pdev->auto_detach = 0;
+
return (error);
}
Modified: head/lib/libusb/libusb20_int.h
==============================================================================
--- head/lib/libusb/libusb20_int.h Thu Jun 16 13:34:20 2016 (r301965)
+++ head/lib/libusb/libusb20_int.h Thu Jun 16 14:26:04 2016 (r301966)
@@ -213,6 +213,9 @@ struct libusb20_device {
/* claimed interface */
uint8_t claimed_interface;
+ /* auto detach kernel driver */
+ uint8_t auto_detach;
+
/* device file handle */
int file;
More information about the svn-src-head
mailing list