Re: Raspberry Pi 3B USB Printing Issue

From: Archimedes Gaviola <archimedes.gaviola_at_gmail.com>
Date: Thu, 31 Mar 2022 12:03:23 UTC
On Thu, Mar 31, 2022 at 7:52 PM Archimedes Gaviola <
archimedes.gaviola@gmail.com> wrote:

>
>
> On Sun, Mar 27, 2022 at 10:28 PM Archimedes Gaviola <
> archimedes.gaviola@gmail.com> wrote:
>
>>
>>
>> On Sun, Mar 27, 2022 at 5:05 PM Hans Petter Selasky <hps@selasky.org>
>> wrote:
>>
>>> On 3/27/22 07:55, Archimedes Gaviola wrote:
>>> > On Sat, Mar 12, 2022 at 4:41 PM Hans Petter Selasky <hps@selasky.org>
>>> wrote:
>>> >
>>> >> On 3/12/22 08:07, Archimedes Gaviola wrote:
>>> >>> ugen1.5: <EPSON EPSON UB-U03II> at usbus1
>>> >>> ulpt1 on uhub1
>>> >>> ulpt1: <EPSON EPSON UB-U03II, class 0/0, rev 1.10/2.00, addr 5> on
>>> usbus1
>>> >>> device_attach: ulpt1 attach returned 12
>>> >>
>>> >> 12 : man errno :
>>> >>        12 ENOMEM Cannot allocate memory.
>>> >>
>>> >> I guess the EPSON printer you've got is not compatible with ulpt<n>
>>> >>
>>> >> When printing, can you make sure that the length transferred is never
>>> a
>>> >> multiple of 64 bytes?
>>> >>
>>> >> Also, there might be a bug lurking in the USB host controller driver,
>>> >> like already mentioned.
>>> >>
>>> >
>>> >
>>> > Hi Hans,
>>> >
>>> > I just figured-out the ulpt(4) driver in my Epson printer while
>>> comparing
>>> > with my Xprinter printer's USB device info. My Epson printer is
>>> providing
>>> > vendor specific values of 255 in the bInterfaceClass and
>>> bInterfaceSubClass
>>> > respectively.
>>> >
>>> >        bInterfaceClass = 0x00ff  <Vendor specific>
>>> >        bInterfaceSubClass = 0x00ff
>>> >
>>> > It should be a value of 7 for bInterfaceClass and a value of 1 in
>>> > bInterfaceSubClass.
>>> >
>>> >        bInterfaceClass = 0x0007  <Printer device>
>>> >        bInterfaceSubClass = 0x0001
>>> >
>>> > So, the ulpt_attach() routine below will break upon validation for
>>> > mismatched values in UICLASS_PRINTER and  UISUBCLASS_PRINTER.
>>> >
>>> >                          } else {
>>> >                                  alt_index++;
>>> >                                  if ((id->bInterfaceClass ==
>>> > UICLASS_PRINTER) &&
>>> >                                      (id->bInterfaceSubClass ==
>>> > UISUBCLASS_PRINTER) &&
>>> >                                      (id->bInterfaceProtocol ==
>>> > UIPROTO_PRINTER_BI)) {
>>> >                                          goto found;
>>> >                                  }
>>> >                          }
>>> >
>>> > What I did is temporarily replace these values in the USB definition.
>>> In
>>> > this case, how should the project handle this non-compliance USB
>>> devices?
>>> > Though I will raise this to Epson if they could provide an updated
>>> firmware.
>>> >
>>> > freebsd@generic:~ % diff -Nur /usr/src/sys/dev/usb/usb.h.orig
>>> > /usr/src/sys/dev/usb/usb.h
>>> > --- /usr/src/sys/dev/usb/usb.h.orig     2022-03-27 02:55:01.319235000
>>> +0800
>>> > +++ /usr/src/sys/dev/usb/usb.h  2022-03-27 02:57:10.608518000 +0800
>>> > @@ -459,8 +459,10 @@
>>> >   #define        UICLASS_PHYSICAL        0x05
>>> >   #define        UICLASS_IMAGE           0x06
>>> >   #define        UISUBCLASS_SIC          1       /* still image class
>>> */
>>> > -#define        UICLASS_PRINTER         0x07
>>> > -#define        UISUBCLASS_PRINTER      1
>>> > +/* #define     UICLASS_PRINTER         0x07 */
>>> > +/* #define     UISUBCLASS_PRINTER      1 */
>>> > +#define        UICLASS_PRINTER         0xff
>>> > +#define        UISUBCLASS_PRINTER      0xff
>>> >
>>> > I can print now with ulpt(4) driver but need further testing for any
>>> issues.
>>> >
>>> > ugen1.5: <EPSON EPSON UB-U03II> at usbus1
>>> > ulpt0 on uhub1
>>> > ulpt0: <EPSON EPSON UB-U03II, class 0/0, rev 1.10/2.00, addr 5> on
>>> usbus1
>>> > ulpt_attach: setting alternate config number: 0
>>> > ulpt0: using bi-directional mode
>>> >
>>>
>>> Hi,
>>>
>>> I think you can just extend that piece of code to accept either value
>>> using a boolean OR, ||.
>>>
>>
>>
>> Hi Hans,
>>
>> Ah okay, this is noted. I just thought it's not allowed. I already
>> extended the code and on the way re-building the kernel.
>>
>
>
> Hi Hans,
>
> Here are the changes I've done in the /usr/src/sys/dev/usb/serial/ulpt.c
> source. This works both now with my Epson TM-U220B and Xprinter printers.
> It can detect either or both in 14.0-CURRENT. So far I haven't encountered
> any strange behavior while printing using this ulpt(4) driver.
>
> freebsd@generic:~ % diff -Nur /usr/src/sys/dev/usb/serial/ulpt.c.orig
> /usr/src/sys/dev/usb/serial/ulpt.c
> --- /usr/src/sys/dev/usb/serial/ulpt.c.orig     2022-03-21
> 19:44:29.178010000 +0800
> +++ /usr/src/sys/dev/usb/serial/ulpt.c  2022-03-31 16:57:53.317952000 +0800
> @@ -495,6 +495,11 @@
>          USB_IFACE_SUBCLASS(UISUBCLASS_PRINTER),
>          USB_IFACE_PROTOCOL(UIPROTO_PRINTER_BI)},
>
> +       /* Bi-directional USB vendor specific */
> +       {USB_IFACE_CLASS(UICLASS_VENDOR),
> +        USB_IFACE_SUBCLASS(UISUBCLASS_VENDOR),
> +        USB_IFACE_PROTOCOL(UIPROTO_PRINTER_BI)},
> +
>         /* 1284 USB printer */
>         {USB_IFACE_CLASS(UICLASS_PRINTER),
>          USB_IFACE_SUBCLASS(UISUBCLASS_PRINTER),
> @@ -555,9 +560,11 @@
>                                 break;
>                         } else {
>                                 alt_index++;
> -                               if ((id->bInterfaceClass ==
> UICLASS_PRINTER) &&
> -                                   (id->bInterfaceSubClass ==
> UISUBCLASS_PRINTER) &&
> -                                   (id->bInterfaceProtocol ==
> UIPROTO_PRINTER_BI)) {
> +                               if ((id->bInterfaceClass ==
> UICLASS_PRINTER ||
> +                                   id->bInterfaceClass == UICLASS_VENDOR)
> &&
> +                                   (id->bInterfaceSubClass ==
> UISUBCLASS_PRINTER ||
> +                                   id->bInterfaceClass ==
> UISUBCLASS_VENDOR) &&
> +                                   (id->bInterfaceProtocol ==
> UIPROTO_PRINTER_BI)) {
>                                         goto found;
>                                 }
>                         }
>
> In the /usr/src/sys/dev/usb/usbdevs, I think there's a need to include the
> undefined TM-U220B.
>
> freebsd@generic:~ % diff -Nur /usr/src/sys/dev/usb/usbdevs.orig
> /usr/src/sys/dev/usb/usbdevs
> --- /usr/src/sys/dev/usb/usbdevs.orig   2022-03-21 19:42:20.999397000 +0800
> +++ /usr/src/sys/dev/usb/usbdevs        2022-04-01 01:21:31.361567000 +0800
> @@ -1941,6 +1941,7 @@
>  product EPSON 2480             0x0121  Perfection 2480 scanner
>  product EPSON 3590             0x0122  Perfection 3590 scanner
>  product EPSON 4990             0x012a  Perfection 4990 Photo scanner
> +product EPSON TMU220B          0x0202  TM-U220B
>  product EPSON CRESSI_EDY       0x0521  Cressi Edy diving computer
>  product EPSON N2ITION3         0x0522  Zeagle N2iTion3 diving computer
>  product EPSON STYLUS_875DC     0x0601  Stylus Photo 875DC Card Reader
>


Here's the dmesg showing ulpt0 and ulpt1 respectively with my printers.

ugen1.5: <EPSON EPSON UB-U03II> at usbus1
ugen1.6: <Printer-58 USB Printing Support> at usbus1
ulpt0 on uhub1
ulpt0: <EPSON EPSON UB-U03II, class 0/0, rev 1.10/2.00, addr 5> on usbus1
ulpt0: using bi-directional mode
ulpt1 on uhub1
ulpt1: <Printer-58 USB Printing Support, class 0/0, rev 2.00/2.54, addr 6>
on usbus1
ulpt1: using bi-directional mode
ulpt1: offline