diff options
author | hselasky <hselasky@FreeBSD.org> | 2016-06-16 14:26:04 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2016-06-16 14:26:04 +0000 |
commit | b6f02274aa36f1ea0540239debc17bd9bd331fc4 (patch) | |
tree | 4d526c30986644cb58497ef2990bd8713ab7da91 /lib/libusb/libusb10.c | |
parent | be411a556e8b17aad2f64a249f5bcc1203537077 (diff) | |
download | FreeBSD-src-b6f02274aa36f1ea0540239debc17bd9bd331fc4.zip FreeBSD-src-b6f02274aa36f1ea0540239debc17bd9bd331fc4.tar.gz |
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
Diffstat (limited to 'lib/libusb/libusb10.c')
-rw-r--r-- | lib/libusb/libusb10.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 1f64252..7e1d9b6 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -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_device *pdev, int interface_number) 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_device *pdev, int interface_number) 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 libusb20_device *pdev, int interface) 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 * |