Using UMTS/GPRS USB stick

Other talk about Salix
Post Reply
User avatar
thenktor
Salix Wizard
Posts: 2426
Joined: 6. Jun 2009, 14:47
Location: Franconia
Contact:

Using UMTS/GPRS USB stick

Post by thenktor »

Hi,

did somebody already use UMTS sticks in Salix/Slackware?
One of my friends says it works out of th ebox in Ubuntu via Gnome NetworkManager. Another possible solution might be umtsmon (but it uses qt3). Perhaps there are better options for Salix? I'm not keen on building NetworkManager just for this task.
Image
burnCDDA (burns audio CDs)
geBIERt (German beer blog)
flux
Posts: 26
Joined: 26. Oct 2009, 12:13

Re: Using UMTS/GPRS USB stick

Post by flux »

One sentence at the beginning: I am no scripter, I never had an education in computing, I only try to make things work. Feel free to change it to your needs!

You can use wvdial, comgt and a bash script to connect UMTS-modems.

Here a script, which uses zenity, gtkdialog, wvdial and comgt (I assume, all packages are installed in your system) ... it is the english one, a german script is available too. It is part of fluxflux-sl (Slackware based system with Openbox) and has been part of fluxflux-eee and fluxflux-se (PCLinuxOS remaster). It is running without problems for many users since more than two years.

Copy this /etc/wvdial.conf to /etc/ (as root in a terminal), this is a configuration file for o2, the last lines (do NOT remove the last 4 lines) are needed for the script and will be reconfigured with the correct values for your provider within the script and with your personal input (AP, user, password):

Code: Select all

[Dialer Defaults]
Modem = /dev/ttyUSB0
ISDN = off
Modem Type = USB Modem
Baud = 460800
Init = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init4 = 
Init5 = 
Init6 = 
Init7 = 
Init8 = 
Init9 = 
Phone1 = 
Phone2 = 
Phone3 = 
Phone4 = 
Dial Prefix = 
Dial Attempts = 1
Dial Command = ATM1L3DT
Ask Password = off
Auto Reconnect = off
Abort on Busy = off
Carrier Check = on
Check Def Route = on
Abort on No Dialtone = on
Stupid Mode = off
Idle Seconds = 0
Init3 = AT+CGDCONT=1,"IP","webmobil1"
Password = o2
Username = o2
Phone = *99#
Then copy this script (called umts-connect) to /usr/local/bin/ and make it executable with "chmod a+x /usr/local/bin/umts-connect" and run a "ldconfig":

Code: Select all

#!/bin/bash
#
# umts-connect 0.3
#
# Script to connect UMTS modems
# via comgt (PIN activation) and wvdial
#
# - icon with established connection
# - used volume is shown after the connection is closed
# - choice of the device (modem, handy via usb or bluetooth
#
# Thomas Schönhütl <pilleus.pulcher@arcor.de>
# 22. September 2008
# 20. April 2009
# 20. Juli 2009
#
# Lizenz: GPL, Version 2
#
DEVICE=$(zenity --title "Modem/Handy" --width=400 --height=200 --radiolist --text "Which device shall be used?" --list --column Choice --column Device TRUE "UMTS-Modem (USB/PCMCIA/Express34)" FALSE "Handy/PDA via USB connection" FALSE "Handy/PDA via bluetooth")
if [ -z "`echo $DEVICE`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
#
#
#
if [ "`echo $DEVICE`" = "UMTS-Modem (USB/PCMCIA/Express34)" ]; then
#
if [ -z "`/bin/ls /dev/ttyUSB*`" -a -z "`/bin/ls /dev/ttyACM*`" ]; then
zenity --title "UMTS connection" --info --text "No UMTS modem available!\n\nThe script will finish now ..."
exit
fi
#
PIN=$(zenity --title "PIN" --entry --text "Please insert the PIN of the SIM card:" --hide-text)
#
export COMGTPIN=$PIN
/usr/local/bin/comgt PIN -d /dev/ttyUSB0
# 
WAHL=$(zenity --title "UMTS connection" --list --radiolist --text "Use the last configuration?" --column Choice --column Action TRUE "Yes, use it." FALSE "No, configure a new one.")
#
if [ -z "`echo $WAHL`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
#
if [ "`echo $WAHL`" = "Yes, use it." ]; then
sed -i "s:ttyACM:ttyUSB:" /etc/wvdial.conf
sed -i "s:rfcomm0:ttyUSB0:" /etc/wvdial.conf
export MAIN_DIALOG="
<window title=\"UMTS connection\">
<hbox>
<vbox>
<text>
<label>Preparing the UMTS modem for wvdial ...</label>
</text>
</vbox>
</hbox>
</window>"
{
sleep 15
killall gtkdialog
} | gtkdialog -c --program MAIN_DIALOG
(xterm -title "Please do NOT close this window during the connection ..." -e wvdial && ERG=$(echo "`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '2,3d'`+`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '1d' | sed -e '2d'`" | bc -l) && ERG1=$(echo "`echo $ERG`/1024" | bc -l) && ERG2=$(echo $ERG1 | cut -d "." -f1) && zenity --info --text "Used data volume:\n\n`echo $ERG2` Kb" && killall zenity) &
sleep 45
rm /etc/resolv.conf
echo "nameserver `tail -30 /var/log/messages | grep DNS | sed -e '2d'| rev | cut -d " " -f1 | rev`" > /etc/resolv.conf
while [ "`ps -e | grep wvdial`" ]; do zenity --notification --window-icon=/usr/share/icons/Tango/scalable/devices/network-wireless.svg --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`" && zenity --info --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`"; continue; done
else
TEL=$(zenity --title "UMTS connection" --entry --text "Insert telefonnumber or accept:" --entry-text *99#)
if [ -z "`echo $TEL`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
NETZ=$(zenity --title "UMTS connection" --entry --text "Please insert APN of the provider:")
if [ -z "`echo $NETZ`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
USER=$(zenity --title "UMTS connection" --entry --text "Please insert username:")
if [ -z "`echo $USER`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
PASSWD=$(zenity --title "UMTS connection" --entry --text "Please insert password:")
if [ -z "`echo $PASSWD`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
#
tac /etc/wvdial.conf | sed -e '1,4d' | tac > /tmp/wvdial.conf
echo "Init3 = AT+CGDCONT=1,\"IP\",\"`echo $NETZ`\"" >> /tmp/wvdial.conf
echo "Password = `echo $PASSWD`" >> /tmp/wvdial.conf
echo "Username = `echo $USER`" >> /tmp/wvdial.conf
echo "Phone = `echo $TEL`" >> /tmp/wvdial.conf
rm -f /etc/wvdial.conf
mv /tmp/wvdial.conf /etc/
sed -i "s:ttyACM:ttyUSB:" /etc/wvdial.conf
sed -i "s:rfcomm0:ttyUSB0:" /etc/wvdial.conf
(xterm -title "Please do NOT close this window during the connection ..." -e wvdial && ERG=$(echo "`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '2,3d'`+`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '1d' | sed -e '2d'`" | bc -l) && ERG1=$(echo "`echo $ERG`/1024" | bc -l) && ERG2=$(echo $ERG1 | cut -d "." -f1) && zenity --info --text "Used data volume:\n\n`echo $ERG2` Kb" && killall zenity) &
sleep 45
rm /etc/resolv.conf
echo "nameserver `tail -30 /var/log/messages | grep DNS | sed -e '2d'| rev | cut -d " " -f1 | rev`" > /etc/resolv.conf
while [ "`ps -e | grep wvdial`" ]; do zenity --notification --window-icon=/usr/share/icons/Tango/scalable/devices/network-wireless.svg --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`" && zenity --info --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`"; continue; done
fi
killall zenity
fi
#
#
#
if [ "`echo $DEVICE`" = "Handy/PDA via USB connection" ]; then
if [ -z "`/bin/ls /dev/ttyUSB*`" -a -z "`/bin/ls /dev/ttyACM*`" ]; then
zenity --title "UMTS connection" --info --text "No UMTS modem available!\n\nThe script will finish now ..."
exit
fi
#
# 
WAHL=$(zenity --title "UMTS connection" --list --radiolist --text "Use the last configuration?" --column Choice --column Action TRUE "Yes, use it." FALSE "No, configure a new one.")
#
if [ -z "`echo $WAHL`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
#
if [ "`echo $WAHL`" = "Yes, use it." ]; then
sed -i "s:ttyUSB:ttyACM:" /etc/wvdial.conf
sed -i "s:rfcomm0:ttyACM0:" /etc/wvdial.conf
export MAIN_DIALOG="
<window title=\"UMTS connection\">
<hbox>
<vbox>
<text>
<label>Preparing Handy/PDA for wvdial ...</label>
</text>
</vbox>
</hbox>
</window>"
{
sleep 4
killall gtkdialog
} | gtkdialog -c --program MAIN_DIALOG
(xterm -title "Please do NOT close this window during the connection ..." -e wvdial && ERG=$(echo "`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '2,3d'`+`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '1d' | sed -e '2d'`" | bc -l) && ERG1=$(echo "`echo $ERG`/1024" | bc -l) && ERG2=$(echo $ERG1 | cut -d "." -f1) && zenity --info --text "Used data volume:\n\n`echo $ERG2` Kb" && killall zenity) &
sleep 45
rm /etc/resolv.conf
echo "nameserver `tail -30 /var/log/messages | grep DNS | sed -e '2d'| rev | cut -d " " -f1 | rev`" > /etc/resolv.conf
while [ "`ps -e | grep wvdial`" ]; do zenity --notification --window-icon=/usr/share/icons/Tango/scalable/devices/network-wireless.svg --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`" && zenity --info --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`"; continue; done
else
TEL=$(zenity --title "UMTS connection" --entry --text "Insert telefonnumber or accept:" --entry-text *99#)
if [ -z "`echo $TEL`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
NETZ=$(zenity --title "UMTS connection" --entry --text "Please insert APN of the provider:")
if [ -z "`echo $NETZ`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
USER=$(zenity --title "UMTS connection" --entry --text "Please insert username:")
if [ -z "`echo $USER`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
PASSWD=$(zenity --title "UMTS connection" --entry --text "Please insert password:")
if [ -z "`echo $PASSWD`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
#
tac /etc/wvdial.conf | sed -e '1,4d' | tac > /tmp/wvdial.conf
echo "Init3 = AT+CGDCONT=1,\"IP\",\"`echo $NETZ`\"" >> /tmp/wvdial.conf
echo "Password = `echo $PASSWD`" >> /tmp/wvdial.conf
echo "Username = `echo $USER`" >> /tmp/wvdial.conf
echo "Phone = `echo $TEL`" >> /tmp/wvdial.conf
rm -f /etc/wvdial.conf
mv /tmp/wvdial.conf /etc/
sed -i "s:ttyUSB:ttyACM:" /etc/wvdial.conf
sed -i "s:rfcomm0:ttyACM0:" /etc/wvdial.conf
(xterm -title "Please do NOT close this window during the connection ..." -e wvdial && ERG=$(echo "`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '2,3d'`+`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '1d' | sed -e '2d'`" | bc -l) && ERG1=$(echo "`echo $ERG`/1024" | bc -l) && ERG2=$(echo $ERG1 | cut -d "." -f1) && zenity --info --text "Used data volume:\n\n`echo $ERG2` Kb" && killall zenity) &
sleep 45
rm /etc/resolv.conf
echo "nameserver `tail -30 /var/log/messages | grep DNS | sed -e '2d'| rev | cut -d " " -f1 | rev`" > /etc/resolv.conf
while [ "`ps -e | grep wvdial`" ]; do zenity --notification --window-icon=/usr/share/icons/Tango/scalable/devices/network-wireless.svg --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`" && zenity --info --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`"; continue; done
fi
killall zenity
fi
#
#
#
if [ "`echo $DEVICE`" = "Handy/PDA via bluetooth" ]; then
zenity --title "UMTS connection" --info --text "Some handies must be paired with the pc before this script will work, just try it!\n\nPair the handy with the pc and make the pc known in the handy as allowed device ..."
# 
if [ "`hcitool dev | awk '{ print $2 $3 }'`" = "" ]; then
zenity --title "UMTS connection" --info --text "No bluetooth device available!\n\nThe script will finish now!"
/etc/rc.d/rc.bluetooth stop
/etc/rc.d/rc.bluetooth start
exit
fi
#
# 
OLD=$(cat /etc/bluetooth/hcid.conf | grep passkey | cut -d " " -f2 | sed -e 's/\";//' -e 's/\"//')
PIN=$(zenity --title "UMTS connection" --entry --text "The actual PIN of the pc is `echo $OLD`. It can be changed now:" --entry-text `echo $OLD`)
echo $PIN > /etc/bluetooth/passkeys/default
if [ -z "`echo $PIN`" ]; then
/etc/rc.d/rc.bluetooth stop
/etc/rc.d/rc.bluetooth start
exit
fi
sed -i "s/`echo $OLD`/`echo $PIN`/" /etc/bluetooth/hcid.conf
zenity --title "UMTS connection" --info --text "The actual PIN of the pc is `echo $PIN`!"
#
# 
zenity --title "UMTS connection" --progress --text "Scanning for bluetooth devices in range ..." --pulsate --auto-close &
hcitool scan > ERG
EMPF=`cat ERG | sed -e '1d' -e 's/ //g'`
rm -f ERG
killall zenity
#
if [ "`echo $EMPF | awk '{ print $1 }'`" = "" ]; then
zenity --title "UMTS connection" --info --text "No bluetooth devices in range!\n\nThe script will finish now!"
/etc/rc.d/rc.bluetooth stop
/etc/rc.d/rc.bluetooth start
exit
fi
#
EMPFWAHL=$(zenity --title "UMTS connection" --list --radiolist --text "Choose the bluetooth device:" --column Choice --column Device TRUE "`echo $EMPF | cut -d " " -f1,2`" FALSE "`echo $EMPF | cut -d " " -f3,4`" FALSE "`echo $EMPF | cut -d " " -f5,6`")
if [ -z "`echo $EMPFWAHL`" ]; then
/etc/rc.d/rc.bluetooth stop
/etc/rc.d/rc.bluetooth start
exit
fi
#
#
KANAL=$(sdptool search dun | grep -i "`echo $EMPFWAHL | cut -d " " -f1`" -A 9 | grep Channel | cut -d ":" -f2 | sed -e 's: ::g')
rfcomm connect 0 "`echo $EMPFWAHL | cut -d " " -f1`" "`echo $KANAL`" &
#
#
WAHL=$(zenity --title "UMTS connection" --list --radiolist --text "Use the last configuration?" --column Choice --column Action TRUE "Yes, use it." FALSE "No, configure a new one.")
#
if [ -z "`echo $WAHL`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
#
if [ "`echo $WAHL`" = "Yes, use it." ]; then
sed -i "s:ttyUSB0:rfcomm0:" /etc/wvdial.conf
sed -i "s:ttyACM0:rfcomm0:" /etc/wvdial.conf
export MAIN_DIALOG="
<window title=\"UMTS connection\">
<hbox>
<vbox>
<text>
<label>Preparing Handy/PDA for wvdial ...</label>
</text>
</vbox>
</hbox>
</window>"
{
sleep 30
killall gtkdialog
} | gtkdialog -c --program MAIN_DIALOG
(xterm -title "Please do NOT close this window during the connection ..." -e wvdial && ERG=$(echo "`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '2,3d'`+`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '1d' | sed -e '2d'`" | bc -l) && ERG1=$(echo "`echo $ERG`/1024" | bc -l) && ERG2=$(echo $ERG1 | cut -d "." -f1) && zenity --info --text "Used data volume:\n\n`echo $ERG2` Kb" && killall zenity) &
#sleep 30 && tail /var/log/messages | grep DNS | sed 's/ primary  //' | sed 's/ secondary//' \ | cut -d" " -f8 | while read line; do echo "nameserver $line" > /etc/resolv.conf; done
sleep 45
rm /etc/resolv.conf
echo "nameserver `tail -30 /var/log/messages | grep DNS | sed -e '2d'| rev | cut -d " " -f1 | rev`" > /etc/resolv.conf
while [ "`ps -e | grep wvdial`" ]; do zenity --notification --window-icon=/usr/share/icons/Tango/scalable/devices/network-wireless.svg --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`" && zenity --info --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`"; continue; done
else
TEL=$(zenity --title "UMTS connection" --entry --text "Insert telefonnumber or accept:" --entry-text *99#)
if [ -z "`echo $TEL`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
NETZ=$(zenity --title "UMTS connection" --entry --text "Please insert APN of the provider:")
if [ -z "`echo $NETZ`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
USER=$(zenity --title "UMTS connection" --entry --text "Please insert username:")
if [ -z "`echo $USER`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
PASSWD=$(zenity --title "UMTS connection" --entry --text "Please insert password:")
if [ -z "`echo $PASSWD`" ]; then
zenity --title "UMTS connection" --info --text "The script will finish now ..."
exit
fi
#
tac /etc/wvdial.conf | sed -e '1,4d' | tac > /tmp/wvdial.conf
echo "Init3 = AT+CGDCONT=1,\"IP\",\"`echo $NETZ`\"" >> /tmp/wvdial.conf
echo "Password = `echo $PASSWD`" >> /tmp/wvdial.conf
echo "Username = `echo $USER`" >> /tmp/wvdial.conf
echo "Phone = `echo $TEL`" >> /tmp/wvdial.conf
rm -f /etc/wvdial.conf
mv /tmp/wvdial.conf /etc/
sed -i "s:ttyUSB0:rfcomm0:" /etc/wvdial.conf
sed -i "s:ttyACM0:rfcomm0:" /etc/wvdial.conf
(xterm -title "Please do NOT close this window during the connection ..." -e wvdial && ERG=$(echo "`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '2,3d'`+`tail /var/log/messages | grep Sent | tr " " "\n" | grep bytes -1 | sed -e '2,3d' | sed -e '1d' | sed -e '2d'`" | bc -l) && ERG1=$(echo "`echo $ERG`/1024" | bc -l) && ERG2=$(echo $ERG1 | cut -d "." -f1) && zenity --info --text "Used data volume:\n\n`echo $ERG2` Kb" && killall zenity) &
#sleep 30 && tail /var/log/messages | grep DNS | sed 's/ primary  //' | sed 's/ secondary//' \ | cut -d" " -f8 | while read line; do echo "nameserver $line" > /etc/resolv.conf; done
sleep 45
rm /etc/resolv.conf
echo "nameserver `tail -30 /var/log/messages | grep DNS | sed -e '2d'| rev | cut -d " " -f1 | rev`" > /etc/resolv.conf
while [ "`ps -e | grep wvdial`" ]; do zenity --notification --window-icon=/usr/share/icons/Tango/scalable/devices/network-wireless.svg --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`" && zenity --info --text "UMTS connection: activ; local IP: `ifconfig | grep P-t-P | tr " " "\n" | grep addr | cut -b 6-`; DNS: `cat /etc/resolv.conf`"; continue; done
fi
killall zenity
rfcomm release "`echo $EMPFWAHL | cut -d " " -f1`" "`echo $KANAL`" 
fi
#

The script will connect all Huawei UMTS modems, an icon will be shown in the panel and after closing the connection the used traffic will be displayed.

You can use the UMTS modem directly or a connection via bluetooth or USB connected handy.

flux.

P. S.: Click here for a screenshot ...
User avatar
thenktor
Salix Wizard
Posts: 2426
Joined: 6. Jun 2009, 14:47
Location: Franconia
Contact:

Re: Using UMTS/GPRS USB stick

Post by thenktor »

My friend has bought one of these sticks now. As he needs something simple to use, I've installed qt3 and umtsmon. I've added his user to the dialout group and and I've done setui root for the umtsmon tool:

Code: Select all

chown root:dialout umtsmon
chmod +s umtsmon
chmod 754 umtsmon
And I had to do a small hack for resolv.conf:

Code: Select all

rm /etc/resolv.conf
ln -s /etc/ppp/resolv.conf /etc/resolv.conf
Everything works fine now. All he has to do is starting the umtsmon tool. It shows signal strenght, connection type (gprs/umts) and traffic.
Image
burnCDDA (burns audio CDs)
geBIERt (German beer blog)
baran
Posts: 74
Joined: 8. Feb 2010, 17:41

Re: Using UMTS/GPRS USB stick

Post by baran »

Sorry another link :-)
Post Reply