DLink DWA-160 USB key is a low price dual-band 2.4 and 5 GHz wifi adapter.
Latest hardware revision DLink DWA-160 rev. B2 is introducing a new RT5572 chipset as a replacement with RT7820.
The result is that, as most of the time with latest wifi adapters, this new harware revision is not recognised Out Of The Box under Ubuntu Precise 12.04.
The generic rt2800usb module is not able to handle the new chipset RT5572 embedded with the DWA-160 rev. B2.
But, thanks to Ralink, the source drivers are publicly available.
So, with little effort, you will be able to get a working DWA-160 rev. B2 USB key under Ubuntu 12.04. This article explains all the steps needed to achieve this goal.
It will also explain how to configure DKMS so that your driver will be automatically built and installed during every kernel update.
It has been tested under Ubuntu 64bits Precise 12.04 with kernel 3.2.0-24 and 3.2.0-30. But it should work on the 32bits version.
I've got few reports saying that the drivers are not compatible with kernel 3.5, giving even some kernel panic. So, if you are planning to use DWA 160 it's advisable stay with Ubuntu 12.04, not upgrading to Ubuntu 12.10.
DWA 160 is also know to freeze under heavy network load. When this happens, the only solution is to unplug and replug the key. Till date this bug has not been corrected.
Because of all that, this wifi key is not, at this time, a very good deal for Linux users.
1. Check your Hardware Version
To be sure that you are in front of D-Link DWA-160 rev. B2, you have 2 options.
- You can check the label :
- Or you can check the USB ID :
Bus 002 Device 002: ID 2001:3c1a D-Link Corp.
2. Install needed Packages
As the D-Link key is using proprietary firmware, we first have to install restricted firmwares :
# sudo apt-get install linux-firmware
To be able to compile the source drivers, we need to install the minimal compilation environment. This can be done quite easily under Ubuntu.
# sudo apt-get install build-essential
3. Download & Install Firmware
You first need to download the latest firmware from the Firmware RT28XX/RT30XX USB series (RT2870/RT2770/RT3572/RT3070) section from MediaTek (ex Ralink) site.
This archive should be extracted and will provide rt2870.bin firmware. This firmware should be copied as root to the firmware default folder.
From the directory where you have downloaded the firmware, start these commands :
# unzip RT2870*.zip
# sudo cp ./RT2870*/rt2870.bin /lib/firmware/rt2870.bin
The latest firmware is now available under /lib/firmware/rt2870.bin.
4. Download & Compile Drivers
We now have to download the latest drivers published by Ralink. They are available from MediaTek (ex Ralink) site in the RT5572 USB section.
From the directory where you have downloaded the drivers, start these commands :
# mv *.tar.bz2 drivers.tar.bz2
# tar -xvjf drivers.tar.bz2
# mv DPO* drivers
The drivers should now be ready for compilation in the drivers subdirectory.
Before doing the compilation job, we need to configure & modify few sources.
4.1. Configure config.mk
We now have to edit the main configuration file to indicate that we are using wpa_supplicant and network manager.
# Support Wpa_Supplicant
# Support Native WpaSupplicant for Network Manger
4.2. Patch rt_linux.c
To remove some compilation warnings, we have to modify ./drivers/os/linux/rt_linux.c around line 510 :
NdisMoveMemory(skb_tail_pointer(skb), pHeader802_3, HdrLen);
NdisMoveMemory(skb_tail_pointer(skb), pData, DataSize);
4.3. Patch usb_main_dev.c
To avoid a compilation error, we also have to add one GPL license declaration line missing at the beginning of ./drivers/os/linux/usb_main_dev.c
MODULE_DESCRIPTION("RT2870 Wireless Lan Linux Driver");
4.4. Patch cmm_wpa.c
We need to change the cifer combination in ./drivers/common/cmm_wpa.c around line 2480 :
WPA_MIX_PAIR_CIPHER FlexibleCipher = WPA_TKIPAES_WPA2_TKIPAES; /* it provide the more flexible cipher combination in WPA-WPA2 and TKIPAES mode*/
4.5. Patch cmm_mac_usb.c
The same way we need to define some functions that are only available in latest 2.6 and in 3.x kernels. As Ralink sources are meant for kernels 2.4 and 2.6, some function have changed name in latest kernel versions.
This should be done by adding these lines at the beginning of ./drivers/common/cmm_mac_usb.c :
#define usb_buffer_alloc(a, b, c, d) usb_alloc_coherent(a, b, c, d)
#define usb_buffer_free(a, b, c, d) usb_free_coherent(a, b, c, d)
4.6. Configure RT2870STA.dat
After installation, the DWA 160 main configuration will be placed under /etc/Wireless/RT2870STA/RT2870STA.dat. Don't ask why it's not called RT5572STA ... It's Ralink mess.
During installation this file will be copied from ./drivers/RT2870STA.dat
In this file, wifi supported modes are defined by the key WirelessMode. To avoid to get random disconnexion, I've found that it's better to use a restrictive combination according to your Wifi AP. Possible values are :
- 5: 11ABGN mixed
- 6: 11N only
- 7: 11GN mixed
- 8: 11AN mixed
- 9: 11BGN mixed
- 10: 11AGN mixed
Another interesting parameter to get better stability is WmmCapable. This defines if the USB key should use some WMM QoS protocol. I've found that connexion is much more stable with QoS disabled.
Here are my parameters to get a stable connexion to a 5GHz 300Mbits AP :
Before doing any compilation job, we need to save the complete patched driver folder for later DKMS declaration.
# cp -R drivers drivers-dkms
Now we can go in the drivers main source folder and start the compilation job.
# cd drivers
make -C tools
make: Entering directory '/home/xxx/Downloads/2012_03_22_RT5572_Linux_STA_v184.108.40.206_DPO/tools'
gcc -g bin2h.c -o bin2h
make: Leaving directory '/home/xxx/Downloads/2012_03_22_RT5572_Linux_STA_v220.127.116.11_DPO/tools'
make: Leaving directory '/usr/src/linux-headers-3.2.0-24-generic'
cp: impossible to suppress «/tftpboot»: Permission denied
make: *** [LINUX] Error 1
Compilation will give some warnings (cast, ...). It's ok.
Latest error is also normal, as the makefile tries to copy one file in a root folder. As operation is not done as sudo ... it fails.
Anyway, compilation is done !
We can now install the newly compiled module :
# sudo make install
make -C /home/xxx/Downloads/2012_03_22_RT5572_Linux_STA_v18.104.22.168_DPO/os/linux -f Makefile.6 install
make: Entering directory '/home/xxx/Downloads/2012_03_22_RT5572_Linux_STA_v22.214.171.124_DPO/os/linux'
/sbin/depmod -a 3.2.0-24-generic
make: Leaving directory '/home/xxx/Downloads/2012_03_22_RT5572_Linux_STA_v126.96.36.199_DPO/os/linux'
5. Load the Module
Once the rt5572sta module is installed, you can connect your DWA-160 USB key.
To make it work, you just need to load the newly compiled module :
# sudo modprobe rt5572sta
The orange light should start blinking. Bingo !
With latest drivers, the orange Led is not blinking any more. It's normal.
Even with the LED off, you should get a complete WAN connexion.
(thanks to Mark Mason for the info :-)
Your wifi adpater DWA-160 should now be available in the Network Manager menu.
You should now be able to connect to any 2.4GHz or 5GHz network, depending on the WirelessMode you've previously configured.
As you've loaded the module manually, you now have to enable it to automatically load at startup.
To do so, you need to add these lines at the end of /etc/modules as root
# sudo gedit '/etc/modules'
# Compiled module for D-Link DWA-160 rev B2
You're done. After a reboot, your DWA-160 should be starting automatically.
6. Declare the Driver to DKmS
Now that driver has been tested and is working properly, we will use DKMS mecanism to rebuild and reinstall it at every kernel update.
DKMS (Dynamic Kernel Module Support) provides support for installing supplementary versions of kernel modules. The package compiles and installs into the kernel tree.
DKMS is called automatically upon installation of new kernel-image packages, and therefore modules added to DKMS will be automatically carried across updates.
For rt5572sta driver to be compiled and installed automatically with new kernel updates, we first need to create a DKMS configuration file.
This file has to be created at the root of the previously saved drivers-dkms driver source directory.
Now we need to copy the whole driver directory to the DKMS drivers folder tree under /usr/src/modulename-module.version
# sudo cp -R drivers-dkms /usr/src/rt5572sta-2.601
Everything is now ready to add the driver to the DKMS database.
# sudo dkms add -m rt5572sta -v 2.601
Creating symlink /var/lib/dkms/rt5572sta/2.601/source ->
DKMS: add completed.
To test the automatic driver building & installation by DKMS, you can trigger it for current kernel :
# sudo dkms build -m rt5572sta -v 2.601
Kernel preparation unnecessary for this kernel. Skipping...
cleaning build area....
make KERNELRELEASE=3.2.0-30-generic KERNELDIR=/lib/modules/3.2.0-30-generic/build.............................................................
cleaning build area....
DKMS: build completed.
# sudo dkms install -m rt5572sta -v 2.601
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installing to /lib/modules/3.2.0-30-generic/updates/dkms/
DKMS: install completed.
The compiled module is available under /lib/modules/yourcurrentkernel/updates/dkms/rt5572sta.ko
You've tested that RT5572STA driver is properly handled by DKMS.
It will be compiled and installed with any new kernel installation on your computer.
In case one day you want to remove rt5572sta driver from DKMS database,
you will just have to use the following command :
# sudo dkms remove rt5572sta/2.601 --all
7. Speed Test
To check what type of speed I can expect from this new wifi adapter, I've done a very simple file transfert test from a NAS with Gbits attachment to my desktop.
Here are the results :
|Type of network||Speed|
|54G WEP||1 Mb/s|
|802.11N Open||3.9 Mb/s|
|802.11N WPA2 (AES)||3.7 Mb/s|
|CPL 200||3 Mb/s|
We can say that there is some improvment from the previous 54G network to the new 802.11N network !
Hope it helps.