common: Claim the device before calling the backend's query_serno() call.

master
Solomon Peachy 2013-07-24 20:54:14 -04:00
parent cc8936094a
commit 051cf386b5
2 changed files with 24 additions and 11 deletions

View File

@ -27,7 +27,7 @@
#include "backend_common.h"
#define BACKEND_VERSION "0.16"
#define BACKEND_VERSION "0.17"
#ifndef URI_PREFIX
#define URI_PREFIX "gutenprint+usb"
#endif
@ -38,12 +38,10 @@
static char *get_device_id(struct libusb_device_handle *dev)
{
int length;
int claimed = 0;
int iface = 0;
char *buf = malloc(ID_BUF_SIZE + 1);
claimed = libusb_kernel_driver_active(dev, iface);
if (claimed)
if (libusb_kernel_driver_active(dev, iface))
libusb_detach_kernel_driver(dev, iface);
libusb_claim_interface(dev, iface);
@ -82,10 +80,7 @@ static char *get_device_id(struct libusb_device_handle *dev)
done:
libusb_release_interface(dev, iface);
#if 0
if (claimed)
libusb_attach_kernel_driver(dev, iface);
#endif
return buf;
}
@ -159,8 +154,26 @@ static int print_scan_output(struct libusb_device *device,
if (desc->iSerialNumber) {
libusb_get_string_descriptor_ascii(dev, desc->iSerialNumber, serial, STR_LEN_MAX);
sanitize_string((char*)serial);
} else if (backend->query_serno) {
backend->query_serno(dev, (char*)serial, STR_LEN_MAX);
} else if (backend->query_serno) { /* XXX this is ... a cut-n-paste hack */
uint8_t endp_up, endp_down;
int i, iface = 0;
struct libusb_config_descriptor *config;
if (libusb_kernel_driver_active(dev, iface))
libusb_detach_kernel_driver(dev, iface);
libusb_claim_interface(dev, iface);
libusb_get_active_config_descriptor(device, &config);
for (i = 0 ; i < config->interface[0].altsetting[0].bNumEndpoints ; i++) {
if ((config->interface[0].altsetting[0].endpoint[i].bmAttributes & 3) == LIBUSB_TRANSFER_TYPE_BULK) {
if (config->interface[0].altsetting[0].endpoint[i].bEndpointAddress & LIBUSB_ENDPOINT_IN)
endp_up = config->interface[0].altsetting[0].endpoint[i].bEndpointAddress;
else
endp_down = config->interface[0].altsetting[0].endpoint[i].bEndpointAddress;
}
}
backend->query_serno(dev, endp_up, endp_down, (char*)serial, STR_LEN_MAX);
libusb_release_interface(dev, iface);
}
if (!strlen((char*)serial)) {

View File

@ -115,7 +115,7 @@ struct dyesub_backend {
int (*early_parse)(void *ctx, int data_fd);
int (*read_parse)(void *ctx, int data_fd);
int (*main_loop)(void *ctx, int copies);
int (*query_serno)(struct libusb_device_handle *dev, char *buf, int buf_len);
int (*query_serno)(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len);
struct device_id devices[];
};