Thursday, February 12, 2015

OpenWRT Wireless Print Server Recap

Here is a friendly recap of my lengthy process of setting up my router as a Wireless Print Service with OpenWRT. My router was a WNDR3400 v1 (N600).

In the first part I discuss (briefly) the process of installing OpenWRT and which distribution you should use. From there I just get the device online as another WiFi client on my network with a static address.
In the second part I cover connecting your USB printer to the router. Not all printers are going to be the same but the process is pretty easy. Mostly the difficult part is using the correct USB drivers.
Lastly, we cover setting up ZeroConf aka Bonjour so that you don't have to remember any information about your printer. It is pretty easy with mDNSResponder. Using mDNSResponder is so easy nobody has written any basic tutorials about the usage.
Do you hate yourself? Do you love Avahi Daemon? For whatever reason you might want to read this part I got ZeroConf aka Bonjour setup using avahi-daemon but it was a pain in my rear end. You can read all about it in Part Four if you really want to. It removed days from my life so I hope it might help convince you that mDNSResponder is way better.
Maybe this series will help you. Maybe it'll help me when I need to remember what I did in 6 months.

Wednesday, February 11, 2015

Using a Netgear WNDR3400 as an OpenWRT Wireless Print Server (Part 4)

Note: Don't follow these directions because the avahi-daemon is terrible and it will hurt your feelings. You can read this garbage but I'd advise you against actually following the directions.

Ready to turn back? Part 3 of this series tells you how to use mDNSResponder instead and you should go there.

First, I got bored of the system having a stupid default hostname and being the wrong timezone so I updated them. Use `vi /etc/config/system` or however you want. Possibly don't do it at all because it's not important.

        option hostname N600
        option timezone CST6CDT,M3.2.0,M11.1.0

Second, get the Avahi bits up and running for ZeroConf so the printer can be automatically detected.
opkg install avahi-daemon
/etc/init.d/avahi-daemon enable
Now, tweak the Avahi config because the avahi-daemon is consistently compiled badly. So run `vi /etc/avahi/avahi-daemon.conf` and disable the dbus piece by adding the below option to the [server] section of the config file. Here you'll need to enable access to wlan1 because that's what the interface on radio1 is called.
Lastly, enable avahi and start it up.
/etc/init.d/avahi-daemon enable
/etc/init.d/avahi-daemon start
Third, setup your Avahi services properly. So delete the services that exist because they aren't going to be used and create a new service file.
rm /etc/avahi/services/http.service
rm /etc/avahi/services/ssh.service
vi /etc/avahi/services/p910nd.service
Your own service file will be a little different. Enter a model name close to the name of your actual printer and the Mac add printer dialog will be pretty helpful in finding the right drivers. I was surprised that mine worked without a problem.

This is an XML blob but blogger decided it hated me and totally destroyed it. As I don't suggest you use Avahi-Daemon anyway I'm not going to fix it. Buyer Beware.

  Lexmark E232 on WiFi
    usb_MDL=Lexmark E232
You can probably remove a lot of those records about binding and collating, but they were in the example I had and I didn't want to make sure.

Fourth, reboot your router again and cross your fingers. If you are lucky you are done fiddling on the command line and you can get back to the real world of mouses and dialog boxes. If you are unlucky you will end up restarting the avahi-daemon service every time you boot your router. So get used to logging in and using
/etc/init.d/avahi-daemon restart
Fifth, uninstall avahi-daemon because you have to manually restart the daemon every time you restart your router and this whole thing was an exercise in futility because the mdns stuff is so much easier to work with and is intentionally really lightweight and all around better.
/etc/init.d/avahi-daemon stop
/etc/init.d/avahi-daemon disable
opkg remove avahi-daemon --autoremove

Tuesday, February 10, 2015

Using a Netgear WNDR3400 as an OpenWRT Wireless Print Server (Part 3)

This is part of a series of blog posts.
Continued from Part 2

Note: Always `opkg update` before you `opkg install.`
Note: This works perfectly for my printer and my Mac. Your results may vary.

First, you want to install mDNSResponder. OpenWRT has a package for both `howl-mdnsresponder` and `mdnsresponder` available. The howl variant has been around for years and they recently decided that it will no longer be supported instead focusing on the real version. I decided to go with the good old reliable version. You can probably get the real responder to work exactly the same but I made my choice. You'll need to install it.
opkg install howl-mdnsresponder
Second, you'll need to configure it. It's super simple. Just edit your mDNSResponder config file with `vi mDNSResponder.conf` and add the following line. You can remove anything that was there if you want. Replace the text in `product=(*)` with your actual printer name. My Mac was smart enough to figure out exactly what driver it needs.
"OpenWRT Printer"  _pdl-datastream._tcp  local.  9100  "txtvers=1"  "note=Office"  "product=(Lexmark E232)"
Third, you'll want to setup automatic restarts of mDNS service. The mDNS service starts real quick, but unfortunately it takes a couple seconds for the WiFi service to connect. You want to restart the service after the WiFi is live so all the other computers around can be friendly.

You could manually restart the service after every reboot but that could get tedious constantly typing `/etc/init.d/mDNSResponder restart` if it isn't on an UPS. Fortunately, OpenWRT has a great little service they call hotplug. Just put some shell scripts in the right folder and they are run networks are activated or buttons are pressed. So just start up an editor for a new file.
vi /etc/hotplug.d/iface/80-mDNSResponder
The name `80-mDNSResponder` is completely arbitrary it is suggested that you name the file with a number in the front so you can tell what order they run in and I wanted it to run pretty late. Now just put the text below in the new file.
if [ "$ACTION" = ifup ] && [ "$DEVICE" = wlan1 ]; then
  /etc/init.d/mDNSResponder restart
That says if the wlan interface is brought up restart the mDNSResponder service. Pretty straight forward.

Fourth, restart your router again. Find the System Preference for adding a new printer and it should show up there as a Bonjour available device.

You are done. Go celebrate.

Part 4 exists, but don't go there.

Monday, February 9, 2015

Using a Netgear WNDR3400 as an OpenWRT Wireless Print Server (Part 2)

This is part of a series of blog posts.
Continued from Part 1

Note: Always `opkg update` before you `opkg install.`

First, load up the correct USB modules. You'll want to make sure USB 1.1 drivers as well as USB 2.0 drivers are loaded because somethings that should be 2.0 default to 1.1 really easily and you'll get confused. Luckily we know the WNDR3400 uses the OHCI (Open Host Controller Interface) parts for USB v1.1 so you can load those easily enough.
opkg install kmod-usb-ohci
This threw an error, but it doesn't seem to hurt anything. Now you'll want to install the USB v2.0 drivers because you'll probably need them as well.
opkg install kmod-usb2
Did you like how you got an error that didn't make sense last time? Did you like getting another error that seemingly shouldn't happen?

Second, reboot your router. After the router is booted wait a minute or two then plug in your printer and run `dmesg` to look for confirmation that your router is talking to your printer. Because you waited for some amount of time your printer detection should be the last line of `dmesg.`
usb 2-1: new full-speed USB device number 2 using ohci-platform
Third, install the printer software. The p910nd printer server is ideal because it is a diskless print setup. So you don't have to worry about print jobs filling up the RAM or storage on your router. That's obviously an issue that'd quickly arrive if you print any PDF. The documentation on the subject is excessive so I'm gonna just give you the good parts.

You'll just need to install support for USB printers and the print server package.
opkg install kmod-usb-printer
opkg install p910nd
After seeing random errors from the last directions it's nice to see things run smoothly isn't it?

Fourth, reboot and make sure everything is working as expected.  Use `dmesg` again and you should find a line in there that's something like below if you did everything correctly.
usblp 2-1:1.0: usblp0: USB Bidirectional printer dev 2 if 0 alt 0 proto 2 vid 0x043D pid 0x0091
Fifth, enable your printer in the p910nd config. I used `vi /etc/config/p910nd` and change the value for `option enabled` from 0 to 1. At this point you can reboot again to make sure everything is working as expected but I'm tired of all that so just restart the p910nd service with `/etc/init.d/p910nd restart` and you are ready to go.

Occasionally the p910nd doesn't completely enable it self properly. So you might need to enable it here or later or a couple times even.
/etc/init.d/p910nd enable
(Optional) Sixth, verify that your pinter works. The Print Server Documentation linked above has a bit about setting up every client that's available. It's hard to trudge through to find what you are looking for and we'll actually set it up on the Mac easier than all that later. So check if you want. I won't blame you.

Continued in Part 3

Sunday, February 8, 2015

Using a Netgear WNDR3400 as an OpenWRT Wireless Print Server (Part 1)

This is part of a series of blog posts.

Note: I have a WNDR3400 v1 so that's all I care about.

Welcome to the wonderful world of woefully inadequate documentation. It seems like everybody wants/likes to talk to their devices via serial ports but I think that's kind of dumb. I don't want to have to build or connect custom hardware bits. I just ssh to it at like a boss.

Overview of Part 1
Basically we are going to take a stock router from out of the box to a device on your network (skipping all the parts that are documented to death) and able to ping. We'll keep the 4 LAN ports untouched (so you can still use them to directly access and tell the

First, you hopefully have read enough about OpenWRT and the like to get a general idea what you are doing. That's great. Unfortunately a lot of what you have read is out of date if you are working on an older piece of hardware.

Second, open up your router because you are going to be flashing the firmware often. I think I've ended up flashing mine at least 10 times. The easiest way to get new firmware on the box is to short a pin and TFTP the new file at your leisure (no worrying about timing or memory).
There are a lot of posts about how dangerous this may potentially be, but I haven't had any problems. It's super easy and the router has almost zero value so I'm not afraid of destroying it.

Third, ignore the OpenWRT Wiki page about this router. You shouldn't have any reason to use the trunk/snapshot version. It'll only cause you headaches if you are tinkering while they release a new snapshot (unless you really like upgrading your kernel). The Wiki has links to 404s of old snapshots as the "recommended firmware" so that should be a good indication that you shouldn't trust it. Go ahead and download the most recent stable version. It is currently Barrier Breaker.
Fourth, flash your router with the firmware and telnet into it so you can set a password and ssh into it from now on. This is documented to death and you said you read some of the docs right?

Fifth, connect your router to your wifi. The OpenWRT Wiki page about setting up a Bridged Client is pretty much spot on and includes somethings you won't have to do. I'm glad they haven't completely given up on keeping their docs updated.
So just follow Step 1 of that Bridged Client article for now. I like to `vi /etc/config/wireless` and set things up like that but you can go your own way. I decided to enable and use `radio1` for this because it supports b/g so it more closely matches what my network already runs.

It is vitally important that you set the correct channel for your WiFi network. I managed to accidentally skip that and spent a few days trying to figure out what went wrong. Also, that `option network wan` bit is important because it's where we tell the device that the new access to the network is via wireless.

Sixth, reboot your router. You should now see a fun blue light blink occasionally on boot. That means your antennae is trying to work. I won't stay lit so don't worry too much.

Seventh,  disable some services you won't be needing. Yeah, you could disable quite a few services but the only ones that could get in your way are the firewall and DHCP servers.
/etc/init.d/firewall stop
/etc/init.d/firewall disable
/etc/init.d/dnsmasq stop
/etc/init.d/dnsmasq disable
Eighth, fully enable wireless access. Remember how we said that the radio was going to work on wan? Now go ahead and edit your network file with `vi /etc/config/network` and delete anything in the wan config and replace it with pieces to make it a fully static IP.
option proto 'static'
option ipaddr ''
option netmask ''
option dns ''
option gateway ''
My router is x.1 and all my other boxes pick up IPs starting in the x.100 range so I keep the lower numbers for devices that should be static. I want to easily access this device so I made it x.2. I didn't want to set this up grabbing a dynamic IP because it would make it impossible to find on my network if it doesn't have any avahi stuff setup.

Ninth, unplug any network cables and reboot your router. You should now be able to ping it and ssh to it as a device on your network. It is free!