From 4381022200a578f4cad45502f3731b0cbc0643d8 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Mon, 5 Nov 2012 20:33:10 -0500 Subject: [PATCH] [libusb] Dump out mfg/product/serial strings, if present. --- es_print_common.h | 6 +++--- es_print_libusb.c | 28 +++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/es_print_common.h b/es_print_common.h index 8413169..b1bbeaa 100644 --- a/es_print_common.h +++ b/es_print_common.h @@ -25,7 +25,7 @@ * */ -#define VERSION "0.23" +#define VERSION "0.24" #if (__BYTE_ORDER == __LITTLE_ENDIAN) #define le32_to_cpu(__x) __x @@ -130,7 +130,7 @@ struct printer_data printers[P_END] = { // .paper_code_offset = -1, }, { .type = P_CP_XXX, - .model = "SELPHY CP Series (Except CP790/CP900)", + .model = "SELPHY CP Series (!CP790/CP900)", .init_length = 12, .foot_length = 0, .init_readback = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, -1, 0x00, 0x00, 0x00, 0x00, 0x00 }, @@ -242,7 +242,7 @@ static int parse_printjob(uint8_t *buffer, int *bw_mode, int *plane_len) printer_type = P_CP_XXX; // XXX the P_CP900 is identical, but has extra // data at the very end of the file. No way to detect - // from a streamed source. + // from a streamed source! } else { printer_type = P_ES1; *bw_mode = (buffer[2] == 0x20); diff --git a/es_print_libusb.c b/es_print_libusb.c index 390e0a6..790e330 100644 --- a/es_print_libusb.c +++ b/es_print_libusb.c @@ -123,6 +123,7 @@ int main (int argc, char **argv) struct libusb_device **list; struct libusb_device_handle *dev; struct libusb_config_descriptor *config; + struct libusb_device_descriptor desc; uint8_t endp_up = 0; uint8_t endp_down = 0; @@ -191,8 +192,6 @@ int main (int argc, char **argv) num = libusb_get_device_list(ctx, &list); for (i = 0 ; i < num ; i++) { - struct libusb_device_descriptor desc; - libusb_get_device_descriptor(list[i], &desc); if (desc.idVendor != USB_VID_CANON) @@ -264,13 +263,30 @@ int main (int argc, char **argv) found2: - fprintf(stderr, "Found a %s printer\r\n", printers[printer_type].model); - ret = libusb_open(list[i], &dev); if (ret) { fprintf(stderr, "Could not open device (Need to be root?) (%d)\r\n", ret); goto done_close; } + + /* Query detailed info */ + fprintf(stderr, "Found a %s printer\r\n", printers[printer_type].model); + fprintf(stderr, "Vid: %04x\nPid: %04x\n", desc.idVendor, desc.idProduct); + if (desc.iManufacturer || desc.iProduct || desc.iSerialNumber) { + unsigned char buf[128]; + if (desc.iManufacturer) { + ret = libusb_get_string_descriptor_ascii(dev, desc.iManufacturer, buf, 128); + fprintf(stderr, "Mfg: %s\n", buf); + } + if (desc.iProduct) { + ret = libusb_get_string_descriptor_ascii(dev, desc.iProduct, buf, 128); + fprintf(stderr, "Prod: %s\n", buf); + } + if (desc.iSerialNumber) { + ret = libusb_get_string_descriptor_ascii(dev, desc.iSerialNumber, buf, 128); + fprintf(stderr, "SerNo: %s\n", buf); + } + } claimed = libusb_kernel_driver_active(dev, iface); if (claimed) { @@ -281,6 +297,8 @@ found2: } } + goto done_close; + ret = libusb_claim_interface(dev, iface); if (ret) { fprintf(stderr, "Could not claim printer interface (%d)\r\n", ret); @@ -415,10 +433,10 @@ top: done_claimed: libusb_release_interface(dev, iface); +done_close: if (claimed) libusb_attach_kernel_driver(dev, iface); -done_close: libusb_close(dev); done: