2000-12-31 19:35:04 +00:00
|
|
|
/* sane-find-scanner.c
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
Copyright (C) 1997-2002 Oliver Rauch, Henning Meier-Geinitz, and others.
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
|
|
|
MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
#include "../include/sane/config.h"
|
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
2002-06-25 18:41:57 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-07-12 20:50:54 +00:00
|
|
|
#ifdef HAVE_LIBUSB
|
|
|
|
#include "usb.h"
|
|
|
|
#endif
|
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
#include "../include/sane/sanei.h"
|
2001-05-13 18:44:13 +00:00
|
|
|
#include "../include/sane/sanei_scsi.h"
|
2001-08-11 13:23:01 +00:00
|
|
|
#include "../include/sane/sanei_usb.h"
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
#ifndef PATH_MAX
|
|
|
|
# define PATH_MAX 1024
|
|
|
|
#endif
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
static const char *prog_name;
|
2002-07-14 16:39:03 +00:00
|
|
|
static int verbose = 1;
|
|
|
|
static SANE_Bool force = SANE_FALSE;
|
2002-07-12 20:50:54 +00:00
|
|
|
static SANE_Bool device_found = SANE_FALSE;
|
2002-06-25 18:41:57 +00:00
|
|
|
static SANE_Bool unknown_found = SANE_FALSE;
|
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
typedef struct
|
2002-04-28 19:20:20 +00:00
|
|
|
{
|
|
|
|
unsigned char *cmd;
|
|
|
|
size_t size;
|
|
|
|
}
|
1999-08-09 18:06:01 +00:00
|
|
|
scsiblk;
|
|
|
|
|
|
|
|
#define INQUIRY 0x12
|
|
|
|
#define set_inquiry_return_size(icb,val) icb[0x04]=val
|
|
|
|
#define IN_periph_devtype_cpu 0x03
|
|
|
|
#define IN_periph_devtype_scanner 0x06
|
2002-06-25 18:41:57 +00:00
|
|
|
#define get_scsi_inquiry_vendor(in, buf) strncpy(buf, in + 0x08, 0x08)
|
|
|
|
#define get_scsi_inquiry_product(in, buf) strncpy(buf, in + 0x10, 0x010)
|
|
|
|
#define get_scsi_inquiry_version(in, buf) strncpy(buf, in + 0x20, 0x04)
|
|
|
|
#define get_scsi_inquiry_periph_devtype(in) (in[0] & 0x1f)
|
|
|
|
#define get_scsi_inquiry_additional_length(in) in[0x04]
|
|
|
|
#define set_scsi_inquiry_length(out,n) out[0x04]=n-5
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-04-28 19:20:20 +00:00
|
|
|
static unsigned char inquiryC[] = {
|
|
|
|
INQUIRY, 0x00, 0x00, 0x00, 0xff, 0x00
|
|
|
|
};
|
|
|
|
static scsiblk inquiry = {
|
|
|
|
inquiryC, sizeof (inquiryC)
|
|
|
|
};
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
usage (char *msg)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Usage: %s [-hv] [devname ...]\n", prog_name);
|
|
|
|
fprintf (stderr, "\t-h: print this help message\n");
|
2002-07-14 16:39:03 +00:00
|
|
|
fprintf (stderr, "\t-v: be more verbose (can be used multiple times)\n");
|
|
|
|
fprintf (stderr, "\t-q: be more quiet\n");
|
|
|
|
fprintf (stderr, "\t-f: force opening devname as SCSI even if it looks "
|
|
|
|
"like USB\n");
|
1999-08-09 18:06:01 +00:00
|
|
|
if (msg)
|
|
|
|
fprintf (stderr, "\t%s\n", msg);
|
|
|
|
}
|
|
|
|
|
2000-03-05 13:57:25 +00:00
|
|
|
/* if SCSI generic is optional on your OS, and there is a software test
|
|
|
|
which will determine if it is included, add it here. If you are sure
|
|
|
|
that SCSI generic was found, return 1. If SCSI generic is always
|
|
|
|
available in your OS, return 1 */
|
|
|
|
|
2001-05-14 07:18:25 +00:00
|
|
|
static int
|
2000-03-05 13:57:25 +00:00
|
|
|
check_sg (void)
|
|
|
|
{
|
|
|
|
#if defined(__linux__)
|
|
|
|
/* Assumption: /proc/devices lines are shorter than 256 characters */
|
2002-04-28 19:20:20 +00:00
|
|
|
char line[256], driver[256] = "";
|
2000-03-05 13:57:25 +00:00
|
|
|
FILE *stream;
|
|
|
|
|
2002-04-28 19:20:20 +00:00
|
|
|
stream = fopen ("/proc/devices", "r");
|
2000-03-05 13:57:25 +00:00
|
|
|
/* Likely reason for failure, no /proc => probably no SG either */
|
2002-04-28 19:20:20 +00:00
|
|
|
if (stream == NULL)
|
2000-03-05 13:57:25 +00:00
|
|
|
return 0;
|
2002-04-28 19:20:20 +00:00
|
|
|
|
|
|
|
while (fgets (line, sizeof (line) - 1, stream))
|
|
|
|
{
|
|
|
|
if (sscanf (line, " %*d %s\n", driver) > 0 && !strcmp (driver, "sg"))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fclose (stream);
|
|
|
|
|
|
|
|
if (strcmp (driver, "sg"))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2000-03-05 13:57:25 +00:00
|
|
|
#endif
|
2002-04-28 19:20:20 +00:00
|
|
|
return 1; /* Give up, and assume yes to avoid false negatives */
|
2000-03-05 13:57:25 +00:00
|
|
|
}
|
|
|
|
|
2002-04-28 19:33:49 +00:00
|
|
|
/* Display a buffer in the log. Display by lines of 16 bytes. */
|
2002-04-28 19:20:20 +00:00
|
|
|
static void
|
2002-04-28 19:33:49 +00:00
|
|
|
hexdump (const char *comment, unsigned char *buf, const int length)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char line[128];
|
|
|
|
char *ptr;
|
|
|
|
char asc_buf[17];
|
|
|
|
char *asc_ptr;
|
|
|
|
|
|
|
|
printf (" %s\n", comment);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
goto start;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (i < length)
|
|
|
|
{
|
|
|
|
ptr += sprintf (ptr, " %2.2x", *buf);
|
|
|
|
|
|
|
|
if (*buf >= 32 && *buf <= 127)
|
|
|
|
{
|
|
|
|
asc_ptr += sprintf (asc_ptr, "%c", *buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
asc_ptr += sprintf (asc_ptr, ".");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* After the length; do nothing. */
|
|
|
|
ptr += sprintf (ptr, " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
buf++;
|
|
|
|
|
|
|
|
if ((i % 16) == 0)
|
|
|
|
{
|
|
|
|
/* It's a new line */
|
|
|
|
printf (" %s %s\n", line, asc_buf);
|
|
|
|
|
|
|
|
start:
|
|
|
|
ptr = line;
|
|
|
|
*ptr = '\0';
|
|
|
|
asc_ptr = asc_buf;
|
|
|
|
*asc_ptr = '\0';
|
|
|
|
|
|
|
|
ptr += sprintf (ptr, " %3.3d:", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
while (i < ((length + 15) & ~15));
|
|
|
|
}
|
|
|
|
|
|
|
|
static SANE_Status
|
2002-06-25 18:41:57 +00:00
|
|
|
scanner_do_scsi_inquiry (unsigned char *buffer, int sfd)
|
1999-08-09 18:06:01 +00:00
|
|
|
{
|
|
|
|
size_t size;
|
2002-04-28 19:33:49 +00:00
|
|
|
SANE_Status status;
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
memset (buffer, '\0', 256); /* clear buffer */
|
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
size = 5; /* first get only 5 bytes to get size of
|
|
|
|
inquiry_return_block */
|
1999-08-09 18:06:01 +00:00
|
|
|
set_inquiry_return_size (inquiry.cmd, size);
|
2002-04-28 19:33:49 +00:00
|
|
|
status = sanei_scsi_cmd (sfd, inquiry.cmd, inquiry.size, buffer, &size);
|
|
|
|
|
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
return (status);
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
size = get_scsi_inquiry_additional_length (buffer) + 5;
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
/* then get inquiry with actual size */
|
|
|
|
set_inquiry_return_size (inquiry.cmd, size);
|
2002-04-28 19:33:49 +00:00
|
|
|
status = sanei_scsi_cmd (sfd, inquiry.cmd, inquiry.size, buffer, &size);
|
|
|
|
|
|
|
|
return (status);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
2002-04-28 19:20:20 +00:00
|
|
|
static void
|
2002-06-25 18:49:44 +00:00
|
|
|
scanner_identify_scsi_scanner (unsigned char *buffer, int sfd,
|
2002-06-25 18:41:57 +00:00
|
|
|
char *devicename)
|
1999-08-09 18:06:01 +00:00
|
|
|
{
|
|
|
|
unsigned char vendor[9];
|
|
|
|
unsigned char product[17];
|
|
|
|
unsigned char version[5];
|
|
|
|
unsigned char *pp;
|
|
|
|
unsigned int devtype;
|
2002-04-28 19:33:49 +00:00
|
|
|
SANE_Status status;
|
2002-04-28 19:20:20 +00:00
|
|
|
static char *devtypes[] = {
|
|
|
|
"disk", "tape", "printer", "processor", "CD-writer",
|
|
|
|
"CD-drive", "scanner", "optical-drive", "jukebox",
|
|
|
|
"communicator"
|
|
|
|
};
|
2002-06-25 18:41:57 +00:00
|
|
|
status = scanner_do_scsi_inquiry (buffer, sfd);
|
2002-04-28 19:33:49 +00:00
|
|
|
if (status != SANE_STATUS_GOOD)
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("inquiry for device %s failed (%s)\n",
|
|
|
|
devicename, sane_strstatus (status));
|
2002-04-28 19:33:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 2)
|
2002-04-28 19:33:49 +00:00
|
|
|
hexdump ("Inquiry for device:", buffer,
|
2002-06-25 18:41:57 +00:00
|
|
|
get_scsi_inquiry_additional_length (buffer) + 5);
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
devtype = get_scsi_inquiry_periph_devtype (buffer);
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose <= 1 && devtype != IN_periph_devtype_scanner
|
1999-08-09 18:06:01 +00:00
|
|
|
/* old HP scanners use the CPU id ... */
|
|
|
|
&& devtype != IN_periph_devtype_cpu)
|
2002-04-28 19:20:20 +00:00
|
|
|
return; /* no, continue searching */
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
get_scsi_inquiry_vendor ((char *) buffer, (char *) vendor);
|
|
|
|
get_scsi_inquiry_product ((char *) buffer, (char *) product);
|
|
|
|
get_scsi_inquiry_version ((char *) buffer, (char *) version);
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
pp = &vendor[7];
|
|
|
|
vendor[8] = '\0';
|
|
|
|
while (pp >= vendor && (*pp == ' ' || *pp >= 127))
|
|
|
|
*pp-- = '\0';
|
|
|
|
|
|
|
|
pp = &product[15];
|
|
|
|
product[16] = '\0';
|
|
|
|
while (pp >= product && (*pp == ' ' || *pp >= 127))
|
|
|
|
*pp-- = '\0';
|
|
|
|
|
|
|
|
pp = &version[3];
|
|
|
|
version[4] = '\0';
|
|
|
|
while (pp >= version && (*pp == ' ' || *(pp - 1) >= 127))
|
|
|
|
*pp-- = '\0';
|
|
|
|
|
2002-07-12 20:50:54 +00:00
|
|
|
device_found = SANE_TRUE;
|
|
|
|
printf ("found SCSI %s \"%s %s %s\" at %s\n",
|
2002-04-28 19:20:20 +00:00
|
|
|
devtype < NELEMS (devtypes) ? devtypes[devtype] : "unknown device",
|
1999-08-09 18:06:01 +00:00
|
|
|
vendor, product, version, devicename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
static void
|
2002-06-25 18:49:44 +00:00
|
|
|
check_scsi_file (char *file_name)
|
2002-06-25 18:41:57 +00:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
int sfd;
|
|
|
|
unsigned char buffer[16384];
|
|
|
|
|
2002-07-14 16:39:03 +00:00
|
|
|
if (strstr (file_name, "usb")
|
|
|
|
|| strstr (file_name, "uscanner") || strstr (file_name, "ugen"))
|
|
|
|
{
|
|
|
|
if (force)
|
|
|
|
{
|
|
|
|
if (verbose > 1)
|
|
|
|
printf ("checking %s even though it looks like a USB device...",
|
|
|
|
file_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (verbose > 1)
|
|
|
|
printf ("ignored %s (not a SCSI device)\n", file_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (verbose > 1)
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("checking %s...", file_name);
|
2002-06-25 18:49:44 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
result = sanei_scsi_open (file_name, &sfd, NULL, NULL);
|
2002-06-25 18:49:44 +00:00
|
|
|
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
2002-06-25 18:41:57 +00:00
|
|
|
{
|
|
|
|
if (result != 0)
|
|
|
|
printf (" failed to open (%s)\n", sane_strstatus (result));
|
|
|
|
else
|
|
|
|
printf (" open ok\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == SANE_STATUS_GOOD)
|
|
|
|
{
|
|
|
|
scanner_identify_scsi_scanner (buffer, sfd, file_name);
|
|
|
|
sanei_scsi_close (sfd);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-06-25 18:49:44 +00:00
|
|
|
check_usb_file (char *file_name)
|
2002-06-25 18:41:57 +00:00
|
|
|
{
|
|
|
|
SANE_Status result;
|
|
|
|
SANE_Word vendor, product;
|
|
|
|
SANE_Int fd;
|
|
|
|
|
2002-07-14 16:39:03 +00:00
|
|
|
if (!strstr (file_name, "usb")
|
|
|
|
&& !strstr (file_name, "uscanner") && !strstr (file_name, "ugen"))
|
|
|
|
{
|
|
|
|
if (force)
|
|
|
|
{
|
|
|
|
if (verbose > 1)
|
|
|
|
printf ("checking %s even though doesn't look like a "
|
|
|
|
"USB device...", file_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (verbose > 1)
|
|
|
|
printf ("ignored %s (not a USB device)\n", file_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (verbose > 1)
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("checking %s...", file_name);
|
2002-06-25 18:41:57 +00:00
|
|
|
|
|
|
|
result = sanei_usb_open (file_name, &fd);
|
|
|
|
|
|
|
|
if (result != SANE_STATUS_GOOD)
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
2002-06-25 18:41:57 +00:00
|
|
|
printf (" failed to open (%s)\n", sane_strstatus (result));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = sanei_usb_get_vendor_product (fd, &vendor, &product);
|
|
|
|
if (result == SANE_STATUS_GOOD)
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
2002-06-25 18:41:57 +00:00
|
|
|
printf (" open ok, vendor and product ids were identified\n");
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("found USB scanner (vendor = 0x%04x, "
|
2002-07-14 16:39:03 +00:00
|
|
|
"product = 0x%04x) at %s\n", vendor, product, file_name);
|
2002-06-25 18:41:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
2002-06-25 18:41:57 +00:00
|
|
|
printf (" open ok, but vendor and product could NOT be "
|
|
|
|
"identified\n");
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("found USB scanner (UNKNOWN vendor and product) "
|
|
|
|
"at device %s\n", file_name);
|
2002-06-25 18:41:57 +00:00
|
|
|
unknown_found = SANE_TRUE;
|
|
|
|
}
|
2002-07-12 20:50:54 +00:00
|
|
|
device_found = SANE_TRUE;
|
2002-06-25 18:41:57 +00:00
|
|
|
sanei_usb_close (fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static DIR *
|
2002-06-25 18:49:44 +00:00
|
|
|
scan_directory (char *dir_name)
|
2002-06-25 18:41:57 +00:00
|
|
|
{
|
|
|
|
struct stat stat_buf;
|
|
|
|
DIR *dir;
|
2002-06-25 18:49:44 +00:00
|
|
|
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 2)
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("scanning directory %s\n", dir_name);
|
2002-06-25 18:49:44 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
if (stat (dir_name, &stat_buf) < 0)
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("cannot stat `%s' (%s)\n", dir_name, strerror (errno));
|
2002-06-25 18:41:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!S_ISDIR (stat_buf.st_mode))
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("`%s' is not a directory\n", dir_name);
|
2002-06-25 18:41:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((dir = opendir (dir_name)) == 0)
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
|
|
|
printf ("cannot read directory `%s' (%s)\n", dir_name,
|
|
|
|
strerror (errno));
|
2002-06-25 18:41:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2002-06-25 18:49:44 +00:00
|
|
|
get_next_file (char *dir_name, DIR * dir)
|
2002-06-25 18:41:57 +00:00
|
|
|
{
|
|
|
|
struct dirent *dir_entry;
|
2002-06-25 18:49:44 +00:00
|
|
|
static char file_name[PATH_MAX];
|
2002-06-25 18:41:57 +00:00
|
|
|
|
2002-06-25 18:49:44 +00:00
|
|
|
do
|
2002-06-25 18:41:57 +00:00
|
|
|
{
|
|
|
|
dir_entry = readdir (dir);
|
|
|
|
if (!dir_entry)
|
|
|
|
return 0;
|
|
|
|
}
|
2002-06-25 18:49:44 +00:00
|
|
|
while (strcmp (dir_entry->d_name, ".") == 0
|
|
|
|
|| strcmp (dir_entry->d_name, "..") == 0);
|
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
if (strlen (dir_name) + strlen (dir_entry->d_name) + 1 > PATH_MAX)
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("filename too long\n");
|
2002-06-25 18:41:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
sprintf (file_name, "%s%s", dir_name, dir_entry->d_name);
|
|
|
|
return file_name;
|
|
|
|
}
|
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2001-08-11 13:23:01 +00:00
|
|
|
char **dev_list, **usb_dev_list, *dev_name, **ap;
|
2002-07-12 20:50:54 +00:00
|
|
|
SANE_Bool libusb_device_found = SANE_FALSE;
|
1999-08-09 18:06:01 +00:00
|
|
|
|
|
|
|
prog_name = strrchr (argv[0], '/');
|
|
|
|
if (prog_name)
|
|
|
|
++prog_name;
|
|
|
|
else
|
|
|
|
prog_name = argv[0];
|
|
|
|
|
|
|
|
for (ap = argv + 1; ap < argv + argc; ++ap)
|
|
|
|
{
|
|
|
|
if ((*ap)[0] != '-')
|
|
|
|
break;
|
|
|
|
switch ((*ap)[1])
|
|
|
|
{
|
|
|
|
case '?':
|
|
|
|
case 'h':
|
|
|
|
usage (0);
|
|
|
|
exit (0);
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
++verbose;
|
2002-07-14 16:39:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'q':
|
|
|
|
--verbose;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
force = SANE_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf ("unknown option: -%c, try -h for help\n", (*ap)[1]);
|
|
|
|
exit (0);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ap < argv + argc)
|
2001-08-11 13:23:01 +00:00
|
|
|
{
|
|
|
|
dev_list = ap;
|
|
|
|
usb_dev_list = ap;
|
|
|
|
}
|
1999-08-09 18:06:01 +00:00
|
|
|
else
|
|
|
|
{
|
2002-04-28 19:20:20 +00:00
|
|
|
static char *default_dev_list[] = {
|
1999-08-09 18:06:01 +00:00
|
|
|
#if defined(__sgi)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/scsi/sc0d1l0", "/dev/scsi/sc0d2l0",
|
|
|
|
"/dev/scsi/sc0d3l0", "/dev/scsi/sc0d4l0",
|
|
|
|
"/dev/scsi/sc0d5l0", "/dev/scsi/sc0d6l0",
|
|
|
|
"/dev/scsi/sc0d7l0", "/dev/scsi/sc0d8l0",
|
|
|
|
"/dev/scsi/sc0d9l0", "/dev/scsi/sc0d10l0",
|
|
|
|
"/dev/scsi/sc0d11l0", "/dev/scsi/sc0d12l0",
|
|
|
|
"/dev/scsi/sc0d13l0", "/dev/scsi/sc0d14l0",
|
|
|
|
"/dev/scsi/sc0d15l0",
|
|
|
|
"/dev/scsi/sc1d1l0", "/dev/scsi/sc1d2l0",
|
|
|
|
"/dev/scsi/sc1d3l0", "/dev/scsi/sc1d4l0",
|
|
|
|
"/dev/scsi/sc1d5l0", "/dev/scsi/sc1d6l0",
|
|
|
|
"/dev/scsi/sc1d7l0", "/dev/scsi/sc1d8l0",
|
|
|
|
"/dev/scsi/sc1d9l0", "/dev/scsi/sc1d10l0",
|
|
|
|
"/dev/scsi/sc1d11l0", "/dev/scsi/sc1d12l0",
|
|
|
|
"/dev/scsi/sc1d13l0", "/dev/scsi/sc1d14l0",
|
|
|
|
"/dev/scsi/sc1d15l0",
|
|
|
|
"/dev/scsi/sc2d1l0", "/dev/scsi/sc2d2l0",
|
|
|
|
"/dev/scsi/sc2d3l0", "/dev/scsi/sc2d4l0",
|
|
|
|
"/dev/scsi/sc2d5l0", "/dev/scsi/sc2d6l0",
|
|
|
|
"/dev/scsi/sc2d7l0", "/dev/scsi/sc2d8l0",
|
|
|
|
"/dev/scsi/sc2d9l0", "/dev/scsi/sc2d10l0",
|
|
|
|
"/dev/scsi/sc2d11l0", "/dev/scsi/sc2d12l0",
|
|
|
|
"/dev/scsi/sc2d13l0", "/dev/scsi/sc2d14l0",
|
|
|
|
"/dev/scsi/sc2d15l0",
|
|
|
|
"/dev/scsi/sc3d1l0", "/dev/scsi/sc3d2l0",
|
|
|
|
"/dev/scsi/sc3d3l0", "/dev/scsi/sc3d4l0",
|
|
|
|
"/dev/scsi/sc3d5l0", "/dev/scsi/sc3d6l0",
|
|
|
|
"/dev/scsi/sc3d7l0", "/dev/scsi/sc3d8l0",
|
|
|
|
"/dev/scsi/sc3d9l0", "/dev/scsi/sc3d10l0",
|
|
|
|
"/dev/scsi/sc3d11l0", "/dev/scsi/sc3d12l0",
|
|
|
|
"/dev/scsi/sc3d13l0", "/dev/scsi/sc3d14l0",
|
|
|
|
"/dev/scsi/sc3d15l0",
|
|
|
|
"/dev/scsi/sc4d1l0", "/dev/scsi/sc4d2l0",
|
|
|
|
"/dev/scsi/sc4d3l0", "/dev/scsi/sc4d4l0",
|
|
|
|
"/dev/scsi/sc4d5l0", "/dev/scsi/sc4d6l0",
|
|
|
|
"/dev/scsi/sc4d7l0", "/dev/scsi/sc4d8l0",
|
|
|
|
"/dev/scsi/sc4d9l0", "/dev/scsi/sc4d10l0",
|
|
|
|
"/dev/scsi/sc4d11l0", "/dev/scsi/sc4d12l0",
|
|
|
|
"/dev/scsi/sc4d13l0", "/dev/scsi/sc4d14l0",
|
|
|
|
"/dev/scsi/sc4d15l0",
|
|
|
|
"/dev/scsi/sc5d1l0", "/dev/scsi/sc5d2l0",
|
|
|
|
"/dev/scsi/sc5d3l0", "/dev/scsi/sc5d4l0",
|
|
|
|
"/dev/scsi/sc5d5l0", "/dev/scsi/sc5d6l0",
|
|
|
|
"/dev/scsi/sc5d7l0", "/dev/scsi/sc5d8l0",
|
|
|
|
"/dev/scsi/sc5d9l0", "/dev/scsi/sc5d10l0",
|
|
|
|
"/dev/scsi/sc5d11l0", "/dev/scsi/sc5d12l0",
|
|
|
|
"/dev/scsi/sc5d13l0", "/dev/scsi/sc5d14l0",
|
|
|
|
"/dev/scsi/sc5d15l0",
|
|
|
|
"/dev/scsi/sc6d1l0", "/dev/scsi/sc6d2l0",
|
|
|
|
"/dev/scsi/sc6d3l0", "/dev/scsi/sc6d4l0",
|
|
|
|
"/dev/scsi/sc6d5l0", "/dev/scsi/sc6d6l0",
|
|
|
|
"/dev/scsi/sc6d7l0", "/dev/scsi/sc6d8l0",
|
|
|
|
"/dev/scsi/sc6d9l0", "/dev/scsi/sc6d10l0",
|
|
|
|
"/dev/scsi/sc6d11l0", "/dev/scsi/sc6d12l0",
|
|
|
|
"/dev/scsi/sc6d13l0", "/dev/scsi/sc6d14l0",
|
|
|
|
"/dev/scsi/sc6d15l0",
|
|
|
|
"/dev/scsi/sc7d1l0", "/dev/scsi/sc7d2l0",
|
|
|
|
"/dev/scsi/sc7d3l0", "/dev/scsi/sc7d4l0",
|
|
|
|
"/dev/scsi/sc7d5l0", "/dev/scsi/sc7d6l0",
|
|
|
|
"/dev/scsi/sc7d7l0", "/dev/scsi/sc7d8l0",
|
|
|
|
"/dev/scsi/sc7d9l0", "/dev/scsi/sc7d10l0",
|
|
|
|
"/dev/scsi/sc7d11l0", "/dev/scsi/sc7d12l0",
|
|
|
|
"/dev/scsi/sc7d13l0", "/dev/scsi/sc7d14l0",
|
|
|
|
"/dev/scsi/sc7d15l0",
|
|
|
|
"/dev/scsi/sc8d1l0", "/dev/scsi/sc8d2l0",
|
|
|
|
"/dev/scsi/sc8d3l0", "/dev/scsi/sc8d4l0",
|
|
|
|
"/dev/scsi/sc8d5l0", "/dev/scsi/sc8d6l0",
|
|
|
|
"/dev/scsi/sc8d7l0", "/dev/scsi/sc8d8l0",
|
|
|
|
"/dev/scsi/sc8d9l0", "/dev/scsi/sc8d10l0",
|
|
|
|
"/dev/scsi/sc8d11l0", "/dev/scsi/sc8d12l0",
|
|
|
|
"/dev/scsi/sc8d13l0", "/dev/scsi/sc8d14l0",
|
|
|
|
"/dev/scsi/sc8d15l0",
|
|
|
|
"/dev/scsi/sc9d1l0", "/dev/scsi/sc9d2l0",
|
|
|
|
"/dev/scsi/sc9d3l0", "/dev/scsi/sc9d4l0",
|
|
|
|
"/dev/scsi/sc9d5l0", "/dev/scsi/sc9d6l0",
|
|
|
|
"/dev/scsi/sc9d7l0", "/dev/scsi/sc9d8l0",
|
|
|
|
"/dev/scsi/sc9d9l0", "/dev/scsi/sc9d10l0",
|
|
|
|
"/dev/scsi/sc9d11l0", "/dev/scsi/sc9d12l0",
|
|
|
|
"/dev/scsi/sc9d13l0", "/dev/scsi/sc9d14l0",
|
|
|
|
"/dev/scsi/sc9d15l0",
|
|
|
|
"/dev/scsi/sc10d1l0", "/dev/scsi/sc10d2l0",
|
|
|
|
"/dev/scsi/sc10d3l0", "/dev/scsi/sc10d4l0",
|
|
|
|
"/dev/scsi/sc10d5l0", "/dev/scsi/sc10d6l0",
|
|
|
|
"/dev/scsi/sc10d7l0", "/dev/scsi/sc10d8l0",
|
|
|
|
"/dev/scsi/sc10d9l0", "/dev/scsi/sc10d10l0",
|
|
|
|
"/dev/scsi/sc10d11l0", "/dev/scsi/sc10d12l0",
|
|
|
|
"/dev/scsi/sc10d13l0", "/dev/scsi/sc10d14l0",
|
|
|
|
"/dev/scsi/sc10d15l0",
|
|
|
|
"/dev/scsi/sc11d1l0", "/dev/scsi/sc11d2l0",
|
|
|
|
"/dev/scsi/sc11d3l0", "/dev/scsi/sc11d4l0",
|
|
|
|
"/dev/scsi/sc11d5l0", "/dev/scsi/sc11d6l0",
|
|
|
|
"/dev/scsi/sc11d7l0", "/dev/scsi/sc11d8l0",
|
|
|
|
"/dev/scsi/sc11d9l0", "/dev/scsi/sc11d10l0",
|
|
|
|
"/dev/scsi/sc11d11l0", "/dev/scsi/sc11d12l0",
|
|
|
|
"/dev/scsi/sc11d13l0", "/dev/scsi/sc11d14l0",
|
|
|
|
"/dev/scsi/sc11d15l0",
|
|
|
|
"/dev/scsi/sc12d1l0", "/dev/scsi/sc12d2l0",
|
|
|
|
"/dev/scsi/sc12d3l0", "/dev/scsi/sc12d4l0",
|
|
|
|
"/dev/scsi/sc12d5l0", "/dev/scsi/sc12d6l0",
|
|
|
|
"/dev/scsi/sc12d7l0", "/dev/scsi/sc12d8l0",
|
|
|
|
"/dev/scsi/sc12d9l0", "/dev/scsi/sc12d10l0",
|
|
|
|
"/dev/scsi/sc12d11l0", "/dev/scsi/sc12d12l0",
|
|
|
|
"/dev/scsi/sc12d13l0", "/dev/scsi/sc12d14l0",
|
|
|
|
"/dev/scsi/sc12d15l0",
|
|
|
|
"/dev/scsi/sc13d1l0", "/dev/scsi/sc13d2l0",
|
|
|
|
"/dev/scsi/sc13d3l0", "/dev/scsi/sc13d4l0",
|
|
|
|
"/dev/scsi/sc13d5l0", "/dev/scsi/sc13d6l0",
|
|
|
|
"/dev/scsi/sc13d7l0", "/dev/scsi/sc13d8l0",
|
|
|
|
"/dev/scsi/sc13d9l0", "/dev/scsi/sc13d10l0",
|
|
|
|
"/dev/scsi/sc13d11l0", "/dev/scsi/sc13d12l0",
|
|
|
|
"/dev/scsi/sc13d13l0", "/dev/scsi/sc13d14l0",
|
|
|
|
"/dev/scsi/sc13d15l0",
|
|
|
|
"/dev/scsi/sc14d1l0", "/dev/scsi/sc14d2l0",
|
|
|
|
"/dev/scsi/sc14d3l0", "/dev/scsi/sc14d4l0",
|
|
|
|
"/dev/scsi/sc14d5l0", "/dev/scsi/sc14d6l0",
|
|
|
|
"/dev/scsi/sc14d7l0", "/dev/scsi/sc14d8l0",
|
|
|
|
"/dev/scsi/sc14d9l0", "/dev/scsi/sc14d10l0",
|
|
|
|
"/dev/scsi/sc14d11l0", "/dev/scsi/sc14d12l0",
|
|
|
|
"/dev/scsi/sc14d13l0", "/dev/scsi/sc14d14l0",
|
|
|
|
"/dev/scsi/sc14d15l0",
|
|
|
|
"/dev/scsi/sc15d1l0", "/dev/scsi/sc15d2l0",
|
|
|
|
"/dev/scsi/sc15d3l0", "/dev/scsi/sc15d4l0",
|
|
|
|
"/dev/scsi/sc15d5l0", "/dev/scsi/sc15d6l0",
|
|
|
|
"/dev/scsi/sc15d7l0", "/dev/scsi/sc15d8l0",
|
|
|
|
"/dev/scsi/sc15d9l0", "/dev/scsi/sc15d10l0",
|
|
|
|
"/dev/scsi/sc15d11l0", "/dev/scsi/sc15d12l0",
|
|
|
|
"/dev/scsi/sc15d13l0", "/dev/scsi/sc15d14l0",
|
|
|
|
"/dev/scsi/sc15d15l0",
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(__EMX__)
|
2002-04-28 19:20:20 +00:00
|
|
|
"b0t0l0", "b0t1l0", "b0t2l0", "b0t3l0",
|
|
|
|
"b0t4l0", "b0t5l0", "b0t6l0", "b0t7l0",
|
|
|
|
"b1t0l0", "b1t1l0", "b1t2l0", "b1t3l0",
|
|
|
|
"b1t4l0", "b1t5l0", "b1t6l0", "b1t7l0",
|
|
|
|
"b2t0l0", "b2t1l0", "b2t2l0", "b2t3l0",
|
|
|
|
"b2t4l0", "b2t5l0", "b2t6l0", "b2t7l0",
|
|
|
|
"b3t0l0", "b3t1l0", "b3t2l0", "b3t3l0",
|
|
|
|
"b3t4l0", "b3t5l0", "b3t6l0", "b3t7l0",
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(__linux__)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/scanner",
|
|
|
|
"/dev/sg0", "/dev/sg1", "/dev/sg2", "/dev/sg3",
|
|
|
|
"/dev/sg4", "/dev/sg5", "/dev/sg6", "/dev/sg7",
|
|
|
|
"/dev/sg8", "/dev/sg9",
|
|
|
|
"/dev/sga", "/dev/sgb", "/dev/sgc", "/dev/sgd",
|
|
|
|
"/dev/sge", "/dev/sgf", "/dev/sgg", "/dev/sgh",
|
|
|
|
"/dev/sgi", "/dev/sgj", "/dev/sgk", "/dev/sgl",
|
|
|
|
"/dev/sgm", "/dev/sgn", "/dev/sgo", "/dev/sgp",
|
|
|
|
"/dev/sgq", "/dev/sgr", "/dev/sgs", "/dev/sgt",
|
|
|
|
"/dev/sgu", "/dev/sgv", "/dev/sgw", "/dev/sgx",
|
|
|
|
"/dev/sgy", "/dev/sgz",
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(__NeXT__)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/sg0a", "/dev/sg0b", "/dev/sg0c", "/dev/sg0d",
|
|
|
|
"/dev/sg0e", "/dev/sg0f", "/dev/sg0g", "/dev/sg0h",
|
|
|
|
"/dev/sg1a", "/dev/sg1b", "/dev/sg1c", "/dev/sg1d",
|
|
|
|
"/dev/sg1e", "/dev/sg1f", "/dev/sg1g", "/dev/sg1h",
|
|
|
|
"/dev/sg2a", "/dev/sg2b", "/dev/sg2c", "/dev/sg2d",
|
|
|
|
"/dev/sg2e", "/dev/sg2f", "/dev/sg2g", "/dev/sg2h",
|
|
|
|
"/dev/sg3a", "/dev/sg3b", "/dev/sg3c", "/dev/sg3d",
|
|
|
|
"/dev/sg3e", "/dev/sg3f", "/dev/sg3g", "/dev/sg3h",
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(_AIX)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/scanner",
|
|
|
|
"/dev/gsc0", "/dev/gsc1", "/dev/gsc2", "/dev/gsc3",
|
|
|
|
"/dev/gsc4", "/dev/gsc5", "/dev/gsc6", "/dev/gsc7",
|
|
|
|
"/dev/gsc8", "/dev/gsc9", "/dev/gsc10", "/dev/gsc11",
|
|
|
|
"/dev/gsc12", "/dev/gsc13", "/dev/gsc14", "/dev/gsc15",
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(__sun)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/scg0a", "/dev/scg0b", "/dev/scg0c", "/dev/scg0d",
|
|
|
|
"/dev/scg0e", "/dev/scg0f", "/dev/scg0g",
|
|
|
|
"/dev/scg1a", "/dev/scg1b", "/dev/scg1c", "/dev/scg1d",
|
|
|
|
"/dev/scg1e", "/dev/scg1f", "/dev/scg1g",
|
|
|
|
"/dev/scg2a", "/dev/scg2b", "/dev/scg2c", "/dev/scg2d",
|
|
|
|
"/dev/scg2e", "/dev/scg2f", "/dev/scg2g",
|
|
|
|
"/dev/sg/0", "/dev/sg/1", "/dev/sg/2", "/dev/sg/3",
|
|
|
|
"/dev/sg/4", "/dev/sg/5", "/dev/sg/6",
|
2002-06-25 18:41:57 +00:00
|
|
|
"/dev/scsi/scanner/", "/dev/scsi/processor/",
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(HAVE_CAMLIB_H)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/scanner", "/dev/scanner0", "/dev/scanner1",
|
|
|
|
"/dev/pass0", "/dev/pass1", "/dev/pass2", "/dev/pass3",
|
|
|
|
"/dev/pass4", "/dev/pass5", "/dev/pass6", "/dev/pass7",
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(__FreeBSD__)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/uk0", "/dev/uk1", "/dev/uk2", "/dev/uk3", "/dev/uk4",
|
|
|
|
"/dev/uk5", "/dev/uk6",
|
1999-08-09 18:06:01 +00:00
|
|
|
#elif defined(__NetBSD__)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/uk0", "/dev/uk1", "/dev/uk2", "/dev/uk3", "/dev/uk4",
|
|
|
|
"/dev/uk5", "/dev/uk6",
|
|
|
|
"/dev/ss0",
|
2001-12-25 16:07:35 +00:00
|
|
|
#elif defined(__OpenBSD__)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/uk0", "/dev/uk1", "/dev/uk2", "/dev/uk3", "/dev/uk4",
|
|
|
|
"/dev/uk5", "/dev/uk6",
|
2001-10-02 20:38:07 +00:00
|
|
|
#elif defined(__hpux)
|
2002-06-28 15:28:21 +00:00
|
|
|
"/dev/rscsi/",
|
1999-08-09 18:06:01 +00:00
|
|
|
#endif
|
2002-04-28 19:20:20 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
static char *usb_default_dev_list[] = {
|
2001-08-16 21:20:20 +00:00
|
|
|
#if defined(__linux__)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/usb/scanner",
|
|
|
|
"/dev/usb/scanner0", "/dev/usb/scanner1",
|
|
|
|
"/dev/usb/scanner2", "/dev/usb/scanner3",
|
|
|
|
"/dev/usb/scanner4", "/dev/usb/scanner5",
|
|
|
|
"/dev/usb/scanner5", "/dev/usb/scanner7",
|
|
|
|
"/dev/usb/scanner8", "/dev/usb/scanner9",
|
|
|
|
"/dev/usb/scanner10", "/dev/usb/scanner11",
|
|
|
|
"/dev/usb/scanner12", "/dev/usb/scanner13",
|
|
|
|
"/dev/usb/scanner14", "/dev/usb/scanner15",
|
|
|
|
"/dev/usbscanner",
|
|
|
|
"/dev/usbscanner0", "/dev/usbscanner1",
|
|
|
|
"/dev/usbscanner2", "/dev/usbscanner3",
|
|
|
|
"/dev/usbscanner4", "/dev/usbscanner5",
|
|
|
|
"/dev/usbscanner6", "/dev/usbscanner7",
|
|
|
|
"/dev/usbscanner8", "/dev/usbscanner9",
|
|
|
|
"/dev/usbscanner10", "/dev/usbscanner11",
|
|
|
|
"/dev/usbscanner12", "/dev/usbscanner13",
|
|
|
|
"/dev/usbscanner14", "/dev/usbscanner15",
|
2001-08-16 21:20:20 +00:00
|
|
|
#elif defined(__FreeBSD__)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/uscanner",
|
|
|
|
"/dev/uscanner0", "/dev/uscanner1",
|
|
|
|
"/dev/uscanner2", "/dev/uscanner3",
|
|
|
|
"/dev/uscanner4", "/dev/uscanner5",
|
|
|
|
"/dev/uscanner6", "/dev/uscanner7",
|
|
|
|
"/dev/uscanner8", "/dev/uscanner9",
|
|
|
|
"/dev/uscanner10", "/dev/uscanner11",
|
|
|
|
"/dev/uscanner12", "/dev/uscanner13",
|
|
|
|
"/dev/uscanner14", "/dev/uscanner15",
|
2001-12-25 16:07:35 +00:00
|
|
|
#elif defined(__OpenBSD__)
|
2002-04-28 19:20:20 +00:00
|
|
|
"/dev/uscanner",
|
|
|
|
"/dev/uscanner0", "/dev/uscanner1",
|
|
|
|
"/dev/uscanner2", "/dev/uscanner3",
|
|
|
|
"/dev/uscanner4", "/dev/uscanner5",
|
|
|
|
"/dev/uscanner6", "/dev/uscanner7",
|
|
|
|
"/dev/uscanner8", "/dev/uscanner9",
|
|
|
|
"/dev/uscanner10", "/dev/uscanner11",
|
|
|
|
"/dev/uscanner12", "/dev/uscanner13",
|
|
|
|
"/dev/uscanner14", "/dev/uscanner15",
|
2001-08-16 21:20:20 +00:00
|
|
|
#endif
|
2002-04-28 19:20:20 +00:00
|
|
|
0
|
|
|
|
};
|
2001-08-11 13:23:01 +00:00
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
dev_list = default_dev_list;
|
2001-08-11 13:23:01 +00:00
|
|
|
usb_dev_list = usb_default_dev_list;
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
printf ("\n");
|
|
|
|
if (verbose > 1)
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("searching for SCSI scanners:\n");
|
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
while ((dev_name = *dev_list++))
|
|
|
|
{
|
2002-06-25 18:41:57 +00:00
|
|
|
if (strlen (dev_name) == 0)
|
2002-06-25 18:49:44 +00:00
|
|
|
continue; /* Empty device names ... */
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-06-25 18:49:44 +00:00
|
|
|
if (dev_name[strlen (dev_name) - 1] == '/')
|
2002-06-25 18:41:57 +00:00
|
|
|
{
|
|
|
|
/* check whole directories */
|
|
|
|
DIR *dir;
|
2002-06-25 18:49:44 +00:00
|
|
|
char *file_name;
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
dir = scan_directory (dev_name);
|
|
|
|
if (!dir)
|
|
|
|
continue;
|
1999-08-09 18:06:01 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
while ((file_name = get_next_file (dev_name, dir)))
|
|
|
|
check_scsi_file (file_name);
|
2002-04-28 19:20:20 +00:00
|
|
|
}
|
2002-06-25 18:41:57 +00:00
|
|
|
else
|
1999-08-09 18:06:01 +00:00
|
|
|
{
|
2002-06-25 18:41:57 +00:00
|
|
|
/* check device files */
|
|
|
|
check_scsi_file (dev_name);
|
1999-08-09 18:06:01 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-12 20:50:54 +00:00
|
|
|
if (device_found)
|
2001-08-11 13:23:01 +00:00
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
printf
|
|
|
|
(" # Your SCSI scanner was detected. It may or may not be "
|
|
|
|
"supported by SANE. Try\n # scanimage -L and read the backend's "
|
|
|
|
"manpage.\n");
|
2001-08-11 13:23:01 +00:00
|
|
|
}
|
2002-07-12 20:50:54 +00:00
|
|
|
else
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
printf
|
|
|
|
(" # No SCSI scanners found. If you expected something different, "
|
|
|
|
"make sure that\n # you have loaded a SCSI driver for your SCSI "
|
|
|
|
"adapter.\n");
|
2002-07-12 20:50:54 +00:00
|
|
|
if (!check_sg ())
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
printf
|
|
|
|
(" # Also you need support for SCSI Generic (sg) in your "
|
|
|
|
"operating system.\n # If using Linux, try \"modprobe "
|
|
|
|
"sg\".\n");
|
2002-07-12 20:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
printf ("\n");
|
2002-07-12 20:50:54 +00:00
|
|
|
device_found = SANE_FALSE;
|
2001-08-11 13:23:01 +00:00
|
|
|
sanei_usb_init ();
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("searching for USB scanners:\n");
|
2002-06-25 18:41:57 +00:00
|
|
|
|
2001-08-11 13:23:01 +00:00
|
|
|
while ((dev_name = *usb_dev_list++))
|
|
|
|
{
|
2002-06-25 18:41:57 +00:00
|
|
|
if (strlen (dev_name) == 0)
|
2002-06-25 18:49:44 +00:00
|
|
|
continue; /* Empty device names ... */
|
2001-08-11 13:23:01 +00:00
|
|
|
|
2002-06-25 18:49:44 +00:00
|
|
|
if (dev_name[strlen (dev_name) - 1] == '/')
|
2002-06-25 18:41:57 +00:00
|
|
|
{
|
|
|
|
/* check whole directories */
|
|
|
|
DIR *dir;
|
2002-06-25 18:49:44 +00:00
|
|
|
char *file_name;
|
2001-08-11 13:23:01 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
dir = scan_directory (dev_name);
|
|
|
|
if (!dir)
|
|
|
|
continue;
|
2001-08-11 13:23:01 +00:00
|
|
|
|
2002-06-25 18:41:57 +00:00
|
|
|
while ((file_name = get_next_file (dev_name, dir)))
|
|
|
|
check_usb_file (file_name);
|
2001-08-11 13:23:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-25 18:41:57 +00:00
|
|
|
/* check device files */
|
|
|
|
check_usb_file (dev_name);
|
2001-08-11 13:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-12 20:50:54 +00:00
|
|
|
#ifdef HAVE_LIBUSB
|
|
|
|
/* Now the libusb devices */
|
|
|
|
{
|
|
|
|
struct usb_bus *bus;
|
|
|
|
struct usb_device *dev;
|
|
|
|
|
2002-07-14 16:39:03 +00:00
|
|
|
if (ap < argv + argc)
|
|
|
|
{
|
|
|
|
/* user-specified devices not useful for libusb */
|
|
|
|
if (verbose > 1)
|
|
|
|
printf ("ignoring libusb devices\n");
|
|
|
|
}
|
|
|
|
else
|
2002-07-12 20:50:54 +00:00
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 2)
|
|
|
|
printf ("trying libusb:\n");
|
|
|
|
for (bus = usb_get_busses (); bus; bus = bus->next)
|
2002-07-12 20:50:54 +00:00
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
for (dev = bus->devices; dev; dev = dev->next)
|
2002-07-12 20:50:54 +00:00
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (!dev->config)
|
|
|
|
{
|
|
|
|
if (verbose > 1)
|
|
|
|
printf ("device 0x%04x/0x%04x is not configured\n",
|
|
|
|
dev->descriptor.idVendor,
|
|
|
|
dev->descriptor.idProduct);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Some heuristics, which device may be a scanner */
|
|
|
|
if (dev->descriptor.idVendor != 0 &&
|
|
|
|
dev->descriptor.idProduct != 0 &&
|
|
|
|
(dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC ||
|
|
|
|
(dev->descriptor.bDeviceClass
|
|
|
|
== USB_CLASS_PER_INTERFACE &&
|
|
|
|
(dev->config[0].interface->altsetting[0].bInterfaceClass
|
|
|
|
== USB_CLASS_VENDOR_SPEC ||
|
|
|
|
dev->config[0].interface->altsetting[0].bInterfaceClass
|
|
|
|
== USB_CLASS_PER_INTERFACE))))
|
|
|
|
{
|
|
|
|
printf ("found USB scanner (vendor=0x%04x, "
|
|
|
|
"product=0x%04x) at libusb:%s:%s\n",
|
|
|
|
dev->descriptor.idVendor,
|
|
|
|
dev->descriptor.idProduct, bus->dirname,
|
|
|
|
dev->filename);
|
|
|
|
libusb_device_found = SANE_TRUE;
|
|
|
|
device_found = SANE_TRUE;
|
|
|
|
}
|
|
|
|
else if (verbose > 2)
|
|
|
|
printf ("found non-scanner (vendor=0x%04x, product=0x%04x, "
|
|
|
|
"class=0x%02x, interface-class=0x%02x) "
|
|
|
|
"at libusb:%s:%s\n",
|
|
|
|
dev->descriptor.idVendor, dev->descriptor.idProduct,
|
|
|
|
dev->descriptor.bDeviceClass,
|
|
|
|
dev->config[0].interface->altsetting[0].
|
|
|
|
bInterfaceClass, bus->dirname, dev->filename);
|
|
|
|
} /* for (dev) */
|
|
|
|
} /* for (bus) */
|
|
|
|
} /* if (usb_dev_list == ap) */
|
2002-07-12 20:50:54 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_LIBUSB */
|
|
|
|
|
|
|
|
if (device_found)
|
|
|
|
{
|
|
|
|
if (libusb_device_found)
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
printf
|
|
|
|
(" # A USB device was detected. This program can't be sure "
|
|
|
|
"if it's really\n # a scanner. If it is your scanner, it "
|
|
|
|
"may or may not be supported by\n # SANE. Try scanimage "
|
|
|
|
"-L and read the backend's manpage.\n");
|
2002-07-12 20:50:54 +00:00
|
|
|
}
|
2002-07-14 16:39:03 +00:00
|
|
|
else if (verbose > 0)
|
|
|
|
printf
|
|
|
|
(" # Your USB scanner was detected. It may or may not "
|
|
|
|
"be supported by\n # SANE. Try scanimage -L and read the "
|
|
|
|
"backend's manpage.\n");
|
|
|
|
if (unknown_found && verbose > 0)
|
|
|
|
printf
|
2002-07-12 20:50:54 +00:00
|
|
|
(" # `UNKNOWN vendor and product' means that there seems to be a "
|
|
|
|
"scanner at this\n # device file but the vendor and product ids "
|
|
|
|
"couldn't be identified.\n # Currently identification only works "
|
|
|
|
"with Linux versions >= 2.4.8. You may\n # need to configure your "
|
|
|
|
"backend manually, see the backend's manpage.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
printf
|
|
|
|
(" # No USB scanners found. If you expected something different, "
|
|
|
|
"make sure that\n # you have loaded a driver for your USB host "
|
|
|
|
"controller and have installed a\n # kernel scanner module.\n");
|
2002-07-12 20:50:54 +00:00
|
|
|
}
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
printf ("\n # Scanners connected to the parallel port or other "
|
|
|
|
"proprietary ports can't be\n # detected by this program.\n");
|
2002-07-12 20:50:54 +00:00
|
|
|
if (getuid ())
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
printf
|
|
|
|
("\n # You may want to run this program as root to find all devices. "
|
|
|
|
"Once you\n # found the scanner devices, be sure to adjust access "
|
|
|
|
"permissions as\n # necessary.\n");
|
2001-08-11 13:23:01 +00:00
|
|
|
|
2002-07-14 16:39:03 +00:00
|
|
|
if (verbose > 1)
|
2002-07-12 20:50:54 +00:00
|
|
|
printf ("done\n");
|
2002-04-28 19:20:20 +00:00
|
|
|
|
1999-08-09 18:06:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|