Sunday, 3 February 2008

Using ndiswrapper to get your wireless connection working

Although it may not always seem like it, Linux is actually the best operating system in the world for out-of-the-box functionality for peripherals. The Linux kernel runs on a staggering panoply of hardware, such as:
  • Wristwatches
  • Consumer electronics (the TiVO is the best example of this)
  • Wireless routers (including the BT Home Hub)
  • Servers (Google use it on their servers, as do many other companies)
  • Supercomputers
I even heard recently that a computerised car that won a competition to drive through a mockup of a city without human intervention was running Ubuntu! So when you take that into account, you realise that Linux is very portable. More things "just work" with Linux than any other operating system you care to name.

This is because Linux has drivers for many pieces of hardware built into the kernel. Because manufacturers do not generally provide Linux drivers when you buy hardware, nor do they make them available to download, the developers who create the Linux kernel are responsible for adding these drivers. This means that for a lot of hardware, it's not necessary to install any drivers before using it like you would have to do in Windows. You can just plug it in and see if it works, and if it does, great!


However, it doesn't always work. New hardware will often have no driver support, or poor support. While anything from a year old is usually a fairly safe bet, there's still no guarantee that it will work. Hopefully in future more manufacturers will be willing to provide drivers for Linux, but at present it's still less well-supported than Windows in terms of drivers from manufacturers.


I'd say that wireless Internet connections are one of the things that are worst affected by this. Support for wireless has been poor in the past (although it is steadily improving). Not every device is supported, and of those that are, they often have less functionality or are less reliable than their Windows equivalents. For instance, back when I was using Kubuntu Feisty, there was a driver for my wireless card, but it didn't support WPA encryption, only WEP.


Fortunately, there is a solution. Ndiswrapper is a program that enables you to use the Windows driver for your device within Linux. It's not perfect as it doesn't support all wireless devices and setting it up does take a bit of effort, but it's sometimes the only option to get wireless support working.


First of all you need to get the Windows drivers. I find the best way to do this is to go to the manufacturer's website and look up your wireless card. I use a Belkin F5D7010uk PCMCIA card and so I looked this up on Belkin's UK website. Most manufacturers will have a link where you can download a copy of the driver (fortunately Belkin are pretty good at this and that's one reason why I'd recommend their products if you're planning to use them with Linux), so just search around for it.


It's also a good idea to try searching under the name of the chipset. You can find this using the connection applet for your desktop (Network Manager in Gnome, KNetwork Manager in KDE). Look for the device name (in mine it's RT2561/RT61). This shouldn't be too hard to find, and if the device manufacturer doesn't offer drivers, the chipset manufacturer may do. You'll also want this information later.


If you can't find it, you might be able to get the driver from your installation CD, or if you still have a Windows install on your computer, you might be able to copy the files you need from your Windows installation. If none of these work, try Googling it (when running Linux, Google is your best friend in the whole world!).



Hopefully you should now have a .zip file for your drivers. I'm assuming that you've saved this to your home directory. I recommend that you set up a new folder (call it Driver for ease of reference), and move the .zip file into it. Now, you'll need to extract the files you need, and this is best done from the command line. Open Terminal or Konsole and enter the following:

cd /home/matthew/Driver
Obviously you need to substitute the name of your home directory (this is your user name when you installed). This changes the working folder (or directory to use the correct terminology) to the Driver folder we just set up. Now enter the following:
unzip f5d7010v6drivers.exe
Again, you need to substitute the name of the file you downloaded. This will work with .zip files, as well as most .exe files. If not, you may have to extract them in Windows, using a tool like Universal Extractor to get the files you need.


What you are after is the .sys and .inf files relevant to your wireless device. Sometimes, there may be .bin files as well - if so, you will need these as well, but they don't appear often. You can ignore any other files that appear.



Now, if there's more than one .inf file, you will need to search through them to see which one relates to your device. Look for the PCI ID of the device by going to System>Administration>Device Manager in Ubuntu, or KInfoCenter in Kubuntu. It may be under PCI, or Network Interfaces. In Ubuntu, look for a line that reads net.physical_device. This should show the PCI number. It should be in the format pci_701e1799. I found that in Kubuntu, I could only find the first part (701e) when I looked under PCI in KInfoCenter, but this should be enough. Open the command line and use the cd command to change back into the folder with the drivers:

cd /home/matthew/Driver
Now we'll use the grep command to search the .inf file. Enter the following:
grep "701E" rt61.inf
Substitute the name of your .inf file for rt61.inf and whatever you can get of the PCI ID in the quotes. Don't forget, the command line is case sensitive so if this doesn't work try using lower case instead of upper case. Alternatively, if you have very little to go on, try replacing "701E" with the name of the manufacturer. You should get a list of the lines in the file that include the term "701E". All you need to do is establish which file has the PCI ID of your device, and keep that one. You can get rid of any others.


Now we have the files we need, we can get on with getting them working. First of all, you will need to install ndiswrapper. This isn't generally installed by default, but it may be on the CD you installed from. But the easiest way to get it is to use an Ethernet connection. Just open the command line and enter the following:

apt-cache search ndiswrapper
We're searching for the most recent version of ndiswrapper. In Gutsy, here's the response I got:
matthew@matthew-laptop:~/Driver$ apt-cache search ndiswrapper
linux-ubuntu-modules-2.6.22-14-386 - Ubuntu supplied Linux modules for version 2.6.22 on i386
linux-ubuntu-modules-2.6.22-14-generic - Ubuntu supplied Linux modules for version 2.6.22 on x86/x86_64
linux-ubuntu-modules-2.6.22-14-server - Ubuntu supplied Linux modules for version 2.6.22 on x86/x86_64
ndiswrapper-common - Common scripts required to use the utilities for ndiswrapper
ndiswrapper-utils-1.9 - Userspace utilities for the ndiswrapper linux kernel module
linux-ubuntu-modules-2.6.22-14-rt - Ubuntu supplied Linux modules for version 2.6.22 on x86/x86_64
linux-ubuntu-modules-2.6.22-14-ume - Ubuntu supplied Linux modules for version 2.6.22 on Embedded/Mobile
linux-ubuntu-modules-2.6.22-14-xen - Ubuntu supplied Linux modules for version 2.6.22 on x86
ndisgtk - graphical frontend for ndiswrapper (installation of Windows WiFi drivers)
Here, what we need is ndiswrapper-utils-1.9, which is the most recent version currently available in Ubuntu. So now enter the following:
sudo apt-get install ndiswrapper-utils-1.9
You'll be told that ndiswrapper-common also needs to be installed. As usual, apt-get will download the files and install them.


What happens next depends on why you are using ndiswrapper. If there is no driver for your wireless device at all, you can skip this step. If the existing driver doesn't work well, you'll need to blacklist it first. Enter the following:

sudo nano /etc/modprobe.d/blacklist
Now, at the bottom, type the following on a new line:
blacklist modulename
In my case this is rt61 as my adapter uses the Ralink RT61 chipset. Now save the file (Ctrl-X to save and exit nano), then reboot your system. If all has gone to plan, when it restarts the wireless network device will no longer be visible in Network Manager.


Here's where the people who have no driver at all can rejoin us. You may want to set up a folder specifically for the wireless drivers, rather than have them in your home directory. Enter the following:
cd /dev
sudo mkdir wireless
cd /dev/wireless
This moves you to the /dev folder (where drivers are kept, so is a logical choice for this), creates a new folder called wireless, then changes into it.


Now we change into the directory where the files are kept and copy them to the new folder:
cd /home/matthew/Driver
sudo cp rt61.inf rt61.sys RT619x.sys /dev/wireless
This copies the folders into /dev/wireless. Don't forget, replace what I've put with the names of the .sys and .inf files for your device (plus any .bin files).


Now the time has come to configure ndiswrapper. Change to the directory where you put the files:
cd /dev/wireless
Now enter the following:
sudo ndiswrapper -i rt61.inf
Again, substitute the name of your .inf file (in my case I didn't know which one of the two to try, so I tried the rt.61 and it worked fine).

Now enter the following:

sudo ndiswrapper -m
sudo nano /etc/modules
This opens the modules configuration file. Add a new line at the bottom, and enter the following:
ndiswrapper
Press enter after adding the line, then save and exit. Now reboot your computer. You should now find that the Windows driver is installed and working!


If you have difficulties getting this working, try the Ubuntu Forums. They are very helpful, as wireless problems seem to be fairly common. But if you can't get it working and want to try a different driver, you'll need to remove the one you've installed.

Open the command line and enter the following:
sudo ndiswrapper -l
Look for the first component of the line that is returned (that will be the name of the driver you need to remove). In my case that would be rt61, so now enter the following:
sudo ndiswrapper -e rt61
If you reboot, the ndiswrapper driver will have been removed so you can try another one.


Don't be scared by the length of this post! I found this to be one of the most daunting tasks in using Ubuntu early on, but as of Gutsy there is a driver for my PCMCIA wireless card that supports both WEP and WPA. The chances are that anything over a year old will be supported OK. And once you have done this once it gets easier. The hardest part is finding your chipset and getting the drivers. Believe me, if you can handle this, you're well on the way to being a proficient Linux user!


As an aside, there's also a graphical front-end for ndiswrapper called ndisgtk. I've never tried it, but if you prefer a graphical interface, you may want to try this to configure ndiswrapper rather than using the command line.

No comments:

Post a Comment