Sunday, December 19, 2010

Custom device driver for Linksys USB Wifi on WDTV Live

There is lot of specifics involved, so before I go any further, let me clarify the title more. This post is about using the Cisco (Linksys) USB Wifi G Adaptor WUSB54GC on your WDTV Live for network connectivity. If you need to do this on your WDTV live, you would need to have sufficient understanding of Linux and shell scripting. Also, you need to have Wifi network and with appropriate network shares available via SMB or FTP and understand how you configure stuff.

WDTV Live has wireless network support, however it doesn't work on all USB Wifi network adaptors or chipsets. There is a defined list of USB Wifi adaptors that are compatible -- again this depends on which firmware you use. The stock firmware support (from western digital) might be different from the unofficial firmwares like wdlxtv. I use wdlxtv unofficial firmware but that doesn't support my linksys Wifi adaptor as well. I had bought this wifi dongle before WDTV live, so didn't want to buy another one. The result of trying to make this work on my WDTV is this post.

Apparently, the particular linksys adaptor that I'm talking about (take a look here if you want to know what I'm talking about) is based on Ralink Chipset 3070; in fact there are many other wifi dongles that are based on the same chipset. At least the unofficial firmware supports ralink 3070 chipset, however, it doesn't matter unless the device driver was built to support that particular device. ie., the device driver should have been compatible with the given vendor id and device id. This is where my device didn't work in spite of it being 3070 chipset.

I had to then setup a total cross-platform toolchain for WDTV Live by downloading the appropriate kernel source from Western Digital website. WD has provided beautiful support for building stuff for WDTV live. The source code of device driver for Ralink 3070 chipset is available from Ralink's website. I tampered the source a bit to accommodate this Linksys device too (Vendor Id: 1737, Device Id: 0077), cross-compiled the device driver for WDTV Live on my desktop Linux. Viola, my driver got loaded for that device.

This device driver was built for the kernel 'Linux WDTVLIVE 2.6.22.19-19-4'. Make sure this matches your kernel version too (this should be in line with the WDTV Live official firmware version 1.02.21).

Also, if you have this USB dongle, you should see an entry like this when you do 'lsusb' on your WDTV Live:

Bus 001 Device 003: ID 1737:0077 Linksys

INSTRUCTIONS:
1. Download this zip file that contains (rt3070sta.ko, net.mounts, RT2870STA.dat, resolv.conf, wpa_supplicant.conf).
2. Create a folder named 'wireless' in the root of a pendrive and extract the contents to that folder.
3. Move/copy net.mounts from that folder to the root of your pendrive.
4. Edit the files net.mounts, RT2870STA.dat, resolv.conf, wpa_supplicant.conf and customize with your Wifi's SSID and WPA PSK as necessary. You can use wpa_passphrase on a desktop linux to create a encoded PSK and copy that to these files.
5. More customization is required in net.mounts script as per your network to mount the right share on startup. I use ftpfs, as that seems more robust than smbfs on WDTV live.
6. Plug-in this pen drive to your WDTV live along with your Linksys Wifi dongle and reboot, your WDTV Live should join your network and mount your network share seamlessly.

I've this setup successfully working for almost 3 months now. Every time I start my WDTV live it joins the wifi network in around 30-45 seconds and the network shares are instantly available. You also don't have to worry about network interruptions, WDTV Live takes care of remounting the shares if the ftpfs breaks for some reason (note the 'xmount' in the script).

Here is the net.mounts script that I use at home (with specifics removed):
#
# Original Author: Gerald Naveen A (http://geraldnaveen.blogspot.com)
#
# WDTV Live! net.mounts to use my custom built device driver for WUSB54GC
# on WDTV Live firmwares. This script uses the wpa_supplicant to configure
# WPA based authentication.
#
# Refer : http://geraldnaveen.blogspot.com/2010/12/custom-device-driver-for-linksys-usb.html
# for more info.
#
# COPY THIS FILE TO THE ROOT FOLDER OF YOUR USB DRIVE ON WDTV LIVE!
#
# License:
# You are free to modify/distribute/use for commercial/non-commercial/
# personal applications. Any modification to this code needn't be published.
# However, any publication of this code or the derivative of this code, should
# include the original author and this license text.
#
logger -t GERALD "$0 starting..."
if [ -f /tmp/gerald ]; then
# make sure this script doesn't run more than once. Sometimes, net.mounts
# gets called multiple times.
logger -t GERALD "$0 already ran."
else
touch /tmp/gerald
config_tool -c DISABLE_ETHERNET_ON_STANDBY=NO
config_tool -c USB_POWER_OFF=NO

# NOTE: change below line to cp from your USB wireless device
cp /tmp/mnt/64BA-4243/wireless/* /tmp/
cp /tmp/resolv.conf /etc/resolv.conf

WIFI_DEV=ra0
insmod /tmp/rt3070sta.ko
ifconfig $WIFI_DEV up
sleep 5 ; # let the radio come up before scanning
#discover the current channel number
CHANNEL_NUMBER=`iwlist $WIFI_DEV scan | grep YOUR_WIFI_SSID -A 2 | grep Channel | cut -d\( -f 2 | cut -d\ -f 2 | cut -d\) -f 1`
logger -t GERALD "Configuring $WIFI_DEV to Channel $CHANNEL_NUMBER"
iwconfig $WIFI_DEV channel $CHANNEL_NUMBER

wpa_supplicant -i$WIFI_DEV -c/tmp/wpa_supplicant.conf -B
# DHCP client has some issue and is inconsistent.
#udhcpc -i $WIFI_DEV
logger -t GERALD "Configuring IP Address for $WIFI_DEV"
ifconfig $WIFI_DEV STATIC_IP_ADDRESS_OF_WDTV_LIVE netmask 255.255.255.0
route add default gw YOUR_NW_DEFAULT_GW_IP

sleep 15 ; # let the n/w settle before mount
logger -t GERALD "Pinging NAS via LAN..."
ping -c 1 -W 2 NAS_IP_ADDR_HSPEED | grep -q "bytes from"
if [ $? -eq 0 ] ; then
logger -t GERALD "Ping successful for NAS via LAN. Now xmounting..."
xmount "ftp://NAS_IP_ADDR_HSPEED" NAS_1Gbps ftpfs "-o user=movies:password"
logger -t GERALD "xmount done for NAS."
else
# could not reach NAS via high speed n/w.
# try to reach via Wifi.
logger -t GERALD "Pinging NAS via Wifi..."
ping -c 1 -W 2 NAS_IP_ADDR | grep -q "bytes from"
if [ $? -eq 0 ] ; then
logger -t GERALD "Ping successful for NAS via Wifi. Now xmounting..."
xmount "ftp://NAS_IP_ADDR" NAS_Wifi ftpfs "-o user=movies:password"
logger -t GERALD "xmount done for NAS."
fi
fi
fi ; # if already ran
logger -t GERALD "$0 complete."

In case you find issues, check /tmp/messages.txt file on your WDTV Live for the relevant log messages to troubleshoot.

8 comments:

  1. Hi naveen ,
    Dou you have any recent version of Gerald Caller Location with you?
    send it to me if you have it, buddy its agreat app.
    Thanks
    Chao!
    sanjoy missra
    sanjum.lko@gmail.com

    ReplyDelete
  2. You did not mention the platform.

    I've stopped development for A780 (linux).

    The last version of caller location on WinMo can be found at http://geraldnaveen.blogspot.com/2009/08/caller-location-info-v-03-for-winmo.html

    ReplyDelete
  3. I have upgraded my WDTV live to official version 1.6.43 and I want to connect wireless-ly through wusb54gc ver 3 adaptor . I don't have linux installed . Under this scenario also can I use the steps listed above ?

    ReplyDelete
  4. Additionally, be informed that an old unregistered antivirus programme starts swallowing your valuable bandwidth since it will keep attempting to update itself in a number of circles until you delete it manually or re-install it. 192.168.2.1



    ReplyDelete