[sane-devel] USB problems with SANE on MacOS

Oliver Schwartz Oliver.Schwartz at gmx.de
Fri Apr 26 18:56:21 BST 2019


Hi all,

I dived into scanning with SANE on MacOS using homebrew in the last few days.

Back in 2017 two problems were reported ( https://alioth-lists.debian.net/pipermail/sane-devel/2017-July/035508.html ) : The first one, old dependencies on libusb-compat was resolved in homebrew. The second one, sanei_usb barking at unconfigured devices, was not addressed as far as I can see and in fact the same problem bit me when using the snapscan backend.

I did some googling and found this remark from the libusb-devel mailing list: ( https://sourceforge.net/p/libusb/mailman/message/27491908/ )

> … OS X won't 
> automatically configure a device if its descriptors are 
> vendor-specific (meaning that the device must be configured through 
> libusb).  But Linux will.

Looking at the code in sanei_usb.c, libusb_scan_devices() ignores devices that are not configured. sanei_usb_open() returns SANE_STATUS_INVAL when the device is not configured. If it is configured, it is actually configured again.

I made a crude patch that just continues execution for non-configured devices (this is against sane-backends-1.0.27):

diff --git a/sanei/sanei_usb.c b/sanei/sanei_usb.c
index e4b23dc..294c64b 100644
--- a/sanei/sanei_usb.c
+++ b/sanei/sanei_usb.c
@@ -936,7 +936,7 @@ static void libusb_scan_devices(void)
 	  DBG (1,
 	       "%s: device 0x%04x/0x%04x at %03d:%03d is not configured\n", __func__,
 	       vid, pid, busno, address);
-	  continue;
+	  /* continue; */
 	}
 
       ret = libusb_get_config_descriptor (dev, 0, &config0);
@@ -1640,7 +1640,7 @@ sanei_usb_open (SANE_String_Const devname, SANE_Int * dn)
       if (config == 0)
 	{
 	  DBG (1, "sanei_usb_open: device `%s' not configured?\n", devname);
-	  return SANE_STATUS_INVAL;
+	  /*return SANE_STATUS_INVAL; */
 	}
 
       result = libusb_get_device_descriptor (dev, &desc);


This works for me and I can now use scanimage on MacOS with my scanner. However, this is hardly the final solution. Can someone with more knowledge on USB comment on this? Is the check for non-configured devices really useful when the device is actually configured later? Should this check only be removed on MacOS? Are there any side effects to be expected?

Kind regards,

Oliver




More information about the sane-devel mailing list