Usb Printers on OpenBSD

Pub:
Tag: OpenBSD

If you’re coming from Linux, you’ve probably noticed that OpenBSD has it’s quirks. One of these is how cups accesses usb printers.

A quick look at man /usr/local/share/doc/pkg-readmes/cups shows us

USB === Since USB printing will be handled by libusb, you need to allow the
_cups user access to the corresponding USB endpoint. To do so, find where your
printer is attached to using:
    $ usbdevs -v then change the ownerships accordingly.

e.g.  Controller /dev/usb0: <...> addr 05: 03f0:4812 HP, Officejet 7500 E910
         high speed, self powered, config 1, rev 1.00, iSerialNumber
MY2793100Q05JB
         driver: umass0
         driver: ugen1

# chown _cups /dev/ugen1.* /dev/usb0

...

To preserve your changes after a system update, use rc.local(8).
Alternatively, hotplugd(8) attach/detach scripts can automate this.

*** WARNING *** ulpt(4) needs to be disabled in the kernel (see bsd.re-
config(5)) or the printer will not be available to libusb: # echo 'disable
ulpt' >>/etc/bsd.re-config # reboot

This is a little dense, so let’s break it down.

First, we need to disable the ulpt for cups to see our usb printer. This is a little counterintuitive because according to it’s manual page:

The ulpt driver provides support for USB printers…

Nevertheless, it needs to go. The way we’ll do this is as follows:

As root run

# echo 'disable ulpt' >>/etc/bsd.re-config 
# reboot
to keep ulpt disabled from boot to boot. This is a little inconvenient, however, because it requires a reboot. We can achieve the same result with config:
# config -fe /bsd
OpenBSD 7.5 (GENERIC.MP) #82: Wed Mar 20 15:48:40 MDT 2024
    deraadt@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
Enter 'help' for information
ukc> disable ulpt # type this command at the prompt
321 ulpt* disabled
ukc> q            # and quit to save changes
Saving modified kernel. 
this allows you to modify the kernel as with the /etc/bsd.re-config file, but turns the usb port over to libusb and ugen without rebooting.

Now we need to actually allow the _cups user access to the printer’s respective usb port. First, we need to see how the usb printer device is connected to the system

$ usbdevs -v
Controller /dev/usb0:
addr 01: 1912:0000 Renesas, xHCI root hub
         super speed, self powered, config 1, rev 1.00
         driver: uhub0
addr 02: 04f2:b6cb Chicony Electronics Co.,Ltd., Integrated Camera
         high speed, power 500 mA, config 1, rev 59.18, iSerial 0001
         driver: uvideo0
         driver: uvideo1
         driver: ugen0
Controller /dev/usb1:
addr 01: 03f0:4812 HP, Officejet 7500 E910
         high speed, self powered, config 1, rev 1.00, iSerialNumber MY2793100Q05JB
         driver: umass0
         driver: ugen1
On my system, I see something like the above. Take note of the bolded text. The printer is connected to the computer by /dev/usb1 with the ugen1 driver. Depending on how your printer is connected to your pc, these will be different (and may change between boots).

Quick side bar: if you see ulpt instead of ugen, you’ve done something wrong. Check your /etc/bsd.re-config, reboot, and check usbdevs -v again.

To give cups access to your printer, just run (where the bolded text is what you see for your printer)

# chown _cups /dev/ugen1.* /dev/usb1

God willing, you should be able to print! Now that you’ve got everything running it would be a good idea to automate it. I use my usb printer fairly infrequently, so I run these commands manually each time, but if you keep your printer in the same usb port you could put the chown command into your /etc/rc.local script.