Friday, July 22, 2011

MiniDLNA upnp-av media sharing on DD-WRT

This is how to get UPNP sharing working from your router using MiniDLNA. I also got sharing working via UShare, but will write this with MiniDLNA because ushare is less compatible and no longer in development. This is a pretty straight forward and simple process if you're familiar with working in the DDWRT environment. The guide is derived from my install using a Buffalo WZR-HP-G300NH running Buffalo's official DDWRT distribution, svn 14889, but can be used for other builds.

Edit: Buffalo's official build mentioned above does not work with inotify. This module in the program allows scanning of watched folders without completely re-building the database.

First off, you need to have a useable IPKG or OPKG installed to automatically retrieve and install MiniDLNA and it's dependencies. The Software Installation tutorial is required to use this application.

Monday, July 18, 2011

Asterisk, the VoIP Server on DD-WRT

I'm a big fan of Asterisk on router -- imho, it's the perfect platform for anyone want to try Asterisk at home -- 24x7, fanless and even the cheapest router can handle at least 2-3 concurrent conversation. Before this WZR-HP-G300NH, I had Asterisk running on a WRT54G-TM for over a year with lots of fun.
Installing Asterisk on the router is easier now as current OpenWrt trunk build(the one we use) includes prebuilt Asterisk binaries. As always, since OpenWrt is designed to work with / not /opt, some adjustment is required to get Asterisk working properly.

Lighttpd and PHP on DD-WRT (Possibly OpenWRT too)

Busybox httpd is good for simple static pages, now here is a tutorial for installing lighttpd and php with fastcgi support in the router. Here I choose lighttpd over Apache for its light cpu usage and small memory footprint.

Since all our software are based in /opt folder, some modification must be done to get everything working:

Simple Busybox HTTP Server

By default DD-WRT runs its own http server (/usr/sbin/httpd), providing web management interface to configure the router. The server is highly integrated and hard to reuse for our own contents. If you just want to host some web pages without CGI support, the httpd server in busybox is a good alternative.

Set local time in DD-WRT

***This has been fixed in newer builds of DD-WRT - Check yours before continuing***

This never looks to be a problem since DD-WRT provides such extensive options. Unfortunately, unlike Tomato and OpenWrt, which do a good job, DD-WRT's approach is way off and completely wrong.

A Linux box can keep its time in either local time or UTC -- both are fine as long as the corresponding time zone info is presented. However, in DD-WRT, the time zone info is completely missing and instead of standard implementing used in almost all Linux distros, DD-WRT  coins a weird scheme to setup(and keep) the time.

For example, 8AM PST(GMT-8) should be 4PM GMT, but a DD-WRT router would "think" the current time is 8AM GMT. Now if you change the time zone to EST(GMT-5), what will the router think? 11AM GMT!! Yes, that's after you've set all the "time zone" info in DD-WRT web management page. This is usually not a problem if you just want to use it as a router but for a Linux server, you definitely don't want to deal with any file created in future.

Now here is the fix:

Upgrade DD-WRT and Keep Installed Applications

The DD-WRT support for these new 11N Gigabit routers are still in early stage with new builds rolling out every one to two weeks. The old good "if its not broken then don't fix it" rule might not apply here and I suggest to stay with latest release if you have the time(and guts).
Upgrading a DD-WRT firmware with loaded software is pretty easy, considering the extra work we've done. Take the trouble not to mess with important system folders like /lib /usr and /bin and now its the reward time.

Once again, this is why I use OpenWRT. Flashing an update doesn't nuke your whole install or require extra steps. Just flash, and finished.

Workaround for Stuck Beacon Problem

Stuck beacon is a notorious problem on madwifi (the wireless driver DD-WRT used for Atheros routers).  If you never experienced any wireless interruptions with DD-WRT then just ignore this article. However, if you're annoyed by this stuck beacon problem with constantly dropping wireless connection, then I hope this can be of help.

Below is a quick hack, not a completely fix but would make life a little easier. The idea is to watch the output of dmesg and when the "stuck beacon" error messages flood, reset the wireless interface to bring it back to life.

Wireless Scheduler with Cron Job

Cron is a time-based job scheduler in Linux systems which enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. In this example, we'll use cron to control the wireless signal, and set it to turn on only at given time.

DD-WRT is shipped with cron support, but again we'll use our own cron daemon as it's easier for future updates and will save some flash wearing.

Saturday, July 16, 2011

BitTorrent Client: Transmission on DD-WRT

If you've followed the previous guide to set-up the opkg system, then installing transmission on the system is a no-brainer. The configuration and system set-up can be a bit more difficult, but not bad at all. We will install the Transmission daemon, web access, and remote access. Optionally, you can grant WAN access and user/password security. Let's get started.

Print Server for DD-WRT (hotplug version)

Hotplug is a set of scripts running upon certain predefined conditions. On today's Linux system, hotplug can do many things from auto mounting USB drives to pairing bluetooth devices to network configuration.

It's seldom mentioned, but DD-WRT does offer (very preliminary) hotplug support. With almost no info on the web, the job is done by digging though DD-WRT's source code and various Linux documents.

Print Server for DD-WRT (simple version)

Since there's USB port on the router, any normal USB printer can become a network printer. As the router is usually on 24x7, there is no need to invest in a (usually overpriced) dedicated printer server.

The printer server program that we use here is p910nd. It's a very small (only 8KB) daemon which simply redirects all printing command from a PC to the printer. Setting up p910nd on the router can be a snap or very comprehensive, depends on the printer. The best scenario would be sharing a Postscript/PCL compatible one, which will be covered here.

Before we start, you'll need a USB hub if your router has only one USB port,
because we now need to connect a USB drive and a USB printer. As I said previously, I recommend a self-powered hub to prevent any power draw issues.

Friday, July 15, 2011

vsftpd: FTP Server for DD-WRT

I generally prefer Samba over FTP, as it gives a better experience by allowing user to access the files as if they're still on local disk. And, unlike FTP, media files can be played directly from Samba. But, one might still need a FTP server as it offers better performance over Samba.

If the router has at least 8MB flash ROM and happens to run DD-WRT MEGA build, it is very likely there is a proftpd FTP server built in.

So why install vsftpd? The main reason is its size. The proftpd is 500KB while vsftpd is only 100KB! This makes it perfect for embedded systems. Also, vsftpd is easy to use and setup.

Samba file server on DD-WRT

It's not easy to configure Samba in standard DD-WRT because, by default, the /etc folder is read-only. So before starting, please set a writable /etc. Also, DD-WRT does have a Samba3 built in the firmware and it works just fine, you're just not able to configure it fully. In this guide, you'll be guided through the whole process to set up a password protected samba share with custom usernames and passwords.

Monday, July 4, 2011

Software Installation on DD-WRT

One great thing about this router is its loaded hardware specifications: 400MHz processor, 32MB flash ROM, 64MB RAM and most important of all, a USB port. All these make the router a very versatile little Linux box with tons of capabilities. 

However, a confusing thing that inexperienced users may not know, the CPU in the router is MIPS (MIPS in big-endian), while the popular Broadcom routers(such as Linksys WRT54G) are MIPSEL (MIPS in little-endian). I don’t want to go into technical detail here, but just remember, even though both are MIPS, they’re totally different and software compiled for Broadcom routers WILL NOT work on this and other Atheros based devices.

Thanks to the OpenWrt guys, with some effort, we can now use the OpenWRT's optware software installer.

Here we come to another downfall of DD-WRT. OpenWRT will allow you to edit the on-board flash ROM and thus install anything you want directly to your router. DD-WRT doesn't provide this type of access, so we have to install programs to an external USB device. The previous blog poster claims that the USB is faster than the internal flash. This may be true for very high-speed drives, but I'd like to see numbers before also making that claim.

Let's get started & keep in mind that this set of instructions is for DD-WRT ONLY as it is not needed for OpenWRT.

Sunday, July 3, 2011

Firmware flashing and brick recovery over TFTP

Though the whole flashing process can be done via web interface without getting your hands dirty, there are cases that the web upgraded is not practical or possible. One common scenario is a semi-bricked router (no web access and no ping response due to bad flash or invalid operation, or you just want to try other firmware like OpenWrt). Luckily that the WZR-HP-G300NH has a robust bootloader and the router can be recovered by using TFTP, either in Windows, Linux or OSX. Flashing via TFTP isn't pretty, so read the appropriate section carefully at least once before attempting.

Flash between DD-WRT, OpenWRT and Buffalo's stock firmware on the G300NH

Flashing DD-WRT on this router is extremely easy - thanks to the hard work of DD-WRT developers and the official partnership with Buffalo. The official Buffalo DD-WRT version has a few bugs, and lacks support for a media sharing program that I use (minidlna - I will add a tutorial for it later), so I recommend downloading the latest stable snapshot from DD-WRT.

Flashing from stock to OpenWRT, or DD-WRT/OpenWRT to stock, is not as easy, but still very possible. Let's get started: