summaryrefslogtreecommitdiff
blob: 52909c42b1f5c481778e06128653d9b838045a63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
--- backend/sm3600.c	3 Jul 2005 13:35:48 -0000	1.13
+++ backend/sm3600.c	16 Aug 2005 19:50:34 -0000	1.14
@@ -55,24 +55,25 @@
 
 ====================================================================== */
 
-#include "sane/config.h"
+#include "../include/sane/config.h"
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 
-#include <usb.h>
-
-#define BUILD	5
+#define BUILD	6
 
 #ifndef BACKEND_NAME
 #define BACKEND_NAME sm3600
 #endif
 
-#include "sane/sane.h"
-#include "sane/sanei.h"
-#include "sane/sanei_backend.h"
-#include "sane/sanei_config.h"
-#include "sane/saneopts.h"
+#include "../include/sane/sane.h"
+#include "../include/sane/sanei.h"
+#include "../include/sane/sanei_backend.h"
+#include "../include/sane/sanei_config.h"
+#include "../include/sane/saneopts.h"
+#include "../include/sane/sanei_usb.h"
+
+#undef HAVE_LIBUSB
 
 /* prevent inclusion of scantool.h */
 #define SCANTOOL_H
@@ -326,7 +327,8 @@
 }
 
 static SANE_Status
-RegisterSaneDev (struct usb_device *pdevUSB, TModel model, char *szName){
+RegisterSaneDev (TModel model, SANE_String_Const szName)
+{
   TDevice * q;
 
   errno = 0;
@@ -342,7 +344,6 @@
   q->sane.model  = "ScanMaker 3600";
   q->sane.type   = "flatbed scanner";
 
-  q->pdev=pdevUSB;
   q->model=model;
 
   ++num_devices;
@@ -351,13 +352,37 @@
 
   return SANE_STATUS_GOOD;
 }
+ 
+static SANE_Status 
+sm_usb_attach (SANE_String_Const dev_name)
+{
+  int fd;
+  SANE_Status err;
+  SANE_Word v, p;
+  TModel model;
+
+  err = sanei_usb_open(dev_name, &fd);
+  if (err)
+    return err;
+  err = sanei_usb_get_vendor_product (fd, &v, &p);
+  if (err)
+    {
+      sanei_usb_close (fd);
+      return err;
+    }
+  DBG (DEBUG_JUNK, "found dev %04X/%04X, %s\n", v, p, dev_name);
+  model = GetScannerModel (v, p);
+  if (model != unknown)
+    RegisterSaneDev (model, dev_name);
+
+  sanei_usb_close(fd);
+  return SANE_STATUS_GOOD;
+}
 
 SANE_Status
 sane_init (SANE_Int *version_code, SANE_Auth_Callback authCB)
 {
-  struct usb_bus    *pbus;
-  struct usb_device *pdev;
-  int                iBus;
+  int                i;
 
   DBG_INIT();
 
@@ -372,38 +397,11 @@
    }
 
   pdevFirst=NULL;
-
-  usb_init();
-  usb_find_busses();
-  if (!usb_busses)
-    return SANE_STATUS_IO_ERROR;
-
-  usb_find_devices();
-
-  iBus=0;
-  DBG(DEBUG_INFO,"starting bus scan\n");
-  for (pbus = usb_busses; pbus; pbus = pbus->next)
-    {
-      int iDev=0;
-      iBus++;
-      /* 0.1.3b no longer has a "busnum" member */
-      DBG(DEBUG_JUNK,"scanning bus %s\n", pbus->dirname);
-      for (pdev=pbus->devices; pdev; pdev  = pdev->next)
-	{
-	  TModel model;
-	  iDev++;
-	  DBG(DEBUG_JUNK,"found dev %04X/%04X\n",
-		  pdev->descriptor.idVendor,
-		  pdev->descriptor.idProduct);
-	  model=GetScannerModel(pdev->descriptor.idVendor,
-				       pdev->descriptor.idProduct);
-	  if (model!=unknown)
-	    {
-	      char ach[100];
-	      sprintf(ach,"%d/%d",iBus,iDev);
-	      RegisterSaneDev(pdev,model,ach);
-	    }
-	}
+  
+  sanei_usb_init();
+  for (i = 0; aScanners[i].idProduct; i++) 
+    {
+      sanei_usb_find_devices(SCANNER_VENDOR, aScanners[i].idProduct, sm_usb_attach);
     }
   return SANE_STATUS_GOOD;
 }
@@ -464,8 +462,11 @@
   if (devicename[0]) /* selected */
     {
       for (pdev=pdevFirst; pdev; pdev=pdev->pNext)
+{
+DBG(DEBUG_VERBOSE,"%s<>%s\n",devicename, pdev->sane.name);
 	if (!strcmp(devicename,pdev->sane.name))
 	  break;
+}
       /* no dynamic post-registration */
     }
   else
@@ -482,14 +483,11 @@
   pinstFirst=this;
   this->model=pdev->model; /* memorize model */
   /* open and prepare USB scanner handle */
-  this->hScanner=usb_open(pdev->pdev);
-  if (!this->hScanner)
-    return SetError(this,SANE_STATUS_IO_ERROR, "cannot open scanner device");
-  rc=SANE_STATUS_GOOD;
-  if (usb_claim_interface(this->hScanner, 0))
-    return SetError(this,SANE_STATUS_IO_ERROR, "cannot claim IF");
-  if (usb_set_configuration(this->hScanner, 1))
-    return SetError(this,SANE_STATUS_IO_ERROR, "cannot set USB config 1");
+
+  if (sanei_usb_open (devicename, &this->hScanner) != SANE_STATUS_GOOD)
+    return SetError (this, SANE_STATUS_IO_ERROR, "cannot open scanner device");
+
+  rc = SANE_STATUS_GOOD;
 
   this->quality=fast;
   return InitOptions(this);
@@ -505,8 +503,9 @@
     {
       if (this->state.bScanning)
 	EndScan(this);
-      usb_close(this->hScanner);
-      this->hScanner=NULL;
+
+      sanei_usb_close(this->hScanner);
+      this->hScanner=-1;
     }
   ResetCalibration(this); /* release calibration data */
   /* unlink active device entry */
--- backend/sm3600.h	30 Apr 2004 21:02:04 -0000	1.10
+++ backend/sm3600.h	16 Aug 2005 19:50:34 -0000	1.11
@@ -190,7 +190,7 @@
   TQuality           quality;
   TMode              mode;
   TModel             model;
-  usb_dev_handle    *hScanner;
+  int                hScanner;
   FILE              *fhLog;
   FILE              *fhScan;
   int                ichPageBuffer; /* write position in full page buffer */
--- backend/sm3600-scanusb.c	15 Apr 2004 21:06:58 -0000	1.11
+++ backend/sm3600-scanusb.c	16 Aug 2005 19:50:34 -0000	1.12
@@ -43,7 +43,7 @@
 
 Userspace scan tool for the Microtek 3600 scanner
 
-$Id: sm3600-scanusb.c,v 1.11 2004/04/15 21:06:58 eichholz-guest Exp $
+$Id: sm3600-scanusb.c,v 1.12 2005/08/16 19:50:34 hmg-guest Exp $
 
 (C) Marian Eichholz 2001
 
@@ -68,14 +68,20 @@
 		       int  cchBuffer,
 		       int  cJiffiesTimeout)
 {
-  return usb_control_msg(this->hScanner,
+  SANE_Status err;
+
+  cJiffiesTimeout = cJiffiesTimeout;
+
+  err = sanei_usb_control_msg (this->hScanner,
 			 nReqType,
 			 nRequest,
 			 nValue,
 			 nIndex,
-			 pBuffer,
 			 cchBuffer,
-			 cJiffiesTimeout);
+			 pBuffer);
+  if (err)
+    return err;
+  return cchBuffer;
 }
 
 /* **********************************************************************
@@ -90,11 +96,18 @@
 	     int cchMax,
 	     int cJiffiesTimeout)
 {
-  return usb_bulk_read(this->hScanner,
-		       nEndPoint,
-		       pBuffer,
-		       cchMax,
-		       cJiffiesTimeout);
+  int err;
+  size_t sz = cchMax;
+
+  nEndPoint = nEndPoint;
+  cJiffiesTimeout = cJiffiesTimeout;
+
+  err = sanei_usb_read_bulk(this->hScanner,
+			    pBuffer,
+			    &sz);
+  if (err)
+    return err;
+  return sz;
 }
 
 /* **********************************************************************
@@ -310,7 +323,9 @@
 	{
 	  rc=SetError(this,SANE_STATUS_IO_ERROR,
 		      "bulk read of %d bytes failed: %s",
-		      cchChunk,usb_strerror());
+		      cchChunk,
+		      "I/O error"
+		      );
 	  continue;
 	}
     }
@@ -371,7 +386,9 @@
       else
 	rc=SetError(this,SANE_STATUS_IO_ERROR,
 		    "bulk read of %d bytes failed: %s",
-		    cchChunk,usb_strerror());
+		    cchChunk,
+		    "I/O error"
+		    );
     }
   dprintf(DEBUG_COMM,"writing %d bytes\n",cchRead);
   
--- backend/sm3600-scanutil.c	15 Apr 2004 21:06:58 -0000	1.11
+++ backend/sm3600-scanutil.c	16 Aug 2005 19:50:34 -0000	1.12
@@ -43,10 +43,11 @@
 
 Userspace scan tool for the Microtek 3600 scanner
 
-$Id: sm3600-scanutil.c,v 1.11 2004/04/15 21:06:58 eichholz-guest Exp $
+$Id: sm3600-scanutil.c,v 1.12 2005/08/16 19:50:34 hmg-guest Exp $
 
 ====================================================================== */
 
+#include <unistd.h>
 #include "sm3600-scantool.h"
 
 /* **********************************************************************