Sunday, March 8, 2009

Start your HSDPA connection when linux starts.

Well in my previous post i showed you how to use a HSDPA modem in linux. But that ejecting and running wvdial was some what a trouble for me. I wanted my internet connection to be ready when i login to my system. So i wrote a startup script and a helper script to handling switching the device to modem mode and dial using wvdial. Feel free to use the following scripts at your own risk.

-------------------Contents of /bin/3gwvdial-------------------
#!/bin/bash
if [ -f /etc/3gwvdial.conf ]; then
if [ -a /dev/ttyUSB0 ]; then
echo "Modem found"
else
echo "Modem not found, switching to modem mode."
xargs eject < /etc/3gwvdial.conf
sleep 10
fi
wvdial -C /etc/wvdial.conf &>/dev/null &
echo "Connected."
else
echo "/etc/3gwvdial.conf file not found."
exit -1
fi
----------------------------------------------------------------


In the above script, you have to mention the device file of your HSDPA modem in
/etc/3gwvdial.conf file as follows

-----------------Contents of /etc/3gwvdial.conf---------------
/dev/sr3
--------------------------------------------------------------

After that make sure you give executable permission to your script. Plug your HSDPA modem (no need to eject for the first time), run the script as the super user. If nothing goes wrong you will be connected to internet. So now its time for the startup script.

-----------------Contents of /etc/init.d/hsdpa---------------
#!/bin/bash
#
# description: Controls the hsdpa connection using 3gwvdial script.
# processname: hsdpa
# chkconfig: 2345 11 89

# Source function library.
. /etc/rc.d/init.d/functions

start() {
echo -n $"Starting hsdpa: "
/bin/3gwvdial &>/dev/null &
success
echo
}

stop() {
echo -n $"Shutting down hsdpa: "
killall wvdial &>/dev/null &
success
echo
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
RETVAL=$?
;;
status)
status wvdial
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac

exit 0
-------------------------------------------------------------

Give executable permission to the above file as well. Run the following command as super user.

/sbin/chkconfig --add hsdpa

Now try to start you newly created service by following command as super user.

/sbin/service hsdpa start

You must have internet by now. If any improvements that you think for the above scripts please drop a comment.

No comments: