Skip to contentSkip to conversation

Patch: usblp quirk for zebra printers

PATCH P. Christeas 2 participants 3 messages May 21, 2008 – May 25, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,
I guess such a quirk may be a little odd, but it has been a blocking point in my system not being able to support more than one printer.

Please comment. (and cc. me)

From 2c87e2cbc8d33b49b6e7a20b9b85570840bb0e12 Mon Sep 17 00:00:00 2001
From: P.Christeas <[email protected]>
Date: Wed, 21 May 2008 20:47:52 +0300
Subject: [PATCH] USB: Quirk for Zebra printers not reporting their S/N.

Those printers (and maybe others) don't report their Serial Number as a part of their IEEE1284 device id string. Thus, printing backends like CUPS cannot select among multiple devices at the same host.
Workaround this situation by appending the SN in usblp.c .

---
 drivers/usb/class/usblp.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
drivers/usb/class/usblp.c +19 -0
index 0647164..a4d324b 100644
@@ -210,6 +210,7 @@ struct quirk_printer_struct {
 #define USBLP_QUIRK_BIDIR	0x1	/* reports bidir but requires unidirectional mode (no INs/reads) */
 #define USBLP_QUIRK_USB_INIT	0x2	/* needs vendor USB init string */
 #define USBLP_QUIRK_BAD_CLASS	0x4	/* descriptor uses vendor-specific Class or SubClass */
+#define USBLP_QUIRK_ID_NO_SERIAL 0x8	/* Printer does not report its serial no. in GET_ID request */
 
 static const struct quirk_printer_struct quirk_printers[] = {
 	{ 0x03f0, 0x0004, USBLP_QUIRK_BIDIR }, /* HP DeskJet 895C */
@@ -227,6 +228,7 @@ static const struct quirk_printer_struct quirk_printers[] = {
 	{ 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */
 	{ 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <[email protected]> */
 	{ 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */
+	{ 0x0a5f, 0x000a, USBLP_QUIRK_ID_NO_SERIAL }, /* Zebra printers don't report their serial */
 	{ 0, 0 }
 };
 
@@ -1330,6 +1332,23 @@ static int usblp_cache_device_id_string(struct usblp *usblp)
 		length = 2;
 	else if (length >= USBLP_DEVICE_ID_SIZE)
 		length = USBLP_DEVICE_ID_SIZE - 1;
+	
+	/* If printer doesn't report its serial, we append it */
+	if ((usblp->quirks & USBLP_QUIRK_ID_NO_SERIAL) && (usblp->dev->serial) &&
+		(length + strlen(usblp->dev->serial) + 5 <USBLP_DEVICE_ID_SIZE) ) {
+		
+		if (usblp->device_id_string[length-1] != ';')
+			usblp->device_id_string[length++]= ';';
+
+		strcpy(&usblp->device_id_string[length],"SN:");
+		length+=3;
+		strcat(&usblp->device_id_string[length],usblp->dev->serial);
+		length += strlen(usblp->dev->serial);
+		usblp->device_id_string[length++]= ';';
+
+		*((__be16 *)usblp->device_id_string) = cpu_to_be16(length);
+	}
+	
 	usblp->device_id_string[length] = '\0';
 
 	dbg("usblp%d Device ID string [len=%d]=\"%s\"",
Signature · 1 line
1.5.4.3
maintainer
#1 lore raw
Quoted 4 lines · P. Christeas

I guess such a quirk may be a little odd, but it has been a blocking point in my system not being able to support more than one printer.

(quoted diff) +0 -0
@@ -1330,6 +1332,23 @@ static int usblp_cache_device_id_string(struct usblp *usblp)

.....

drivers/usb/class/usblp.c static int usblp_cache_device_id_string(struct usblp *usblp) · line 1349

Quoted 7 lines
drivers/usb/class/usblp.c +7 -0
+		strcpy(&usblp->device_id_string[length],"SN:");
+		length+=3;
+		strcat(&usblp->device_id_string[length],usblp->dev->serial);
+		length += strlen(usblp->dev->serial);
+		usblp->device_id_string[length++]= ';';
+
+		*((__be16 *)usblp->device_id_string) = cpu_to_be16(length);

I see...

Quoted 1 line

Please comment. (and cc. me)

Personally, I don't like this. In kernel, we typically try not to fake things in lower levels in order to fool upper levels. There are always knock-off effects. Sometimes we have to do it, but in my experience CUPS folks always were for doing the right thing.

Let's ask them if extracting the S/N from sysfs is too onerous. I'm cc-ing this to Tim Waugh.

BTW, Please try to tinker with the following udev ruleset:
BUS="usb", KERNEL="lp[0-9]*", SYSFS{serial}=="XXXXXXX", SYMLINK+="mylp0" BUS="usb", KERNEL="lp[0-9]*", SYSFS{serial}=="YYYYYYY", SYMLINK+="mylp1" Encoding your serial numbers into udev rules is not pleasant, but the above should provide a stop-gap solution without patching kernels.

-- Pete

#2 lore raw
Quoted 7 lines · Pete Zaitcev
Quoted 2 lines · P. Christeas

I guess such a quirk may be a little odd, but it has been a blocking point in my system not being able to support more than one printer.

Personally, I don't like this. In kernel, we typically try not to fake things in lower levels in order to fool upper levels.
...
I'm cc-ing this to Tim Waugh.

I'm now working in a more "politically correct" way around that issue [1]. The outline is that we _add_ a backend to CUPS[2], which will bring back USB addressing by /dev/.. name. Then, we could implement udev rulesets which will create "by-id" symlinks to the usblpX devices.
My work is at github under "cups-usbbackend".

[1] it is a blocking point for my business, as I cannot attach a second printer.
[2] it could remain a complementary package until we really agree we want that code mainline.