Jeremy's Web Corner http://jeremydenise.net
:: home :: member area :: contact ::

Navigation

Wifi with DWL-G122 under Linux

Submitted by jeremy on Mon, 2006-07-31 13:07.

After some days of struggle, I managed to establish a wifi connection between a PC and my router at home, using a D-Link DWL-G122 USB dongle. This is device is numbered "B1", and is based on a RA2570 chipset (it is important). Here is a summary of my investigations.

Step one: decide which driver to use

Under Linux, three possibilities at sight:

  1. kernel module ndiswrapper allows one to directly use the Windows driver (yes, it can cope with .SYS and .INF files). Sounds magic, but unfortunately many users reported this solution as not so stable in practice, and hey, what about using Linux software under Linux ? ;-)
  2. Ralink, the chipset vendor, is smart enough to provide a native Linux driver, code named RT25USB, under the GPL license; it may be found here, and, as of writing, is version 2.0.6.0 (2005/10/14);
  3. an open-source project called rt2x00.serialmonkey.com contributed to enhance version 1.x of the former driver (released as rt2400 and rt2500). Then a full rewrite got started, in order to produce a fully integrated 2.6 kernel module (especially to make proper use of the inner ieee80211 stack); so was born driver rt2x00, that can be found here.

Hmmm, what a mess. Well, after some testing, I found the native Ralink driver to be the most stable (RT25USB 2.0.6.0).

Step two: let's install it

I did this installation under Debian, with a 2.6.15 kernel.

  1. uncompress driver sources to /usr/src/modules:

    cd /usr/src/modules
    tar xvzf RT25USB-SRC-Vx.x.x.x

  2. if kernel version >= 2.6.13, replace calls to verify_area with access_ok (this function no longer exists under recent kernels)

    perl -pi'.orig' -e 's/verify_area/access_ok/' *.c

  3. compile module as indicated in README

    cp Makefile.6 Makefile
    make

  4. install module so it can be found by the kernel

    mkdir /lib/modules/2.6.15/extras
    cp rt2570.ko /lib/modules/2.6.15/extras

  5. then some depmod -a, update-modules if needed, and you're done.

Step three: configure it

The README file that comes with the driver is pretty optimistic about configuration. Practically speaking, if your aim is not to become a free ISP for your neighborood, it is more than recommended to activate the so-called WPA-PSK protocol, so transmissions between the wifi adapter and the access point are encrypted. Some commands have to be known, though

  • iwconfig is used to define parameters shared between all wireless adapters;
  • iwpriv does the same with adapter-specific parameters;
  • ifconfig has a similar use, for common network adapters (ethernet, token-ring, irda, wifi, ...).

So I wrote a script (/usr/local/bin/wifi) that is to be called each time the rausb0 network interface gets up or down (with ifup/ifdown).

Excerpt from /etc/network/interfaces:

auto rausb0
iface rausb0 inet dhcp
pre-up /usr/local/bin/wifi start
pre-down /usr/local/bin/wifi stop

Excerpt from /usr/local/bin/wifi:

#! /bin/sh
IFACE="rausb0"
MODULE="rt2570"
MODE="wpapsk"
ESSID="ACCESSPOINTNAME"
WPAPSK="63CHARSMAXPASSPHRASE"
case "$1_$MODE" in
start_wpapsk)
ifconfig $IFACE down
modprobe $MODULE
ifconfig $IFACE up
ifconfig $IFACE down
ifconfig $IFACE up
sleep 3
iwconfig $IFACE mode managed
iwpriv $IFACE enc 3
iwpriv $IFACE auth 3
iwconfig $IFACE essid "$ESSID"
pause 3
iwpriv $IFACE wpapsk "$WPAPSK"
pause 3
iwconfig $IFACE essid "$ESSID"
pause 3
;;
stop_*)
ifconfig $IFACE down
rmmod $MODULE
;;
esac

One may ask: what's the point of all these 'sleep's ? I must admit it's a problem I could not really figure out. Some precise sync's are needed to get WPA working, and these delays seem to depend on what machine is used (and whether it's a USB 1.x or 2.x bus). I found other timings on the net, that don't work for me; OK, it's kind of black magic, your mileage may vary...

In hope you will not waste as much time as I did to have all this working...

-J-

Useful links

jeremy's blog | login to post comments | French Language Icon

:: home :: member area :: contact ::