Introduction: NLDWRTG the ULTIMATE WRT54G Expansion Board
I'm modding WRT54G routers since 2006 but never had time to actually design a dedicated board for it until last year.
This hardware is still one of the most hackable wifi routers at the time of writing and deserves to be kept alive.
Step 1: Brief Overview of the Linksys WRT54G Series
https://en.wikipedia.org/wiki/Linksys_WRT54G_serie...
There are lots of different versions on the market so let's take a look which can be modified:
-WRT54G 2.0/2.1/2.2 -> Although all the mods are possible the big old motherboard taking up all the space in the case, if you modify this series you have to move your circuit outside of the box or create a completely new casing (srsly don't worth the effort)
-WRT54G 4.0 Switched to new SoC -> This was the first board where the L shaped motherboard was introduced so this is the first version where you can take advantage of my shield and insert it into the case
-WRT54GL 1.0/1.1 -> Linksys released the WRT54GL (the best-selling router of all time) in 2005 to support third-party firmware based on Linux, after the original WRT54G line was switched from Linux to VxWorks, starting with version 5. The WRT54GL is technically a reissue of the version 4 WRT54G. This model is the KING of WRTGs. There are a lot of second hand routers around the market so if you have a choice which type to buy, ALWAYS buy the WRT54GL.
-WRT54G 5.0 and higher -> Uses VxWorks OS and reduced Flash Memory; not compatible with most third-party firmware, although the "VxWorks killer" utility allows some third-party open source firmware to be loaded on this and future versions. Linksys made a bad turn here and essentially ruined a completely good product. Although it is possible to modify these, the space on the router is so small (2MB) it can only fit the DD-WRT micro firmware which pretty much cannot do anything beyond regular routing functionality (no VPN, no smbfs/cifs, no NFS, no mmc, no ext2). I have managed to create kernels for this series and squeeze in 1-1 required module on the cost of taking out others. It does NOT worth your time and effort, do NOT buy these routers.
With the later WRT series Linksys switched to ARM architecture for example the WRT1200 AC has 1.3 GHz dual-core ARM cpu. I have however bad experience with these routers even after trying out multiple OpenWRT (now LEDE) versions the routers can freeze randomly. I expect 300+ days uptime form unix devices.
Step 2: Extending the Functionality
Ok so what hacks can you do with this router:
1, Add 2x serial ports -> which can come handy if you have other servers on a remote location and you want to connect to their bios over serial line or other routers, swtiches which allowing this
2, Add 1 USB1.0 port -> could be used to connect printer, external hard drive etc (I never did this mod, so it won't be part of the writing)
3, Add external SDcard for storage, this can extend your router's little 16MB flash storage memory to 16/32/...+GB. I had no problem with using these size of SDcards and also no problem with using brand new durable CLASS 10 cards. If you have experimented with what is the limitation of cards per WRTG models please leave a comment down below.
4, Add an arduino to control your home, relays, rcswitches
Adding an arduino essentially opening up an unlimited amount of options: robot control, controlling infrared devices in sight (TVs, VCRs, DVDs, Projectors, Air Condition), hooking up tons of devices to cheap 433Mhz wireless switches, communicating with other arduinos, raspis, adding an Xbee etc etc.
Although this could be all done with a Raspberry PI + Arduino and extensions, I consider the WRT54G router more reliable than the raspis. I have these routers in similar configurations with over 1 year (!) uptime, I couldn't say the same about the raspis where my highest uptime was around 240 days on a raspi 1 then the SDcard give up on the system, although the C Arduino control code was loaded into the memory so I did not have to hurry with the replacement since the control node was still perfectly functional :))
Step 3: Hardware List
I am attaching the board layout in both SVG and EasyEda format. If you want to build the project you will need the following components:
1x LM7805 Voltage regulator
2x caps for vreg 1uF 10uF (10PCS Electrolytic Capacitors 25V 35V 50V 1uF~1000uF Various Value and Voltage)
1x 4 pin cable from the SDcar to the board (10Pcs Jumper Wire 2/3/4/5/6/7Pin Female to Female Dupont Cable 20cm for Arduino)
2x DIP051A7212D Reed Relays
1x RS232 male socket (20 pcs 9 pin D-Sub DB9 Male Right Angle PCB Connector WT7n)
1x MAX 233 (10Pcs Max233 Max233cpp Rs232 Rs-232 Driver/Receivers Ic New X)
1x 10 pin connector cable (5Pcs 2mm Pitch 2x5 Pin 10 Pin 10 Wire IDC Flat Ribbon Cable Length 10CM)
1x 10 pin socket (20Pcs 2.54mm 2x5 Pin 10 Pin Straight Male Shrouded PCB Box Header IDC Connector)
1x Connector headers (10pc 1*40Pin Single Row Female 2.54mm Breakable Header Connector fr Arduino 2017)
1x SD Card (can be old big SD or new microsd with converter, under 32GB in size they should work, over that I did not test cards)
1x 3v5v TTL converter (5x Logic Level Converter 3.3V to 5V TTL Bi-Directional for Arduino Raspberry pi)
1x 4n35 optocoupler
1x SD Card Module Slot Socket Reader For Arduino ARM MCU Read And Write
1x Arduino Promicro (5Pcs Leonardo Pro Micro ATmega32U4 16MHz 5V Replace ATmega328 Arduino Pro Mini)
1x RX and TX modules buy them as a combo pack (5pcs 433Mhz RF transmitter and receiver kit for Arduino Wireless Remote Control)
Step 4: Hardware Design
-Board screws into the main black plastic bottom board part
-MAX233 was chosen over the MAX232 so no additional caps will be required for the PC->WRTG serial converter
-All components are in 1 line so a simple rectangle can be cut at the front instead of drilling multiple holes, alternatively a nice cover plate (or a whole new WRTG case) could be designed with makerbot
-The arduino promicros micro USB socket facing the front panel for external programming.
-Based on Arduino Promicro (arduino is feeding from the 12V input of the WRT54G router (thorugh a voltage regulator), the open circuit voltage of the adapter is about 16V!)
-The Promicro has real usb, not shared rubbish so the WRTG's /dev/tts/1 can be wired to the Promicro's hardware UART
-Serial communication through /dev/tts/0 between PC < > WRTG
-RF 433Mhz receiver + transmitter (transmitter could take 12V for higher range)
-IR transmitter and receiver can be added to the front panel
-Additional LEDs can be added to the front panel (indicate Rx/Tx for RF, IR, router/ardu comm indicator)
I could've design the board with a mini buck converter but took the linear voltage regulator approach since I had that in hand. I have found 5V some point of the circuit but when tapping to it rendered the router unusable (probably couldn't provide the amount of current the arduino board needed), therefore I went with an additional vreg approach.
The 3v5v TTL converter is there to provide the proper volatage conversion (I'm using an 5V arduino promicro model, which uses 5V on it's hardware UART port, therefore voltage level conversion is required). However I have modded routers in the past adding Arduino Nanos, Micros without the converter and didn't have an issue since the WRTG's TTY port is 5V tolerant but it does not mean that you should operate it from this voltage.
The 4n35 was also introduced to get rid of some noise originating from the external PC side, I did not use this component in the past but it can also be because the laptop I have used during the tests was faulty.
The 10pin connector cable takes care most of the connections however you have to make sure you install the sockets correctly.
As it is shown on the picture at the serial port
Pin 1: 3.3V + Pin 2: 3.3V <= The 2 far right pins (closer to the LEDs) are the POSITIVE connects to the right side of the connector on the NLDWRTG shield (close to the LM7805 voltage regulator)
Pin 9: GND + Pin 10: GND <= Opposite side are the NEGATIVE connects to the left side of the connector on the NLDWRTG shield
For connecting the wires between the SDCARD reader and the WRTG follow:
https://www.jbprojects.net/articles/wrt54gl_mods/
The relevant pins:
- CS -> Point 1
- MOSI -> Point 2
- SCK -> Point 5
- MISO -> Point 7
Step 5: Limitations
The WRT54GL's CPU is not the strongest (Broadcom BCM5352 @ 200 MHz), can be overclocked to 250Mhz (it is not recommended :)) so don't expect to run SETI@HOME on it.
The router -only- have 100mbit/s interfaces and unlike what you can find on a lot of places this hardware *DOES NOT support 802.1q VLANs*. It's only a simple port based VLAN, please do not put the WRTG in a network transporting VLANs, it cannot do it.
One particularly useful application is using the router as VPN client to connect to a central location. Although it is perfectly usable for VPN server as well don't expect much performance out of it.
Here are some of my results with a WRT54GL v1.1 using OpenVPN as a client.
Maximum tunnel throughput: 500kbit/s down 50 kbit/s up
Maximum routing performance without VPN from WAN -> LAN 28 mbit/s
Maximum NAT (Masquerade) performance without VPN from WAN -> LAN 27 mbit/s
There are still a lot of locations with lower overall bandwidth than these (ISDNs, Adsls, Cable networks, Satellite etc) what this router can perfectly satisfy.
Usually the problems come from putting way too many wireless clients on these routers. I saw many setups over the years in coffees, hotels, restaurants where they throw one wifi router on the counter and call it a day, expecting it to be able to server 10+ people. All they get is a completely unusable wifi experience at the end since the overall theoretical bandwidth for this 802.11G router is 51 mbit/s and that is for everyone, let's say the real is around 30mbit/s. For 10 person that is 3mbit/s per user in best case which is nowhere enough for Todays bandwidth hungry (video/audio streaming, web 2.0 pages full of big pictures etc) applications.
As I stated earlier the point of this hack is remote control and that would not use more than couple of kbit/s traffic through a VPN.
Step 6: WRTG Software
The firmware is built on the best version: DD-WRT v24-sp2 (08/12/10) std-nokaid (SVN revision 14929) There are other images like the VPN which sacrifices the ext2 module to save space while still having the mmc kernelmodul (LoL).
Optware 2 is a discontinued but still useful utility package which extends the basic DD-WRT functionality:
-It makes a basic linux distro from the crippled down busybox installation.
-Provides bash and other shells.
-Provides lot of goddies like: htop, netcat, tcpdump, ngrep, mc
-Provides server serivces like: samba, asterisk, vsftpd, jabber server
However the software packages are old, ridden with bugs and vulnerabilities. Publishing and image here would be the same as providing a Window$ 98 installation, therefore I will not publish anything yet but write it down step by step how to setup your OptWare 2 SDCard.
In the future I planning to make a new linux distro (SnowGlobe Linux) with fresh packages for this device and publish that.
1, JFFS2 must be enabled, doesn't matter that it has no free space on it:
/dev/mtdblock/4 128K 128K 0 100% /jffs
2, SDCARD partitioning. Here is a clever trick:
14GB or whatever we want to have for the first data partition for ddwrt 100-500mb second partition (EXT2) for recovery
For example:
Disk /dev/sde: 14.5 GiB, 15523119104 bytes, 30318592 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x6ad48986 Device Boot Start End Sectors Size Id Type /dev/sde1 2048 29362175 29360128 14G 83 Linux /dev/sde2 29362176 30318591 956416 467M 83 Linux
Create filesystems:
mkfs.ext2 -L SnowGlobe-data /dev/sde1 mkfs.ext2 -L SnowGlobe-recovery /dev/sde2
Tune filesystems:
tune2fs -c0 -i0 -m0 /dev/sde1 tune2fs -c0 -i0 -m0 /dev/sde2
Only the first partition will be automounted by the system at start! The idea behind the recovery partition is that WRT54G has no space to hold an fdisk anywhere else. So if there is an unclean shutdown and there are filesystem inconsistencies, the only way to repair it is to have a copy of fdisk (and required libs to start) on a second partition which will be only mounted occasionally as read only to run fsck if needed. Otherwise the card would needed to be taken out and put into a pc for repair...
3, Mounting
If you put in an already partitioned, formatted card and wrtg boots properly it's most likely that the first partition will be automounted:
/dev/mmc/disc0/part1 13.8G 59.6M 13.7G 0% /mmc
Opt must be bind mounted now:
mount -o bind /mmc/ /opt/
4, OWRT2 install script
Before you begin check if defgw, dns all good.
wget http://www.3iii.dk/linux/optware/optware-install-... -O - | tr -d '\r' > /tmp/optware-install.sh sh /tmp/optware-install.sh
If it can't get the script that's because busybox wget fails. It will work with owrt's wget but hey you want to install owrt...
Output should look like:
Checking system config ... Using 192.168.1.1 as default gateway. Using the following nameserver(s): nameserver 192.168.1.30 Warning: local nameserver is different than gateway! Check config or enter: sed -i s/192.168.*/192.168.1.1/ /tmp/resolv.conf to correct this. Installing package uclibc-opt_0.9.28-13_mipsel.ipk ... Connecting to ipkg.nslu2-linux.org[140.211.166.82]:80 uclibc-opt_0.9.28-12 100% |***********************************************| 832 KB 00:00:00 ETA Updating /opt/etc/ld.so.cache /opt/sbin/ldconfig: can't create /opt/etc/ld.so.cache~ (No such file or directory) Installing package ipkg-opt_0.99.163-9_mipsel.ipk ... Connecting to ipkg.nslu2-linux.org[140.211.166.82]:80 ipkg-opt_0.99.163-9_ 100% |***********************************************| 75896 00:00:00 ETA Downloading http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/c... Inflating http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/c... Updated list of available packages in /opt/lib/ipkg/lists/optware Successfully terminated. Installing uclibc-opt (0.9.28-12) to /opt/... Downloading http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/c... package uclibc-opt suggests installing ipkg-opt Configuring uclibc-opt Updating /opt/etc/ld.so.cache Successfully terminated. Installing ipkg-opt (0.99.163-9) to /opt/... Downloading http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/c... Configuring ipkg-opt Successfully terminated.
5, Path bug:
You MUST export the path with:
export PATH="/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin:/bin:/usr/bin:/sbin:/usr/sbin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin:/mmc/sbin:/mmc/bin:/mmc/usr/sbin:/mmc/usr/bin"
otherwise ipkg will do nothing!
6, Verify ipkg:
ipkg update
Should output:
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/c... Inflating http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/c... Updated list of available packages in /opt/lib/ipkg/lists/optware Successfully terminated.
7, Install packages:
ipkg install bash htop mc openvpn tcpdump vim bzip2 bc e2fsprogs findutils gawk grep gzip less make ntfs-3g openssl perl php psmisc psutils samba36 sed tar unrar unzip vnstat vsftpd wget whois zip ncftp
8, List installed packages:
ipkg-opt list_installed
Building packages on the router is not advised due to the lack of resources. Setup separate mips crosscompiling environment in Vmware/Vbox/KVM for this purpose.
Things needed:
-Debian 7 wheezy 64bit host OS
-OpenWrt-SDK-Linux-x86_64-1.tar.bz2 ->
https://openwrt.org/docs/guide-developer/obtain.fi...
Don't waste time to try to compile the SDK on your own, the provided binary SDK is good enough.
Build a simple helloworld app
#include <stdio.h>
int main(void) { printf("Hell! O' world, why won't my code compile?\n\n"); return 0; }
./staging_dir_mipsel/mipsel-linux-uclibc/bin/gcc -lpthread hello.c -o hello
If everything goes right you should have a mips executable now:
hello: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked (uses shared libs), not stripped
Step 7: Arduino Software
You can download the full source code below. It is fairly simple, it can control the 2 relays and some RC plugs through 433Mhz radio. You can easily extend it eg: add more rc switches.
Attachments
Step 8: Closure and ToDo List
The WRT54G is an excellent hardware so all the work invested into this project well worth it, besides the NLD Wrtg shield might be usable with future hardware versions.
Since the power consumption of a WRTG is lower than the Raspberry PIs, solar powering the router can be also a good upgrade and with the Arduino we can monitor every detail of the solar charging process (battery voltage, panel voltage, consumption). I will continue the WRTG series with solar hacks later on.
Finding a way to program the Arduino directly from the WRTG would be great (this would require a method for resetting the Arduino).
People with 3D, Makerbot skills are more than welcome to design a custom cover plate (featuring the connectors of my board) for the front or redesign the complete plastic front part of the router.
UPDATE: To celebrate the MIPS architecture becoming Open Source, I have updated the tutorial with how to crossbuild simple C programs to the WRTG.
Long Live the MIPS! :)
system type : Broadcom BCM5352 chip rev 0
processor : 0 cpu model : BCM3302 V0.8 BogoMIPS : 199.47 wait instruction : no microsecond timers : yes tlb_entries : 32 extra interrupt vector : no hardware watchpoint : no VCED exceptions : not available VCEI exceptions : not available