2006-05-26 07:49:24 +00:00
|
|
|
/* SANE - Scanner Access Now Easy.
|
2008-10-14 19:48:59 +00:00
|
|
|
* For limitations, see function sanei_usb_get_vendor_product().
|
2006-05-26 07:49:24 +00:00
|
|
|
|
2015-04-03 17:19:02 +00:00
|
|
|
Copyright (C) 2011-2015 Rolf Bensch <rolf at bensch hyphen online dot de>
|
2007-04-09 20:41:25 +00:00
|
|
|
Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de>
|
2006-05-26 07:49:24 +00:00
|
|
|
|
|
|
|
This file is part of the SANE package.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
As a special exception, the authors of SANE give permission for
|
|
|
|
additional uses of the libraries contained in this release of SANE.
|
|
|
|
|
|
|
|
The exception is that, if you link a SANE library with other files
|
|
|
|
to produce an executable, this does not by itself cause the
|
|
|
|
resulting executable to be covered by the GNU General Public
|
|
|
|
License. Your use of that executable is in no way restricted on
|
|
|
|
account of linking the SANE library code into it.
|
|
|
|
|
|
|
|
This exception does not, however, invalidate any other reasons why
|
|
|
|
the executable file might be covered by the GNU General Public
|
|
|
|
License.
|
|
|
|
|
|
|
|
If you submit changes to SANE to the maintainers to be included in
|
|
|
|
a subsequent release, you agree by submitting the changes that
|
|
|
|
those changes may be distributed with this exception intact.
|
|
|
|
|
|
|
|
If you write modifications of your own for SANE, it is your choice
|
|
|
|
whether to permit this exception to apply to your modifications.
|
|
|
|
If you do not wish that, delete this exception notice.
|
|
|
|
*/
|
|
|
|
#include "../include/sane/config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2008-10-14 19:48:59 +00:00
|
|
|
#include <stdio.h>
|
2006-05-26 07:49:24 +00:00
|
|
|
#include <limits.h> /* INT_MAX */
|
|
|
|
|
|
|
|
#include "pixma_rename.h"
|
|
|
|
#include "pixma_common.h"
|
|
|
|
#include "pixma_io.h"
|
2008-10-14 19:48:59 +00:00
|
|
|
#include "pixma_bjnp.h"
|
2006-05-26 07:49:24 +00:00
|
|
|
|
|
|
|
#include "../include/sane/sanei_usb.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
# define UNUSED(v) (void) v
|
|
|
|
#else
|
|
|
|
# define UNUSED(v)
|
|
|
|
#endif
|
|
|
|
|
2009-04-05 19:49:41 +00:00
|
|
|
/* MAC OS X does not support timeouts in darwin/libusb interrupt reads
|
|
|
|
* This is a very basic turnaround for MAC OS X
|
|
|
|
* Button scan will not work with this wrapper */
|
|
|
|
#ifdef __APPLE__
|
|
|
|
# define sanei_usb_read_int sanei_usb_read_bulk
|
|
|
|
#endif
|
|
|
|
|
2006-08-27 12:39:18 +00:00
|
|
|
|
2006-05-26 07:49:24 +00:00
|
|
|
struct pixma_io_t
|
|
|
|
{
|
|
|
|
pixma_io_t *next;
|
2008-10-14 19:48:59 +00:00
|
|
|
int interface;
|
|
|
|
SANE_Int dev;
|
2006-05-26 07:49:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct scanner_info_t
|
|
|
|
{
|
|
|
|
struct scanner_info_t *next;
|
|
|
|
char *devname;
|
2008-10-14 19:48:59 +00:00
|
|
|
int interface;
|
2006-05-26 07:49:24 +00:00
|
|
|
const pixma_config_t *cfg;
|
|
|
|
char serial[PIXMA_MAX_ID_LEN + 1]; /* "xxxxyyyy_zzzzzzz..."
|
|
|
|
x = vid, y = pid, z = serial */
|
|
|
|
} scanner_info_t;
|
|
|
|
|
2008-10-14 19:48:59 +00:00
|
|
|
#define INT_USB 0
|
|
|
|
#define INT_BJNP 1
|
2006-05-26 07:49:24 +00:00
|
|
|
|
|
|
|
static scanner_info_t *first_scanner = NULL;
|
|
|
|
static pixma_io_t *first_io = NULL;
|
|
|
|
static unsigned nscanners;
|
|
|
|
|
|
|
|
|
|
|
|
static scanner_info_t *
|
|
|
|
get_scanner_info (unsigned devnr)
|
|
|
|
{
|
|
|
|
scanner_info_t *si;
|
|
|
|
for (si = first_scanner; si && devnr != 0; --devnr, si = si->next)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return si;
|
|
|
|
}
|
|
|
|
|
2008-10-14 19:48:59 +00:00
|
|
|
static const struct pixma_config_t *lookup_scanner(const char *makemodel,
|
|
|
|
const struct pixma_config_t *const pixma_devices[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const struct pixma_config_t *cfg;
|
|
|
|
char *match;
|
|
|
|
|
|
|
|
for (i = 0; pixma_devices[i]; i++)
|
|
|
|
{
|
|
|
|
/* loop through the device classes (mp150, mp730 etc) */
|
|
|
|
for (cfg = pixma_devices[i]; cfg->name; cfg++)
|
|
|
|
{
|
|
|
|
/* loop through devices in class */
|
|
|
|
if ((match = strcasestr (makemodel, cfg->model)) != NULL)
|
|
|
|
{
|
|
|
|
/* possible match found, make sure it is not a partial match */
|
|
|
|
/* MP600 and MP600R are different models! */
|
2009-10-20 16:22:45 +00:00
|
|
|
/* some models contain ranges, so check for a '-' too */
|
2009-10-20 16:11:45 +00:00
|
|
|
|
2008-10-14 19:48:59 +00:00
|
|
|
if ((match[strlen(cfg->model)] == ' ') ||
|
2009-10-20 16:11:45 +00:00
|
|
|
(match[strlen(cfg->model)] == '\0') ||
|
|
|
|
(match[strlen(cfg->model)] == '-'))
|
2008-10-14 19:48:59 +00:00
|
|
|
{
|
2013-01-10 20:10:41 +00:00
|
|
|
pixma_dbg (3, "Scanner model found: Name %s(%s) matches %s\n", cfg->model, cfg->name, makemodel);
|
2008-10-14 19:48:59 +00:00
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
}
|
2013-01-10 20:10:41 +00:00
|
|
|
pixma_dbg (20, "Scanner model %s(%s) not found, giving up! %s\n", cfg->model, cfg->name, makemodel);
|
2008-10-14 19:48:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-26 07:49:24 +00:00
|
|
|
static SANE_Status
|
|
|
|
attach (SANE_String_Const devname)
|
|
|
|
{
|
|
|
|
scanner_info_t *si;
|
|
|
|
|
|
|
|
si = (scanner_info_t *) calloc (1, sizeof (*si));
|
|
|
|
if (!si)
|
|
|
|
return SANE_STATUS_NO_MEM;
|
|
|
|
si->devname = strdup (devname);
|
|
|
|
if (!si->devname)
|
|
|
|
return SANE_STATUS_NO_MEM;
|
2008-10-14 19:48:59 +00:00
|
|
|
si -> interface = INT_USB;
|
|
|
|
si->next = first_scanner;
|
|
|
|
first_scanner = si;
|
|
|
|
nscanners++;
|
|
|
|
return SANE_STATUS_GOOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SANE_Status
|
|
|
|
attach_bjnp (SANE_String_Const devname, SANE_String_Const makemodel,
|
|
|
|
SANE_String_Const serial,
|
|
|
|
const struct pixma_config_t *const pixma_devices[])
|
|
|
|
{
|
|
|
|
scanner_info_t *si;
|
|
|
|
const pixma_config_t *cfg;
|
2013-02-09 15:56:40 +00:00
|
|
|
SANE_Status error;
|
2008-10-22 20:35:25 +00:00
|
|
|
|
2008-10-14 19:48:59 +00:00
|
|
|
si = (scanner_info_t *) calloc (1, sizeof (*si));
|
|
|
|
if (!si)
|
|
|
|
return SANE_STATUS_NO_MEM;
|
|
|
|
si->devname = strdup (devname);
|
|
|
|
if (!si->devname)
|
|
|
|
return SANE_STATUS_NO_MEM;
|
|
|
|
if ((cfg = lookup_scanner(makemodel, pixma_devices)) == (struct pixma_config_t *)NULL)
|
2013-02-09 15:56:40 +00:00
|
|
|
error = SANE_STATUS_INVAL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
si->cfg = cfg;
|
|
|
|
sprintf(si->serial, "%s_%s", cfg->model, serial);
|
|
|
|
si -> interface = INT_BJNP;
|
|
|
|
si->next = first_scanner;
|
|
|
|
first_scanner = si;
|
|
|
|
nscanners++;
|
|
|
|
error = SANE_STATUS_GOOD;
|
|
|
|
}
|
|
|
|
return error;
|
2006-05-26 07:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_scanner_list (void)
|
|
|
|
{
|
|
|
|
scanner_info_t *si = first_scanner;
|
|
|
|
while (si)
|
|
|
|
{
|
|
|
|
scanner_info_t *temp = si;
|
|
|
|
free (si->devname);
|
|
|
|
si = si->next;
|
|
|
|
free (temp);
|
|
|
|
}
|
|
|
|
nscanners = 0;
|
|
|
|
first_scanner = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SANE_Status
|
|
|
|
get_descriptor (SANE_Int dn, SANE_Int type, SANE_Int descidx,
|
|
|
|
SANE_Int index, SANE_Int length, SANE_Byte * data)
|
|
|
|
{
|
|
|
|
return sanei_usb_control_msg (dn, 0x80, USB_REQ_GET_DESCRIPTOR,
|
|
|
|
((type & 0xff) << 8) | (descidx & 0xff),
|
|
|
|
index, length, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SANE_Status
|
|
|
|
get_string_descriptor (SANE_Int dn, SANE_Int index, SANE_Int lang,
|
|
|
|
SANE_Int length, SANE_Byte * data)
|
|
|
|
{
|
|
|
|
return get_descriptor (dn, USB_DT_STRING, index, lang, length, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
u16tohex (uint16_t x, char *str)
|
|
|
|
{
|
|
|
|
static const char hdigit[16] =
|
|
|
|
{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
|
2008-02-17 15:49:43 +00:00
|
|
|
'E', 'F'
|
2008-10-14 19:48:59 +00:00
|
|
|
};
|
2006-05-26 07:49:24 +00:00
|
|
|
str[0] = hdigit[(x >> 12) & 0xf];
|
|
|
|
str[1] = hdigit[(x >> 8) & 0xf];
|
|
|
|
str[2] = hdigit[(x >> 4) & 0xf];
|
|
|
|
str[3] = hdigit[x & 0xf];
|
|
|
|
str[4] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
read_serial_number (scanner_info_t * si)
|
|
|
|
{
|
|
|
|
uint8_t unicode[2 * (PIXMA_MAX_ID_LEN - 9) + 2];
|
|
|
|
uint8_t ddesc[18];
|
2013-02-09 15:56:40 +00:00
|
|
|
int iSerialNumber;
|
2006-05-26 07:49:24 +00:00
|
|
|
SANE_Int usb;
|
|
|
|
char *serial = si->serial;
|
|
|
|
|
|
|
|
u16tohex (si->cfg->vid, serial);
|
|
|
|
u16tohex (si->cfg->pid, serial + 4);
|
|
|
|
|
|
|
|
if (SANE_STATUS_GOOD != sanei_usb_open (si->devname, &usb))
|
|
|
|
return;
|
|
|
|
if (get_descriptor (usb, USB_DT_DEVICE, 0, 0, 18, ddesc)
|
|
|
|
!= SANE_STATUS_GOOD)
|
|
|
|
goto done;
|
|
|
|
iSerialNumber = ddesc[16];
|
|
|
|
if (iSerialNumber != 0)
|
|
|
|
{
|
2013-02-09 15:56:40 +00:00
|
|
|
int i, len;
|
|
|
|
SANE_Status status;
|
|
|
|
|
2010-04-12 20:45:58 +00:00
|
|
|
/*int iSerialNumber = ddesc[16];*/
|
2007-04-09 20:41:25 +00:00
|
|
|
/* Read the first language code. Assumed that there is at least one. */
|
2006-05-26 07:49:24 +00:00
|
|
|
if (get_string_descriptor (usb, 0, 0, 4, unicode) != SANE_STATUS_GOOD)
|
2008-10-14 19:48:59 +00:00
|
|
|
goto done;
|
2007-04-09 20:41:25 +00:00
|
|
|
/* Read the serial number string. */
|
2008-10-14 19:48:59 +00:00
|
|
|
status = get_string_descriptor (usb, iSerialNumber,
|
|
|
|
unicode[3] * 256 + unicode[2],
|
|
|
|
sizeof (unicode), unicode);
|
2006-05-26 07:49:24 +00:00
|
|
|
if (status != SANE_STATUS_GOOD)
|
2008-10-14 19:48:59 +00:00
|
|
|
goto done;
|
2006-05-26 07:49:24 +00:00
|
|
|
/* Assumed charset: Latin1 */
|
|
|
|
len = unicode[0];
|
|
|
|
if (len > (int) sizeof (unicode))
|
2008-10-14 19:48:59 +00:00
|
|
|
{
|
|
|
|
len = sizeof (unicode);
|
|
|
|
PDBG (pixma_dbg (1, "WARNING:Truncated serial number\n"));
|
|
|
|
}
|
|
|
|
serial[8] = '_';
|
|
|
|
for (i = 2; i < len; i += 2)
|
|
|
|
{
|
|
|
|
serial[9 + i / 2 - 1] = unicode[i];
|
|
|
|
}
|
2006-05-26 07:49:24 +00:00
|
|
|
serial[9 + i / 2 - 1] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PDBG (pixma_dbg (1, "WARNING:No serial number\n"));
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
sanei_usb_close (usb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
map_error (SANE_Status ss)
|
|
|
|
{
|
|
|
|
switch (ss)
|
|
|
|
{
|
|
|
|
case SANE_STATUS_GOOD:
|
|
|
|
return 0;
|
|
|
|
case SANE_STATUS_UNSUPPORTED:
|
2006-08-27 12:39:18 +00:00
|
|
|
return PIXMA_ENODEV;
|
2006-05-26 07:49:24 +00:00
|
|
|
case SANE_STATUS_DEVICE_BUSY:
|
2006-08-27 12:39:18 +00:00
|
|
|
return PIXMA_EBUSY;
|
2006-05-26 07:49:24 +00:00
|
|
|
case SANE_STATUS_INVAL:
|
2006-08-27 12:39:18 +00:00
|
|
|
return PIXMA_EINVAL;
|
|
|
|
case SANE_STATUS_IO_ERROR:
|
|
|
|
return PIXMA_EIO;
|
|
|
|
case SANE_STATUS_NO_MEM:
|
|
|
|
return PIXMA_ENOMEM;
|
|
|
|
case SANE_STATUS_ACCESS_DENIED:
|
|
|
|
return PIXMA_EACCES;
|
|
|
|
case SANE_STATUS_CANCELLED:
|
2008-05-29 20:03:35 +00:00
|
|
|
return PIXMA_ECANCELED;
|
2006-05-26 07:49:24 +00:00
|
|
|
case SANE_STATUS_JAMMED:
|
2008-05-29 20:03:35 +00:00
|
|
|
return PIXMA_EPAPER_JAMMED;
|
2006-05-26 07:49:24 +00:00
|
|
|
case SANE_STATUS_COVER_OPEN:
|
2008-05-29 20:03:35 +00:00
|
|
|
return PIXMA_ECOVER_OPEN;
|
|
|
|
case SANE_STATUS_NO_DOCS:
|
|
|
|
return PIXMA_ENO_PAPER;
|
|
|
|
case SANE_STATUS_EOF:
|
2009-03-12 11:13:37 +00:00
|
|
|
return PIXMA_EOF;
|
2009-04-12 19:40:31 +00:00
|
|
|
#ifdef SANE_STATUS_HW_LOCKED
|
2008-06-25 20:54:16 +00:00
|
|
|
case SANE_STATUS_HW_LOCKED: /* unused by pixma */
|
2009-04-12 19:40:31 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SANE_STATUS_WARMING_UP
|
2008-05-29 20:03:35 +00:00
|
|
|
case SANE_STATUS_WARMING_UP: /* unused by pixma */
|
2009-04-12 19:40:31 +00:00
|
|
|
#endif
|
2006-08-27 12:39:18 +00:00
|
|
|
break;
|
2006-05-26 07:49:24 +00:00
|
|
|
}
|
2006-08-27 12:39:18 +00:00
|
|
|
PDBG (pixma_dbg (1, "BUG:Unmapped SANE Status code %d\n", ss));
|
|
|
|
return PIXMA_EIO; /* should not happen */
|
2006-05-26 07:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
pixma_io_init (void)
|
|
|
|
{
|
|
|
|
sanei_usb_init ();
|
2008-10-14 19:48:59 +00:00
|
|
|
sanei_bjnp_init();
|
2006-05-26 07:49:24 +00:00
|
|
|
nscanners = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pixma_io_cleanup (void)
|
|
|
|
{
|
|
|
|
while (first_io)
|
|
|
|
pixma_disconnect (first_io);
|
|
|
|
clear_scanner_list ();
|
|
|
|
}
|
|
|
|
|
2006-08-27 12:39:18 +00:00
|
|
|
unsigned
|
2008-10-25 14:56:11 +00:00
|
|
|
pixma_collect_devices (const char **conf_devices,
|
|
|
|
const struct pixma_config_t *const pixma_devices[])
|
2006-05-26 07:49:24 +00:00
|
|
|
{
|
|
|
|
unsigned i, j;
|
2008-10-14 19:48:59 +00:00
|
|
|
struct scanner_info_t *si;
|
|
|
|
const struct pixma_config_t *cfg;
|
2006-05-26 07:49:24 +00:00
|
|
|
|
|
|
|
clear_scanner_list ();
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; pixma_devices[i]; i++)
|
|
|
|
{
|
|
|
|
for (cfg = pixma_devices[i]; cfg->name; cfg++)
|
2008-10-14 19:48:59 +00:00
|
|
|
{
|
|
|
|
sanei_usb_find_devices (cfg->vid, cfg->pid, attach);
|
|
|
|
si = first_scanner;
|
|
|
|
while (j < nscanners)
|
|
|
|
{
|
|
|
|
PDBG (pixma_dbg (3, "pixma_collect_devices() found %s at %s\n",
|
|
|
|
cfg->name, si->devname));
|
|
|
|
si->cfg = cfg;
|
|
|
|
read_serial_number (si);
|
|
|
|
si = si->next;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-25 14:56:11 +00:00
|
|
|
sanei_bjnp_find_devices(conf_devices, attach_bjnp, pixma_devices);
|
2008-10-14 19:48:59 +00:00
|
|
|
si = first_scanner;
|
|
|
|
while (j < nscanners)
|
|
|
|
{
|
|
|
|
PDBG (pixma_dbg (3, "pixma_collect_devices() found %s at %s\n",
|
|
|
|
si->cfg->name, si->devname));
|
|
|
|
si = si->next;
|
|
|
|
j++;
|
|
|
|
|
2006-05-26 07:49:24 +00:00
|
|
|
}
|
|
|
|
return nscanners;
|
|
|
|
}
|
|
|
|
|
|
|
|
const pixma_config_t *
|
|
|
|
pixma_get_device_config (unsigned devnr)
|
|
|
|
{
|
|
|
|
const scanner_info_t *si = get_scanner_info (devnr);
|
|
|
|
return (si) ? si->cfg : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
pixma_get_device_id (unsigned devnr)
|
|
|
|
{
|
|
|
|
const scanner_info_t *si = get_scanner_info (devnr);
|
|
|
|
return (si) ? si->serial : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pixma_connect (unsigned devnr, pixma_io_t ** handle)
|
|
|
|
{
|
|
|
|
pixma_io_t *io;
|
2008-10-14 19:48:59 +00:00
|
|
|
SANE_Int dev;
|
2006-05-26 07:49:24 +00:00
|
|
|
const scanner_info_t *si;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
*handle = NULL;
|
|
|
|
si = get_scanner_info (devnr);
|
|
|
|
if (!si)
|
2006-08-27 12:39:18 +00:00
|
|
|
return PIXMA_EINVAL;
|
2008-10-14 19:48:59 +00:00
|
|
|
if (si-> interface == INT_BJNP)
|
|
|
|
error = map_error (sanei_bjnp_open (si->devname, &dev));
|
|
|
|
else
|
|
|
|
error = map_error (sanei_usb_open (si->devname, &dev));
|
|
|
|
|
2006-05-26 07:49:24 +00:00
|
|
|
if (error < 0)
|
|
|
|
return error;
|
|
|
|
io = (pixma_io_t *) calloc (1, sizeof (*io));
|
|
|
|
if (!io)
|
|
|
|
{
|
2008-10-14 19:48:59 +00:00
|
|
|
if (si -> interface == INT_BJNP)
|
|
|
|
sanei_bjnp_close (dev);
|
|
|
|
else
|
|
|
|
sanei_usb_close (dev);
|
2006-08-27 12:39:18 +00:00
|
|
|
return PIXMA_ENOMEM;
|
2006-05-26 07:49:24 +00:00
|
|
|
}
|
|
|
|
io->next = first_io;
|
|
|
|
first_io = io;
|
2008-10-14 19:48:59 +00:00
|
|
|
io->dev = dev;
|
|
|
|
io->interface = si->interface;
|
2006-05-26 07:49:24 +00:00
|
|
|
*handle = io;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
pixma_disconnect (pixma_io_t * io)
|
|
|
|
{
|
|
|
|
pixma_io_t **p;
|
|
|
|
|
|
|
|
if (!io)
|
|
|
|
return;
|
|
|
|
for (p = &first_io; *p && *p != io; p = &((*p)->next))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
PASSERT (*p);
|
|
|
|
if (!(*p))
|
|
|
|
return;
|
2008-10-14 19:48:59 +00:00
|
|
|
if (io-> interface == INT_BJNP)
|
|
|
|
sanei_bjnp_close (io->dev);
|
|
|
|
else
|
|
|
|
sanei_usb_close (io->dev);
|
2006-05-26 07:49:24 +00:00
|
|
|
*p = io->next;
|
|
|
|
free (io);
|
|
|
|
}
|
|
|
|
|
2008-11-05 20:53:30 +00:00
|
|
|
int pixma_activate (pixma_io_t * io)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
if (io->interface == INT_BJNP)
|
|
|
|
{
|
|
|
|
error = map_error(sanei_bjnp_activate (io->dev));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* noop for USB interface */
|
|
|
|
error = 0;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pixma_deactivate (pixma_io_t * io)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
if (io->interface == INT_BJNP)
|
|
|
|
{
|
|
|
|
error = map_error(sanei_bjnp_deactivate (io->dev));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* noop for USB interface */
|
|
|
|
error = 0;
|
|
|
|
return error;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-05-26 07:49:24 +00:00
|
|
|
int
|
|
|
|
pixma_reset_device (pixma_io_t * io)
|
|
|
|
{
|
|
|
|
UNUSED (io);
|
2006-08-27 12:39:18 +00:00
|
|
|
return PIXMA_ENOTSUP;
|
2006-05-26 07:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pixma_write (pixma_io_t * io, const void *cmd, unsigned len)
|
|
|
|
{
|
|
|
|
size_t count = len;
|
|
|
|
int error;
|
|
|
|
|
2008-10-14 19:48:59 +00:00
|
|
|
if (io->interface == INT_BJNP)
|
|
|
|
{
|
|
|
|
sanei_bjnp_set_timeout (io->dev, PIXMA_BULKOUT_TIMEOUT);
|
|
|
|
error = map_error (sanei_bjnp_write_bulk (io->dev, cmd, &count));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-26 07:49:24 +00:00
|
|
|
#ifdef HAVE_SANEI_USB_SET_TIMEOUT
|
2008-10-14 19:48:59 +00:00
|
|
|
sanei_usb_set_timeout (PIXMA_BULKOUT_TIMEOUT);
|
2006-05-26 07:49:24 +00:00
|
|
|
#endif
|
2008-10-14 19:48:59 +00:00
|
|
|
error = map_error (sanei_usb_write_bulk (io->dev, cmd, &count));
|
|
|
|
}
|
2006-08-27 12:39:18 +00:00
|
|
|
if (error == PIXMA_EIO)
|
|
|
|
error = PIXMA_ETIMEDOUT; /* FIXME: SANE doesn't have ETIMEDOUT!! */
|
|
|
|
if (count != len)
|
|
|
|
{
|
|
|
|
PDBG (pixma_dbg (1, "WARNING:pixma_write(): count(%u) != len(%u)\n",
|
|
|
|
(unsigned) count, len));
|
|
|
|
error = PIXMA_EIO;
|
|
|
|
}
|
|
|
|
if (error >= 0)
|
2006-05-26 07:49:24 +00:00
|
|
|
error = count;
|
|
|
|
PDBG (pixma_dump (10, "OUT ", cmd, error, len, 128));
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pixma_read (pixma_io_t * io, void *buf, unsigned size)
|
|
|
|
{
|
|
|
|
size_t count = size;
|
|
|
|
int error;
|
|
|
|
|
2008-10-14 19:48:59 +00:00
|
|
|
if (io-> interface == INT_BJNP)
|
|
|
|
{
|
|
|
|
sanei_bjnp_set_timeout (io->dev, PIXMA_BULKIN_TIMEOUT);
|
|
|
|
error = map_error (sanei_bjnp_read_bulk (io->dev, buf, &count));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-26 07:49:24 +00:00
|
|
|
#ifdef HAVE_SANEI_USB_SET_TIMEOUT
|
2008-10-14 19:48:59 +00:00
|
|
|
sanei_usb_set_timeout (PIXMA_BULKIN_TIMEOUT);
|
2006-05-26 07:49:24 +00:00
|
|
|
#endif
|
2008-10-14 19:48:59 +00:00
|
|
|
error = map_error (sanei_usb_read_bulk (io->dev, buf, &count));
|
|
|
|
}
|
|
|
|
|
2006-08-27 12:39:18 +00:00
|
|
|
if (error == PIXMA_EIO)
|
|
|
|
error = PIXMA_ETIMEDOUT; /* FIXME: SANE doesn't have ETIMEDOUT!! */
|
|
|
|
if (error >= 0)
|
2006-05-26 07:49:24 +00:00
|
|
|
error = count;
|
|
|
|
PDBG (pixma_dump (10, "IN ", buf, error, -1, 128));
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pixma_wait_interrupt (pixma_io_t * io, void *buf, unsigned size, int timeout)
|
|
|
|
{
|
|
|
|
size_t count = size;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* FIXME: What is the meaning of "timeout" in sanei_usb? */
|
|
|
|
if (timeout < 0)
|
|
|
|
timeout = INT_MAX;
|
2009-04-05 19:49:41 +00:00
|
|
|
else if (timeout < 100)
|
|
|
|
timeout = 100;
|
2008-10-14 19:48:59 +00:00
|
|
|
if (io-> interface == INT_BJNP)
|
|
|
|
{
|
|
|
|
sanei_bjnp_set_timeout (io->dev, timeout);
|
|
|
|
error = map_error (sanei_bjnp_read_int (io->dev, buf, &count));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SANEI_USB_SET_TIMEOUT
|
|
|
|
sanei_usb_set_timeout (timeout);
|
2006-05-26 07:49:24 +00:00
|
|
|
#endif
|
2008-10-14 19:48:59 +00:00
|
|
|
error = map_error (sanei_usb_read_int (io->dev, buf, &count));
|
|
|
|
}
|
2015-08-07 21:19:33 +00:00
|
|
|
if (error == PIXMA_EIO /*|| error == PIXMA_EOF*/) /* EOF isn't an error! */
|
2006-08-27 12:39:18 +00:00
|
|
|
error = PIXMA_ETIMEDOUT; /* FIXME: SANE doesn't have ETIMEDOUT!! */
|
2006-05-26 07:49:24 +00:00
|
|
|
if (error == 0)
|
|
|
|
error = count;
|
2006-08-27 12:39:18 +00:00
|
|
|
if (error != PIXMA_ETIMEDOUT)
|
2006-06-08 17:47:34 +00:00
|
|
|
PDBG (pixma_dump (10, "INTR", buf, error, -1, -1));
|
2006-05-26 07:49:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pixma_set_interrupt_mode (pixma_io_t * s, int background)
|
|
|
|
{
|
|
|
|
UNUSED (s);
|
2006-08-27 12:39:18 +00:00
|
|
|
return (background) ? PIXMA_ENOTSUP : 0;
|
2006-05-26 07:49:24 +00:00
|
|
|
}
|