Sunday, January 25, 2009

Configuring the Ralink RT2860 card

This is how I set up my Zepto Znote 6024W (using the Ralink RT2860 wifi card) with my D-Link DI-524 router. It is a really crappy router, and I have had lots of problems with it, but today I seem to have found a solution to my problems. It still seems to disconnect a lot, but if I dhclient it again, it usually reconnects. This is how I set it up.

Go to Ralink's website at http://web.ralinktech.com/ralink/Home/Support/Linux.html. The latest drivers when writing this is 1.8.0. Download them and untar them somewhere.

I really recommend you to read the README_STA that comes with the drivers. It tells you how to configure the drivers for your setup, even if they do leave a lot to wish for. The information that I'm sharing here is a mix between that file, as well as the info that can be found in the manpages for wpa_supplicant, wpa_cli, wpa_supplicant.conf and ifup.

First we change the config for the build so the card is being controlled by wext and network manager. Open the file os/linux/config.mk and set:
'HAS_WPA_SUPPLICANT=y' and "HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y'.

Save the file, we now move on to configuring the more detailed stuff. The settings for the drivers are entered into the RT2860STA.dat file in the base directory of the drivers. This is then copied to /etc/Wireless/RT2860STA/ when we compile the source and run 'make install'.
Edit the settings that interests you. I don't see why we need to enter our psk (preshared key) both here and in the wpa settings (see further down), but I haven't had the guts to remove my settings. The things I changed are:

#The word of "Default" must not be removed
Default
CountryRegion=5
CountryRegionABand=7
CountryCode=
ChannelGeography=1
SSID=your_ssid
NetworkType=Infra
WirelessMode=9
Channel=0
AuthMode=WPA2
EncrypType=TKIP
WPAPSK=cf3e61b119de1e8bceb45edc60c5b7aa00b240c58bee8ba83cc9448761300cf3

To find the encrypted version of your password, use wpa_passphrase. The output should look something like this:
root@george:# wpa_passphrase your_ssid super_duper_password
network={
ssid="your_ssid"
#psk="super_duper_password"
psk=cf3e61b119de1e8bceb45edc60c5b7aa00b240c58bee8ba83cc9448761300cf3
}

We will do the same again later, but for setting up the wpa_supplicant. Now let's build the driver and load it into the kernel.

root@george:# make all && make install && modprobe rt2860sta

Enable, build and load the kernel modules that allows for encryption (TKIP, AES etc). If you are running Ubuntu, these will be compiled as modules already (which means that we don't have to recompile anything), otherwise enable them as modules in the kernel and compile and install them.

load kernel modules for encryption
root@george:# modprobe ieee80211_crypt_tkip \
ieee80211_crypt_ccmp \
ieee80211_crypt \
aes_x86_64 \
aes_generic

Now it's time to set up the configuration for wpa_supplicant, so we can connect to our encrypted access point. Since you've already set a password on the AP, let us try to use it.

Encrypt password using wpa_passphrase
root@george:# wpa_passphrase your_ssid super_duper_password >> /etc/wpa_supplicant/wpa_supplicant.conf

Edit the created file so we can add some settings. I am running WPA2 with both AES and TKIP encryption, so I'll let the driver use both.

root@george:# vim /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="your_ssid"
scan_ssid=0
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
#psk="super_duper_password"
psk=cf3e61b119de1e8bceb45edc60c5b7aa00b240c58bee8ba83cc9448761300cf3

}

The file should now look something like above. We now start wpa_supplicant with the arguments that it should use the wext (generic wireless driver for Linux) driver, with our config file. It will also set up the interface as ra0. We also tell it to be verbose, so it is easier to spot errors in our configuration.

root@george: #wpa_supplicant -Dwext -ira0 -c /etc/wpa_supplicant/wpa_supplicant.conf -d

And to receive the correct dhcp info from our access point we run dhclient on it.

root@george: # dhclient ra0

We can check the interface has been started now with ifconfig and iwconfig:

root@George:# ifconfig ra0
ra0 Link encap:Ethernet HWaddr 00:15:af:b7:93:xx
inet addr:192.168.0.116 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:44812 errors:0 dropped:0 overruns:0 frame:0
TX packets:9096 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4619023 (4.6 MB) TX bytes:369091 (369.0 KB)
Interrupt:18

root@George:# iwconfig ra0
ra0 RT2860 Wireless ESSID:"your_ssid" Nickname:"RT2860STA"
Mode:Managed Frequency=2.452 GHz Access Point: 00:1C:F0:88:A4:02
Bit Rate=54 Mb/s
RTS thr:off Fragment thr:off
Encryption key:50FF-9C3C-6A3B-1EBB-6D50-AF11-8F74-XXXX
Link Quality=100/100 Signal level:-39 dBm Noise level:-81 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0

My computer keeps disconnecting, and I'm unsure about what to do about that. This does at least get the network up, so I could post this article! First I had lots of settings for the encryption in my /etc/network/interfaces file, but I moved all these to the wpa_supplicant.conf file, which should mean that we can keep a very clean interfaces file. We do need to make it run wpa_supplicant every time we want the interface up though, so we'll add that to the config. Mine now looks like:

root@George:# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto ra0
iface ra0 inet dhcp
pre-up /sbin/wpa_supplicant -Dwext -ira0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B

Now it should get the interface up and running every time you boot the computer. Good luck!

2 comments:

Anonymous said...

Why would you go through all that pain manually?

Mandriva has rt2860 included in its stock kernel. There's a working package for Fedora in the RPMfusion repository. I think there's packages easily available for Ubuntu as well. Once the driver's available, net_applet (on Mandriva) or networkmanager (on Ubuntu or Fedora) can easily set up the connection for you. There's really not many distros left which would make you build the driver and set up the entire network environment manually, it seems like a lot of trouble to go to.

Peter said...

I'm using Ubuntu and the laptop for which I did this, and the driver for RT2860 does not exist in the repository. The source for RT2870 and some other cards do though.

Network manager never worked very well for me sadly, and after much crying this was the way that I got it up and running.

Some of the wpa_supplicant stuff could probably have been done with the wpa_gui though, but why make it harder than it already is, right? ;)