apple / cups

Apple CUPS Sources
https://www.cups.org
Apache License 2.0
1.91k stars 464 forks source link

One "usb" CUPS backend for both libusb-based and usblp-based access #3357

Closed michaelrsweet closed 12 years ago

michaelrsweet commented 14 years ago

Version: -feature CUPS.org User: till.kamppeter

On Linux (and perhaps some other Unixes), the "usb" backend can currently be either compiled to access the printers through the "usblp" kernel module (/dev/usb/lp*) or through libusb (low-level USB), but one cannot have one backend which uses both access methods.

This causes a problem when transferring Linux distributions from the use of the kernel module to the use of libusb. Reasons why to switch libusb are:

  1. HPLIP (and soon perhaps more manufacturer-supplied backends) is libusb-based, it grabs the device and takes it away from the usblip-based usb backend of. This causes some confusion, especially the UDEV scripts must always check both the low-level signals and the usblp signals coming from the printer to reliably determine when a printer appears and when it disappears.
  2. The usblp-based backend disables bi-di access for several important manufacturers, as usblp does not work with most printers of them.
  3. The libusb-based backend supports also some more general access, for example to allow printing and non-printing functions on an MF device to be done in parallel. This allows to drop many manufacturer-supplied CUPS backends in the future.
  4. The possibility to get the serial number from every printer, even if the device ID does not contain it.

Problems of the switchover are caused by the absence of the usblp kernel module, for example printer firmware upload through /dev/usb/lp*, ecputil, libinklevel, ... Also URIs have changed and so printers created with the usb backend of CUPS 1.3.x will not work with the new 1ibusb-based backend.

The attached patch make one "usb" backend out of the two. This new backend

The attached patch is done in a somehow minimum invasive way, keeping the changes small. Probably one can simplify the code. It was also not tested whether whether it works with all possibilities of conditional compiling. I have tested on both the HP LaserJet 3390 and the HP PhotoSmart C8100. On both printers one can print with and without "usblp" loaded and without needing to re-create the print queues.

The patch is for CUPS 1.4.1.

michaelrsweet commented 14 years ago

CUPS.org User: till.kamppeter

Updated the patch for CUPS 1.4.3.

michaelrsweet commented 14 years ago

CUPS.org User: till.kamppeter

As talked about with Mike Sweet on the OpenPrinting Summit 2010 I have updated the patch. With this an easy transition between usblp and libusb without need to change the URIs of existing queues is possible and users of binary packages in distributions can choose whether they want to use usblp or libusb.

The patch is already in use in the Debian and Ubuntu distributions for several months and there are no user complaints about it.

michaelrsweet commented 14 years ago

CUPS.org User: sbd

Great patch, but there's no allowance made for "--disable-libusb", so I've posted a revison that does.

michaelrsweet commented 12 years ago

CUPS.org User: mike

Sorry, we have decided this issue will not be addressed in a CUPS release.

michaelrsweet commented 12 years ago

"usb-backend-both-usblp-and-libusb.patch":

--- backend/Makefile.orig 2009-09-29 14:22:59.000000000 +0200 +++ backend/Makefile 2009-09-29 14:24:47.000000000 +0200 @@ -267,7 +267,7 @@ echo Linking $@... $(CC) $(LDFLAGS) -o usb usb.o libbackend.a $(LIBUSB) \ $(BACKLIBS) $(LIBS) -usb.o: usb.c usb-darwin.c usb-libusb.c usb-unix.c +usb.o: usb.c usb-darwin.c usb-hybrid.c usb-libusb.c usb-unix.c

# --- backend/ieee1284.c.orig 2009-09-29 16:53:31.000000000 +0200 +++ backend/ieee1284.c 2009-09-29 17:01:15.000000000 +0200 @@ -275,6 +275,7 @@ cups_option_t values; / Keys and values in device ID / const char *mfg, / Manufacturer / *mdl, / Model */

+#if defined(linux) || defined(sun) || defined(FreeBSD) || defined(NetBSD) || defined(OpenBSD) || defined(DragonFly) || defined(FreeBSD_kernel)

-static int open_device(const char uri, int use_bc); -static int side_cb(int print_fd, int device_fd, int snmp_fd, +static int open_device_unix(const char uri, int use_bc); +static int side_cb_unix(int print_fd, int device_fd, int snmp_fd, http_addr_t *addr, int use_bc);

/*

-static void -side_cb(int printfd, /* I - Print file / +static int +side_cb_unix(int printfd, / I - Print file _/ int devicefd, / I - Device file _/ int snmpfd, / I - SNMP socket (unused) _/ http_addrt *addr, / I - Device address (unused) / --- backend/usb.c.orig 2008-06-24 03:28:36.000000000 +0200 +++ backend/usb.c 2009-09-29 14:21:51.000000000 +0200 @@ -56,7 +56,7 @@ /

ifdef HAVE_USB_H

-# include "usb-libusb.c" +# include "usb-hybrid.c"

elif defined(APPLE)

include "usb-darwin.c"

elif defined(linux) || defined(sun) || defined(FreeBSD) || defined(NetBSD) || defined(OpenBSD) || defined(DragonFly) || defined(FreeBSD_kernel)

michaelrsweet commented 12 years ago

"usb-backend-both-usblp-and-libusb-2.diff":

diff -up -rN cups-1.4.3.orig/backend/Makefile cups-1.4.3/backend/Makefile --- cups-1.4.3.orig/backend/Makefile 2010-06-09 20:58:19.641591399 +1200 +++ cups-1.4.3/backend/Makefile 2010-06-09 20:51:06.025595868 +1200 @@ -267,7 +267,7 @@ usb: usb.o ../cups/$(LIBCUPS) libbackend echo Linking $@... $(CC) $(LDFLAGS) -o usb usb.o libbackend.a $(LIBUSB) \ $(BACKLIBS) $(LIBS) -usb.o: usb.c usb-darwin.c usb-libusb.c usb-unix.c +usb.o: usb.c usb-darwin.c usb-hybrid.c usb-libusb.c usb-unix.c

# diff -up -rN cups-1.4.3.orig/backend/ieee1284.c cups-1.4.3/backend/ieee1284.c --- cups-1.4.3.orig/backend/ieee1284.c 2009-12-08 15:13:42.000000000 +1300 +++ cups-1.4.3/backend/ieee1284.c 2010-06-09 20:51:06.357598941 +1200 @@ -255,6 +255,7 @@ backendGetDeviceID( cups_option_t values; / Keys and values in device ID / const char *mfg, / Manufacturer / *mdl, / Model */

+#if defined(linux) || defined(sun) || defined(FreeBSD) || defined(NetBSD) || defined(OpenBSD) || defined(DragonFly) || defined(FreeBSD_kernel)

@@ -132,6 +142,10 @@ print_device(const char uri, / I - De _("INFO: Printer busy; will retry in 10 seconds...\n")); sleep(10); } +#ifdef HAVE_USB_H

- device_uri[1024]; /* Device URI string */

+#undef print_device +#undef list_devices +#undef open_device +#undef side_cb

/*