[sane-devel] how does sane-find-scanner work?

abel deuring a.deuring@satzbau-gmbh.de
Sun, 17 Feb 2002 00:58:16 +0100


paul beard wrote:
> 
> I'm trying to do something more constructive than inserting lots
> of DEBUG printfs in the sane-find-scanner code, though that's not
> a bad approach if I could figure out what to print(f) out.
> 
> I can't seem to work out where exactly the device is probed so I
> can examine what comes back. I have verified that
> sane-find-scanner sees the device as a scanner (devtype 6), but
> can't get the vendor or other particulars to show up.
> 
> DEBUG: at 146: devtype = 6
> DEBUG: at 157: buffer =, sfd = 3
> DEBUG: at 159: pp = 0
> DEBUG: at 160: vendor = 0
> DEBUG: at 164: pp = 0
> DEBUG: at 171: pp = 0
> Hmmm: sane-find-scanner: found SCSI scanner "  " at device /dev/uk0
> 
> but that's all I can get out of this, given my C knowledge.
> 
> I would have thought this would output "unknown device" since
> nothing seems to be known about the device. All I can find out is
> that it's accessible on /dev/uk0.
> 
>    printf ("Hmmm: %s: found SCSI %s \"%s %s %s\" at device %s\n",
> prog_name, devtype < NELEMS(devtypes) ? devtypes[devtype] :
> "unknown device", vendor, product, version, devicename);

Paul,

this looks really weird. The idea of the "SCSI part" of
sane-find-scanner is to send a SCSI INQUIRY command to the scanner (or
other SCSI devices); a SCSI device sends back things like device type
and SCSI version; the minimum return length is 5 bytes (SCSI 1); for
SCSI 2 and above, bytes 8..15 should contain the vendor name; 16..31 the
product name and bytes 32..35 the product revision level (names and
revision level in ASCII; unused bytes should be padded with 0x20). So it
seems that you either have a SCSI 1 device - in this case the vendor
name etc will not be available -, or you might have some kind of a SCSI
problem, like a broken cable. 

To see what's going on, you could add some debug output to
scanner_do_inquiry (line 110 ff in sane_find_scanner): 

static void
scanner_do_inquiry (unsigned char *buffer, int sfd)
{
  size_t size;
 
  DBG (5, "do_inquiry\n");
  memset (buffer, '\0', 256);   /* clear buffer */
 
  size = 5; /* first get only 5 bytes to get size of
inquiry_return_block */
  set_inquiry_return_size (inquiry.cmd, size);
  sanei_scsi_cmd (sfd, inquiry.cmd, inquiry.size, buffer, &size);
 
  size = get_inquiry_additional_length (buffer) + 5;
  fprintf(stderr, "data block size for second INQUIRY: %i\n", size);
 
  /* then get inquiry with actual size */
  set_inquiry_return_size (inquiry.cmd, size);
  sanei_scsi_cmd (sfd, inquiry.cmd, inquiry.size, buffer, &size);
  {
    int i;
    fprintf(stderr, "result of second INQUIRY:\n");
    for (i = 0; i < size; i++)
      fprintf(stderr, "%02x ", buffer[i]);
    fprintf(stderr, "\n");
  }
}

Abel