Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Mar 2002 21:03:43 +0100
From:      Anders Nordby <anders@fix.no>
To:        dominic_marks@btinternet.com, current@freebsd.org, stable@freebsd.org
Cc:        n_hibma@freebsd.org
Subject:   How to make USB scanners work in FreeBSD (well at least Agfa ones..)
Message-ID:  <20020324200343.GA24999@totem.fix.no>

next in thread | raw e-mail | index | archive | help

--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,

Attached are patches that makes scanning work with sane, using an Agfa
Snapscan 1212U USB scanner for me. They are merely reworked from PRs
32652 and 32653 by ebakke@trolltech.com.

NB: Only tested in 4.5-stable, not in -current (sorry). Patches should
apply cleanly in -stable.

It would be nice if more people could have a look at this, so that we
can get hopefully get it in the tree sometime soon.

Thanks.

-- 
Anders.

--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="mypatch-usb.h"

--- sys/dev/usb/usb.h.orig	Tue Oct 31 23:59:35 2000
+++ sys/dev/usb/usb.h	Wed Feb 20 01:52:35 2002
@@ -566,4 +566,7 @@
 #define USB_GET_CM_OVER_DATA	_IOR ('U', 130, int)
 #define USB_SET_CM_OVER_DATA	_IOW ('U', 131, int)
 
+/* Scanner device */
+#define USB_GET_DEVICE_ID	_IOR('U', 140, int)
+
 #endif /* _USB_H_ */

--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="mypatch-uscanner.c_v2"

--- sys/dev/usb/uscanner.c.orig	Thu Feb 14 03:52:50 2002
+++ sys/dev/usb/uscanner.c	Sun Feb 24 00:46:11 2002
@@ -222,6 +222,8 @@
 
 	int			sc_refcnt;
 	u_char			sc_dying;
+	u_int16_t		sc_vendor_id;
+	u_int16_t		sc_product_id;
 };
 
 #if defined(__NetBSD__) || defined(__OpenBSD__)
@@ -233,7 +235,7 @@
 d_write_t uscannerwrite;
 d_ioctl_t uscannerioctl;
 d_poll_t  uscannerpoll;
-
+d_ioctl_t uscannerioctl;
 #define USCANNER_CDEV_MAJOR	156
 
 Static struct cdevsw uscanner_cdevsw = {
@@ -289,6 +291,8 @@
 	sc->sc_dev_flags = uscanner_lookup(uaa->vendor, uaa->product)->flags;
 
 	sc->sc_udev = uaa->device;
+	sc->sc_vendor_id = uaa->vendor;
+	sc->sc_product_id = uaa->product;
 
 	err = usbd_set_config_no(uaa->device, 1, 1); /* XXX */
 	if (err) {
@@ -360,9 +364,10 @@
 
 	USB_GET_SC_OPEN(uscanner, unit, sc);
 
- 	DPRINTFN(5, ("uscanneropen: flag=%d, mode=%d, unit=%d\n", 
+ 	DPRINTFN(5, ("uscanneropen: flag=%d, mode=%d, unit=%d\n",
 		     flag, mode, unit));
 
+	printf( "uscanneropen()\n" );
 	if (sc->sc_dying)
 		return (ENXIO);
 
@@ -696,9 +701,25 @@
 int
 uscannerioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
 {
-	return (EINVAL);
+	struct uscanner_softc* sc;
+
+	USB_GET_SC( uscanner, USCANNERUNIT( dev ), sc );
+
+	if( sc->sc_dying )
+		return( EIO );
+
+	switch( cmd ) {
+	case USB_GET_DEVICE_ID:
+		*(u_int32_t*)addr = ( sc->sc_vendor_id << 16 ) | sc->sc_product_id;
+		break;
+	default:
+		return EINVAL;
+	}
+	return 0;
 }
 
 #if defined(__FreeBSD__)
 DRIVER_MODULE(uscanner, uhub, uscanner_driver, uscanner_devclass, usbd_driver_load, 0);
 #endif
+
+

--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=mypatch-sane-backends

diff -Nur sane-backends.old/files/patch-backend_snapscan.c sane-backends/files/patch-backend_snapscan.c
--- sane-backends.old/files/patch-backend_snapscan.c	Thu Jan  1 00:00:00 1970
+++ sane-backends/files/patch-backend_snapscan.c	Tue Mar  5 23:49:15 2002
@@ -0,0 +1,19 @@
+--- backend/snapscan.c.bak	Sun Dec  9 22:51:01 2001
++++ backend/snapscan.c	Sun Dec  9 22:51:01 2001
+@@ -1016,7 +1016,11 @@
+ 
+     vendor[0] = model[0] = '\0';
+ 
++#if defined( __FreeBSD__ )
++    if(strstr (name, "uscanner"))
++#else /* __FreeBSD__ */
+     if((strstr (name, "usb")) || (strstr (name, "USB")))
++#endif /* __FreeBSD__ */
+     {
+         DBG (DL_VERBOSE, "%s: Detected (kind of) an USB device\n", me);
+ 
+@@ -3540,3 +3544,4 @@
+  * Revision 1.1  1997/10/13  02:25:54  charter
+  * Initial revision
+  * */
++
diff -Nur sane-backends.old/files/patch-sanei_sanei_usb.c sane-backends/files/patch-sanei_sanei_usb.c
--- sane-backends.old/files/patch-sanei_sanei_usb.c	Thu Jan  1 00:00:00 1970
+++ sane-backends/files/patch-sanei_sanei_usb.c	Tue Mar  5 23:49:22 2002
@@ -0,0 +1,42 @@
+--- sanei/sanei_usb.c.bak	Sun Dec  9 22:40:14 2001
++++ sanei/sanei_usb.c	Sun Dec  9 22:49:04 2001
+@@ -112,6 +112,9 @@
+ 			      SANE_Word * product)
+ {
+   SANE_Word vendorID, productID;
++#if defined( __FreeBSD__ )
++  u_int32_t vendorproductID;
++#endif /* __FreeBSD__ */
+ 
+ #if defined (__linux__)
+ #define IOCTL_SCANNER_VENDOR _IOR('U', 0x20, int)
+@@ -145,8 +148,24 @@
+   if (product)
+     *product = productID;
+ #else /* not defined (__linux__) */
++#if defined( __FreeBSD__ )
++#define USB_GET_DEVICE_ID _IOR('U', 140, int)
++  /* read the vendo and product IDs via the IOCTLs */
++  if( ioctl( fd, USB_GET_DEVICE_ID, &vendorproductID ) == -1 )
++  {
++    DBG( 3, "sanei_usb_get_vendor_product: ioctl( productid ) of fd %d "
++            "failed: %s\n", fd, strerror( errno ) );
++  }
++  productID = vendorproductID & 0xffff;
++  vendorID = ( vendorproductID >> 16 ) & 0xffff;
++  if( vendor )
++    *vendor = vendorID;
++  if( product )
++    *product = productID;
++#else /* __FreeBSD__ */
+   vendorID = 0;
+   productID = 0;
++#endif /* __FreeBSD__ */
+ #endif /* not defined (__linux__) */
+ 
+   if (!vendorID || !productID)
+@@ -309,3 +328,4 @@
+   *size = write_size;
+   return SANE_STATUS_GOOD;
+ }
++

--2fHTh5uZTiUOsy+g--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020324200343.GA24999>