aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libusb/Makefile1
-rw-r--r--lib/libusb/libusb.37
-rw-r--r--lib/libusb/libusb.h4
-rw-r--r--lib/libusb/libusb01.c18
-rw-r--r--lib/libusb/libusb10.c8
-rw-r--r--lib/libusb/libusb20.311
-rw-r--r--lib/libusb/libusb20.c11
-rw-r--r--lib/libusb/libusb20.h2
-rw-r--r--lib/libusb/libusb20_int.h2
-rw-r--r--lib/libusb/libusb20_ugen20.c12
-rw-r--r--lib/libusb/usb.h1
11 files changed, 71 insertions, 6 deletions
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile
index b3ef5a061584..89cf600236cc 100644
--- a/lib/libusb/Makefile
+++ b/lib/libusb/Makefile
@@ -225,6 +225,7 @@ MLINKS += libusb20.3 libusb20_dev_get_desc.3
MLINKS += libusb20.3 libusb20_dev_get_stats.3
MLINKS += libusb20.3 libusb20_dev_close.3
MLINKS += libusb20.3 libusb20_dev_detach_kernel_driver.3
+MLINKS += libusb20.3 libusb20_dev_attach_kernel_driver.3
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
diff --git a/lib/libusb/libusb.3 b/lib/libusb/libusb.3
index 607a7f645d95..90d9afdb5609 100644
--- a/lib/libusb/libusb.3
+++ b/lib/libusb/libusb.3
@@ -95,8 +95,10 @@ supports hotplug notifications.
can access HID devices without requiring user intervention.
.It Va LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER
.Nm
-supports detaching of the default USB driver with
-.Fn libusb_detach_kernel_driver .
+supports detaching and attaching of the default USB driver with
+.Fn libusb_detach_kernel_driver
+and
+.Fn libusb_attach_kernel_driver .
.El
.Pp
.Ft const char *
@@ -869,6 +871,7 @@ The library is also compliant with LibUSB version 0.1.12.
.Fn usb_check_connected
.Fn usb_get_driver_np
.Fn usb_detach_kernel_driver_np
+.Fn usb_attach_kernel_driver_np
.Sh SEE ALSO
.Xr libusb20 3 ,
.Xr usb 4 ,
diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h
index 46a2ed5eb8a6..fd99a67216aa 100644
--- a/lib/libusb/libusb.h
+++ b/lib/libusb/libusb.h
@@ -209,8 +209,8 @@ enum libusb_capability {
LIBUSB_CAP_HAS_HID_ACCESS,
/*
- * Supports detaching of the default USB driver with
- * libusb_detach_kernel_driver().
+ * Supports detaching and attaching of the default USB driver with
+ * libusb_detach_kernel_driver() and libusb_attach_kernel_driver().
*/
LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER,
};
diff --git a/lib/libusb/libusb01.c b/lib/libusb/libusb01.c
index f246e74353a6..84367765815a 100644
--- a/lib/libusb/libusb01.c
+++ b/lib/libusb/libusb01.c
@@ -1023,3 +1023,21 @@ usb_detach_kernel_driver_np(usb_dev_handle * dev, int interface)
return (0);
}
+
+int
+usb_attach_kernel_driver_np(usb_dev_handle *dev, int interface)
+{
+ struct libusb20_device *pdev;
+ int err;
+
+ pdev = (void *)dev;
+
+ if (pdev == NULL)
+ return (-1);
+
+ err = libusb20_dev_attach_kernel_driver(pdev, interface);
+ if (err != 0)
+ return (-1);
+
+ return (0);
+}
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c
index 56c9caedab16..289b56842b5d 100644
--- a/lib/libusb/libusb10.c
+++ b/lib/libusb/libusb10.c
@@ -1052,10 +1052,14 @@ libusb_detach_kernel_driver(struct libusb20_device *pdev, int interface)
int
libusb_attach_kernel_driver(struct libusb20_device *pdev, int interface)
{
+ int err;
+
if (pdev == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
- /* stub - currently not supported by libusb20 */
- return (0);
+
+ err = libusb20_dev_attach_kernel_driver(pdev, interface);
+
+ return (err ? LIBUSB_ERROR_OTHER : 0);
}
int
diff --git a/lib/libusb/libusb20.3 b/lib/libusb/libusb20.3
index 7854b0f8ed7e..a5213b1aa187 100644
--- a/lib/libusb/libusb20.3
+++ b/lib/libusb/libusb20.3
@@ -126,6 +126,8 @@ USB access library (libusb -lusb)
.Ft int
.Fn libusb20_dev_detach_kernel_driver "struct libusb20_device *pdev" "uint8_t iface_index"
.Ft int
+.Fn libusb20_dev_attach_kernel_driver "struct libusb20_device *pdev" "uint8_t iface_index"
+.Ft int
.Fn libusb20_dev_set_config_index "struct libusb20_device *pdev" "uint8_t configIndex"
.Ft int
.Fn libusb20_dev_get_debug "struct libusb20_device *pdev"
@@ -623,6 +625,15 @@ returned.
.
.Pp
.
+.Fn libusb20_dev_attach_kernel_driver
+will try to attach the kernel driver for the USB interface given by
+.Fa iface_index .
+.
+This function returns zero on success else a LIBUSB20_ERROR value is
+returned.
+.
+.Pp
+.
.Fn libusb20_dev_set_config_index
will try to set the configuration index on an USB
device.
diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c
index 25c95adc27ff..7b443e236cc2 100644
--- a/lib/libusb/libusb20.c
+++ b/lib/libusb/libusb20.c
@@ -80,6 +80,7 @@ dummy_callback(struct libusb20_transfer *xfer)
#define dummy_get_stats (void *)dummy_int
#define dummy_kernel_driver_active (void *)dummy_int
#define dummy_detach_kernel_driver (void *)dummy_int
+#define dummy_attach_kernel_driver (void *)dummy_int
#define dummy_do_request_sync (void *)dummy_int
#define dummy_tr_open (void *)dummy_int
#define dummy_tr_close (void *)dummy_int
@@ -636,6 +637,16 @@ libusb20_dev_detach_kernel_driver(struct libusb20_device *pdev, uint8_t ifaceInd
return (error);
}
+int
+libusb20_dev_attach_kernel_driver(struct libusb20_device *pdev,
+ uint8_t ifaceIndex)
+{
+ int error;
+
+ error = pdev->methods->attach_kernel_driver(pdev, ifaceIndex);
+ return (error);
+}
+
struct LIBUSB20_DEVICE_DESC_DECODED *
libusb20_dev_get_device_desc(struct libusb20_device *pdev)
{
diff --git a/lib/libusb/libusb20.h b/lib/libusb/libusb20.h
index c132c58a9f69..a9bb3ec1647e 100644
--- a/lib/libusb/libusb20.h
+++ b/lib/libusb/libusb20.h
@@ -246,6 +246,8 @@ const char *libusb20_dev_get_backend_name(struct libusb20_device *pdev);
const char *libusb20_dev_get_desc(struct libusb20_device *pdev);
int libusb20_dev_close(struct libusb20_device *pdev);
int libusb20_dev_detach_kernel_driver(struct libusb20_device *pdev, uint8_t iface_index);
+int libusb20_dev_attach_kernel_driver(struct libusb20_device *pdev,
+ uint8_t iface_index);
int libusb20_dev_set_config_index(struct libusb20_device *pdev, uint8_t configIndex);
int libusb20_dev_get_debug(struct libusb20_device *pdev);
int libusb20_dev_get_fd(struct libusb20_device *pdev);
diff --git a/lib/libusb/libusb20_int.h b/lib/libusb/libusb20_int.h
index 4b0cef442c36..b9d614ffd8ff 100644
--- a/lib/libusb/libusb20_int.h
+++ b/lib/libusb/libusb20_int.h
@@ -92,6 +92,7 @@ typedef void (libusb20_dummy_void_t)(void);
/* USB device specific */
typedef int (libusb20_detach_kernel_driver_t)(struct libusb20_device *pdev, uint8_t iface_index);
+typedef int (libusb20_attach_kernel_driver_t)(struct libusb20_device *pdev, uint8_t iface_index);
typedef int (libusb20_do_request_sync_t)(struct libusb20_device *pdev, struct LIBUSB20_CONTROL_SETUP_DECODED *setup, void *data, uint16_t *pactlen, uint32_t timeout, uint8_t flags);
typedef int (libusb20_get_config_desc_full_t)(struct libusb20_device *pdev, uint8_t **ppbuf, uint16_t *plen, uint8_t index);
typedef int (libusb20_get_config_index_t)(struct libusb20_device *pdev, uint8_t *pindex);
@@ -116,6 +117,7 @@ typedef void (libusb20_tr_cancel_async_t)(struct libusb20_transfer *xfer);
#define LIBUSB20_DEVICE(m,n) \
m(n, detach_kernel_driver) \
+ m(n, attach_kernel_driver) \
m(n, do_request_sync) \
m(n, get_config_desc_full) \
m(n, get_config_index) \
diff --git a/lib/libusb/libusb20_ugen20.c b/lib/libusb/libusb20_ugen20.c
index 11064d2644d6..6c838814a45d 100644
--- a/lib/libusb/libusb20_ugen20.c
+++ b/lib/libusb/libusb20_ugen20.c
@@ -82,6 +82,7 @@ static libusb20_get_power_usage_t ugen20_get_power_usage;
static libusb20_get_stats_t ugen20_get_stats;
static libusb20_kernel_driver_active_t ugen20_kernel_driver_active;
static libusb20_detach_kernel_driver_t ugen20_detach_kernel_driver;
+static libusb20_attach_kernel_driver_t ugen20_attach_kernel_driver;
static libusb20_do_request_sync_t ugen20_do_request_sync;
static libusb20_process_t ugen20_process;
@@ -717,6 +718,17 @@ ugen20_detach_kernel_driver(struct libusb20_device *pdev,
}
static int
+ugen20_attach_kernel_driver(struct libusb20_device *pdev, uint8_t iface_index)
+{
+ int temp = iface_index;
+
+ if (ioctl(pdev->file_ctrl, IOUSB(USB_IFACE_DRIVER_ATTACH), &temp)) {
+ return (LIBUSB20_ERROR_OTHER);
+ }
+ return (0); /* kernel driver is attached */
+}
+
+static int
ugen20_do_request_sync(struct libusb20_device *pdev,
struct LIBUSB20_CONTROL_SETUP_DECODED *setup,
void *data, uint16_t *pactlen, uint32_t timeout, uint8_t flags)
diff --git a/lib/libusb/usb.h b/lib/libusb/usb.h
index ab225060c55e..fd77a9077fa8 100644
--- a/lib/libusb/usb.h
+++ b/lib/libusb/usb.h
@@ -303,6 +303,7 @@ struct usb_device *usb_device(usb_dev_handle * dev);
struct usb_bus *usb_get_busses(void);
int usb_get_driver_np(usb_dev_handle * dev, int interface, char *name, int namelen);
int usb_detach_kernel_driver_np(usb_dev_handle * dev, int interface);
+int usb_attach_kernel_driver_np(usb_dev_handle *dev, int interface);
#if 0
{ /* style */