Friday, February 1, 2008

NSLU2 + DWL-G122 = NAS with Wi-Fi

Our starting point is a Linksys NSLU2 with Debian GNU/Linux 4.0 (alias etch) and a D-Link DWL-G122 Ver. C1 USB Wi-Fi adapter. The Debian's Linux Kernel for the NSLU2 comes with no drivers for the DWL-G122, so it is necessary to compile them. The C1 version of the DWL-G122 has inside the rt73 chipset from Ralink and its source code can be found in the rt2x00 project page. They offer two types of drivers: 'enhanced legacy drivers' and 'next-generation rt2x00 drivers'. The next-generation drivers often fail to compile with not up to date kernel releases, so I decided to use the legacy ones. The steps I followed to compile them are does described in this forum (first comment form Sinclair73). So, in the NSLU2 with Debian (with the make, gcc & co. packages installed) one must execute:

1) Download and uncompress the driver's source code:
$ wget
$ tar zxvf rt73-cvs-daily.tar.gz

2) Edit the Module/rtmp_init.c file to change the RTMPMoveMemory function body to only { memcpy(pDest, pSrc, Length); }
$ cd rt73-cvs-AAAAMMDDHH
$ vi Module/rtmp_init.c
// RTMPMoveMemory must change to:
VOID RTMPMoveMemory(
  IN PVOID pSrc,
  IN ULONG Length
memcpy(pDest, pSrc, Length);

3) Compile the driver:
$ cd Module
$ make arm

4) Copy the resulting rt73.ko module to an appropriate place under /lib:
$ su
# mkdir -p /lib/modules/`uname -r`/kernel\

# cp rt73.ko /lib/modules/`uname -r`/kernel\

5) Copy the rt73.bin firmware to /lib/firmware:
# cp rt73.bin /lib/firmware

6) Update module dependencies:
# depmod

7) Edit the /etc/network/interfaces file according to the configuration of the wireless network. The alias for the DWL-G122 interface will be wlan0. For example, if we have an open network with static ip addresses, the wlan0 stanza in the /etc/network/interfaces file could be:
allow-hotplug wlan0
iface wlan0 inet static
pre-up ifconfig wlan0 up
  pre-up iwconfig wlan0 mode Managed
  pre-up iwconfig wlan0 essid

With all this steps done, we can place our NSLU2 on any place in our home. There are other options to have a wireless NAS, like the Asus WL-HDD 2.5, but installing other GNU/Linux flavors on them besides the manufacturer one is not so 'worked out' as with the NSLU2. And if we have all ready a NSLU2, it is good to have this 'expansion'.

Here you can find a lot more information about other ways to have your NSLU2 working with a wireless network adapter.

Notes: I had some instabilities with this configuration: some times, at power on, the link was not up, and time to time it went down. In this cases the fix was always to bring down and up the link with:
# ifdown wlan0
# ifup wlan0

or unplug and plug again the DWL-G122 if a telnet/ssh session to the NSLU2 was not available. The last weeks I have almost none of this problems, so I think that the cause may be environment factors, as interferences. If I find more information about this issue, I will post comments with it.