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.

Internet on linux with HSDPA

Well if you own a HSDPA modem most of the time your vendor will say that it doesn't support linux :( . I own a BandLuxe C120 HSDPA modem, But i didn't gave up configuring it on linux. Most of the HSDPA modems comes with driver stored inside the modem. When you plug it for first time in your PC, the modem get detected as a USB storage which is read-only. And it will start installing the necessary driver software. So after that it will switch to the modem mode and work. Unfortunately it works only for windows for most of the time. Well that's how it works in brief.

For more information you can visit http://my.opera.com/CrazyTerabyte/blog/2008/12/28/bandluxe-c120-3g-modem-from-oi-velox-plug.

So the working solution for my BandLuxe C120 was ejecting the device once it get detected for the first time. This will switch the device to modem mode. Then you will find a new USB device file some thing like /dev/ttyUSB0. That is your modem.

After that now you need to use the dialer program to dial out. For me wvdial worked. So here i will be mentioning the required modem commands to dial with wvdial.

Modem = /dev/ttyUSB0
ISDN = off
Modem Type = USB Modem
Baud = 115200
Init = ATZ
Init2 = AT+CGDCONT=1,"IP",""
Phone = *99#
Dial Command = ATM1L3DT
Ask Password = off
Password = no_need
Username = no_need
Carrier Check = on
Check Def Route = on
Abort on No Dialtone = on
Stupid Mode = on
Auto DNS = on

These settings will work for wvdial, and there are some settings you need to put in /etc/ppp/options file as well.
/dev/ttyUSB0
115200
noauth
noipdefault
nodetach
local
usepeerdns
lock

Now run the wvdial program as root. Thats it happy browsing :)