diff --git a/backend/Makefile.in b/backend/Makefile.in index b286f47e8..6748e59a0 100644 --- a/backend/Makefile.in +++ b/backend/Makefile.in @@ -260,6 +260,7 @@ libsane-sm3600.la: ../sanei/sanei_constrain_value.lo libsane-snapscan.la: ../sanei/sanei_config2.lo libsane-snapscan.la: ../sanei/sanei_constrain_value.lo libsane-snapscan.la: ../sanei/sanei_scsi.lo +libsane-snapscan.la: ../sanei/sanei_usb.lo libsane-sp15c.la: ../sanei/sanei_config2.lo libsane-sp15c.la: ../sanei/sanei_constrain_value.lo libsane-sp15c.la: ../sanei/sanei_scsi.lo diff --git a/backend/snapscan-usb.c b/backend/snapscan-usb.c index eca1e3b36..df2440866 100644 --- a/backend/snapscan-usb.c +++ b/backend/snapscan-usb.c @@ -125,12 +125,26 @@ static SANE_Status atomic_usb_cmd(int fd, const void *src, size_t src_size, static SANE_Status snapscani_usb_open(const char *dev, int *fdp) { - return usb_open(dev,fdp); + static const char me[] = "snapscani_usb_open"; + + DBG (DL_CALL_TRACE, "%s(%s)\n", me, dev); + + if((sem_id = semget( ftok(dev,0x1234), 1, IPC_CREAT | 0660 )) == -1) { + DBG (DL_MAJOR_ERROR, "%s: Can't get semaphore\n", me); + return SANE_STATUS_INVAL; + } + semop(sem_id, &sem_signal, 1); + sanei_usb_init(); + return sanei_usb_open(dev, fdp); } static void snapscani_usb_close(int fd) { - usb_close(fd); + static const char me[] = "snapscani_usb_close"; + + DBG (DL_CALL_TRACE, "%s(%d)\n", me, fd); + semctl(sem_id, 0, IPC_RMID, 0); + sanei_usb_close(fd); } @@ -170,33 +184,6 @@ static char *usb_debug_data(char *str,const char *data, int len) { return str; } - -static SANE_Status usb_open(const char *dev, int *fdp) -{ -static const char me[] = "usb_open"; - -DBG (DL_CALL_TRACE, "%s(%s)\n", me, dev); - - if((sem_id = semget( ftok(dev,0x1234), 1, IPC_CREAT | 0660 )) == -1) { - DBG (DL_MAJOR_ERROR, "%s: Can't get semaphore\n", me); - return SANE_STATUS_INVAL; - } - semop(sem_id, &sem_signal, 1); - - *fdp = open(dev, O_RDWR); - if( *fdp < 0) - return SANE_STATUS_INVAL; - return SANE_STATUS_GOOD; -} - -static void usb_close(int fd) { - static const char me[] = "usb_close"; - - DBG (DL_CALL_TRACE, "%s(%d)\n", me, fd); - semctl(sem_id, 0, IPC_RMID, 0); - close(fd); -} - /* static int usb_status(char *status_buf) { int status; @@ -419,6 +406,9 @@ static void dequeue_bq() } /* * $Log$ + * Revision 1.4 2001/10/27 09:08:13 oliverschwartz + * Check USB vendor IDs to avoid hanging scanners, fix bug in dither matrix computation + * * Revision 1.3 2001/10/10 07:30:06 oliverschwartz * fix compiler warnings * diff --git a/backend/snapscan-usb.h b/backend/snapscan-usb.h index 3a77f95de..af56a237a 100644 --- a/backend/snapscan-usb.h +++ b/backend/snapscan-usb.h @@ -75,10 +75,6 @@ static int is_queueable(const char *src); static SANE_Status atomic_usb_cmd(int fd, const void *src, size_t src_size, void *dst, size_t * dst_size); -static SANE_Status usb_open(const char *dev, int *fdp); - -static void usb_close(int fd); - static SANE_Status usb_cmd(int fd, const void *src, size_t src_size, void *dst, size_t * dst_size); @@ -86,6 +82,9 @@ static SANE_Status usb_cmd(int fd, const void *src, size_t src_size, /* * $Log$ + * Revision 1.3 2001/10/27 09:08:14 oliverschwartz + * Check USB vendor IDs to avoid hanging scanners, fix bug in dither matrix computation + * * Revision 1.2 2001/10/09 09:45:15 oliverschwartz * update snapscan to snapshot 20011008 * diff --git a/backend/snapscan.c b/backend/snapscan.c index 17c51c4c4..3c78f503b 100644 --- a/backend/snapscan.c +++ b/backend/snapscan.c @@ -70,6 +70,7 @@ #include "../include/sane/sane.h" #include "../include/sane/sanei.h" #include "../include/sane/sanei_scsi.h" +#include "../include/sane/sanei_usb.h" #ifndef PATH_MAX #define PATH_MAX 1024 @@ -941,8 +942,15 @@ static void mkDn (u_char *Dn, u_char *Dn2, unsigned n) unsigned f; /* compute 4*D(n/2) */ + /* Oliver Schwartz, 27 Oct. 2001: Changed code from + tmp[i] = (u_char) (4 * Dn2[i]); + to + tmp[i] = (u_char) (4 * Dn2[i/4]); + to avoid illegal indices in Dn2. Don't know if this + is the desired algorithm. + */ for (i = 0; i < nsq; i++) - tmp[i] = (u_char) (4 * Dn2[i]); + tmp[i] = (u_char) (4 * Dn2[i/4]); /* now the dither matrix */ for (r = 0, imin = 0, f = 0; r < 2; r++, imin += n2) @@ -993,8 +1001,10 @@ static SANE_Status add_device (SANE_String_Const name) SnapScan_Device *pd; SnapScan_Model model_num = UNKNOWN; SnapScan_Bus bus_type = UNKNOWN_BUS; + SANE_Word vendor_id, product_id; int i; int supported_vendor = 0; + int supported_usb_vendor = 0; char vendor[8]; char model[17]; @@ -1007,7 +1017,7 @@ static SANE_Status add_device (SANE_String_Const name) vendor[0] = model[0] = '\0'; if((strstr (name, "usb")) || (strstr (name, "USB"))) - { + { DBG (DL_VERBOSE, "%s: Detected (kind of) an USB device\n", me); bus_type = USB; @@ -1018,31 +1028,52 @@ static SANE_Status add_device (SANE_String_Const name) } status = snapscani_usb_open (name, &fd); if (status != SANE_STATUS_GOOD) - { + { DBG (DL_MAJOR_ERROR, "%s: error opening device %s: %s\n", me, name, sane_strstatus (status)); return status; - } - } + } + if (sanei_usb_get_vendor_product(fd, &vendor_id, &product_id) == + SANE_STATUS_GOOD) + { + /* check for known USB vendors to avoid hanging scanners by + inquiry-command. + */ + DBG(DL_INFO, "%s: Checking if 0x%04x is a supported USB vendor ID\n", + me, vendor_id); + for (i = 0; i < known_usb_vendor_ids; i++) { + if (vendor_id == usb_vendor_ids[i]) { + supported_usb_vendor = 1; + } + } + if (!supported_usb_vendor) { + DBG(DL_MINOR_ERROR, + "%s: USB vendor ID 0x%04x is currently NOT supported by the snapscan backend.\n", + me, vendor_id); + snapscani_usb_close (fd); + return SANE_STATUS_INVAL; + } + } + } else - { + { DBG (DL_VERBOSE, "%s: Detected (kind of) a SCSI device\n", me); bus_type = SCSI; status = sanei_scsi_open (name, &fd, sense_handler, NULL); if (status != SANE_STATUS_GOOD) - { + { DBG (DL_MAJOR_ERROR, "%s: error opening device %s: %s\n", me, name, sane_strstatus (status)); return status; - } - } + } + } /* check that the device is legitimate */ if ((status = mini_inquiry (bus_type, fd, vendor, model)) != SANE_STATUS_GOOD) @@ -1053,13 +1084,13 @@ static SANE_Status add_device (SANE_String_Const name) sane_strstatus (status)); if(bus_type == SCSI) - { + { sanei_scsi_close (fd); - } + } else if(bus_type == USB) - { + { snapscani_usb_close (fd); - } + } return status; } @@ -3092,6 +3123,9 @@ SANE_Status sane_get_select_fd (SANE_Handle h, SANE_Int * fd) /* * $Log$ + * Revision 1.10 2001/10/27 09:08:14 oliverschwartz + * Check USB vendor IDs to avoid hanging scanners, fix bug in dither matrix computation + * * Revision 1.9 2001/10/25 10:56:39 oliverschwartz * Change snapscan backend version number to 1.4.0 * diff --git a/backend/snapscan.h b/backend/snapscan.h index d9120bef7..55c381c15 100644 --- a/backend/snapscan.h +++ b/backend/snapscan.h @@ -142,6 +142,15 @@ static char *vendors[] = }; #define known_vendors ((int) (sizeof(vendors)/sizeof(vendors[0]))) +static SANE_Word usb_vendor_ids[] = +{ + /* USB Vendor IDs */ + 0x06bd, /* Agfa */ + 0x04a5 /* Acer */ +}; +#define known_usb_vendor_ids ((int) (sizeof(usb_vendor_ids)/sizeof(usb_vendor_ids[0]))) + + typedef enum { OPT_COUNT = 0, /* option count */ @@ -312,6 +321,9 @@ struct snapscan_scanner /* * $Log$ + * Revision 1.7 2001/10/27 09:08:17 oliverschwartz + * Check USB vendor IDs to avoid hanging scanners, fix bug in dither matrix computation + * * Revision 1.6 2001/10/12 21:19:16 oliverschwartz * update to snapscan-20011012 *