vrijdag 9 oktober 2020

Adding USB ports to an old router (WRT54GL)

I needed a wireless Linux device with an antenna, preferably free. Luckily I had an old router laying around, as you do, and it already has Linux on it, aren't I a lucky old fella. I hooked it up, brute-forced the password manually by memory and gave the device a long needed firmware upgrade... a 9 year old image.

The problem

Device up and running, next step is popping a shell and start getting software on the thing. Sadly the Linksys WRT54GL only has 4MB internal flash storage, and the OS takes a (relatively) big chunk. If only this old friend had a USB port or something...

The Mod

I quickly stumbled upon possible hardware hacks which listed adding an SD card or USB port(s). For multiple reasons I chose USB, you can disagree with me in the comments below.

Easily I found multiple guides, for multiple versions. The general idea was the same, solder some wires to the PCB, some resistors a USB port and some jenky way of getting 5V, simple enough.

I followed this guide on the OpenWrt wiki and soldered wires to the appropriate resistors (21, 23, 25, 26). Then I proceeded to complete the circuit on a breadboard. I installed the needed USB kernel modules and checked dmesg.

usb.c: new USB bus registered, assigned bus number 1
hub.c: USB hub found
hub.c: 2 ports detected

Halfway there, right? Let's connect a drive.

usb.c: USB device not accepting new address=2 (error=-145)

That doesn't seem like it's working properly...

The this-always-happens-to-me

Okay, so here's the thing. Whenever I attempt to do anything like this it never works for me, either I have some slightly different version or some other glitch-in-the-matrix type thing causes me to encounter corner cases that don't seem to be documented anywhere else. For those who are on the same quest as I have been, I hope this post is helpful to you.

So maybe the guide is wrong? I came across other guides like the DD-WRT one which point to other resistors (19 and 20). So what the hell, let's try that, what have I got to loose?

Long story short this didn't work at all. The USB hub was still detected but alas no devices at all. So I re-soldered the tiny SMDs back to the board. This was a step in the wrong direction, back to the first mod.

Soldered the wires back to 21, 23, 25 and 26 and broke out my Google-Fu.

The clue

Since I am messing with hardware I'm assuming the fault is there so searching for the error seemed to return a lot of useless results as most of them were not soldering shit on their machines. There was however one slight clue on this site where someone builds their own USB device? (didn't read it fully, sorry bro.)

Apparently the error 'device not accepting address' means that the pull-up resistor is detected, but not necessarily anything else. Clock speed, zener diodes and I/O setting of pins can be wrong.

 The shot in the dark

So, there's something going on with the pull-up resistor apparently. Maybe the signal is too weak? I don't know, I'm not qualified to work on this. So I removed the 22ohm resistors between the data wire and the USB port and tried again, what's the worst that could happen?

hub.c: new USB device 00:03.0-1, assigned address 2

Fuck yeah! Success at last.

The end-result

I created a prototype PCB and screwed that to the case, I'm tired of using hot glue, after a while it loses it's grip. I added a connector to the board so that I could just plug in a regular PC USB bracket I had.

Cut 2 holes with a knockoff Dremel for the USB ports and drilled two holes to mount it.

The end result looks nice, except for the leftover duct-tape from previous abuse.

The solution

So this is what I ended up doing. I soldered a wire to each of the resistors 21, 23, 25 and 26 on the side closest to the Broadcom chip. These are the USB data lines.

21 = data+

23 = data-

25 = data+

26 = data-

Each wire is connected directly to the appropriate USB pin and to a 15K resistor which goes to ground.

USB also requires a 5V power source which I provided with a 7805. I stole 12V from the WRT54GL's power socket as input for the 7805 and tapped the ground from the power socket as well. 12v and ground go to the 7805 and 5V comes out, simple! All of the power circuits I encounter add capacitors so I did this as well, however as I don't have a lot of capacitors laying around so I used different ones (50V, 0.22uF or something, does this really matter that much? What's the science behind this?) The electrolytic capacitors are connected between 12V-GND and 5V-GND, mind the capacitor direction!

The firmware I used is this image: http://downloads.openwrt.org/backfire/10.03.1/brcm-2.4/openwrt-brcm-2.4-squashfs.trx

To get the USB mod working we need drivers:

opkg update
opkg install kmod-usb-ohci kmod-usb-storage kmod-usb-core

Well, that's it, now my old router has two USB 1.1 ports.