cleanups and final version

merge-requests/1/head
Stphane Voltz 2013-06-03 20:57:28 +02:00
rodzic 3af775de44
commit 4bc8ce9b8b
1 zmienionych plików z 72 dodań i 95 usunięć

Wyświetl plik

@ -3451,31 +3451,26 @@ check_usb_chip (struct usb_device *dev, int verbosity, SANE_Bool from_file)
* @param from_file SANE_True if data read from file * @param from_file SANE_True if data read from file
* @return a string containing the name of the detected scanner chip * @return a string containing the name of the detected scanner chip
*/ */
char * check_usb_chip (int verbosity, char *check_usb_chip (int verbosity,
struct libusb_device_descriptor desc, struct libusb_device_descriptor desc,
libusb_device_handle *hdl, libusb_device_handle * hdl,
struct libusb_config_descriptor *config0); struct libusb_config_descriptor *config0);
static int verbose = 0; static int verbose = 0;
static int static int
genesys_write_reg (libusb_device_handle *handle, unsigned char reg, genesys_write_reg (libusb_device_handle * handle, unsigned char reg,
unsigned char val) unsigned char val)
{ {
int result; int result;
unsigned char data[2]; unsigned char data[2];
data[0]=reg; data[0] = reg;
data[1]=val; data[1] = val;
result = libusb_control_transfer (handle, result = libusb_control_transfer (handle,
0x40, 0x40,
0x04, 0x04, 0x83, 0x00, data, 0x02, TIMEOUT);
0x83,
0x00,
data,
0x02,
TIMEOUT);
if (result < 0) if (result < 0)
return 0; return 0;
return 1; return 1;
@ -3483,29 +3478,19 @@ genesys_write_reg (libusb_device_handle *handle, unsigned char reg,
static int static int
genesys_read_reg (libusb_device_handle * handle, unsigned char reg, genesys_read_reg (libusb_device_handle * handle, unsigned char reg,
unsigned char *val) unsigned char *val)
{ {
int result; int result;
result = libusb_control_transfer (handle, result = libusb_control_transfer (handle,
0x40, 0x40,
0x0c, 0x0c, 0x83, 0x00, &reg, 0x01, TIMEOUT);
0x83,
0x00,
&reg,
0x01,
TIMEOUT);
if (result < 0) if (result < 0)
return 0; return 0;
result = libusb_control_transfer (handle, result = libusb_control_transfer (handle,
0xc0, 0xc0,
0x0c, 0x0c, 0x84, 0x00, val, 0x01, TIMEOUT);
0x84,
0x00,
val,
0x01,
TIMEOUT);
if (result < 0) if (result < 0)
return 0; return 0;
@ -3520,18 +3505,17 @@ genesys_read_reg (libusb_device_handle * handle, unsigned char reg,
* @return a string with ASIC name, or NULL if not recognized * @return a string with ASIC name, or NULL if not recognized
*/ */
static char * static char *
check_gl646 (libusb_device_handle *handle, check_gl646 (libusb_device_handle * handle,
struct libusb_device_descriptor desc, struct libusb_device_descriptor desc,
struct libusb_config_descriptor *config0) struct libusb_config_descriptor *config0)
{ {
unsigned char val; unsigned char val;
int result; int result;
if (desc.bcdUSB != 0x110) if (desc.bcdUSB != 0x110)
{ {
if (verbose > 2) if (verbose > 2)
printf (" this is not a GL646 (bcdUSB = 0x%x)\n", printf (" this is not a GL646 (bcdUSB = 0x%x)\n", desc.bcdUSB);
desc.bcdUSB);
return 0; return 0;
} }
if (desc.bDeviceSubClass != 0x00) if (desc.bDeviceSubClass != 0x00)
@ -3558,68 +3542,59 @@ check_gl646 (libusb_device_handle *handle,
return 0; return 0;
} }
if ((config0->interface[0].altsetting[0].endpoint[0]. if ((config0->interface[0].altsetting[0].endpoint[0].bEndpointAddress !=
bEndpointAddress != 0x81) 0x81)
|| (config0->interface[0].altsetting[0].endpoint[0]. || (config0->interface[0].altsetting[0].endpoint[0].bmAttributes !=
bmAttributes != 0x02) 0x02)
|| (config0->interface[0].altsetting[0].endpoint[0]. || (config0->interface[0].altsetting[0].endpoint[0].wMaxPacketSize !=
wMaxPacketSize != 0x40) 0x40)
|| (config0->interface[0].altsetting[0].endpoint[0].bInterval != || (config0->interface[0].altsetting[0].endpoint[0].bInterval != 0x0))
0x0))
{ {
if (verbose > 2) if (verbose > 2)
printf printf
(" this is not a GL646 (bEndpointAddress = 0x%x, bmAttributes = 0x%x, " (" this is not a GL646 (bEndpointAddress = 0x%x, bmAttributes = 0x%x, "
"wMaxPacketSize = 0x%x, bInterval = 0x%x)\n", "wMaxPacketSize = 0x%x, bInterval = 0x%x)\n",
config0->interface[0].altsetting[0].endpoint[0]. config0->interface[0].altsetting[0].endpoint[0].bEndpointAddress,
bEndpointAddress,
config0->interface[0].altsetting[0].endpoint[0].bmAttributes, config0->interface[0].altsetting[0].endpoint[0].bmAttributes,
config0->interface[0].altsetting[0].endpoint[0]. config0->interface[0].altsetting[0].endpoint[0].wMaxPacketSize,
wMaxPacketSize,
config0->interface[0].altsetting[0].endpoint[0].bInterval); config0->interface[0].altsetting[0].endpoint[0].bInterval);
return 0; return 0;
} }
if ((config0->interface[0].altsetting[0].endpoint[1]. if ((config0->interface[0].altsetting[0].endpoint[1].bEndpointAddress !=
bEndpointAddress != 0x02) 0x02)
|| (config0->interface[0].altsetting[0].endpoint[1]. || (config0->interface[0].altsetting[0].endpoint[1].bmAttributes !=
bmAttributes != 0x02) 0x02)
|| (config0->interface[0].altsetting[0].endpoint[1]. || (config0->interface[0].altsetting[0].endpoint[1].wMaxPacketSize !=
wMaxPacketSize != 0x40) 0x40)
|| (config0->interface[0].altsetting[0].endpoint[1].bInterval != || (config0->interface[0].altsetting[0].endpoint[1].bInterval != 0))
0))
{ {
if (verbose > 2) if (verbose > 2)
printf printf
(" this is not a GL646 (bEndpointAddress = 0x%x, bmAttributes = 0x%x, " (" this is not a GL646 (bEndpointAddress = 0x%x, bmAttributes = 0x%x, "
"wMaxPacketSize = 0x%x, bInterval = 0x%x)\n", "wMaxPacketSize = 0x%x, bInterval = 0x%x)\n",
config0->interface[0].altsetting[0].endpoint[1]. config0->interface[0].altsetting[0].endpoint[1].bEndpointAddress,
bEndpointAddress,
config0->interface[0].altsetting[0].endpoint[1].bmAttributes, config0->interface[0].altsetting[0].endpoint[1].bmAttributes,
config0->interface[0].altsetting[0].endpoint[1]. config0->interface[0].altsetting[0].endpoint[1].wMaxPacketSize,
wMaxPacketSize,
config0->interface[0].altsetting[0].endpoint[1].bInterval); config0->interface[0].altsetting[0].endpoint[1].bInterval);
return 0; return 0;
} }
if ((config0->interface[0].altsetting[0].endpoint[2]. if ((config0->interface[0].altsetting[0].endpoint[2].bEndpointAddress !=
bEndpointAddress != 0x83) 0x83)
|| (config0->interface[0].altsetting[0].endpoint[2]. || (config0->interface[0].altsetting[0].endpoint[2].bmAttributes !=
bmAttributes != 0x03) 0x03)
|| (config0->interface[0].altsetting[0].endpoint[2]. || (config0->interface[0].altsetting[0].endpoint[2].wMaxPacketSize !=
wMaxPacketSize != 0x1) 0x1)
|| (config0->interface[0].altsetting[0].endpoint[2].bInterval != || (config0->interface[0].altsetting[0].endpoint[2].bInterval != 8))
8))
{ {
if (verbose > 2) if (verbose > 2)
printf printf
(" this is not a GL646 (bEndpointAddress = 0x%x, bmAttributes = 0x%x, " (" this is not a GL646 (bEndpointAddress = 0x%x, bmAttributes = 0x%x, "
"wMaxPacketSize = 0x%x, bInterval = 0x%x)\n", "wMaxPacketSize = 0x%x, bInterval = 0x%x)\n",
config0->interface[0].altsetting[0].endpoint[2]. config0->interface[0].altsetting[0].endpoint[2].bEndpointAddress,
bEndpointAddress,
config0->interface[0].altsetting[0].endpoint[2].bmAttributes, config0->interface[0].altsetting[0].endpoint[2].bmAttributes,
config0->interface[0].altsetting[0].endpoint[2]. config0->interface[0].altsetting[0].endpoint[2].wMaxPacketSize,
wMaxPacketSize,
config0->interface[0].altsetting[0].endpoint[2].bInterval); config0->interface[0].altsetting[0].endpoint[2].bInterval);
return 0; return 0;
} }
@ -3670,8 +3645,8 @@ check_gl646 (libusb_device_handle *handle,
* @return a string with ASIC name, or NULL if not recognized * @return a string with ASIC name, or NULL if not recognized
*/ */
static char * static char *
check_genesys (libusb_device_handle *handle, check_genesys (libusb_device_handle * handle,
struct libusb_device_descriptor desc, struct libusb_device_descriptor desc,
struct libusb_config_descriptor *config0) struct libusb_config_descriptor *config0)
{ {
unsigned char val; unsigned char val;
@ -3679,20 +3654,20 @@ check_genesys (libusb_device_handle *handle,
if (verbose > 2) if (verbose > 2)
printf (" checking for GLxxx ...\n"); printf (" checking for GLxxx ...\n");
/* Check GL646 device descriptor */ /* Check GL646 device descriptor */
if ((desc.bDeviceClass == LIBUSB_CLASS_PER_INTERFACE) if ((desc.bDeviceClass == LIBUSB_CLASS_PER_INTERFACE)
&& (config0->interface[0].altsetting[0].bInterfaceClass == 0x10)) && (config0->interface[0].altsetting[0].bInterfaceClass == 0x10))
{ {
return check_gl646(handle, desc, config0); return check_gl646 (handle, desc, config0);
}
if (verbose > 2)
{
printf
(" this is not a GL646 (bDeviceClass = %d, bInterfaceClass = %d)\n",
desc.bDeviceClass,
config0->interface[0].altsetting[0].bInterfaceClass);
} }
if (verbose > 2)
{
printf
(" this is not a GL646 (bDeviceClass = %d, bInterfaceClass = %d)\n",
desc.bDeviceClass,
config0->interface[0].altsetting[0].bInterfaceClass);
}
/* Check device desc */ /* Check device desc */
if ((desc.bDeviceClass != LIBUSB_CLASS_VENDOR_SPEC) if ((desc.bDeviceClass != LIBUSB_CLASS_VENDOR_SPEC)
@ -3820,7 +3795,7 @@ check_genesys (libusb_device_handle *handle,
return NULL; return NULL;
} }
/* decide revison number based on bcdUsb heuristics */ /* decide revision number based on bcdUsb heuristics */
if (desc.bcdDevice == 0x701) if (desc.bcdDevice == 0x701)
return "GL124"; return "GL124";
if (desc.bcdDevice >= 0x700) if (desc.bcdDevice >= 0x700)
@ -3837,13 +3812,14 @@ check_genesys (libusb_device_handle *handle,
return "GL842"; return "GL842";
if (desc.bcdDevice > 0x101) if (desc.bcdDevice > 0x101)
return "GL841"; return "GL841";
return "GL646"; return "GL646_HP";
} }
char * check_usb_chip (int verbosity, char *
struct libusb_device_descriptor desc, check_usb_chip (int verbosity,
libusb_device_handle *hdl, struct libusb_device_descriptor desc,
struct libusb_config_descriptor *config0) libusb_device_handle * hdl,
struct libusb_config_descriptor *config0)
{ {
char *chip_name = NULL; char *chip_name = NULL;
int ret; int ret;
@ -3858,11 +3834,12 @@ char * check_usb_chip (int verbosity,
{ {
ret = libusb_set_configuration (hdl, config0->bConfigurationValue); ret = libusb_set_configuration (hdl, config0->bConfigurationValue);
if (ret < 0) if (ret < 0)
{ {
if (verbose > 2) if (verbose > 2)
printf("couldnt set device to configuration %d\n", config0->bConfigurationValue); printf ("couldnt set device to configuration %d\n",
return NULL; config0->bConfigurationValue);
} return NULL;
}
} }
/* claim the interface (only interface 0 is currently handled */ /* claim the interface (only interface 0 is currently handled */
@ -3870,7 +3847,7 @@ char * check_usb_chip (int verbosity,
if (ret < 0) if (ret < 0)
{ {
if (verbose > 2) if (verbose > 2)
printf ("could not claim USB device interface\n"); printf ("could not claim USB device interface\n");
return NULL; return NULL;
} }