core: Make the 'reset_device' function of the backend optional
authorChris Dickens <christopher.a.dickens@gmail.com>
Mon, 16 Mar 2020 08:15:29 +0000 (01:15 -0700)
committerChris Dickens <christopher.a.dickens@gmail.com>
Mon, 16 Mar 2020 08:15:29 +0000 (01:15 -0700)
The majority of backends do not have support for resetting a device, so
simplify them all by making the function optional and having the core
return the appropriate error when the function is not implemented.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/core.c
libusb/libusbi.h
libusb/os/haiku_usb_raw.cpp
libusb/os/netbsd_usb.c
libusb/os/null_usb.c
libusb/os/openbsd_usb.c
libusb/os/sunos_usb.c
libusb/version_nano.h

index 7ffec1f..e7f8d5e 100644 (file)
@@ -1835,7 +1835,10 @@ int API_EXPORTED libusb_reset_device(libusb_device_handle *dev_handle)
        if (!dev_handle->dev->attached)
                return LIBUSB_ERROR_NO_DEVICE;
 
-       return usbi_backend.reset_device(dev_handle);
+       if (usbi_backend.reset_device)
+               return usbi_backend.reset_device(dev_handle);
+       else
+               return LIBUSB_ERROR_NOT_SUPPORTED;
 }
 
 /** \ingroup libusb_asyncio
index 1fdfc84..a9f904e 100644 (file)
@@ -984,7 +984,7 @@ struct usbi_os_backend {
        int (*clear_halt)(struct libusb_device_handle *dev_handle,
                unsigned char endpoint);
 
-       /* Perform a USB port reset to reinitialize a device.
+       /* Perform a USB port reset to reinitialize a device. Optional.
         *
         * If possible, the device handle should still be usable after the reset
         * completes, assuming that the device descriptors did not change during
index 63efc17..7c0c4db 100644 (file)
@@ -136,13 +136,6 @@ haiku_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint
 }
 
 static int
-haiku_reset_device(struct libusb_device_handle *dev_handle)
-{
-       /* TODO */
-       return LIBUSB_ERROR_NOT_SUPPORTED;
-}
-
-static int
 haiku_release_interface(struct libusb_device_handle *dev_handle, int interface_number)
 {
        USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
@@ -212,7 +205,6 @@ const struct usbi_os_backend usbi_backend = {
 
        .set_interface_altsetting = haiku_set_altsetting,
        .clear_halt = haiku_clear_halt,
-       .reset_device = haiku_reset_device,
 
        .submit_transfer = haiku_submit_transfer,
        .cancel_transfer = haiku_cancel_transfer,
index 66ff887..41f003f 100644 (file)
@@ -68,7 +68,6 @@ static int netbsd_release_interface(struct libusb_device_handle *, int);
 static int netbsd_set_interface_altsetting(struct libusb_device_handle *, int,
     int);
 static int netbsd_clear_halt(struct libusb_device_handle *, unsigned char);
-static int netbsd_reset_device(struct libusb_device_handle *);
 static void netbsd_destroy_device(struct libusb_device *);
 
 static int netbsd_submit_transfer(struct usbi_transfer *);
@@ -103,7 +102,6 @@ const struct usbi_os_backend usbi_backend = {
 
        .set_interface_altsetting = netbsd_set_interface_altsetting,
        .clear_halt = netbsd_clear_halt,
-       .reset_device = netbsd_reset_device,
 
        .destroy_device = netbsd_destroy_device,
 
@@ -387,14 +385,6 @@ netbsd_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
        return (LIBUSB_SUCCESS);
 }
 
-int
-netbsd_reset_device(struct libusb_device_handle *handle)
-{
-       usbi_dbg(" ");
-
-       return (LIBUSB_ERROR_NOT_SUPPORTED);
-}
-
 void
 netbsd_destroy_device(struct libusb_device *dev)
 {
index 03c33e1..7893b0c 100644 (file)
@@ -89,12 +89,6 @@ null_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
 }
 
 static int
-null_reset_device(struct libusb_device_handle *handle)
-{
-       return LIBUSB_ERROR_NOT_SUPPORTED;
-}
-
-static int
 null_submit_transfer(struct usbi_transfer *itransfer)
 {
        return LIBUSB_ERROR_NOT_SUPPORTED;
@@ -120,7 +114,6 @@ const struct usbi_os_backend usbi_backend = {
        .release_interface = null_release_interface,
        .set_interface_altsetting = null_set_interface_altsetting,
        .clear_halt = null_clear_halt,
-       .reset_device = null_reset_device,
        .submit_transfer = null_submit_transfer,
        .cancel_transfer = null_cancel_transfer,
 };
index 430023a..1080026 100644 (file)
@@ -68,7 +68,6 @@ static int obsd_release_interface(struct libusb_device_handle *, int);
 static int obsd_set_interface_altsetting(struct libusb_device_handle *, int,
     int);
 static int obsd_clear_halt(struct libusb_device_handle *, unsigned char);
-static int obsd_reset_device(struct libusb_device_handle *);
 static void obsd_destroy_device(struct libusb_device *);
 
 static int obsd_submit_transfer(struct usbi_transfer *);
@@ -105,7 +104,6 @@ const struct usbi_os_backend usbi_backend = {
 
        .set_interface_altsetting = obsd_set_interface_altsetting,
        .clear_halt = obsd_clear_halt,
-       .reset_device = obsd_reset_device,
        .destroy_device = obsd_destroy_device,
 
        .submit_transfer = obsd_submit_transfer,
@@ -425,14 +423,6 @@ obsd_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
        return (LIBUSB_SUCCESS);
 }
 
-int
-obsd_reset_device(struct libusb_device_handle *handle)
-{
-       usbi_dbg(" ");
-
-       return (LIBUSB_ERROR_NOT_SUPPORTED);
-}
-
 void
 obsd_destroy_device(struct libusb_device *dev)
 {
index cd32f8b..bc66859 100644 (file)
@@ -75,7 +75,6 @@ static int sunos_release_interface(struct libusb_device_handle *, int);
 static int sunos_set_interface_altsetting(struct libusb_device_handle *,
     int, int);
 static int sunos_clear_halt(struct libusb_device_handle *, uint8_t);
-static int sunos_reset_device(struct libusb_device_handle *);
 static void sunos_destroy_device(struct libusb_device *);
 static int sunos_submit_transfer(struct usbi_transfer *);
 static int sunos_cancel_transfer(struct usbi_transfer *);
@@ -1385,14 +1384,6 @@ sunos_clear_halt(struct libusb_device_handle *handle, uint8_t endpoint)
        return (ret);
 }
 
-int
-sunos_reset_device(struct libusb_device_handle *handle)
-{
-       usbi_dbg(" ");
-
-       return (LIBUSB_ERROR_NOT_SUPPORTED);
-}
-
 void
 sunos_destroy_device(struct libusb_device *dev)
 {
@@ -1632,7 +1623,6 @@ const struct usbi_os_backend usbi_backend = {
         .release_interface = sunos_release_interface,
         .set_interface_altsetting = sunos_set_interface_altsetting,
         .clear_halt = sunos_clear_halt,
-        .reset_device = sunos_reset_device, /* TODO */
         .kernel_driver_active = sunos_kernel_driver_active,
         .detach_kernel_driver = sunos_detach_kernel_driver,
         .attach_kernel_driver = sunos_attach_kernel_driver,
index 626497e..4528bbf 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11466
+#define LIBUSB_NANO 11467