Only if old backend api is UNSUPPORTED.

This happens when a libusb driver (e.g. WinUSB) is installed
after a device has been setup/discovered (with get_device_list).

---

We want to install libusb driver for USB devices dynamically following a
request by users. There is a problem however to access such devices
after libusb driver is installed as the backend api is UNSUPPORTED.

With this patch, after the WinUSB libusb driver has been installed, an 
application
only needs to call libusb_get_device_list again such that it can
access the device.


Is there a better way to change the backend api for a specific libusb device,
after WinUsb driver has been installed for that device ?


 libusb/os/windows_usb.c |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index 1957964..3038625 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -1432,12 +1432,30 @@ static int windows_get_device_list(struct 
libusb_context *ctx, struct discovered
                                break;
                        case HUB_PASS:
                        case DEV_PASS:
+                               // If the api was UNSUPPORTED and it has 
changed, use the new api
+                               // This happens when a libusb driver is 
installed after
+                               // an earlier libusb_get_devices() call
+                               if ((priv->path == NULL) || /* first time setup 
*/
+                                   ((priv->apib != &usb_api_backend[api]) && 
/* new driver */
+                                    (priv->apib->id == USB_API_UNSUPPORTED))) {
+                                       priv->apib = &usb_api_backend[api];
+                                       usbi_dbg("setting priv->apib to 
%d(%d-->%s)",
+                                               api, priv->apib->id, 
priv->apib->designation);
+
+                                       if ((api != USB_API_COMPOSITE) && (api 
!= USB_API_HUB)) {
+                                               // The following is needed if 
we want API calls to work for both simple
+                                               // and composite devices.
+                                               for(j=0; j<USB_MAXINTERFACES; 
j++) {
+                                                       
priv->usb_interface[j].apib = &usb_api_backend[api];
+                                               }
+                                       }
+                               }
+
                                // If the device has already been setup, don't 
do it again
                                if (priv->path != NULL)
                                        break;
                                // Take care of API initialization
                                priv->path = dev_interface_path; 
dev_interface_path = NULL;
-                               priv->apib = &usb_api_backend[api];
                                switch(api) {
                                case USB_API_COMPOSITE:
                                case USB_API_HUB:
@@ -1450,11 +1468,6 @@ static int windows_get_device_list(struct libusb_context 
*ctx, struct discovered
                                        } else {
                                                usbi_warn(ctx, "could not 
duplicate interface path '%s'", priv->path);
                                        }
-                                       // The following is needed if we want 
API calls to work for both simple
-                                       // and composite devices.
-                                       for(j=0; j<USB_MAXINTERFACES; j++) {
-                                               priv->usb_interface[j].apib = 
&usb_api_backend[api];
-                                       }
                                        break;
                                }
                                break;
-- 
1.7.7.6


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to