Beispiel #1
0
/* 
   Find our devices
 */
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
  char config_line[PATH_MAX];
  size_t len;
  FILE *fp;

  DBG_INIT ();

#if 0
  DBG_LEVEL = 10;
#endif

  DBG (2, "sane_init: version_code %s 0, authorize %s 0\n",
       version_code == 0 ? "=" : "!=", authorize == 0 ? "=" : "!=");
  DBG (1, "sane_init: SANE Canon630u backend version %d.%d.%d from %s\n",
       SANE_CURRENT_MAJOR, V_MINOR, BUILD, PACKAGE_STRING);

  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);

  sanei_usb_init ();

  fp = sanei_config_open (CANONUSB_CONFIG_FILE);
  if (!fp)
    {
      /* no config-file: try these */
      attach_scanner ("/dev/scanner", 0);
      attach_scanner ("/dev/usbscanner", 0);
      attach_scanner ("/dev/usb/scanner", 0);
      return SANE_STATUS_GOOD;
    }

  DBG (3, "reading configure file %s\n", CANONUSB_CONFIG_FILE);

  while (sanei_config_read (config_line, sizeof (config_line), fp))
    {
      if (config_line[0] == '#')
	continue;		/* ignore line comments */

      len = strlen (config_line);

      if (!len)
	continue;		/* ignore empty lines */

      DBG (4, "attach_matching_devices(%s)\n", config_line);
      sanei_usb_attach_matching_devices (config_line, attach_one);
    }

  DBG (4, "finished reading configure file\n");

  fclose (fp);

  return SANE_STATUS_GOOD;
}
Beispiel #2
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback __sane_unused__ authorize)
{
  SANE_Status 	ret;
  SANE_Word	vendor_id, product_id;
  
  DBG_INIT();
  
  DBG (1, "SANE backed for HP ScanJet 4500C/4570C/5500C/5550C/5590/7650 %u.%u.%u\n",
       SANE_CURRENT_MAJOR, V_MINOR, BUILD);
  DBG (1, "(c) Ilia Sotnikov <*****@*****.**>\n");

  if (version_code)
    *version_code = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, V_MINOR, BUILD);

  sanei_usb_init();

  sanei_usb_set_timeout (USB_TIMEOUT);

  scanners_list = NULL;

  ret = hp5590_vendor_product_id (SCANNER_HP4570, &vendor_id, &product_id);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp4570);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = hp5590_vendor_product_id (SCANNER_HP5550, &vendor_id, &product_id);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp5550);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = hp5590_vendor_product_id (SCANNER_HP5590, &vendor_id, &product_id);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp5590);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = hp5590_vendor_product_id (SCANNER_HP7650, &vendor_id, &product_id);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  ret = sanei_usb_find_devices (vendor_id, product_id, attach_hp7650);
  if (ret != SANE_STATUS_GOOD)
    return ret;

  return SANE_STATUS_GOOD;
}
Beispiel #3
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback cb)
{
  DBG_INIT ();
  DBG (2, "sane_init: Xerox backend (build %d), version %s null, authorize %s null\n", BACKEND_BUILD,
       (version_code) ? "!=" : "==", (cb) ? "!=" : "==");

  if (version_code)
    *version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, BACKEND_BUILD);

  sanei_usb_init ();
  return SANE_STATUS_GOOD;
}
Beispiel #4
0
SANE_Status
sane_init (SANE_Int * version_code,
	   SANE_Auth_Callback __sane_unused__ authorize)
{

  if (version_code != NULL)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);

  DBG_INIT();

  sanei_usb_init ();

  return SANE_STATUS_GOOD;
}
Beispiel #5
0
SANE_Status
sane_init (SANE_Int __sane_unused__ * version_code,
	   SANE_Auth_Callback __sane_unused__ authorize)
{
  DBG_INIT ();
  DBG (DBG_INFO, "This is panasonic kvs40xx driver\n");

  *version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 1);

  /* Initialize USB */
  sanei_usb_init ();

  return SANE_STATUS_GOOD;
}
Beispiel #6
0
/* Get all supported scanners, and store into g_devlist */
SANE_Status
kv_usb_enum_devices (void)
{
  int cnt = 0;
  int i;
  PKV_DEV pd;
  char usb_str[18];

  DBG (DBG_proc, "kv_usb_enum_devices: enter\n");

  sanei_usb_init();

  sprintf(usb_str,"usb %#04x %#04x",VENDOR_ID,KV_S1020C);
  sanei_usb_attach_matching_devices(usb_str, attach_scanner_usb);

  sprintf(usb_str,"usb %#04x %#04x",VENDOR_ID,KV_S1025C);
  sanei_usb_attach_matching_devices(usb_str, attach_scanner_usb);

  sprintf(usb_str,"usb %#04x %#04x",VENDOR_ID,KV_S1045C);
  sanei_usb_attach_matching_devices(usb_str, attach_scanner_usb);

  for (pd = g_devices; pd; pd=pd->next) {
    cnt++;
  }

  g_devlist =
    (const SANE_Device **) malloc (sizeof (SANE_Device *) * (cnt + 1));
  if (g_devlist == NULL)
    {
      DBG (DBG_proc,
	   "kv_usb_enum_devices: leave on error " " --out of memory\n");
      return SANE_STATUS_NO_MEM;
    }

  pd = g_devices;
  for (i = 0; i < cnt; i++)
    {
      g_devlist[i] = (const SANE_Device *) &pd->sane;
      pd = pd->next;
    }
  g_devlist[cnt] = 0;

  DBG (DBG_proc, "kv_usb_enum_devices: leave with %d devices.\n", cnt);

  return SANE_STATUS_GOOD;
}
Beispiel #7
0
/*
 * Called by SANE initially.
 * 
 * From the SANE spec:
 * This function must be called before any other SANE function can be
 * called. The behavior of a SANE backend is undefined if this
 * function is not called first. The version code of the backend is
 * returned in the value pointed to by version_code. If that pointer
 * is NULL, no version code is returned. Argument authorize is either
 * a pointer to a function that is invoked when the backend requires
 * authentication for a specific resource or NULL if the frontend does
 * not support authentication.
 */
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
    authorize = authorize;        /* get rid of compiler warning */
  
    DBG_INIT ();
    DBG (10, "sane_init: start\n");
  
    sanei_usb_init();
  
    if (version_code)
      *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);
  
    DBG (5, "sane_init: cardscan backend %d.%d.%d, from %s\n",
      SANE_CURRENT_MAJOR, V_MINOR, BUILD, PACKAGE_STRING);
  
    DBG (10, "sane_init: finish\n");
  
    return SANE_STATUS_GOOD;
}
Beispiel #8
0
/** test sanei_usb_init()
 * calls sanei_usb_init
 * @param expected expected use count
 * @return 1 on success, else 0
 */
static int
test_init (int expected)
{
  /* initialize USB */
  printf ("%s starting ...\n", __func__);
  sanei_usb_init ();
  if (initialized == 0)
    {
      printf ("ERROR: sanei_usb not initialized!\n");
      return 0;
    }
  if (initialized != expected)
    {
      printf ("ERROR: incorrect use count, expected %d, got %d!\n", expected,
	      initialized);
      return 0;
    }

  printf ("sanei_usb initialized, use count is %d ...\n", initialized);
  printf ("%s success\n\n", __func__);
  return 1;
}
Beispiel #9
0
SANE_Status
sane_init (SANE_Int * piVersion, SANE_Auth_Callback pfnAuth)
{
  FILE *conf_fp;		/* Config file stream  */
  SANE_Char line[PATH_MAX];
  SANE_Char *str = NULL;
  SANE_String_Const proper_str;
  int nline = 0;

  /* prevent compiler from complaing about unused parameters */
  pfnAuth = pfnAuth;

  strcpy(usb_devfile, "/dev/usb/scanner0");
  _pFirstSaneDev = 0;
  iNumSaneDev = 0;

  InitHp5400_internal();


  DBG_INIT ();

  HP5400_DBG (DBG_MSG, "sane_init: SANE hp5400 backend version %d.%d-%d (from %s)\n",
       SANE_CURRENT_MAJOR, V_MINOR, BUILD, PACKAGE_STRING);

  sanei_usb_init ();

  conf_fp = sanei_config_open (HP5400_CONFIG_FILE);

  iNumSaneDev = 0;

  if (conf_fp)
    {
      HP5400_DBG (DBG_MSG, "Reading config file\n");

      while (sanei_config_read (line, sizeof (line), conf_fp))
	{
	  ++nline;

	  if (str)
	    {
	      free (str);
	    }

	  proper_str = sanei_config_get_string (line, &str);

	  /* Discards white lines and comments */
	  if (!str || proper_str == line || str[0] == '#')
	    {
	      HP5400_DBG (DBG_MSG, "Discarding line %d\n", nline);
	    }
	  else
	    {
	      /* If line's not blank or a comment, then it's the device
	       * filename or a usb directive. */
	      HP5400_DBG (DBG_MSG, "Trying to attach %s\n", line);
	      sanei_usb_attach_matching_devices (line, attach_one_device);
	    }
	}			/* while */
      fclose (conf_fp);
    }
  else
    {
      HP5400_DBG (DBG_ERR, "Unable to read config file \"%s\": %s\n",
	   HP5400_CONFIG_FILE, strerror (errno));
      HP5400_DBG (DBG_MSG, "Using default built-in values\n");
      attach_one_device (usb_devfile);
    }

  if (piVersion != NULL)
    {
      *piVersion = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);
    }


  return SANE_STATUS_GOOD;
}
Beispiel #10
0
SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
  SANE_Char line[PATH_MAX];
  SANE_Char *word, *end;
  SANE_String_Const cp;
  SANE_Int linenumber;
  FILE *fp;

  DBG_INIT ();
  DBG (2, "SANE Mustek USB backend version %d.%d build %d from %s\n", SANE_CURRENT_MAJOR,
       V_MINOR, BUILD, PACKAGE_STRING);

  if (version_code)
    *version_code = SANE_VERSION_CODE (SANE_CURRENT_MAJOR, V_MINOR, BUILD);

  DBG (5, "sane_init: authorize %s null\n", authorize ? "!=" : "==");


  num_devices = 0;
  first_dev = 0;
  first_handle = 0;
  devlist = 0;
  new_dev = 0;
  new_dev_len = 0;
  new_dev_alloced = 0;

  sanei_usb_init ();

  fp = sanei_config_open (MUSTEK_USB_CONFIG_FILE);
  if (!fp)
    {
      /* default to /dev/usb/scanner instead of insisting on config file */
      DBG (3, "sane_init: couldn't open config file `%s': %s. Using "
	   "/dev/usb/scanner directly\n", MUSTEK_USB_CONFIG_FILE,
	   strerror (errno));
      attach ("/dev/usb/scanner", 0, SANE_FALSE);
      return SANE_STATUS_GOOD;
    }
  linenumber = 0;
  DBG (4, "sane_init: reading config file `%s'\n", MUSTEK_USB_CONFIG_FILE);

  while (sanei_config_read (line, sizeof (line), fp))
    {
      word = 0;
      linenumber++;

      cp = sanei_config_get_string (line, &word);
      if (!word || cp == line)
	{
	  DBG (5, "sane_init: config file line %d: ignoring empty line\n",
	       linenumber);
	  if (word)
	    free (word);
	  continue;
	}
      if (word[0] == '#')
	{
	  DBG (5, "sane_init: config file line %d: ignoring comment line\n",
	       linenumber);
	  free (word);
	  continue;
	}

      if (strcmp (word, "option") == 0)
	{
	  free (word);
	  word = 0;
	  cp = sanei_config_get_string (cp, &word);

	  if (!word)
	    {
	      DBG (1, "sane_init: config file line %d: missing quotation mark?\n",
		   linenumber);
	      continue;
	    }

	  if (strcmp (word, "max_block_size") == 0)
	    {
	      free (word);
	      word = 0;
	      cp = sanei_config_get_string (cp, &word);
	      if (!word)
		{
		  DBG (1, "sane_init: config file line %d: missing quotation mark?\n",
		       linenumber);
		  continue;
		}

	      errno = 0;
	      max_block_size = strtol (word, &end, 0);
	      if (end == word)
		{
		  DBG (3, "sane-init: config file line %d: max_block_size "
		       "must have a parameter; using 8192 bytes\n",
		       linenumber);
		  max_block_size = 8192;
		}
	      if (errno)
		{
		  DBG (3,
		       "sane-init: config file line %d: max_block_size `%s' "
		       "is invalid (%s); using 8192 bytes\n", linenumber,
		       word, strerror (errno));
		  max_block_size = 8192;
		}
	      else
		{
		  DBG (3,
		       "sane_init: config file line %d: max_block_size set "
		       "to %d bytes\n", linenumber, max_block_size);
		}
	      if (word)
		free (word);
	      word = 0;
	    }
	  else if (strcmp (word, "1200ub") == 0)
	    {
	      if (new_dev_len > 0)
		{
		  /* this is a 1200 UB */
		  new_dev[new_dev_len - 1]->chip->scanner_type = MT_1200UB;
		  new_dev[new_dev_len - 1]->sane.model = "1200 UB";
		  DBG (3, "sane_init: config file line %d: `%s' is a Mustek "
		       "1200 UB\n", linenumber,
		       new_dev[new_dev_len - 1]->sane.name);
		}
	      else
		{
		  DBG (3, "sane_init: config file line %d: option "
		       "1200ub ignored, was set before any device "
		       "name\n", linenumber);
		}
	      if (word)
		free (word);
	      word = 0;
	    }
	  else if (strcmp (word, "1200cu") == 0)
	    {
	      if (new_dev_len > 0)
		{
		  /* this is a 1200 CU */
		  new_dev[new_dev_len - 1]->chip->scanner_type = MT_1200CU;
		  new_dev[new_dev_len - 1]->sane.model = "1200 CU";
		  DBG (3, "sane_init: config file line %d: `%s' is a Mustek "
		       "1200 CU\n", linenumber,
		       new_dev[new_dev_len - 1]->sane.name);
		}
	      else
		{
		  DBG (3, "sane_init: config file line %d: option "
		       "1200cu ignored, was set before any device "
		       "name\n", linenumber);
		}
	      if (word)
		free (word);
	      word = 0;
	    }
	  else if (strcmp (word, "1200cu_plus") == 0)
	    {
	      if (new_dev_len > 0)
		{
		  /* this is a 1200 CU Plus */
		  new_dev[new_dev_len - 1]->chip->scanner_type
		    = MT_1200CU_PLUS;
		  new_dev[new_dev_len - 1]->sane.model = "1200 CU Plus";
		  DBG (3, "sane_init: config file line %d: `%s' is a Mustek "
		       "1200 CU Plus\n", linenumber,
		       new_dev[new_dev_len - 1]->sane.name);
		}
	      else
		{
		  DBG (3, "sane_init: config file line %d: option "
		       "1200cu_plus ignored, was set before any device "
		       "name\n", linenumber);
		}
	      if (word)
		free (word);
	      word = 0;
	    }
	  else if (strcmp (word, "600cu") == 0)
	    {
	      if (new_dev_len > 0)
		{
		  /* this is a 600 CU */
		  new_dev[new_dev_len - 1]->chip->scanner_type = MT_600CU;
		  new_dev[new_dev_len - 1]->sane.model = "600 CU";
		  DBG (3, "sane_init: config file line %d: `%s' is a Mustek "
		       "600 CU\n", linenumber,
		       new_dev[new_dev_len - 1]->sane.name);
		}
	      else
		{
		  DBG (3, "sane_init: config file line %d: option "
		       "600cu ignored, was set before any device "
		       "name\n", linenumber);
		}
	      if (word)
		free (word);
	      word = 0;
	    }
	  else
	    {
	      DBG (3, "sane_init: config file line %d: option "
		   "%s is unknown\n", linenumber, word);
	      if (word)
		free (word);
	      word = 0;
	    }
	}
      else
	{
	  new_dev_len = 0;
	  DBG (4, "sane_init: config file line %d: trying to attach `%s'\n",
	       linenumber, line);
	  sanei_usb_attach_matching_devices (line, attach_one_device);
	  if (word)
	    free (word);
	  word = 0;
	}
    }

  if (new_dev_alloced > 0)
    {
      new_dev_len = new_dev_alloced = 0;
      free (new_dev);
    }

  fclose (fp);
  DBG (5, "sane_init: exit\n");

  return SANE_STATUS_GOOD;
}