/*
* If it didn't exit abort the pending read and wait an additional second...
*/
-
+
if (!g.read_thread_done)
{
- fputs("DEBUG: Read thread still active, aborting the pending read...\n",
+ fputs("DEBUG: Read thread still active, aborting the pending read...\n",
stderr);
g.wait_eof = 0;
gettimeofday(&tv, NULL);
cond_timeout.tv_sec = tv.tv_sec + 1;
cond_timeout.tv_nsec = tv.tv_usec * 1000;
-
+
while (!g.read_thread_done)
{
if (pthread_cond_timedwait(&g.read_thread_cond, &g.read_thread_mutex,
int number; /* Interface number */
- libusb_get_device_descriptor (printer->device, &devdesc);
- libusb_get_config_descriptor (printer->device, printer->conf, &confptr);
+ libusb_get_device_descriptor(printer->device, &devdesc);
+ libusb_get_config_descriptor(printer->device, printer->conf, &confptr);
number = confptr->interface[printer->iface].
altsetting[printer->altset].bInterfaceNumber;
libusb_release_interface(printer->handle, number);
* a printer...
*/
- libusb_get_device_descriptor (device, &devdesc);
+ libusb_get_device_descriptor(device, &devdesc);
if (!devdesc.bNumConfigurations || !devdesc.idVendor ||
!devdesc.idProduct)
for (conf = 0; conf < devdesc.bNumConfigurations; conf ++)
{
- if (libusb_get_config_descriptor (device, conf, &confptr) < 0)
+ if (libusb_get_config_descriptor(device, conf, &confptr) < 0)
continue;
for (iface = 0, ifaceptr = confptr->interface;
iface < confptr->bNumInterfaces;
if ((sern = cupsGetOption("SERIALNUMBER", num_values, values)) == NULL)
if ((sern = cupsGetOption("SERN", num_values, values)) == NULL)
if ((sern = cupsGetOption("SN", num_values, values)) == NULL &&
- ((libusb_get_device_descriptor (printer->device, &devdesc) >= 0) &&
+ ((libusb_get_device_descriptor(printer->device, &devdesc) >= 0) &&
devdesc.iSerialNumber))
{
/*
if (libusb_open(printer->device, &printer->handle) < 0)
return (-1);
+ printer->usblp_attached = 0;
+
if (verbose)
fputs("STATE: +connecting-to-device\n", stderr);
+ if ((errcode = libusb_get_device_descriptor (printer->device, &devdesc)) < 0)
+ {
+ fprintf(stderr, "DEBUG: Failed to get device descriptor, code: %d\n",
+ errcode);
+ goto error;
+ }
+
+ /*
+ * Get the "usblp" kernel module out of the way. This backend only
+ * works without the module attached.
+ */
+
+ errcode = libusb_kernel_driver_active(printer->handle, printer->iface);
+ if (errcode == 0)
+ printer->usblp_attached = 0;
+ else if (errcode == 1)
+ {
+ printer->usblp_attached = 1;
+ if ((errcode =
+ libusb_detach_kernel_driver(printer->handle, printer->iface)) < 0)
+ {
+ fprintf(stderr, "DEBUG: Failed to detach \"usblp\" module from %04x:%04x\n",
+ devdesc.idVendor, devdesc.idProduct);
+ goto error;
+ }
+ }
+ else
+ {
+ printer->usblp_attached = 0;
+ fprintf(stderr, "DEBUG: Failed to check whether %04x:%04x has the \"usblp\" kernel module attached\n",
+ devdesc.idVendor, devdesc.idProduct);
+ goto error;
+ }
+
/*
* Set the desired configuration, but only if it needs changing. Some
* printers (e.g., Samsung) don't like libusb_set_configuration. It will
0, 0, (unsigned char *)¤t, 1, 5000) < 0)
current = 0; /* Assume not configured */
- libusb_get_device_descriptor (printer->device, &devdesc);
- libusb_get_config_descriptor (printer->device, printer->conf, &confptr);
+ libusb_get_device_descriptor(printer->device, &devdesc);
+ libusb_get_config_descriptor(printer->device, printer->conf, &confptr);
number1 = confptr->bConfigurationValue;
if (number1 != current)
else
{
printer->usblp_attached = 0;
- fprintf(stderr, "DEBUG: Failed to check whether %04x:%04x has the \"usblp\" kernel module attached\n",
- devdesc.idVendor, devdesc.idProduct);
- goto error;
+
+ if (errcode != LIBUSB_ERROR_NOT_SUPPORTED)
+ {
+ fprintf(stderr,
+ "DEBUG: Failed to check whether %04x:%04x has the \"usblp\" "
+ "kernel module attached\n", devdesc.idVendor, devdesc.idProduct);
+ goto error;
+ }
}
/*
while ((errcode = libusb_claim_interface(printer->handle, number1)) < 0)
{
if (errcode != LIBUSB_ERROR_BUSY)
+ {
fprintf(stderr,
"DEBUG: Failed to claim interface %d for %04x:%04x: %s\n",
number1, devdesc.idVendor, devdesc.idProduct, strerror(errno));
- goto error;
+ goto error;
+ }
}
/*
< 0)
{
if (errcode != LIBUSB_ERROR_BUSY)
+ {
fprintf(stderr,
"DEBUG: Failed to set alternate interface %d for %04x:%04x: "
"%s\n",
number2, devdesc.idVendor, devdesc.idProduct, strerror(errno));
- goto error;
+ goto error;
+ }
}
}