Ejemplo n.º 1
0
/* Close device */
void
sane_close (SANE_Handle handle)
{
  struct scanner *s = (struct scanner *) handle;
  unsigned i;
  hopper_down (s);
  if (s->bus == USB)
    {
      sanei_usb_release_interface (s->file, 0);
      sanei_usb_close (s->file);
    }
  else
    sanei_scsi_close (s->file);

  for (i = 1; i < NUM_OPTIONS; i++)
    {
      if (s->opt[i].type == SANE_TYPE_STRING && s->val[i].s)
	free (s->val[i].s);
    }

  for (i = 0; i < sizeof (s->buf) / sizeof (s->buf[0]); i++)
    buf_deinit (&s->buf[i]);

  free (s->buffer);
  free (s);

}
Ejemplo n.º 2
0
static int u12if_close( U12_Device *dev )
{
	DBG( _DBG_INFO, "u12if_close()\n" );
	u12io_CloseScanPath( dev );
	sanei_usb_close( dev->fd );
	dev->fd = -1;
    return 0;
}
Ejemplo n.º 3
0
/* Open the device. 
 */
static SANE_Status
sanei_umaxusb_open (const char *dev, int *fdp,
					SANEI_SCSI_Sense_Handler handler, void *handler_arg)
{
	SANE_Status status;

	handler = handler;			/* silence gcc */
	handler_arg = handler_arg;	/* silence gcc */

	status = sanei_usb_open (dev, fdp);
	if (status != SANE_STATUS_GOOD) {
		DBG (1, "sanei_umaxusb_open: open of `%s' failed: %s\n",
			 dev, sane_strstatus(status));
		return status;
    } else {
		SANE_Word vendor;
		SANE_Word product;

		/* We have openned the device. Check that it is a USB scanner. */
		if (sanei_usb_get_vendor_product (*fdp, &vendor, &product) != SANE_STATUS_GOOD) {
			/* This is not a USB scanner, or SANE or the OS doesn't support it. */
			sanei_usb_close(*fdp);
			*fdp = -1;
			return SANE_STATUS_UNSUPPORTED;
		}

		/* So it's a scanner. Does this backend support it?
		 * Only the UMAX 2200 USB is currently supported. */
		if ((vendor != 0x1606) || (product != 0x0230)) {
			sanei_usb_close(*fdp);
			*fdp = -1;
			return SANE_STATUS_UNSUPPORTED;
		}
		
		/* It's a good scanner. Initialize it.  
		 *
		 * Note: pv8630_init_umaxusb_scanner() is for the UMAX
		 * 2200. Other UMAX scanner might need a different
		 * initialization routine. */

		pv8630_init_umaxusb_scanner(*fdp); 
	}
	
	return(SANE_STATUS_GOOD);
}
Ejemplo n.º 4
0
void
sane_close (SANE_Handle handle)
{
  struct hp5590_scanner *scanner = handle;

  DBG (DBG_proc, "%s\n", __FUNCTION__);

  sanei_usb_close (scanner->dn);
  scanner->dn = -1;
}
Ejemplo n.º 5
0
/* Close an USB device */
void
kv_usb_close (PKV_DEV dev)
{
  DBG (DBG_proc, "kv_usb_close: enter\n");
  if (kv_usb_already_open(dev))
    {
      sanei_usb_close(dev->usb_fd);
      dev->usb_fd = -1;
    }
  DBG (DBG_proc, "kv_usb_close: leave\n");
}
Ejemplo n.º 6
0
static void
channel_usb_close (channel *self, SANE_Status *status)
{
  SANE_Status s = SANE_STATUS_GOOD;

  if (self->interpreter)
    {
      self->interpreter->close (self);
    }

  sanei_usb_close (self->fd);
  self->fd = -1;
  if (status) *status = s;
}
Ejemplo n.º 7
0
static SANE_Status
disconnect_fd (struct scanner *s)
{
  DBG (10, "disconnect_fd: start\n");

  if(s->fd > -1){
    DBG (15, "disconnecting usb device\n");
    sanei_usb_close (s->fd);
    s->fd = -1;
  }

  DBG (10, "disconnect_fd: finish\n");

  return SANE_STATUS_GOOD;
}
Ejemplo n.º 8
0
SANE_Status
sane_open (SANE_String_Const name, SANE_Handle * h)
{
  struct device_s *dev;
  int ret;

  if(!devlist_head)
    sane_get_devices(NULL,(SANE_Bool)0);

  dev = devlist_head;

  if (strlen (name))
    for (; dev; dev = dev->next)
      if (!strcmp (name, dev->devname))
	break;

  if (!dev) {
    DBG(1,"Unable to find device %s\n",name);
    return SANE_STATUS_INVAL;
  }

  DBG(1,"Found device %s\n",name);

  /* Now open the usb device */
  ret = sanei_usb_open (name, &(dev->dn));
  if (ret != SANE_STATUS_GOOD) {
    DBG(1,"Unable to open device %s\n",name);
    return ret;
  }

  /* Claim the first interface */
  ret = sanei_usb_claim_interface (dev->dn, 0);
  if (ret != SANE_STATUS_GOOD)
    {
      sanei_usb_close (dev->dn);
      /* if we cannot claim the interface, this is because
         someone else is using it */
      DBG(1,"Unable to claim scanner interface on device %s\n",name);
      return SANE_STATUS_DEVICE_BUSY;
    }
#ifdef HAVE_SANEI_USB_SET_TIMEOUT
  sanei_usb_set_timeout (30000);	/* 30s timeout */
#endif

  *h = dev;

  return SANE_STATUS_GOOD;
}
Ejemplo n.º 9
0
void
sane_close (SANE_Handle h)
{
  struct device_s *dev = (struct device_s *) h;

  /* Just in case if sane_cancel() is called
   * after starting a scan but not while a sane_read
   */
  if (dev->status == STATUS_CANCELING)
    {
       do_cancel(dev);
    }

  sanei_usb_release_interface (dev->dn, 0);
  sanei_usb_close (dev->dn);

}
Ejemplo n.º 10
0
/** close all devices
 * loop on all opened devices and close them
 * @param dn array of opened device number
 * @param expected number of devices to be closed
 * @return 1 on success, else 0
 */
static int
test_close_all (SANE_Int * dn, int expected)
{
  int closed = 0;
  int i;

  /* loop on detected devices and open them */
  for (i = 0; i < expected; i++)
    {
      /* close device */
      sanei_usb_close (dn[i]);
      closed++;
    }
  printf ("closed %d devices\n", closed);

  /* there should be any more opened devices */
  return count_opened (0);
}
Ejemplo n.º 11
0
/** will be called upon sane_exit
 */
static void u12if_shutdown( U12_Device *dev  )
{
	SANE_Int handle;
	TimerDef timer;

	DBG( _DBG_INFO, "Shutdown called (dev->fd=%d, %s)\n",
													dev->fd, dev->sane.name );
	if( SANE_STATUS_GOOD == sanei_usb_open( dev->sane.name, &handle )) {
		
    	dev->fd = handle;
		u12io_OpenScanPath( dev );

		u12hw_PutToIdleMode( dev );

		if( !(u12io_DataFromRegister( dev, REG_STATUS ) & _FLAG_PAPER)) {

			u12motor_PositionModuleToHome( dev );

			u12io_StartTimer( &timer, _SECOND * 20);
			do {
				if( u12io_DataFromRegister( dev, REG_STATUS ) & _FLAG_PAPER) {
					break;
				}
			} while( !u12io_CheckTimer( &timer ));
		}
		DBG( _DBG_INFO, "* Home position reached.\n" );

		if( 0 != dev->adj.lampOffOnEnd ) {

			DBG( _DBG_INFO, "* Switching lamp off...\n" );
			dev->regs.RD_ScanControl &= ~_SCAN_LAMPS_ON;
			u12io_DataToRegister(dev,REG_SCANCONTROL, dev->regs.RD_ScanControl );
		}

		u12io_CloseScanPath( dev );
		dev->fd = -1;
		sanei_usb_close( handle );
	}

#if 0
	usb_StopLampTimer( dev );
#endif
	DBG( _DBG_INFO, "Shutdown done.\n" );
}
Ejemplo n.º 12
0
void
usb_dev_close (struct device *dev)
{
  if (!dev)
    return;
  DBG (3, "%s: closing dev %p\n", __FUNCTION__, (void *)dev);

  /* finish all operations */
  if (dev->scanning) {
    dev->cancel = 1;
    /* flush READ_IMAGE data */
    if (dev->reading)
      sane_read(dev, NULL, 1, NULL);
    /* send cancel if not sent before */
    if (dev->state != SANE_STATUS_CANCELLED)
      ret_cancel(dev, 0);
  }

  sanei_usb_clear_halt (dev->dn);	/* unstall for next users */
  sanei_usb_close (dev->dn);
  dev->dn = -1;
}
Ejemplo n.º 13
0
/* Close device */
void
sane_close (SANE_Handle handle)
{
  struct scanner *s = (struct scanner *) handle;
  int i;
  if (s->bus == USB)
    {
      sanei_usb_release_interface (s->file, 0);
      sanei_usb_close (s->file);
    }
  else
    sanei_scsi_close (s->file);

  for (i = 1; i < NUM_OPTIONS; i++)
    {
      if (s->opt[i].type == SANE_TYPE_STRING && s->val[i].s)
	free (s->val[i].s);
    }
  if (s->data)
    free (s->data);
  free (s->buffer);
  free (s);

}
Ejemplo n.º 14
0
/* Open device, return the device handle */
SANE_Status
sane_open (SANE_String_Const devname, SANE_Handle * handle)
{
  unsigned i, j, id = 0;
  struct scanner *s;
  SANE_Int h, bus;
  SANE_Status st = SANE_STATUS_GOOD;
  if (!devlist)
    {
      st = sane_get_devices (NULL, 0);
      if (st)
	return st;
    }
  for (i = 0; devlist[i]; i++)
    {
      if (!strcmp (devlist[i]->name, devname))
	break;
    }
  if (!devlist[i])
    return SANE_STATUS_INVAL;
  for (j = 0; j < sizeof (known_devices) / sizeof (known_devices[0]); j++)
    {
      if (!strcmp (devlist[i]->model, known_devices[j].scanner.model))
	{
	  id = known_devices[j].id;
	  break;
	}
    }

  st = sanei_usb_open (devname, &h);

  if (st == SANE_STATUS_ACCESS_DENIED)
    return st;
  if (st)
    {
      st = sanei_scsi_open (devname, &h, kvs40xx_sense_handler, NULL);
      if (st)
	{
	  return st;
	}
      bus = SCSI;
    }
  else
    {
      bus = USB;
      st = sanei_usb_claim_interface (h, 0);
      if (st)
	{
	  sanei_usb_close (h);
	  return st;
	}
    }

  s = malloc (sizeof (struct scanner));
  if (!s)
    return SANE_STATUS_NO_MEM;
  memset (s, 0, sizeof (struct scanner));
  s->buffer = malloc (MAX_READ_DATA_SIZE + BULK_HEADER_SIZE);
  if (!s->buffer)
    return SANE_STATUS_NO_MEM;

  s->file = h;
  s->bus = bus;
  s->id = id;
  strcpy (s->name, devname);
  *handle = s;
  for (i = 0; i < 3; i++)
    {
      st = kvs40xx_test_unit_ready (s);
      if (st)
	{
	  if (s->bus == SCSI)
	    {
	      sanei_scsi_close (s->file);
	      st = sanei_scsi_open (devname, &h, kvs40xx_sense_handler, NULL);
	      if (st)
		return st;
	    }
	  else
	    {
	      sanei_usb_release_interface (s->file, 0);
	      sanei_usb_close (s->file);
	      st = sanei_usb_open (devname, &h);
	      if (st)
		return st;
	      st = sanei_usb_claim_interface (h, 0);
	      if (st)
		{
		  sanei_usb_close (h);
		  return st;
		}
	    }
	  s->file = h;
	}
      else
	break;
    }
  if (i == 3)
    return SANE_STATUS_DEVICE_BUSY;

  if (id == KV_S4085C || id == KV_S4065C)
    {
      char str[16];
      st = inquiry (s, str);
      if (st)
	goto err;
      if (id == KV_S4085C)
	s->id = !strcmp (str, "KV-S4085CL") ? KV_S4085CL : KV_S4085CW;
      else
	s->id = !strcmp (str, "KV-S4065CL") ? KV_S4065CL : KV_S4065CW;
    }
  kvs40xx_init_options (s);
  st = kvs40xx_set_timeout (s, s->val[FEED_TIMEOUT].w);
  if (st)
    goto err;

  return SANE_STATUS_GOOD;
err:
  sane_close (s);
  return st;
}
Ejemplo n.º 15
0
static int u12if_open( U12_Device *dev )
{
	char      devStr[50];
	int       result;
	SANE_Int  handle;
	SANE_Word vendor, product;
	SANE_Bool was_empty;

	DBG( _DBG_INFO, "u12if_open(%s,%s)\n", dev->name, dev->usbId );

	USB_devname[0] = '\0';

#ifdef _FAKE_DEVICE
	dev->name      = strdup( "auto" );
	dev->sane.name = dev->name;
	was_empty      = SANE_FALSE;

	result = SANE_STATUS_UNSUPPORTED;
#else
	if( !strcmp( dev->name, "auto" )) {

		if( dev->usbId[0] == '\0' ) {

			if( !usbDev_autodetect( &vendor, &product )) {
				DBG( _DBG_ERROR, "No supported device found!\n" );
				return -1;
			}

		} else {

			vendor  = strtol( &dev->usbId[0], 0, 0 );
			product = strtol( &dev->usbId[7], 0, 0 );

			sanei_usb_find_devices( vendor, product, u12if_usbattach );

			if( USB_devname[0] == '\0' ) {
				DBG( _DBG_ERROR, "No matching device found!\n" );
        		return -1;
			}
		}

		if( SANE_STATUS_GOOD != sanei_usb_open( USB_devname, &handle )) {
			return -1;
		}

		/* replace the old devname, so we are able to have multiple
         * auto-detected devices
         */
		free( dev->name );
		dev->name      = strdup( USB_devname );
		dev->sane.name = dev->name; 

	} else {

		if( SANE_STATUS_GOOD != sanei_usb_open( dev->name, &handle ))
    		return -1;
	}
	was_empty = SANE_FALSE;

	result = sanei_usb_get_vendor_product( handle, &vendor, &product );
#endif

	if( SANE_STATUS_GOOD == result ) {

		sprintf( devStr, "0x%04X-0x%04X", vendor, product );

		DBG(_DBG_INFO,"Vendor ID=0x%04X, Product ID=0x%04X\n",vendor,product);

		if( dev->usbId[0] != '\0' ) {
		
			if( 0 != strcmp( dev->usbId, devStr )) {
				DBG( _DBG_ERROR, "Specified Vendor and Product ID "
								 "doesn't match with the ones\n"
								 "in the config file\n" );
				sanei_usb_close( handle );
		        return -1;
			}
		} else {
			sprintf( dev->usbId, "0x%04X-0x%04X", vendor, product );
			was_empty = SANE_TRUE;
		}			

	} else {

		DBG( _DBG_INFO, "Can't get vendor & product ID from driver...\n" );

		/* if the ioctl stuff is not supported by the kernel and we have
		 * nothing specified, we have to give up...
		*/
		if( dev->usbId[0] == '\0' ) {
			DBG( _DBG_ERROR, "Cannot autodetect Vendor an Product ID, "
							 "please specify in config file.\n" );
			sanei_usb_close( handle );
			return -1;
		}

		vendor  = strtol( &dev->usbId[0], 0, 0 );
		product = strtol( &dev->usbId[7], 0, 0 );
		DBG( _DBG_INFO, "... using the specified: "
		                "0x%04X-0x%04X\n", vendor, product );
	}

	/* before accessing the scanner, check if supported!
	 */
	if( !u12if_IsDeviceSupported( dev )) {
		DBG( _DBG_ERROR, "Device >%s<, is not supported!\n", dev->usbId );
		sanei_usb_close( handle );
		return -1;
	}

	dev->mode = _PP_MODE_SPP;
	dev->fd   = handle;

	/* is it accessible ? */
	if( SANE_STATUS_GOOD != u12hw_CheckDevice( dev )) {
		dev->fd = -1;
		sanei_usb_close( handle );
		return -1;
	}

	DBG( _DBG_INFO, "Detected vendor & product ID: "
		                "0x%04X-0x%04X\n", vendor, product );

	if( was_empty )
		dev->usbId[0] = '\0';

	/* now initialize the device */
	if( SANE_STATUS_GOOD != u12_initDev( dev, handle, vendor )) {
		dev->fd = -1;
		sanei_usb_close( handle );
		return -1;
	}

	if( _PLUSTEK_VENID == vendor ) {
		if( dev->Tpa )
			dev->sane.model = "UT12";
	}
	
	dev->initialized = SANE_TRUE;
	return handle;
}
Ejemplo n.º 16
0
static SANE_Status
attach (SANE_String_Const devname, Mustek_Usb_Device ** devp,
	SANE_Bool may_wait)
{
  Mustek_Usb_Device *dev;
  SANE_Status status;
  Mustek_Type scanner_type;
  SANE_Int fd;

  DBG (5, "attach: start: devp %s NULL, may_wait = %d\n", devp ? "!=" : "==",
       may_wait);
  if (!devname)
    {
      DBG (1, "attach: devname == NULL\n");
      return SANE_STATUS_INVAL;
    }

  for (dev = first_dev; dev; dev = dev->next)
    if (strcmp (dev->sane.name, devname) == 0)
      {
	if (devp)
	  *devp = dev;
	DBG (4, "attach: device `%s' was already in device list\n", devname);
	return SANE_STATUS_GOOD;
      }

  DBG (4, "attach: trying to open device `%s'\n", devname);
  status = sanei_usb_open (devname, &fd);
  if (status != SANE_STATUS_GOOD)
    {
      DBG (3, "attach: couldn't open device `%s': %s\n", devname,
	   sane_strstatus (status));
      return status;
    }
  DBG (4, "attach: device `%s' successfully opened\n", devname);

  /* try to identify model */
  DBG (4, "attach: trying to identify device `%s'\n", devname);
  status = usb_low_identify_scanner (fd, &scanner_type);
  if (status != SANE_STATUS_GOOD)
    {
      DBG (1, "attach: device `%s' doesn't look like a supported scanner\n",
	   devname);
      sanei_usb_close (fd);
      return status;
    }
  sanei_usb_close (fd);
  if (scanner_type == MT_UNKNOWN)
    {
      DBG (3, "attach: warning: couldn't identify device `%s', must set "
	   "type manually\n", devname);
    }

  dev = malloc (sizeof (Mustek_Usb_Device));
  if (!dev)
    {
      DBG (1, "attach: couldn't malloc Mustek_Usb_Device\n");
      return SANE_STATUS_NO_MEM;
    }

  memset (dev, 0, sizeof (*dev));
  dev->name = strdup (devname);
  dev->sane.name = (SANE_String_Const) dev->name;
  dev->sane.vendor = "Mustek";
  switch (scanner_type)
    {
    case MT_1200CU:
      dev->sane.model = "1200 CU";
      break;
    case MT_1200CU_PLUS:
      dev->sane.model = "1200 CU Plus";
      break;
    case MT_1200USB:
      dev->sane.model = "1200 USB (unsupported)";
      break;
    case MT_1200UB:
      dev->sane.model = "1200 UB";
      break;
    case MT_600CU:
      dev->sane.model = "600 CU";
      break;
    case MT_600USB:
      dev->sane.model = "600 USB (unsupported)";
      break;
    default:
      dev->sane.model = "(unidentified)";
      break;
    }
  dev->sane.type = "flatbed scanner";

  dev->x_range.min = 0;
  dev->x_range.max = SANE_FIX (8.4 * MM_PER_INCH);
  dev->x_range.quant = 0;

  dev->y_range.min = 0;
  dev->y_range.max = SANE_FIX (11.7 * MM_PER_INCH);
  dev->y_range.quant = 0;

  dev->max_height = 11.7 * 300;
  dev->max_width = 8.4 * 300;
  dev->dpi_range.min = SANE_FIX (50);
  dev->dpi_range.max = SANE_FIX (600);
  dev->dpi_range.quant = SANE_FIX (1);

  status = usb_high_scan_init (dev);
  if (status != SANE_STATUS_GOOD)
    {
      DBG (1, "attach: usb_high_scan_init returned status: %s\n",
	   sane_strstatus (status));
      free (dev);
      return status;
    }
  dev->chip->scanner_type = scanner_type;
  dev->chip->max_block_size = max_block_size;

  DBG (2, "attach: found %s %s %s at %s\n", dev->sane.vendor, dev->sane.type,
       dev->sane.model, dev->sane.name);
  ++num_devices;
  dev->next = first_dev;
  first_dev = dev;

  if (devp)
    *devp = dev;

  DBG (5, "attach: exit\n");
  return SANE_STATUS_GOOD;
}
Ejemplo n.º 17
0
/* Close the scanner. */
static void
sanei_umaxusb_close (int fd)
{
	sanei_usb_close(fd);
}