Update for October 2011: This guide was written in 2009, has not been supported in years, and is not a recommended way to deal with this problem.

Ubuntu 11.10 "Oneiric Ocelot" no longer includes Ralink's out-of-kernel-tree drivers, instead it distributes drivers developed by the rt2x00 community project.

For Those using Ubuntu 11.04 Natty and Lower: Luckily, someone has outlined how to pass new USB Dev IDs to a compiled kernel module using udev, and it is a MUCH better solution than what I've explained below (recompiling a kernel module).
If you're having an issue with a driver not supporting your device due to a USB Dev ID issue, please see flash63's post here: http://ubuntuforums.org/showpost.php...48&postcount=6


I no longer support this tutorial because I don't own any Ralink devices to test it on. It still has some useful info, so i'll leave it up. Good luck!

This tutorial is for USB WiFi Adapters that use the RT2870 or RT3070 chipsets by Ralink.

THE CURRENT STATE OF RALINK DRIVERS

There are currently 2 groups developing drivers for Ralink chipsets: Ralink's own team and the community-run rt2x00 project. Rt2x00 drivers work very well, and are distributed with the Linux kernel. Ralink's drivers (such as rt2870sta and rt3070sta) have some ugly code, and at this time are distributed separately from the Linux kernel. These drivers have varying levels of support for different chipsets, and in some cases they would both support a given chip

A Common Problem:
USB devices report their USB Device IDs, which are used to determine whether a Linux kernel module (driver component) should control a device. Conflicts can occur when more than one module attempts to control a device with a given USB Dev ID. In Ubuntu 9.10, such conflicts exist between the community-written rt2x00 module, and Ralink's rt2870sta and rt3070sta modules. Furthermore, these modules do not detect many devices which they are able to control.

The Scope of This Guide:
This guide describes how to “blacklist” modules, to prevent conflicting modules from being concurrently loaded. Additionally, it describes how to modify and compile Ralink's rt2870sta and rt3070sta modules with support for new USB Dev Ids.

Determining which module you should use:
If a USB WiFi adapter is automatically detected by rt2870sta, rt3070sta or an rt2x00 module, it has likely been verified to function by that module's developers. While the rt2x00 driver has some support for rt2870 chipsets, it seems that rt2870 and rt3070 chipsets work best when controlled by Ralink's drivers. Only one of these modules should be loaded per network adapter.

To determine which modules control your USB WiFi adapter, insert it and run the following command in terminal

rt2870 devices are supported by Ralink's rt2870 driver (module rt2870sta) or by the rt2x00 project's driver (modules rt2800usb, rt2x00lib, rt2x00usb). rt3070 devices are supported by Ralink's rt3070 driver (module rt3070sta)

Blacklisting Modules:

To begin, unplug any Ralink USB WiFi adapters and restart your computer (or unload the modules).

To use rt2870sta and blacklist rt2800usb, run the following commands in terminal:

Code:

gksudo gedit /etc/modprobe.d/blacklist.conf
add these lines to the end of the file:

Code:

blacklist rt2x00usb
blacklist rt2x00lib
blacklist rt2800usb
Save the file, then insert your USB WiFi device.

To use rt2800usb and blacklist rt2870sta, run the following commands in terminal:

Code:

gksudo gedit /etc/modprobe.d/blacklist.conf
add these lines to the end of the file:

Code:

blacklist rt2870sta
Save the file, then insert your USB WiFii device.

To use rt3070sta and blacklist all other modules (probably unnecessary, not recommended), run the following commands in terminal:

Code:

gksudo gedit /etc/modprobe.d/blacklist.conf
add these lines to the end of the file:

Code:

blacklist rt2x00usb
blacklist rt2x00lib
blacklist rt2800usb
blacklist rt2870sta
Save the file, then insert your USB WiFi device.

If this didn't work:

Your device either doesn't function with the driver you chose, or your WiFi Adapter's USB Device ID is not detected by that driver. If you're certain of which chipset is in your WiFi Adapter, you can modify and compile a kernel module that will detect and attempt to control any adapter with its USB Dev ID.

Determining Your Device's USB Device ID
You can check your USB Device ID using

For example, lsusb states that a USB WiFi adapter has a device ID of 1234:7777

Code:

 oo@oo:~$ lsusb
Bus 001 Device 004: ID 1234:7777 Brand

EDIT: PLEASE READ: Luckily, someone has outlined how to pass new USB Dev IDs to a compiled kernel module, and it is a MUCH better solution than what I've explained below (recompiling a kernel module).
If you're having an issue with a driver not supporting your device due to a USB Dev ID issue, please see flash63's post here: http://ubuntuforums.org/showpost.php...48&postcount=6
His Udev Rule is the best way to solve this problem. Good luck!

Compiling a New Kernel Module (Driver)
You'll need a compiler and Linux headers installed

Code:

sudo apt-get install build-essential linux-headers-generic

Modifying and Compiling RT2870STA:

Download a copy of Ralink's rt2870 USB driver from http://www.ralinktech.com/support.php?s=2
Save it to your Ubuntu computer's desktop, then extract its contents using the following commands in terminal:

Code:

cd ~/Desktop
tar -xvf ~/Desktop/RT2870_LinuxSTA*.tgz
cd ~/Desktop/*2870*
Now you'll make some modifications, to add your device's USB Device ID. The following is an EXAMPLE. Using the lsusb command, it has been determined that an adapter has has the USB Device ID 1234:7777. MODIFY THESE INSTRUCTIONS TO USE YOUR USB DEV ID! You can put whatever you want for comments between */ s, they are meant to document the code.

Edit

Code:

gedit ~/Desktop/*2870*/common/rtusb_dev_id.c
add to the group:

Code:

{USB_DEVICE(0x1234,0x7777)}, /* Example WiFi Device Name */
Save.

You'll now configure the source to be compiled with support for NetworkManager and wext. NetworkManager is Ubuntu's default graphical method for configuring networking. It provides the icon in the "notification area" aka "system tray".

Edit

Code:

gedit ~/Desktop/*2870*/os/linux/config.mk
Change

Code:

# Support Wpa_Supplicant
HAS_WPA_SUPPLICANT=n
# Support Native WpaSupplicant for Network Maganger
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n
to

Code:

# Support Wpa_Supplicant
HAS_WPA_SUPPLICANT=y
# Support Native WpaSupplicant for Network Maganger
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y
Save.

In terminal:

Code:

cd ~/Desktop/*2870*
(If you're trying to compile a second time, please note: Run "make clean" before running "make" to remove your previous attempt.)
make
sudo make install
This installs the module rt2870sta.ko, but now you have 2 copies of it:
one in /lib/modules/`uname -r`/kernel/drivers/net/wireless and another at /lib/modules/`uname -r`/kernel/drivers/staging/rt2870. The one in the staging directory is the one that came with Ubuntu, which obviously doesn't work for you.

Before you move your old driver, run the following commands to see if your newly compiled driver actually functions with your USB device.

Code:

sudo modprobe -r rt2870sta
sudo insmod /lib/modules/`uname -r`/kernel/drivers/net/wireless/rt2870sta.ko
sudo /etc/init.d/networking restart
sudo restart network-manager
If NetworkManager now works, congratulations.

Then delete the version of the rt2870sta module that came with Ubuntu (there are certainly better ways to do this [PLEASE ADVISE!], but this will allow the newly compiled one will load by default).

Code:

sudo mkdir ~/.rt2870.bak
sudo mv /lib/modules/`uname -r`/kernel/drivers/staging/rt2870 ~/.rt2870.bak
Otherwise, you will have to run the above commands whenever you want to use the new driver. You will need to recompile this module every time a new Linux kernel is installed.

Modifying and Compiling RT3070STA:

Download a copy of Ralink's rt3070 USB driver from http://www.ralinktech.com/support.php?s=2
Save it to your Ubuntu computer's desktop, then extract its contents using the following commands in terminal:

Code:

cd ~/Desktop
tar -xvf ~/Desktop/RT3070_LinuxSTA*.tgz
cd ~/Desktop/*3070*
Now you'll make some modifications, to add your device's USB Device ID. The following is an EXAMPLE. Using the lsusb command, it has been determined that an adapter has has the USB Device ID 1234:7777. MODIFY THESE INSTRUCTIONS TO USE YOUR USB DEV ID! You can put whatever you want for comments between */ s, they are meant to document the code.

Edit

Code:

gedit ~/Desktop/*3070*/os/linux/usb_main_dev.c
add your device to the group:

Code:

{USB_DEVICE(0x1234,0x7777)}, /* Example WiFi Device Name */
Save.

You'll now configure the source to be compiled with support for NetworkManager and wext. NetworkManager is Ubuntu's default graphical method for configuring networking. It provides the icon in the "notification area" aka "system tray".

Edit

Code:

gedit ~/Desktop/*3070*/os/linux/config.mk
Change

Code:

# Support Wpa_Supplicant
HAS_WPA_SUPPLICANT=n
# Support Native WpaSupplicant for Network Maganger
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n
to

Code:

# Support Wpa_Supplicant
HAS_WPA_SUPPLICANT=y
# Support Native WpaSupplicant for Network Maganger
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y
Save.

In terminal:

Code:

cd ~/Desktop/*3070*
(If you're trying to compile for the second time, please note: Run "make clean" before running "make" to remove your previous configuration files.)
make
sudo make install
If you see any garbage about “/tftpboot”, disregard it. The developers made a mistake here and "make" tries to write to "/"
The module rt3070sta.ko is now installed, but there are 2 copies of it:
one in /lib/modules/`uname -r`/kernel/drivers/net/wireless and another at /lib/modules/`uname -r`/kernel/drivers/staging/rt3070. The one in the staging directory is the one that came with Ubuntu, which obviously doesn't work for you.

Before you move your old driver, run the following commands to see if your newly compiled driver actually functions with your USB device.

Code:

sudo modprobe -r rt3070sta
sudo insmod /lib/modules/`uname -r`/kernel/drivers/net/wireless/rt3070sta.ko
sudo /etc/init.d/networking restart
sudo restart network-manager
If NetworkManager now works, congratulations.

Then move the version of the rt3070sta module that came with Ubuntu (there are certainly better ways to do this [PLEASE ADVISE!], but this will allow the newly compiled one will load by default).

Code:

sudo mv /lib/modules/`uname -r`/kernel/drivers/staging/rt3070 ~/.rt3070.bak
Otherwise, you will have to run the above commands whenever you want to use the new driver. You will need to recompile this module every time a new Linux kernel is installed.

FAILURE AND DEBUGGING:

If it failed, you should seriously reconsider whether your card has a different Ralink chipset such as the rt3070. Manufacturers often use various chipsets per model, even within a single revision. Many Ralink drivers are very similar, and seem to almost function with incompatible devices.

This driver was configured to support NetworkManager. This is an layer that abstracts control over wifi devices, and is another point of failure. Linux network interfaces are normally controllled using a configuration file at /etc/network/interfaces . Normally, we could test this driver's functionality using iwlist scan, to make sure that any problems aren't being caused by NetworkManager while the driver functions properly. iwlist's performance is very unpredictable with this driver (this may only be when it is compiled to support NetworkManager) and it may not work at all, or only for a short time after the interface is brought up.

First we need to know: Was your device detected by the version of rt2870sta included with Karmic, or did you add your USB Device ID to the module you compiled? You must do the blacklist steps even if you compiled a module.
Does your device show up in the NetworkManager applet (networking icon in notification area aka "system tray)?
What is the manufacturer and model number of your WiFi adapter?
Have you tried to use ndiswrapper? If so, add "ndiswrapper" to /etc/modprobe.d/blacklist.conf . It will conflict with any native drivers.
Are you running a new Karmic install or did you upgrade from Jaunty? This is important because if you've upgraded. some settings may not have gracefully migrated.

For debugging purposes: Turn off your computer, unplug any Ralink-based USB wifi adapters. Turn it on, log in, let it finish booting. Open a terminal and run the command

Code:

tail -f /var/log/messages
Open another terminal and run

Code:

tail -f /var/log/syslog
Maximize the terminal windows (to fit outputs on 1 line) Then plug in your rt2870 device. Observe the outputs, and save them both to a txt file. The reason for turning off the computer is to ensure the device has to reload its firmware, and also to make the messages output easier to read. Post the output in this thread along with the output of the following commands, run with your WiFi adapter still connected:
If ra0 was not listed by ifconfig, run the following commands shortly after inserting the device and post the output:

Code:

sudo ifconfig ra0 up
sudo iwlist ra0 scan

Also post the output of the following commands.

Code:

cat /etc/network/interfaces | grep -v ^#
lsusb
lsmod
modinfo /lib/modules/`uname -r`/kernel/drivers/net/wireless/rt2870sta.ko
The purpose of these queries is to determine: Do you have conflicting drivers loaded? Does your newly compiled module have the correct device IDs? Is your WiFi card functioning without NetworkManager?

When you run lsmod, you're looking to see which modules containing "rt" are loaded. If you have more than rt2870sta, you need to make some changes.

I'm still looking for a better way to do this, I think there is
a way to insert these IDs into a driver without compiling: using Udev.
We should find a way to add dev ids to a binary module, and to blacklist them.
There must be a mechanism to do this, please post if you learn how to use Udev or whatever it is Blacklisting a specific device from use by rt2x00 is a much better solution than blacklisting rt2x00. If someone has an rt73 device and an rt2870 device for example, the current solution does not work. rt73 will load rt2x00, and rt2870sta wont work.