1 # http://www.cups.org/str.php?L3965
2
3 Index: usb-libusb.c
4 ===================================================================
5 --- usb-libusb.c (revision 10087)
6 +++ usb-libusb.c (working copy)
7 @@ -631,6 +631,7 @@
8 int verbose) /* I - Update connecting-to-device state? */
9 {
10 int number; /* Configuration/interface/altset numbers */
11 + char current_bConfiguration;
12
13
14 /*
15 @@ -647,27 +648,40 @@
16 if ((printer->handle = usb_open(printer->device)) == NULL)
17 return (-1);
18
19 - /*
20 - * Then set the desired configuration...
21 - */
22
23 if (verbose)
24 fputs("STATE: +connecting-to-device\n", stderr);
25
26 + /*
27 + * Set the desired configuration, but only if it needs changing. Some
28 + * printers (e.g., Samsung) don't like usb_set_configuration. It will succeed,
29 + * but the following print job is sometimes silently lost by the printer.
30 + */
31 + if (usb_control_msg(printer->handle,
32 + USB_TYPE_STANDARD | USB_ENDPOINT_IN | USB_RECIP_DEVICE,
33 + 8, /* GET_CONFIGURATION */
34 + 0, 0, ¤t_bConfiguration, 1, 5000) != 1)
35 + {
36 + current_bConfiguration = 0; /* Failed. Assume not configured */
37 + }
38 +
39 number = printer->device->config[printer->conf].bConfigurationValue;
40 -
41 - if (usb_set_configuration(printer->handle, number) < 0)
42 + if (number != current_bConfiguration)
43 {
44 - /*
45 - * If the set fails, chances are that the printer only supports a
46 - * single configuration. Technically these printers don't conform to
47 - * the USB printer specification, but otherwise they'll work...
48 - */
49
50 - if (errno != EBUSY)
51 - fprintf(stderr, "DEBUG: Failed to set configuration %d for %04x:%04x\n",
52 - number, printer->device->descriptor.idVendor,
53 - printer->device->descriptor.idProduct);
54 + if (usb_set_configuration(printer->handle, number) < 0)
55 + {
56 + /*
57 + * If the set fails, chances are that the printer only supports a
58 + * single configuration. Technically these printers don't conform to
59 + * the USB printer specification, but otherwise they'll work...
60 + */
61 +
62 + if (errno != EBUSY)
63 + fprintf(stderr, "DEBUG: Failed to set configuration %d for %04x:%04x\n",
64 + number, printer->device->descriptor.idVendor,
65 + printer->device->descriptor.idProduct);
66 + }
67 }
68
69 /*
70 @@ -700,20 +714,24 @@
71 #endif /* 0 */
72
73 /*
74 - * Set alternate setting...
75 + * Set alternate setting, but only if there is more than one option.
76 + * Some printers (e.g., Samsung) don't like usb_set_altinterface.
77 */
78 -
79 - number = printer->device->config[printer->conf].interface[printer->iface].
80 - altsetting[printer->altset].bAlternateSetting;
81 - while (usb_set_altinterface(printer->handle, number) < 0)
82 + if (printer->device->config[printer->conf].interface[printer->iface].
83 + num_altsetting > 1)
84 {
85 - if (errno != EBUSY)
86 - fprintf(stderr,
87 - "DEBUG: Failed to set alternate interface %d for %04x:%04x: %s\n",
88 - number, printer->device->descriptor.idVendor,
89 - printer->device->descriptor.idProduct, strerror(errno));
90 + number = printer->device->config[printer->conf].interface[printer->iface].
91 + altsetting[printer->altset].bAlternateSetting;
92 + while (usb_set_altinterface(printer->handle, number) < 0)
93 + {
94 + if (errno != EBUSY)
95 + fprintf(stderr,
96 + "DEBUG: Failed to set alternate interface %d for %04x:%04x: %s\n",
97 + number, printer->device->descriptor.idVendor,
98 + printer->device->descriptor.idProduct, strerror(errno));
99
100 - goto error;
101 + goto error;
102 + }
103 }
104
105 if (verbose)
|