Sunday, January 30, 2011

Making Wireless work on the Asus O!Play HD2

WARNING: There might be side effects to the below that i am yet to discover.

The Asus OPLay HD2 runs Linux! (2.6.12 kernel/MIPS). Woot!

Power on your oPlay, get a RJ45 cable and connect the HD2 to your wireless router. You can even take the HDMI cable and connect it to your computer monitor (if you have an HDMI port), but this isn't really necessary.

Figure out the IP Address of OPlay from the setup. Now open up a command shell in your OS and telnet to this IP address.


$ telnet 192.168.10.101
Trying 192.168.10.101...
Connected to 192.168.10.101.
Escape character is '^]'.
OPLAYF9 login: root
warning: cannot change to home directory


BusyBox v1.1.3 (2010.06.24-09:31+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

Now, plug in your wireless dongle. (I use an Asus N10). If you have your HDMI cable connected to your TV/comp monitor, it should say 'wifi-plugin detected'. But you can check this using 'ifconfig'


/ # ifconfig
.........

wlan0 Link encap:Ethernet HWaddr 00:26:18:A1:57:4B
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:10 overruns:0 frame:0
TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:1176 (1.1 KiB)
..........

Ifconfig must show a wireless interface or there is no point in progressing further!

Now we need to make a wireless configuration file that provides details of our SSID, authentication, etc. The tool that reads this on Linux is called wpa_supplicant.

Now, I first take a look at whether I have some free space to put this file anywhere. (I haven't attached a USB/internal hard disk to my OPlay yet so that option is ruled out)


/usr/local/etc # df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 46.9M 46.9M 0 100% /
/dev/mtdblock/2 60.0M 2.6M 57.4M 4% /usr/local/etc
/dev/rd/0 40.0k 40.0k 0 100% /mnt/rd

Ok, so there is space available under '/usr/local/etc'. Teeny 'vi' is available everywhere, so I use that

# vi /usr/local/etc/wpa.conf

and fill in the contents below. This is just an example, study the wpa_supplicant manual and adjust the configuration according to your specific authentication method, etc.

network={
ssid="mySSID"
scan_ssid=1
key_mgmt=WPA-PSK
psk="myPassKey"
}

Let check whether the configuration is valid. Launch wpa_supplicant in debug model with this configuration in the foreground.

# wpa_supplicant -c/usr/local/etc/wpa.conf -iwlan0 -d
Initializing interface 'wlan0' conf '/usr/local/etc/wpa.conf' driver 'default' ctrl_interface 'N/A'
bridge 'N/A'
....loads of stuff
CTRL-EVENT-CONNECTED - Connection to 00:14:bf:93:84:80 completed (auth) [id=0 id_str=]
...
EAPOL authentication completed successfully
...

Ok, let us CTRL-C and return to the command prompt. Let us ensure that that 'wpa_supplicant' is started at boot time. The way I suggest here isn't very clean but I can't be bothered to think of a better approach now.

Open up '/usr/local/etc/rcS', look for this line at the end

/usr/sbin/initsys

Change it to

/usr/sbin/initsys &


And now adds line to start wpa_supplicant and the dhcp client (to get your wireless IP) after sleeping for 12 seconds. Modify the sleep value to whatever you think is appropriate - I found that a value of less than 12 seconds caused problems for me.



/usr/sbin/initsys &
sleep 12
/usr/local/bin/wpa_supplicant -c/usr/local/etc/wpa.conf -iwlan0 -P /var/run/wpa_supplicant.pid -B
sleep 6
/sbin/udhcpc -p /var/lock/udhcpc_wlan0.pid -iwlan0 -t15 -b -s /etc/udhcpc.script



Note: If someone can suggest a better method, please leave a comment. I am really uncomfortable about launching initsys in the background!

Perform a reboot.

/usr/local/etc # reboot
/usr/local/etc # Connection closed by foreign host.

Telnet in again and check that the processes are really running

/ # ps | grep wpa
476 root 796 S /usr/local/bin/wpa_supplicant -c/usr/local/etc/wpa.co
1168 root 304 S grep wpa
/ # ps | grep ud
433 root 368 S /sbin/udhcpc -p /var/lock/udhcpc_eth0.pid -t 15 -b -s
731 root 368 S /sbin/udhcpc -p /var/lock/udhcpc_wlan0.pid -iwlan0 -t
1170 root 304 S grep ud

Check that ip assignment to wlan0 has occurred correctly.

/ # ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 00:26:18:A1:57:4B
inet addr:192.168.10.103 Bcast:192.168.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:685 errors:0 dropped:194 overruns:0 frame:0
TX packets:52 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:97537 (95.2 KiB) TX bytes:7774 (7.5 KiB)


Check that you can ping the inet address assigned to wlan0 from another comp in your home network

$ ping 192.168.10.103
PING 192.168.10.103 (192.168.10.103): 56 data bytes
64 bytes from 192.168.10.103: icmp_seq=0 ttl=64 time=1 ms
...


Finally, disconnect your RJ45 cable, power off/on and check that you are able to still telnet into O!Play. See the wireless client list in your router to figure out the IP. (since the OPLay UI only shows wired IP's)

Now I can carry my O!Play away from my router and towards my TV! Woot!