Ralink RT2870

From Gentoo-en
Jump to: navigation, search

This article is on how to use USB WiFi adaptors based on RT2870 or RT3070 chips by Ralink Corp, e.g. Belkin N1 F5D8051 (3100uk) and Vigor N61 USB.

Kernel versions and choices

What are the choices?

In kernel >= 3.0, there's only one driver, rt2800usb.

Linux Kernel Configuration: 3.0.4
Device Drivers --->
  Network device support --->
    Wireless LAN --->
      Ralink driver support --->  
        <*> Ralink rt27xx/rt28xx/rt30xx (USB) support 
	[*]   rt2800usb - Include support for unknown (USB) devices  

Probably you'll also have to install the necessary firmware rt2870.bin provided by kernel.org, which is included in sys-kernel/linux-firmware

emerge sys-kernel/linux-firmware

In kernels <= 2.6.39, there also existed "staging" drivers, considered to be "experimental", explained below.

Ralink Corp also provides their own version of module. See #Using the Ralink sources.

Kernel versions

The staging Ralink 3070 driver in 2.6.32 kernel works fine, but it does not seem to work for newer kernels 2.6.34 and 2.6.35.

Historical background

The long-term aim of the kernel wireless team is to develop support for all Ralink cards within the rt2x00 project; as of December 2009, rt2x00 doesn't support RT2870 so you'll need to use the Ralink-supplied driver, either from "staging" or direct from the vendor.

The staging drivers were originally released by Ralink Tech.

If it works

To see if your adaptor is supported by the driver you chose (after loading the module, if necessary) run ifconfig -a:

root ~ $ ifconfig -a
dummy0    Link encap:Ethernet  HWaddr fa:db:16:55:98:b3  

lo        Link encap:Local Loopback  

wlan0     Link encap:Ethernet  HWaddr 4c:e6:76:07:1d:56  
          inet addr:  Bcast:  Mask:

If there appears wlan0, ra0 or something like that, it's ok.

Using the "staging" sources

Linux Kernel Configuration: 2.6.32-gentoo
Device Drivers --->
  Staging Drivers --->
    <M> Ralink 2870/3070 wireless support

IF it successfully creates a wlan0 interface, continue with

ln -s /etc/init.d/net.lo /etc/init.d/net.wlan0

and configure using iwconfig / wpa_supplicant / NetworkManager / whatever.

Using the Ralink sources

Download one from their site -> Support -> Linux.

It doesn't compile with 2.6.39 kernel.

Kernel Configuration - Ralink sources

Configure the kernel to enable operation of the RT2870:

Linux Kernel Configuration: 2.6.28-r1
Networking --->
  Wireless --->
    -*- Improved wireless configuration API
    [*]   nl80211 new netlink interface support
    -*- Wireless extensions
    <*> Generic IEEE 802.11 Networking Stack (mac80211)
          Rate control algorithm selection  --->
    [ ]   Enable mac80211 mesh networking (pre-802.11s) support
    [ ]   Enable LED triggers
    [ ]   Export mac80211 internals in DebugFS
    [ ]   Enable packet alignment debugging
    [ ]   Enable debugging output
    < > Generic IEEE 802.11 Networking Stack (DEPRECATED)
Device Drivers --->
  [*] Network device support  --->
        Wireless LAN  --->
          [ ] Wireless LAN (pre-802.11)
          [ ] Wireless LAN (IEEE 802.11)


Read the README file well included in the Ralink's source.

The July 2011 driver can be compiled anywhere, but for older drivers, you may have to create a folder for holding the downloaded driver from the Ralink site.

mkdir -p /usr/src/rt2870

Download (see above) the driver and unpack it. (Ralink may provide a different driver for the rt3070)

For example package 'RT2870_LinuxSTA_V2.3.0.0.tar.tar.bz2' can be saved to:


Now unpack it:

tar zxvf *.tgz

Some adjustments are required to the supplied source before it is compiled.

Basically two lines of the configuration file require editing to enable the RT2870:

File: .../os/linux/config.mk

Once this has been done, make sure you are in the appropriate directory and compile and install the driver:

make && make install

The DAT file should be copied to /etc/Wireless as part of the make install.


At this point you should have the rt2870sta module available, modprobe it to get the adapter up and running:

modprobe rt2870sta

You can get this to load automatically on boot by adding the following to your modules configuration file:

File: /etc/conf.d/modules
# Ralink Wireless Driver for Belkin N1 USB adapter.

Add a link for the adapter in /etc/init.d/:

ln -s /etc/init.d/net.lo /etc/init.d/net.ra0

Please see Wireless/Configuration for notes on configuring the device for your access point.

Finally the adapter can be brought up for network access:

/etc/init.d/net.ra0 restart

If you want the adapter to be started at boot time add it to your default runlevel as follows:

rc-update add net.ra0 default

You should now have the Belkin N1 USB adapter working on a 64bit Gentoo build at 270Mbps and capable of connecting using WPA2.


Ensure that you arrange for the re-compilation of the RT2870 driver if you compile and install a new kernel configuration on your system. Compiling your kernel and then rebooting without re-compiling and installing the RT2870 driver may result in no network connectivity.

Kernel 2.6.35

Ralink hasn't upgraded their RT2870 driver since July 2010. The version provided on the website http://www.ralinktech.com/support.php?s=2 doesn't compile in 2.6.35, due to some errors. The kernel developers renamed some functions.

How to fix

-Go to: [driver_dir]/include/os/ and open rt_linux.h
-Go to line 1077 and replace it with:

#define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, BufSize, pDma_addr) usb_alloc_coherent(pUsb_Dev, BufSize, GFP_ATOMIC, pDma_addr)

-Go to line 1078, replace it with:

#define RTUSB_URB_FREE_BUFFER(pUsb_Dev, BufSize, pTransferBuf, Dma_addr) usb_free_coherent(pUsb_Dev, BufSize, pTransferBuf, Dma_addr)

You should be able to compile the driver now. However, you will see some warnings. If you have played around with some alternatives drivers, unload them. Restart linux. The driver should work now.

When similar adapters are supported, but yours not

If you know similar products are supported by some driver, but when yours is not (yet), you can try patching sources. Warning: this may damage your device. The file to fix is rtusb_dev_id.c (in Ralink's or stanging driver) or rt2800usb.c (in official), and the patch looks like this:
--- linux-3.0.4/drivers/net/wireless/rt2x00/rt2800usb.c.orig  2011-10-11 21:04:16.893188320 +0900
+++ linux-3.0.4/drivers/net/wireless/rt2x00/rt2800usb.c  2011-10-11 21:04:16.893188320 +0900
@@ -1039,6 +1039,7 @@
 	{ USB_DEVICE(0x0411, 0x012e) },
 	{ USB_DEVICE(0x0411, 0x0148) },
 	{ USB_DEVICE(0x0411, 0x0150) },
+	{ USB_DEVICE(0x0411, 0x0158) },
 	{ USB_DEVICE(0x0411, 0x015d) },
 	/* Corega */
 	{ USB_DEVICE(0x07aa, 0x0041) },

These items are IDs of the device, which you can tell by lsusb command included in sys-apps/usbutil.

$ lsusb
Bus 001 Device 002: ID 0411:0158 MelCo., Inc.

sysfs "new_id"

There's an alternative to patching, by using sysfs, like this:

echo "0411 0158" > /sys/bus/usb/drivers/rt2870/new_id 

However, at least there's one case this trick does not work, even when patching is ok.