Thanks...

Live forum: http://rt2x00.serialmonkey.com/viewtopic.php?t=4359

tranholm

14-10-2007 19:53:07

I am writing this to help other users of the rt61 module having problems maintaining a connection to their WPA-PSK encrypted wireless router/access point.

During the last couple of days I have been working on configuring my local network. I have an older computer running Debian Lenny, where I installed a OvisLink AirLive WT-2000PCI[/url1dfintok] card that uses the Ralink chipset.

When I compiled the [url=http://rt2x00.serialmonkey.com/rt61-cvs-daily.tar.gz1dfintok]rt61-cvs-daily[/url1dfintok] driver and followed the instructions in the README file, I was able to establish connection (some times), but the connection was frequently lost again within minutes. To overcome this problem I chose to write a little script ([b1dfintok]/usr/local/sbin/wlan0_reconnect[/b1dfintok]) that's running in the background. This script checks for connection every 10 second, if a connection isn't found it will recheck 2 seconds later, and afterwards initiate a reconfiguration of the network
[code1dfintok]#!/bin/bash
# Reconnect script.
# Thanks to <http://ubuntuforums.org/showthread.php?t=413499>

iface=wlan0
wlan_module=rt61
router_ip=<MY ROUTER/ACCESS POINT IP ADDRESS>
lockfile=/var/run/connstatus.pid
output=/var/log/connstatus.log
iplog=/var/log/last_ip

check_newip () {
newip=$(/sbin/ifconfig|/bin/grep "Bcast")
oldip=$(cat $iplog)
if [ "$newip" != "$oldip" ]; then
echo Address changed, time: $(date) >> $output
echo "$newip" >> $output
if [ $return_val == 0 ]; then
echo "$newip" > $iplog
fi
fi
}

reconnect () {
sleep 2
ping -c 1 $router_ip >/dev/null 2>&1
return_val=$?
if [ $return_val != 0 ]; then
echo
echo Reconnecting, time: $(date) >> $output
fi
while [ $return_val != 0 ]; do
if [ -f /var/run/dhclient.pid ]; then
kill -9 $(cat /var/run/dhclient.pid)
rm -f /var/run/dhclient.pid
fi
ifdown $iface 2> /dev/null
ifconfig $iface down
sleep 1
modprobe -r $wlan_module
sleep 1
modprobe $wlan_module
sleep 1
ifup $iface
sleep 1
dhclient3 $iface
sleep 1
ping -c 1 $router_ip >/dev/null 2>&1
return_val=$?
for i in $(seq 1 5); do
if [ $return_val == 0 ]; then
break
fi
iwconfig $iface mode managed
ifconfig $iface up
iwpriv $iface set AuthMode=WPAPSK
iwpriv $iface set EncrypType=TKIP
iwconfig $iface ap <MY ROUTER/ACCESS POINT ID ADDRESS>
iwconfig $iface channel <MY ROUTER/ACCESS POINT CHANNEL>
iwconfig $iface essid <MY ROUTER/ACCESS POINT ESSID>
iwpriv $iface set WPAPSK=<MY ROUTER/ACCESS POINT WPAPSK>
iwconfig $iface essid <MY ROUTER/ACCESS POINT ESSID>
sleep 1
dhclient3 $iface
sleep 1
ping -c 1 $router_ip >/dev/null 2>&1
return_val=$?
done
done
}

if ( set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null; then
trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
echo Log for $iface started at $(date): > $output
while [ 1 ]; do
ping -c 1 $router_ip >/dev/null 2>&1
return_val=$?
if [ $return_val == 0 ]; then
echo -n "."
check_newip
else
reconnect
fi
sleep 10
done
rm -f "$lockfile"
trap - INT TERM EXIT
else
echo "Lockfile $lockfile is held by $(cat $lockfile)."
fi[/code1dfintok]
To protect your network password you have to (as root)
[code1dfintok]chmod 700 /usr/local/sbin/wlan0_reconnect[/code1dfintok]
At my Debian Lenny I start this script with the following ([b1dfintok]/etc/init.d/wlan0_reconnect[/b1dfintok])
[code1dfintok]#!/bin/sh
#
### BEGIN INIT INFO
# Provides: wlan0_reconnect
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start the wlan0 reconnect script
### END INIT INFO

# Set variables

WLAN0_RECONNECT_LOG=/var/log/wlan0_reconnect.log
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Functions
do_status () {
cat /var/log/last_ip
echo
cat /proc/net/wireless
}

do_start () {
/usr/bin/nohup /usr/local/sbin/wlan0_reconnect > $WLAN0_RECONNECT_LOG 2>&1 &
}

do_stop () {
if [ -f /var/run/connstatus.pid ]
then
kill -9 $(cat /var/run/connstatus.pid)
rm -f /var/run/connstatus.pid
fi
}

if ! [ -x /usr/local/sbin/wlan0_reconnect ]; then
echo "cannot execute wlan0_reconnect, exiting..."
exit 1
fi

# See how we were called.
case "$1" in
status)
do_status
;;
start)
do_stop
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
esac[/code1dfintok]
At Debian you can activate this [i1dfintok]/etc/init.d/wlan0_reconnect[/i1dfintok] by issuing the following commands (as root)
[code1dfintok]update-rc.d wlan0_reconnect defaults 95 20
/etc/init.d/wlan0_reconnect start[/code1dfintok]
This is definitely not a perfect solution, but it works... My wireless network will still reconnect in average every 30 minutes, but the reconnection process i usually quite fast (less than a minute).

To follow the instructions for posting in this group, I have just created information showing my driver version and kernel
[code1dfintok]hp-hoerby ~ # find /lib/modules/ -name "rt61.ko" -exec modinfo {} \;
filename: /lib/modules/2.6.22-2-686/kernel/drivers/net/rt61.ko
license: GPL
description: Ralink RT61 802.11abg WLAN Driver 1.1.0 CVS 2007100514
author: http://rt2x00.serialmonkey.com
alias: pci:v00001814d00000401sv*sd*bc*sc*i*
alias: pci:v00001814d00000302sv*sd*bc*sc*i*
alias: pci:v00001814d00000301sv*sd*bc*sc*i*
depends: firmware_class
vermagic: 2.6.22-2-686 SMP mod_unload 686
parm: debug:Debug mask: n selects filter, 0 for none (int)
parm: ifname:Network device name (default wlan%d) (charp)[/code1dfintok]
Best regards, and thanks for the work you have put into the rt61 driver.
Jacob Tranholm

PS. I had minor problems running this script along side 'knemo', which I then chose to uninstall.